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/ldso/dynlink.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/ldso') diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c index d689f96e..fa5ad004 100644 --- a/src/ldso/dynlink.c +++ b/src/ldso/dynlink.c @@ -783,6 +783,19 @@ void _dl_debug_state(void) { } +void __reset_tls() +{ + pthread_t self = __pthread_self(); + struct dso *p; + for (p=head; p; p=p->next) { + if (!p->tls_id || !self->dtv[p->tls_id]) continue; + memcpy(self->dtv[p->tls_id], p->tls_image, p->tls_len); + memset((char *)self->dtv[p->tls_id]+p->tls_len, 0, + p->tls_size - p->tls_len); + if (p->tls_id == (size_t)self->dtv[0]) break; + } +} + void *__copy_tls(unsigned char *mem) { pthread_t td; -- cgit v1.2.1