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
13struct my_kernel_sigaction {
14  long handler, flags, restorer;
15  uint64_t mask[20]; // larger than any known platform
16};
17
18int main() {
19  my_kernel_sigaction act = {}, oldact = {};
20
21#if defined(PRE1)
22  __msan_poison(&act.handler, sizeof(act.handler));
23  __sanitizer_syscall_pre_rt_sigaction(SIGUSR1, &act, &oldact, 20 * 8);
24#elif defined(PRE2)
25  __msan_poison(&act.flags, sizeof(act.flags));
26  __sanitizer_syscall_pre_rt_sigaction(SIGUSR1, &act, &oldact, 20 * 8);
27#elif defined(PRE3)
28  __msan_poison(&act.mask, 1);
29  __sanitizer_syscall_pre_rt_sigaction(SIGUSR1, &act, &oldact, 20 * 8);
30#else
31  // Uninit past the end of the mask is ignored.
32  __msan_poison(((char *)&act.mask) + 5, 1);
33  __sanitizer_syscall_pre_rt_sigaction(SIGUSR1, &act, &oldact, 5);
34
35  memset(&act, 0, sizeof(act));
36  __msan_poison(&oldact, sizeof(oldact));
37  __sanitizer_syscall_post_rt_sigaction(0, SIGUSR1, &act, &oldact, 5);
38  assert(__msan_test_shadow(&oldact, sizeof(oldact)) == sizeof(long)*3 + 5);
39#endif
40}
41