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