From: Mathieu Desnoyers Date: Tue, 26 Jul 2016 20:54:55 +0000 (-0400) Subject: Fix: pre-fault TLS in ust-malloc instrumentation X-Git-Tag: v2.9.0-rc1~27 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=f4a90c3e8f3f5e8dd5c1896afb82fa96c1a32f22;p=lttng-ust.git Fix: pre-fault TLS in ust-malloc instrumentation Faulting the TLS variable when accessed for the first time can trigger deadlocks with internal libc lock when using the liblttng-ust-malloc wrapper. Fix this by pre-faulting it in a library constructor, similarly to the approach taken for all other TLS variables in lttng-ust. Signed-off-by: Mathieu Desnoyers --- diff --git a/liblttng-ust-libc-wrapper/lttng-ust-malloc.c b/liblttng-ust-libc-wrapper/lttng-ust-malloc.c index 5d290445..f3e1e19e 100644 --- a/liblttng-ust-libc-wrapper/lttng-ust-malloc.c +++ b/liblttng-ust-libc-wrapper/lttng-ust-malloc.c @@ -421,6 +421,12 @@ int posix_memalign(void **memptr, size_t alignment, size_t size) return retval; } +static +void lttng_ust_fixup_malloc_nesting_tls(void) +{ + asm volatile ("" : : "m" (URCU_TLS(malloc_nesting))); +} + __attribute__((constructor)) void lttng_ust_malloc_wrapper_init(void) { @@ -428,6 +434,7 @@ void lttng_ust_malloc_wrapper_init(void) if (cur_alloc.calloc) { return; } + lttng_ust_fixup_malloc_nesting_tls(); /* * Ensure the allocator is in place before the process becomes * multithreaded.