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