1 //===-- asan_interceptors.h -------------------------------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of AddressSanitizer, an address sanity checker.
10 // ASan-private header for asan_interceptors.cc
11 //===----------------------------------------------------------------------===//
12 #ifndef ASAN_INTERCEPTORS_H
13 #define ASAN_INTERCEPTORS_H
15 #include "asan_internal.h"
16 #include "asan_interceptors_memintrinsics.h"
17 #include "interception/interception.h"
18 #include "sanitizer_common/sanitizer_platform_interceptors.h"
22 void InitializeAsanInterceptors();
23 void InitializePlatformInterceptors();
25 #define ENSURE_ASAN_INITED() \
27 CHECK(!asan_init_is_running); \
28 if (UNLIKELY(!asan_inited)) { \
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
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
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
56 #if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
57 # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 1
59 # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 0
62 #if SANITIZER_LINUX && !SANITIZER_ANDROID
63 # define ASAN_INTERCEPT_SWAPCONTEXT 1
65 # define ASAN_INTERCEPT_SWAPCONTEXT 0
68 #if !SANITIZER_WINDOWS
69 # define ASAN_INTERCEPT_SIGLONGJMP 1
71 # define ASAN_INTERCEPT_SIGLONGJMP 0
74 #if SANITIZER_LINUX && !SANITIZER_ANDROID
75 # define ASAN_INTERCEPT___LONGJMP_CHK 1
77 # define ASAN_INTERCEPT___LONGJMP_CHK 0
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
85 # define ASAN_INTERCEPT___CXA_THROW 0
88 #if !SANITIZER_WINDOWS
89 # define ASAN_INTERCEPT___CXA_ATEXIT 1
91 # define ASAN_INTERCEPT___CXA_ATEXIT 0
94 #if SANITIZER_LINUX && !SANITIZER_ANDROID
95 # define ASAN_INTERCEPT___STRDUP 1
97 # define ASAN_INTERCEPT___STRDUP 0
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
)
107 DECLARE_REAL(int, sigaction
, int signum
, const struct sigaction
*act
,
108 struct sigaction
*oldact
)
111 #define ASAN_INTERCEPT_FUNC(name) \
113 if ((!INTERCEPT_FUNCTION(name) || !REAL(name))) \
114 VReport(1, "AddressSanitizer: failed to intercept '" #name "'\n"); \
116 #define ASAN_INTERCEPT_FUNC_VER(name, ver) \
118 if ((!INTERCEPT_FUNCTION_VER(name, ver) || !REAL(name))) \
120 1, "AddressSanitizer: failed to intercept '" #name "@@" #ver "'\n"); \
123 // OS X interceptors don't need to be initialized with INTERCEPT_FUNCTION.
124 #define ASAN_INTERCEPT_FUNC(name)
125 #endif // SANITIZER_MAC
127 #endif // !SANITIZER_FUCHSIA
129 #endif // ASAN_INTERCEPTORS_H