1//=-- lsan.cc -------------------------------------------------------------===//
2//
3// This file is distributed under the University of Illinois Open Source
4// License. See LICENSE.TXT for details.
5//
6//===----------------------------------------------------------------------===//
7//
8// This file is a part of LeakSanitizer.
9// Standalone LSan RTL.
10//
11//===----------------------------------------------------------------------===//
12
13#include "lsan.h"
14
15#include "sanitizer_common/sanitizer_flags.h"
16#include "sanitizer_common/sanitizer_stacktrace.h"
17#include "lsan_allocator.h"
18#include "lsan_common.h"
19#include "lsan_thread.h"
20
21bool lsan_inited;
22bool lsan_init_is_running;
23
24namespace __lsan {
25
26///// Interface to the common LSan module. /////
27bool WordIsPoisoned(uptr addr) {
28  return false;
29}
30
31}  // namespace __lsan
32
33using namespace __lsan;  // NOLINT
34
35extern "C" void __lsan_init() {
36  CHECK(!lsan_init_is_running);
37  if (lsan_inited)
38    return;
39  lsan_init_is_running = true;
40  SanitizerToolName = "LeakSanitizer";
41  InitCommonLsan(true);
42  InitializeAllocator();
43  InitTlsSize();
44  InitializeInterceptors();
45  InitializeThreadRegistry();
46  u32 tid = ThreadCreate(0, 0, true);
47  CHECK_EQ(tid, 0);
48  ThreadStart(tid, GetTid());
49  SetCurrentThread(tid);
50
51  if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit)
52    Atexit(DoLeakCheck);
53  lsan_inited = true;
54  lsan_init_is_running = false;
55}
56
57extern "C" SANITIZER_INTERFACE_ATTRIBUTE
58void __sanitizer_print_stack_trace() {
59  GET_STACK_TRACE_FATAL;
60  stack.Print();
61}
62