xref: /freebsd/contrib/llvm-project/compiler-rt/lib/memprof/memprof_internal.h (revision 35c0a8c449fd2b7f75029ebed5e10852240f0865)
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 // Build-time configuration options.
24 
25 // If set, memprof will intercept C++ exception api call(s).
26 #ifndef MEMPROF_HAS_EXCEPTIONS
27 #define MEMPROF_HAS_EXCEPTIONS 1
28 #endif
29 
30 #ifndef MEMPROF_DYNAMIC
31 #ifdef PIC
32 #define MEMPROF_DYNAMIC 1
33 #else
34 #define MEMPROF_DYNAMIC 0
35 #endif
36 #endif
37 
38 // All internal functions in memprof reside inside the __memprof namespace
39 // to avoid namespace collisions with the user programs.
40 // Separate namespace also makes it simpler to distinguish the memprof
41 // run-time functions from the instrumented user code in a profile.
42 namespace __memprof {
43 
44 class MemprofThread;
45 using __sanitizer::StackTrace;
46 
47 void MemprofInitFromRtl();
48 
49 // memprof_rtl.cpp
50 void PrintAddressSpaceLayout();
51 
52 // memprof_shadow_setup.cpp
53 void InitializeShadowMemory();
54 
55 // memprof_malloc_linux.cpp
56 void ReplaceSystemMalloc();
57 
58 // memprof_linux.cpp
59 uptr FindDynamicShadowStart();
60 
61 // memprof_thread.cpp
62 MemprofThread *CreateMainThread();
63 
64 // Wrapper for TLS/TSD.
65 void TSDInit(void (*destructor)(void *tsd));
66 void *TSDGet();
67 void TSDSet(void *tsd);
68 void PlatformTSDDtor(void *tsd);
69 
70 void *MemprofDlSymNext(const char *sym);
71 
72 extern int memprof_inited;
73 extern int memprof_timestamp_inited;
74 // Used to avoid infinite recursion in __memprof_init().
75 extern bool memprof_init_is_running;
76 extern void (*death_callback)(void);
77 extern long memprof_init_timestamp_s;
78 
79 } // namespace __memprof
80 
81 #endif // MEMPROF_INTERNAL_H
82