#endif
+static size_t __libc_pagesize;
+
#define MORECORE (*__morecore)
#define MORECORE_FAILURE 0
#define MORECORE_CLEARS 1
#define mremap __mremap
#define mprotect __mprotect
#undef malloc_getpagesize
-#define malloc_getpagesize __getpagesize()
+#define malloc_getpagesize __libc_pagesize
#else /* _LIBC */
/* Initialize the pthreads interface. */
if (__pthread_initialize != NULL)
__pthread_initialize();
+ __libc_pagesize = __getpagesize();
#endif
mutex_init(&main_arena.mutex);
mutex_init(&list_lock);
__free_hook = free_check;
__realloc_hook = realloc_check;
__memalign_hook = memalign_check;
- if(check_action == 1)
+ if(check_action & 1)
fprintf(stderr, "malloc: using debugging hooks\n");
}
the heap contents are saved/restored via some other method. The
primary example for this is GNU Emacs with its `dumping' procedure.
`Hook' function pointers are never saved or restored by these
- functions. */
+ functions, with two exceptions: If malloc checking was in use when
+ malloc_get_state() was called, then malloc_set_state() calls
+ __malloc_check_init() if possible; if malloc checking was not in
+ use in the recorded state but the user requested malloc checking,
+ then the hooks are reset to 0. */
#define MALLOC_STATE_MAGIC 0x444c4541l
#define MALLOC_STATE_VERSION (0*0x100l + 1l) /* major*0x100 + minor */
/* add version-dependent code here */
if (ms->version >= 1) {
#if defined _LIBC || defined MALLOC_HOOKS
- /* Check whether it is safe to enable malloc checking. */
+ /* Check whether it is safe to enable malloc checking, or whether
+ it is necessary to disable it. */
if (ms->using_malloc_checking && !using_malloc_checking &&
!disallow_malloc_check)
__malloc_check_init ();
+ else if (!ms->using_malloc_checking && using_malloc_checking) {
+ __malloc_hook = 0;
+ __free_hook = 0;
+ __realloc_hook = 0;
+ __memalign_hook = 0;
+ using_malloc_checking = 0;
+ }
#endif
}
if((char*)t + chunksize(t) == sbrk_base + sbrked_mem ||
t == initial_top(&main_arena)) return 0;
- switch(check_action) {
- case 1:
+ if(check_action & 1)
fprintf(stderr, "malloc: top chunk is corrupt\n");
- break;
- case 2:
+ if(check_action & 2)
abort();
- }
+
/* Try to set up a new top chunk. */
brk = MORECORE(0);
front_misalign = (unsigned long)chunk2mem(brk) & MALLOC_ALIGN_MASK;
p = mem2chunk_check(mem);
if(!p) {
(void)mutex_unlock(&main_arena.mutex);
- switch(check_action) {
- case 1:
+ if(check_action & 1)
fprintf(stderr, "free(): invalid pointer %p!\n", mem);
- break;
- case 2:
+ if(check_action & 2)
abort();
- }
return;
}
#if HAVE_MMAP