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 AsanPlatformThreadInit();
119 // Wrapper for TLS/TSD.
120 void AsanTSDInit(void (*destructor
)(void *tsd
));
122 void AsanTSDSet(void *tsd
);
124 void AppendToErrorMessageBuffer(const char *buffer
);
127 // Poisons the shadow memory for "size" bytes starting from "addr".
128 void PoisonShadow(uptr addr
, uptr size
, u8 value
);
129 // Poisons the shadow memory for "redzone_size" bytes starting from
131 void PoisonShadowPartialRightRedzone(uptr addr
,
136 // Platfrom-specific options.
138 bool PlatformHasDifferentMemcpyAndMemmove();
139 # define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE \
140 (PlatformHasDifferentMemcpyAndMemmove())
142 # define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE true
145 extern int asan_inited
;
146 // Used to avoid infinite recursion in __asan_init().
147 extern bool asan_init_is_running
;
148 extern void (*death_callback
)(void);
150 // These magic values are written to shadow for better error reporting.
151 const int kAsanHeapLeftRedzoneMagic
= 0xfa;
152 const int kAsanHeapRightRedzoneMagic
= 0xfb;
153 const int kAsanHeapFreeMagic
= 0xfd;
154 const int kAsanStackLeftRedzoneMagic
= 0xf1;
155 const int kAsanStackMidRedzoneMagic
= 0xf2;
156 const int kAsanStackRightRedzoneMagic
= 0xf3;
157 const int kAsanStackPartialRedzoneMagic
= 0xf4;
158 const int kAsanStackAfterReturnMagic
= 0xf5;
159 const int kAsanInitializationOrderMagic
= 0xf6;
160 const int kAsanUserPoisonedMemoryMagic
= 0xf7;
161 const int kAsanGlobalRedzoneMagic
= 0xf9;
162 const int kAsanInternalHeapMagic
= 0xfe;
164 static const uptr kCurrentStackFrameMagic
= 0x41B58AB3;
165 static const uptr kRetiredStackFrameMagic
= 0x45E0360E;
167 } // namespace __asan
169 #endif // ASAN_INTERNAL_H