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