This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2] malloc: Remove malloc hooks (Bug 23328)


* 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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]