]> git.proxmox.com Git - rustc.git/blame - src/compiler-rt/lib/lsan/lsan.cc
New upstream version 1.19.0+dfsg3
[rustc.git] / src / compiler-rt / lib / lsan / lsan.cc
CommitLineData
1a4d82fc
JJ
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"
92a42be0 18#include "sanitizer_common/sanitizer_flag_parser.h"
1a4d82fc
JJ
19#include "sanitizer_common/sanitizer_stacktrace.h"
20#include "lsan_allocator.h"
21#include "lsan_common.h"
22#include "lsan_thread.h"
23
24bool lsan_inited;
25bool lsan_init_is_running;
26
27namespace __lsan {
28
1a4d82fc
JJ
29///// Interface to the common LSan module. /////
30bool WordIsPoisoned(uptr addr) {
31 return false;
32}
33
34} // namespace __lsan
35
36using namespace __lsan; // NOLINT
37
92a42be0
SL
38static 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;
5bcae85e 46 cf.intercept_tls_get_addr = true;
92a42be0
SL
47 cf.detect_leaks = true;
48 cf.exitcode = 23;
49 OverrideCommonFlags(cf);
50 }
51
52 Flags *f = flags();
53 f->SetDefaults();
54
55 FlagParser parser;
56 RegisterLsanFlags(&parser, f);
57 RegisterCommonFlags(&parser);
58
59 parser.ParseString(GetEnv("LSAN_OPTIONS"));
60
61 SetVerbosity(common_flags()->verbosity);
62
63 if (Verbosity()) ReportUnrecognizedFlags();
64
65 if (common_flags()->help) parser.PrintFlagDescriptions();
66}
67
1a4d82fc
JJ
68extern "C" void __lsan_init() {
69 CHECK(!lsan_init_is_running);
70 if (lsan_inited)
71 return;
72 lsan_init_is_running = true;
73 SanitizerToolName = "LeakSanitizer";
92a42be0 74 CacheBinaryName();
5bcae85e 75 AvoidCVE_2016_2143();
92a42be0
SL
76 InitializeFlags();
77 InitCommonLsan();
1a4d82fc
JJ
78 InitializeAllocator();
79 InitTlsSize();
80 InitializeInterceptors();
81 InitializeThreadRegistry();
82 u32 tid = ThreadCreate(0, 0, true);
83 CHECK_EQ(tid, 0);
84 ThreadStart(tid, GetTid());
85 SetCurrentThread(tid);
86
1a4d82fc
JJ
87 if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit)
88 Atexit(DoLeakCheck);
92a42be0
SL
89
90 InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir);
91
1a4d82fc
JJ
92 lsan_inited = true;
93 lsan_init_is_running = false;
94}
95
92a42be0
SL
96extern "C" SANITIZER_INTERFACE_ATTRIBUTE
97void __sanitizer_print_stack_trace() {
98 GET_STACK_TRACE_FATAL;
99 stack.Print();
100}