| Sergey Matveev | e96c62a | 2013-05-20 11:04:43 +0000 | [diff] [blame] | 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 | namespace __lsan { |
| 24 | |
| 25 | static void InitializeCommonFlags() { |
| 26 | CommonFlags *cf = common_flags(); |
| 27 | cf->external_symbolizer_path = GetEnv("LSAN_SYMBOLIZER_PATH"); |
| 28 | cf->symbolize = (cf->external_symbolizer_path && |
| 29 | cf->external_symbolizer_path[0]); |
| 30 | cf->strip_path_prefix = ""; |
| 31 | cf->fast_unwind_on_malloc = true; |
| 32 | cf->malloc_context_size = 30; |
| Sergey Matveev | 62519eb | 2013-07-22 12:38:17 +0000 | [diff] [blame^] | 33 | cf->detect_leaks = true; |
| Sergey Matveev | e96c62a | 2013-05-20 11:04:43 +0000 | [diff] [blame] | 34 | |
| 35 | ParseCommonFlagsFromString(GetEnv("LSAN_OPTIONS")); |
| 36 | } |
| 37 | |
| 38 | void Init() { |
| 39 | static bool inited; |
| 40 | if (inited) |
| 41 | return; |
| 42 | inited = true; |
| 43 | SanitizerToolName = "LeakSanitizer"; |
| 44 | InitializeCommonFlags(); |
| 45 | InitializeAllocator(); |
| Sergey Matveev | e96c62a | 2013-05-20 11:04:43 +0000 | [diff] [blame] | 46 | InitTlsSize(); |
| 47 | InitializeInterceptors(); |
| 48 | InitializeThreadRegistry(); |
| 49 | u32 tid = ThreadCreate(0, 0, true); |
| 50 | CHECK_EQ(tid, 0); |
| 51 | ThreadStart(tid, GetTid()); |
| Sergey Matveev | 02d7f32 | 2013-06-18 14:44:45 +0000 | [diff] [blame] | 52 | SetCurrentThread(tid); |
| Sergey Matveev | e96c62a | 2013-05-20 11:04:43 +0000 | [diff] [blame] | 53 | |
| 54 | // Start symbolizer process if necessary. |
| 55 | const char* external_symbolizer = common_flags()->external_symbolizer_path; |
| 56 | if (common_flags()->symbolize && external_symbolizer && |
| 57 | external_symbolizer[0]) { |
| 58 | InitializeExternalSymbolizer(external_symbolizer); |
| 59 | } |
| Sergey Matveev | 4cacb4f | 2013-05-21 17:56:45 +0000 | [diff] [blame] | 60 | |
| Sergey Matveev | fc1a612 | 2013-05-23 10:24:44 +0000 | [diff] [blame] | 61 | InitCommonLsan(); |
| 62 | Atexit(DoLeakCheck); |
| Sergey Matveev | e96c62a | 2013-05-20 11:04:43 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | } // namespace __lsan |