From dcd60371500a74d489372cac7240674c992c2484 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Fri, 5 Oct 2012 11:51:50 -0400 Subject: support for TLS in dynamic-loaded (dlopen) modules unlike other implementations, this one reserves memory for new TLS in all pre-existing threads at dlopen-time, and dlopen will fail with no resources consumed and no new libraries loaded if memory is not available. memory is not immediately distributed to running threads; that would be too complex and too costly. instead, assurances are made that threads needing the new TLS can obtain it in an async-signal-safe way from a buffer belonging to the dynamic linker/new module (via atomic fetch-and-add based allocator). I've re-appropriated the lock that was previously used for __synccall (synchronizing set*id() syscalls between threads) as a general pthread_create lock. it's a "backwards" rwlock where the "read" operation is safe atomic modification of the live thread count, which multiple threads can perform at the same time, and the "write" operation is making sure the count does not increase during an operation that depends on it remaining bounded (__synccall or dlopen). in static-linked programs that don't use __synccall, this lock is a no-op and has no cost. --- src/env/__init_tls.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/env') diff --git a/src/env/__init_tls.c b/src/env/__init_tls.c index aff388bd..b19bdb64 100644 --- a/src/env/__init_tls.c +++ b/src/env/__init_tls.c @@ -9,7 +9,7 @@ static void *image; static size_t len, size, align; -void *__copy_tls(unsigned char *mem, size_t cnt) +void *__copy_tls(unsigned char *mem) { mem += -size & (4*sizeof(size_t)-1); mem += ((uintptr_t)image - (uintptr_t)mem) & (align-1); @@ -64,7 +64,7 @@ void __init_tls(size_t *auxv) MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); if (mem == MAP_FAILED) a_crash(); - if (!__install_initial_tls(__copy_tls(mem, 0))) a_crash(); + if (!__install_initial_tls(__copy_tls(mem))) a_crash(); } #else void __init_tls(size_t *auxv) { } -- cgit v1.2.1