Index: compiler-rt/trunk/lib/asan/asan_stack.h =================================================================== --- compiler-rt/trunk/lib/asan/asan_stack.h +++ compiler-rt/trunk/lib/asan/asan_stack.h @@ -26,37 +26,6 @@ void SetMallocContextSize(u32 size); u32 GetMallocContextSize(); -// 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. -ALWAYS_INLINE -void GetStackTrace(BufferedStackTrace *stack, uptr max_depth, uptr pc, uptr bp, - void *context, bool fast) { -#if SANITIZER_WINDOWS - stack->Unwind(max_depth, pc, 0, context, 0, 0, false); -#else - AsanThread *t; - stack->size = 0; - if (LIKELY(asan_inited)) { - if ((t = GetCurrentThread()) && !t->isUnwinding()) { - uptr stack_top = t->stack_top(); - uptr stack_bottom = t->stack_bottom(); - ScopedUnwinding unwind_scope(t); - if (!SANITIZER_MIPS || IsValidFrame(bp, stack_top, stack_bottom)) { - if (StackTrace::WillUseFastUnwind(fast)) - stack->Unwind(max_depth, pc, bp, nullptr, stack_top, stack_bottom, - true); - else - stack->Unwind(max_depth, pc, 0, context, 0, 0, false); - } - } else if (!t && !fast) { - /* If GetCurrentThread() has failed, try to do slow unwind anyways. */ - stack->Unwind(max_depth, pc, bp, context, 0, 0, false); - } - } -#endif // SANITIZER_WINDOWS -} - } // namespace __asan // NOTE: A Rule of thumb is to retrieve stack trace in the interceptors Index: compiler-rt/trunk/lib/asan/asan_stack.cc =================================================================== --- compiler-rt/trunk/lib/asan/asan_stack.cc +++ compiler-rt/trunk/lib/asan/asan_stack.cc @@ -28,6 +28,34 @@ } // namespace __asan +void __sanitizer::GetStackTrace(BufferedStackTrace *stack, uptr max_depth, + uptr pc, uptr bp, void *context, bool fast) { + using namespace __asan; +#if SANITIZER_WINDOWS + stack->Unwind(max_depth, pc, 0, context, 0, 0, false); +#else + AsanThread *t; + stack->size = 0; + if (LIKELY(asan_inited)) { + if ((t = GetCurrentThread()) && !t->isUnwinding()) { + uptr stack_top = t->stack_top(); + uptr stack_bottom = t->stack_bottom(); + ScopedUnwinding unwind_scope(t); + if (!SANITIZER_MIPS || IsValidFrame(bp, stack_top, stack_bottom)) { + if (StackTrace::WillUseFastUnwind(fast)) + stack->Unwind(max_depth, pc, bp, nullptr, stack_top, stack_bottom, + true); + else + stack->Unwind(max_depth, pc, 0, context, 0, 0, false); + } + } else if (!t && !fast) { + /* If GetCurrentThread() has failed, try to do slow unwind anyways. */ + stack->Unwind(max_depth, pc, bp, context, 0, 0, false); + } + } +#endif // SANITIZER_WINDOWS +} + // ------------------ Interface -------------- {{{1 extern "C" { Index: compiler-rt/trunk/lib/hwasan/hwasan.h =================================================================== --- compiler-rt/trunk/lib/hwasan/hwasan.h +++ compiler-rt/trunk/lib/hwasan/hwasan.h @@ -104,9 +104,6 @@ ~SymbolizerScope() { ExitSymbolizer(); } }; -void GetStackTrace(BufferedStackTrace *stack, uptr max_s, uptr pc, uptr bp, - void *context, bool request_fast_unwind); - // Returns a "chained" origin id, pointing to the given stack trace followed by // the previous origin id. u32 ChainOrigin(u32 id, StackTrace *stack); Index: compiler-rt/trunk/lib/hwasan/hwasan.cpp =================================================================== --- compiler-rt/trunk/lib/hwasan/hwasan.cpp +++ compiler-rt/trunk/lib/hwasan/hwasan.cpp @@ -144,26 +144,6 @@ if (common_flags()->help) parser.PrintFlagDescriptions(); } -void GetStackTrace(BufferedStackTrace *stack, uptr max_s, uptr pc, uptr bp, - void *context, bool request_fast_unwind) { - Thread *t = GetCurrentThread(); - if (!t) { - // the thread is still being created. - stack->size = 0; - return; - } - if (!StackTrace::WillUseFastUnwind(request_fast_unwind)) { - // Block reports from our interceptors during _Unwind_Backtrace. - SymbolizerScope sym_scope; - return stack->Unwind(max_s, pc, bp, context, 0, 0, request_fast_unwind); - } - if (StackTrace::WillUseFastUnwind(request_fast_unwind)) - stack->Unwind(max_s, pc, bp, nullptr, t->stack_top(), t->stack_bottom(), - true); - else - stack->Unwind(max_s, pc, 0, context, 0, 0, false); -} - static void HWAsanCheckFailed(const char *file, int line, const char *cond, u64 v1, u64 v2) { Report("HWAddressSanitizer CHECK failed: %s:%d \"%s\" (0x%zx, 0x%zx)\n", file, @@ -264,6 +244,28 @@ } // namespace __hwasan +void __sanitizer::GetStackTrace(BufferedStackTrace *stack, uptr max_s, uptr pc, + uptr bp, void *context, + bool request_fast_unwind) { + using namespace __hwasan; + Thread *t = GetCurrentThread(); + if (!t) { + // the thread is still being created. + stack->size = 0; + return; + } + if (!StackTrace::WillUseFastUnwind(request_fast_unwind)) { + // Block reports from our interceptors during _Unwind_Backtrace. + SymbolizerScope sym_scope; + return stack->Unwind(max_s, pc, bp, context, 0, 0, request_fast_unwind); + } + if (StackTrace::WillUseFastUnwind(request_fast_unwind)) + stack->Unwind(max_s, pc, bp, nullptr, t->stack_top(), t->stack_bottom(), + true); + else + stack->Unwind(max_s, pc, 0, context, 0, 0, false); +} + // Interface. using namespace __hwasan; Index: compiler-rt/trunk/lib/lsan/lsan.h =================================================================== --- compiler-rt/trunk/lib/lsan/lsan.h +++ compiler-rt/trunk/lib/lsan/lsan.h @@ -40,28 +40,6 @@ __lsan_init(); \ } while (0) -// 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. -ALWAYS_INLINE -void GetStackTrace(__sanitizer::BufferedStackTrace *stack, - __sanitizer::uptr max_depth, __sanitizer::uptr pc, - __sanitizer::uptr bp, void *context, bool fast) { - uptr stack_top = 0, stack_bottom = 0; - ThreadContext *t; - if (__sanitizer::StackTrace::WillUseFastUnwind(fast) && - (t = CurrentThreadContext())) { - stack_top = t->stack_end(); - stack_bottom = t->stack_begin(); - } - if (!SANITIZER_MIPS || IsValidFrame(bp, stack_top, stack_bottom)) { - if (StackTrace::WillUseFastUnwind(fast)) - stack->Unwind(max_depth, pc, bp, nullptr, stack_top, stack_bottom, true); - else - stack->Unwind(max_depth, pc, 0, context, 0, 0, false); - } -} - } // namespace __lsan extern bool lsan_inited; Index: compiler-rt/trunk/lib/lsan/lsan.cc =================================================================== --- compiler-rt/trunk/lib/lsan/lsan.cc +++ compiler-rt/trunk/lib/lsan/lsan.cc @@ -32,6 +32,24 @@ } // namespace __lsan +void __sanitizer::GetStackTrace(BufferedStackTrace *stack, uptr max_depth, + uptr pc, uptr bp, void *context, bool fast) { + using namespace __lsan; + uptr stack_top = 0, stack_bottom = 0; + ThreadContext *t; + if (StackTrace::WillUseFastUnwind(fast) && + (t = CurrentThreadContext())) { + stack_top = t->stack_end(); + stack_bottom = t->stack_begin(); + } + if (!SANITIZER_MIPS || IsValidFrame(bp, stack_top, stack_bottom)) { + if (StackTrace::WillUseFastUnwind(fast)) + stack->Unwind(max_depth, pc, bp, nullptr, stack_top, stack_bottom, true); + else + stack->Unwind(max_depth, pc, 0, context, 0, 0, false); + } +} + using namespace __lsan; // NOLINT static void InitializeFlags() { Index: compiler-rt/trunk/lib/msan/msan.h =================================================================== --- compiler-rt/trunk/lib/msan/msan.h +++ compiler-rt/trunk/lib/msan/msan.h @@ -312,9 +312,6 @@ void PrintWarning(uptr pc, uptr bp); void PrintWarningWithOrigin(uptr pc, uptr bp, u32 origin); -void GetStackTrace(BufferedStackTrace *stack, uptr max_s, uptr pc, uptr bp, - void *context, bool request_fast_unwind); - // Unpoison first n function arguments. void UnpoisonParam(uptr n); void UnpoisonThreadLocalState(); Index: compiler-rt/trunk/lib/msan/msan.cc =================================================================== --- compiler-rt/trunk/lib/msan/msan.cc +++ compiler-rt/trunk/lib/msan/msan.cc @@ -221,21 +221,6 @@ if (f->store_context_size < 1) f->store_context_size = 1; } -void GetStackTrace(BufferedStackTrace *stack, uptr max_s, uptr pc, uptr bp, - void *context, bool request_fast_unwind) { - MsanThread *t = GetCurrentThread(); - if (!t || !StackTrace::WillUseFastUnwind(request_fast_unwind)) { - // Block reports from our interceptors during _Unwind_Backtrace. - SymbolizerScope sym_scope; - return stack->Unwind(max_s, pc, bp, context, 0, 0, false); - } - if (StackTrace::WillUseFastUnwind(request_fast_unwind)) - stack->Unwind(max_s, pc, bp, nullptr, t->stack_top(), t->stack_bottom(), - true); - else - stack->Unwind(max_s, pc, 0, context, 0, 0, false); -} - void PrintWarning(uptr pc, uptr bp) { PrintWarningWithOrigin(pc, bp, __msan_origin_tls); } @@ -316,6 +301,23 @@ } // namespace __msan +void __sanitizer::GetStackTrace(BufferedStackTrace *stack, uptr max_s, uptr pc, + uptr bp, void *context, + bool request_fast_unwind) { + using namespace __msan; + MsanThread *t = GetCurrentThread(); + if (!t || !StackTrace::WillUseFastUnwind(request_fast_unwind)) { + // Block reports from our interceptors during _Unwind_Backtrace. + SymbolizerScope sym_scope; + return stack->Unwind(max_s, pc, bp, context, 0, 0, false); + } + if (StackTrace::WillUseFastUnwind(request_fast_unwind)) + stack->Unwind(max_s, pc, bp, nullptr, t->stack_top(), t->stack_bottom(), + true); + else + stack->Unwind(max_s, pc, 0, context, 0, 0, false); +} + // Interface. using namespace __msan; Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h =================================================================== --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h @@ -121,6 +121,12 @@ return frame > stack_bottom && frame < stack_top - 2 * sizeof (uhwptr); } +// 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. +void GetStackTrace(BufferedStackTrace *stack, uptr max_depth, uptr pc, uptr bp, + void *context, bool request_fast_unwind); + } // namespace __sanitizer // Use this macro if you want to print stack trace with the caller Index: compiler-rt/trunk/lib/tsan/rtl/tsan_stack_trace.cc =================================================================== --- compiler-rt/trunk/lib/tsan/rtl/tsan_stack_trace.cc +++ compiler-rt/trunk/lib/tsan/rtl/tsan_stack_trace.cc @@ -48,3 +48,15 @@ } } // namespace __tsan + +void __sanitizer::GetStackTrace(BufferedStackTrace *stack, uptr max_depth, + uptr pc, uptr bp, void *context, + bool request_fast_unwind) { + uptr top = 0; + uptr bottom = 0; + if (StackTrace::WillUseFastUnwind(request_fast_unwind)) { + GetThreadStackTopAndBottom(false, &top, &bottom); + stack->Unwind(kStackTraceMax, pc, bp, nullptr, top, bottom, true); + } else + stack->Unwind(kStackTraceMax, pc, 0, context, 0, 0, false); +} Index: compiler-rt/trunk/lib/ubsan/ubsan_diag.h =================================================================== --- compiler-rt/trunk/lib/ubsan/ubsan_diag.h +++ compiler-rt/trunk/lib/ubsan/ubsan_diag.h @@ -234,9 +234,6 @@ GET_CALLER_PC_BP; \ ReportOptions Opts = {unrecoverable_handler, pc, bp} -void GetStackTrace(BufferedStackTrace *stack, uptr max_depth, uptr pc, uptr bp, - void *context, bool fast); - /// \brief Instantiate this class before printing diagnostics in the error /// report. This class ensures that reports from different threads and from /// different sanitizers won't be mixed. Index: compiler-rt/trunk/lib/ubsan/ubsan_diag.cc =================================================================== --- compiler-rt/trunk/lib/ubsan/ubsan_diag.cc +++ compiler-rt/trunk/lib/ubsan/ubsan_diag.cc @@ -26,17 +26,6 @@ using namespace __ubsan; -void __ubsan::GetStackTrace(BufferedStackTrace *stack, uptr max_depth, uptr pc, - uptr bp, void *context, bool fast) { - uptr top = 0; - uptr bottom = 0; - if (StackTrace::WillUseFastUnwind(fast)) { - GetThreadStackTopAndBottom(false, &top, &bottom); - stack->Unwind(max_depth, pc, bp, nullptr, top, bottom, true); - } else - stack->Unwind(max_depth, pc, bp, context, 0, 0, false); -} - static void MaybePrintStackTrace(uptr pc, uptr bp) { // We assume that flags are already parsed, as UBSan runtime // will definitely be called when we print the first diagnostics message. Index: compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cc =================================================================== --- compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cc +++ compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cc @@ -14,6 +14,17 @@ #if CAN_SANITIZE_UB #include "ubsan_diag.h" +void __sanitizer::GetStackTrace(BufferedStackTrace *stack, uptr max_depth, + uptr pc, uptr bp, void *context, bool fast) { + uptr top = 0; + uptr bottom = 0; + if (StackTrace::WillUseFastUnwind(fast)) { + GetThreadStackTopAndBottom(false, &top, &bottom); + stack->Unwind(max_depth, pc, bp, nullptr, top, bottom, true); + } else + stack->Unwind(max_depth, pc, bp, context, 0, 0, false); +} + using namespace __ubsan; extern "C" {