]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/lsan/lsan.h
Merge llvm trunk r321017 to contrib/llvm.
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / lsan / lsan.h
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 "sanitizer_common/sanitizer_flags.h"
16 #include "sanitizer_common/sanitizer_stacktrace.h"
17
18 #define GET_STACK_TRACE(max_size, fast)                                        \
19   BufferedStackTrace stack;                                                    \
20   {                                                                            \
21     uptr stack_top = 0, stack_bottom = 0;                                      \
22     ThreadContext *t;                                                          \
23     if (fast && (t = CurrentThreadContext())) {                                \
24       stack_top = t->stack_end();                                              \
25       stack_bottom = t->stack_begin();                                         \
26     }                                                                          \
27     if (!SANITIZER_MIPS ||                                                     \
28         IsValidFrame(GET_CURRENT_FRAME(), stack_top, stack_bottom)) {          \
29       stack.Unwind(max_size, StackTrace::GetCurrentPc(), GET_CURRENT_FRAME(),  \
30                    /* context */ 0, stack_top, stack_bottom, fast);            \
31     }                                                                          \
32   }
33
34 #define GET_STACK_TRACE_FATAL \
35   GET_STACK_TRACE(kStackTraceMax, common_flags()->fast_unwind_on_fatal)
36
37 #define GET_STACK_TRACE_MALLOC                                      \
38   GET_STACK_TRACE(__sanitizer::common_flags()->malloc_context_size, \
39                   common_flags()->fast_unwind_on_malloc)
40
41 #define GET_STACK_TRACE_THREAD GET_STACK_TRACE(kStackTraceMax, true)
42
43 namespace __lsan {
44
45 void InitializeInterceptors();
46 void ReplaceSystemMalloc();
47
48 #define ENSURE_LSAN_INITED do {   \
49   CHECK(!lsan_init_is_running);   \
50   if (!lsan_inited)               \
51     __lsan_init();                \
52 } while (0)
53
54 }  // namespace __lsan
55
56 extern bool lsan_inited;
57 extern bool lsan_init_is_running;
58
59 extern "C" void __lsan_init();