]>
Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* Hardware memory allocator. |
2 | Copyright (C) 1998 Free Software Foundation, Inc. | |
3 | Contributed by Cygnus Support. | |
4 | ||
5 | This file is part of GDB, the GNU debugger. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License along | |
18 | with this program; if not, write to the Free Software Foundation, Inc., | |
19 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | ||
22 | #include "hw-main.h" | |
23 | #include "hw-base.h" | |
24 | ||
25 | ||
26 | #ifdef HAVE_STDLIB_H | |
27 | #include <stdlib.h> | |
28 | #endif | |
29 | ||
30 | struct hw_alloc_data { | |
31 | void *alloc; | |
32 | int zalloc_p; | |
33 | struct hw_alloc_data *next; | |
34 | }; | |
35 | ||
36 | void | |
37 | create_hw_alloc_data (struct hw *me) | |
38 | { | |
39 | /* NULL */ | |
40 | } | |
41 | ||
42 | void | |
43 | delete_hw_alloc_data (struct hw *me) | |
44 | { | |
c906108c SS |
45 | while (me->alloc_of_hw != NULL) |
46 | { | |
47 | hw_free (me, me->alloc_of_hw->alloc); | |
48 | } | |
49 | } | |
50 | ||
51 | ||
52 | ||
53 | void * | |
54 | hw_zalloc (struct hw *me, unsigned long size) | |
55 | { | |
56 | struct hw_alloc_data *memory = ZALLOC (struct hw_alloc_data); | |
57 | memory->alloc = zalloc (size); | |
58 | memory->zalloc_p = 1; | |
59 | memory->next = me->alloc_of_hw; | |
60 | me->alloc_of_hw = memory; | |
61 | return memory->alloc; | |
62 | } | |
63 | ||
64 | void * | |
65 | hw_malloc (struct hw *me, unsigned long size) | |
66 | { | |
67 | struct hw_alloc_data *memory = ZALLOC (struct hw_alloc_data); | |
68 | memory->alloc = zalloc (size); | |
69 | memory->zalloc_p = 0; | |
70 | memory->next = me->alloc_of_hw; | |
71 | me->alloc_of_hw = memory; | |
72 | return memory->alloc; | |
73 | } | |
74 | ||
75 | void | |
76 | hw_free (struct hw *me, | |
77 | void *alloc) | |
78 | { | |
79 | struct hw_alloc_data **memory; | |
80 | for (memory = &me->alloc_of_hw; | |
81 | *memory != NULL; | |
82 | memory = &(*memory)->next) | |
83 | { | |
84 | if ((*memory)->alloc == alloc) | |
85 | { | |
86 | struct hw_alloc_data *die = (*memory); | |
87 | (*memory) = die->next; | |
88 | if (die->zalloc_p) | |
89 | zfree (die->alloc); | |
90 | else | |
91 | free (die->alloc); | |
92 | zfree (die); | |
93 | return; | |
94 | } | |
95 | } | |
96 | hw_abort (me, "free of memory not belonging to a device"); | |
97 | } |