1 //===-- asan_interceptors.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 for asan_interceptors.cc 11 //===----------------------------------------------------------------------===// 12 #ifndef ASAN_INTERCEPTORS_H 13 #define ASAN_INTERCEPTORS_H 14 15 #include "asan_internal.h" 16 #include "asan_interceptors_memintrinsics.h" 17 #include "interception/interception.h" 18 #include "sanitizer_common/sanitizer_platform_interceptors.h" 19 20 namespace __asan { 21 22 void InitializeAsanInterceptors(); 23 void InitializePlatformInterceptors(); 24 25 #define ENSURE_ASAN_INITED() \ 26 do { \ 27 CHECK(!asan_init_is_running); \ 28 if (UNLIKELY(!asan_inited)) { \ 29 AsanInitFromRtl(); \ 30 } \ 31 } while (0) 32 33 } // namespace __asan 34 35 // There is no general interception at all on Fuchsia. 36 // Only the functions in asan_interceptors_memintrinsics.h are 37 // really defined to replace libc functions. 38 #if !SANITIZER_FUCHSIA 39 40 // Use macro to describe if specific function should be 41 // intercepted on a given platform. 42 #if !SANITIZER_WINDOWS 43 # define ASAN_INTERCEPT_ATOLL_AND_STRTOLL 1 44 # define ASAN_INTERCEPT__LONGJMP 1 45 # define ASAN_INTERCEPT_INDEX 1 46 # define ASAN_INTERCEPT_PTHREAD_CREATE 1 47 # define ASAN_INTERCEPT_FORK 1 48 #else 49 # define ASAN_INTERCEPT_ATOLL_AND_STRTOLL 0 50 # define ASAN_INTERCEPT__LONGJMP 0 51 # define ASAN_INTERCEPT_INDEX 0 52 # define ASAN_INTERCEPT_PTHREAD_CREATE 0 53 # define ASAN_INTERCEPT_FORK 0 54 #endif 55 56 #if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD 57 # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 1 58 #else 59 # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 0 60 #endif 61 62 #if SANITIZER_LINUX && !SANITIZER_ANDROID 63 # define ASAN_INTERCEPT_SWAPCONTEXT 1 64 #else 65 # define ASAN_INTERCEPT_SWAPCONTEXT 0 66 #endif 67 68 #if !SANITIZER_WINDOWS 69 # define ASAN_INTERCEPT_SIGLONGJMP 1 70 #else 71 # define ASAN_INTERCEPT_SIGLONGJMP 0 72 #endif 73 74 #if SANITIZER_LINUX && !SANITIZER_ANDROID 75 # define ASAN_INTERCEPT___LONGJMP_CHK 1 76 #else 77 # define ASAN_INTERCEPT___LONGJMP_CHK 0 78 #endif 79 80 // Android bug: https://code.google.com/p/android/issues/detail?id=61799 81 #if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && \ 82 !(SANITIZER_ANDROID && defined(__i386)) 83 # define ASAN_INTERCEPT___CXA_THROW 1 84 #else 85 # define ASAN_INTERCEPT___CXA_THROW 0 86 #endif 87 88 #if !SANITIZER_WINDOWS 89 # define ASAN_INTERCEPT___CXA_ATEXIT 1 90 #else 91 # define ASAN_INTERCEPT___CXA_ATEXIT 0 92 #endif 93 94 #if SANITIZER_LINUX && !SANITIZER_ANDROID 95 # define ASAN_INTERCEPT___STRDUP 1 96 #else 97 # define ASAN_INTERCEPT___STRDUP 0 98 #endif 99 100 DECLARE_REAL(int, memcmp, const void *a1, const void *a2, uptr size) 101 DECLARE_REAL(char*, strchr, const char *str, int c) 102 DECLARE_REAL(SIZE_T, strlen, const char *s) 103 DECLARE_REAL(char*, strncpy, char *to, const char *from, uptr size) 104 DECLARE_REAL(uptr, strnlen, const char *s, uptr maxlen) 105 DECLARE_REAL(char*, strstr, const char *s1, const char *s2) 106 struct sigaction; 107 DECLARE_REAL(int, sigaction, int signum, const struct sigaction *act, 108 struct sigaction *oldact) 109 110 #if !SANITIZER_MAC 111 #define ASAN_INTERCEPT_FUNC(name) \ 112 do { \ 113 if ((!INTERCEPT_FUNCTION(name) || !REAL(name))) \ 114 VReport(1, "AddressSanitizer: failed to intercept '" #name "'\n"); \ 115 } while (0) 116 #define ASAN_INTERCEPT_FUNC_VER(name, ver) \ 117 do { \ 118 if ((!INTERCEPT_FUNCTION_VER(name, ver) || !REAL(name))) \ 119 VReport( \ 120 1, "AddressSanitizer: failed to intercept '" #name "@@" #ver "'\n"); \ 121 } while (0) 122 #else 123 // OS X interceptors don't need to be initialized with INTERCEPT_FUNCTION. 124 #define ASAN_INTERCEPT_FUNC(name) 125 #endif // SANITIZER_MAC 126 127 #endif // !SANITIZER_FUCHSIA 128 129 #endif // ASAN_INTERCEPTORS_H 130