about summary refs log tree commit diff
path: root/src/env/__reset_tls.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2015-11-12 15:50:26 -0500
committerRich Felker <dalias@aerifal.cx>2015-11-12 16:07:00 -0500
commitd56460c939c94a6c547abe8238f442b8de10bfbd (patch)
treeaaba49b1834dfdaafabb371d39bf4e1111935d18 /src/env/__reset_tls.c
parentad1cd43a86645ba2d4f7c8747240452a349d6bc1 (diff)
downloadmusl-d56460c939c94a6c547abe8238f442b8de10bfbd.tar.gz
musl-d56460c939c94a6c547abe8238f442b8de10bfbd.tar.xz
musl-d56460c939c94a6c547abe8238f442b8de10bfbd.zip
unify static and dynamic linked implementations of thread-local storage
this both allows removal of some of the main remaining uses of the
SHARED macro and clears one obstacle to static-linked dlopen support,
which may be added at some point in the future.

specialized single-TLS-module versions of __copy_tls and __reset_tls
are removed and replaced with code adapted from their dynamic-linked
versions, capable of operating on a whole chain of TLS modules, and
use of the dynamic linker's DSO chain (which contains large struct dso
objects) by these functions is replaced with a new chain of struct
tls_module objects containing only the information needed for
implementing TLS. this may also yield some performance benefit
initializing TLS for a new thread when a large number of modules
without TLS have been loaded, since since there is no need to walk
structures for modules without TLS.
Diffstat (limited to 'src/env/__reset_tls.c')
-rw-r--r--src/env/__reset_tls.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/env/__reset_tls.c b/src/env/__reset_tls.c
index bd61f311..677e57f5 100644
--- a/src/env/__reset_tls.c
+++ b/src/env/__reset_tls.c
@@ -1,21 +1,16 @@
-#ifndef SHARED
-
 #include <string.h>
 #include "pthread_impl.h"
-
-extern struct tls_image {
-	void *image;
-	size_t len, size, align;
-} __static_tls;
-
-#define T __static_tls
+#include "libc.h"
 
 void __reset_tls()
 {
-	if (!T.size) return;
 	pthread_t self = __pthread_self();
-	memcpy(self->dtv[1], T.image, T.len);
-	memset((char *)self->dtv[1]+T.len, 0, T.size-T.len);
+	struct tls_module *p;
+	size_t i, n = (size_t)self->dtv[0];
+	if (n) for (p=libc.tls_head, i=1; i<=n; i++, p=p->next) {
+		if (!self->dtv[i]) continue;
+		memcpy(self->dtv[i], p->image, p->len);
+		memset((char *)self->dtv[i]+p->len, 0,
+			p->size - p->len);
+	}
 }
-
-#endif