2014-06-05 Julian Brown <julian@codesourcery.com>
[official-gcc.git] / libsanitizer / asan / asan_internal.h
blobd56943a08389b3aacf76dd1550ecbf8bcbd1a5c3
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_USE_PREINIT_ARRAY
47 # define ASAN_USE_PREINIT_ARRAY (SANITIZER_LINUX && !SANITIZER_ANDROID)
48 #endif
50 #ifndef ASAN_DYNAMIC
51 # ifdef PIC
52 # define ASAN_DYNAMIC 1
53 # else
54 # define ASAN_DYNAMIC 0
55 # endif
56 #endif
58 // All internal functions in asan reside inside the __asan namespace
59 // to avoid namespace collisions with the user programs.
60 // Separate namespace also makes it simpler to distinguish the asan run-time
61 // functions from the instrumented user code in a profile.
62 namespace __asan {
64 class AsanThread;
65 using __sanitizer::StackTrace;
67 void AsanInitFromRtl();
69 // asan_rtl.cc
70 void NORETURN ShowStatsAndAbort();
72 // asan_malloc_linux.cc / asan_malloc_mac.cc
73 void ReplaceSystemMalloc();
75 // asan_linux.cc / asan_mac.cc / asan_win.cc
76 void *AsanDoesNotSupportStaticLinkage();
77 void AsanCheckDynamicRTPrereqs();
78 void AsanCheckIncompatibleRT();
80 void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp);
81 void AsanOnSIGSEGV(int, void *siginfo, void *context);
83 void MaybeReexec();
84 bool AsanInterceptsSignal(int signum);
85 void ReadContextStack(void *context, uptr *stack, uptr *ssize);
86 void AsanPlatformThreadInit();
87 void StopInitOrderChecking();
89 // Wrapper for TLS/TSD.
90 void AsanTSDInit(void (*destructor)(void *tsd));
91 void *AsanTSDGet();
92 void AsanTSDSet(void *tsd);
93 void PlatformTSDDtor(void *tsd);
95 void AppendToErrorMessageBuffer(const char *buffer);
97 void ParseExtraActivationFlags();
99 // Platform-specific options.
100 #if SANITIZER_MAC
101 bool PlatformHasDifferentMemcpyAndMemmove();
102 # define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE \
103 (PlatformHasDifferentMemcpyAndMemmove())
104 #else
105 # define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE true
106 #endif // SANITIZER_MAC
108 // Add convenient macro for interface functions that may be represented as
109 // weak hooks.
110 #define ASAN_MALLOC_HOOK(ptr, size) \
111 if (&__asan_malloc_hook) __asan_malloc_hook(ptr, size)
112 #define ASAN_FREE_HOOK(ptr) \
113 if (&__asan_free_hook) __asan_free_hook(ptr)
114 #define ASAN_ON_ERROR() \
115 if (&__asan_on_error) __asan_on_error()
117 extern int asan_inited;
118 // Used to avoid infinite recursion in __asan_init().
119 extern bool asan_init_is_running;
120 extern void (*death_callback)(void);
122 // These magic values are written to shadow for better error reporting.
123 const int kAsanHeapLeftRedzoneMagic = 0xfa;
124 const int kAsanHeapRightRedzoneMagic = 0xfb;
125 const int kAsanHeapFreeMagic = 0xfd;
126 const int kAsanStackLeftRedzoneMagic = 0xf1;
127 const int kAsanStackMidRedzoneMagic = 0xf2;
128 const int kAsanStackRightRedzoneMagic = 0xf3;
129 const int kAsanStackPartialRedzoneMagic = 0xf4;
130 const int kAsanStackAfterReturnMagic = 0xf5;
131 const int kAsanInitializationOrderMagic = 0xf6;
132 const int kAsanUserPoisonedMemoryMagic = 0xf7;
133 const int kAsanContiguousContainerOOBMagic = 0xfc;
134 const int kAsanStackUseAfterScopeMagic = 0xf8;
135 const int kAsanGlobalRedzoneMagic = 0xf9;
136 const int kAsanInternalHeapMagic = 0xfe;
138 static const uptr kCurrentStackFrameMagic = 0x41B58AB3;
139 static const uptr kRetiredStackFrameMagic = 0x45E0360E;
141 } // namespace __asan
143 #endif // ASAN_INTERNAL_H