[compiler-rt] r260539 - [Windows] Fill in read/write information in SignalContext

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 11 08:44:35 PST 2016


Author: rnk
Date: Thu Feb 11 10:44:35 2016
New Revision: 260539

URL: http://llvm.org/viewvc/llvm-project?rev=260539&view=rev
Log:
[Windows] Fill in read/write information in SignalContext

Implements https://github.com/google/sanitizers/issues/653

Added:
    compiler-rt/trunk/test/asan/TestCases/Windows/crash_read_write.cc
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/report_after_syminitialize.cc

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=260539&r1=260538&r2=260539&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Thu Feb 11 10:44:35 2016
@@ -744,8 +744,17 @@ SignalContext SignalContext::Create(void
 #endif
   uptr access_addr = exception_record->ExceptionInformation[1];
 
-  WriteFlag write_flag = SignalContext::UNKNOWN;  // FIXME: compute this.
-  bool is_memory_access = false;                  // FIXME: compute this.
+  // The contents of this array are documented at
+  // https://msdn.microsoft.com/en-us/library/windows/desktop/aa363082(v=vs.85).aspx
+  // The first element indicates read as 0, write as 1, or execute as 8.  The
+  // second element is the faulting address.
+  WriteFlag write_flag = SignalContext::UNKNOWN;
+  switch (exception_record->ExceptionInformation[0]) {
+  case 0: write_flag = SignalContext::READ; break;
+  case 1: write_flag = SignalContext::WRITE; break;
+  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);
 }

Added: compiler-rt/trunk/test/asan/TestCases/Windows/crash_read_write.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/crash_read_write.cc?rev=260539&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/crash_read_write.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/crash_read_write.cc Thu Feb 11 10:44:35 2016
@@ -0,0 +1,29 @@
+// RUN: %clangxx_asan -std=c++11 -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
+
+#include <windows.h>
+#include <stdio.h>
+
+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) {
+  // Writes to shadow are detected as reads from shadow gap (because of how the
+  // shadow mapping works). This is kinda hard to fix. Test a random address in
+  // the application part of the address space.
+  void *volatile p = VirtualAlloc(0, 4096, MEM_COMMIT, PAGE_READONLY);
+  bool ok = VirtualFree(p, 0, MEM_RELEASE);
+  if (!ok) {
+    printf("VirtualFree failed\n");
+    return 0;
+  }
+  if (argc == 1)
+    Read((int *)p);
+  else
+    Write((int *)p);
+}
+// READ: AddressSanitizer: access-violation on unknown address
+// READ: The signal is caused by a READ memory access.
+// WRITE: AddressSanitizer: access-violation on unknown address
+// WRITE: The signal is caused by a WRITE memory access.

Modified: compiler-rt/trunk/test/asan/TestCases/Windows/report_after_syminitialize.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/report_after_syminitialize.cc?rev=260539&r1=260538&r2=260539&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/report_after_syminitialize.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/report_after_syminitialize.cc Thu Feb 11 10:44:35 2016
@@ -14,8 +14,10 @@ int main() {
 
   *(volatile int*)0 = 42;
   // CHECK: ERROR: AddressSanitizer: access-violation on unknown address
+  // CHECK: The signal is caused by a WRITE memory access.
+  // CHECK: Hint: address points to the zero page.
   // CHECK-NEXT: {{WARNING: Failed to use and restart external symbolizer}}
   // CHECK-NEXT: {{WARNING: .*DbgHelp}}
-  // CHECK: {{#0 0x.* in main.*report_after_syminitialize.cc:}}[[@LINE-4]]
+  // CHECK: {{#0 0x.* in main.*report_after_syminitialize.cc:}}[[@LINE-6]]
   // CHECK: AddressSanitizer can not provide additional info.
 }




More information about the llvm-commits mailing list