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