[compiler-rt] r206367 - [asan] try to harden __tls_get_addr interceptor against signals (no good test still); update the comment in a test.

Kostya Serebryany kcc at google.com
Wed Apr 16 02:07:28 PDT 2014


Author: kcc
Date: Wed Apr 16 04:07:27 2014
New Revision: 206367

URL: http://llvm.org/viewvc/llvm-project?rev=206367&view=rev
Log:
[asan] try to harden __tls_get_addr interceptor against signals (no good test still); update the comment in a test.

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_tls_get_addr.cc
    compiler-rt/trunk/test/asan/TestCases/Linux/uar_signals.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_tls_get_addr.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_tls_get_addr.cc?rev=206367&r1=206366&r2=206367&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_tls_get_addr.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_tls_get_addr.cc Wed Apr 16 04:07:27 2014
@@ -43,10 +43,10 @@ static atomic_uintptr_t number_of_live_d
 
 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_
       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) {

Modified: compiler-rt/trunk/test/asan/TestCases/Linux/uar_signals.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/uar_signals.cc?rev=206367&r1=206366&r2=206367&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/uar_signals.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Linux/uar_signals.cc Wed Apr 16 04:07:27 2014
@@ -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>





More information about the llvm-commits mailing list