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