Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sanitizer] Move signal interceptors from asan to sanitizer_common
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
1 parent
aa499c1
commit 6c19697
Showing
4 changed files
with
73 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
compiler-rt/lib/sanitizer_common/sanitizer_signal_interceptors.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |