asan_internal.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //===-- asan_internal.h -----------------------------------------*- C++ -*-===//
  2. //
  3. // This file is distributed under the University of Illinois Open Source
  4. // License. See LICENSE.TXT for details.
  5. //
  6. //===----------------------------------------------------------------------===//
  7. //
  8. // This file is a part of AddressSanitizer, an address sanity checker.
  9. //
  10. // ASan-private header which defines various general utilities.
  11. //===----------------------------------------------------------------------===//
  12. #ifndef ASAN_INTERNAL_H
  13. #define ASAN_INTERNAL_H
  14. #include "asan_flags.h"
  15. #include "asan_interface_internal.h"
  16. #include "sanitizer_common/sanitizer_common.h"
  17. #include "sanitizer_common/sanitizer_internal_defs.h"
  18. #include "sanitizer_common/sanitizer_stacktrace.h"
  19. #include "sanitizer_common/sanitizer_libc.h"
  20. #define ASAN_DEFAULT_FAILURE_EXITCODE 1
  21. #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
  22. # error "The AddressSanitizer run-time should not be"
  23. " instrumented by AddressSanitizer"
  24. #endif
  25. // Build-time configuration options.
  26. // If set, asan will intercept C++ exception api call(s).
  27. #ifndef ASAN_HAS_EXCEPTIONS
  28. # define ASAN_HAS_EXCEPTIONS 1
  29. #endif
  30. // If set, values like allocator chunk size, as well as defaults for some flags
  31. // will be changed towards less memory overhead.
  32. #ifndef ASAN_LOW_MEMORY
  33. #if SANITIZER_WORDSIZE == 32
  34. # define ASAN_LOW_MEMORY 1
  35. #else
  36. # define ASAN_LOW_MEMORY 0
  37. # endif
  38. #endif
  39. #ifndef ASAN_DYNAMIC
  40. # ifdef PIC
  41. # define ASAN_DYNAMIC 1
  42. # else
  43. # define ASAN_DYNAMIC 0
  44. # endif
  45. #endif
  46. // All internal functions in asan reside inside the __asan namespace
  47. // to avoid namespace collisions with the user programs.
  48. // Separate namespace also makes it simpler to distinguish the asan run-time
  49. // functions from the instrumented user code in a profile.
  50. namespace __asan {
  51. class AsanThread;
  52. using __sanitizer::StackTrace;
  53. void AsanInitFromRtl();
  54. // asan_rtl.cc
  55. void NORETURN ShowStatsAndAbort();
  56. // asan_malloc_linux.cc / asan_malloc_mac.cc
  57. void ReplaceSystemMalloc();
  58. // asan_linux.cc / asan_mac.cc / asan_win.cc
  59. void *AsanDoesNotSupportStaticLinkage();
  60. void AsanCheckDynamicRTPrereqs();
  61. void AsanCheckIncompatibleRT();
  62. void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp);
  63. void AsanOnSIGSEGV(int, void *siginfo, void *context);
  64. void MaybeReexec();
  65. bool AsanInterceptsSignal(int signum);
  66. void ReadContextStack(void *context, uptr *stack, uptr *ssize);
  67. void AsanPlatformThreadInit();
  68. void StopInitOrderChecking();
  69. // Wrapper for TLS/TSD.
  70. void AsanTSDInit(void (*destructor)(void *tsd));
  71. void *AsanTSDGet();
  72. void AsanTSDSet(void *tsd);
  73. void PlatformTSDDtor(void *tsd);
  74. void AppendToErrorMessageBuffer(const char *buffer);
  75. void ParseExtraActivationFlags();
  76. void *AsanDlSymNext(const char *sym);
  77. // Platform-specific options.
  78. #if SANITIZER_MAC
  79. bool PlatformHasDifferentMemcpyAndMemmove();
  80. # define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE \
  81. (PlatformHasDifferentMemcpyAndMemmove())
  82. #else
  83. # define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE true
  84. #endif // SANITIZER_MAC
  85. // Add convenient macro for interface functions that may be represented as
  86. // weak hooks.
  87. #define ASAN_MALLOC_HOOK(ptr, size) \
  88. if (&__sanitizer_malloc_hook) __sanitizer_malloc_hook(ptr, size)
  89. #define ASAN_FREE_HOOK(ptr) \
  90. if (&__sanitizer_free_hook) __sanitizer_free_hook(ptr)
  91. #define ASAN_ON_ERROR() \
  92. if (&__asan_on_error) __asan_on_error()
  93. extern int asan_inited;
  94. // Used to avoid infinite recursion in __asan_init().
  95. extern bool asan_init_is_running;
  96. extern void (*death_callback)(void);
  97. // These magic values are written to shadow for better error reporting.
  98. const int kAsanHeapLeftRedzoneMagic = 0xfa;
  99. const int kAsanHeapRightRedzoneMagic = 0xfb;
  100. const int kAsanHeapFreeMagic = 0xfd;
  101. const int kAsanStackLeftRedzoneMagic = 0xf1;
  102. const int kAsanStackMidRedzoneMagic = 0xf2;
  103. const int kAsanStackRightRedzoneMagic = 0xf3;
  104. const int kAsanStackPartialRedzoneMagic = 0xf4;
  105. const int kAsanStackAfterReturnMagic = 0xf5;
  106. const int kAsanInitializationOrderMagic = 0xf6;
  107. const int kAsanUserPoisonedMemoryMagic = 0xf7;
  108. const int kAsanContiguousContainerOOBMagic = 0xfc;
  109. const int kAsanStackUseAfterScopeMagic = 0xf8;
  110. const int kAsanGlobalRedzoneMagic = 0xf9;
  111. const int kAsanInternalHeapMagic = 0xfe;
  112. const int kAsanArrayCookieMagic = 0xac;
  113. const int kAsanIntraObjectRedzone = 0xbb;
  114. static const uptr kCurrentStackFrameMagic = 0x41B58AB3;
  115. static const uptr kRetiredStackFrameMagic = 0x45E0360E;
  116. } // namespace __asan
  117. #endif // ASAN_INTERNAL_H