1 //=-- lsan.h --------------------------------------------------------------===// 2 // 3 // This file is distributed under the University of Illinois Open Source 4 // License. See LICENSE.TXT for details. 5 // 6 //===----------------------------------------------------------------------===// 7 // 8 // This file is a part of LeakSanitizer. 9 // Private header for standalone LSan RTL. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "lsan_thread.h" 14 #include "sanitizer_common/sanitizer_flags.h" 15 #include "sanitizer_common/sanitizer_stacktrace.h" 16 17 #define GET_STACK_TRACE(max_size, fast) \ 18 __sanitizer::BufferedStackTrace stack; \ 19 GetStackTrace(&stack, max_size, StackTrace::GetCurrentPc(), \ 20 GET_CURRENT_FRAME(), nullptr, fast); 21 22 #define GET_STACK_TRACE_FATAL \ 23 GET_STACK_TRACE(kStackTraceMax, common_flags()->fast_unwind_on_fatal) 24 25 #define GET_STACK_TRACE_MALLOC \ 26 GET_STACK_TRACE(__sanitizer::common_flags()->malloc_context_size, \ 27 common_flags()->fast_unwind_on_malloc) 28 29 #define GET_STACK_TRACE_THREAD GET_STACK_TRACE(kStackTraceMax, true) 30 31 namespace __lsan { 32 33 void InitializeInterceptors(); 34 void ReplaceSystemMalloc(); 35 36 #define ENSURE_LSAN_INITED do { \ 37 CHECK(!lsan_init_is_running); \ 38 if (!lsan_inited) \ 39 __lsan_init(); \ 40 } while (0) 41 42 // Get the stack trace with the given pc and bp. 43 // The pc will be in the position 0 of the resulting stack trace. 44 // The bp may refer to the current frame or to the caller's frame. 45 ALWAYS_INLINE 46 void GetStackTrace(__sanitizer::BufferedStackTrace *stack, 47 __sanitizer::uptr max_depth, __sanitizer::uptr pc, 48 __sanitizer::uptr bp, void *context, bool fast) { 49 uptr stack_top = 0, stack_bottom = 0; 50 ThreadContext *t; 51 if (fast && (t = CurrentThreadContext())) { 52 stack_top = t->stack_end(); 53 stack_bottom = t->stack_begin(); 54 } 55 if (!SANITIZER_MIPS || IsValidFrame(bp, stack_top, stack_bottom)) { 56 stack->Unwind(max_depth, pc, bp, context, stack_top, stack_bottom, fast); 57 } 58 } 59 60 } // namespace __lsan 61 62 extern bool lsan_inited; 63 extern bool lsan_init_is_running; 64 65 extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __lsan_init(); 66