]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/lsan/lsan.cc
MFV ntp 4.2.8p2 (r281348)
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / lsan / lsan.cc
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_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"
23
24 bool lsan_inited;
25 bool lsan_init_is_running;
26
27 namespace __lsan {
28
29 ///// Interface to the common LSan module. /////
30 bool WordIsPoisoned(uptr addr) {
31   return false;
32 }
33
34 }  // namespace __lsan
35
36 using namespace __lsan;  // NOLINT
37
38 static void InitializeFlags() {
39   // Set all the default values.
40   SetCommonFlagsDefaults();
41   {
42     CommonFlags cf;
43     cf.CopyFrom(*common_flags());
44     cf.external_symbolizer_path = GetEnv("LSAN_SYMBOLIZER_PATH");
45     cf.malloc_context_size = 30;
46     cf.detect_leaks = true;
47     OverrideCommonFlags(cf);
48   }
49
50   Flags *f = flags();
51   f->SetDefaults();
52
53   FlagParser parser;
54   RegisterLsanFlags(&parser, f);
55   RegisterCommonFlags(&parser);
56
57   parser.ParseString(GetEnv("LSAN_OPTIONS"));
58
59   SetVerbosity(common_flags()->verbosity);
60
61   if (Verbosity()) ReportUnrecognizedFlags();
62
63   if (common_flags()->help) parser.PrintFlagDescriptions();
64 }
65
66 extern "C" void __lsan_init() {
67   CHECK(!lsan_init_is_running);
68   if (lsan_inited)
69     return;
70   lsan_init_is_running = true;
71   SanitizerToolName = "LeakSanitizer";
72   InitializeFlags();
73   InitCommonLsan();
74   InitializeAllocator();
75   InitTlsSize();
76   InitializeInterceptors();
77   InitializeThreadRegistry();
78   u32 tid = ThreadCreate(0, 0, true);
79   CHECK_EQ(tid, 0);
80   ThreadStart(tid, GetTid());
81   SetCurrentThread(tid);
82
83   if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit)
84     Atexit(DoLeakCheck);
85
86   InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir);
87
88   lsan_inited = true;
89   lsan_init_is_running = false;
90 }
91
92 extern "C" SANITIZER_INTERFACE_ATTRIBUTE
93 void __sanitizer_print_stack_trace() {
94   GET_STACK_TRACE_FATAL;
95   stack.Print();
96 }