[compiler-rt] r318082 - [tsan] Fix signal chaining

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 13 12:49:14 PST 2017


Author: vitalybuka
Date: Mon Nov 13 12:49:14 2017
New Revision: 318082

URL: http://llvm.org/viewvc/llvm-project?rev=318082&view=rev
Log:
[tsan] Fix signal chaining

Summary: Return saved values only if installed sigaction is our wrapper.

Reviewers: eugenis, dvyukov

Subscribers: llvm-commits, kubamracek

Differential Revision: https://reviews.llvm.org/D39935

Modified:
    compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
    compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=318082&r1=318081&r2=318082&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Mon Nov 13 12:49:14 2017
@@ -2276,7 +2276,8 @@ int sigaction_impl(int sig, const __sani
   // The handler will run synchronously and corrupt tsan per-thread state.
   SCOPED_INTERCEPTOR_RAW(sigaction, sig, act, old);
   __sanitizer_sigaction *sigactions = interceptor_ctx()->sigactions;
-  if (old) internal_memcpy(old, &sigactions[sig], sizeof(*old));
+  __sanitizer_sigaction old_stored;
+  internal_memcpy(&old_stored, &sigactions[sig], sizeof(old_stored));
   if (act == 0) return 0;
   // Copy act into sigactions[sig].
   // Can't use struct copy, because compiler can emit call to memcpy.
@@ -2302,7 +2303,13 @@ int sigaction_impl(int sig, const __sani
       newact.handler = rtl_sighandler;
   }
   ReleaseStore(thr, pc, (uptr)&sigactions[sig]);
-  int res = REAL(sigaction)(sig, &newact, 0);
+  int res = REAL(sigaction)(sig, &newact, old);
+  if (res == 0 && old) {
+    uptr cb = (uptr)old->sigaction;
+    if (cb == (uptr)rtl_sigaction || cb == (uptr)rtl_sighandler) {
+      internal_memcpy(old, &old_stored, sizeof(*old));
+    }
+  }
   return res;
 }
 

Modified: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc?rev=318082&r1=318081&r2=318082&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc (original)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc Mon Nov 13 12:49:14 2017
@@ -17,10 +17,6 @@
 // RUN: %env_tool_opts=handle_segv=2:allow_user_segv_handler=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2
 // clang-format on
 
-// Remove when fixed: https://github.com/google/sanitizers/issues/637
-
-// XFAIL: tsan
-
 // Flaky errors in debuggerd with "waitpid returned unexpected pid (0)" in logcat.
 // UNSUPPORTED: android && i386-target-arch
 




More information about the llvm-commits mailing list