signal_stress_test.cpp
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// RUN: %clangxx_msan -std=c++11 -O0 %s -o %t && %run %t
//
// Test that va_arg shadow from a signal handler does not leak outside.
// Reported deadly signal due to stack-overflow
// XFAIL: netbsd
#include <signal.h>
#include <stdarg.h>
#include <sanitizer/msan_interface.h>
#include <assert.h>
#include <sys/time.h>
#include <stdio.h>
const int kSigCnt = 200;
void f(bool poisoned, int n, ...) {
va_list vl;
va_start(vl, n);
for (int i = 0; i < n; ++i) {
void *p = va_arg(vl, void *);
if (!poisoned)
assert(__msan_test_shadow(&p, sizeof(p)) == -1);
}
va_end(vl);
}
int sigcnt;
void SignalHandler(int signo) {
assert(signo == SIGPROF);
void *p;
void **volatile q = &p;
f(true, 10,
*q, *q, *q, *q, *q,
*q, *q, *q, *q, *q);
++sigcnt;
}
int main() {
signal(SIGPROF, SignalHandler);
itimerval itv;
itv.it_interval.tv_sec = 0;
itv.it_interval.tv_usec = 100;
itv.it_value.tv_sec = 0;
itv.it_value.tv_usec = 100;
setitimer(ITIMER_PROF, &itv, NULL);
void *p;
void **volatile q = &p;
do {
f(false, 20,
nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr);
f(true, 20,
*q, *q, *q, *q, *q,
*q, *q, *q, *q, *q,
*q, *q, *q, *q, *q,
*q, *q, *q, *q, *q);
} while (sigcnt < kSigCnt);
itv.it_interval.tv_sec = 0;
itv.it_interval.tv_usec = 0;
itv.it_value.tv_sec = 0;
itv.it_value.tv_usec = 0;
setitimer(ITIMER_PROF, &itv, NULL);
signal(SIGPROF, SIG_DFL);
return 0;
}