Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Hardware memory allocator. |
3666a048 | 2 | Copyright (C) 1998-2021 Free Software Foundation, Inc. |
c906108c SS |
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 | |
4744ac1b JB |
9 | the Free Software Foundation; either version 3 of the License, or |
10 | (at your option) any later version. | |
c906108c SS |
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 | ||
4744ac1b JB |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
c906108c | 19 | |
6df01ab8 MF |
20 | /* This must come before any other includes. */ |
21 | #include "defs.h" | |
c906108c SS |
22 | |
23 | #include "hw-main.h" | |
24 | #include "hw-base.h" | |
25 | ||
c906108c | 26 | #include <stdlib.h> |
c906108c | 27 | |
12c4cbd5 MF |
28 | struct hw_alloc_data |
29 | { | |
c906108c | 30 | void *alloc; |
c906108c SS |
31 | struct hw_alloc_data *next; |
32 | }; | |
33 | ||
34 | void | |
35 | create_hw_alloc_data (struct hw *me) | |
36 | { | |
37 | /* NULL */ | |
38 | } | |
39 | ||
40 | void | |
41 | delete_hw_alloc_data (struct hw *me) | |
42 | { | |
c906108c SS |
43 | while (me->alloc_of_hw != NULL) |
44 | { | |
45 | hw_free (me, me->alloc_of_hw->alloc); | |
46 | } | |
47 | } | |
48 | ||
49 | ||
50 | ||
51 | void * | |
52 | hw_zalloc (struct hw *me, unsigned long size) | |
53 | { | |
54 | struct hw_alloc_data *memory = ZALLOC (struct hw_alloc_data); | |
55 | memory->alloc = zalloc (size); | |
c906108c SS |
56 | memory->next = me->alloc_of_hw; |
57 | me->alloc_of_hw = memory; | |
58 | return memory->alloc; | |
59 | } | |
60 | ||
61 | void * | |
62 | hw_malloc (struct hw *me, unsigned long size) | |
63 | { | |
64 | struct hw_alloc_data *memory = ZALLOC (struct hw_alloc_data); | |
65 | memory->alloc = zalloc (size); | |
c906108c SS |
66 | memory->next = me->alloc_of_hw; |
67 | me->alloc_of_hw = memory; | |
68 | return memory->alloc; | |
69 | } | |
70 | ||
71 | void | |
72 | hw_free (struct hw *me, | |
73 | void *alloc) | |
74 | { | |
75 | struct hw_alloc_data **memory; | |
76 | for (memory = &me->alloc_of_hw; | |
77 | *memory != NULL; | |
78 | memory = &(*memory)->next) | |
79 | { | |
80 | if ((*memory)->alloc == alloc) | |
81 | { | |
82 | struct hw_alloc_data *die = (*memory); | |
83 | (*memory) = die->next; | |
d79fe0d6 MF |
84 | free (die->alloc); |
85 | free (die); | |
c906108c SS |
86 | return; |
87 | } | |
88 | } | |
89 | hw_abort (me, "free of memory not belonging to a device"); | |
90 | } |