memprof_internal.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #include "memprof_flags.h"
  16. #include "memprof_interface_internal.h"
  17. #include "sanitizer_common/sanitizer_common.h"
  18. #include "sanitizer_common/sanitizer_internal_defs.h"
  19. #include "sanitizer_common/sanitizer_libc.h"
  20. #include "sanitizer_common/sanitizer_stacktrace.h"
  21. #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
  22. #error "The MemProfiler run-time should not be instrumented by MemProfiler"
  23. #endif
  24. // Build-time configuration options.
  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. #ifndef MEMPROF_DYNAMIC
  30. #ifdef PIC
  31. #define MEMPROF_DYNAMIC 1
  32. #else
  33. #define MEMPROF_DYNAMIC 0
  34. #endif
  35. #endif
  36. // All internal functions in memprof reside inside the __memprof namespace
  37. // to avoid namespace collisions with the user programs.
  38. // Separate namespace also makes it simpler to distinguish the memprof
  39. // run-time functions from the instrumented user code in a profile.
  40. namespace __memprof {
  41. class MemprofThread;
  42. using __sanitizer::StackTrace;
  43. void MemprofInitFromRtl();
  44. // memprof_rtl.cpp
  45. void PrintAddressSpaceLayout();
  46. // memprof_shadow_setup.cpp
  47. void InitializeShadowMemory();
  48. // memprof_malloc_linux.cpp
  49. void ReplaceSystemMalloc();
  50. // memprof_linux.cpp
  51. uptr FindDynamicShadowStart();
  52. void *MemprofDoesNotSupportStaticLinkage();
  53. // memprof_thread.cpp
  54. MemprofThread *CreateMainThread();
  55. void ReadContextStack(void *context, uptr *stack, uptr *ssize);
  56. // Wrapper for TLS/TSD.
  57. void TSDInit(void (*destructor)(void *tsd));
  58. void *TSDGet();
  59. void TSDSet(void *tsd);
  60. void PlatformTSDDtor(void *tsd);
  61. void *MemprofDlSymNext(const char *sym);
  62. // Add convenient macro for interface functions that may be represented as
  63. // weak hooks.
  64. #define MEMPROF_MALLOC_HOOK(ptr, size) \
  65. do { \
  66. if (&__sanitizer_malloc_hook) \
  67. __sanitizer_malloc_hook(ptr, size); \
  68. RunMallocHooks(ptr, size); \
  69. } while (false)
  70. #define MEMPROF_FREE_HOOK(ptr) \
  71. do { \
  72. if (&__sanitizer_free_hook) \
  73. __sanitizer_free_hook(ptr); \
  74. RunFreeHooks(ptr); \
  75. } while (false)
  76. extern int memprof_inited;
  77. extern int memprof_timestamp_inited;
  78. extern int memprof_init_done;
  79. // Used to avoid infinite recursion in __memprof_init().
  80. extern bool memprof_init_is_running;
  81. extern void (*death_callback)(void);
  82. extern long memprof_init_timestamp_s;
  83. } // namespace __memprof
  84. #endif // MEMPROF_INTERNAL_H