From 11dc92881a4e8cd59ed66387a0fbe9b409d88f79 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 26 Jul 2016 16:54:55 -0400 Subject: [PATCH] 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 --- liblttng-ust-libc-wrapper/lttng-ust-malloc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/liblttng-ust-libc-wrapper/lttng-ust-malloc.c b/liblttng-ust-libc-wrapper/lttng-ust-malloc.c index d1ad3cf5..d91813e7 100644 --- a/liblttng-ust-libc-wrapper/lttng-ust-malloc.c +++ b/liblttng-ust-libc-wrapper/lttng-ust-malloc.c @@ -416,6 +416,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) { @@ -423,6 +429,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. -- 2.34.1