summaryrefslogtreecommitdiff
path: root/test/tsan
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2014-09-16 21:48:22 +0000
committerDmitry Vyukov <dvyukov@google.com>2014-09-16 21:48:22 +0000
commit6afe775d2ca25bb266f9c343861a1c33858f53db (patch)
tree23445d1cb137130d6da0d4b422879fa800baa358 /test/tsan
parente770075cbd2897cafdd30217da21ff4f45ee3e2f (diff)
tsan: support longjmp out of signal handlers
Fixes https://code.google.com/p/thread-sanitizer/issues/detail?id=75 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@217908 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/tsan')
-rw-r--r--test/tsan/signal_longjmp.cc63
1 files changed, 63 insertions, 0 deletions
diff --git a/test/tsan/signal_longjmp.cc b/test/tsan/signal_longjmp.cc
new file mode 100644
index 000000000..ce0993146
--- /dev/null
+++ b/test/tsan/signal_longjmp.cc
@@ -0,0 +1,63 @@
+// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+
+// Test case for longjumping out of signal handler:
+// https://code.google.com/p/thread-sanitizer/issues/detail?id=71
+
+#include <setjmp.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+sigjmp_buf fault_jmp;
+volatile int fault_expected;
+
+void sigfault_handler(int sig) {
+ if (!fault_expected)
+ abort();
+
+ /* just return from sighandler to proper place */
+ fault_expected = 0;
+ siglongjmp(fault_jmp, 1);
+}
+
+#define MUST_FAULT(code) do { \
+ fault_expected = 1; \
+ if (!sigsetjmp(fault_jmp, 1)) { \
+ code; /* should pagefault -> sihandler does longjmp */ \
+ fprintf(stderr, "%s not faulted\n", #code); \
+ abort(); \
+ } else { \
+ fprintf(stderr, "%s faulted ok\n", #code); \
+ } \
+} while (0)
+
+int main() {
+ struct sigaction act;
+ act.sa_handler = sigfault_handler;
+ act.sa_flags = 0;
+ if (sigemptyset(&act.sa_mask)) {
+ perror("sigemptyset");
+ exit(1);
+ }
+
+ if (sigaction(SIGSEGV, &act, NULL)) {
+ perror("sigaction");
+ exit(1);
+ }
+
+ MUST_FAULT(((volatile int *volatile)0)[0] = 0);
+ MUST_FAULT(((volatile int *volatile)0)[1] = 1);
+ MUST_FAULT(((volatile int *volatile)0)[3] = 1);
+
+ // Ensure that tsan does not think that we are
+ // in a signal handler.
+ void *volatile p = malloc(10);
+ ((volatile int*)p)[1] = 1;
+ free((void*)p);
+
+ fprintf(stderr, "DONE\n");
+ return 0;
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer
+// CHECK: DONE