summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_tls_get_addr.cc
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2014-04-16 09:07:27 +0000
committerKostya Serebryany <kcc@google.com>2014-04-16 09:07:27 +0000
commit7fc4c57d8c3c80cc8f7967fa93c924a15142299f (patch)
tree93ef7b8ac5b7fc9c2326e8ac5777725503cac431 /lib/sanitizer_common/sanitizer_tls_get_addr.cc
parent170ad114f2d633267b2a9c87e5e0a70963707cd8 (diff)
[asan] try to harden __tls_get_addr interceptor against signals (no good test still); update the comment in a test.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@206367 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_tls_get_addr.cc')
-rw-r--r--lib/sanitizer_common/sanitizer_tls_get_addr.cc16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/sanitizer_common/sanitizer_tls_get_addr.cc b/lib/sanitizer_common/sanitizer_tls_get_addr.cc
index 82cd4c075..42d7d1a8d 100644
--- a/lib/sanitizer_common/sanitizer_tls_get_addr.cc
+++ b/lib/sanitizer_common/sanitizer_tls_get_addr.cc
@@ -43,10 +43,10 @@ static atomic_uintptr_t number_of_live_dtls;
static const uptr kDestroyedThread = -1;
-static inline void DTLS_Deallocate(uptr size) {
+static inline void DTLS_Deallocate(DTLS::DTV *dtv, uptr size) {
if (!size) return;
- VPrintf(2, "__tls_get_addr: DTLS_Deallocate %p %zd\n", &dtls, size);
- UnmapOrDie(dtls.dtv, size * sizeof(DTLS::DTV));
+ VPrintf(2, "__tls_get_addr: DTLS_Deallocate %p %zd\n", dtv, size);
+ UnmapOrDie(dtv, size * sizeof(DTLS::DTV));
atomic_fetch_sub(&number_of_live_dtls, 1, memory_order_relaxed);
}
@@ -60,12 +60,14 @@ static inline void DTLS_Resize(uptr new_size) {
atomic_fetch_add(&number_of_live_dtls, 1, memory_order_relaxed);
VPrintf(2, "__tls_get_addr: DTLS_Resize %p %zd\n", &dtls, num_live_dtls);
CHECK_LT(num_live_dtls, 1 << 20);
- if (dtls.dtv_size) {
+ uptr old_dtv_size = dtls.dtv_size;
+ DTLS::DTV *old_dtv = dtls.dtv;
+ if (old_dtv_size)
internal_memcpy(new_dtv, dtls.dtv, dtls.dtv_size * sizeof(DTLS::DTV));
- DTLS_Deallocate(dtls.dtv_size);
- }
dtls.dtv = new_dtv;
dtls.dtv_size = new_size;
+ if (old_dtv_size)
+ DTLS_Deallocate(old_dtv, old_dtv_size);
}
void DTLS_Destroy() {
@@ -73,7 +75,7 @@ void DTLS_Destroy() {
VPrintf(2, "__tls_get_addr: DTLS_Destroy %p %zd\n", &dtls, dtls.dtv_size);
uptr s = dtls.dtv_size;
dtls.dtv_size = kDestroyedThread; // Do this before unmap for AS-safety.
- DTLS_Deallocate(s);
+ DTLS_Deallocate(dtls.dtv, s);
}
void DTLS_on_tls_get_addr(void *arg_void, void *res) {