2017-09-16 15:16:29 +08:00
|
|
|
//===-- sanitizer_signal_interceptors.inc -----------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Signal interceptors for sanitizers.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "interception/interception.h"
|
|
|
|
#include "sanitizer_common.h"
|
|
|
|
#include "sanitizer_internal_defs.h"
|
|
|
|
#include "sanitizer_platform_interceptors.h"
|
|
|
|
|
|
|
|
using namespace __sanitizer;
|
|
|
|
|
2017-11-10 06:48:54 +08:00
|
|
|
#ifndef SIGNAL_INTERCEPTOR_SIGNAL_IMPL
|
|
|
|
#define SIGNAL_INTERCEPTOR_SIGNAL_IMPL(func, signum, handler) \
|
|
|
|
{ return REAL(func)(signum, handler); }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SIGNAL_INTERCEPTOR_SIGACTION_IMPL
|
|
|
|
#define SIGNAL_INTERCEPTOR_SIGACTION_IMPL(signum, act, oldact) \
|
|
|
|
{ return REAL(sigaction)(signum, act, oldact); }
|
|
|
|
#endif
|
|
|
|
|
2017-09-16 15:16:29 +08:00
|
|
|
#if SANITIZER_INTERCEPT_BSD_SIGNAL
|
2017-11-10 06:48:54 +08:00
|
|
|
INTERCEPTOR(void *, bsd_signal, int signum, uptr handler) {
|
2017-09-16 15:16:29 +08:00
|
|
|
if (GetHandleSignalMode(signum) == kHandleSignalExclusive) return 0;
|
2017-11-10 06:48:54 +08:00
|
|
|
SIGNAL_INTERCEPTOR_SIGNAL_IMPL(bsd_signal, signum, handler);
|
2017-09-16 15:16:29 +08:00
|
|
|
}
|
|
|
|
#define INIT_BSD_SIGNAL COMMON_INTERCEPT_FUNCTION(bsd_signal)
|
|
|
|
#else // SANITIZER_INTERCEPT_BSD_SIGNAL
|
|
|
|
#define INIT_BSD_SIGNAL
|
|
|
|
#endif // SANITIZER_INTERCEPT_BSD_SIGNAL
|
|
|
|
|
|
|
|
#if SANITIZER_INTERCEPT_SIGNAL_AND_SIGACTION
|
2017-11-10 06:48:54 +08:00
|
|
|
INTERCEPTOR(void *, signal, int signum, uptr handler) {
|
2017-09-16 15:16:29 +08:00
|
|
|
if (GetHandleSignalMode(signum) == kHandleSignalExclusive) return nullptr;
|
2017-11-10 06:48:54 +08:00
|
|
|
SIGNAL_INTERCEPTOR_SIGNAL_IMPL(signal, signum, handler);
|
2017-09-16 15:16:29 +08:00
|
|
|
}
|
|
|
|
#define INIT_SIGNAL COMMON_INTERCEPT_FUNCTION(signal)
|
|
|
|
|
2017-11-10 06:48:54 +08:00
|
|
|
INTERCEPTOR(int, sigaction, int signum, const __sanitizer_sigaction *act,
|
|
|
|
__sanitizer_sigaction *oldact) {
|
2017-09-16 15:16:29 +08:00
|
|
|
if (GetHandleSignalMode(signum) == kHandleSignalExclusive) return 0;
|
2017-11-10 06:48:54 +08:00
|
|
|
SIGNAL_INTERCEPTOR_SIGACTION_IMPL(signum, act, oldact);
|
2017-09-16 15:16:29 +08:00
|
|
|
}
|
|
|
|
#define INIT_SIGACTION COMMON_INTERCEPT_FUNCTION(sigaction)
|
|
|
|
|
|
|
|
namespace __sanitizer {
|
|
|
|
int real_sigaction(int signum, const void *act, void *oldact) {
|
2017-11-10 06:48:54 +08:00
|
|
|
return REAL(sigaction)(signum, (const __sanitizer_sigaction *)act,
|
|
|
|
(__sanitizer_sigaction *)oldact);
|
2017-09-16 15:16:29 +08:00
|
|
|
}
|
|
|
|
} // namespace __sanitizer
|
|
|
|
#else // SANITIZER_INTERCEPT_SIGNAL_AND_SIGACTION
|
|
|
|
#define INIT_SIGNAL
|
|
|
|
#define INIT_SIGACTION
|
|
|
|
// We need to have defined REAL(sigaction) on other systems.
|
2017-11-10 12:05:38 +08:00
|
|
|
namespace __sanitizer {
|
|
|
|
struct __sanitizer_sigaction;
|
|
|
|
}
|
2017-11-10 07:05:01 +08:00
|
|
|
DEFINE_REAL(int, sigaction, int signum, const __sanitizer_sigaction *act,
|
2017-11-10 07:06:59 +08:00
|
|
|
__sanitizer_sigaction *oldact)
|
2017-09-16 15:16:29 +08:00
|
|
|
#endif // SANITIZER_INTERCEPT_SIGNAL_AND_SIGACTION
|
|
|
|
|
|
|
|
static void InitializeSignalInterceptors() {
|
|
|
|
static bool was_called_once;
|
|
|
|
CHECK(!was_called_once);
|
|
|
|
was_called_once = true;
|
|
|
|
|
|
|
|
INIT_BSD_SIGNAL;
|
|
|
|
INIT_SIGNAL;
|
|
|
|
INIT_SIGACTION;
|
|
|
|
}
|