1 | // RUN: %clang_dfsan -DUSE_SIGNAL_ACTION -mllvm -dfsan-fast-16-labels=true %s -o %t && \ |
2 | // RUN: %run %t |
3 | // RUN: %clang_dfsan -mllvm -dfsan-fast-16-labels=true %s -o %t && %run %t |
4 | // |
5 | // REQUIRES: x86_64-target-arch |
6 | |
7 | #include <sanitizer/dfsan_interface.h> |
8 | |
9 | #include <assert.h> |
10 | #include <signal.h> |
11 | #include <string.h> |
12 | #include <sys/types.h> |
13 | #include <unistd.h> |
14 | |
15 | volatile int x; |
16 | volatile int z = 1; |
17 | |
18 | void SignalHandler(int signo) { |
19 | assert(dfsan_get_label(signo) == 0); |
20 | x = z; |
21 | } |
22 | |
23 | void SignalAction(int signo, siginfo_t *si, void *uc) { |
24 | assert(dfsan_get_label(signo) == 0); |
25 | assert(dfsan_get_label(si) == 0); |
26 | assert(dfsan_get_label(uc) == 0); |
27 | assert(0 == dfsan_read_label(si, sizeof(*si))); |
28 | assert(0 == dfsan_read_label(uc, sizeof(ucontext_t))); |
29 | x = z; |
30 | } |
31 | |
32 | int main(int argc, char *argv[]) { |
33 | dfsan_set_label(8, (void *)&z, sizeof(z)); |
34 | |
35 | struct sigaction sa = {}; |
36 | #ifdef USE_SIGNAL_ACTION |
37 | sa.sa_flags = SA_SIGINFO; |
38 | sa.sa_sigaction = SignalAction; |
39 | #else |
40 | sa.sa_handler = SignalHandler; |
41 | #endif |
42 | int r = sigaction(SIGHUP, &sa, NULL); |
43 | assert(dfsan_get_label(r) == 0); |
44 | |
45 | kill(getpid(), SIGHUP); |
46 | signal(SIGHUP, SIG_DFL); |
47 | |
48 | assert(x == 1); |
49 | |
50 | return 0; |
51 | } |
52 | |