]>
Commit | Line | Data |
---|---|---|
1 | // RUN: %clangxx_msan -DPRE1 -O0 %s -o %t && not %run %t 2>&1 | |
2 | // RUN: %clangxx_msan -DPRE2 -O0 %s -o %t && not %run %t 2>&1 | |
3 | // RUN: %clangxx_msan -DPRE3 -O0 %s -o %t && not %run %t 2>&1 | |
4 | // RUN: %clangxx_msan -O0 %s -o %t && %run %t 2>&1 | |
5 | ||
6 | #include <assert.h> | |
7 | #include <signal.h> | |
8 | #include <string.h> | |
9 | ||
10 | #include <sanitizer/linux_syscall_hooks.h> | |
11 | #include <sanitizer/msan_interface.h> | |
12 | ||
13 | struct my_kernel_sigaction { | |
14 | #if defined(__mips__) | |
15 | long flags, handler; | |
16 | #else | |
17 | long handler, flags, restorer; | |
18 | #endif | |
19 | uint64_t mask[20]; // larger than any known platform | |
20 | }; | |
21 | ||
22 | int main() { | |
23 | my_kernel_sigaction act = {}, oldact = {}; | |
24 | ||
25 | #if defined(PRE1) | |
26 | __msan_poison(&act.handler, sizeof(act.handler)); | |
27 | __sanitizer_syscall_pre_rt_sigaction(SIGUSR1, &act, &oldact, 20 * 8); | |
28 | #elif defined(PRE2) | |
29 | __msan_poison(&act.flags, sizeof(act.flags)); | |
30 | __sanitizer_syscall_pre_rt_sigaction(SIGUSR1, &act, &oldact, 20 * 8); | |
31 | #elif defined(PRE3) | |
32 | __msan_poison(&act.mask, 1); | |
33 | __sanitizer_syscall_pre_rt_sigaction(SIGUSR1, &act, &oldact, 20 * 8); | |
34 | #else | |
35 | // Uninit past the end of the mask is ignored. | |
36 | __msan_poison(((char *)&act.mask) + 5, 1); | |
37 | __sanitizer_syscall_pre_rt_sigaction(SIGUSR1, &act, &oldact, 5); | |
38 | ||
39 | memset(&act, 0, sizeof(act)); | |
40 | __msan_poison(&oldact, sizeof(oldact)); | |
41 | __sanitizer_syscall_post_rt_sigaction(0, SIGUSR1, &act, &oldact, 5); | |
42 | #if defined(__mips__) | |
43 | assert(__msan_test_shadow(&oldact, sizeof(oldact)) == sizeof(long)*2 + 5); | |
44 | #else | |
45 | assert(__msan_test_shadow(&oldact, sizeof(oldact)) == sizeof(long)*3 + 5); | |
46 | #endif | |
47 | #endif | |
48 | } |