From 7c6c290695cb8726e876ff4fb8413913f661fc0b Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 3 Aug 2013 16:27:30 -0400 Subject: add system for resetting TLS to initial values this is needed for reused threads in the SIGEV_THREAD timer notification system, and could be reused elsewhere in the future if needed, though it should be refactored for such use. for static linking, __init_tls.c is simply modified to export the TLS info in a structure with external linkage, rather than using statics. this perhaps makes the code more clear, since the statics were poorly named for statics. the new __reset_tls.c is only linked if it is used. for dynamic linking, the code is in dynlink.c. sharing code with __copy_tls is not practical since __reset_tls must also re-zero thread-local bss. --- src/env/__reset_tls.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/env/__reset_tls.c (limited to 'src/env/__reset_tls.c') diff --git a/src/env/__reset_tls.c b/src/env/__reset_tls.c new file mode 100644 index 00000000..28c4405e --- /dev/null +++ b/src/env/__reset_tls.c @@ -0,0 +1,22 @@ +#ifndef SHARED + +#include +#include "pthread_impl.h" +#include "libc.h" + +extern struct tls_image { + void *image; + size_t len, size, align; +} __static_tls ATTR_LIBC_VISIBILITY; + +#define T __static_tls + +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); +} + +#endif -- cgit v1.2.1