1 //=-- lsan.cc -------------------------------------------------------------===// 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 // Standalone LSan RTL. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #include "lsan.h" 16 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" 22 23 bool lsan_inited; 24 bool lsan_init_is_running; 25 26 namespace __lsan { 27 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; 34 35 ParseCommonFlagsFromString(cf, GetEnv("LSAN_OPTIONS")); 36 } 37 38 ///// Interface to the common LSan module. ///// 39 bool WordIsPoisoned(uptr addr) { 40 return false; 41 } 42 43 } // namespace __lsan 44 45 using namespace __lsan; // NOLINT 46 47 extern "C" void __lsan_init() { 48 CHECK(!lsan_init_is_running); 49 if (lsan_inited) 50 return; 51 lsan_init_is_running = true; 52 SanitizerToolName = "LeakSanitizer"; 53 InitializeCommonFlags(); 54 InitializeAllocator(); 55 InitTlsSize(); 56 InitializeInterceptors(); 57 InitializeThreadRegistry(); 58 u32 tid = ThreadCreate(0, 0, true); 59 CHECK_EQ(tid, 0); 60 ThreadStart(tid, GetTid()); 61 SetCurrentThread(tid); 62 63 Symbolizer::Init(common_flags()->external_symbolizer_path); 64 65 InitCommonLsan(); 66 if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit) 67 Atexit(DoLeakCheck); 68 lsan_inited = true; 69 lsan_init_is_running = false; 70 } 71 72