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