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