1 //=-- lsan.cc -------------------------------------------------------------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of LeakSanitizer.
9 // Standalone LSan RTL.
11 //===----------------------------------------------------------------------===//
15 #include "sanitizer_common/sanitizer_flags.h"
16 #include "sanitizer_common/sanitizer_stacktrace.h"
17 #include "lsan_allocator.h"
18 #include "lsan_common.h"
19 #include "lsan_thread.h"
22 bool lsan_init_is_running
;
26 static void InitializeCommonFlags() {
27 CommonFlags
*cf
= common_flags();
28 SetCommonFlagsDefaults(cf
);
29 cf
->external_symbolizer_path
= GetEnv("LSAN_SYMBOLIZER_PATH");
30 cf
->malloc_context_size
= 30;
31 cf
->detect_leaks
= true;
33 ParseCommonFlagsFromString(cf
, GetEnv("LSAN_OPTIONS"));
36 ///// Interface to the common LSan module. /////
37 bool WordIsPoisoned(uptr addr
) {
43 using namespace __lsan
; // NOLINT
45 extern "C" void __lsan_init() {
46 CHECK(!lsan_init_is_running
);
49 lsan_init_is_running
= true;
50 SanitizerToolName
= "LeakSanitizer";
51 InitializeCommonFlags();
52 InitializeAllocator();
54 InitializeInterceptors();
55 InitializeThreadRegistry();
56 u32 tid
= ThreadCreate(0, 0, true);
58 ThreadStart(tid
, GetTid());
59 SetCurrentThread(tid
);
61 Symbolizer::Init(common_flags()->external_symbolizer_path
);
64 if (common_flags()->detect_leaks
&& common_flags()->leak_check_at_exit
)
67 lsan_init_is_running
= false;