* configure.ac: Change target-libasan to target-libsanitizer.
[official-gcc.git] / libsanitizer / asan / asan_internal.h
blob21368eef7c98ed881bb85ff56a2d246aae9ad633
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
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"
23 #endif
25 #define ASAN_DEFAULT_FAILURE_EXITCODE 1
27 #if defined(__linux__)
28 # define ASAN_LINUX 1
29 #else
30 # define ASAN_LINUX 0
31 #endif
33 #if defined(__APPLE__)
34 # define ASAN_MAC 1
35 #else
36 # define ASAN_MAC 0
37 #endif
39 #if defined(_WIN32)
40 # define ASAN_WINDOWS 1
41 #else
42 # define ASAN_WINDOWS 0
43 #endif
45 #if defined(__ANDROID__) || defined(ANDROID)
46 # define ASAN_ANDROID 1
47 #else
48 # define ASAN_ANDROID 0
49 #endif
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"
57 #endif
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
65 # else
66 # define ASAN_NEEDS_SEGV 1
67 # endif
68 #endif
70 // If set, asan will intercept C++ exception api call(s).
71 #ifndef ASAN_HAS_EXCEPTIONS
72 # define ASAN_HAS_EXCEPTIONS 1
73 #endif
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
79 #endif
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
84 # ifdef ASAN_ANDROID
85 # define ASAN_LOW_MEMORY 1
86 # else
87 # define ASAN_LOW_MEMORY 0
88 # endif
89 #endif
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.
95 namespace __asan {
97 class AsanThread;
98 using __sanitizer::StackTrace;
100 // asan_rtl.cc
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);
112 void MaybeReexec();
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));
121 void *AsanTSDGet();
122 void AsanTSDSet(void *tsd);
124 void AppendToErrorMessageBuffer(const char *buffer);
126 // asan_poisoning.cc
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
130 // "addr + size".
131 void PoisonShadowPartialRightRedzone(uptr addr,
132 uptr size,
133 uptr redzone_size,
134 u8 value);
136 // Platfrom-specific options.
137 #ifdef __APPLE__
138 bool PlatformHasDifferentMemcpyAndMemmove();
139 # define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE \
140 (PlatformHasDifferentMemcpyAndMemmove())
141 #else
142 # define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE true
143 #endif // __APPLE__
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