[compiler-rt] r313227 - [sanitizer] Move IsStackOverflow into SignalContext
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 13 20:23:02 PDT 2017
Author: vitalybuka
Date: Wed Sep 13 20:23:02 2017
New Revision: 313227
URL: http://llvm.org/viewvc/llvm-project?rev=313227&view=rev
Log:
[sanitizer] Move IsStackOverflow into SignalContext
Modified:
compiler-rt/trunk/lib/asan/asan_posix.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
Modified: compiler-rt/trunk/lib/asan/asan_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_posix.cc?rev=313227&r1=313226&r2=313227&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_posix.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_posix.cc Wed Sep 13 20:23:02 2017
@@ -37,7 +37,7 @@ void AsanOnDeadlySignal(int signo, void
ScopedDeadlySignal signal_scope(GetCurrentThread());
StartReportDeadlySignal();
SignalContext sig(siginfo, context);
- if (IsStackOverflow(sig))
+ if (sig.IsStackOverflow())
ReportStackOverflow(sig);
else
ReportDeadlySignal(sig);
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=313227&r1=313226&r2=313227&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Wed Sep 13 20:23:02 2017
@@ -311,7 +311,6 @@ HandleSignalMode GetHandleSignalMode(int
void InstallDeadlySignalHandlers(SignalHandlerType handler);
// Signal reporting.
void StartReportDeadlySignal();
-bool IsStackOverflow(const SignalContext &sig);
// FIXME: Hide after moving more signal handling code into common.
void MaybeReportNonExecRegion(uptr pc);
void MaybeDumpInstructionBytes(uptr pc);
@@ -827,6 +826,9 @@ struct SignalContext {
// String description of the signal.
const char *Describe() const;
+ // Returns true if signal is stack overflow.
+ bool IsStackOverflow() const;
+
private:
// Platform specific initialization.
void InitPcSpBp();
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc?rev=313227&r1=313226&r2=313227&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc Wed Sep 13 20:23:02 2017
@@ -97,6 +97,7 @@ void InitTlsSize() {}
void PrintModuleMap() {}
+bool SignalContext::IsStackOverflow() const { return false; }
void SignalContext::DumpAllRegisters(void *context) { UNIMPLEMENTED(); }
const char *SignalContext::Describe() const { UNIMPLEMENTED(); }
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc?rev=313227&r1=313226&r2=313227&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc Wed Sep 13 20:23:02 2017
@@ -215,7 +215,7 @@ void InstallDeadlySignalHandlers(SignalH
MaybeInstallSigaction(SIGILL, handler);
}
-bool IsStackOverflow(const SignalContext &sig) {
+bool SignalContext::IsStackOverflow() const {
// Access at a reasonable offset above SP, or slightly below it (to account
// for x86_64 or PowerPC redzone, ARM push of multiple registers, etc) is
// probably a stack overflow.
@@ -223,10 +223,9 @@ bool IsStackOverflow(const SignalContext
// On s390, the fault address in siginfo points to start of the page, not
// to the precise word that was accessed. Mask off the low bits of sp to
// take it into account.
- bool IsStackAccess =
- sig.addr >= (sig.sp & ~0xFFF) && sig.addr < sig.sp + 0xFFFF;
+ bool IsStackAccess = sig.addr >= (sig.sp & ~0xFFF) && sig.addr < sp + 0xFFFF;
#else
- bool IsStackAccess = sig.addr + 512 > sig.sp && sig.addr < sig.sp + 0xFFFF;
+ bool IsStackAccess = addr + 512 > sp && addr < sp + 0xFFFF;
#endif
#if __powerpc__
@@ -236,8 +235,8 @@ bool IsStackOverflow(const SignalContext
// If the store faults then sp will not have been updated, so test above
// will not work, because the fault address will be more than just "slightly"
// below sp.
- if (!IsStackAccess && IsAccessibleMemoryRange(sig.pc, 4)) {
- u32 inst = *(unsigned *)sig.pc;
+ if (!IsStackAccess && IsAccessibleMemoryRange(pc, 4)) {
+ u32 inst = *(unsigned *)pc;
u32 ra = (inst >> 16) & 0x1F;
u32 opcd = inst >> 26;
u32 xo = (inst >> 1) & 0x3FF;
@@ -257,7 +256,7 @@ bool IsStackOverflow(const SignalContext
// We also check si_code to filter out SEGV caused by something else other
// then hitting the guard page or unmapped memory, like, for example,
// unaligned memory access.
- auto si = static_cast<const siginfo_t *>(sig.siginfo);
+ auto si = static_cast<const siginfo_t *>(siginfo);
return IsStackAccess &&
(si->si_code == si_SEGV_MAPERR || si->si_code == si_SEGV_ACCERR);
}
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc?rev=313227&r1=313226&r2=313227&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Wed Sep 13 20:23:02 2017
@@ -915,6 +915,10 @@ bool IsAccessibleMemoryRange(uptr beg, u
return true;
}
+bool SignalContext::IsStackOverflow() const {
+ return GetType() == EXCEPTION_STACK_OVERFLOW;
+}
+
void SignalContext::InitPcSpBp() {
EXCEPTION_RECORD *exception_record = (EXCEPTION_RECORD *)siginfo;
CONTEXT *context_record = (CONTEXT *)context;
More information about the llvm-commits
mailing list