[compiler-rt] r259741 - [asan] When catching a signal caused by a memory access, print if it's a READ or a WRITE. This touches win/mac files which I have not tested, if a win/mac bot fails I'll try to quick-fix
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 3 18:02:09 PST 2016
Author: kcc
Date: Wed Feb 3 20:02:09 2016
New Revision: 259741
URL: http://llvm.org/viewvc/llvm-project?rev=259741&view=rev
Log:
[asan] When catching a signal caused by a memory access, print if it's a READ or a WRITE. This touches win/mac files which I have not tested, if a win/mac bot fails I'll try to quick-fix
Added:
compiler-rt/trunk/test/asan/TestCases/Linux/segv_read_write.c
Modified:
compiler-rt/trunk/lib/asan/asan_report.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
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=259741&r1=259740&r2=259741&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_report.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_report.cc Wed Feb 3 20:02:09 2016
@@ -761,10 +761,15 @@ void ReportDeadlySignal(const char *desc
" (pc %p bp %p sp %p T%d)\n",
description, (void *)sig.addr, (void *)sig.pc, (void *)sig.bp,
(void *)sig.sp, GetCurrentTidOrInvalid());
- if (sig.pc < GetPageSizeCached()) {
+ Printf("%s", d.EndWarning());
+ if (sig.pc < GetPageSizeCached())
Report("Hint: pc points to the zero page.\n");
+ if (sig.is_memory_access) {
+ Report("The signal is caused by a %s memory access.\n",
+ sig.is_write ? "WRITE" : "READ");
+ if (sig.addr < GetPageSizeCached())
+ Report("Hint: address points to the zero page.\n");
}
- Printf("%s", d.EndWarning());
GET_STACK_TRACE_SIGNAL(sig);
stack.Print();
MaybeDumpInstructionBytes(sig.pc);
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=259741&r1=259740&r2=259741&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Wed Feb 3 20:02:09 2016
@@ -749,15 +749,20 @@ struct SignalContext {
uptr pc;
uptr sp;
uptr bp;
+ bool is_memory_access;
+ bool is_write;
- SignalContext(void *context, uptr addr, uptr pc, uptr sp, uptr bp) :
- context(context), addr(addr), pc(pc), sp(sp), bp(bp) {
- }
+ SignalContext(void *context, uptr addr, uptr pc, uptr sp, uptr bp,
+ bool is_memory_access, bool is_write)
+ : context(context), addr(addr), pc(pc), sp(sp), bp(bp),
+ is_memory_access(is_memory_access), is_write(is_write) {}
// Creates signal context in a platform-specific manner.
static SignalContext Create(void *siginfo, void *context);
};
+// Returns true if the "context" indicates a memory write.
+bool GetSigContextWriteFlag(void *context);
void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp);
void DisableReexec();
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=259741&r1=259740&r2=259741&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Wed Feb 3 20:02:09 2016
@@ -1155,6 +1155,11 @@ void *internal_start_thread(void (*func)
void internal_join_thread(void *th) {}
#endif
+bool GetSigContextWriteFlag(void *context) {
+ ucontext_t *ucontext = (ucontext_t*)context;
+ return ucontext->uc_mcontext.gregs[REG_ERR] & 2;
+}
+
void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
#if defined(__arm__)
ucontext_t *ucontext = (ucontext_t*)context;
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=259741&r1=259740&r2=259741&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Wed Feb 3 20:02:09 2016
@@ -491,6 +491,10 @@ void LogFullErrorReport(const char *buff
// The report is added to CrashLog as part of logging all of Printf output.
}
+bool GetSigContextWriteFlag(void *context) {
+ return false; // FIXME: implement this.
+}
+
void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
ucontext_t *ucontext = (ucontext_t*)context;
# if defined(__aarch64__)
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=259741&r1=259740&r2=259741&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc Wed Feb 3 20:02:09 2016
@@ -323,10 +323,13 @@ bool GetCodeRangeForFile(const char *mod
}
SignalContext SignalContext::Create(void *siginfo, void *context) {
- uptr addr = (uptr)((siginfo_t*)siginfo)->si_addr;
+ auto si = (siginfo_t*)siginfo;
+ uptr addr = (uptr)si->si_addr;
uptr pc, sp, bp;
GetPcSpBp(context, &pc, &sp, &bp);
- return SignalContext(context, addr, pc, sp, bp);
+ bool is_write = GetSigContextWriteFlag(context);
+ bool is_memory_access = si->si_signo == SIGSEGV;
+ return SignalContext(context, addr, pc, sp, bp, is_memory_access, is_write);
}
} // namespace __sanitizer
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=259741&r1=259740&r2=259741&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Wed Feb 3 20:02:09 2016
@@ -744,7 +744,10 @@ SignalContext SignalContext::Create(void
#endif
uptr access_addr = exception_record->ExceptionInformation[1];
- return SignalContext(context, access_addr, pc, sp, bp);
+ bool is_write = false; // FIXME: compute this.
+ bool is_memory_access = false; // FIXME: compute this.
+ return SignalContext(context, access_addr, pc, sp, bp, is_memory_access,
+ is_write);
}
uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) {
Added: compiler-rt/trunk/test/asan/TestCases/Linux/segv_read_write.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/segv_read_write.c?rev=259741&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/segv_read_write.c (added)
+++ compiler-rt/trunk/test/asan/TestCases/Linux/segv_read_write.c Wed Feb 3 20:02:09 2016
@@ -0,0 +1,17 @@
+// RUN: %clangxx_asan -O0 %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=READ
+// RUN: not %run %t write 2>&1 | FileCheck %s --check-prefix=WRITE
+
+static volatile int sink;
+__attribute__((noinline)) void Read(int *ptr) { sink = *ptr; }
+__attribute__((noinline)) void Write(int *ptr) { *ptr = 0; }
+int main(int argc, char **argv) {
+ if (argc == 1)
+ Read((int *)0);
+ else
+ Write((int *)0);
+}
+// READ: AddressSanitizer: SEGV on unknown address
+// READ: The signal is caused by a READ memory access.
+// WRITE: AddressSanitizer: SEGV on unknown address
+// WRITE: The signal is caused by a WRITE memory access.
More information about the llvm-commits
mailing list