Skip to content

Commit

Permalink
[sanitizer] Allow sanitizers to redefine implementation of signal int…
Browse files Browse the repository at this point in the history
…erceptors

Reviewers: eugenis

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 317843
  • Loading branch information
vitalybuka committed Nov 9, 2017
1 parent 771e399 commit 43c3e6a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
9 changes: 7 additions & 2 deletions compiler-rt/lib/asan/asan_interceptors.h
Expand Up @@ -19,6 +19,10 @@
#include "interception/interception.h"
#include "sanitizer_common/sanitizer_platform_interceptors.h"

namespace __sanitizer {
struct __sanitizer_sigaction;
}

namespace __asan {

void InitializeAsanInterceptors();
Expand Down Expand Up @@ -106,8 +110,9 @@ DECLARE_REAL(char*, strncpy, char *to, const char *from, uptr size)
DECLARE_REAL(uptr, strnlen, const char *s, uptr maxlen)
DECLARE_REAL(char*, strstr, const char *s1, const char *s2)
struct sigaction;
DECLARE_REAL(int, sigaction, int signum, const struct sigaction *act,
struct sigaction *oldact)
DECLARE_REAL(int, sigaction, int signum,
const __sanitizer::__sanitizer_sigaction *act,
__sanitizer::__sanitizer_sigaction *oldact)

#if !SANITIZER_MAC
#define ASAN_INTERCEPT_FUNC(name) \
Expand Down
32 changes: 23 additions & 9 deletions compiler-rt/lib/sanitizer_common/sanitizer_signal_interceptors.inc
Expand Up @@ -18,34 +18,48 @@

using namespace __sanitizer;

namespace __sanitizer {
struct __sanitizer_sigaction;
}

#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

#if SANITIZER_INTERCEPT_BSD_SIGNAL
INTERCEPTOR(void *, bsd_signal, int signum, void *handler) {
INTERCEPTOR(void *, bsd_signal, int signum, uptr handler) {
if (GetHandleSignalMode(signum) == kHandleSignalExclusive) return 0;
return REAL(bsd_signal)(signum, handler);
SIGNAL_INTERCEPTOR_SIGNAL_IMPL(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) {
INTERCEPTOR(void *, signal, int signum, uptr handler) {
if (GetHandleSignalMode(signum) == kHandleSignalExclusive) return nullptr;
return REAL(signal)(signum, handler);
SIGNAL_INTERCEPTOR_SIGNAL_IMPL(signal, signum, handler);
}
#define INIT_SIGNAL COMMON_INTERCEPT_FUNCTION(signal)

INTERCEPTOR(int, sigaction, int signum, const struct sigaction *act,
struct sigaction *oldact) {
INTERCEPTOR(int, sigaction, int signum, const __sanitizer_sigaction *act,
__sanitizer_sigaction *oldact) {
if (GetHandleSignalMode(signum) == kHandleSignalExclusive) return 0;
return REAL(sigaction)(signum, act, oldact);
SIGNAL_INTERCEPTOR_SIGACTION_IMPL(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);
return REAL(sigaction)(signum, (const __sanitizer_sigaction *)act,
(__sanitizer_sigaction *)oldact);
}
} // namespace __sanitizer
#else // SANITIZER_INTERCEPT_SIGNAL_AND_SIGACTION
Expand Down

0 comments on commit 43c3e6a

Please sign in to comment.