summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2012-08-28 13:25:55 +0000
committerKostya Serebryany <kcc@google.com>2012-08-28 13:25:55 +0000
commit2b939c3abc8b7713ef28000bd768ca6d77445f45 (patch)
tree52290ded4e51a97e788ec2b2ecbddda1bdc0a685
parent8757a68c78f76fca32d3f2256fa70a7b550aa9e1 (diff)
[asan] more refactoring to move StackTrace to sanitizer_common
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@162752 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/asan/asan_linux.cc15
-rw-r--r--lib/asan/asan_mac.cc12
-rw-r--r--lib/asan/asan_stack.cc16
-rw-r--r--lib/asan/asan_stack.h10
4 files changed, 26 insertions, 27 deletions
diff --git a/lib/asan/asan_linux.cc b/lib/asan/asan_linux.cc
index bbc7dad13..5c52ddc96 100644
--- a/lib/asan/asan_linux.cc
+++ b/lib/asan/asan_linux.cc
@@ -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 @@ _Unwind_Reason_Code Unwind_Trace(struct _Unwind_Context *ctx,
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
}
}
diff --git a/lib/asan/asan_mac.cc b/lib/asan/asan_mac.cc
index d7fc6c47b..a96117dfe 100644
--- a/lib/asan/asan_mac.cc
+++ b/lib/asan/asan_mac.cc
@@ -152,12 +152,14 @@ void AsanLock::Unlock() {
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());
}
}
diff --git a/lib/asan/asan_stack.cc b/lib/asan/asan_stack.cc
index 08fdb4255..618fc32d5 100644
--- a/lib/asan/asan_stack.cc
+++ b/lib/asan/asan_stack.cc
@@ -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 @@ uptr StackTrace::GetCurrentPc() {
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) {
diff --git a/lib/asan/asan_stack.h b/lib/asan/asan_stack.h
index df1f24662..0d483b9a1 100644
--- a/lib/asan/asan_stack.h
+++ b/lib/asan/asan_stack.h
@@ -43,9 +43,7 @@ struct StackTrace {
}
}
- 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 @@ struct StackTrace {
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 @@ struct StackTrace {
// 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