1 /* Hardware memory allocator.
2 Copyright (C) 1998, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
4 Contributed by Cygnus Support.
6 This file is part of GDB, the GNU debugger.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
30 struct hw_alloc_data {
33 struct hw_alloc_data *next;
37 create_hw_alloc_data (struct hw *me)
43 delete_hw_alloc_data (struct hw *me)
45 while (me->alloc_of_hw != NULL)
47 hw_free (me, me->alloc_of_hw->alloc);
54 hw_zalloc (struct hw *me, unsigned long size)
56 struct hw_alloc_data *memory = ZALLOC (struct hw_alloc_data);
57 memory->alloc = zalloc (size);
59 memory->next = me->alloc_of_hw;
60 me->alloc_of_hw = memory;
65 hw_malloc (struct hw *me, unsigned long size)
67 struct hw_alloc_data *memory = ZALLOC (struct hw_alloc_data);
68 memory->alloc = zalloc (size);
70 memory->next = me->alloc_of_hw;
71 me->alloc_of_hw = memory;
76 hw_free (struct hw *me,
79 struct hw_alloc_data **memory;
80 for (memory = &me->alloc_of_hw;
82 memory = &(*memory)->next)
84 if ((*memory)->alloc == alloc)
86 struct hw_alloc_data *die = (*memory);
87 (*memory) = die->next;
96 hw_abort (me, "free of memory not belonging to a device");