1 //===-- asan_internal.h -----------------------------------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of AddressSanitizer, an address sanity checker.
10 // ASan-private header which defines various general utilities.
11 //===----------------------------------------------------------------------===//
12 #ifndef ASAN_INTERNAL_H
13 #define ASAN_INTERNAL_H
15 #include "asan_flags.h"
16 #include "asan_interface_internal.h"
17 #include "sanitizer_common/sanitizer_common.h"
18 #include "sanitizer_common/sanitizer_internal_defs.h"
19 #include "sanitizer_common/sanitizer_stacktrace.h"
20 #include "sanitizer_common/sanitizer_libc.h"
22 #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
23 # error "The AddressSanitizer run-time should not be"
24 " instrumented by AddressSanitizer"
27 // Build-time configuration options.
29 // If set, asan will intercept C++ exception api call(s).
30 #ifndef ASAN_HAS_EXCEPTIONS
31 # define ASAN_HAS_EXCEPTIONS 1
34 // If set, values like allocator chunk size, as well as defaults for some flags
35 // will be changed towards less memory overhead.
36 #ifndef ASAN_LOW_MEMORY
37 #if SANITIZER_WORDSIZE == 32
38 # define ASAN_LOW_MEMORY 1
40 # define ASAN_LOW_MEMORY 0
46 # define ASAN_DYNAMIC 1
48 # define ASAN_DYNAMIC 0
52 // All internal functions in asan reside inside the __asan namespace
53 // to avoid namespace collisions with the user programs.
54 // Separate namespace also makes it simpler to distinguish the asan run-time
55 // functions from the instrumented user code in a profile.
59 using __sanitizer::StackTrace
;
61 void AsanInitFromRtl();
64 void NORETURN
ShowStatsAndAbort();
66 // asan_malloc_linux.cc / asan_malloc_mac.cc
67 void ReplaceSystemMalloc();
69 // asan_linux.cc / asan_mac.cc / asan_win.cc
70 void *AsanDoesNotSupportStaticLinkage();
71 void AsanCheckDynamicRTPrereqs();
72 void AsanCheckIncompatibleRT();
74 void AsanOnDeadlySignal(int, void *siginfo
, void *context
);
78 void ReadContextStack(void *context
, uptr
*stack
, uptr
*ssize
);
79 void StopInitOrderChecking();
81 // Wrapper for TLS/TSD.
82 void AsanTSDInit(void (*destructor
)(void *tsd
));
84 void AsanTSDSet(void *tsd
);
85 void PlatformTSDDtor(void *tsd
);
87 void AppendToErrorMessageBuffer(const char *buffer
);
89 void *AsanDlSymNext(const char *sym
);
91 void ReserveShadowMemoryRange(uptr beg
, uptr end
, const char *name
);
93 // Platform-specific options.
95 bool PlatformHasDifferentMemcpyAndMemmove();
96 # define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE \
97 (PlatformHasDifferentMemcpyAndMemmove())
99 # define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE true
100 #endif // SANITIZER_MAC
102 // Add convenient macro for interface functions that may be represented as
104 #define ASAN_MALLOC_HOOK(ptr, size) \
105 if (&__sanitizer_malloc_hook) __sanitizer_malloc_hook(ptr, size)
106 #define ASAN_FREE_HOOK(ptr) \
107 if (&__sanitizer_free_hook) __sanitizer_free_hook(ptr)
108 #define ASAN_ON_ERROR() \
109 if (&__asan_on_error) __asan_on_error()
111 extern int asan_inited
;
112 // Used to avoid infinite recursion in __asan_init().
113 extern bool asan_init_is_running
;
114 extern void (*death_callback
)(void);
116 // These magic values are written to shadow for better error reporting.
117 const int kAsanHeapLeftRedzoneMagic
= 0xfa;
118 const int kAsanHeapRightRedzoneMagic
= 0xfb;
119 const int kAsanHeapFreeMagic
= 0xfd;
120 const int kAsanStackLeftRedzoneMagic
= 0xf1;
121 const int kAsanStackMidRedzoneMagic
= 0xf2;
122 const int kAsanStackRightRedzoneMagic
= 0xf3;
123 const int kAsanStackPartialRedzoneMagic
= 0xf4;
124 const int kAsanStackAfterReturnMagic
= 0xf5;
125 const int kAsanInitializationOrderMagic
= 0xf6;
126 const int kAsanUserPoisonedMemoryMagic
= 0xf7;
127 const int kAsanContiguousContainerOOBMagic
= 0xfc;
128 const int kAsanStackUseAfterScopeMagic
= 0xf8;
129 const int kAsanGlobalRedzoneMagic
= 0xf9;
130 const int kAsanInternalHeapMagic
= 0xfe;
131 const int kAsanArrayCookieMagic
= 0xac;
132 const int kAsanIntraObjectRedzone
= 0xbb;
133 const int kAsanAllocaLeftMagic
= 0xca;
134 const int kAsanAllocaRightMagic
= 0xcb;
136 static const uptr kCurrentStackFrameMagic
= 0x41B58AB3;
137 static const uptr kRetiredStackFrameMagic
= 0x45E0360E;
139 } // namespace __asan
141 #endif // ASAN_INTERNAL_H