diff options
author | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2021-07-22 18:38:08 +0530 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2021-07-22 18:38:08 +0530 |
commit | b5bd5bfe88f496463ec9fab680a8edf64d7c2a42 (patch) | |
tree | 51978efe075143c64fcd622b051faa49572928db /malloc/malloc.c | |
parent | 9dad716d4d2993f50b165747781244bd7c43bc95 (diff) | |
download | glibc-b5bd5bfe88f496463ec9fab680a8edf64d7c2a42.tar.gz glibc-b5bd5bfe88f496463ec9fab680a8edf64d7c2a42.tar.xz glibc-b5bd5bfe88f496463ec9fab680a8edf64d7c2a42.zip |
glibc.malloc.check: Wean away from malloc hooks
The malloc-check debugging feature is tightly integrated into glibc malloc, so thanks to an idea from Florian Weimer, much of the malloc implementation has been moved into libc_malloc_debug.so to support malloc-check. Due to this, glibc malloc and malloc-check can no longer work together; they use altogether different (but identical) structures for heap management. This should not make a difference though since the malloc check hook is not disabled anywhere. malloc_set_state does, but it does so early enough that it shouldn't cause any problems. The malloc check tunable is now in the debug DSO and has no effect when the DSO is not preloaded. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'malloc/malloc.c')
-rw-r--r-- | malloc/malloc.c | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/malloc/malloc.c b/malloc/malloc.c index ed0316e690..b8fcb2f2d3 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -288,6 +288,7 @@ #define MALLOC_DEBUG 0 #endif +#if IS_IN (libc) #ifndef NDEBUG # define __assert_fail(assertion, file, line, function) \ __malloc_assert(assertion, file, line, function) @@ -307,6 +308,7 @@ __malloc_assert (const char *assertion, const char *file, unsigned int line, abort (); } #endif +#endif #if USE_TCACHE /* We want 64 entries. This is an arbitrary limit, which tunables can reduce. */ @@ -592,6 +594,7 @@ tag_at (void *ptr) /* ---------- description of public routines ------------ */ +#if IS_IN (libc) /* malloc(size_t n) Returns a pointer to a newly allocated chunk of at least n bytes, or null @@ -815,6 +818,7 @@ void __malloc_stats(void); POSIX wrapper like memalign(), checking for validity of size. */ int __posix_memalign(void **, size_t, size_t); +#endif /* IS_IN (libc) */ /* mallopt tuning options */ @@ -1106,24 +1110,17 @@ static void _int_free(mstate, mchunkptr, int); static void* _int_realloc(mstate, mchunkptr, INTERNAL_SIZE_T, INTERNAL_SIZE_T); static void* _int_memalign(mstate, size_t, size_t); +#if IS_IN (libc) static void* _mid_memalign(size_t, size_t, void *); +#endif static void malloc_printerr(const char *str) __attribute__ ((noreturn)); -static void* mem2mem_check(void *p, size_t sz); -static void top_check(void); static void munmap_chunk(mchunkptr p); #if HAVE_MREMAP static mchunkptr mremap_chunk(mchunkptr p, size_t new_size); #endif -static void* malloc_check(size_t sz, const void *caller); -static void free_check(void* mem, const void *caller); -static void* realloc_check(void* oldmem, size_t bytes, - const void *caller); -static void* memalign_check(size_t alignment, size_t bytes, - const void *caller); - /* ------------------ MMAP support ------------------ */ @@ -2385,7 +2382,9 @@ do_check_malloc_state (mstate av) /* ----------------- Support for debugging hooks -------------------- */ +#if IS_IN (libc) #include "hooks.c" +#endif /* ----------- Routines dealing with system allocation -------------- */ @@ -3186,6 +3185,7 @@ tcache_thread_shutdown (void) #endif /* !USE_TCACHE */ +#if IS_IN (libc) void * __libc_malloc (size_t bytes) { @@ -3686,6 +3686,7 @@ __libc_calloc (size_t n, size_t elem_size) return mem; } +#endif /* IS_IN (libc) */ /* ------------------------------ malloc ------------------------------ @@ -5054,9 +5055,6 @@ musable (void *mem) p = mem2chunk (mem); - if (__builtin_expect (using_malloc_checking == 1, 0)) - return malloc_check_get_size (p); - if (chunk_is_mmapped (p)) { if (DUMPED_MAIN_ARENA_CHUNK (p)) @@ -5072,7 +5070,7 @@ musable (void *mem) return 0; } - +#if IS_IN (libc) size_t __malloc_usable_size (void *m) { @@ -5081,12 +5079,12 @@ __malloc_usable_size (void *m) result = musable (m); return result; } +#endif /* ------------------------------ mallinfo ------------------------------ Accumulate malloc statistics for arena AV into M. */ - static void int_mallinfo (mstate av, struct mallinfo2 *m) { @@ -5585,10 +5583,15 @@ extern char **__libc_argv attribute_hidden; static void malloc_printerr (const char *str) { +#if IS_IN (libc) __libc_message (do_abort, "%s\n", str); +#else + __libc_fatal (str); +#endif __builtin_unreachable (); } +#if IS_IN (libc) /* We need a wrapper function for one of the additions of POSIX. */ int __posix_memalign (void **memptr, size_t alignment, size_t size) @@ -5618,6 +5621,7 @@ __posix_memalign (void **memptr, size_t alignment, size_t size) return ENOMEM; } weak_alias (__posix_memalign, posix_memalign) +#endif int @@ -5821,9 +5825,9 @@ __malloc_info (int options, FILE *fp) return 0; } +#if IS_IN (libc) weak_alias (__malloc_info, malloc_info) - strong_alias (__libc_calloc, __calloc) weak_alias (__libc_calloc, calloc) strong_alias (__libc_free, __free) strong_alias (__libc_free, free) strong_alias (__libc_malloc, __malloc) strong_alias (__libc_malloc, malloc) @@ -5841,6 +5845,7 @@ strong_alias (__libc_mallopt, __mallopt) weak_alias (__libc_mallopt, mallopt) weak_alias (__malloc_stats, malloc_stats) weak_alias (__malloc_usable_size, malloc_usable_size) weak_alias (__malloc_trim, malloc_trim) +#endif #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_26) compat_symbol (libc, __libc_free, cfree, GLIBC_2_0); |