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_flag_parser.h"
19 #include "sanitizer_common/sanitizer_stacktrace.h"
20 #include "lsan_allocator.h"
21 #include "lsan_common.h"
22 #include "lsan_thread.h"
25 bool lsan_init_is_running;
29 ///// Interface to the common LSan module. /////
30 bool WordIsPoisoned(uptr addr) {
36 using namespace __lsan; // NOLINT
38 static void InitializeFlags() {
39 // Set all the default values.
40 SetCommonFlagsDefaults();
43 cf.CopyFrom(*common_flags());
44 cf.external_symbolizer_path = GetEnv("LSAN_SYMBOLIZER_PATH");
45 cf.malloc_context_size = 30;
46 cf.intercept_tls_get_addr = true;
47 cf.detect_leaks = true;
49 OverrideCommonFlags(cf);
56 RegisterLsanFlags(&parser, f);
57 RegisterCommonFlags(&parser);
59 parser.ParseString(GetEnv("LSAN_OPTIONS"));
61 SetVerbosity(common_flags()->verbosity);
63 if (Verbosity()) ReportUnrecognizedFlags();
65 if (common_flags()->help) parser.PrintFlagDescriptions();
68 extern "C" void __lsan_init() {
69 CHECK(!lsan_init_is_running);
72 lsan_init_is_running = true;
73 SanitizerToolName = "LeakSanitizer";
78 InitializeAllocator();
80 InitializeInterceptors();
81 InitializeThreadRegistry();
82 u32 tid = ThreadCreate(0, 0, true);
84 ThreadStart(tid, GetTid());
85 SetCurrentThread(tid);
87 if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit)
90 InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir);
93 lsan_init_is_running = false;
96 extern "C" SANITIZER_INTERFACE_ATTRIBUTE
97 void __sanitizer_print_stack_trace() {
98 GET_STACK_TRACE_FATAL;