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 and RTEMS. 36 // Only the functions in asan_interceptors_memintrinsics.h are 37 // really defined to replace libc functions. 38 #if !SANITIZER_FUCHSIA && !SANITIZER_RTEMS 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 #else 48 # define ASAN_INTERCEPT_ATOLL_AND_STRTOLL 0 49 # define ASAN_INTERCEPT__LONGJMP 0 50 # define ASAN_INTERCEPT_INDEX 0 51 # define ASAN_INTERCEPT_PTHREAD_CREATE 0 52 #endif 53 54 #if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \ 55 SANITIZER_SOLARIS 56 # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 1 57 #else 58 # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 0 59 #endif 60 61 #if (SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_SOLARIS 62 # define ASAN_INTERCEPT_SWAPCONTEXT 1 63 #else 64 # define ASAN_INTERCEPT_SWAPCONTEXT 0 65 #endif 66 67 #if !SANITIZER_WINDOWS 68 # define ASAN_INTERCEPT_SIGLONGJMP 1 69 #else 70 # define ASAN_INTERCEPT_SIGLONGJMP 0 71 #endif 72 73 #if SANITIZER_LINUX && !SANITIZER_ANDROID 74 # define ASAN_INTERCEPT___LONGJMP_CHK 1 75 #else 76 # define ASAN_INTERCEPT___LONGJMP_CHK 0 77 #endif 78 79 #if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && !SANITIZER_SOLARIS && \ 80 !SANITIZER_NETBSD 81 # define ASAN_INTERCEPT___CXA_THROW 1 82 # define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1 83 # if defined(_GLIBCXX_SJLJ_EXCEPTIONS) || (SANITIZER_IOS && defined(__arm__)) 84 # define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 1 85 # else 86 # define ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION 1 87 # endif 88 #else 89 # define ASAN_INTERCEPT___CXA_THROW 0 90 # define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 0 91 # define ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION 0 92 # define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 0 93 #endif 94 95 #if !SANITIZER_WINDOWS 96 # define ASAN_INTERCEPT___CXA_ATEXIT 1 97 #else 98 # define ASAN_INTERCEPT___CXA_ATEXIT 0 99 #endif 100 101 #if SANITIZER_LINUX && !SANITIZER_ANDROID 102 # define ASAN_INTERCEPT___STRDUP 1 103 #else 104 # define ASAN_INTERCEPT___STRDUP 0 105 #endif 106 107 DECLARE_REAL(int, memcmp, const void *a1, const void *a2, uptr size) 108 DECLARE_REAL(char*, strchr, const char *str, int c) 109 DECLARE_REAL(SIZE_T, strlen, const char *s) 110 DECLARE_REAL(char*, strncpy, char *to, const char *from, uptr size) 111 DECLARE_REAL(uptr, strnlen, const char *s, uptr maxlen) 112 DECLARE_REAL(char*, strstr, const char *s1, const char *s2) 113 114 #if !SANITIZER_MAC 115 #define ASAN_INTERCEPT_FUNC(name) \ 116 do { \ 117 if ((!INTERCEPT_FUNCTION(name) || !REAL(name))) \ 118 VReport(1, "AddressSanitizer: failed to intercept '" #name "'\n"); \ 119 } while (0) 120 #define ASAN_INTERCEPT_FUNC_VER(name, ver) \ 121 do { \ 122 if ((!INTERCEPT_FUNCTION_VER(name, ver) || !REAL(name))) \ 123 VReport( \ 124 1, "AddressSanitizer: failed to intercept '" #name "@@" #ver "'\n"); \ 125 } while (0) 126 #else 127 // OS X interceptors don't need to be initialized with INTERCEPT_FUNCTION. 128 #define ASAN_INTERCEPT_FUNC(name) 129 #endif // SANITIZER_MAC 130 131 #endif // !SANITIZER_FUCHSIA 132 133 #endif // ASAN_INTERCEPTORS_H 134