blob: 99b165b5d8c2f95e13f8878f7e3d204000ba41f5 [file] [log] [blame]
Sergey Matveeve96c62a2013-05-20 11:04:43 +00001//=-- 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
23namespace __lsan {
24
25static void InitializeCommonFlags() {
26 CommonFlags *cf = common_flags();
27 cf->external_symbolizer_path = GetEnv("LSAN_SYMBOLIZER_PATH");
Alexey Samsonov68c016a2013-09-03 13:22:51 +000028 cf->symbolize = true;
Sergey Matveeve96c62a2013-05-20 11:04:43 +000029 cf->strip_path_prefix = "";
30 cf->fast_unwind_on_malloc = true;
31 cf->malloc_context_size = 30;
Sergey Matveev62519eb2013-07-22 12:38:17 +000032 cf->detect_leaks = true;
Sergey Matveev41f15402013-08-01 14:57:07 +000033 cf->leak_check_at_exit = true;
Sergey Matveeve96c62a2013-05-20 11:04:43 +000034
35 ParseCommonFlagsFromString(GetEnv("LSAN_OPTIONS"));
36}
37
38void Init() {
39 static bool inited;
40 if (inited)
41 return;
42 inited = true;
43 SanitizerToolName = "LeakSanitizer";
44 InitializeCommonFlags();
45 InitializeAllocator();
Sergey Matveeve96c62a2013-05-20 11:04:43 +000046 InitTlsSize();
47 InitializeInterceptors();
48 InitializeThreadRegistry();
49 u32 tid = ThreadCreate(0, 0, true);
50 CHECK_EQ(tid, 0);
51 ThreadStart(tid, GetTid());
Sergey Matveev02d7f322013-06-18 14:44:45 +000052 SetCurrentThread(tid);
Sergey Matveeve96c62a2013-05-20 11:04:43 +000053
54 // Start symbolizer process if necessary.
Alexey Samsonov68c016a2013-09-03 13:22:51 +000055 if (common_flags()->symbolize) {
56 InitializeExternalSymbolizer(common_flags()->external_symbolizer_path);
Sergey Matveeve96c62a2013-05-20 11:04:43 +000057 }
Sergey Matveev4cacb4f2013-05-21 17:56:45 +000058
Sergey Matveevfc1a6122013-05-23 10:24:44 +000059 InitCommonLsan();
Sergey Matveev41f15402013-08-01 14:57:07 +000060 if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit)
61 Atexit(DoLeakCheck);
Sergey Matveeve96c62a2013-05-20 11:04:43 +000062}
63
64} // namespace __lsan