1 //===-- sanitizer_signal_interceptors.inc -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Signal interceptors for sanitizers.
12 //===----------------------------------------------------------------------===//
14 #include "interception/interception.h"
15 #include "sanitizer_common.h"
16 #include "sanitizer_internal_defs.h"
17 #include "sanitizer_platform_interceptors.h"
19 using namespace __sanitizer;
22 #define sigaction_symname __sigaction14
24 #define sigaction_symname sigaction
27 #ifndef SIGNAL_INTERCEPTOR_SIGNAL_IMPL
28 #define SIGNAL_INTERCEPTOR_SIGNAL_IMPL(func, signum, handler) \
29 { return REAL(func)(signum, handler); }
32 #ifndef SIGNAL_INTERCEPTOR_SIGACTION_IMPL
33 #define SIGNAL_INTERCEPTOR_SIGACTION_IMPL(signum, act, oldact) \
34 { return REAL(sigaction_symname)(signum, act, oldact); }
37 #if SANITIZER_INTERCEPT_BSD_SIGNAL
38 INTERCEPTOR(uptr, bsd_signal, int signum, uptr handler) {
39 if (GetHandleSignalMode(signum) == kHandleSignalExclusive) return 0;
40 SIGNAL_INTERCEPTOR_SIGNAL_IMPL(bsd_signal, signum, handler);
42 #define INIT_BSD_SIGNAL COMMON_INTERCEPT_FUNCTION(bsd_signal)
43 #else // SANITIZER_INTERCEPT_BSD_SIGNAL
44 #define INIT_BSD_SIGNAL
45 #endif // SANITIZER_INTERCEPT_BSD_SIGNAL
47 #if SANITIZER_INTERCEPT_SIGNAL_AND_SIGACTION
48 INTERCEPTOR(uptr, signal, int signum, uptr handler) {
49 if (GetHandleSignalMode(signum) == kHandleSignalExclusive)
50 return (uptr) nullptr;
51 SIGNAL_INTERCEPTOR_SIGNAL_IMPL(signal, signum, handler);
53 #define INIT_SIGNAL COMMON_INTERCEPT_FUNCTION(signal)
55 INTERCEPTOR(int, sigaction_symname, int signum,
56 const __sanitizer_sigaction *act, __sanitizer_sigaction *oldact) {
57 if (GetHandleSignalMode(signum) == kHandleSignalExclusive) return 0;
58 SIGNAL_INTERCEPTOR_SIGACTION_IMPL(signum, act, oldact);
60 #define INIT_SIGACTION COMMON_INTERCEPT_FUNCTION(sigaction_symname)
62 namespace __sanitizer {
63 int real_sigaction(int signum, const void *act, void *oldact) {
64 return REAL(sigaction_symname)(signum, (const __sanitizer_sigaction *)act,
65 (__sanitizer_sigaction *)oldact);
67 } // namespace __sanitizer
68 #else // SANITIZER_INTERCEPT_SIGNAL_AND_SIGACTION
70 #define INIT_SIGACTION
71 // We need to have defined REAL(sigaction) on other systems.
72 namespace __sanitizer {
73 struct __sanitizer_sigaction;
75 DEFINE_REAL(int, sigaction, int signum, const __sanitizer_sigaction *act,
76 __sanitizer_sigaction *oldact)
77 #endif // SANITIZER_INTERCEPT_SIGNAL_AND_SIGACTION
79 static void InitializeSignalInterceptors() {
80 static bool was_called_once;
81 CHECK(!was_called_once);
82 was_called_once = true;