[docs] Fix build-docs.sh
[llvm-project.git] / compiler-rt / test / dfsan / origin_with_sigactions.c
blobd58d842885440f7c0fc2440f6dff1c4a895b2bbe
1 // Check that stores in signal handlers are not recorded in origin history.
2 //
3 // Origin tracking uses ChainedOriginDepot that is not async signal safe, so we
4 // do not track origins inside signal handlers.
5 //
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
9 //
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 // REQUIRES: x86_64-target-arch
24 #include <sanitizer/dfsan_interface.h>
26 #include <assert.h>
27 #include <signal.h>
28 #include <string.h>
29 #include <sys/types.h>
30 #include <unistd.h>
32 int x, y, u;
34 void CopyXtoYtoU() {
35 y = x;
36 memcpy(&u, &y, sizeof(int));
39 void SignalHandler(int signo) {
40 CopyXtoYtoU();
43 void SignalAction(int signo, siginfo_t *si, void *uc) {
44 CopyXtoYtoU();
47 int main(int argc, char *argv[]) {
48 int z = 1;
49 dfsan_set_label(8, &z, sizeof(z));
50 x = z;
52 struct sigaction psa = {};
53 #ifdef USE_SIGNAL_ACTION
54 psa.sa_flags = SA_SIGINFO;
55 psa.sa_sigaction = SignalAction;
56 #else
57 psa.sa_flags = 0;
58 psa.sa_handler = SignalHandler;
59 #endif
60 sigaction(SIGHUP, &psa, NULL);
61 kill(getpid(), SIGHUP);
62 signal(SIGHUP, SIG_DFL);
64 assert(x == 1);
65 assert(y == 1);
66 assert(u == 1);
68 dfsan_print_origin_trace(&u, NULL);
69 return 0;
72 // CHECK: Taint value 0x8 {{.*}} origin tracking ()
73 // CHECK: Origin value: {{.*}}, Taint value was stored to memory at
74 // CHECK-NOT: {{.*}} in CopyXtoYtoU.dfsan {{.*}}origin_with_sigactions.c{{.*}}
76 // CHECK: #0 {{.*}} in main {{.*}}origin_with_sigactions.c:[[@LINE-26]]
78 // CHECK: Origin value: {{.*}}, Taint value was created at
79 // CHECK: #0 {{.*}} in main {{.*}}origin_with_sigactions.c:[[@LINE-30]]