Fix: pre-fault TLS in ust-malloc instrumentation
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 26 Jul 2016 20:54:55 +0000 (16:54 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 26 Jul 2016 20:58:09 +0000 (16:58 -0400)
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 <mathieu.desnoyers@efficios.com>
liblttng-ust-libc-wrapper/lttng-ust-malloc.c

index 5d290445026575f15de5074cb33f696be62c09c1..f3e1e19e28e52d8d5fe07d399f6c4741d0d87282 100644 (file)
@@ -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.
This page took 0.02584 seconds and 4 git commands to generate.