summaryrefslogtreecommitdiffstats
path: root/compiler-rt
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
commit498b18a01e235d12d59076e5b6214c72ced32d23 (patch)
tree3d9997883f053ba02b931bd54c965a1ef8db4fb5 /compiler-rt
parent97c5b6fe4fed17315ba135b2e34d7fe6c0e0366f (diff)
downloadbcm5719-llvm-498b18a01e235d12d59076e5b6214c72ced32d23.tar.gz
bcm5719-llvm-498b18a01e235d12d59076e5b6214c72ced32d23.zip
[asan] try to harden __tls_get_addr interceptor against signals (no good test still); update the comment in a test.
llvm-svn: 206367
Diffstat (limited to 'compiler-rt')
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cc16
-rw-r--r--compiler-rt/test/asan/TestCases/Linux/uar_signals.cc5
2 files changed, 11 insertions, 10 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cc b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cc
index 82cd4c075ad..42d7d1a8d15 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cc
+++ b/compiler-rt/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) {
diff --git a/compiler-rt/test/asan/TestCases/Linux/uar_signals.cc b/compiler-rt/test/asan/TestCases/Linux/uar_signals.cc
index 9663859dfef..0c75344bb93 100644
--- a/compiler-rt/test/asan/TestCases/Linux/uar_signals.cc
+++ b/compiler-rt/test/asan/TestCases/Linux/uar_signals.cc
@@ -1,6 +1,5 @@
-// This test shows that the current implementation of use-after-return is
-// not signal-safe.
-// RUN: %clangxx_asan -O1 %s -o %t -lpthread && %t
+// This test checks that the implementation of use-after-return
+// is async-signal-safe.
// RUN: %clangxx_asan -O1 %s -o %t -lpthread && %t
#include <signal.h>
#include <stdlib.h>
OpenPOWER on IntegriCloud