[llvm-commits] [compiler-rt] r162752 - in /compiler-rt/trunk/lib/asan: asan_linux.cc asan_mac.cc asan_stack.cc asan_stack.h

Kostya Serebryany kcc at google.com
Tue Aug 28 06:25:56 PDT 2012


Author: kcc
Date: Tue Aug 28 08:25:55 2012
New Revision: 162752

URL: http://llvm.org/viewvc/llvm-project?rev=162752&view=rev
Log:
[asan] more refactoring to move StackTrace to sanitizer_common

Modified:
    compiler-rt/trunk/lib/asan/asan_linux.cc
    compiler-rt/trunk/lib/asan/asan_mac.cc
    compiler-rt/trunk/lib/asan/asan_stack.cc
    compiler-rt/trunk/lib/asan/asan_stack.h

Modified: compiler-rt/trunk/lib/asan/asan_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_linux.cc?rev=162752&r1=162751&r2=162752&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_linux.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_linux.cc Tue Aug 28 08:25:55 2012
@@ -17,6 +17,7 @@
 #include "asan_internal.h"
 #include "asan_lock.h"
 #include "asan_thread.h"
+#include "asan_thread_registry.h"
 #include "sanitizer_common/sanitizer_libc.h"
 #include "sanitizer_common/sanitizer_procmaps.h"
 
@@ -131,15 +132,17 @@
   return UNWIND_CONTINUE;
 }
 
-void StackTrace::GetStackTrace(uptr max_s, uptr pc, uptr bp) {
-  size = 0;
-  trace[0] = pc;
+void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp) {
+  stack->size = 0;
+  stack->trace[0] = pc;
   if ((max_s) > 1) {
-    max_size = max_s;
+    stack->max_size = max_s;
 #ifdef __arm__
-    _Unwind_Backtrace(Unwind_Trace, this);
+    _Unwind_Backtrace(Unwind_Trace, stack);
 #else
-     FastUnwindStack(pc, bp);
+    if (!asan_inited) return;
+    if (AsanThread *t = asanThreadRegistry().GetCurrent())
+      stack->FastUnwindStack(pc, bp, t->stack_top(), t->stack_bottom());
 #endif
   }
 }

Modified: compiler-rt/trunk/lib/asan/asan_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_mac.cc?rev=162752&r1=162751&r2=162752&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_mac.cc Tue Aug 28 08:25:55 2012
@@ -152,12 +152,14 @@
   OSSpinLockUnlock((OSSpinLock*)&opaque_storage_);
 }
 
-void StackTrace::GetStackTrace(uptr max_s, uptr pc, uptr bp) {
-  size = 0;
-  trace[0] = pc;
+void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp) {
+  stack->size = 0;
+  stack->trace[0] = pc;
   if ((max_s) > 1) {
-    max_size = max_s;
-    FastUnwindStack(pc, bp);
+    stack->max_size = max_s;
+    if (!asan_inited) return;
+    if (AsanThread *t = asanThreadRegistry().GetCurrent())
+      stack->FastUnwindStack(pc, bp, t->stack_top(), t->stack_bottom());
   }
 }
 

Modified: compiler-rt/trunk/lib/asan/asan_stack.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_stack.cc?rev=162752&r1=162751&r2=162752&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_stack.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_stack.cc Tue Aug 28 08:25:55 2012
@@ -11,12 +11,8 @@
 //
 // Code for ASan stack trace.
 //===----------------------------------------------------------------------===//
-#include "asan_interceptors.h"
 #include "asan_interface.h"
-#include "asan_lock.h"
 #include "asan_stack.h"
-#include "asan_thread.h"
-#include "asan_thread_registry.h"
 #include "sanitizer_common/sanitizer_procmaps.h"
 #include "sanitizer_common/sanitizer_symbolizer.h"
 
@@ -100,19 +96,15 @@
   return GET_CALLER_PC();
 }
 
-void StackTrace::FastUnwindStack(uptr pc, uptr bp) {
+void StackTrace::FastUnwindStack(uptr pc, uptr bp,
+                                 uptr stack_top, uptr stack_bottom) {
   CHECK(size == 0 && trace[0] == pc);
   size = 1;
-  if (!asan_inited) return;
-  AsanThread *t = asanThreadRegistry().GetCurrent();
-  if (!t) return;
   uptr *frame = (uptr*)bp;
   uptr *prev_frame = frame;
-  uptr *top = (uptr*)t->stack_top();
-  uptr *bottom = (uptr*)t->stack_bottom();
   while (frame >= prev_frame &&
-         frame < top - 2 &&
-         frame > bottom &&
+         frame < (uptr*)stack_top - 2 &&
+         frame > (uptr*)stack_bottom &&
          size < max_size) {
     uptr pc1 = frame[1];
     if (pc1 != pc) {

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=162752&r1=162751&r2=162752&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_stack.h (original)
+++ compiler-rt/trunk/lib/asan/asan_stack.h Tue Aug 28 08:25:55 2012
@@ -43,9 +43,7 @@
     }
   }
 
-  void GetStackTrace(uptr max_s, uptr pc, uptr bp);
-
-  void FastUnwindStack(uptr pc, uptr bp);
+  void FastUnwindStack(uptr pc, uptr bp, uptr stack_top, uptr stack_bottom);
 
   static uptr GetCurrentPc();
 
@@ -55,6 +53,10 @@
                               u32 *compressed, uptr size);
 };
 
+void GetStackTrace(StackTrace *trace, uptr max_s, uptr pc, uptr bp);
+
+
+
 }  // namespace __asan
 
 // Use this macro if you want to print stack trace with the caller
@@ -79,7 +81,7 @@
 // fast_unwind is currently unused.
 #define GET_STACK_TRACE_WITH_PC_AND_BP(max_s, pc, bp)               \
   StackTrace stack;                                             \
-  stack.GetStackTrace(max_s, pc, bp)
+  GetStackTrace(&stack, max_s, pc, bp)
 
 // NOTE: A Rule of thumb is to retrieve stack trace in the interceptors
 // as early as possible (in functions exposed to the user), as we generally





More information about the llvm-commits mailing list