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 "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"
21 #if !defined(__linux__) && !defined(__APPLE__) && !defined(_WIN32)
22 # error "This operating system is not supported by AddressSanitizer"
25 #define ASAN_DEFAULT_FAILURE_EXITCODE 1
27 #if defined(__linux__)
33 #if defined(__APPLE__)
40 # define ASAN_WINDOWS 1
42 # define ASAN_WINDOWS 0
45 #if defined(__ANDROID__) || defined(ANDROID)
46 # define ASAN_ANDROID 1
48 # define ASAN_ANDROID 0
52 #define ASAN_POSIX (ASAN_LINUX || ASAN_MAC)
54 #if __has_feature(address_sanitizer)
55 # error "The AddressSanitizer run-time should not be"
56 " instrumented by AddressSanitizer"
59 // Build-time configuration options.
61 // If set, asan will install its own SEGV signal handler.
62 #ifndef ASAN_NEEDS_SEGV
63 # if ASAN_ANDROID == 1
64 # define ASAN_NEEDS_SEGV 0
66 # define ASAN_NEEDS_SEGV 1
70 // If set, asan will intercept C++ exception api call(s).
71 #ifndef ASAN_HAS_EXCEPTIONS
72 # define ASAN_HAS_EXCEPTIONS 1
75 // If set, asan uses the values of SHADOW_SCALE and SHADOW_OFFSET
76 // provided by the instrumented objects. Otherwise constants are used.
77 #ifndef ASAN_FLEXIBLE_MAPPING_AND_OFFSET
78 # define ASAN_FLEXIBLE_MAPPING_AND_OFFSET 0
81 // If set, values like allocator chunk size, as well as defaults for some flags
82 // will be changed towards less memory overhead.
83 #ifndef ASAN_LOW_MEMORY
85 # define ASAN_LOW_MEMORY 1
87 # define ASAN_LOW_MEMORY 0
91 // All internal functions in asan reside inside the __asan namespace
92 // to avoid namespace collisions with the user programs.
93 // Seperate namespace also makes it simpler to distinguish the asan run-time
94 // functions from the instrumented user code in a profile.
98 using __sanitizer::StackTrace
;
101 void NORETURN
ShowStatsAndAbort();
103 void ReplaceOperatorsNewAndDelete();
104 // asan_malloc_linux.cc / asan_malloc_mac.cc
105 void ReplaceSystemMalloc();
107 // asan_linux.cc / asan_mac.cc / asan_win.cc
108 void *AsanDoesNotSupportStaticLinkage();
110 void GetPcSpBp(void *context
, uptr
*pc
, uptr
*sp
, uptr
*bp
);
113 bool AsanInterceptsSignal(int signum
);
114 void SetAlternateSignalStack();
115 void UnsetAlternateSignalStack();
116 void InstallSignalHandlers();
117 void ClearShadowMemoryForContext(void *context
);
118 void AsanPlatformThreadInit();
120 // Wrapper for TLS/TSD.
121 void AsanTSDInit(void (*destructor
)(void *tsd
));
123 void AsanTSDSet(void *tsd
);
125 void AppendToErrorMessageBuffer(const char *buffer
);
128 // Poisons the shadow memory for "size" bytes starting from "addr".
129 void PoisonShadow(uptr addr
, uptr size
, u8 value
);
130 // Poisons the shadow memory for "redzone_size" bytes starting from
132 void PoisonShadowPartialRightRedzone(uptr addr
,
137 // Platfrom-specific options.
139 bool PlatformHasDifferentMemcpyAndMemmove();
140 # define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE \
141 (PlatformHasDifferentMemcpyAndMemmove())
143 # define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE true
146 extern int asan_inited
;
147 // Used to avoid infinite recursion in __asan_init().
148 extern bool asan_init_is_running
;
149 extern void (*death_callback
)(void);
151 // These magic values are written to shadow for better error reporting.
152 const int kAsanHeapLeftRedzoneMagic
= 0xfa;
153 const int kAsanHeapRightRedzoneMagic
= 0xfb;
154 const int kAsanHeapFreeMagic
= 0xfd;
155 const int kAsanStackLeftRedzoneMagic
= 0xf1;
156 const int kAsanStackMidRedzoneMagic
= 0xf2;
157 const int kAsanStackRightRedzoneMagic
= 0xf3;
158 const int kAsanStackPartialRedzoneMagic
= 0xf4;
159 const int kAsanStackAfterReturnMagic
= 0xf5;
160 const int kAsanInitializationOrderMagic
= 0xf6;
161 const int kAsanUserPoisonedMemoryMagic
= 0xf7;
162 const int kAsanStackUseAfterScopeMagic
= 0xf8;
163 const int kAsanGlobalRedzoneMagic
= 0xf9;
164 const int kAsanInternalHeapMagic
= 0xfe;
166 static const uptr kCurrentStackFrameMagic
= 0x41B58AB3;
167 static const uptr kRetiredStackFrameMagic
= 0x45E0360E;
169 } // namespace __asan
171 #endif // ASAN_INTERNAL_H