Add C++11 header <cuchar>.
[official-gcc.git] / libsanitizer / asan / asan_internal.h
blob8911575d84a05e4d65cca511e565d0197958b7aa
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 "asan_interface_internal.h"
17 #include "sanitizer_common/sanitizer_common.h"
18 #include "sanitizer_common/sanitizer_internal_defs.h"
19 #include "sanitizer_common/sanitizer_stacktrace.h"
20 #include "sanitizer_common/sanitizer_libc.h"
22 #define ASAN_DEFAULT_FAILURE_EXITCODE 1
24 #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
25 # error "The AddressSanitizer run-time should not be"
26 " instrumented by AddressSanitizer"
27 #endif
29 // Build-time configuration options.
31 // If set, asan will intercept C++ exception api call(s).
32 #ifndef ASAN_HAS_EXCEPTIONS
33 # define ASAN_HAS_EXCEPTIONS 1
34 #endif
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
46 #ifndef ASAN_DYNAMIC
47 # ifdef PIC
48 # define ASAN_DYNAMIC 1
49 # else
50 # define ASAN_DYNAMIC 0
51 # endif
52 #endif
54 // All internal functions in asan reside inside the __asan namespace
55 // to avoid namespace collisions with the user programs.
56 // Separate namespace also makes it simpler to distinguish the asan run-time
57 // functions from the instrumented user code in a profile.
58 namespace __asan {
60 class AsanThread;
61 using __sanitizer::StackTrace;
63 void AsanInitFromRtl();
65 // asan_rtl.cc
66 void NORETURN ShowStatsAndAbort();
68 // asan_malloc_linux.cc / asan_malloc_mac.cc
69 void ReplaceSystemMalloc();
71 // asan_linux.cc / asan_mac.cc / asan_win.cc
72 void *AsanDoesNotSupportStaticLinkage();
73 void AsanCheckDynamicRTPrereqs();
74 void AsanCheckIncompatibleRT();
76 void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp);
77 void AsanOnSIGSEGV(int, void *siginfo, void *context);
79 void MaybeReexec();
80 bool AsanInterceptsSignal(int signum);
81 void ReadContextStack(void *context, uptr *stack, uptr *ssize);
82 void AsanPlatformThreadInit();
83 void StopInitOrderChecking();
85 // Wrapper for TLS/TSD.
86 void AsanTSDInit(void (*destructor)(void *tsd));
87 void *AsanTSDGet();
88 void AsanTSDSet(void *tsd);
89 void PlatformTSDDtor(void *tsd);
91 void AppendToErrorMessageBuffer(const char *buffer);
93 void ParseExtraActivationFlags();
95 void *AsanDlSymNext(const char *sym);
97 // Platform-specific options.
98 #if SANITIZER_MAC
99 bool PlatformHasDifferentMemcpyAndMemmove();
100 # define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE \
101 (PlatformHasDifferentMemcpyAndMemmove())
102 #else
103 # define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE true
104 #endif // SANITIZER_MAC
106 // Add convenient macro for interface functions that may be represented as
107 // weak hooks.
108 #define ASAN_MALLOC_HOOK(ptr, size) \
109 if (&__sanitizer_malloc_hook) __sanitizer_malloc_hook(ptr, size)
110 #define ASAN_FREE_HOOK(ptr) \
111 if (&__sanitizer_free_hook) __sanitizer_free_hook(ptr)
112 #define ASAN_ON_ERROR() \
113 if (&__asan_on_error) __asan_on_error()
115 extern int asan_inited;
116 // Used to avoid infinite recursion in __asan_init().
117 extern bool asan_init_is_running;
118 extern void (*death_callback)(void);
120 // These magic values are written to shadow for better error reporting.
121 const int kAsanHeapLeftRedzoneMagic = 0xfa;
122 const int kAsanHeapRightRedzoneMagic = 0xfb;
123 const int kAsanHeapFreeMagic = 0xfd;
124 const int kAsanStackLeftRedzoneMagic = 0xf1;
125 const int kAsanStackMidRedzoneMagic = 0xf2;
126 const int kAsanStackRightRedzoneMagic = 0xf3;
127 const int kAsanStackPartialRedzoneMagic = 0xf4;
128 const int kAsanStackAfterReturnMagic = 0xf5;
129 const int kAsanInitializationOrderMagic = 0xf6;
130 const int kAsanUserPoisonedMemoryMagic = 0xf7;
131 const int kAsanContiguousContainerOOBMagic = 0xfc;
132 const int kAsanStackUseAfterScopeMagic = 0xf8;
133 const int kAsanGlobalRedzoneMagic = 0xf9;
134 const int kAsanInternalHeapMagic = 0xfe;
135 const int kAsanArrayCookieMagic = 0xac;
136 const int kAsanIntraObjectRedzone = 0xbb;
138 static const uptr kCurrentStackFrameMagic = 0x41B58AB3;
139 static const uptr kRetiredStackFrameMagic = 0x45E0360E;
141 } // namespace __asan
143 #endif // ASAN_INTERNAL_H