Mercurial > emacs
annotate src/gmalloc.c @ 78437:77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
[USE_PTHREAD] (LOCK, UNLOCK, LOCK_ALIGNED_BLOCKS)
(UNLOCK_ALIGNED_BLOCKS): Conditionalize with it.
(malloc_atfork_handler_prepare, malloc_atfork_handler_parent)
(malloc_atfork_handler_child, malloc_enable_thread) [USE_PTHREAD]:
New functions.
| author | YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> |
|---|---|
| date | Tue, 07 Aug 2007 08:57:24 +0000 |
| parents | 2c30fdff6890 |
| children | c4c2bb082d62 |
| rev | line source |
|---|---|
| 17130 | 1 /* This file is no longer automatically generated from libc. */ |
| 2 | |
| 3 #define _MALLOC_INTERNAL | |
| 4 | |
| 5 /* The malloc headers and source files from the C library follow here. */ | |
| 6 | |
| 7 /* Declarations for `malloc' and friends. | |
|
64770
a0d1312ede66
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64092
diff
changeset
|
8 Copyright (C) 1990, 1991, 1992, 1993, 1995, 1996, 1999, 2002, 2003, 2004, |
| 75348 | 9 2005, 2006, 2007 Free Software Foundation, Inc. |
| 17130 | 10 Written May 1989 by Mike Haertel. |
| 11 | |
| 12 This library is free software; you can redistribute it and/or | |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
13 modify it under the terms of the GNU General Public License as |
| 17130 | 14 published by the Free Software Foundation; either version 2 of the |
| 15 License, or (at your option) any later version. | |
| 16 | |
| 17 This library is distributed in the hope that it will be useful, | |
| 18 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
20 General Public License for more details. |
| 17130 | 21 |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
22 You should have received a copy of the GNU General Public |
|
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
23 License along with this library; see the file COPYING. If |
| 64092 | 24 not, write to the Free Software Foundation, Inc., 51 Franklin Street, |
| 25 Fifth Floor, Boston, MA 02110-1301, USA. | |
| 17130 | 26 |
| 27 The author may be reached (Email) at the address mike@ai.mit.edu, | |
| 28 or (US mail) as Mike Haertel c/o Free Software Foundation. */ | |
| 29 | |
| 30 #ifndef _MALLOC_H | |
| 31 | |
| 32 #define _MALLOC_H 1 | |
| 33 | |
| 34 #ifdef _MALLOC_INTERNAL | |
| 35 | |
| 36 #ifdef HAVE_CONFIG_H | |
| 37 #include <config.h> | |
| 38 #endif | |
| 39 | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
40 #ifdef HAVE_GTK_AND_PTHREAD |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
41 #define USE_PTHREAD |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
42 #endif |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
43 |
|
40670
8cb4d744ae0d
Test BROKEN_PROTOTYPES.
Richard M. Stallman <rms@gnu.org>
parents:
37372
diff
changeset
|
44 #if ((defined __cplusplus || (defined (__STDC__) && __STDC__) \ |
|
8cb4d744ae0d
Test BROKEN_PROTOTYPES.
Richard M. Stallman <rms@gnu.org>
parents:
37372
diff
changeset
|
45 || defined STDC_HEADERS || defined PROTOTYPES) \ |
|
8cb4d744ae0d
Test BROKEN_PROTOTYPES.
Richard M. Stallman <rms@gnu.org>
parents:
37372
diff
changeset
|
46 && ! defined (BROKEN_PROTOTYPES)) |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
47 #undef PP |
|
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
48 #define PP(args) args |
| 17130 | 49 #undef __ptr_t |
| 50 #define __ptr_t void * | |
| 51 #else /* Not C++ or ANSI C. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
52 #undef PP |
|
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
53 #define PP(args) () |
| 17130 | 54 #undef __ptr_t |
| 55 #define __ptr_t char * | |
| 56 #endif /* C++ or ANSI C. */ | |
| 57 | |
| 58 #if defined(_LIBC) || defined(STDC_HEADERS) || defined(USG) | |
| 59 #include <string.h> | |
| 60 #else | |
| 61 #ifndef memset | |
| 62 #define memset(s, zero, n) bzero ((s), (n)) | |
| 63 #endif | |
| 64 #ifndef memcpy | |
| 65 #define memcpy(d, s, n) bcopy ((s), (d), (n)) | |
| 66 #endif | |
| 67 #endif | |
| 68 | |
|
26526
b7438760079b
* callproc.c (strerror): Remove decl.
Paul Eggert <eggert@twinsun.com>
parents:
26088
diff
changeset
|
69 #ifdef HAVE_LIMITS_H |
| 17130 | 70 #include <limits.h> |
|
26526
b7438760079b
* callproc.c (strerror): Remove decl.
Paul Eggert <eggert@twinsun.com>
parents:
26088
diff
changeset
|
71 #endif |
| 17130 | 72 #ifndef CHAR_BIT |
| 73 #define CHAR_BIT 8 | |
| 74 #endif | |
| 75 | |
| 76 #ifdef HAVE_UNISTD_H | |
| 77 #include <unistd.h> | |
| 78 #endif | |
| 79 | |
|
76776
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
80 #ifdef USE_PTHREAD |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
81 #include <pthread.h> |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
82 #endif |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
83 |
| 17130 | 84 #endif /* _MALLOC_INTERNAL. */ |
| 85 | |
| 86 | |
| 87 #ifdef __cplusplus | |
| 88 extern "C" | |
| 89 { | |
| 90 #endif | |
| 91 | |
|
26526
b7438760079b
* callproc.c (strerror): Remove decl.
Paul Eggert <eggert@twinsun.com>
parents:
26088
diff
changeset
|
92 #ifdef STDC_HEADERS |
| 17130 | 93 #include <stddef.h> |
| 94 #define __malloc_size_t size_t | |
| 95 #define __malloc_ptrdiff_t ptrdiff_t | |
| 96 #else | |
|
37372
46942d9e7537
(__malloc_size_t) [__GNUC__]: If STDC_HEADERS is not
Eli Zaretskii <eliz@gnu.org>
parents:
37268
diff
changeset
|
97 #ifdef __GNUC__ |
|
46942d9e7537
(__malloc_size_t) [__GNUC__]: If STDC_HEADERS is not
Eli Zaretskii <eliz@gnu.org>
parents:
37268
diff
changeset
|
98 #include <stddef.h> |
|
46942d9e7537
(__malloc_size_t) [__GNUC__]: If STDC_HEADERS is not
Eli Zaretskii <eliz@gnu.org>
parents:
37268
diff
changeset
|
99 #ifdef __SIZE_TYPE__ |
|
46942d9e7537
(__malloc_size_t) [__GNUC__]: If STDC_HEADERS is not
Eli Zaretskii <eliz@gnu.org>
parents:
37268
diff
changeset
|
100 #define __malloc_size_t __SIZE_TYPE__ |
|
46942d9e7537
(__malloc_size_t) [__GNUC__]: If STDC_HEADERS is not
Eli Zaretskii <eliz@gnu.org>
parents:
37268
diff
changeset
|
101 #endif |
|
46942d9e7537
(__malloc_size_t) [__GNUC__]: If STDC_HEADERS is not
Eli Zaretskii <eliz@gnu.org>
parents:
37268
diff
changeset
|
102 #endif |
|
46942d9e7537
(__malloc_size_t) [__GNUC__]: If STDC_HEADERS is not
Eli Zaretskii <eliz@gnu.org>
parents:
37268
diff
changeset
|
103 #ifndef __malloc_size_t |
| 17130 | 104 #define __malloc_size_t unsigned int |
|
37372
46942d9e7537
(__malloc_size_t) [__GNUC__]: If STDC_HEADERS is not
Eli Zaretskii <eliz@gnu.org>
parents:
37268
diff
changeset
|
105 #endif |
| 17130 | 106 #define __malloc_ptrdiff_t int |
| 107 #endif | |
| 108 | |
| 109 #ifndef NULL | |
| 110 #define NULL 0 | |
| 111 #endif | |
| 112 | |
|
26526
b7438760079b
* callproc.c (strerror): Remove decl.
Paul Eggert <eggert@twinsun.com>
parents:
26088
diff
changeset
|
113 #ifndef FREE_RETURN_TYPE |
|
b7438760079b
* callproc.c (strerror): Remove decl.
Paul Eggert <eggert@twinsun.com>
parents:
26088
diff
changeset
|
114 #define FREE_RETURN_TYPE void |
|
b7438760079b
* callproc.c (strerror): Remove decl.
Paul Eggert <eggert@twinsun.com>
parents:
26088
diff
changeset
|
115 #endif |
|
b7438760079b
* callproc.c (strerror): Remove decl.
Paul Eggert <eggert@twinsun.com>
parents:
26088
diff
changeset
|
116 |
| 17130 | 117 |
| 118 /* Allocate SIZE bytes of memory. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
119 extern __ptr_t malloc PP ((__malloc_size_t __size)); |
| 17130 | 120 /* Re-allocate the previously allocated block |
| 121 in __ptr_t, making the new block SIZE bytes long. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
122 extern __ptr_t realloc PP ((__ptr_t __ptr, __malloc_size_t __size)); |
| 17130 | 123 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */ |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
124 extern __ptr_t calloc PP ((__malloc_size_t __nmemb, __malloc_size_t __size)); |
| 17130 | 125 /* Free a block allocated by `malloc', `realloc' or `calloc'. */ |
|
26526
b7438760079b
* callproc.c (strerror): Remove decl.
Paul Eggert <eggert@twinsun.com>
parents:
26088
diff
changeset
|
126 extern FREE_RETURN_TYPE free PP ((__ptr_t __ptr)); |
| 17130 | 127 |
| 128 /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */ | |
| 129 #if ! (defined (_MALLOC_INTERNAL) && __DJGPP__ - 0 == 1) /* Avoid conflict. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
130 extern __ptr_t memalign PP ((__malloc_size_t __alignment, |
|
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
131 __malloc_size_t __size)); |
| 17130 | 132 #endif |
| 133 | |
| 134 /* Allocate SIZE bytes on a page boundary. */ | |
| 135 #if ! (defined (_MALLOC_INTERNAL) && defined (GMALLOC_INHIBIT_VALLOC)) | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
136 extern __ptr_t valloc PP ((__malloc_size_t __size)); |
| 17130 | 137 #endif |
| 138 | |
|
78437
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
139 #ifdef USE_PTHREAD |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
140 /* Set up mutexes and make malloc etc. thread-safe. */ |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
141 extern void malloc_enable_thread PP ((void)); |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
142 #endif |
| 17130 | 143 |
| 144 #ifdef _MALLOC_INTERNAL | |
| 145 | |
| 146 /* The allocator divides the heap into blocks of fixed size; large | |
| 147 requests receive one or more whole blocks, and small requests | |
| 148 receive a fragment of a block. Fragment sizes are powers of two, | |
| 149 and all fragments of a block are the same size. When all the | |
| 150 fragments in a block have been freed, the block itself is freed. */ | |
| 151 #define INT_BIT (CHAR_BIT * sizeof(int)) | |
| 152 #define BLOCKLOG (INT_BIT > 16 ? 12 : 9) | |
| 153 #define BLOCKSIZE (1 << BLOCKLOG) | |
| 154 #define BLOCKIFY(SIZE) (((SIZE) + BLOCKSIZE - 1) / BLOCKSIZE) | |
| 155 | |
| 156 /* Determine the amount of memory spanned by the initial heap table | |
| 157 (not an absolute limit). */ | |
| 158 #define HEAP (INT_BIT > 16 ? 4194304 : 65536) | |
| 159 | |
| 160 /* Number of contiguous free blocks allowed to build up at the end of | |
| 161 memory before they will be returned to the system. */ | |
| 162 #define FINAL_FREE_BLOCKS 8 | |
| 163 | |
| 164 /* Data structure giving per-block information. */ | |
| 165 typedef union | |
| 166 { | |
| 167 /* Heap information for a busy block. */ | |
| 168 struct | |
| 169 { | |
| 170 /* Zero for a large (multiblock) object, or positive giving the | |
| 171 logarithm to the base two of the fragment size. */ | |
| 172 int type; | |
| 173 union | |
| 174 { | |
| 175 struct | |
| 176 { | |
| 177 __malloc_size_t nfree; /* Free frags in a fragmented block. */ | |
| 178 __malloc_size_t first; /* First free fragment of the block. */ | |
| 179 } frag; | |
| 180 /* For a large object, in its first block, this has the number | |
| 181 of blocks in the object. In the other blocks, this has a | |
| 182 negative number which says how far back the first block is. */ | |
| 183 __malloc_ptrdiff_t size; | |
| 184 } info; | |
| 185 } busy; | |
| 186 /* Heap information for a free block | |
| 187 (that may be the first of a free cluster). */ | |
| 188 struct | |
| 189 { | |
| 190 __malloc_size_t size; /* Size (in blocks) of a free cluster. */ | |
| 191 __malloc_size_t next; /* Index of next free cluster. */ | |
| 192 __malloc_size_t prev; /* Index of previous free cluster. */ | |
| 193 } free; | |
| 194 } malloc_info; | |
| 195 | |
| 196 /* Pointer to first block of the heap. */ | |
| 197 extern char *_heapbase; | |
| 198 | |
| 199 /* Table indexed by block number giving per-block information. */ | |
| 200 extern malloc_info *_heapinfo; | |
| 201 | |
| 202 /* Address to block number and vice versa. */ | |
| 203 #define BLOCK(A) (((char *) (A) - _heapbase) / BLOCKSIZE + 1) | |
| 204 #define ADDRESS(B) ((__ptr_t) (((B) - 1) * BLOCKSIZE + _heapbase)) | |
| 205 | |
| 206 /* Current search index for the heap table. */ | |
| 207 extern __malloc_size_t _heapindex; | |
| 208 | |
| 209 /* Limit of valid info table indices. */ | |
| 210 extern __malloc_size_t _heaplimit; | |
| 211 | |
| 212 /* Doubly linked lists of free fragments. */ | |
| 213 struct list | |
| 214 { | |
| 215 struct list *next; | |
| 216 struct list *prev; | |
| 217 }; | |
| 218 | |
| 219 /* Free list headers for each fragment size. */ | |
| 220 extern struct list _fraghead[]; | |
| 221 | |
| 222 /* List of blocks allocated with `memalign' (or `valloc'). */ | |
| 223 struct alignlist | |
| 224 { | |
| 225 struct alignlist *next; | |
| 226 __ptr_t aligned; /* The address that memaligned returned. */ | |
| 227 __ptr_t exact; /* The address that malloc returned. */ | |
| 228 }; | |
| 229 extern struct alignlist *_aligned_blocks; | |
| 230 | |
| 231 /* Instrumentation. */ | |
| 232 extern __malloc_size_t _chunks_used; | |
| 233 extern __malloc_size_t _bytes_used; | |
| 234 extern __malloc_size_t _chunks_free; | |
| 235 extern __malloc_size_t _bytes_free; | |
| 236 | |
| 237 /* Internal versions of `malloc', `realloc', and `free' | |
| 238 used when these functions need to call each other. | |
| 239 They are the same but don't call the hooks. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
240 extern __ptr_t _malloc_internal PP ((__malloc_size_t __size)); |
|
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
241 extern __ptr_t _realloc_internal PP ((__ptr_t __ptr, __malloc_size_t __size)); |
|
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
242 extern void _free_internal PP ((__ptr_t __ptr)); |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
243 extern __ptr_t _malloc_internal_nolock PP ((__malloc_size_t __size)); |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
244 extern __ptr_t _realloc_internal_nolock PP ((__ptr_t __ptr, __malloc_size_t __size)); |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
245 extern void _free_internal_nolock PP ((__ptr_t __ptr)); |
| 17130 | 246 |
|
76776
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
247 #ifdef USE_PTHREAD |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
248 extern pthread_mutex_t _malloc_mutex, _aligned_blocks_mutex; |
|
78437
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
249 extern int _malloc_thread_enabled_p; |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
250 #define LOCK() \ |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
251 do { \ |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
252 if (_malloc_thread_enabled_p) \ |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
253 pthread_mutex_lock (&_malloc_mutex); \ |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
254 } while (0) |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
255 #define UNLOCK() \ |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
256 do { \ |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
257 if (_malloc_thread_enabled_p) \ |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
258 pthread_mutex_unlock (&_malloc_mutex); \ |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
259 } while (0) |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
260 #define LOCK_ALIGNED_BLOCKS() \ |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
261 do { \ |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
262 if (_malloc_thread_enabled_p) \ |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
263 pthread_mutex_lock (&_aligned_blocks_mutex); \ |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
264 } while (0) |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
265 #define UNLOCK_ALIGNED_BLOCKS() \ |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
266 do { \ |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
267 if (_malloc_thread_enabled_p) \ |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
268 pthread_mutex_unlock (&_aligned_blocks_mutex); \ |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
269 } while (0) |
|
76776
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
270 #else |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
271 #define LOCK() |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
272 #define UNLOCK() |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
273 #define LOCK_ALIGNED_BLOCKS() |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
274 #define UNLOCK_ALIGNED_BLOCKS() |
|
76776
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
275 #endif |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
276 |
| 17130 | 277 #endif /* _MALLOC_INTERNAL. */ |
| 278 | |
| 279 /* Given an address in the middle of a malloc'd object, | |
| 280 return the address of the beginning of the object. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
281 extern __ptr_t malloc_find_object_address PP ((__ptr_t __ptr)); |
| 17130 | 282 |
| 283 /* Underlying allocation function; successive calls should | |
| 284 return contiguous pieces of memory. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
285 extern __ptr_t (*__morecore) PP ((__malloc_ptrdiff_t __size)); |
| 17130 | 286 |
| 287 /* Default value of `__morecore'. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
288 extern __ptr_t __default_morecore PP ((__malloc_ptrdiff_t __size)); |
| 17130 | 289 |
| 290 /* If not NULL, this function is called after each time | |
| 291 `__morecore' is called to increase the data size. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
292 extern void (*__after_morecore_hook) PP ((void)); |
| 17130 | 293 |
| 294 /* Number of extra blocks to get each time we ask for more core. | |
| 295 This reduces the frequency of calling `(*__morecore)'. */ | |
| 296 extern __malloc_size_t __malloc_extra_blocks; | |
| 297 | |
| 298 /* Nonzero if `malloc' has been called and done its initialization. */ | |
| 299 extern int __malloc_initialized; | |
| 300 /* Function called to initialize malloc data structures. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
301 extern int __malloc_initialize PP ((void)); |
| 17130 | 302 |
| 303 /* Hooks for debugging versions. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
304 extern void (*__malloc_initialize_hook) PP ((void)); |
|
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
305 extern void (*__free_hook) PP ((__ptr_t __ptr)); |
|
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
306 extern __ptr_t (*__malloc_hook) PP ((__malloc_size_t __size)); |
|
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
307 extern __ptr_t (*__realloc_hook) PP ((__ptr_t __ptr, __malloc_size_t __size)); |
|
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
308 extern __ptr_t (*__memalign_hook) PP ((__malloc_size_t __size, |
|
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
309 __malloc_size_t __alignment)); |
| 17130 | 310 |
| 311 /* Return values for `mprobe': these are the kinds of inconsistencies that | |
| 312 `mcheck' enables detection of. */ | |
| 313 enum mcheck_status | |
| 314 { | |
| 315 MCHECK_DISABLED = -1, /* Consistency checking is not turned on. */ | |
| 316 MCHECK_OK, /* Block is fine. */ | |
| 317 MCHECK_FREE, /* Block freed twice. */ | |
| 318 MCHECK_HEAD, /* Memory before the block was clobbered. */ | |
| 319 MCHECK_TAIL /* Memory after the block was clobbered. */ | |
| 320 }; | |
| 321 | |
| 322 /* Activate a standard collection of debugging hooks. This must be called | |
| 323 before `malloc' is ever called. ABORTFUNC is called with an error code | |
| 324 (see enum above) when an inconsistency is detected. If ABORTFUNC is | |
| 325 null, the standard function prints on stderr and then calls `abort'. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
326 extern int mcheck PP ((void (*__abortfunc) PP ((enum mcheck_status)))); |
| 17130 | 327 |
| 328 /* Check for aberrations in a particular malloc'd block. You must have | |
| 329 called `mcheck' already. These are the same checks that `mcheck' does | |
| 330 when you free or reallocate a block. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
331 extern enum mcheck_status mprobe PP ((__ptr_t __ptr)); |
| 17130 | 332 |
| 333 /* Activate a standard collection of tracing hooks. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
334 extern void mtrace PP ((void)); |
|
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
335 extern void muntrace PP ((void)); |
| 17130 | 336 |
| 337 /* Statistics available to the user. */ | |
| 338 struct mstats | |
| 339 { | |
| 340 __malloc_size_t bytes_total; /* Total size of the heap. */ | |
| 341 __malloc_size_t chunks_used; /* Chunks allocated by the user. */ | |
| 342 __malloc_size_t bytes_used; /* Byte total of user-allocated chunks. */ | |
| 343 __malloc_size_t chunks_free; /* Chunks in the free list. */ | |
| 344 __malloc_size_t bytes_free; /* Byte total of chunks in the free list. */ | |
| 345 }; | |
| 346 | |
| 347 /* Pick up the current statistics. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
348 extern struct mstats mstats PP ((void)); |
| 17130 | 349 |
| 350 /* Call WARNFUN with a warning message when memory usage is high. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
351 extern void memory_warnings PP ((__ptr_t __start, |
|
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
352 void (*__warnfun) PP ((const char *)))); |
| 17130 | 353 |
| 354 | |
| 355 /* Relocating allocator. */ | |
| 356 | |
| 357 /* Allocate SIZE bytes, and store the address in *HANDLEPTR. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
358 extern __ptr_t r_alloc PP ((__ptr_t *__handleptr, __malloc_size_t __size)); |
| 17130 | 359 |
| 360 /* Free the storage allocated in HANDLEPTR. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
361 extern void r_alloc_free PP ((__ptr_t *__handleptr)); |
| 17130 | 362 |
| 363 /* Adjust the block at HANDLEPTR to be SIZE bytes long. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
364 extern __ptr_t r_re_alloc PP ((__ptr_t *__handleptr, __malloc_size_t __size)); |
| 17130 | 365 |
| 366 | |
| 367 #ifdef __cplusplus | |
| 368 } | |
| 369 #endif | |
| 370 | |
| 371 #endif /* malloc.h */ | |
| 372 /* Memory allocator `malloc'. | |
| 373 Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. | |
| 374 Written May 1989 by Mike Haertel. | |
| 375 | |
| 376 This library is free software; you can redistribute it and/or | |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
377 modify it under the terms of the GNU General Public License as |
| 17130 | 378 published by the Free Software Foundation; either version 2 of the |
| 379 License, or (at your option) any later version. | |
| 380 | |
| 381 This library is distributed in the hope that it will be useful, | |
| 382 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 383 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
384 General Public License for more details. |
| 17130 | 385 |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
386 You should have received a copy of the GNU General Public |
|
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
387 License along with this library; see the file COPYING. If |
| 64092 | 388 not, write to the Free Software Foundation, Inc., 51 Franklin Street, |
| 389 Fifth Floor, Boston, MA 02110-1301, USA. | |
| 17130 | 390 |
| 391 The author may be reached (Email) at the address mike@ai.mit.edu, | |
| 392 or (US mail) as Mike Haertel c/o Free Software Foundation. */ | |
| 393 | |
| 394 #ifndef _MALLOC_INTERNAL | |
| 395 #define _MALLOC_INTERNAL | |
| 396 #include <malloc.h> | |
| 397 #endif | |
| 398 #include <errno.h> | |
| 399 | |
| 400 /* How to really get more memory. */ | |
|
54824
54395b0b6779
(__default_morecore): Use bss_sbrk(), not __sbrk(), before Cygwin unexec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
401 #if defined(CYGWIN) |
|
54395b0b6779
(__default_morecore): Use bss_sbrk(), not __sbrk(), before Cygwin unexec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
402 extern __ptr_t bss_sbrk PP ((ptrdiff_t __size)); |
|
54395b0b6779
(__default_morecore): Use bss_sbrk(), not __sbrk(), before Cygwin unexec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
403 extern int bss_sbrk_did_unexec; |
|
54395b0b6779
(__default_morecore): Use bss_sbrk(), not __sbrk(), before Cygwin unexec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
404 #endif |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
405 __ptr_t (*__morecore) PP ((ptrdiff_t __size)) = __default_morecore; |
| 17130 | 406 |
| 407 /* Debugging hook for `malloc'. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
408 __ptr_t (*__malloc_hook) PP ((__malloc_size_t __size)); |
| 17130 | 409 |
| 410 /* Pointer to the base of the first block. */ | |
| 411 char *_heapbase; | |
| 412 | |
| 413 /* Block information table. Allocated with align/__free (not malloc/free). */ | |
| 414 malloc_info *_heapinfo; | |
| 415 | |
| 416 /* Number of info entries. */ | |
| 417 static __malloc_size_t heapsize; | |
| 418 | |
| 419 /* Search index in the info table. */ | |
| 420 __malloc_size_t _heapindex; | |
| 421 | |
| 422 /* Limit of valid info table indices. */ | |
| 423 __malloc_size_t _heaplimit; | |
| 424 | |
| 425 /* Free lists for each fragment size. */ | |
| 426 struct list _fraghead[BLOCKLOG]; | |
| 427 | |
| 428 /* Instrumentation. */ | |
| 429 __malloc_size_t _chunks_used; | |
| 430 __malloc_size_t _bytes_used; | |
| 431 __malloc_size_t _chunks_free; | |
| 432 __malloc_size_t _bytes_free; | |
| 433 | |
| 434 /* Are you experienced? */ | |
| 435 int __malloc_initialized; | |
| 436 | |
| 437 __malloc_size_t __malloc_extra_blocks; | |
| 438 | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
439 void (*__malloc_initialize_hook) PP ((void)); |
|
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
440 void (*__after_morecore_hook) PP ((void)); |
| 17130 | 441 |
|
32821
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
442 #if defined GC_MALLOC_CHECK && defined GC_PROTECT_MALLOC_STATE |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
443 |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
444 /* Some code for hunting a bug writing into _heapinfo. |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
445 |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
446 Call this macro with argument PROT non-zero to protect internal |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
447 malloc state against writing to it, call it with a zero argument to |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
448 make it readable and writable. |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
449 |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
450 Note that this only works if BLOCKSIZE == page size, which is |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
451 the case on the i386. */ |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
452 |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
453 #include <sys/types.h> |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
454 #include <sys/mman.h> |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
455 |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
456 static int state_protected_p; |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
457 static __malloc_size_t last_state_size; |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
458 static malloc_info *last_heapinfo; |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
459 |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
460 void |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
461 protect_malloc_state (protect_p) |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
462 int protect_p; |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
463 { |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
464 /* If _heapinfo has been relocated, make sure its old location |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
465 isn't left read-only; it will be reused by malloc. */ |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
466 if (_heapinfo != last_heapinfo |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
467 && last_heapinfo |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
468 && state_protected_p) |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
469 mprotect (last_heapinfo, last_state_size, PROT_READ | PROT_WRITE); |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
470 |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
471 last_state_size = _heaplimit * sizeof *_heapinfo; |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
472 last_heapinfo = _heapinfo; |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
40670
diff
changeset
|
473 |
|
32821
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
474 if (protect_p != state_protected_p) |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
475 { |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
476 state_protected_p = protect_p; |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
477 if (mprotect (_heapinfo, last_state_size, |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
478 protect_p ? PROT_READ : PROT_READ | PROT_WRITE) != 0) |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
479 abort (); |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
480 } |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
481 } |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
482 |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
483 #define PROTECT_MALLOC_STATE(PROT) protect_malloc_state(PROT) |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
484 |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
485 #else |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
486 #define PROTECT_MALLOC_STATE(PROT) /* empty */ |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
487 #endif |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
488 |
| 17130 | 489 |
| 490 /* Aligned allocation. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
491 static __ptr_t align PP ((__malloc_size_t)); |
| 17130 | 492 static __ptr_t |
| 493 align (size) | |
| 494 __malloc_size_t size; | |
| 495 { | |
| 496 __ptr_t result; | |
| 497 unsigned long int adj; | |
| 498 | |
|
37268
0f5de719ab07
(align): If the argument SIZE would overflow
Eli Zaretskii <eliz@gnu.org>
parents:
32973
diff
changeset
|
499 /* align accepts an unsigned argument, but __morecore accepts a |
|
0f5de719ab07
(align): If the argument SIZE would overflow
Eli Zaretskii <eliz@gnu.org>
parents:
32973
diff
changeset
|
500 signed one. This could lead to trouble if SIZE overflows a |
|
0f5de719ab07
(align): If the argument SIZE would overflow
Eli Zaretskii <eliz@gnu.org>
parents:
32973
diff
changeset
|
501 signed int type accepted by __morecore. We just punt in that |
|
0f5de719ab07
(align): If the argument SIZE would overflow
Eli Zaretskii <eliz@gnu.org>
parents:
32973
diff
changeset
|
502 case, since they are requesting a ludicrous amount anyway. */ |
|
0f5de719ab07
(align): If the argument SIZE would overflow
Eli Zaretskii <eliz@gnu.org>
parents:
32973
diff
changeset
|
503 if ((__malloc_ptrdiff_t)size < 0) |
|
0f5de719ab07
(align): If the argument SIZE would overflow
Eli Zaretskii <eliz@gnu.org>
parents:
32973
diff
changeset
|
504 result = 0; |
|
0f5de719ab07
(align): If the argument SIZE would overflow
Eli Zaretskii <eliz@gnu.org>
parents:
32973
diff
changeset
|
505 else |
|
0f5de719ab07
(align): If the argument SIZE would overflow
Eli Zaretskii <eliz@gnu.org>
parents:
32973
diff
changeset
|
506 result = (*__morecore) (size); |
| 17130 | 507 adj = (unsigned long int) ((unsigned long int) ((char *) result - |
| 508 (char *) NULL)) % BLOCKSIZE; | |
| 509 if (adj != 0) | |
| 510 { | |
| 511 __ptr_t new; | |
| 512 adj = BLOCKSIZE - adj; | |
| 513 new = (*__morecore) (adj); | |
| 514 result = (char *) result + adj; | |
| 515 } | |
| 516 | |
| 517 if (__after_morecore_hook) | |
| 518 (*__after_morecore_hook) (); | |
| 519 | |
| 520 return result; | |
| 521 } | |
| 522 | |
| 523 /* Get SIZE bytes, if we can get them starting at END. | |
| 524 Return the address of the space we got. | |
| 525 If we cannot get space at END, fail and return 0. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
526 static __ptr_t get_contiguous_space PP ((__malloc_ptrdiff_t, __ptr_t)); |
| 17130 | 527 static __ptr_t |
| 528 get_contiguous_space (size, position) | |
| 529 __malloc_ptrdiff_t size; | |
| 530 __ptr_t position; | |
| 531 { | |
| 532 __ptr_t before; | |
| 533 __ptr_t after; | |
| 534 | |
| 535 before = (*__morecore) (0); | |
| 536 /* If we can tell in advance that the break is at the wrong place, | |
| 537 fail now. */ | |
| 538 if (before != position) | |
| 539 return 0; | |
| 540 | |
| 541 /* Allocate SIZE bytes and get the address of them. */ | |
| 542 after = (*__morecore) (size); | |
| 543 if (!after) | |
| 544 return 0; | |
| 545 | |
| 546 /* It was not contiguous--reject it. */ | |
| 547 if (after != position) | |
| 548 { | |
| 549 (*__morecore) (- size); | |
| 550 return 0; | |
| 551 } | |
| 552 | |
| 553 return after; | |
| 554 } | |
| 555 | |
| 556 | |
| 557 /* This is called when `_heapinfo' and `heapsize' have just | |
| 558 been set to describe a new info table. Set up the table | |
| 559 to describe itself and account for it in the statistics. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
560 static void register_heapinfo PP ((void)); |
| 17130 | 561 #ifdef __GNUC__ |
| 562 __inline__ | |
| 563 #endif | |
| 564 static void | |
| 565 register_heapinfo () | |
| 566 { | |
| 567 __malloc_size_t block, blocks; | |
| 568 | |
| 569 block = BLOCK (_heapinfo); | |
| 570 blocks = BLOCKIFY (heapsize * sizeof (malloc_info)); | |
| 571 | |
| 572 /* Account for the _heapinfo block itself in the statistics. */ | |
| 573 _bytes_used += blocks * BLOCKSIZE; | |
| 574 ++_chunks_used; | |
| 575 | |
| 576 /* Describe the heapinfo block itself in the heapinfo. */ | |
| 577 _heapinfo[block].busy.type = 0; | |
| 578 _heapinfo[block].busy.info.size = blocks; | |
| 579 /* Leave back-pointers for malloc_find_address. */ | |
| 580 while (--blocks > 0) | |
| 581 _heapinfo[block + blocks].busy.info.size = -blocks; | |
| 582 } | |
| 583 | |
|
76776
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
584 #ifdef USE_PTHREAD |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
585 static pthread_once_t malloc_init_once_control = PTHREAD_ONCE_INIT; |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
586 pthread_mutex_t _malloc_mutex = PTHREAD_MUTEX_INITIALIZER; |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
587 pthread_mutex_t _aligned_blocks_mutex = PTHREAD_MUTEX_INITIALIZER; |
|
78437
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
588 int _malloc_thread_enabled_p; |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
589 |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
590 static void |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
591 malloc_atfork_handler_prepare () |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
592 { |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
593 LOCK (); |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
594 LOCK_ALIGNED_BLOCKS (); |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
595 } |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
596 |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
597 static void |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
598 malloc_atfork_handler_parent () |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
599 { |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
600 UNLOCK_ALIGNED_BLOCKS (); |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
601 UNLOCK (); |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
602 } |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
603 |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
604 static void |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
605 malloc_atfork_handler_child () |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
606 { |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
607 UNLOCK_ALIGNED_BLOCKS (); |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
608 UNLOCK (); |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
609 } |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
610 |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
611 /* Set up mutexes and make malloc etc. thread-safe. */ |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
612 void |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
613 malloc_enable_thread () |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
614 { |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
615 if (_malloc_thread_enabled_p) |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
616 return; |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
617 |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
618 /* Some pthread implementations call malloc for statically |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
619 initialized mutexes when they are used first. To avoid such a |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
620 situation, we initialize mutexes here while their use is |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
621 disabled in malloc etc. */ |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
622 pthread_mutex_init (&_malloc_mutex, NULL); |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
623 pthread_mutex_init (&_aligned_blocks_mutex, NULL); |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
624 pthread_atfork (malloc_atfork_handler_prepare, |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
625 malloc_atfork_handler_parent, |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
626 malloc_atfork_handler_child); |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
627 _malloc_thread_enabled_p = 1; |
|
77430fdfce38
(_malloc_thread_enabled_p) [USE_PTHREAD]: New variable.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
78051
diff
changeset
|
628 } |
|
76776
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
629 #endif |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
630 |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
631 static void |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
632 malloc_initialize_1 () |
| 17130 | 633 { |
|
32973
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
634 #ifdef GC_MCHECK |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
635 mcheck (NULL); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
636 #endif |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
637 |
| 17130 | 638 if (__malloc_initialize_hook) |
| 639 (*__malloc_initialize_hook) (); | |
| 640 | |
| 641 heapsize = HEAP / BLOCKSIZE; | |
| 642 _heapinfo = (malloc_info *) align (heapsize * sizeof (malloc_info)); | |
| 643 if (_heapinfo == NULL) | |
|
76776
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
644 return; |
| 17130 | 645 memset (_heapinfo, 0, heapsize * sizeof (malloc_info)); |
| 646 _heapinfo[0].free.size = 0; | |
| 647 _heapinfo[0].free.next = _heapinfo[0].free.prev = 0; | |
| 648 _heapindex = 0; | |
| 649 _heapbase = (char *) _heapinfo; | |
| 650 _heaplimit = BLOCK (_heapbase + heapsize * sizeof (malloc_info)); | |
| 651 | |
| 652 register_heapinfo (); | |
| 653 | |
| 654 __malloc_initialized = 1; | |
|
32821
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
655 PROTECT_MALLOC_STATE (1); |
|
76776
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
656 return; |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
657 } |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
658 |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
659 /* Set everything up and remember that we have. */ |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
660 int |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
661 __malloc_initialize () |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
662 { |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
663 #ifdef USE_PTHREAD |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
664 pthread_once (&malloc_init_once_control, malloc_initialize_1); |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
665 #else |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
666 if (__malloc_initialized) |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
667 return 0; |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
668 |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
669 malloc_initialize_1 (); |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
670 #endif |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
671 |
|
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
672 return __malloc_initialized; |
| 17130 | 673 } |
| 674 | |
| 675 static int morecore_recursing; | |
| 676 | |
| 677 /* Get neatly aligned memory, initializing or | |
| 678 growing the heap info table as necessary. */ | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
679 static __ptr_t morecore_nolock PP ((__malloc_size_t)); |
| 17130 | 680 static __ptr_t |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
681 morecore_nolock (size) |
| 17130 | 682 __malloc_size_t size; |
| 683 { | |
| 684 __ptr_t result; | |
| 685 malloc_info *newinfo, *oldinfo; | |
| 686 __malloc_size_t newsize; | |
| 687 | |
| 688 if (morecore_recursing) | |
| 689 /* Avoid recursion. The caller will know how to handle a null return. */ | |
| 690 return NULL; | |
| 691 | |
| 692 result = align (size); | |
| 693 if (result == NULL) | |
| 694 return NULL; | |
| 695 | |
|
32821
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
696 PROTECT_MALLOC_STATE (0); |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
697 |
| 17130 | 698 /* Check if we need to grow the info table. */ |
| 699 if ((__malloc_size_t) BLOCK ((char *) result + size) > heapsize) | |
| 700 { | |
| 701 /* Calculate the new _heapinfo table size. We do not account for the | |
| 702 added blocks in the table itself, as we hope to place them in | |
| 703 existing free space, which is already covered by part of the | |
| 704 existing table. */ | |
| 705 newsize = heapsize; | |
| 706 do | |
| 707 newsize *= 2; | |
| 708 while ((__malloc_size_t) BLOCK ((char *) result + size) > newsize); | |
| 709 | |
| 710 /* We must not reuse existing core for the new info table when called | |
| 711 from realloc in the case of growing a large block, because the | |
| 712 block being grown is momentarily marked as free. In this case | |
| 713 _heaplimit is zero so we know not to reuse space for internal | |
| 714 allocation. */ | |
| 715 if (_heaplimit != 0) | |
| 716 { | |
| 717 /* First try to allocate the new info table in core we already | |
| 718 have, in the usual way using realloc. If realloc cannot | |
| 719 extend it in place or relocate it to existing sufficient core, | |
| 720 we will get called again, and the code above will notice the | |
| 721 `morecore_recursing' flag and return null. */ | |
| 722 int save = errno; /* Don't want to clobber errno with ENOMEM. */ | |
| 723 morecore_recursing = 1; | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
724 newinfo = (malloc_info *) _realloc_internal_nolock |
| 17130 | 725 (_heapinfo, newsize * sizeof (malloc_info)); |
| 726 morecore_recursing = 0; | |
| 727 if (newinfo == NULL) | |
| 728 errno = save; | |
| 729 else | |
| 730 { | |
| 731 /* We found some space in core, and realloc has put the old | |
| 732 table's blocks on the free list. Now zero the new part | |
| 733 of the table and install the new table location. */ | |
| 734 memset (&newinfo[heapsize], 0, | |
| 735 (newsize - heapsize) * sizeof (malloc_info)); | |
| 736 _heapinfo = newinfo; | |
| 737 heapsize = newsize; | |
| 738 goto got_heap; | |
| 739 } | |
| 740 } | |
| 741 | |
| 742 /* Allocate new space for the malloc info table. */ | |
| 743 while (1) | |
| 744 { | |
| 745 newinfo = (malloc_info *) align (newsize * sizeof (malloc_info)); | |
| 746 | |
| 747 /* Did it fail? */ | |
| 748 if (newinfo == NULL) | |
| 749 { | |
| 750 (*__morecore) (-size); | |
| 751 return NULL; | |
| 752 } | |
| 753 | |
| 754 /* Is it big enough to record status for its own space? | |
| 755 If so, we win. */ | |
| 756 if ((__malloc_size_t) BLOCK ((char *) newinfo | |
| 757 + newsize * sizeof (malloc_info)) | |
| 758 < newsize) | |
| 759 break; | |
| 760 | |
| 761 /* Must try again. First give back most of what we just got. */ | |
| 762 (*__morecore) (- newsize * sizeof (malloc_info)); | |
| 763 newsize *= 2; | |
| 764 } | |
| 765 | |
| 766 /* Copy the old table to the beginning of the new, | |
| 767 and zero the rest of the new table. */ | |
| 768 memcpy (newinfo, _heapinfo, heapsize * sizeof (malloc_info)); | |
| 769 memset (&newinfo[heapsize], 0, | |
| 770 (newsize - heapsize) * sizeof (malloc_info)); | |
| 771 oldinfo = _heapinfo; | |
| 772 _heapinfo = newinfo; | |
| 773 heapsize = newsize; | |
| 774 | |
| 775 register_heapinfo (); | |
| 776 | |
| 777 /* Reset _heaplimit so _free_internal never decides | |
| 778 it can relocate or resize the info table. */ | |
| 779 _heaplimit = 0; | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
780 _free_internal_nolock (oldinfo); |
|
32821
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
781 PROTECT_MALLOC_STATE (0); |
| 17130 | 782 |
| 783 /* The new heap limit includes the new table just allocated. */ | |
| 784 _heaplimit = BLOCK ((char *) newinfo + heapsize * sizeof (malloc_info)); | |
| 785 return result; | |
| 786 } | |
| 787 | |
| 788 got_heap: | |
| 789 _heaplimit = BLOCK ((char *) result + size); | |
| 790 return result; | |
| 791 } | |
| 792 | |
| 793 /* Allocate memory from the heap. */ | |
| 794 __ptr_t | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
795 _malloc_internal_nolock (size) |
| 17130 | 796 __malloc_size_t size; |
| 797 { | |
| 798 __ptr_t result; | |
| 799 __malloc_size_t block, blocks, lastblocks, start; | |
| 800 register __malloc_size_t i; | |
| 801 struct list *next; | |
| 802 | |
| 803 /* ANSI C allows `malloc (0)' to either return NULL, or to return a | |
| 804 valid address you can realloc and free (though not dereference). | |
| 805 | |
| 806 It turns out that some extant code (sunrpc, at least Ultrix's version) | |
| 807 expects `malloc (0)' to return non-NULL and breaks otherwise. | |
| 808 Be compatible. */ | |
| 809 | |
| 810 #if 0 | |
| 811 if (size == 0) | |
| 812 return NULL; | |
| 813 #endif | |
| 814 | |
|
32821
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
815 PROTECT_MALLOC_STATE (0); |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
816 |
| 17130 | 817 if (size < sizeof (struct list)) |
| 818 size = sizeof (struct list); | |
| 819 | |
| 820 #ifdef SUNOS_LOCALTIME_BUG | |
| 821 if (size < 16) | |
| 822 size = 16; | |
| 823 #endif | |
| 824 | |
| 825 /* Determine the allocation policy based on the request size. */ | |
| 826 if (size <= BLOCKSIZE / 2) | |
| 827 { | |
| 828 /* Small allocation to receive a fragment of a block. | |
| 829 Determine the logarithm to base two of the fragment size. */ | |
| 830 register __malloc_size_t log = 1; | |
| 831 --size; | |
| 832 while ((size /= 2) != 0) | |
| 833 ++log; | |
| 834 | |
| 835 /* Look in the fragment lists for a | |
| 836 free fragment of the desired size. */ | |
| 837 next = _fraghead[log].next; | |
| 838 if (next != NULL) | |
| 839 { | |
| 840 /* There are free fragments of this size. | |
| 841 Pop a fragment out of the fragment list and return it. | |
| 842 Update the block's nfree and first counters. */ | |
| 843 result = (__ptr_t) next; | |
| 844 next->prev->next = next->next; | |
| 845 if (next->next != NULL) | |
| 846 next->next->prev = next->prev; | |
| 847 block = BLOCK (result); | |
| 848 if (--_heapinfo[block].busy.info.frag.nfree != 0) | |
| 849 _heapinfo[block].busy.info.frag.first = (unsigned long int) | |
| 850 ((unsigned long int) ((char *) next->next - (char *) NULL) | |
| 851 % BLOCKSIZE) >> log; | |
| 852 | |
| 853 /* Update the statistics. */ | |
| 854 ++_chunks_used; | |
| 855 _bytes_used += 1 << log; | |
| 856 --_chunks_free; | |
| 857 _bytes_free -= 1 << log; | |
| 858 } | |
| 859 else | |
| 860 { | |
| 861 /* No free fragments of the desired size, so get a new block | |
| 862 and break it into fragments, returning the first. */ | |
|
32693
8223a86fa594
(_malloc_internal) [GC_MALLOC_CHECK]: Use
Gerd Moellmann <gerd@gnu.org>
parents:
29837
diff
changeset
|
863 #ifdef GC_MALLOC_CHECK |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
864 result = _malloc_internal_nolock (BLOCKSIZE); |
|
32821
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
865 PROTECT_MALLOC_STATE (0); |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
866 #elif defined (USE_PTHREAD) |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
867 result = _malloc_internal_nolock (BLOCKSIZE); |
|
32693
8223a86fa594
(_malloc_internal) [GC_MALLOC_CHECK]: Use
Gerd Moellmann <gerd@gnu.org>
parents:
29837
diff
changeset
|
868 #else |
| 17130 | 869 result = malloc (BLOCKSIZE); |
|
32693
8223a86fa594
(_malloc_internal) [GC_MALLOC_CHECK]: Use
Gerd Moellmann <gerd@gnu.org>
parents:
29837
diff
changeset
|
870 #endif |
| 17130 | 871 if (result == NULL) |
|
32821
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
872 { |
|
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
873 PROTECT_MALLOC_STATE (1); |
|
76776
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
874 goto out; |
|
32821
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
875 } |
| 17130 | 876 |
| 877 /* Link all fragments but the first into the free list. */ | |
| 878 next = (struct list *) ((char *) result + (1 << log)); | |
| 879 next->next = NULL; | |
| 880 next->prev = &_fraghead[log]; | |
| 881 _fraghead[log].next = next; | |
| 882 | |
| 883 for (i = 2; i < (__malloc_size_t) (BLOCKSIZE >> log); ++i) | |
| 884 { | |
| 885 next = (struct list *) ((char *) result + (i << log)); | |
| 886 next->next = _fraghead[log].next; | |
| 887 next->prev = &_fraghead[log]; | |
| 888 next->prev->next = next; | |
| 889 next->next->prev = next; | |
| 890 } | |
| 891 | |
| 892 /* Initialize the nfree and first counters for this block. */ | |
| 893 block = BLOCK (result); | |
| 894 _heapinfo[block].busy.type = log; | |
| 895 _heapinfo[block].busy.info.frag.nfree = i - 1; | |
| 896 _heapinfo[block].busy.info.frag.first = i - 1; | |
| 897 | |
| 898 _chunks_free += (BLOCKSIZE >> log) - 1; | |
| 899 _bytes_free += BLOCKSIZE - (1 << log); | |
| 900 _bytes_used -= BLOCKSIZE - (1 << log); | |
| 901 } | |
| 902 } | |
| 903 else | |
| 904 { | |
| 905 /* Large allocation to receive one or more blocks. | |
| 906 Search the free list in a circle starting at the last place visited. | |
| 907 If we loop completely around without finding a large enough | |
| 908 space we will have to get more memory from the system. */ | |
| 909 blocks = BLOCKIFY (size); | |
| 910 start = block = _heapindex; | |
| 911 while (_heapinfo[block].free.size < blocks) | |
| 912 { | |
| 913 block = _heapinfo[block].free.next; | |
| 914 if (block == start) | |
| 915 { | |
| 916 /* Need to get more from the system. Get a little extra. */ | |
| 917 __malloc_size_t wantblocks = blocks + __malloc_extra_blocks; | |
| 918 block = _heapinfo[0].free.prev; | |
| 919 lastblocks = _heapinfo[block].free.size; | |
| 920 /* Check to see if the new core will be contiguous with the | |
| 921 final free block; if so we don't need to get as much. */ | |
| 922 if (_heaplimit != 0 && block + lastblocks == _heaplimit && | |
| 923 /* We can't do this if we will have to make the heap info | |
| 924 table bigger to accomodate the new space. */ | |
| 925 block + wantblocks <= heapsize && | |
| 926 get_contiguous_space ((wantblocks - lastblocks) * BLOCKSIZE, | |
| 927 ADDRESS (block + lastblocks))) | |
| 928 { | |
| 929 /* We got it contiguously. Which block we are extending | |
| 930 (the `final free block' referred to above) might have | |
| 931 changed, if it got combined with a freed info table. */ | |
| 932 block = _heapinfo[0].free.prev; | |
| 933 _heapinfo[block].free.size += (wantblocks - lastblocks); | |
| 934 _bytes_free += (wantblocks - lastblocks) * BLOCKSIZE; | |
| 935 _heaplimit += wantblocks - lastblocks; | |
| 936 continue; | |
| 937 } | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
938 result = morecore_nolock (wantblocks * BLOCKSIZE); |
| 17130 | 939 if (result == NULL) |
|
76776
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
940 goto out; |
| 17130 | 941 block = BLOCK (result); |
| 942 /* Put the new block at the end of the free list. */ | |
| 943 _heapinfo[block].free.size = wantblocks; | |
| 944 _heapinfo[block].free.prev = _heapinfo[0].free.prev; | |
| 945 _heapinfo[block].free.next = 0; | |
| 946 _heapinfo[0].free.prev = block; | |
| 947 _heapinfo[_heapinfo[block].free.prev].free.next = block; | |
| 948 ++_chunks_free; | |
| 949 /* Now loop to use some of that block for this allocation. */ | |
| 950 } | |
| 951 } | |
| 952 | |
| 953 /* At this point we have found a suitable free list entry. | |
| 954 Figure out how to remove what we need from the list. */ | |
| 955 result = ADDRESS (block); | |
| 956 if (_heapinfo[block].free.size > blocks) | |
| 957 { | |
| 958 /* The block we found has a bit left over, | |
| 959 so relink the tail end back into the free list. */ | |
| 960 _heapinfo[block + blocks].free.size | |
| 961 = _heapinfo[block].free.size - blocks; | |
| 962 _heapinfo[block + blocks].free.next | |
| 963 = _heapinfo[block].free.next; | |
| 964 _heapinfo[block + blocks].free.prev | |
| 965 = _heapinfo[block].free.prev; | |
| 966 _heapinfo[_heapinfo[block].free.prev].free.next | |
| 967 = _heapinfo[_heapinfo[block].free.next].free.prev | |
| 968 = _heapindex = block + blocks; | |
| 969 } | |
| 970 else | |
| 971 { | |
| 972 /* The block exactly matches our requirements, | |
| 973 so just remove it from the list. */ | |
| 974 _heapinfo[_heapinfo[block].free.next].free.prev | |
| 975 = _heapinfo[block].free.prev; | |
| 976 _heapinfo[_heapinfo[block].free.prev].free.next | |
| 977 = _heapindex = _heapinfo[block].free.next; | |
| 978 --_chunks_free; | |
| 979 } | |
| 980 | |
| 981 _heapinfo[block].busy.type = 0; | |
| 982 _heapinfo[block].busy.info.size = blocks; | |
| 983 ++_chunks_used; | |
| 984 _bytes_used += blocks * BLOCKSIZE; | |
| 985 _bytes_free -= blocks * BLOCKSIZE; | |
| 986 | |
| 987 /* Mark all the blocks of the object just allocated except for the | |
| 988 first with a negative number so you can find the first block by | |
| 989 adding that adjustment. */ | |
| 990 while (--blocks > 0) | |
| 991 _heapinfo[block + blocks].busy.info.size = -blocks; | |
| 992 } | |
| 993 | |
|
32821
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
994 PROTECT_MALLOC_STATE (1); |
|
76776
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
995 out: |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
996 return result; |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
997 } |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
998 |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
999 __ptr_t |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1000 _malloc_internal (size) |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1001 __malloc_size_t size; |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1002 { |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1003 __ptr_t result; |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1004 |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1005 LOCK (); |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1006 result = _malloc_internal_nolock (size); |
|
76776
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
1007 UNLOCK (); |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1008 |
| 17130 | 1009 return result; |
| 1010 } | |
| 1011 | |
| 1012 __ptr_t | |
| 1013 malloc (size) | |
| 1014 __malloc_size_t size; | |
| 1015 { | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1016 __ptr_t (*hook) (__malloc_size_t); |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1017 |
| 17130 | 1018 if (!__malloc_initialized && !__malloc_initialize ()) |
| 1019 return NULL; | |
| 1020 | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1021 /* Copy the value of __malloc_hook to an automatic variable in case |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1022 __malloc_hook is modified in another thread between its |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1023 NULL-check and the use. |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1024 |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1025 Note: Strictly speaking, this is not a right solution. We should |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1026 use mutexes to access non-read-only variables that are shared |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1027 among multiple threads. We just leave it for compatibility with |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1028 glibc malloc (i.e., assignments to __malloc_hook) for now. */ |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1029 hook = __malloc_hook; |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1030 return (hook != NULL ? *hook : _malloc_internal) (size); |
| 17130 | 1031 } |
| 1032 | |
| 1033 #ifndef _LIBC | |
| 1034 | |
| 1035 /* On some ANSI C systems, some libc functions call _malloc, _free | |
| 1036 and _realloc. Make them use the GNU functions. */ | |
| 1037 | |
| 1038 __ptr_t | |
| 1039 _malloc (size) | |
| 1040 __malloc_size_t size; | |
| 1041 { | |
| 1042 return malloc (size); | |
| 1043 } | |
| 1044 | |
| 1045 void | |
| 1046 _free (ptr) | |
| 1047 __ptr_t ptr; | |
| 1048 { | |
| 1049 free (ptr); | |
| 1050 } | |
| 1051 | |
| 1052 __ptr_t | |
| 1053 _realloc (ptr, size) | |
| 1054 __ptr_t ptr; | |
| 1055 __malloc_size_t size; | |
| 1056 { | |
| 1057 return realloc (ptr, size); | |
| 1058 } | |
| 1059 | |
| 1060 #endif | |
| 1061 /* Free a block of memory allocated by `malloc'. | |
| 1062 Copyright 1990, 1991, 1992, 1994, 1995 Free Software Foundation, Inc. | |
| 1063 Written May 1989 by Mike Haertel. | |
| 1064 | |
| 1065 This library is free software; you can redistribute it and/or | |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1066 modify it under the terms of the GNU General Public License as |
| 17130 | 1067 published by the Free Software Foundation; either version 2 of the |
| 1068 License, or (at your option) any later version. | |
| 1069 | |
| 1070 This library is distributed in the hope that it will be useful, | |
| 1071 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 1072 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1073 General Public License for more details. |
| 17130 | 1074 |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1075 You should have received a copy of the GNU General Public |
|
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1076 License along with this library; see the file COPYING. If |
| 64092 | 1077 not, write to the Free Software Foundation, Inc., 51 Franklin Street, |
| 1078 Fifth Floor, Boston, MA 02110-1301, USA. | |
| 17130 | 1079 |
| 1080 The author may be reached (Email) at the address mike@ai.mit.edu, | |
| 1081 or (US mail) as Mike Haertel c/o Free Software Foundation. */ | |
| 1082 | |
| 1083 #ifndef _MALLOC_INTERNAL | |
| 1084 #define _MALLOC_INTERNAL | |
| 1085 #include <malloc.h> | |
| 1086 #endif | |
| 1087 | |
| 1088 | |
| 1089 /* Cope with systems lacking `memmove'. */ | |
| 1090 #ifndef memmove | |
| 1091 #if (defined (MEMMOVE_MISSING) || \ | |
| 1092 !defined(_LIBC) && !defined(STDC_HEADERS) && !defined(USG)) | |
| 1093 #ifdef emacs | |
| 1094 #undef __malloc_safe_bcopy | |
| 1095 #define __malloc_safe_bcopy safe_bcopy | |
| 1096 #endif | |
| 1097 /* This function is defined in realloc.c. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
1098 extern void __malloc_safe_bcopy PP ((__ptr_t, __ptr_t, __malloc_size_t)); |
| 17130 | 1099 #define memmove(to, from, size) __malloc_safe_bcopy ((from), (to), (size)) |
| 1100 #endif | |
| 1101 #endif | |
| 1102 | |
| 1103 | |
| 1104 /* Debugging hook for free. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
1105 void (*__free_hook) PP ((__ptr_t __ptr)); |
| 17130 | 1106 |
| 1107 /* List of blocks allocated by memalign. */ | |
| 1108 struct alignlist *_aligned_blocks = NULL; | |
| 1109 | |
| 1110 /* Return memory to the heap. | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1111 Like `_free_internal' but don't lock mutex. */ |
| 17130 | 1112 void |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1113 _free_internal_nolock (ptr) |
| 17130 | 1114 __ptr_t ptr; |
| 1115 { | |
| 1116 int type; | |
| 1117 __malloc_size_t block, blocks; | |
| 1118 register __malloc_size_t i; | |
| 1119 struct list *prev, *next; | |
| 1120 __ptr_t curbrk; | |
| 1121 const __malloc_size_t lesscore_threshold | |
| 1122 /* Threshold of free space at which we will return some to the system. */ | |
| 1123 = FINAL_FREE_BLOCKS + 2 * __malloc_extra_blocks; | |
| 1124 | |
| 1125 register struct alignlist *l; | |
| 1126 | |
| 1127 if (ptr == NULL) | |
| 1128 return; | |
| 1129 | |
|
32821
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
1130 PROTECT_MALLOC_STATE (0); |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
40670
diff
changeset
|
1131 |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1132 LOCK_ALIGNED_BLOCKS (); |
| 17130 | 1133 for (l = _aligned_blocks; l != NULL; l = l->next) |
| 1134 if (l->aligned == ptr) | |
| 1135 { | |
| 1136 l->aligned = NULL; /* Mark the slot in the list as free. */ | |
| 1137 ptr = l->exact; | |
| 1138 break; | |
| 1139 } | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1140 UNLOCK_ALIGNED_BLOCKS (); |
| 17130 | 1141 |
| 1142 block = BLOCK (ptr); | |
| 1143 | |
| 1144 type = _heapinfo[block].busy.type; | |
| 1145 switch (type) | |
| 1146 { | |
| 1147 case 0: | |
| 1148 /* Get as many statistics as early as we can. */ | |
| 1149 --_chunks_used; | |
| 1150 _bytes_used -= _heapinfo[block].busy.info.size * BLOCKSIZE; | |
| 1151 _bytes_free += _heapinfo[block].busy.info.size * BLOCKSIZE; | |
| 1152 | |
| 1153 /* Find the free cluster previous to this one in the free list. | |
| 1154 Start searching at the last block referenced; this may benefit | |
| 1155 programs with locality of allocation. */ | |
| 1156 i = _heapindex; | |
| 1157 if (i > block) | |
| 1158 while (i > block) | |
| 1159 i = _heapinfo[i].free.prev; | |
| 1160 else | |
| 1161 { | |
| 1162 do | |
| 1163 i = _heapinfo[i].free.next; | |
| 1164 while (i > 0 && i < block); | |
| 1165 i = _heapinfo[i].free.prev; | |
| 1166 } | |
| 1167 | |
| 1168 /* Determine how to link this block into the free list. */ | |
| 1169 if (block == i + _heapinfo[i].free.size) | |
| 1170 { | |
| 1171 /* Coalesce this block with its predecessor. */ | |
| 1172 _heapinfo[i].free.size += _heapinfo[block].busy.info.size; | |
| 1173 block = i; | |
| 1174 } | |
| 1175 else | |
| 1176 { | |
| 1177 /* Really link this block back into the free list. */ | |
| 1178 _heapinfo[block].free.size = _heapinfo[block].busy.info.size; | |
| 1179 _heapinfo[block].free.next = _heapinfo[i].free.next; | |
| 1180 _heapinfo[block].free.prev = i; | |
| 1181 _heapinfo[i].free.next = block; | |
| 1182 _heapinfo[_heapinfo[block].free.next].free.prev = block; | |
| 1183 ++_chunks_free; | |
| 1184 } | |
| 1185 | |
| 1186 /* Now that the block is linked in, see if we can coalesce it | |
| 1187 with its successor (by deleting its successor from the list | |
| 1188 and adding in its size). */ | |
| 1189 if (block + _heapinfo[block].free.size == _heapinfo[block].free.next) | |
| 1190 { | |
| 1191 _heapinfo[block].free.size | |
| 1192 += _heapinfo[_heapinfo[block].free.next].free.size; | |
| 1193 _heapinfo[block].free.next | |
| 1194 = _heapinfo[_heapinfo[block].free.next].free.next; | |
| 1195 _heapinfo[_heapinfo[block].free.next].free.prev = block; | |
| 1196 --_chunks_free; | |
| 1197 } | |
| 1198 | |
| 1199 /* How many trailing free blocks are there now? */ | |
| 1200 blocks = _heapinfo[block].free.size; | |
| 1201 | |
| 1202 /* Where is the current end of accessible core? */ | |
| 1203 curbrk = (*__morecore) (0); | |
| 1204 | |
| 1205 if (_heaplimit != 0 && curbrk == ADDRESS (_heaplimit)) | |
| 1206 { | |
| 1207 /* The end of the malloc heap is at the end of accessible core. | |
| 1208 It's possible that moving _heapinfo will allow us to | |
| 1209 return some space to the system. */ | |
| 1210 | |
| 1211 __malloc_size_t info_block = BLOCK (_heapinfo); | |
| 1212 __malloc_size_t info_blocks = _heapinfo[info_block].busy.info.size; | |
| 1213 __malloc_size_t prev_block = _heapinfo[block].free.prev; | |
| 1214 __malloc_size_t prev_blocks = _heapinfo[prev_block].free.size; | |
| 1215 __malloc_size_t next_block = _heapinfo[block].free.next; | |
| 1216 __malloc_size_t next_blocks = _heapinfo[next_block].free.size; | |
| 1217 | |
| 1218 if (/* Win if this block being freed is last in core, the info table | |
| 1219 is just before it, the previous free block is just before the | |
| 1220 info table, and the two free blocks together form a useful | |
| 1221 amount to return to the system. */ | |
| 1222 (block + blocks == _heaplimit && | |
| 1223 info_block + info_blocks == block && | |
| 1224 prev_block != 0 && prev_block + prev_blocks == info_block && | |
| 1225 blocks + prev_blocks >= lesscore_threshold) || | |
| 1226 /* Nope, not the case. We can also win if this block being | |
| 1227 freed is just before the info table, and the table extends | |
| 1228 to the end of core or is followed only by a free block, | |
| 1229 and the total free space is worth returning to the system. */ | |
| 1230 (block + blocks == info_block && | |
| 1231 ((info_block + info_blocks == _heaplimit && | |
| 1232 blocks >= lesscore_threshold) || | |
| 1233 (info_block + info_blocks == next_block && | |
| 1234 next_block + next_blocks == _heaplimit && | |
| 1235 blocks + next_blocks >= lesscore_threshold))) | |
| 1236 ) | |
| 1237 { | |
| 1238 malloc_info *newinfo; | |
| 1239 __malloc_size_t oldlimit = _heaplimit; | |
| 1240 | |
| 1241 /* Free the old info table, clearing _heaplimit to avoid | |
| 1242 recursion into this code. We don't want to return the | |
| 1243 table's blocks to the system before we have copied them to | |
| 1244 the new location. */ | |
| 1245 _heaplimit = 0; | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1246 _free_internal_nolock (_heapinfo); |
| 17130 | 1247 _heaplimit = oldlimit; |
| 1248 | |
| 1249 /* Tell malloc to search from the beginning of the heap for | |
| 1250 free blocks, so it doesn't reuse the ones just freed. */ | |
| 1251 _heapindex = 0; | |
| 1252 | |
| 1253 /* Allocate new space for the info table and move its data. */ | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1254 newinfo = (malloc_info *) _malloc_internal_nolock (info_blocks |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1255 * BLOCKSIZE); |
|
32821
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
1256 PROTECT_MALLOC_STATE (0); |
| 17130 | 1257 memmove (newinfo, _heapinfo, info_blocks * BLOCKSIZE); |
| 1258 _heapinfo = newinfo; | |
| 1259 | |
| 1260 /* We should now have coalesced the free block with the | |
| 1261 blocks freed from the old info table. Examine the entire | |
| 1262 trailing free block to decide below whether to return some | |
| 1263 to the system. */ | |
| 1264 block = _heapinfo[0].free.prev; | |
| 1265 blocks = _heapinfo[block].free.size; | |
| 1266 } | |
| 1267 | |
| 1268 /* Now see if we can return stuff to the system. */ | |
| 1269 if (block + blocks == _heaplimit && blocks >= lesscore_threshold) | |
| 1270 { | |
| 1271 register __malloc_size_t bytes = blocks * BLOCKSIZE; | |
| 1272 _heaplimit -= blocks; | |
| 1273 (*__morecore) (-bytes); | |
| 1274 _heapinfo[_heapinfo[block].free.prev].free.next | |
| 1275 = _heapinfo[block].free.next; | |
| 1276 _heapinfo[_heapinfo[block].free.next].free.prev | |
| 1277 = _heapinfo[block].free.prev; | |
| 1278 block = _heapinfo[block].free.prev; | |
| 1279 --_chunks_free; | |
| 1280 _bytes_free -= bytes; | |
| 1281 } | |
| 1282 } | |
| 1283 | |
| 1284 /* Set the next search to begin at this block. */ | |
| 1285 _heapindex = block; | |
| 1286 break; | |
| 1287 | |
| 1288 default: | |
| 1289 /* Do some of the statistics. */ | |
| 1290 --_chunks_used; | |
| 1291 _bytes_used -= 1 << type; | |
| 1292 ++_chunks_free; | |
| 1293 _bytes_free += 1 << type; | |
| 1294 | |
| 1295 /* Get the address of the first free fragment in this block. */ | |
| 1296 prev = (struct list *) ((char *) ADDRESS (block) + | |
| 1297 (_heapinfo[block].busy.info.frag.first << type)); | |
| 1298 | |
| 1299 if (_heapinfo[block].busy.info.frag.nfree == (BLOCKSIZE >> type) - 1) | |
| 1300 { | |
| 1301 /* If all fragments of this block are free, remove them | |
| 1302 from the fragment list and free the whole block. */ | |
| 1303 next = prev; | |
| 1304 for (i = 1; i < (__malloc_size_t) (BLOCKSIZE >> type); ++i) | |
| 1305 next = next->next; | |
| 1306 prev->prev->next = next; | |
| 1307 if (next != NULL) | |
| 1308 next->prev = prev->prev; | |
| 1309 _heapinfo[block].busy.type = 0; | |
| 1310 _heapinfo[block].busy.info.size = 1; | |
| 1311 | |
| 1312 /* Keep the statistics accurate. */ | |
| 1313 ++_chunks_used; | |
| 1314 _bytes_used += BLOCKSIZE; | |
| 1315 _chunks_free -= BLOCKSIZE >> type; | |
| 1316 _bytes_free -= BLOCKSIZE; | |
| 1317 | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1318 #if defined (GC_MALLOC_CHECK) || defined (USE_PTHREAD) |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1319 _free_internal_nolock (ADDRESS (block)); |
|
32693
8223a86fa594
(_malloc_internal) [GC_MALLOC_CHECK]: Use
Gerd Moellmann <gerd@gnu.org>
parents:
29837
diff
changeset
|
1320 #else |
| 17130 | 1321 free (ADDRESS (block)); |
|
32693
8223a86fa594
(_malloc_internal) [GC_MALLOC_CHECK]: Use
Gerd Moellmann <gerd@gnu.org>
parents:
29837
diff
changeset
|
1322 #endif |
| 17130 | 1323 } |
| 1324 else if (_heapinfo[block].busy.info.frag.nfree != 0) | |
| 1325 { | |
| 1326 /* If some fragments of this block are free, link this | |
| 1327 fragment into the fragment list after the first free | |
| 1328 fragment of this block. */ | |
| 1329 next = (struct list *) ptr; | |
| 1330 next->next = prev->next; | |
| 1331 next->prev = prev; | |
| 1332 prev->next = next; | |
| 1333 if (next->next != NULL) | |
| 1334 next->next->prev = next; | |
| 1335 ++_heapinfo[block].busy.info.frag.nfree; | |
| 1336 } | |
| 1337 else | |
| 1338 { | |
| 1339 /* No fragments of this block are free, so link this | |
| 1340 fragment into the fragment list and announce that | |
| 1341 it is the first free fragment of this block. */ | |
| 1342 prev = (struct list *) ptr; | |
| 1343 _heapinfo[block].busy.info.frag.nfree = 1; | |
| 1344 _heapinfo[block].busy.info.frag.first = (unsigned long int) | |
| 1345 ((unsigned long int) ((char *) ptr - (char *) NULL) | |
| 1346 % BLOCKSIZE >> type); | |
| 1347 prev->next = _fraghead[type].next; | |
| 1348 prev->prev = &_fraghead[type]; | |
| 1349 prev->prev->next = prev; | |
| 1350 if (prev->next != NULL) | |
| 1351 prev->next->prev = prev; | |
| 1352 } | |
| 1353 break; | |
| 1354 } | |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
40670
diff
changeset
|
1355 |
|
32821
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
1356 PROTECT_MALLOC_STATE (1); |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1357 } |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1358 |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1359 /* Return memory to the heap. |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1360 Like `free' but don't call a __free_hook if there is one. */ |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1361 void |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1362 _free_internal (ptr) |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1363 __ptr_t ptr; |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1364 { |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1365 LOCK (); |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1366 _free_internal_nolock (ptr); |
|
76776
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
1367 UNLOCK (); |
| 17130 | 1368 } |
| 1369 | |
| 1370 /* Return memory to the heap. */ | |
|
26526
b7438760079b
* callproc.c (strerror): Remove decl.
Paul Eggert <eggert@twinsun.com>
parents:
26088
diff
changeset
|
1371 |
|
b7438760079b
* callproc.c (strerror): Remove decl.
Paul Eggert <eggert@twinsun.com>
parents:
26088
diff
changeset
|
1372 FREE_RETURN_TYPE |
| 17130 | 1373 free (ptr) |
| 1374 __ptr_t ptr; | |
| 1375 { | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1376 void (*hook) (__ptr_t) = __free_hook; |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1377 |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1378 if (hook != NULL) |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1379 (*hook) (ptr); |
| 17130 | 1380 else |
| 1381 _free_internal (ptr); | |
| 1382 } | |
| 1383 | |
| 1384 /* Define the `cfree' alias for `free'. */ | |
| 1385 #ifdef weak_alias | |
| 1386 weak_alias (free, cfree) | |
| 1387 #else | |
| 1388 void | |
| 1389 cfree (ptr) | |
| 1390 __ptr_t ptr; | |
| 1391 { | |
| 1392 free (ptr); | |
| 1393 } | |
| 1394 #endif | |
| 1395 /* Change the size of a block allocated by `malloc'. | |
| 1396 Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. | |
| 1397 Written May 1989 by Mike Haertel. | |
| 1398 | |
| 1399 This library is free software; you can redistribute it and/or | |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1400 modify it under the terms of the GNU General Public License as |
| 17130 | 1401 published by the Free Software Foundation; either version 2 of the |
| 1402 License, or (at your option) any later version. | |
| 1403 | |
| 1404 This library is distributed in the hope that it will be useful, | |
| 1405 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 1406 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1407 General Public License for more details. |
| 17130 | 1408 |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1409 You should have received a copy of the GNU General Public |
|
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1410 License along with this library; see the file COPYING. If |
| 64092 | 1411 not, write to the Free Software Foundation, Inc., 51 Franklin Street, |
| 1412 Fifth Floor, Boston, MA 02110-1301, USA. | |
| 17130 | 1413 |
| 1414 The author may be reached (Email) at the address mike@ai.mit.edu, | |
| 1415 or (US mail) as Mike Haertel c/o Free Software Foundation. */ | |
| 1416 | |
| 1417 #ifndef _MALLOC_INTERNAL | |
| 1418 #define _MALLOC_INTERNAL | |
| 1419 #include <malloc.h> | |
| 1420 #endif | |
| 1421 | |
| 1422 | |
| 1423 | |
| 1424 /* Cope with systems lacking `memmove'. */ | |
| 1425 #if (defined (MEMMOVE_MISSING) || \ | |
| 1426 !defined(_LIBC) && !defined(STDC_HEADERS) && !defined(USG)) | |
| 1427 | |
| 1428 #ifdef emacs | |
| 1429 #undef __malloc_safe_bcopy | |
| 1430 #define __malloc_safe_bcopy safe_bcopy | |
| 1431 #else | |
| 1432 | |
| 1433 /* Snarfed directly from Emacs src/dispnew.c: | |
| 1434 XXX Should use system bcopy if it handles overlap. */ | |
| 1435 | |
| 1436 /* Like bcopy except never gets confused by overlap. */ | |
| 1437 | |
| 1438 void | |
| 1439 __malloc_safe_bcopy (afrom, ato, size) | |
| 1440 __ptr_t afrom; | |
| 1441 __ptr_t ato; | |
| 1442 __malloc_size_t size; | |
| 1443 { | |
| 1444 char *from = afrom, *to = ato; | |
| 1445 | |
| 1446 if (size <= 0 || from == to) | |
| 1447 return; | |
| 1448 | |
| 1449 /* If the source and destination don't overlap, then bcopy can | |
| 1450 handle it. If they do overlap, but the destination is lower in | |
| 1451 memory than the source, we'll assume bcopy can handle that. */ | |
| 1452 if (to < from || from + size <= to) | |
| 1453 bcopy (from, to, size); | |
| 1454 | |
| 1455 /* Otherwise, we'll copy from the end. */ | |
| 1456 else | |
| 1457 { | |
| 1458 register char *endf = from + size; | |
| 1459 register char *endt = to + size; | |
| 1460 | |
| 1461 /* If TO - FROM is large, then we should break the copy into | |
| 1462 nonoverlapping chunks of TO - FROM bytes each. However, if | |
| 1463 TO - FROM is small, then the bcopy function call overhead | |
| 1464 makes this not worth it. The crossover point could be about | |
| 1465 anywhere. Since I don't think the obvious copy loop is too | |
| 1466 bad, I'm trying to err in its favor. */ | |
| 1467 if (to - from < 64) | |
| 1468 { | |
| 1469 do | |
| 1470 *--endt = *--endf; | |
| 1471 while (endf != from); | |
| 1472 } | |
| 1473 else | |
| 1474 { | |
| 1475 for (;;) | |
| 1476 { | |
| 1477 endt -= (to - from); | |
| 1478 endf -= (to - from); | |
| 1479 | |
| 1480 if (endt < to) | |
| 1481 break; | |
| 1482 | |
| 1483 bcopy (endf, endt, to - from); | |
| 1484 } | |
| 1485 | |
| 1486 /* If SIZE wasn't a multiple of TO - FROM, there will be a | |
| 1487 little left over. The amount left over is | |
| 1488 (endt + (to - from)) - to, which is endt - from. */ | |
| 1489 bcopy (from, to, endt - from); | |
| 1490 } | |
| 1491 } | |
| 1492 } | |
| 1493 #endif /* emacs */ | |
| 1494 | |
| 1495 #ifndef memmove | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
1496 extern void __malloc_safe_bcopy PP ((__ptr_t, __ptr_t, __malloc_size_t)); |
| 17130 | 1497 #define memmove(to, from, size) __malloc_safe_bcopy ((from), (to), (size)) |
| 1498 #endif | |
| 1499 | |
| 1500 #endif | |
| 1501 | |
| 1502 | |
| 1503 #define min(A, B) ((A) < (B) ? (A) : (B)) | |
| 1504 | |
| 1505 /* Debugging hook for realloc. */ | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
1506 __ptr_t (*__realloc_hook) PP ((__ptr_t __ptr, __malloc_size_t __size)); |
| 17130 | 1507 |
| 1508 /* Resize the given region to the new size, returning a pointer | |
| 1509 to the (possibly moved) region. This is optimized for speed; | |
| 1510 some benchmarks seem to indicate that greater compactness is | |
| 1511 achieved by unconditionally allocating and copying to a | |
| 1512 new region. This module has incestuous knowledge of the | |
| 1513 internals of both free and malloc. */ | |
| 1514 __ptr_t | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1515 _realloc_internal_nolock (ptr, size) |
| 17130 | 1516 __ptr_t ptr; |
| 1517 __malloc_size_t size; | |
| 1518 { | |
| 1519 __ptr_t result; | |
| 1520 int type; | |
| 1521 __malloc_size_t block, blocks, oldlimit; | |
| 1522 | |
| 1523 if (size == 0) | |
| 1524 { | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1525 _free_internal_nolock (ptr); |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1526 return _malloc_internal_nolock (0); |
| 17130 | 1527 } |
| 1528 else if (ptr == NULL) | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1529 return _malloc_internal_nolock (size); |
| 17130 | 1530 |
| 1531 block = BLOCK (ptr); | |
| 1532 | |
|
32821
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
1533 PROTECT_MALLOC_STATE (0); |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
40670
diff
changeset
|
1534 |
| 17130 | 1535 type = _heapinfo[block].busy.type; |
| 1536 switch (type) | |
| 1537 { | |
| 1538 case 0: | |
| 1539 /* Maybe reallocate a large block to a small fragment. */ | |
| 1540 if (size <= BLOCKSIZE / 2) | |
| 1541 { | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1542 result = _malloc_internal_nolock (size); |
| 17130 | 1543 if (result != NULL) |
| 1544 { | |
| 1545 memcpy (result, ptr, size); | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1546 _free_internal_nolock (ptr); |
|
76776
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
1547 goto out; |
| 17130 | 1548 } |
| 1549 } | |
| 1550 | |
| 1551 /* The new size is a large allocation as well; | |
| 1552 see if we can hold it in place. */ | |
| 1553 blocks = BLOCKIFY (size); | |
| 1554 if (blocks < _heapinfo[block].busy.info.size) | |
| 1555 { | |
| 1556 /* The new size is smaller; return | |
| 1557 excess memory to the free list. */ | |
| 1558 _heapinfo[block + blocks].busy.type = 0; | |
| 1559 _heapinfo[block + blocks].busy.info.size | |
| 1560 = _heapinfo[block].busy.info.size - blocks; | |
| 1561 _heapinfo[block].busy.info.size = blocks; | |
| 1562 /* We have just created a new chunk by splitting a chunk in two. | |
| 1563 Now we will free this chunk; increment the statistics counter | |
| 1564 so it doesn't become wrong when _free_internal decrements it. */ | |
| 1565 ++_chunks_used; | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1566 _free_internal_nolock (ADDRESS (block + blocks)); |
| 17130 | 1567 result = ptr; |
| 1568 } | |
| 1569 else if (blocks == _heapinfo[block].busy.info.size) | |
| 1570 /* No size change necessary. */ | |
| 1571 result = ptr; | |
| 1572 else | |
| 1573 { | |
| 1574 /* Won't fit, so allocate a new region that will. | |
| 1575 Free the old region first in case there is sufficient | |
| 1576 adjacent free space to grow without moving. */ | |
| 1577 blocks = _heapinfo[block].busy.info.size; | |
| 1578 /* Prevent free from actually returning memory to the system. */ | |
| 1579 oldlimit = _heaplimit; | |
| 1580 _heaplimit = 0; | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1581 _free_internal_nolock (ptr); |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1582 result = _malloc_internal_nolock (size); |
|
32821
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
1583 PROTECT_MALLOC_STATE (0); |
| 17130 | 1584 if (_heaplimit == 0) |
| 1585 _heaplimit = oldlimit; | |
| 1586 if (result == NULL) | |
| 1587 { | |
| 1588 /* Now we're really in trouble. We have to unfree | |
| 1589 the thing we just freed. Unfortunately it might | |
| 1590 have been coalesced with its neighbors. */ | |
| 1591 if (_heapindex == block) | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1592 (void) _malloc_internal_nolock (blocks * BLOCKSIZE); |
| 17130 | 1593 else |
| 1594 { | |
| 1595 __ptr_t previous | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1596 = _malloc_internal_nolock ((block - _heapindex) * BLOCKSIZE); |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1597 (void) _malloc_internal_nolock (blocks * BLOCKSIZE); |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1598 _free_internal_nolock (previous); |
| 17130 | 1599 } |
|
76776
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
1600 goto out; |
| 17130 | 1601 } |
| 1602 if (ptr != result) | |
| 1603 memmove (result, ptr, blocks * BLOCKSIZE); | |
| 1604 } | |
| 1605 break; | |
| 1606 | |
| 1607 default: | |
| 1608 /* Old size is a fragment; type is logarithm | |
| 1609 to base two of the fragment size. */ | |
| 1610 if (size > (__malloc_size_t) (1 << (type - 1)) && | |
| 1611 size <= (__malloc_size_t) (1 << type)) | |
| 1612 /* The new size is the same kind of fragment. */ | |
| 1613 result = ptr; | |
| 1614 else | |
| 1615 { | |
| 1616 /* The new size is different; allocate a new space, | |
| 1617 and copy the lesser of the new size and the old. */ | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1618 result = _malloc_internal_nolock (size); |
| 17130 | 1619 if (result == NULL) |
|
76776
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
1620 goto out; |
| 17130 | 1621 memcpy (result, ptr, min (size, (__malloc_size_t) 1 << type)); |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1622 _free_internal_nolock (ptr); |
| 17130 | 1623 } |
| 1624 break; | |
| 1625 } | |
| 1626 | |
|
32821
08e5ab6d998f
(state_protected_p, last_state_size, last_heapinfo)
Gerd Moellmann <gerd@gnu.org>
parents:
32693
diff
changeset
|
1627 PROTECT_MALLOC_STATE (1); |
|
76776
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
1628 out: |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1629 return result; |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1630 } |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1631 |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1632 __ptr_t |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1633 _realloc_internal (ptr, size) |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1634 __ptr_t ptr; |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1635 __malloc_size_t size; |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1636 { |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1637 __ptr_t result; |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1638 |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1639 LOCK(); |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1640 result = _realloc_internal_nolock (ptr, size); |
|
76776
2bb28b957639
[HAVE_GTK_AND_PTHREAD]: Define USE_PTHREAD.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75348
diff
changeset
|
1641 UNLOCK (); |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1642 |
| 17130 | 1643 return result; |
| 1644 } | |
| 1645 | |
| 1646 __ptr_t | |
| 1647 realloc (ptr, size) | |
| 1648 __ptr_t ptr; | |
| 1649 __malloc_size_t size; | |
| 1650 { | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1651 __ptr_t (*hook) (__ptr_t, __malloc_size_t); |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1652 |
| 17130 | 1653 if (!__malloc_initialized && !__malloc_initialize ()) |
| 1654 return NULL; | |
| 1655 | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1656 hook = __realloc_hook; |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1657 return (hook != NULL ? *hook : _realloc_internal) (ptr, size); |
| 17130 | 1658 } |
| 1659 /* Copyright (C) 1991, 1992, 1994 Free Software Foundation, Inc. | |
| 1660 | |
| 1661 This library is free software; you can redistribute it and/or | |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1662 modify it under the terms of the GNU General Public License as |
| 17130 | 1663 published by the Free Software Foundation; either version 2 of the |
| 1664 License, or (at your option) any later version. | |
| 1665 | |
| 1666 This library is distributed in the hope that it will be useful, | |
| 1667 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 1668 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1669 General Public License for more details. |
| 17130 | 1670 |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1671 You should have received a copy of the GNU General Public |
|
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1672 License along with this library; see the file COPYING. If |
| 64092 | 1673 not, write to the Free Software Foundation, Inc., 51 Franklin Street, |
| 1674 Fifth Floor, Boston, MA 02110-1301, USA. | |
| 17130 | 1675 |
| 1676 The author may be reached (Email) at the address mike@ai.mit.edu, | |
| 1677 or (US mail) as Mike Haertel c/o Free Software Foundation. */ | |
| 1678 | |
| 1679 #ifndef _MALLOC_INTERNAL | |
| 1680 #define _MALLOC_INTERNAL | |
| 1681 #include <malloc.h> | |
| 1682 #endif | |
| 1683 | |
| 1684 /* Allocate an array of NMEMB elements each SIZE bytes long. | |
| 1685 The entire array is initialized to zeros. */ | |
| 1686 __ptr_t | |
| 1687 calloc (nmemb, size) | |
| 1688 register __malloc_size_t nmemb; | |
| 1689 register __malloc_size_t size; | |
| 1690 { | |
| 1691 register __ptr_t result = malloc (nmemb * size); | |
| 1692 | |
| 1693 if (result != NULL) | |
| 1694 (void) memset (result, 0, nmemb * size); | |
| 1695 | |
| 1696 return result; | |
| 1697 } | |
| 1698 /* Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. | |
| 1699 This file is part of the GNU C Library. | |
| 1700 | |
| 1701 The GNU C Library is free software; you can redistribute it and/or modify | |
| 1702 it under the terms of the GNU General Public License as published by | |
| 1703 the Free Software Foundation; either version 2, or (at your option) | |
| 1704 any later version. | |
| 1705 | |
| 1706 The GNU C Library is distributed in the hope that it will be useful, | |
| 1707 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 1708 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 1709 GNU General Public License for more details. | |
| 1710 | |
| 1711 You should have received a copy of the GNU General Public License | |
| 1712 along with the GNU C Library; see the file COPYING. If not, write to | |
| 64092 | 1713 the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, |
| 1714 MA 02110-1301, USA. */ | |
| 17130 | 1715 |
| 1716 #ifndef _MALLOC_INTERNAL | |
| 1717 #define _MALLOC_INTERNAL | |
| 1718 #include <malloc.h> | |
| 1719 #endif | |
| 1720 | |
| 1721 #ifndef __GNU_LIBRARY__ | |
| 1722 #define __sbrk sbrk | |
| 1723 #endif | |
| 1724 | |
| 1725 #ifdef __GNU_LIBRARY__ | |
| 1726 /* It is best not to declare this and cast its result on foreign operating | |
| 1727 systems with potentially hostile include files. */ | |
| 1728 | |
| 1729 #include <stddef.h> | |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
1730 extern __ptr_t __sbrk PP ((ptrdiff_t increment)); |
| 17130 | 1731 #endif |
| 1732 | |
| 1733 #ifndef NULL | |
| 1734 #define NULL 0 | |
| 1735 #endif | |
| 1736 | |
| 1737 /* Allocate INCREMENT more bytes of data space, | |
| 1738 and return the start of data space, or NULL on errors. | |
| 1739 If INCREMENT is negative, shrink data space. */ | |
| 1740 __ptr_t | |
| 1741 __default_morecore (increment) | |
| 1742 __malloc_ptrdiff_t increment; | |
| 1743 { | |
|
54824
54395b0b6779
(__default_morecore): Use bss_sbrk(), not __sbrk(), before Cygwin unexec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
1744 __ptr_t result; |
|
54395b0b6779
(__default_morecore): Use bss_sbrk(), not __sbrk(), before Cygwin unexec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
1745 #if defined(CYGWIN) |
|
54395b0b6779
(__default_morecore): Use bss_sbrk(), not __sbrk(), before Cygwin unexec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
1746 if (!bss_sbrk_did_unexec) |
|
54395b0b6779
(__default_morecore): Use bss_sbrk(), not __sbrk(), before Cygwin unexec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
1747 { |
|
54395b0b6779
(__default_morecore): Use bss_sbrk(), not __sbrk(), before Cygwin unexec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
1748 return bss_sbrk (increment); |
|
54395b0b6779
(__default_morecore): Use bss_sbrk(), not __sbrk(), before Cygwin unexec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
1749 } |
|
54395b0b6779
(__default_morecore): Use bss_sbrk(), not __sbrk(), before Cygwin unexec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
1750 #endif |
|
54395b0b6779
(__default_morecore): Use bss_sbrk(), not __sbrk(), before Cygwin unexec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
1751 result = (__ptr_t) __sbrk (increment); |
| 17130 | 1752 if (result == (__ptr_t) -1) |
| 1753 return NULL; | |
| 1754 return result; | |
| 1755 } | |
| 1756 /* Copyright (C) 1991, 92, 93, 94, 95, 96 Free Software Foundation, Inc. | |
| 1757 | |
| 1758 This library is free software; you can redistribute it and/or | |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1759 modify it under the terms of the GNU General Public License as |
| 17130 | 1760 published by the Free Software Foundation; either version 2 of the |
| 1761 License, or (at your option) any later version. | |
| 1762 | |
| 1763 This library is distributed in the hope that it will be useful, | |
| 1764 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 1765 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1766 General Public License for more details. |
| 17130 | 1767 |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1768 You should have received a copy of the GNU General Public |
|
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1769 License along with this library; see the file COPYING. If |
| 64092 | 1770 not, write to the Free Software Foundation, Inc., 51 Franklin Street, |
| 1771 Fifth Floor, Boston, MA 02110-1301, USA. */ | |
| 17130 | 1772 |
| 1773 #ifndef _MALLOC_INTERNAL | |
| 1774 #define _MALLOC_INTERNAL | |
| 1775 #include <malloc.h> | |
| 1776 #endif | |
| 1777 | |
| 1778 #if __DJGPP__ - 0 == 1 | |
| 1779 | |
| 1780 /* There is some problem with memalign in DJGPP v1 and we are supposed | |
| 1781 to omit it. Noone told me why, they just told me to do it. */ | |
| 1782 | |
| 1783 #else | |
| 1784 | |
|
37372
46942d9e7537
(__malloc_size_t) [__GNUC__]: If STDC_HEADERS is not
Eli Zaretskii <eliz@gnu.org>
parents:
37268
diff
changeset
|
1785 __ptr_t (*__memalign_hook) PP ((__malloc_size_t __size, |
|
46942d9e7537
(__malloc_size_t) [__GNUC__]: If STDC_HEADERS is not
Eli Zaretskii <eliz@gnu.org>
parents:
37268
diff
changeset
|
1786 __malloc_size_t __alignment)); |
| 17130 | 1787 |
| 1788 __ptr_t | |
| 1789 memalign (alignment, size) | |
| 1790 __malloc_size_t alignment; | |
| 1791 __malloc_size_t size; | |
| 1792 { | |
| 1793 __ptr_t result; | |
| 1794 unsigned long int adj, lastadj; | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1795 __ptr_t (*hook) (__malloc_size_t, __malloc_size_t) = __memalign_hook; |
| 17130 | 1796 |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1797 if (hook) |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1798 return (*hook) (alignment, size); |
| 17130 | 1799 |
| 1800 /* Allocate a block with enough extra space to pad the block with up to | |
| 1801 (ALIGNMENT - 1) bytes if necessary. */ | |
| 1802 result = malloc (size + alignment - 1); | |
| 1803 if (result == NULL) | |
| 1804 return NULL; | |
| 1805 | |
| 1806 /* Figure out how much we will need to pad this particular block | |
| 1807 to achieve the required alignment. */ | |
| 1808 adj = (unsigned long int) ((char *) result - (char *) NULL) % alignment; | |
| 1809 | |
| 1810 do | |
| 1811 { | |
| 1812 /* Reallocate the block with only as much excess as it needs. */ | |
| 1813 free (result); | |
| 1814 result = malloc (adj + size); | |
| 1815 if (result == NULL) /* Impossible unless interrupted. */ | |
| 1816 return NULL; | |
| 1817 | |
| 1818 lastadj = adj; | |
| 1819 adj = (unsigned long int) ((char *) result - (char *) NULL) % alignment; | |
| 1820 /* It's conceivable we might have been so unlucky as to get a | |
| 1821 different block with weaker alignment. If so, this block is too | |
| 1822 short to contain SIZE after alignment correction. So we must | |
| 1823 try again and get another block, slightly larger. */ | |
| 1824 } while (adj > lastadj); | |
| 1825 | |
| 1826 if (adj != 0) | |
| 1827 { | |
| 1828 /* Record this block in the list of aligned blocks, so that `free' | |
| 1829 can identify the pointer it is passed, which will be in the middle | |
| 1830 of an allocated block. */ | |
| 1831 | |
| 1832 struct alignlist *l; | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1833 LOCK_ALIGNED_BLOCKS (); |
| 17130 | 1834 for (l = _aligned_blocks; l != NULL; l = l->next) |
| 1835 if (l->aligned == NULL) | |
| 1836 /* This slot is free. Use it. */ | |
| 1837 break; | |
| 1838 if (l == NULL) | |
| 1839 { | |
| 1840 l = (struct alignlist *) malloc (sizeof (struct alignlist)); | |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1841 if (l != NULL) |
| 17130 | 1842 { |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1843 l->next = _aligned_blocks; |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1844 _aligned_blocks = l; |
| 17130 | 1845 } |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1846 } |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1847 if (l != NULL) |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1848 { |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1849 l->exact = result; |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1850 result = l->aligned = (char *) result + alignment - adj; |
| 17130 | 1851 } |
|
78051
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1852 UNLOCK_ALIGNED_BLOCKS (); |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1853 if (l == NULL) |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1854 { |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1855 free (result); |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1856 result = NULL; |
|
2c30fdff6890
[HAVE_GTK_AND_PTHREAD] Check this after including config.h.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
76776
diff
changeset
|
1857 } |
| 17130 | 1858 } |
| 1859 | |
| 1860 return result; | |
| 1861 } | |
| 1862 | |
| 1863 #endif /* Not DJGPP v1 */ | |
| 1864 /* Allocate memory on a page boundary. | |
| 1865 Copyright (C) 1991, 92, 93, 94, 96 Free Software Foundation, Inc. | |
| 1866 | |
| 1867 This library is free software; you can redistribute it and/or | |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1868 modify it under the terms of the GNU General Public License as |
| 17130 | 1869 published by the Free Software Foundation; either version 2 of the |
| 1870 License, or (at your option) any later version. | |
| 1871 | |
| 1872 This library is distributed in the hope that it will be useful, | |
| 1873 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 1874 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1875 General Public License for more details. |
| 17130 | 1876 |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1877 You should have received a copy of the GNU General Public |
|
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1878 License along with this library; see the file COPYING. If |
| 64092 | 1879 not, write to the Free Software Foundation, Inc., 51 Franklin Street, |
| 1880 Fifth Floor, Boston, MA 02110-1301, USA. | |
| 17130 | 1881 |
| 1882 The author may be reached (Email) at the address mike@ai.mit.edu, | |
| 1883 or (US mail) as Mike Haertel c/o Free Software Foundation. */ | |
| 1884 | |
| 1885 #if defined (_MALLOC_INTERNAL) && defined (GMALLOC_INHIBIT_VALLOC) | |
| 1886 | |
| 1887 /* Emacs defines GMALLOC_INHIBIT_VALLOC to avoid this definition | |
| 1888 on MSDOS, where it conflicts with a system header file. */ | |
| 1889 | |
| 1890 #define ELIDE_VALLOC | |
| 1891 | |
| 1892 #endif | |
| 1893 | |
| 1894 #ifndef ELIDE_VALLOC | |
| 1895 | |
| 1896 #if defined (__GNU_LIBRARY__) || defined (_LIBC) | |
| 1897 #include <stddef.h> | |
| 1898 #include <sys/cdefs.h> | |
|
17131
6ff1e0aec51e
[__GLIBC__ >= 2]: Don't declare __getpagesize.
Karl Heuer <kwzh@gnu.org>
parents:
17130
diff
changeset
|
1899 #if defined (__GLIBC__) && __GLIBC__ >= 2 |
|
6ff1e0aec51e
[__GLIBC__ >= 2]: Don't declare __getpagesize.
Karl Heuer <kwzh@gnu.org>
parents:
17130
diff
changeset
|
1900 /* __getpagesize is already declared in <unistd.h> with return type int */ |
|
6ff1e0aec51e
[__GLIBC__ >= 2]: Don't declare __getpagesize.
Karl Heuer <kwzh@gnu.org>
parents:
17130
diff
changeset
|
1901 #else |
|
18667
d4f53287fc5b
Rename macro __P to PP.
Richard M. Stallman <rms@gnu.org>
parents:
17131
diff
changeset
|
1902 extern size_t __getpagesize PP ((void)); |
|
17131
6ff1e0aec51e
[__GLIBC__ >= 2]: Don't declare __getpagesize.
Karl Heuer <kwzh@gnu.org>
parents:
17130
diff
changeset
|
1903 #endif |
| 17130 | 1904 #else |
| 1905 #include "getpagesize.h" | |
| 1906 #define __getpagesize() getpagesize() | |
| 1907 #endif | |
| 1908 | |
| 1909 #ifndef _MALLOC_INTERNAL | |
| 1910 #define _MALLOC_INTERNAL | |
| 1911 #include <malloc.h> | |
| 1912 #endif | |
| 1913 | |
| 1914 static __malloc_size_t pagesize; | |
| 1915 | |
| 1916 __ptr_t | |
| 1917 valloc (size) | |
| 1918 __malloc_size_t size; | |
| 1919 { | |
| 1920 if (pagesize == 0) | |
| 1921 pagesize = __getpagesize (); | |
| 1922 | |
| 1923 return memalign (pagesize, size); | |
| 1924 } | |
| 1925 | |
| 1926 #endif /* Not ELIDE_VALLOC. */ | |
|
32973
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1927 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1928 #ifdef GC_MCHECK |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1929 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1930 /* Standard debugging hooks for `malloc'. |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1931 Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1932 Written May 1989 by Mike Haertel. |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1933 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1934 This library is free software; you can redistribute it and/or |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1935 modify it under the terms of the GNU General Public License as |
|
32973
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1936 published by the Free Software Foundation; either version 2 of the |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1937 License, or (at your option) any later version. |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1938 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1939 This library is distributed in the hope that it will be useful, |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1940 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1941 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1942 General Public License for more details. |
|
32973
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1943 |
|
72951
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1944 You should have received a copy of the GNU General Public |
|
751c24f0ec88
Replace "GNU Library General Public License" by "GNU General Public
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68651
diff
changeset
|
1945 License along with this library; see the file COPYING. If |
| 64092 | 1946 not, write to the Free Software Foundation, Inc., 51 Franklin Street, |
| 1947 Fifth Floor, Boston, MA 02110-1301, USA. | |
|
32973
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1948 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1949 The author may be reached (Email) at the address mike@ai.mit.edu, |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1950 or (US mail) as Mike Haertel c/o Free Software Foundation. */ |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1951 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1952 #ifdef emacs |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1953 #include <stdio.h> |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1954 #else |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1955 #ifndef _MALLOC_INTERNAL |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1956 #define _MALLOC_INTERNAL |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1957 #include <malloc.h> |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1958 #include <stdio.h> |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1959 #endif |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1960 #endif |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1961 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1962 /* Old hook values. */ |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1963 static void (*old_free_hook) __P ((__ptr_t ptr)); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1964 static __ptr_t (*old_malloc_hook) __P ((__malloc_size_t size)); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1965 static __ptr_t (*old_realloc_hook) __P ((__ptr_t ptr, __malloc_size_t size)); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1966 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1967 /* Function to call when something awful happens. */ |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1968 static void (*abortfunc) __P ((enum mcheck_status)); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1969 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1970 /* Arbitrary magical numbers. */ |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1971 #define MAGICWORD 0xfedabeeb |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1972 #define MAGICFREE 0xd8675309 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1973 #define MAGICBYTE ((char) 0xd7) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1974 #define MALLOCFLOOD ((char) 0x93) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1975 #define FREEFLOOD ((char) 0x95) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1976 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1977 struct hdr |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1978 { |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1979 __malloc_size_t size; /* Exact size requested by user. */ |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1980 unsigned long int magic; /* Magic number to check header integrity. */ |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1981 }; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1982 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1983 #if defined(_LIBC) || defined(STDC_HEADERS) || defined(USG) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1984 #define flood memset |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1985 #else |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1986 static void flood __P ((__ptr_t, int, __malloc_size_t)); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1987 static void |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1988 flood (ptr, val, size) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1989 __ptr_t ptr; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1990 int val; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1991 __malloc_size_t size; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1992 { |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1993 char *cp = ptr; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1994 while (size--) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1995 *cp++ = val; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1996 } |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1997 #endif |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1998 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
1999 static enum mcheck_status checkhdr __P ((const struct hdr *)); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2000 static enum mcheck_status |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2001 checkhdr (hdr) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2002 const struct hdr *hdr; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2003 { |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2004 enum mcheck_status status; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2005 switch (hdr->magic) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2006 { |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2007 default: |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2008 status = MCHECK_HEAD; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2009 break; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2010 case MAGICFREE: |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2011 status = MCHECK_FREE; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2012 break; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2013 case MAGICWORD: |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2014 if (((char *) &hdr[1])[hdr->size] != MAGICBYTE) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2015 status = MCHECK_TAIL; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2016 else |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2017 status = MCHECK_OK; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2018 break; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2019 } |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2020 if (status != MCHECK_OK) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2021 (*abortfunc) (status); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2022 return status; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2023 } |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2024 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2025 static void freehook __P ((__ptr_t)); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2026 static void |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2027 freehook (ptr) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2028 __ptr_t ptr; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2029 { |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2030 struct hdr *hdr; |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
40670
diff
changeset
|
2031 |
|
32973
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2032 if (ptr) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2033 { |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2034 hdr = ((struct hdr *) ptr) - 1; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2035 checkhdr (hdr); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2036 hdr->magic = MAGICFREE; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2037 flood (ptr, FREEFLOOD, hdr->size); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2038 } |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2039 else |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2040 hdr = NULL; |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
40670
diff
changeset
|
2041 |
|
32973
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2042 __free_hook = old_free_hook; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2043 free (hdr); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2044 __free_hook = freehook; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2045 } |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2046 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2047 static __ptr_t mallochook __P ((__malloc_size_t)); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2048 static __ptr_t |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2049 mallochook (size) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2050 __malloc_size_t size; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2051 { |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2052 struct hdr *hdr; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2053 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2054 __malloc_hook = old_malloc_hook; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2055 hdr = (struct hdr *) malloc (sizeof (struct hdr) + size + 1); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2056 __malloc_hook = mallochook; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2057 if (hdr == NULL) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2058 return NULL; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2059 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2060 hdr->size = size; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2061 hdr->magic = MAGICWORD; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2062 ((char *) &hdr[1])[size] = MAGICBYTE; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2063 flood ((__ptr_t) (hdr + 1), MALLOCFLOOD, size); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2064 return (__ptr_t) (hdr + 1); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2065 } |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2066 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2067 static __ptr_t reallochook __P ((__ptr_t, __malloc_size_t)); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2068 static __ptr_t |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2069 reallochook (ptr, size) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2070 __ptr_t ptr; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2071 __malloc_size_t size; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2072 { |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2073 struct hdr *hdr = NULL; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2074 __malloc_size_t osize = 0; |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
40670
diff
changeset
|
2075 |
|
32973
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2076 if (ptr) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2077 { |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2078 hdr = ((struct hdr *) ptr) - 1; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2079 osize = hdr->size; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2080 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2081 checkhdr (hdr); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2082 if (size < osize) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2083 flood ((char *) ptr + size, FREEFLOOD, osize - size); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2084 } |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
40670
diff
changeset
|
2085 |
|
32973
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2086 __free_hook = old_free_hook; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2087 __malloc_hook = old_malloc_hook; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2088 __realloc_hook = old_realloc_hook; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2089 hdr = (struct hdr *) realloc ((__ptr_t) hdr, sizeof (struct hdr) + size + 1); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2090 __free_hook = freehook; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2091 __malloc_hook = mallochook; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2092 __realloc_hook = reallochook; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2093 if (hdr == NULL) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2094 return NULL; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2095 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2096 hdr->size = size; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2097 hdr->magic = MAGICWORD; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2098 ((char *) &hdr[1])[size] = MAGICBYTE; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2099 if (size > osize) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2100 flood ((char *) (hdr + 1) + osize, MALLOCFLOOD, size - osize); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2101 return (__ptr_t) (hdr + 1); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2102 } |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2103 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2104 static void |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2105 mabort (status) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2106 enum mcheck_status status; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2107 { |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2108 const char *msg; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2109 switch (status) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2110 { |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2111 case MCHECK_OK: |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2112 msg = "memory is consistent, library is buggy"; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2113 break; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2114 case MCHECK_HEAD: |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2115 msg = "memory clobbered before allocated block"; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2116 break; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2117 case MCHECK_TAIL: |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2118 msg = "memory clobbered past end of allocated block"; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2119 break; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2120 case MCHECK_FREE: |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2121 msg = "block freed twice"; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2122 break; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2123 default: |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2124 msg = "bogus mcheck_status, library is buggy"; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2125 break; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2126 } |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2127 #ifdef __GNU_LIBRARY__ |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2128 __libc_fatal (msg); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2129 #else |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2130 fprintf (stderr, "mcheck: %s\n", msg); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2131 fflush (stderr); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2132 abort (); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2133 #endif |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2134 } |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2135 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2136 static int mcheck_used = 0; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2137 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2138 int |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2139 mcheck (func) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2140 void (*func) __P ((enum mcheck_status)); |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2141 { |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2142 abortfunc = (func != NULL) ? func : &mabort; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2143 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2144 /* These hooks may not be safely inserted if malloc is already in use. */ |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2145 if (!__malloc_initialized && !mcheck_used) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2146 { |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2147 old_free_hook = __free_hook; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2148 __free_hook = freehook; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2149 old_malloc_hook = __malloc_hook; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2150 __malloc_hook = mallochook; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2151 old_realloc_hook = __realloc_hook; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2152 __realloc_hook = reallochook; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2153 mcheck_used = 1; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2154 } |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2155 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2156 return mcheck_used ? 0 : -1; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2157 } |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2158 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2159 enum mcheck_status |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2160 mprobe (__ptr_t ptr) |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2161 { |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2162 return mcheck_used ? checkhdr (ptr) : MCHECK_DISABLED; |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2163 } |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2164 |
|
c3f68b4d9e37
Add code from mcheck.c of glibc-1.09.1.
Gerd Moellmann <gerd@gnu.org>
parents:
32821
diff
changeset
|
2165 #endif /* GC_MCHECK */ |
| 52401 | 2166 |
| 2167 /* arch-tag: 93dce5c0-f49a-41b5-86b1-f91c4169c02e | |
| 2168 (do not change this comment) */ |
