From: Siddhesh Poyarekar <siddhesh@sourceware.org>
To: DJ Delorie <dj@redhat.com>
Cc: fweimer@redhat.com, libc-alpha@sourceware.org
Subject: Re: [PATCH 6/8] Remove malloc hooks
Date: Mon, 28 Jun 2021 12:07:15 +0530 [thread overview]
Message-ID: <d40f25f8-3952-cd13-e611-cf700370a967@sourceware.org> (raw)
In-Reply-To: <xnzgve6dqx.fsf@greed.delorie.com>
On 6/25/21 5:01 AM, DJ Delorie via Libc-alpha wrote:
>> diff --git a/malloc/hooks.c b/malloc/hooks.c
>> index 492e9aac63..cc9ffc8b63 100644
>> --- a/malloc/hooks.c
>> +++ b/malloc/hooks.c
>> @@ -42,23 +42,84 @@ enum malloc_debug_hooks
>> static unsigned __malloc_debugging_hooks;
>>
>> /* Forward declarations. */
>> +static void ptmalloc_init (void);
>>
>> -#if HAVE_MALLOC_INIT_HOOK
>> +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_24)
>
> 2_24? Not 2_34?
__malloc_initialize_hook was made compat in 2.24.
>> void (*__malloc_initialize_hook) (void) __attribute__ ((nocommon));
>> compat_symbol (libc, __malloc_initialize_hook,
>> __malloc_initialize_hook, GLIBC_2_0);
>> +
>> +# define MALLOC_INIT_HOOK() ({ \
>> + void (*hook) (void) = atomic_forced_read (__malloc_initialize_hook); \
>> + if (hook != NULL) \
>> + (*hook)(); \
>> +})
>> +#else
>> +# define MALLOC_INIT_HOOK()
>> #endif
>
> Ok.
>
>> +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_34)
>> +
>> +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 *__ptr,
>> const void *) = NULL;
>> void *weak_variable (*__malloc_hook)
>> - (size_t __size, const void *) = NULL;
>> + (size_t __size, const void *) = malloc_hook_ini;
>> void *weak_variable (*__realloc_hook)
>> - (void *__ptr, size_t __size, const void *) = NULL;
>> + (void *__ptr, size_t __size, const void *) = realloc_hook_ini;
>> void *weak_variable (*__memalign_hook)
>> - (size_t __alignment, size_t __size, const void *) = NULL;
>> + (size_t __alignment, size_t __size, const void *) = memalign_hook_ini;
>>
>> -static void ptmalloc_init (void);
>> +compat_symbol (libc, __free_hook, __free_hook, GLIBC_2_0);
>> +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);
>> +
>> +/* 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
>> + 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;
>> + if (__malloc_initialized < 0)
>> + {
>> + ptmalloc_init ();
>> + MALLOC_INIT_HOOK ();
>> + }
>> +}
>> +
>> +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);
>> +}
>> +#endif
>
> Ok. Why not free_hook?
free_hook started out as NULL, so there's no need to reset it. It also
cannot legitimately be the first malloc function to be called (except
with NULL, which is a nop anyway)
Siddhesh
next prev parent reply other threads:[~2021-06-28 6:37 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-24 18:23 [PATCH 0/8] " Siddhesh Poyarekar
2021-06-24 18:23 ` [PATCH 1/8] Move glibc.malloc.check implementation into its own file Siddhesh Poyarekar
2021-06-24 19:57 ` DJ Delorie
2021-06-28 4:34 ` Siddhesh Poyarekar
2021-06-24 18:23 ` [PATCH 2/8] malloc: Move malloc hook references to hooks.c Siddhesh Poyarekar
2021-06-24 21:10 ` DJ Delorie
2021-06-24 18:23 ` [PATCH 3/8] glibc.malloc.check: Wean away from malloc hooks Siddhesh Poyarekar
2021-06-24 21:43 ` DJ Delorie
2021-06-24 18:23 ` [PATCH 4/8] mcheck: " Siddhesh Poyarekar
2021-06-24 22:51 ` DJ Delorie
2021-06-28 6:22 ` Siddhesh Poyarekar
2021-06-24 18:23 ` [PATCH 5/8] mtrace: " Siddhesh Poyarekar
2021-06-24 23:13 ` DJ Delorie
2021-06-28 6:25 ` Siddhesh Poyarekar
2021-06-24 18:23 ` [PATCH 6/8] Remove " Siddhesh Poyarekar
2021-06-24 23:31 ` DJ Delorie
2021-06-28 6:37 ` Siddhesh Poyarekar [this message]
2021-06-24 18:23 ` [PATCH 7/8] Remove __after_morecore_hook Siddhesh Poyarekar
2021-06-24 23:33 ` DJ Delorie
2021-06-24 18:23 ` [PATCH 8/8] Remove __morecore and __default_morecore Siddhesh Poyarekar
2021-06-24 23:38 ` DJ Delorie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d40f25f8-3952-cd13-e611-cf700370a967@sourceware.org \
--to=siddhesh@sourceware.org \
--cc=dj@redhat.com \
--cc=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).