]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/asan/asan_internal.h
Update llvm, clang and lldb to trunk r257626, and update build glue.
[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 void AsanInitFromRtl();
66
67 // asan_rtl.cc
68 void NORETURN ShowStatsAndAbort();
69
70 // asan_malloc_linux.cc / asan_malloc_mac.cc
71 void ReplaceSystemMalloc();
72
73 // asan_linux.cc / asan_mac.cc / asan_win.cc
74 void *AsanDoesNotSupportStaticLinkage();
75 void AsanCheckDynamicRTPrereqs();
76 void AsanCheckIncompatibleRT();
77
78 void AsanOnSIGSEGV(int, void *siginfo, void *context);
79
80 void DisableReexec();
81 void MaybeReexec();
82 void ReadContextStack(void *context, uptr *stack, uptr *ssize);
83 void AsanPlatformThreadInit();
84 void StopInitOrderChecking();
85
86 // Wrapper for TLS/TSD.
87 void AsanTSDInit(void (*destructor)(void *tsd));
88 void *AsanTSDGet();
89 void AsanTSDSet(void *tsd);
90 void PlatformTSDDtor(void *tsd);
91
92 void AppendToErrorMessageBuffer(const char *buffer);
93
94 void *AsanDlSymNext(const char *sym);
95
96 void ReserveShadowMemoryRange(uptr beg, uptr end, const char *name);
97
98 // Platform-specific options.
99 #if SANITIZER_MAC
100 bool PlatformHasDifferentMemcpyAndMemmove();
101 # define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE \
102     (PlatformHasDifferentMemcpyAndMemmove())
103 #else
104 # define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE true
105 #endif  // SANITIZER_MAC
106
107 // Add convenient macro for interface functions that may be represented as
108 // weak hooks.
109 #define ASAN_MALLOC_HOOK(ptr, size) \
110   if (&__sanitizer_malloc_hook) __sanitizer_malloc_hook(ptr, size)
111 #define ASAN_FREE_HOOK(ptr) \
112   if (&__sanitizer_free_hook) __sanitizer_free_hook(ptr)
113 #define ASAN_ON_ERROR() \
114   if (&__asan_on_error) __asan_on_error()
115
116 extern int asan_inited;
117 // Used to avoid infinite recursion in __asan_init().
118 extern bool asan_init_is_running;
119 extern void (*death_callback)(void);
120
121 // These magic values are written to shadow for better error reporting.
122 const int kAsanHeapLeftRedzoneMagic = 0xfa;
123 const int kAsanHeapRightRedzoneMagic = 0xfb;
124 const int kAsanHeapFreeMagic = 0xfd;
125 const int kAsanStackLeftRedzoneMagic = 0xf1;
126 const int kAsanStackMidRedzoneMagic = 0xf2;
127 const int kAsanStackRightRedzoneMagic = 0xf3;
128 const int kAsanStackPartialRedzoneMagic = 0xf4;
129 const int kAsanStackAfterReturnMagic = 0xf5;
130 const int kAsanInitializationOrderMagic = 0xf6;
131 const int kAsanUserPoisonedMemoryMagic = 0xf7;
132 const int kAsanContiguousContainerOOBMagic = 0xfc;
133 const int kAsanStackUseAfterScopeMagic = 0xf8;
134 const int kAsanGlobalRedzoneMagic = 0xf9;
135 const int kAsanInternalHeapMagic = 0xfe;
136 const int kAsanArrayCookieMagic = 0xac;
137 const int kAsanIntraObjectRedzone = 0xbb;
138 const int kAsanAllocaLeftMagic = 0xca;
139 const int kAsanAllocaRightMagic = 0xcb;
140
141 static const uptr kCurrentStackFrameMagic = 0x41B58AB3;
142 static const uptr kRetiredStackFrameMagic = 0x45E0360E;
143
144 }  // namespace __asan
145
146 #endif  // ASAN_INTERNAL_H