1 //=-- lsan.h --------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of LeakSanitizer.
11 // Private header for standalone LSan RTL.
13 //===----------------------------------------------------------------------===//
15 #include "lsan_thread.h"
16 #include "sanitizer_common/sanitizer_flags.h"
17 #include "sanitizer_common/sanitizer_stacktrace.h"
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);
24 #define GET_STACK_TRACE_FATAL \
25 GET_STACK_TRACE(kStackTraceMax, common_flags()->fast_unwind_on_fatal)
27 #define GET_STACK_TRACE_MALLOC \
28 GET_STACK_TRACE(__sanitizer::common_flags()->malloc_context_size, \
29 common_flags()->fast_unwind_on_malloc)
31 #define GET_STACK_TRACE_THREAD GET_STACK_TRACE(kStackTraceMax, true)
35 void InitializeInterceptors();
36 void ReplaceSystemMalloc();
38 #define ENSURE_LSAN_INITED do { \
39 CHECK(!lsan_init_is_running); \
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.
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;
53 if (fast && (t = CurrentThreadContext())) {
54 stack_top = t->stack_end();
55 stack_bottom = t->stack_begin();
57 if (!SANITIZER_MIPS || IsValidFrame(bp, stack_top, stack_bottom)) {
58 stack->Unwind(max_depth, pc, bp, context, stack_top, stack_bottom, fast);
64 extern bool lsan_inited;
65 extern bool lsan_init_is_running;
67 extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __lsan_init();