mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-22 11:15:44 +00:00
[sanitizer] Move signal interceptors from asan to sanitizer_common
Summary: Part of https://github.com/google/sanitizers/issues/637 Reviewers: eugenis, alekseyshl Subscribers: srhines, kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D37889 llvm-svn: 313449
This commit is contained in:
parent
aa499c1cb2
commit
6c196978eb
@ -161,6 +161,7 @@ DECLARE_REAL_AND_INTERCEPTOR(void, free, void *)
|
||||
} while (false)
|
||||
|
||||
#include "sanitizer_common/sanitizer_common_interceptors.inc"
|
||||
#include "sanitizer_common/sanitizer_signal_interceptors.inc"
|
||||
|
||||
// Syscall interceptors don't have contexts, we don't support suppressions
|
||||
// for them.
|
||||
@ -242,42 +243,6 @@ INTERCEPTOR(int, pthread_join, void *t, void **arg) {
|
||||
DEFINE_REAL_PTHREAD_FUNCTIONS
|
||||
#endif // ASAN_INTERCEPT_PTHREAD_CREATE
|
||||
|
||||
#if ASAN_INTERCEPT_SIGNAL_AND_SIGACTION
|
||||
|
||||
#if SANITIZER_ANDROID
|
||||
INTERCEPTOR(void*, bsd_signal, int signum, void *handler) {
|
||||
if (GetHandleSignalMode(signum) != kHandleSignalExclusive)
|
||||
return REAL(bsd_signal)(signum, handler);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
INTERCEPTOR(void*, signal, int signum, void *handler) {
|
||||
if (GetHandleSignalMode(signum) != kHandleSignalExclusive)
|
||||
return REAL(signal)(signum, handler);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
INTERCEPTOR(int, sigaction, int signum, const struct sigaction *act,
|
||||
struct sigaction *oldact) {
|
||||
if (GetHandleSignalMode(signum) != kHandleSignalExclusive)
|
||||
return REAL(sigaction)(signum, act, oldact);
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace __sanitizer {
|
||||
int real_sigaction(int signum, const void *act, void *oldact) {
|
||||
return REAL(sigaction)(signum, (const struct sigaction *)act,
|
||||
(struct sigaction *)oldact);
|
||||
}
|
||||
} // namespace __sanitizer
|
||||
|
||||
#elif SANITIZER_POSIX
|
||||
// We need to have defined REAL(sigaction) on posix systems.
|
||||
DEFINE_REAL(int, sigaction, int signum, const struct sigaction *act,
|
||||
struct sigaction *oldact)
|
||||
#endif // ASAN_INTERCEPT_SIGNAL_AND_SIGACTION
|
||||
|
||||
#if ASAN_INTERCEPT_SWAPCONTEXT
|
||||
static void ClearShadowMemoryForContextStack(uptr stack, uptr ssize) {
|
||||
// Align to page size.
|
||||
@ -590,6 +555,7 @@ void InitializeAsanInterceptors() {
|
||||
CHECK(!was_called_once);
|
||||
was_called_once = true;
|
||||
InitializeCommonInterceptors();
|
||||
InitializeSignalInterceptors();
|
||||
|
||||
// Intercept str* functions.
|
||||
ASAN_INTERCEPT_FUNC(strcat); // NOLINT
|
||||
@ -612,15 +578,9 @@ void InitializeAsanInterceptors() {
|
||||
ASAN_INTERCEPT_FUNC(strtoll);
|
||||
#endif
|
||||
|
||||
// Intecept signal- and jump-related functions.
|
||||
// Intecept jump-related functions.
|
||||
ASAN_INTERCEPT_FUNC(longjmp);
|
||||
#if ASAN_INTERCEPT_SIGNAL_AND_SIGACTION
|
||||
ASAN_INTERCEPT_FUNC(sigaction);
|
||||
#if SANITIZER_ANDROID
|
||||
ASAN_INTERCEPT_FUNC(bsd_signal);
|
||||
#endif
|
||||
ASAN_INTERCEPT_FUNC(signal);
|
||||
#endif
|
||||
|
||||
#if ASAN_INTERCEPT_SWAPCONTEXT
|
||||
ASAN_INTERCEPT_FUNC(swapcontext);
|
||||
#endif
|
||||
|
@ -67,12 +67,6 @@ void InitializePlatformInterceptors();
|
||||
# define ASAN_INTERCEPT_SWAPCONTEXT 0
|
||||
#endif
|
||||
|
||||
#if !SANITIZER_WINDOWS
|
||||
# define ASAN_INTERCEPT_SIGNAL_AND_SIGACTION 1
|
||||
#else
|
||||
# define ASAN_INTERCEPT_SIGNAL_AND_SIGACTION 0
|
||||
#endif
|
||||
|
||||
#if !SANITIZER_WINDOWS
|
||||
# define ASAN_INTERCEPT_SIGLONGJMP 1
|
||||
#else
|
||||
|
@ -389,5 +389,7 @@
|
||||
#define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE (!SI_MAC)
|
||||
#define SANITIZER_INTERCEPT_MCHECK_MPROBE SI_LINUX_NOT_ANDROID
|
||||
#define SANITIZER_INTERCEPT_WCSCAT SI_POSIX
|
||||
#define SANITIZER_INTERCEPT_SIGNAL_AND_SIGACTION (!SANITIZER_WINDOWS)
|
||||
#define SANITIZER_INTERCEPT_BSD_SIGNAL SANITIZER_ANDROID
|
||||
|
||||
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
|
||||
|
@ -0,0 +1,67 @@
|
||||
//===-- 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;
|
||||
|
||||
#if SANITIZER_INTERCEPT_BSD_SIGNAL
|
||||
INTERCEPTOR(void *, bsd_signal, int signum, void *handler) {
|
||||
if (GetHandleSignalMode(signum) == kHandleSignalExclusive) return 0;
|
||||
return REAL(bsd_signal)(signum, handler);
|
||||
}
|
||||
#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
|
||||
INTERCEPTOR(void *, signal, int signum, void *handler) {
|
||||
if (GetHandleSignalMode(signum) == kHandleSignalExclusive) return nullptr;
|
||||
return REAL(signal)(signum, handler);
|
||||
}
|
||||
#define INIT_SIGNAL COMMON_INTERCEPT_FUNCTION(signal)
|
||||
|
||||
INTERCEPTOR(int, sigaction, int signum, const struct sigaction *act,
|
||||
struct sigaction *oldact) {
|
||||
if (GetHandleSignalMode(signum) == kHandleSignalExclusive) return 0;
|
||||
return REAL(sigaction)(signum, act, oldact);
|
||||
}
|
||||
#define INIT_SIGACTION COMMON_INTERCEPT_FUNCTION(sigaction)
|
||||
|
||||
namespace __sanitizer {
|
||||
int real_sigaction(int signum, const void *act, void *oldact) {
|
||||
return REAL(sigaction)(signum, (const struct sigaction *)act,
|
||||
(struct sigaction *)oldact);
|
||||
}
|
||||
} // namespace __sanitizer
|
||||
#else // SANITIZER_INTERCEPT_SIGNAL_AND_SIGACTION
|
||||
#define INIT_SIGNAL
|
||||
#define INIT_SIGACTION
|
||||
// We need to have defined REAL(sigaction) on other systems.
|
||||
DEFINE_REAL(int, sigaction, int signum, const struct sigaction *act,
|
||||
struct sigaction *oldact)
|
||||
#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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user