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 @@ -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; } Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc =================================================================== --- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc +++ compiler-rt/trunk/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