49 lines · cpp
1// RUN: %clangxx_msan -DPRE1 -O0 %s -o %t && not %run %t 2>&12// RUN: %clangxx_msan -DPRE2 -O0 %s -o %t && not %run %t 2>&13// RUN: %clangxx_msan -DPRE3 -O0 %s -o %t && not %run %t 2>&14// RUN: %clangxx_msan -O0 %s -o %t && %run %t 2>&15 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#if defined(__mips__)15 long flags, handler;16#else17 long handler, flags, restorer;18#endif19 uint64_t mask[20]; // larger than any known platform20};21 22int 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#else35 // 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#else45 assert(__msan_test_shadow(&oldact, sizeof(oldact)) == sizeof(long)*3 + 5);46#endif47#endif48}49