xref: /llvm-project/compiler-rt/test/msan/interception_sigaction_test.cpp (revision 643a2080ec028bd7674206e0f97cbc7d0f132f99)
1fd893bdaSMatt Morehouse // RUN: %clangxx_msan -O0 -g %s -o %t
2*643a2080SHarini0924 // RUN: env MSAN_OPTIONS=handle_segv=2 %t 2>&1 | FileCheck %s
3fd893bdaSMatt Morehouse #include <stdlib.h>
4fd893bdaSMatt Morehouse #include <stdio.h>
5fd893bdaSMatt Morehouse #include <unistd.h>
6fd893bdaSMatt Morehouse #include <signal.h>
7fd893bdaSMatt Morehouse #include <string.h>
8fd893bdaSMatt Morehouse 
9fd893bdaSMatt Morehouse extern "C" int __interceptor_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
10fd893bdaSMatt Morehouse extern "C" int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) {
11fd893bdaSMatt Morehouse   write(2, "sigaction call\n", sizeof("sigaction call\n") - 1);
12fd893bdaSMatt Morehouse   return __interceptor_sigaction(signum, act, oldact);
13fd893bdaSMatt Morehouse }
14fd893bdaSMatt Morehouse 
15fd893bdaSMatt Morehouse int main() {
16fd893bdaSMatt Morehouse   struct sigaction oldact;
17fd893bdaSMatt Morehouse   sigaction(SIGSEGV, nullptr, &oldact);
18fd893bdaSMatt Morehouse 
19fd893bdaSMatt Morehouse   if (oldact.sa_handler || oldact.sa_sigaction) {
20fd893bdaSMatt Morehouse     fprintf(stderr, "oldact filled\n");
21fd893bdaSMatt Morehouse   }
22fd893bdaSMatt Morehouse   return 0;
23fd893bdaSMatt Morehouse   // CHECK: sigaction call
24fd893bdaSMatt Morehouse   // CHECK: oldact filled
25fd893bdaSMatt Morehouse }
26