1 //===-- memprof_internal.h -------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a part of MemProfiler, a memory profiler.
10 //
11 // MemProf-private header which defines various general utilities.
12 //===----------------------------------------------------------------------===//
13 #ifndef MEMPROF_INTERNAL_H
14 #define MEMPROF_INTERNAL_H
15 
16 #include "memprof_flags.h"
17 #include "memprof_interface_internal.h"
18 #include "sanitizer_common/sanitizer_common.h"
19 #include "sanitizer_common/sanitizer_internal_defs.h"
20 #include "sanitizer_common/sanitizer_libc.h"
21 #include "sanitizer_common/sanitizer_stacktrace.h"
22 
23 #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
24 #error "The MemProfiler run-time should not be instrumented by MemProfiler"
25 #endif
26 
27 // Build-time configuration options.
28 
29 // If set, memprof will intercept C++ exception api call(s).
30 #ifndef MEMPROF_HAS_EXCEPTIONS
31 #define MEMPROF_HAS_EXCEPTIONS 1
32 #endif
33 
34 #ifndef MEMPROF_DYNAMIC
35 #ifdef PIC
36 #define MEMPROF_DYNAMIC 1
37 #else
38 #define MEMPROF_DYNAMIC 0
39 #endif
40 #endif
41 
42 // All internal functions in memprof reside inside the __memprof namespace
43 // to avoid namespace collisions with the user programs.
44 // Separate namespace also makes it simpler to distinguish the memprof
45 // run-time functions from the instrumented user code in a profile.
46 namespace __memprof {
47 
48 class MemprofThread;
49 using __sanitizer::StackTrace;
50 
51 void MemprofInitFromRtl();
52 
53 // memprof_rtl.cpp
54 void PrintAddressSpaceLayout();
55 
56 // memprof_shadow_setup.cpp
57 void InitializeShadowMemory();
58 
59 // memprof_malloc_linux.cpp
60 void ReplaceSystemMalloc();
61 
62 // memprof_linux.cpp
63 uptr FindDynamicShadowStart();
64 void *MemprofDoesNotSupportStaticLinkage();
65 
66 // memprof_thread.cpp
67 MemprofThread *CreateMainThread();
68 
69 void ReadContextStack(void *context, uptr *stack, uptr *ssize);
70 
71 // Wrapper for TLS/TSD.
72 void TSDInit(void (*destructor)(void *tsd));
73 void *TSDGet();
74 void TSDSet(void *tsd);
75 void PlatformTSDDtor(void *tsd);
76 
77 void *MemprofDlSymNext(const char *sym);
78 
79 extern int memprof_inited;
80 extern int memprof_timestamp_inited;
81 extern int memprof_init_done;
82 // Used to avoid infinite recursion in __memprof_init().
83 extern bool memprof_init_is_running;
84 extern void (*death_callback)(void);
85 extern long memprof_init_timestamp_s;
86 
87 } // namespace __memprof
88 
89 #endif // MEMPROF_INTERNAL_H
90