1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
3 // Test case for longjumping out of signal handler:
4 // https://github.com/google/sanitizers/issues/482
6 // This test fails on powerpc64 BE (VMA=44), a segmentation fault
7 // error happens at the second assignment
8 // "((volatile int *volatile)mem)[1] = 1".
9 // XFAIL: target=powerpc64-unknown-linux-gnu{{.*}}
18 #define SIGNAL_TO_HANDLE SIGBUS
20 #define SIGNAL_TO_HANDLE SIGSEGV
24 volatile int fault_expected
;
26 void sigfault_handler(int sig
) {
30 /* just return from sighandler to proper place */
32 siglongjmp(fault_jmp
, 1);
35 #define MUST_FAULT(code) do { \
37 if (!sigsetjmp(fault_jmp, 1)) { \
38 code; /* should pagefault -> sihandler does longjmp */ \
39 fprintf(stderr, "%s not faulted\n", #code); \
42 fprintf(stderr, "%s faulted ok\n", #code); \
48 act
.sa_handler
= sigfault_handler
;
50 if (sigemptyset(&act
.sa_mask
)) {
51 perror("sigemptyset");
55 if (sigaction(SIGNAL_TO_HANDLE
, &act
, NULL
)) {
60 void *mem
= mmap(0, 4096, PROT_NONE
, MAP_PRIVATE
| MAP_ANON
,
63 MUST_FAULT(((volatile int *volatile)mem
)[0] = 0);
64 MUST_FAULT(((volatile int *volatile)mem
)[1] = 1);
65 MUST_FAULT(((volatile int *volatile)mem
)[3] = 1);
67 // Ensure that tsan does not think that we are
68 // in a signal handler.
69 void *volatile p
= malloc(10);
70 ((volatile int*)p
)[1] = 1;
75 fprintf(stderr
, "DONE\n");
79 // CHECK-NOT: WARNING: ThreadSanitizer