about summary refs log tree commit diff
path: root/malloc/hooks.c
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@sourceware.org>2021-07-22 18:38:02 +0530
committerSiddhesh Poyarekar <siddhesh@sourceware.org>2021-07-22 18:38:02 +0530
commitc142eb253f3814f46527e9b37484041dd85702cf (patch)
treeee11b3299370d97ca570aecebdae9f1f54debaaf /malloc/hooks.c
parent2d2d9f2b48a943fa556301db532103d09800da4d (diff)
downloadglibc-c142eb253f3814f46527e9b37484041dd85702cf.tar.gz
glibc-c142eb253f3814f46527e9b37484041dd85702cf.tar.xz
glibc-c142eb253f3814f46527e9b37484041dd85702cf.zip
mcheck: Wean away from malloc hooks [BZ #23489]
Split the mcheck implementation into the debugging hooks and API so
that the API can be replicated in libc and libc_malloc_debug.so.  The
libc APIs always result in failure.

The mcheck implementation has also been moved entirely into
libc_malloc_debug.so and with it, all of the hook initialization code
can now be moved into the debug library.  Now the initialization can
be done independently of libc internals.

With this patch, libc_malloc_debug.so can no longer be used with older
libcs, which is not its goal anyway.  tst-vfork3 breaks due to this
since it spawns shell scripts, which in turn execute using the system
glibc.  Move the test to tests-container so that only the built glibc
is used.

This move also fixes bugs in the mcheck version of memalign and
realloc, thus allowing removal of the tests from tests-mcheck
exclusion list.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'malloc/hooks.c')
-rw-r--r--malloc/hooks.c61
1 files changed, 3 insertions, 58 deletions
diff --git a/malloc/hooks.c b/malloc/hooks.c
index 3cd44eeb84..8e9fefe6c3 100644
--- a/malloc/hooks.c
+++ b/malloc/hooks.c
@@ -34,65 +34,10 @@ void *(*__morecore)(ptrdiff_t);
 compat_symbol (libc, __morecore, __morecore, GLIBC_2_0);
 #endif
 
-static void *malloc_hook_ini (size_t, const void *) __THROW;
-static void *realloc_hook_ini (void *, size_t, const void *) __THROW;
-static void *memalign_hook_ini (size_t, size_t, const void *) __THROW;
-
 void weak_variable (*__free_hook) (void *, const void *) = NULL;
-void *weak_variable (*__malloc_hook)
-  (size_t, const void *) = malloc_hook_ini;
-void *weak_variable (*__realloc_hook)
-  (void *, size_t, const void *) = realloc_hook_ini;
-void *weak_variable (*__memalign_hook)
-  (size_t, size_t, const void *) = memalign_hook_ini;
-
-/* Hooks for debugging versions.  The initial hooks just call the
-   initialization routine, then do the normal work. */
-
-/* These hooks will get executed only through the interposed allocator
-   functions in libc_malloc_debug.so.  This means that the calls to malloc,
-   realloc, etc. will lead back into the interposed functions, which is what we
-   want.
-
-   These initial hooks are assumed to be called in a single-threaded context,
-   so it is safe to reset all hooks at once upon initialization.  */
-
-static void
-generic_hook_ini (void)
-{
-  __malloc_hook = NULL;
-  __realloc_hook = NULL;
-  __memalign_hook = NULL;
-  ptmalloc_init ();
-
-#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_24)
-  void (*hook) (void) = atomic_forced_read (__malloc_initialize_hook);
-  if (hook != NULL)
-    (*hook)();
-#endif
-  __malloc_initialized = 1;
-}
-
-static void *
-malloc_hook_ini (size_t sz, const void *caller)
-{
-  generic_hook_ini ();
-  return malloc (sz);
-}
-
-static void *
-realloc_hook_ini (void *ptr, size_t sz, const void *caller)
-{
-  generic_hook_ini ();
-  return realloc (ptr, sz);
-}
-
-static void *
-memalign_hook_ini (size_t alignment, size_t sz, const void *caller)
-{
-  generic_hook_ini ();
-  return memalign (alignment, sz);
-}
+void *weak_variable (*__malloc_hook) (size_t, const void *) = NULL;
+void *weak_variable (*__realloc_hook) (void *, size_t, const void *) = NULL;
+void *weak_variable (*__memalign_hook) (size_t, size_t, const void *) = NULL;
 
 #include "malloc-check.c"