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.
5 This file is part of GDB.
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.
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.
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. */
23 #if defined (HAVE_MMAP)
25 /* Redefine the external visible symbols in gmalloc.c to be mmap versions */
27 #define free _mmap_free
28 #define malloc _mmap_malloc
29 #define realloc _mmap_realloc
30 #define valloc _mmap_valloc
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
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
50 /* Arrange that instead of calling sbrk() we call mmap_sbrk() */
52 #define sbrk mmap_sbrk
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. */
60 /* Like mmap_malloc but get error if no storage available. */
66 register char *val = NULL;
68 /* Protect against gdb wanting to allocate zero bytes. */
72 if ((val = (char *) _mmap_malloc (size)) == NULL)
74 fatal ("virtual memory exhausted.", 0);
80 /* Like mmap_realloc but get error if no storage available. */
83 mmap_xrealloc (ptr, size)
89 if ((val = (char *) _mmap_realloc (ptr, size)) == NULL)
91 fatal ("virtual memory exhausted.", 0);
100 return (_mmap_malloc (size));
104 mmap_realloc (ptr, size)
108 return (_mmap_realloc (ptr, size));
118 #else /* !defined (HAVE_MMAP) */
120 static char *errmsg = "This version of gdb does not support dumpable state.";
137 mmap_realloc (ptr, size)
145 mmap_xrealloc (ptr, size)
159 #endif /* HAVE_MMAP */