1 // Check that stores in signal handlers are not recorded in origin history.
3 // Origin tracking uses ChainedOriginDepot that is not async signal safe, so we
4 // do not track origins inside signal handlers.
6 // RUN: %clang_dfsan -gmlt -DUSE_SIGNAL_ACTION -mllvm -dfsan-track-origins=1 %s -o %t && \
7 // RUN: %run %t >%t.out 2>&1
8 // RUN: FileCheck %s < %t.out
10 // RUN: %clang_dfsan -gmlt -DUSE_SIGNAL_ACTION -mllvm -dfsan-instrument-with-call-threshold=0 -mllvm -dfsan-track-origins=1 %s -o %t && \
11 // RUN: %run %t >%t.out 2>&1
12 // RUN: FileCheck %s < %t.out
14 // RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 %s -o %t && \
15 // RUN: %run %t >%t.out 2>&1
16 // RUN: FileCheck %s < %t.out
18 // RUN: %clang_dfsan -gmlt -mllvm -dfsan-instrument-with-call-threshold=0 -mllvm -dfsan-track-origins=1 %s -o %t && \
19 // RUN: %run %t >%t.out 2>&1
20 // RUN: FileCheck %s < %t.out
22 #include <sanitizer/dfsan_interface.h>
27 #include <sys/types.h>
34 memcpy(&u
, &y
, sizeof(int));
37 void SignalHandler(int signo
) {
41 void SignalAction(int signo
, siginfo_t
*si
, void *uc
) {
45 int main(int argc
, char *argv
[]) {
47 dfsan_set_label(8, &z
, sizeof(z
));
50 struct sigaction psa
= {};
51 #ifdef USE_SIGNAL_ACTION
52 psa
.sa_flags
= SA_SIGINFO
;
53 psa
.sa_sigaction
= SignalAction
;
56 psa
.sa_handler
= SignalHandler
;
58 sigaction(SIGHUP
, &psa
, NULL
);
59 kill(getpid(), SIGHUP
);
60 signal(SIGHUP
, SIG_DFL
);
66 dfsan_print_origin_trace(&u
, NULL
);
70 // CHECK: Taint value 0x8 {{.*}} origin tracking ()
71 // CHECK: Origin value: {{.*}}, Taint value was stored to memory at
72 // CHECK-NOT: {{.*}} in CopyXtoYtoU.dfsan {{.*}}origin_with_sigactions.c{{.*}}
74 // CHECK: #0 {{.*}} in main {{.*}}origin_with_sigactions.c:[[@LINE-26]]
76 // CHECK: Origin value: {{.*}}, Taint value was created at
77 // CHECK: #0 {{.*}} in main {{.*}}origin_with_sigactions.c:[[@LINE-30]]