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