1 //=-- lsan.cc -------------------------------------------------------------===//
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 // Standalone LSan RTL.
13 //===----------------------------------------------------------------------===//
17 #include "sanitizer_common/sanitizer_flags.h"
18 #include "sanitizer_common/sanitizer_stacktrace.h"
19 #include "lsan_allocator.h"
20 #include "lsan_common.h"
21 #include "lsan_thread.h"
24 bool lsan_init_is_running
;
28 static void InitializeCommonFlags() {
29 CommonFlags
*cf
= common_flags();
30 SetCommonFlagsDefaults(cf
);
31 cf
->external_symbolizer_path
= GetEnv("LSAN_SYMBOLIZER_PATH");
32 cf
->malloc_context_size
= 30;
33 cf
->detect_leaks
= true;
35 ParseCommonFlagsFromString(cf
, GetEnv("LSAN_OPTIONS"));
38 ///// Interface to the common LSan module. /////
39 bool WordIsPoisoned(uptr addr
) {
45 using namespace __lsan
; // NOLINT
47 extern "C" void __lsan_init() {
48 CHECK(!lsan_init_is_running
);
51 lsan_init_is_running
= true;
52 SanitizerToolName
= "LeakSanitizer";
53 InitializeCommonFlags();
54 InitializeAllocator();
56 InitializeInterceptors();
57 InitializeThreadRegistry();
58 u32 tid
= ThreadCreate(0, 0, true);
60 ThreadStart(tid
, GetTid());
61 SetCurrentThread(tid
);
63 Symbolizer::Init(common_flags()->external_symbolizer_path
);
66 if (common_flags()->detect_leaks
&& common_flags()->leak_check_at_exit
)
69 lsan_init_is_running
= false;