| 1 | /* GDB support for special malloc using mmap. |
| 2 | Copyright 1992 Free Software Foundation, Inc. |
| 3 | Contributed by Cygnus Support, using pieces from other GDB modules. |
| 4 | |
| 5 | This file is part of GDB. |
| 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 of the License, or |
| 10 | (at your option) 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 |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 20 | |
| 21 | #include "defs.h" |
| 22 | |
| 23 | #if defined (HAVE_MMAP) |
| 24 | |
| 25 | /* Redefine the external visible symbols in gmalloc.c to be mmap versions */ |
| 26 | |
| 27 | #define free _mmap_free |
| 28 | #define malloc _mmap_malloc |
| 29 | #define realloc _mmap_realloc |
| 30 | #define valloc _mmap_valloc |
| 31 | |
| 32 | #define _bytes_free _mmap__bytes_free |
| 33 | #define _bytes_used _mmap__bytes_used |
| 34 | #define _chunks_free _mmap__chunks_free |
| 35 | #define _chunks_used _mmap__chunks_used |
| 36 | #define _fraghead _mmap__fraghead |
| 37 | #define _heapbase _mmap__heapbase |
| 38 | #define _heapindex _mmap__heapindex |
| 39 | #define _heapinfo _mmap__heapinfo |
| 40 | #define _heaplimit _mmap__heaplimit |
| 41 | |
| 42 | #define __default_morecore _mmap___default_morecore |
| 43 | #define __free _mmap___free |
| 44 | #define __free_hook _mmap___free_hook |
| 45 | #define __malloc_hook _mmap___malloc_hook |
| 46 | #define __malloc_initialized _mmap___malloc_initialized |
| 47 | #define __morecore _mmap___morecore |
| 48 | #define __realloc_hook _mmap___realloc_hook |
| 49 | |
| 50 | /* Arrange that instead of calling sbrk() we call mmap_sbrk() */ |
| 51 | |
| 52 | #define sbrk mmap_sbrk |
| 53 | |
| 54 | /* Now simply include the standard GNU malloc source, and all the |
| 55 | externally visible symbols will become _mmap_* versions, and |
| 56 | _mmap_sbrk will be called to get more core instead of sbrk. */ |
| 57 | |
| 58 | #include "gmalloc.c" |
| 59 | |
| 60 | /* Like mmap_malloc but get error if no storage available. */ |
| 61 | |
| 62 | PTR |
| 63 | mmap_xmalloc (size) |
| 64 | long size; |
| 65 | { |
| 66 | register char *val = NULL; |
| 67 | |
| 68 | /* Protect against gdb wanting to allocate zero bytes. */ |
| 69 | |
| 70 | if (size > 0) |
| 71 | { |
| 72 | if ((val = (char *) _mmap_malloc (size)) == NULL) |
| 73 | { |
| 74 | fatal ("virtual memory exhausted.", 0); |
| 75 | } |
| 76 | } |
| 77 | return (val); |
| 78 | } |
| 79 | |
| 80 | /* Like mmap_realloc but get error if no storage available. */ |
| 81 | |
| 82 | PTR |
| 83 | mmap_xrealloc (ptr, size) |
| 84 | PTR ptr; |
| 85 | long size; |
| 86 | { |
| 87 | register char *val; |
| 88 | |
| 89 | if ((val = (char *) _mmap_realloc (ptr, size)) == NULL) |
| 90 | { |
| 91 | fatal ("virtual memory exhausted.", 0); |
| 92 | } |
| 93 | return (val); |
| 94 | } |
| 95 | |
| 96 | PTR |
| 97 | mmap_malloc (size) |
| 98 | long size; |
| 99 | { |
| 100 | return (_mmap_malloc (size)); |
| 101 | } |
| 102 | |
| 103 | PTR |
| 104 | mmap_realloc (ptr, size) |
| 105 | PTR ptr; |
| 106 | long size; |
| 107 | { |
| 108 | return (_mmap_realloc (ptr, size)); |
| 109 | } |
| 110 | |
| 111 | void |
| 112 | mmap_free (ptr) |
| 113 | PTR ptr; |
| 114 | { |
| 115 | _mmap_free (ptr); |
| 116 | } |
| 117 | |
| 118 | #else /* !defined (HAVE_MMAP) */ |
| 119 | |
| 120 | static char *errmsg = "This version of gdb does not support dumpable state."; |
| 121 | |
| 122 | PTR |
| 123 | mmap_malloc (size) |
| 124 | long size; |
| 125 | { |
| 126 | error (errmsg); |
| 127 | } |
| 128 | |
| 129 | PTR |
| 130 | mmap_xmalloc (size) |
| 131 | long size; |
| 132 | { |
| 133 | error (errmsg); |
| 134 | } |
| 135 | |
| 136 | PTR |
| 137 | mmap_realloc (ptr, size) |
| 138 | PTR ptr; |
| 139 | long size; |
| 140 | { |
| 141 | error (errmsg); |
| 142 | } |
| 143 | |
| 144 | PTR |
| 145 | mmap_xrealloc (ptr, size) |
| 146 | PTR ptr; |
| 147 | long size; |
| 148 | { |
| 149 | error (errmsg); |
| 150 | } |
| 151 | |
| 152 | void |
| 153 | mmap_free (ptr) |
| 154 | PTR ptr; |
| 155 | { |
| 156 | error (errmsg); |
| 157 | } |
| 158 | |
| 159 | #endif /* HAVE_MMAP */ |