summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2019-10-07 22:43:17 +0000
committerVitaly Buka <vitalybuka@google.com>2019-10-07 22:43:17 +0000
commit50d8df97befe6f5804b38d1d974f9b3c65282744 (patch)
tree92ada8a4ba7841f45d642bf1b449cf8f5da5b186
parent5b3c533a7b7066ffe881b7e9a15b026682e04427 (diff)
downloadcompiler-rt-50d8df97befe6f5804b38d1d974f9b3c65282744.tar.gz
[tsan] Don't delay SIGTRAP handler
Reviewers: eugenis, jfb Subscribers: #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D68604 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@373978 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/tsan/rtl/tsan_interceptors_posix.cpp9
-rw-r--r--test/sanitizer_common/TestCases/Linux/signal_trap_handler.cpp29
2 files changed, 34 insertions, 4 deletions
diff --git a/lib/tsan/rtl/tsan_interceptors_posix.cpp b/lib/tsan/rtl/tsan_interceptors_posix.cpp
index d1d83e23d..8aea1e4ec 100644
--- a/lib/tsan/rtl/tsan_interceptors_posix.cpp
+++ b/lib/tsan/rtl/tsan_interceptors_posix.cpp
@@ -114,6 +114,7 @@ const int PTHREAD_MUTEX_RECURSIVE_NP = 2;
const int EPOLL_CTL_ADD = 1;
#endif
const int SIGILL = 4;
+const int SIGTRAP = 5;
const int SIGABRT = 6;
const int SIGFPE = 8;
const int SIGSEGV = 11;
@@ -1962,10 +1963,10 @@ void ProcessPendingSignals(ThreadState *thr) {
} // namespace __tsan
static bool is_sync_signal(ThreadSignalContext *sctx, int sig) {
- return sig == SIGSEGV || sig == SIGBUS || sig == SIGILL ||
- sig == SIGABRT || sig == SIGFPE || sig == SIGPIPE || sig == SIGSYS ||
- // If we are sending signal to ourselves, we must process it now.
- (sctx && sig == sctx->int_signal_send);
+ return sig == SIGSEGV || sig == SIGBUS || sig == SIGILL || sig == SIGTRAP ||
+ sig == SIGABRT || sig == SIGFPE || sig == SIGPIPE || sig == SIGSYS ||
+ // If we are sending signal to ourselves, we must process it now.
+ (sctx && sig == sctx->int_signal_send);
}
void ALWAYS_INLINE rtl_generic_sighandler(bool sigact, int sig,
diff --git a/test/sanitizer_common/TestCases/Linux/signal_trap_handler.cpp b/test/sanitizer_common/TestCases/Linux/signal_trap_handler.cpp
new file mode 100644
index 000000000..9b4bc067e
--- /dev/null
+++ b/test/sanitizer_common/TestCases/Linux/signal_trap_handler.cpp
@@ -0,0 +1,29 @@
+// RUN: %clangxx -O1 %s -o %t && %env_tool_opts=handle_sigtrap=1 %run %t 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <signal.h>
+#include <stdio.h>
+
+int handled;
+
+void handler(int signo, siginfo_t *info, void *uctx) {
+ handled = 1;
+}
+
+int main() {
+ struct sigaction a = {}, old = {};
+ a.sa_sigaction = handler;
+ a.sa_flags = SA_SIGINFO;
+ sigaction(SIGTRAP, &a, &old);
+
+ a = {};
+ sigaction(SIGTRAP, 0, &a);
+ assert(a.sa_sigaction == handler);
+ assert(a.sa_flags & SA_SIGINFO);
+
+ __builtin_debugtrap();
+ assert(handled);
+ fprintf(stderr, "HANDLED %d\n", handled);
+}
+
+// CHECK: HANDLED 1