llvm-project
65 строк · 1.4 Кб
1// RUN: %clangxx_dfsan %s -o %t && %run %t
2// RUN: %clangxx_dfsan -mllvm -dfsan-track-origins=1 %s -o %t && %run %t
3// RUN: %clangxx_dfsan -mllvm -dfsan-track-origins=1 -mllvm -dfsan-instrument-with-call-threshold=0 %s -o %t && %run %t
4//
5// Test that the state of shadows from a sigaction handler are consistent.
6
7#include <signal.h>
8#include <stdarg.h>
9#include <sanitizer/dfsan_interface.h>
10#include <assert.h>
11#include <sys/time.h>
12#include <stdio.h>
13
14const int kSigCnt = 200;
15int x = 0;
16
17__attribute__((noinline))
18int f(int a) {
19return a;
20}
21
22__attribute__((noinline))
23void g() {
24int r = f(x);
25const dfsan_label r_label = dfsan_get_label(r);
26assert(r_label == 8 || r_label == 0);
27return;
28}
29
30int sigcnt;
31
32void SignalHandler(int signo) {
33assert(signo == SIGPROF);
34int a = 0;
35dfsan_set_label(4, &a, sizeof(a));
36(void)f(a);
37++sigcnt;
38}
39
40int main() {
41struct sigaction psa = {};
42psa.sa_handler = SignalHandler;
43int r = sigaction(SIGPROF, &psa, NULL);
44
45itimerval itv;
46itv.it_interval.tv_sec = 0;
47itv.it_interval.tv_usec = 100;
48itv.it_value.tv_sec = 0;
49itv.it_value.tv_usec = 100;
50setitimer(ITIMER_PROF, &itv, NULL);
51
52dfsan_set_label(8, &x, sizeof(x));
53do {
54g();
55} while (sigcnt < kSigCnt);
56
57itv.it_interval.tv_sec = 0;
58itv.it_interval.tv_usec = 0;
59itv.it_value.tv_sec = 0;
60itv.it_value.tv_usec = 0;
61setitimer(ITIMER_PROF, &itv, NULL);
62
63signal(SIGPROF, SIG_DFL);
64return 0;
65}
66