]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/compiler-rt/lib/asan/asan_interceptors.h
MFC r355940:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / compiler-rt / lib / asan / asan_interceptors.h
1 //===-- asan_interceptors.h -------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a part of AddressSanitizer, an address sanity checker.
10 //
11 // ASan-private header for asan_interceptors.cc
12 //===----------------------------------------------------------------------===//
13 #ifndef ASAN_INTERCEPTORS_H
14 #define ASAN_INTERCEPTORS_H
15
16 #include "asan_internal.h"
17 #include "asan_interceptors_memintrinsics.h"
18 #include "interception/interception.h"
19 #include "sanitizer_common/sanitizer_platform_interceptors.h"
20
21 namespace __asan {
22
23 void InitializeAsanInterceptors();
24 void InitializePlatformInterceptors();
25
26 #define ENSURE_ASAN_INITED()      \
27   do {                            \
28     CHECK(!asan_init_is_running); \
29     if (UNLIKELY(!asan_inited)) { \
30       AsanInitFromRtl();          \
31     }                             \
32   } while (0)
33
34 }  // namespace __asan
35
36 // There is no general interception at all on Fuchsia and RTEMS.
37 // Only the functions in asan_interceptors_memintrinsics.h are
38 // really defined to replace libc functions.
39 #if !SANITIZER_FUCHSIA && !SANITIZER_RTEMS
40
41 // Use macro to describe if specific function should be
42 // intercepted on a given platform.
43 #if !SANITIZER_WINDOWS
44 # define ASAN_INTERCEPT_ATOLL_AND_STRTOLL 1
45 # define ASAN_INTERCEPT__LONGJMP 1
46 # define ASAN_INTERCEPT_INDEX 1
47 # define ASAN_INTERCEPT_PTHREAD_CREATE 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 #endif
54
55 #if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \
56     SANITIZER_SOLARIS
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) || SANITIZER_SOLARIS
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 #if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && !SANITIZER_SOLARIS && \
81     !SANITIZER_NETBSD
82 # define ASAN_INTERCEPT___CXA_THROW 1
83 # define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1
84 # if defined(_GLIBCXX_SJLJ_EXCEPTIONS) || (SANITIZER_IOS && defined(__arm__))
85 #  define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 1
86 # else
87 #  define ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION 1
88 # endif
89 #else
90 # define ASAN_INTERCEPT___CXA_THROW 0
91 # define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 0
92 # define ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION 0
93 # define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 0
94 #endif
95
96 #if !SANITIZER_WINDOWS
97 # define ASAN_INTERCEPT___CXA_ATEXIT 1
98 #else
99 # define ASAN_INTERCEPT___CXA_ATEXIT 0
100 #endif
101
102 #if SANITIZER_LINUX && !SANITIZER_ANDROID
103 # define ASAN_INTERCEPT___STRDUP 1
104 #else
105 # define ASAN_INTERCEPT___STRDUP 0
106 #endif
107
108 #if SANITIZER_LINUX && (defined(__arm__) || defined(__aarch64__) || \
109                         defined(__i386__) || defined(__x86_64__))
110 # define ASAN_INTERCEPT_VFORK 1
111 #else
112 # define ASAN_INTERCEPT_VFORK 0
113 #endif
114
115 DECLARE_REAL(int, memcmp, const void *a1, const void *a2, uptr size)
116 DECLARE_REAL(char*, strchr, const char *str, int c)
117 DECLARE_REAL(SIZE_T, strlen, const char *s)
118 DECLARE_REAL(char*, strncpy, char *to, const char *from, uptr size)
119 DECLARE_REAL(uptr, strnlen, const char *s, uptr maxlen)
120 DECLARE_REAL(char*, strstr, const char *s1, const char *s2)
121
122 #if !SANITIZER_MAC
123 #define ASAN_INTERCEPT_FUNC(name)                                         \
124   do {                                                                    \
125     if (!INTERCEPT_FUNCTION(name))                                        \
126       VReport(1, "AddressSanitizer: failed to intercept '%s'\n'", #name); \
127   } while (0)
128 #define ASAN_INTERCEPT_FUNC_VER(name, ver)                                  \
129   do {                                                                      \
130     if (!INTERCEPT_FUNCTION_VER(name, ver))                                 \
131       VReport(1, "AddressSanitizer: failed to intercept '%s@@%s'\n", #name, \
132               #ver);                                                        \
133   } while (0)
134 #else
135 // OS X interceptors don't need to be initialized with INTERCEPT_FUNCTION.
136 #define ASAN_INTERCEPT_FUNC(name)
137 #endif  // SANITIZER_MAC
138
139 #endif  // !SANITIZER_FUCHSIA
140
141 #endif  // ASAN_INTERCEPTORS_H