diff mbox series

[7/8] Remove __after_morecore_hook

Message ID 20210624182312.236596-8-siddhesh@sourceware.org
State Superseded
Headers show
Series Remove malloc hooks | expand

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Siddhesh Poyarekar June 24, 2021, 6:23 p.m. UTC
Remove __after_morecore_hook from the API and finalize the symbol so
that it can no longer be used in new applications.  Old applications
using __after_morecore_hook will find that their hook is no longer
called.
---
 malloc/hooks.c  |  3 +++
 malloc/malloc.c | 30 +-----------------------------
 malloc/malloc.h |  5 -----
 3 files changed, 4 insertions(+), 34 deletions(-)

Comments

DJ Delorie June 24, 2021, 11:33 p.m. UTC | #1
Siddhesh Poyarekar <siddhesh@sourceware.org> writes:
> Remove __after_morecore_hook from the API and finalize the symbol so
> that it can no longer be used in new applications.  Old applications
> using __after_morecore_hook will find that their hook is no longer
> called.

> diff --git a/malloc/hooks.c b/malloc/hooks.c
> index cc9ffc8b63..fa6b3f4c16 100644
> --- a/malloc/hooks.c
> +++ b/malloc/hooks.c
> @@ -78,6 +78,9 @@ compat_symbol (libc, __malloc_hook, __malloc_hook, GLIBC_2_0);
>  compat_symbol (libc, __realloc_hook, __realloc_hook, GLIBC_2_0);
>  compat_symbol (libc, __memalign_hook, __memalign_hook, GLIBC_2_0);
>  
> +void weak_variable (*__after_morecore_hook) (void) = NULL;
> +compat_symbol (libc, __after_morecore_hook, __after_morecore_hook, GLIBC_2_0);
> +

Ok.

> diff --git a/malloc/malloc.c b/malloc/malloc.c
> index 16ad933c66..51970105b5 100644
> --- a/malloc/malloc.c
> +++ b/malloc/malloc.c
> @@ -1988,16 +1988,6 @@ static void     malloc_consolidate (mstate);
>  
>  /* -------------- Early definitions for debugging hooks ---------------- */
>  
> -/* Define and initialize the hook variables.  These weak definitions must
> -   appear before any use of the variables in a function (arena.c uses one).  */
> -#ifndef weak_variable
> -/* In GNU libc we want the hook variables to be weak definitions to
> -   avoid a problem with Emacs.  */
> -# define weak_variable weak_function
> -#endif
> -
> -void weak_variable (*__after_morecore_hook) (void) = NULL;
> -

Ok.

> @@ -2622,14 +2612,7 @@ sysmalloc (INTERNAL_SIZE_T nb, mstate av)
>            LIBC_PROBE (memory_sbrk_more, 2, brk, size);
>          }
>  
> -      if (brk != (char *) (MORECORE_FAILURE))
> -        {
> -          /* Call the `morecore' hook if necessary.  */
> -          void (*hook) (void) = atomic_forced_read (__after_morecore_hook);
> -          if (__builtin_expect (hook != NULL, 0))
> -            (*hook)();
> -        }
> -      else
> +      if (brk == (char *) (MORECORE_FAILURE))

Ok.

> @@ -2768,13 +2751,6 @@ sysmalloc (INTERNAL_SIZE_T nb, mstate av)
>                        correction = 0;
>                        snd_brk = (char *) (MORECORE (0));
>                      }
> -                  else
> -                    {
> -                      /* Call the `morecore' hook if necessary.  */
> -                      void (*hook) (void) = atomic_forced_read (__after_morecore_hook);
> -                      if (__builtin_expect (hook != NULL, 0))
> -                        (*hook)();
> -                    }

Ok.

> @@ -2933,10 +2909,6 @@ systrim (size_t pad, mstate av)
>         */
>  
>        MORECORE (-extra);
> -      /* Call the `morecore' hook if necessary.  */
> -      void (*hook) (void) = atomic_forced_read (__after_morecore_hook);
> -      if (__builtin_expect (hook != NULL, 0))
> -        (*hook)();
>        new_brk = (char *) (MORECORE (0));

Ok.

> diff --git a/malloc/malloc.h b/malloc/malloc.h
> index 709fa454b5..d066a05d82 100644
> --- a/malloc/malloc.h
> +++ b/malloc/malloc.h
> @@ -164,10 +164,5 @@ extern void malloc_stats (void) __THROW;
>  /* Output information about state of allocator to stream FP.  */
>  extern int malloc_info (int __options, FILE *__fp) __THROW;
>  
> -/* Hooks for debugging and user-defined versions. */
> -extern void (*__MALLOC_HOOK_VOLATILE __after_morecore_hook) (void)
> -  __MALLOC_DEPRECATED;
> -
> -
>  __END_DECLS
>  #endif /* malloc.h */

Ok.

LGTM
Reviewed-by: DJ Delorie <dj@redhat.com>
diff mbox series

Patch

diff --git a/malloc/hooks.c b/malloc/hooks.c
index cc9ffc8b63..fa6b3f4c16 100644
--- a/malloc/hooks.c
+++ b/malloc/hooks.c
@@ -78,6 +78,9 @@  compat_symbol (libc, __malloc_hook, __malloc_hook, GLIBC_2_0);
 compat_symbol (libc, __realloc_hook, __realloc_hook, GLIBC_2_0);
 compat_symbol (libc, __memalign_hook, __memalign_hook, GLIBC_2_0);
 
+void weak_variable (*__after_morecore_hook) (void) = NULL;
+compat_symbol (libc, __after_morecore_hook, __after_morecore_hook, GLIBC_2_0);
+
 /* These hooks will get executed only through the interposed allocator
    functions in libmalloc_compathooks.  This means that the calls to malloc,
    realloc, etc. will lead back into the interposed functions, which is what we
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 16ad933c66..51970105b5 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -1988,16 +1988,6 @@  static void     malloc_consolidate (mstate);
 
 /* -------------- Early definitions for debugging hooks ---------------- */
 
-/* Define and initialize the hook variables.  These weak definitions must
-   appear before any use of the variables in a function (arena.c uses one).  */
-#ifndef weak_variable
-/* In GNU libc we want the hook variables to be weak definitions to
-   avoid a problem with Emacs.  */
-# define weak_variable weak_function
-#endif
-
-void weak_variable (*__after_morecore_hook) (void) = NULL;
-
 /* This function is called from the arena shutdown hook, to free the
    thread cache (if it exists).  */
 static void tcache_thread_shutdown (void);
@@ -2622,14 +2612,7 @@  sysmalloc (INTERNAL_SIZE_T nb, mstate av)
           LIBC_PROBE (memory_sbrk_more, 2, brk, size);
         }
 
-      if (brk != (char *) (MORECORE_FAILURE))
-        {
-          /* Call the `morecore' hook if necessary.  */
-          void (*hook) (void) = atomic_forced_read (__after_morecore_hook);
-          if (__builtin_expect (hook != NULL, 0))
-            (*hook)();
-        }
-      else
+      if (brk == (char *) (MORECORE_FAILURE))
         {
           /*
              If have mmap, try using it as a backup when MORECORE fails or
@@ -2768,13 +2751,6 @@  sysmalloc (INTERNAL_SIZE_T nb, mstate av)
                       correction = 0;
                       snd_brk = (char *) (MORECORE (0));
                     }
-                  else
-                    {
-                      /* Call the `morecore' hook if necessary.  */
-                      void (*hook) (void) = atomic_forced_read (__after_morecore_hook);
-                      if (__builtin_expect (hook != NULL, 0))
-                        (*hook)();
-                    }
                 }
 
               /* handle non-contiguous cases */
@@ -2933,10 +2909,6 @@  systrim (size_t pad, mstate av)
        */
 
       MORECORE (-extra);
-      /* Call the `morecore' hook if necessary.  */
-      void (*hook) (void) = atomic_forced_read (__after_morecore_hook);
-      if (__builtin_expect (hook != NULL, 0))
-        (*hook)();
       new_brk = (char *) (MORECORE (0));
 
       LIBC_PROBE (memory_sbrk_less, 2, new_brk, extra);
diff --git a/malloc/malloc.h b/malloc/malloc.h
index 709fa454b5..d066a05d82 100644
--- a/malloc/malloc.h
+++ b/malloc/malloc.h
@@ -164,10 +164,5 @@  extern void malloc_stats (void) __THROW;
 /* Output information about state of allocator to stream FP.  */
 extern int malloc_info (int __options, FILE *__fp) __THROW;
 
-/* Hooks for debugging and user-defined versions. */
-extern void (*__MALLOC_HOOK_VOLATILE __after_morecore_hook) (void)
-  __MALLOC_DEPRECATED;
-
-
 __END_DECLS
 #endif /* malloc.h */