This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v2] malloc: Remove malloc hooks (Bug 23328)
- From: Florian Weimer <fw at deneb dot enyo dot de>
- To: Carlos O'Donell <carlos at redhat dot com>
- Cc: DJ Delorie <dj at redhat dot com>, GNU C Library <libc-alpha at sourceware dot org>, "Joseph S. Myers" <joseph at codesourcery dot com>
- Date: Mon, 02 Jul 2018 16:02:34 +0200
- Subject: Re: [PATCH v2] malloc: Remove malloc hooks (Bug 23328)
- References: <ddf39fca-aa0a-9b14-ee78-a1bfa1225623@redhat.com>
* Carlos O'Donell:
> +/* Call a hook function FUNC, and if recusion is detected return
> + with value ERV. In addition we check for
> + __glibc_malloc_check_requested to see if the runtime is waiting
> + to know if the hooks are active and if malloc_usable_size can
> + use the more accurate checking sizes for chunks. */
> +#define HOOK(func, erv) \
> + if (next_##func == NULL) \
> + { \
> + int r; \
> + r = atomic_load_acquire (&recursing); \
> + if (r) \
> + return erv; \
> + __typeof__ (next_##func) tmp; \
> + atomic_add (&recursing, 1); \
> + tmp = dlsym (RTLD_NEXT, #func); \
> + atomic_store_relaxed (&next_##func, tmp); \
> + if (tmp == NULL) \
> + abort (); \
> + atomic_add (&recursing, -1); \
> + atomic_store_relaxed (&__malloc_extras_initialized, 1); \
> + if (__glibc_malloc_check_request) \
> + __glibc_malloc_check_enable (); \
> + }
> +
> +void *
> +malloc (size_t sz)
> +{
> + void *rv;
> + size_t original_size = sz;
> + void *caller;
> + Dl_info info;
> +
> + void *(*hook) (size_t, const void *)
> + = atomic_forced_read (__glibc_malloc_hook);
> + if (__builtin_expect (hook != NULL, 0))
> + return (*hook) (sz, RETURN_ADDRESS (0));
Should this use atomic_load_relaxed instead?
> + HOOK (malloc, NULL);
I think you can simplify HOOK considerably if you always initialize
all function pointers. Then you don't need to use atomics there
because pthread_create always initializes malloc before creating new
threads.