[compiler-rt] r313167 - [compiler-rt] Add siginfo into SignalContext
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 13 11:30:06 PDT 2017
Author: vitalybuka
Date: Wed Sep 13 11:30:06 2017
New Revision: 313167
URL: http://llvm.org/viewvc/llvm-project?rev=313167&view=rev
Log:
[compiler-rt] Add siginfo into SignalContext
Summary:
Information stored there is often been passed along with SignalContext.
Part of https://github.com/google/sanitizers/issues/637
Reviewers: eugenis, alekseyshl
Subscribers: kubamracek, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D37792
Modified:
compiler-rt/trunk/lib/asan/asan_errors.h
compiler-rt/trunk/lib/asan/asan_posix.cc
compiler-rt/trunk/lib/asan/asan_report.cc
compiler-rt/trunk/lib/asan/asan_report.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.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_errors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_errors.h?rev=313167&r1=313166&r2=313167&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_errors.h (original)
+++ compiler-rt/trunk/lib/asan/asan_errors.h Wed Sep 13 11:30:06 2017
@@ -57,14 +57,14 @@ struct ErrorDeadlySignal : ErrorBase {
// VS2013 doesn't implement unrestricted unions, so we need a trivial default
// constructor
ErrorDeadlySignal() = default;
- ErrorDeadlySignal(u32 tid, const SignalContext &sig, int signo_)
+ ErrorDeadlySignal(u32 tid, const SignalContext &sig)
: ErrorBase(tid),
addr(sig.addr),
pc(sig.pc),
bp(sig.bp),
sp(sig.sp),
context(sig.context),
- signo(signo_),
+ signo(sig.GetType()),
write_flag(sig.write_flag),
is_memory_access(sig.is_memory_access) {
scariness.Clear();
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=313167&r1=313166&r2=313167&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_posix.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_posix.cc Wed Sep 13 11:30:06 2017
@@ -37,10 +37,10 @@ void AsanOnDeadlySignal(int signo, void
ScopedDeadlySignal signal_scope(GetCurrentThread());
StartReportDeadlySignal();
SignalContext sig = SignalContext::Create(siginfo, context);
- if (IsStackOverflow(((siginfo_t *)siginfo)->si_code, sig))
+ if (IsStackOverflow(sig))
ReportStackOverflow(sig);
else
- ReportDeadlySignal(signo, sig);
+ ReportDeadlySignal(sig);
}
// ---------------------- TSD ---------------- {{{1
Modified: compiler-rt/trunk/lib/asan/asan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_report.cc?rev=313167&r1=313166&r2=313167&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_report.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_report.cc Wed Sep 13 11:30:06 2017
@@ -266,9 +266,9 @@ void ReportStackOverflow(const SignalCon
in_report.ReportError(error);
}
-void ReportDeadlySignal(int signo, const SignalContext &sig) {
+void ReportDeadlySignal(const SignalContext &sig) {
ScopedInErrorReport in_report(/*fatal*/ true);
- ErrorDeadlySignal error(GetCurrentTidOrInvalid(), sig, signo);
+ ErrorDeadlySignal error(GetCurrentTidOrInvalid(), sig);
in_report.ReportError(error);
}
Modified: compiler-rt/trunk/lib/asan/asan_report.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_report.h?rev=313167&r1=313166&r2=313167&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_report.h (original)
+++ compiler-rt/trunk/lib/asan/asan_report.h Wed Sep 13 11:30:06 2017
@@ -47,7 +47,7 @@ bool ParseFrameDescription(const char *f
void ReportGenericError(uptr pc, uptr bp, uptr sp, uptr addr, bool is_write,
uptr access_size, u32 exp, bool fatal);
void ReportStackOverflow(const SignalContext &sig);
-void ReportDeadlySignal(int signo, const SignalContext &sig);
+void ReportDeadlySignal(const SignalContext &sig);
void ReportNewDeleteSizeMismatch(uptr addr, uptr delete_size,
BufferedStackTrace *free_stack);
void ReportDoubleFree(uptr addr, BufferedStackTrace *free_stack);
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=313167&r1=313166&r2=313167&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Wed Sep 13 11:30:06 2017
@@ -312,7 +312,7 @@ void InstallDeadlySignalHandlers(SignalH
const char *DescribeSignalOrException(int signo);
// Signal reporting.
void StartReportDeadlySignal();
-bool IsStackOverflow(int code, const SignalContext &sig);
+bool IsStackOverflow(const SignalContext &sig);
// FIXME: Hide after moving more signal handling code into common.
void MaybeReportNonExecRegion(uptr pc);
void MaybeDumpInstructionBytes(uptr pc);
@@ -795,6 +795,7 @@ static inline void SanitizerBreakOptimiz
}
struct SignalContext {
+ void *siginfo;
void *context;
uptr addr;
uptr pc;
@@ -804,9 +805,12 @@ struct SignalContext {
enum WriteFlag { UNKNOWN, READ, WRITE } write_flag;
- SignalContext(void *context, uptr addr, uptr pc, uptr sp, uptr bp,
- bool is_memory_access, WriteFlag write_flag)
- : context(context),
+ // SignalContext is going to keep pointers to siginfo and context without
+ // owning them.
+ SignalContext(void *siginfo, void *context, uptr addr, uptr pc, uptr sp,
+ uptr bp, bool is_memory_access, WriteFlag write_flag)
+ : siginfo(siginfo),
+ context(context),
addr(addr),
pc(pc),
sp(sp),
@@ -821,6 +825,12 @@ struct SignalContext {
// Returns true if the "context" indicates a memory write.
static WriteFlag GetWriteFlag(void *context);
+
+ // Type of signal e.g. SIGSEGV or EXCEPTION_ACCESS_VIOLATION.
+ int GetType() const;
+
+ // String description of the signal.
+ const char *Describe() const { return DescribeSignalOrException(GetType()); }
};
void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp);
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc?rev=313167&r1=313166&r2=313167&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc Wed Sep 13 11:30:06 2017
@@ -296,13 +296,18 @@ bool GetCodeRangeForFile(const char *mod
}
SignalContext SignalContext::Create(void *siginfo, void *context) {
- auto si = (siginfo_t *)siginfo;
+ auto si = static_cast<const siginfo_t *>(siginfo);
uptr addr = (uptr)si->si_addr;
uptr pc, sp, bp;
GetPcSpBp(context, &pc, &sp, &bp);
WriteFlag write_flag = GetWriteFlag(context);
bool is_memory_access = si->si_signo == SIGSEGV;
- return SignalContext(context, addr, pc, sp, bp, is_memory_access, write_flag);
+ return SignalContext(siginfo, context, addr, pc, sp, bp, is_memory_access,
+ write_flag);
+}
+
+int SignalContext::GetType() const {
+ return static_cast<const siginfo_t *>(siginfo)->si_signo;
}
const char *DescribeSignalOrException(int signo) {
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=313167&r1=313166&r2=313167&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 11:30:06 2017
@@ -215,7 +215,7 @@ void InstallDeadlySignalHandlers(SignalH
MaybeInstallSigaction(SIGILL, handler);
}
-bool IsStackOverflow(int code, const SignalContext &sig) {
+bool IsStackOverflow(const SignalContext &sig) {
// 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.
@@ -257,7 +257,9 @@ bool IsStackOverflow(int code, const 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.
- return IsStackAccess && (code == si_SEGV_MAPERR || code == si_SEGV_ACCERR);
+ auto si = static_cast<const siginfo_t *>(sig.siginfo);
+ return IsStackAccess &&
+ (si->si_code == si_SEGV_MAPERR || si->si_code == si_SEGV_ACCERR);
}
void StartReportDeadlySignal() {
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=313167&r1=313166&r2=313167&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Wed Sep 13 11:30:06 2017
@@ -966,14 +966,18 @@ SignalContext SignalContext::Create(void
case 8: write_flag = SignalContext::UNKNOWN; break;
}
bool is_memory_access = write_flag != SignalContext::UNKNOWN;
- return SignalContext(context, access_addr, pc, sp, bp, is_memory_access,
- write_flag);
+ return SignalContext(siginfo, context, access_addr, pc, sp, bp,
+ is_memory_access, write_flag);
}
void SignalContext::DumpAllRegisters(void *context) {
// FIXME: Implement this.
}
+int SignalContext::GetType() const {
+ return static_cast<const EXCEPTION_RECORD *>(siginfo)->ExceptionCode;
+}
+
uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) {
// FIXME: Actually implement this function.
CHECK_GT(buf_len, 0);
More information about the llvm-commits
mailing list