From ca3cfe473f54b36adf014a42d55d46b968e8ef77 Mon Sep 17 00:00:00 2001 From: davidxu Date: Fri, 27 Aug 2010 05:20:22 +0000 Subject: Unregister thread specific data destructor when a corresponding dso is unloaded. --- lib/libthr/thread/thr_fork.c | 1 + lib/libthr/thread/thr_private.h | 1 + lib/libthr/thread/thr_spec.c | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+) (limited to 'lib') diff --git a/lib/libthr/thread/thr_fork.c b/lib/libthr/thread/thr_fork.c index b1c221e..f20942d 100644 --- a/lib/libthr/thread/thr_fork.c +++ b/lib/libthr/thread/thr_fork.c @@ -114,6 +114,7 @@ __pthread_cxa_finalize(struct dl_phdr_info *phdr_info) } } THR_UMUTEX_UNLOCK(curthread, &_thr_atfork_lock); + _thr_tsd_unload(phdr_info); } __weak_reference(_fork, fork); diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h index f92913b..f261810 100644 --- a/lib/libthr/thread/thr_private.h +++ b/lib/libthr/thread/thr_private.h @@ -739,6 +739,7 @@ _thr_check_init(void) struct dl_phdr_info; void __pthread_cxa_finalize(struct dl_phdr_info *phdr_info); +void _thr_tsd_unload(struct dl_phdr_info *phdr_info) __hidden; __END_DECLS diff --git a/lib/libthr/thread/thr_spec.c b/lib/libthr/thread/thr_spec.c index 0740d6b..86dc794 100644 --- a/lib/libthr/thread/thr_spec.c +++ b/lib/libthr/thread/thr_spec.c @@ -36,6 +36,7 @@ #include #include #include "un-namespace.h" +#include "libc_private.h" #include "thr_private.h" @@ -235,3 +236,23 @@ _pthread_getspecific(pthread_key_t key) data = NULL; return (__DECONST(void *, data)); } + +void +_thr_tsd_unload(struct dl_phdr_info *phdr_info) +{ + struct pthread *curthread = _get_curthread(); + void (*destructor)(void *); + int key; + + THR_LOCK_ACQUIRE(curthread, &_keytable_lock); + for (key = 0; key < PTHREAD_KEYS_MAX; key++) { + if (_thread_keytable[key].allocated) { + destructor = _thread_keytable[key].destructor; + if (destructor != NULL) { + if (__elf_phdr_match_addr(phdr_info, destructor)) + _thread_keytable[key].destructor = NULL; + } + } + } + THR_LOCK_RELEASE(curthread, &_keytable_lock); +} -- cgit v1.1