1 //=-- lsan.h --------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a part of LeakSanitizer.
10 // Private header for standalone LSan RTL.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "lsan_thread.h"
15 #include "sanitizer_common/sanitizer_flags.h"
16 #include "sanitizer_common/sanitizer_stacktrace.h"
17 
18 #define GET_STACK_TRACE(max_size, fast)                       \
19   __sanitizer::BufferedStackTrace stack;                      \
20   stack.Unwind(StackTrace::GetCurrentPc(),                    \
21                GET_CURRENT_FRAME(), nullptr, fast, max_size);
22 
23 #define GET_STACK_TRACE_FATAL \
24   GET_STACK_TRACE(kStackTraceMax, common_flags()->fast_unwind_on_fatal)
25 
26 #define GET_STACK_TRACE_MALLOC                                      \
27   GET_STACK_TRACE(__sanitizer::common_flags()->malloc_context_size, \
28                   common_flags()->fast_unwind_on_malloc)
29 
30 #define GET_STACK_TRACE_THREAD GET_STACK_TRACE(kStackTraceMax, true)
31 
32 namespace __lsan {
33 
34 void InitializeInterceptors();
35 void ReplaceSystemMalloc();
36 
37 #define ENSURE_LSAN_INITED do {   \
38   CHECK(!lsan_init_is_running);   \
39   if (!lsan_inited)               \
40     __lsan_init();                \
41 } while (0)
42 
43 }  // namespace __lsan
44 
45 extern bool lsan_inited;
46 extern bool lsan_init_is_running;
47 
48 extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __lsan_init();
49