Skip to content

Commit

Permalink
[sanitizer] Move signal interceptors from asan to sanitizer_common
Browse files Browse the repository at this point in the history
Summary: Part of google/sanitizers#637

Reviewers: eugenis, alekseyshl

Subscribers: srhines, kubamracek, llvm-commits

Differential Revision: https://reviews.llvm.org/D37889

llvm-svn: 313449
  • Loading branch information
vitalybuka committed Sep 16, 2017
1 parent aa499c1 commit 6c19697
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 50 deletions.
48 changes: 4 additions & 44 deletions compiler-rt/lib/asan/asan_interceptors.cc
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -590,6 +555,7 @@ void InitializeAsanInterceptors() {
CHECK(!was_called_once);
was_called_once = true;
InitializeCommonInterceptors();
InitializeSignalInterceptors();

// Intercept str* functions.
ASAN_INTERCEPT_FUNC(strcat); // NOLINT
Expand All @@ -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
Expand Down
6 changes: 0 additions & 6 deletions compiler-rt/lib/asan/asan_interceptors.h
Expand Up @@ -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
Expand Down
Expand Up @@ -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
67 changes: 67 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_signal_interceptors.inc
@@ -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;
}

0 comments on commit 6c19697

Please sign in to comment.