Index: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc =================================================================== --- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc +++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc @@ -1943,21 +1943,6 @@ rtl_generic_sighandler(true, sig, info, ctx); } -static int sigaction_impl(int sig, __sanitizer_sigaction *act, - __sanitizer_sigaction *old); -static __sanitizer_sighandler_ptr signal_impl(int sig, - __sanitizer_sighandler_ptr h); - -TSAN_INTERCEPTOR(int, sigaction, int sig, __sanitizer_sigaction *act, - __sanitizer_sigaction *old) { - return sigaction_impl(sig, act, old); -} - -TSAN_INTERCEPTOR(__sanitizer_sighandler_ptr, signal, int sig, - __sanitizer_sighandler_ptr h) { - return signal_impl(sig, h); -} - TSAN_INTERCEPTOR(int, raise, int sig) { SCOPED_TSAN_INTERCEPTOR(raise, sig); ThreadSignalContext *sctx = SigCtx(thr); @@ -2271,9 +2256,20 @@ #include "sanitizer_common/sanitizer_common_interceptors.inc" -// TODO(vitalybuka): use sanitizer_signal_interceptors.inc here. +static int sigaction_impl(int sig, const __sanitizer_sigaction *act, + __sanitizer_sigaction *old); +static __sanitizer_sighandler_ptr signal_impl(int sig, + __sanitizer_sighandler_ptr h); + +#define SIGNAL_INTERCEPTOR_SIGACTION_IMPL(signo, act, oldact) \ + { return sigaction_impl(signo, act, oldact); } + +#define SIGNAL_INTERCEPTOR_SIGNAL_IMPL(func, signo, handler) \ + { return (uptr)signal_impl(signo, (__sanitizer_sighandler_ptr)handler); } + +#include "sanitizer_common/sanitizer_signal_interceptors.inc" -int sigaction_impl(int sig, __sanitizer_sigaction *act, +int sigaction_impl(int sig, const __sanitizer_sigaction *act, __sanitizer_sigaction *old) { // Note: if we call REAL(sigaction) directly for any reason without proxying // the signal handler through rtl_sigaction, very bad things will happen. @@ -2289,8 +2285,8 @@ // some bytes from old value and some bytes from new value. // Use volatile to prevent insertion of memcpy. sigactions[sig].handler = - *(volatile __sanitizer_sighandler_ptr *)&act->handler; - sigactions[sig].sa_flags = *(volatile int *)&act->sa_flags; + *(volatile __sanitizer_sighandler_ptr const *)&act->handler; + sigactions[sig].sa_flags = *(volatile int const *)&act->sa_flags; internal_memcpy(&sigactions[sig].sa_mask, &act->sa_mask, sizeof(sigactions[sig].sa_mask)); #if !SANITIZER_FREEBSD && !SANITIZER_MAC && !SANITIZER_NETBSD @@ -2506,6 +2502,7 @@ new(interceptor_ctx()) InterceptorContext(); InitializeCommonInterceptors(); + InitializeSignalInterceptors(); #if !SANITIZER_MAC // We can not use TSAN_INTERCEPT to get setjmp addr, @@ -2613,8 +2610,6 @@ TSAN_INTERCEPT(rmdir); TSAN_INTERCEPT(closedir); - TSAN_INTERCEPT(sigaction); - TSAN_INTERCEPT(signal); TSAN_INTERCEPT(sigsuspend); TSAN_INTERCEPT(sigblock); TSAN_INTERCEPT(sigsetmask); Index: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc =================================================================== --- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc +++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc @@ -324,6 +324,21 @@ } } +#if !SANITIZER_GO +static void OnStackUnwind(const SignalContext &sig, const void *, + BufferedStackTrace *stack) { + uptr top = 0; + uptr bottom = 0; + bool fast = common_flags()->fast_unwind_on_fatal; + if (fast) GetThreadStackTopAndBottom(false, &top, &bottom); + stack->Unwind(kStackTraceMax, sig.pc, sig.bp, sig.context, top, bottom, fast); +} + +static void TsanOnDeadlySignal(int signo, void *siginfo, void *context) { + HandleDeadlySignal(siginfo, context, GetTid(), &OnStackUnwind, nullptr); +} +#endif + void Initialize(ThreadState *thr) { // Thread safe because done before all threads exist. static bool is_initialized = false; @@ -361,6 +376,7 @@ #if !SANITIZER_GO InitializeShadowMemory(); InitializeAllocatorLate(); + InstallDeadlySignalHandlers(TsanOnDeadlySignal); #endif // Setup correct file descriptor for error reports. __sanitizer_set_report_path(common_flags()->log_path); Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/assert.cc =================================================================== --- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/assert.cc +++ compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/assert.cc @@ -7,9 +7,6 @@ // RUN: %env_tool_opts=handle_abort=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK1 %s // clang-format on -// FIXME: implement in other sanitizers. -// XFAIL: tsan - #include #include #include Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/ill.cc =================================================================== --- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/ill.cc +++ compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/ill.cc @@ -7,9 +7,6 @@ // RUN: %env_tool_opts=handle_sigill=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK1 %s // clang-format on -// FIXME: implement in other sanitizers. -// XFAIL: tsan - // FIXME: seems to fail on ARM // REQUIRES: x86_64-target-arch #include Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc =================================================================== --- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc +++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc @@ -7,8 +7,6 @@ // RUN: env %tool_options='abort_on_error=0, dedup_token_length=3' not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3 --match-full-lines // REQUIRES: stable-runtime -// FIXME: implement SEGV handler in other sanitizers. -// XFAIL: tsan volatile int *null = 0; Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc =================================================================== --- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc +++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc @@ -8,8 +8,6 @@ // clang-format on // REQUIRES: x86-target-arch -// FIXME: implement in other sanitizers. -// XFAIL: tsan int main() { #if defined(__x86_64__) Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fpe.cc =================================================================== --- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fpe.cc +++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fpe.cc @@ -4,9 +4,6 @@ // RUN: %env_tool_opts=handle_sigfpe=0 not --crash %run %t 2>&1 | FileCheck --check-prefix=CHECK0 %s // RUN: %env_tool_opts=handle_sigfpe=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK1 %s -// FIXME: implement in other sanitizers, not just asan. -// XFAIL: tsan - // FIXME: seems to fail on ARM // REQUIRES: x86_64-target-arch #include Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc =================================================================== --- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc +++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc @@ -6,8 +6,6 @@ // REQUIRES: stable-runtime // XFAIL: android && asan -// FIXME: implement SEGV handler in other sanitizers, not just asan. -// XFAIL: tsan #include #include