[sanitizer] Move IsStackOverflow into SignalContext
llvm-svn: 313227
This commit is contained in:
parent
5d53e050ca
commit
9a4c73e20c
|
@ -37,7 +37,7 @@ void AsanOnDeadlySignal(int signo, void *siginfo, void *context) {
|
|||
ScopedDeadlySignal signal_scope(GetCurrentThread());
|
||||
StartReportDeadlySignal();
|
||||
SignalContext sig(siginfo, context);
|
||||
if (IsStackOverflow(sig))
|
||||
if (sig.IsStackOverflow())
|
||||
ReportStackOverflow(sig);
|
||||
else
|
||||
ReportDeadlySignal(sig);
|
||||
|
|
|
@ -311,7 +311,6 @@ HandleSignalMode GetHandleSignalMode(int signum);
|
|||
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();
|
||||
|
|
|
@ -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(); }
|
||||
|
||||
|
|
|
@ -215,7 +215,7 @@ void InstallDeadlySignalHandlers(SignalHandlerType handler) {
|
|||
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 &sig) {
|
|||
// 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 &sig) {
|
|||
// 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 &sig) {
|
|||
// 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);
|
||||
}
|
||||
|
|
|
@ -915,6 +915,10 @@ bool IsAccessibleMemoryRange(uptr beg, uptr size) {
|
|||
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;
|
||||
|
|
Loading…
Reference in New Issue