[PATCH] D39935: [tsan] Fix signal chaining
Vitaly Buka via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 10 19:23:08 PST 2017
vitalybuka created this revision.
Return saved values only if installed sigaction is our wrapper.
https://reviews.llvm.org/D39935
Files:
compiler-rt/lib/tsan/rtl/tsan_interceptors.cc
compiler-rt/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc
Index: compiler-rt/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc
===================================================================
--- compiler-rt/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc
+++ compiler-rt/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc
@@ -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
Index: compiler-rt/lib/tsan/rtl/tsan_interceptors.cc
===================================================================
--- compiler-rt/lib/tsan/rtl/tsan_interceptors.cc
+++ compiler-rt/lib/tsan/rtl/tsan_interceptors.cc
@@ -2276,7 +2276,8 @@
// 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 @@
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39935.122569.patch
Type: text/x-patch
Size: 1855 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171111/7d70affb/attachment.bin>
More information about the llvm-commits
mailing list