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_flag_parser.h"
17 #include "sanitizer_common/sanitizer_stacktrace.h"
18 #include "lsan_allocator.h"
19 #include "lsan_common.h"
20 #include "lsan_thread.h"
23 bool lsan_init_is_running
;
27 ///// Interface to the common LSan module. /////
28 bool WordIsPoisoned(uptr addr
) {
34 using namespace __lsan
; // NOLINT
36 static void InitializeFlags() {
37 // Set all the default values.
38 SetCommonFlagsDefaults();
41 cf
.CopyFrom(*common_flags());
42 cf
.external_symbolizer_path
= GetEnv("LSAN_SYMBOLIZER_PATH");
43 cf
.malloc_context_size
= 30;
44 cf
.intercept_tls_get_addr
= true;
45 cf
.detect_leaks
= true;
47 OverrideCommonFlags(cf
);
54 RegisterLsanFlags(&parser
, f
);
55 RegisterCommonFlags(&parser
);
57 parser
.ParseString(GetEnv("LSAN_OPTIONS"));
59 SetVerbosity(common_flags()->verbosity
);
61 if (Verbosity()) ReportUnrecognizedFlags();
63 if (common_flags()->help
) parser
.PrintFlagDescriptions();
66 extern "C" void __lsan_init() {
67 CHECK(!lsan_init_is_running
);
70 lsan_init_is_running
= true;
71 SanitizerToolName
= "LeakSanitizer";
76 InitializeAllocator();
78 InitializeInterceptors();
79 InitializeThreadRegistry();
80 u32 tid
= ThreadCreate(0, 0, true);
82 ThreadStart(tid
, GetTid());
83 SetCurrentThread(tid
);
85 if (common_flags()->detect_leaks
&& common_flags()->leak_check_at_exit
)
88 InitializeCoverage(common_flags()->coverage
, common_flags()->coverage_dir
);
91 lsan_init_is_running
= false;
94 extern "C" SANITIZER_INTERFACE_ATTRIBUTE
95 void __sanitizer_print_stack_trace() {
96 GET_STACK_TRACE_FATAL
;