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