]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/asan/asan_internal.h
Merge clang trunk r238337 from ^/vendor/clang/dist, resolve conflicts,
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / asan / asan_internal.h
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
24 #define ASAN_DEFAULT_FAILURE_EXITCODE 1
25
26 #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
27 # error "The AddressSanitizer run-time should not be"
28         " instrumented by AddressSanitizer"
29 #endif
30
31 // Build-time configuration options.
32
33 // If set, asan will intercept C++ exception api call(s).
34 #ifndef ASAN_HAS_EXCEPTIONS
35 # define ASAN_HAS_EXCEPTIONS 1
36 #endif
37
38 // If set, values like allocator chunk size, as well as defaults for some flags
39 // will be changed towards less memory overhead.
40 #ifndef ASAN_LOW_MEMORY
41 #if SANITIZER_WORDSIZE == 32
42 #  define ASAN_LOW_MEMORY 1
43 #else
44 #  define ASAN_LOW_MEMORY 0
45 # endif
46 #endif
47
48 #ifndef ASAN_DYNAMIC
49 # ifdef PIC
50 #  define ASAN_DYNAMIC 1
51 # else
52 #  define ASAN_DYNAMIC 0
53 # endif
54 #endif
55
56 // All internal functions in asan reside inside the __asan namespace
57 // to avoid namespace collisions with the user programs.
58 // Separate namespace also makes it simpler to distinguish the asan run-time
59 // functions from the instrumented user code in a profile.
60 namespace __asan {
61
62 class AsanThread;
63 using __sanitizer::StackTrace;
64
65 struct SignalContext {
66   void *context;
67   uptr addr;
68   uptr pc;
69   uptr sp;
70   uptr bp;
71
72   SignalContext(void *context, uptr addr, uptr pc, uptr sp, uptr bp) :
73       context(context), addr(addr), pc(pc), sp(sp), bp(bp) {
74   }
75
76   // Creates signal context in a platform-specific manner.
77   static SignalContext Create(void *siginfo, void *context);
78 };
79
80 void AsanInitFromRtl();
81
82 // asan_rtl.cc
83 void NORETURN ShowStatsAndAbort();
84
85 // asan_malloc_linux.cc / asan_malloc_mac.cc
86 void ReplaceSystemMalloc();
87
88 // asan_linux.cc / asan_mac.cc / asan_win.cc
89 void *AsanDoesNotSupportStaticLinkage();
90 void AsanCheckDynamicRTPrereqs();
91 void AsanCheckIncompatibleRT();
92
93 void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp);
94 void AsanOnSIGSEGV(int, void *siginfo, void *context);
95
96 void DisableReexec();
97 void MaybeReexec();
98 void ReadContextStack(void *context, uptr *stack, uptr *ssize);
99 void AsanPlatformThreadInit();
100 void StopInitOrderChecking();
101
102 // Wrapper for TLS/TSD.
103 void AsanTSDInit(void (*destructor)(void *tsd));
104 void *AsanTSDGet();
105 void AsanTSDSet(void *tsd);
106 void PlatformTSDDtor(void *tsd);
107
108 void AppendToErrorMessageBuffer(const char *buffer);
109
110 void *AsanDlSymNext(const char *sym);
111
112 void ReserveShadowMemoryRange(uptr beg, uptr end);
113
114 // Platform-specific options.
115 #if SANITIZER_MAC
116 bool PlatformHasDifferentMemcpyAndMemmove();
117 # define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE \
118     (PlatformHasDifferentMemcpyAndMemmove())
119 #else
120 # define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE true
121 #endif  // SANITIZER_MAC
122
123 // Add convenient macro for interface functions that may be represented as
124 // weak hooks.
125 #define ASAN_MALLOC_HOOK(ptr, size) \
126   if (&__sanitizer_malloc_hook) __sanitizer_malloc_hook(ptr, size)
127 #define ASAN_FREE_HOOK(ptr) \
128   if (&__sanitizer_free_hook) __sanitizer_free_hook(ptr)
129 #define ASAN_ON_ERROR() \
130   if (&__asan_on_error) __asan_on_error()
131
132 extern int asan_inited;
133 // Used to avoid infinite recursion in __asan_init().
134 extern bool asan_init_is_running;
135 extern void (*death_callback)(void);
136
137 // These magic values are written to shadow for better error reporting.
138 const int kAsanHeapLeftRedzoneMagic = 0xfa;
139 const int kAsanHeapRightRedzoneMagic = 0xfb;
140 const int kAsanHeapFreeMagic = 0xfd;
141 const int kAsanStackLeftRedzoneMagic = 0xf1;
142 const int kAsanStackMidRedzoneMagic = 0xf2;
143 const int kAsanStackRightRedzoneMagic = 0xf3;
144 const int kAsanStackPartialRedzoneMagic = 0xf4;
145 const int kAsanStackAfterReturnMagic = 0xf5;
146 const int kAsanInitializationOrderMagic = 0xf6;
147 const int kAsanUserPoisonedMemoryMagic = 0xf7;
148 const int kAsanContiguousContainerOOBMagic = 0xfc;
149 const int kAsanStackUseAfterScopeMagic = 0xf8;
150 const int kAsanGlobalRedzoneMagic = 0xf9;
151 const int kAsanInternalHeapMagic = 0xfe;
152 const int kAsanArrayCookieMagic = 0xac;
153 const int kAsanIntraObjectRedzone = 0xbb;
154 const int kAsanAllocaLeftMagic = 0xca;
155 const int kAsanAllocaRightMagic = 0xcb;
156
157 static const uptr kCurrentStackFrameMagic = 0x41B58AB3;
158 static const uptr kRetiredStackFrameMagic = 0x45E0360E;
159
160 }  // namespace __asan
161
162 #endif  // ASAN_INTERNAL_H