[llvm-commits] [compiler-rt] r152768 - in /compiler-rt/trunk/lib/asan: asan_interceptors.cc asan_internal.h asan_rtl.cc asan_stack.h output_tests/memcmp_test.cc

Kostya Serebryany kcc at google.com
Wed Mar 14 18:36:00 PDT 2012


Author: kcc
Date: Wed Mar 14 20:36:00 2012
New Revision: 152768

URL: http://llvm.org/viewvc/llvm-project?rev=152768&view=rev
Log:
[asan] fix unwinding inside libc intercepors (asan issue #46)

Modified:
    compiler-rt/trunk/lib/asan/asan_interceptors.cc
    compiler-rt/trunk/lib/asan/asan_internal.h
    compiler-rt/trunk/lib/asan/asan_rtl.cc
    compiler-rt/trunk/lib/asan/asan_stack.h
    compiler-rt/trunk/lib/asan/output_tests/memcmp_test.cc

Modified: compiler-rt/trunk/lib/asan/asan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.cc?rev=152768&r1=152767&r2=152768&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.cc Wed Mar 14 20:36:00 2012
@@ -63,12 +63,12 @@
 
 // Instruments read/write access to a single byte in memory.
 // On error calls __asan_report_error, which aborts the program.
-static NOINLINE void AccessAddress(uintptr_t address, bool isWrite) {
-  if (AddressIsPoisoned(address)) {
-    GET_BP_PC_SP;
-    __asan_report_error(pc, bp, sp, address, isWrite, /* access_size */ 1);
-  }
-}
+#define ACCESS_ADDRESS(address, isWrite)   do {         \
+  if (AddressIsPoisoned(address)) {                     \
+    GET_CURRENT_PC_BP_SP;                               \
+    __asan_report_error(pc, bp, sp, address, isWrite, /* access_size */ 1); \
+  } \
+} while (0)
 
 // We implement ACCESS_MEMORY_RANGE, ASAN_READ_RANGE,
 // and ASAN_WRITE_RANGE as macro instead of function so
@@ -81,8 +81,8 @@
 #define ACCESS_MEMORY_RANGE(offset, size, isWrite) do { \
   if (size > 0) { \
     uintptr_t ptr = (uintptr_t)(offset); \
-    AccessAddress(ptr, isWrite); \
-    AccessAddress(ptr + (size) - 1, isWrite); \
+    ACCESS_ADDRESS(ptr, isWrite); \
+    ACCESS_ADDRESS(ptr + (size) - 1, isWrite); \
   } \
 } while (0)
 

Modified: compiler-rt/trunk/lib/asan/asan_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_internal.h?rev=152768&r1=152767&r2=152768&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_internal.h (original)
+++ compiler-rt/trunk/lib/asan/asan_internal.h Wed Mar 14 20:36:00 2012
@@ -296,12 +296,6 @@
 
 typedef thread_return_t (THREAD_CALLING_CONV *thread_callback_t)(void* arg);
 
-#define GET_BP_PC_SP \
-  uintptr_t bp = GET_CURRENT_FRAME();              \
-  uintptr_t pc = GET_CALLER_PC();                  \
-  uintptr_t local_stack;                           \
-  uintptr_t sp = (uintptr_t)&local_stack;
-
 // These magic values are written to shadow for better error reporting.
 const int kAsanHeapLeftRedzoneMagic = 0xfa;
 const int kAsanHeapRightRedzoneMagic = 0xfb;

Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=152768&r1=152767&r2=152768&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Wed Mar 14 20:36:00 2012
@@ -221,7 +221,7 @@
 NOINLINE ASAN_INTERFACE_ATTRIBUTE                                   \
 extern "C" void __asan_report_ ## type ## size(uintptr_t addr);     \
 extern "C" void __asan_report_ ## type ## size(uintptr_t addr) {    \
-  GET_BP_PC_SP;                                                     \
+  GET_CALLER_PC_BP_SP;                                              \
   __asan_report_error(pc, bp, sp, addr, is_write, size);            \
 }
 

Modified: compiler-rt/trunk/lib/asan/asan_stack.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_stack.h?rev=152768&r1=152767&r2=152768&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_stack.h (original)
+++ compiler-rt/trunk/lib/asan/asan_stack.h Wed Mar 14 20:36:00 2012
@@ -57,6 +57,22 @@
 
 }  // namespace __asan
 
+// Use this macro if you want to print stack trace with the caller
+// of the current function in the top frame.
+#define GET_CALLER_PC_BP_SP \
+  uintptr_t bp = GET_CURRENT_FRAME();              \
+  uintptr_t pc = GET_CALLER_PC();                  \
+  uintptr_t local_stack;                           \
+  uintptr_t sp = (uintptr_t)&local_stack;
+
+// Use this macro if you want to print stack trace with the current
+// function in the top frame.
+#define GET_CURRENT_PC_BP_SP \
+  uintptr_t bp = GET_CURRENT_FRAME();              \
+  uintptr_t pc = AsanStackTrace::GetCurrentPc();   \
+  uintptr_t local_stack;                           \
+  uintptr_t sp = (uintptr_t)&local_stack;
+
 // Get the stack trace with the given pc and bp.
 // The pc will be in the position 0 of the resulting stack trace.
 // The bp may refer to the current frame or to the caller's frame.

Modified: compiler-rt/trunk/lib/asan/output_tests/memcmp_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/output_tests/memcmp_test.cc?rev=152768&r1=152767&r2=152768&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/output_tests/memcmp_test.cc (original)
+++ compiler-rt/trunk/lib/asan/output_tests/memcmp_test.cc Wed Mar 14 20:36:00 2012
@@ -3,6 +3,8 @@
   char a1[] = {argc, 2, 3, 4};
   char a2[] = {1, 2*argc, 3, 4};
 // Check-Common: AddressSanitizer stack-buffer-overflow
+// Check-Common: {{#0.*memcmp}}
+// Check-Common: {{#1.*main}}
   int res = memcmp(a1, a2, 4 + argc);  // BOOM
   return res;
 }





More information about the llvm-commits mailing list