annotate libsanitizer/interception/interception.h @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 //===-- interception.h ------------------------------------------*- C++ -*-===//
kono
parents:
diff changeset
2 //
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
111
kono
parents:
diff changeset
6 //
kono
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
kono
parents:
diff changeset
8 //
kono
parents:
diff changeset
9 // This file is a part of AddressSanitizer, an address sanity checker.
kono
parents:
diff changeset
10 //
kono
parents:
diff changeset
11 // Machinery for providing replacements/wrappers for system functions.
kono
parents:
diff changeset
12 //===----------------------------------------------------------------------===//
kono
parents:
diff changeset
13
kono
parents:
diff changeset
14 #ifndef INTERCEPTION_H
kono
parents:
diff changeset
15 #define INTERCEPTION_H
kono
parents:
diff changeset
16
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
17 #include "sanitizer_common/sanitizer_internal_defs.h"
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
18
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
19 #if !SANITIZER_LINUX && !SANITIZER_FREEBSD && !SANITIZER_MAC && \
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
20 !SANITIZER_NETBSD && !SANITIZER_OPENBSD && !SANITIZER_WINDOWS && \
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
21 !SANITIZER_FUCHSIA && !SANITIZER_RTEMS && !SANITIZER_SOLARIS
111
kono
parents:
diff changeset
22 # error "Interception doesn't work on this operating system."
kono
parents:
diff changeset
23 #endif
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 // These typedefs should be used only in the interceptor definitions to replace
kono
parents:
diff changeset
26 // the standard system types (e.g. SSIZE_T instead of ssize_t)
kono
parents:
diff changeset
27 typedef __sanitizer::uptr SIZE_T;
kono
parents:
diff changeset
28 typedef __sanitizer::sptr SSIZE_T;
kono
parents:
diff changeset
29 typedef __sanitizer::sptr PTRDIFF_T;
kono
parents:
diff changeset
30 typedef __sanitizer::s64 INTMAX_T;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
31 typedef __sanitizer::u64 UINTMAX_T;
111
kono
parents:
diff changeset
32 typedef __sanitizer::OFF_T OFF_T;
kono
parents:
diff changeset
33 typedef __sanitizer::OFF64_T OFF64_T;
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 // How to add an interceptor:
kono
parents:
diff changeset
36 // Suppose you need to wrap/replace system function (generally, from libc):
kono
parents:
diff changeset
37 // int foo(const char *bar, double baz);
kono
parents:
diff changeset
38 // You'll need to:
kono
parents:
diff changeset
39 // 1) define INTERCEPTOR(int, foo, const char *bar, double baz) { ... } in
kono
parents:
diff changeset
40 // your source file. See the notes below for cases when
kono
parents:
diff changeset
41 // INTERCEPTOR_WITH_SUFFIX(...) should be used instead.
kono
parents:
diff changeset
42 // 2) Call "INTERCEPT_FUNCTION(foo)" prior to the first call of "foo".
kono
parents:
diff changeset
43 // INTERCEPT_FUNCTION(foo) evaluates to "true" iff the function was
kono
parents:
diff changeset
44 // intercepted successfully.
kono
parents:
diff changeset
45 // You can access original function by calling REAL(foo)(bar, baz).
kono
parents:
diff changeset
46 // By default, REAL(foo) will be visible only inside your interceptor, and if
kono
parents:
diff changeset
47 // you want to use it in other parts of RTL, you'll need to:
kono
parents:
diff changeset
48 // 3a) add DECLARE_REAL(int, foo, const char*, double) to a
kono
parents:
diff changeset
49 // header file.
kono
parents:
diff changeset
50 // However, if the call "INTERCEPT_FUNCTION(foo)" and definition for
kono
parents:
diff changeset
51 // INTERCEPTOR(..., foo, ...) are in different files, you'll instead need to:
kono
parents:
diff changeset
52 // 3b) add DECLARE_REAL_AND_INTERCEPTOR(int, foo, const char*, double)
kono
parents:
diff changeset
53 // to a header file.
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 // Notes: 1. Things may not work properly if macro INTERCEPTOR(...) {...} or
kono
parents:
diff changeset
56 // DECLARE_REAL(...) are located inside namespaces.
kono
parents:
diff changeset
57 // 2. On Mac you can also use: "OVERRIDE_FUNCTION(foo, zoo)" to
kono
parents:
diff changeset
58 // effectively redirect calls from "foo" to "zoo". In this case
kono
parents:
diff changeset
59 // you aren't required to implement
kono
parents:
diff changeset
60 // INTERCEPTOR(int, foo, const char *bar, double baz) {...}
kono
parents:
diff changeset
61 // but instead you'll have to add
kono
parents:
diff changeset
62 // DECLARE_REAL(int, foo, const char *bar, double baz) in your
kono
parents:
diff changeset
63 // source file (to define a pointer to overriden function).
kono
parents:
diff changeset
64 // 3. Some Mac functions have symbol variants discriminated by
kono
parents:
diff changeset
65 // additional suffixes, e.g. _$UNIX2003 (see
kono
parents:
diff changeset
66 // https://developer.apple.com/library/mac/#releasenotes/Darwin/SymbolVariantsRelNotes/index.html
kono
parents:
diff changeset
67 // for more details). To intercept such functions you need to use the
kono
parents:
diff changeset
68 // INTERCEPTOR_WITH_SUFFIX(...) macro.
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 // How it works:
kono
parents:
diff changeset
71 // To replace system functions on Linux we just need to declare functions
kono
parents:
diff changeset
72 // with same names in our library and then obtain the real function pointers
kono
parents:
diff changeset
73 // using dlsym().
kono
parents:
diff changeset
74 // There is one complication. A user may also intercept some of the functions
kono
parents:
diff changeset
75 // we intercept. To resolve this we declare our interceptors with __interceptor_
kono
parents:
diff changeset
76 // prefix, and then make actual interceptors weak aliases to __interceptor_
kono
parents:
diff changeset
77 // functions.
kono
parents:
diff changeset
78 //
kono
parents:
diff changeset
79 // This is not so on Mac OS, where the two-level namespace makes
kono
parents:
diff changeset
80 // our replacement functions invisible to other libraries. This may be overcomed
kono
parents:
diff changeset
81 // using the DYLD_FORCE_FLAT_NAMESPACE, but some errors loading the shared
kono
parents:
diff changeset
82 // libraries in Chromium were noticed when doing so.
kono
parents:
diff changeset
83 // Instead we create a dylib containing a __DATA,__interpose section that
kono
parents:
diff changeset
84 // associates library functions with their wrappers. When this dylib is
kono
parents:
diff changeset
85 // preloaded before an executable using DYLD_INSERT_LIBRARIES, it routes all
kono
parents:
diff changeset
86 // the calls to interposed functions done through stubs to the wrapper
kono
parents:
diff changeset
87 // functions.
kono
parents:
diff changeset
88 // As it's decided at compile time which functions are to be intercepted on Mac,
kono
parents:
diff changeset
89 // INTERCEPT_FUNCTION() is effectively a no-op on this system.
kono
parents:
diff changeset
90
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
91 #if SANITIZER_MAC
111
kono
parents:
diff changeset
92 #include <sys/cdefs.h> // For __DARWIN_ALIAS_C().
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 // Just a pair of pointers.
kono
parents:
diff changeset
95 struct interpose_substitution {
kono
parents:
diff changeset
96 const __sanitizer::uptr replacement;
kono
parents:
diff changeset
97 const __sanitizer::uptr original;
kono
parents:
diff changeset
98 };
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 // For a function foo() create a global pair of pointers { wrap_foo, foo } in
kono
parents:
diff changeset
101 // the __DATA,__interpose section.
kono
parents:
diff changeset
102 // As a result all the calls to foo() will be routed to wrap_foo() at runtime.
kono
parents:
diff changeset
103 #define INTERPOSER(func_name) __attribute__((used)) \
kono
parents:
diff changeset
104 const interpose_substitution substitution_##func_name[] \
kono
parents:
diff changeset
105 __attribute__((section("__DATA, __interpose"))) = { \
kono
parents:
diff changeset
106 { reinterpret_cast<const uptr>(WRAP(func_name)), \
kono
parents:
diff changeset
107 reinterpret_cast<const uptr>(func_name) } \
kono
parents:
diff changeset
108 }
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 // For a function foo() and a wrapper function bar() create a global pair
kono
parents:
diff changeset
111 // of pointers { bar, foo } in the __DATA,__interpose section.
kono
parents:
diff changeset
112 // As a result all the calls to foo() will be routed to bar() at runtime.
kono
parents:
diff changeset
113 #define INTERPOSER_2(func_name, wrapper_name) __attribute__((used)) \
kono
parents:
diff changeset
114 const interpose_substitution substitution_##func_name[] \
kono
parents:
diff changeset
115 __attribute__((section("__DATA, __interpose"))) = { \
kono
parents:
diff changeset
116 { reinterpret_cast<const uptr>(wrapper_name), \
kono
parents:
diff changeset
117 reinterpret_cast<const uptr>(func_name) } \
kono
parents:
diff changeset
118 }
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 # define WRAP(x) wrap_##x
kono
parents:
diff changeset
121 # define WRAPPER_NAME(x) "wrap_"#x
kono
parents:
diff changeset
122 # define INTERCEPTOR_ATTRIBUTE
kono
parents:
diff changeset
123 # define DECLARE_WRAPPER(ret_type, func, ...)
kono
parents:
diff changeset
124
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
125 #elif SANITIZER_WINDOWS
111
kono
parents:
diff changeset
126 # define WRAP(x) __asan_wrap_##x
kono
parents:
diff changeset
127 # define WRAPPER_NAME(x) "__asan_wrap_"#x
kono
parents:
diff changeset
128 # define INTERCEPTOR_ATTRIBUTE __declspec(dllexport)
kono
parents:
diff changeset
129 # define DECLARE_WRAPPER(ret_type, func, ...) \
kono
parents:
diff changeset
130 extern "C" ret_type func(__VA_ARGS__);
kono
parents:
diff changeset
131 # define DECLARE_WRAPPER_WINAPI(ret_type, func, ...) \
kono
parents:
diff changeset
132 extern "C" __declspec(dllimport) ret_type __stdcall func(__VA_ARGS__);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
133 #elif SANITIZER_RTEMS
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
134 # define WRAP(x) x
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
135 # define WRAPPER_NAME(x) #x
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
136 # define INTERCEPTOR_ATTRIBUTE
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
137 # define DECLARE_WRAPPER(ret_type, func, ...)
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
138 #elif SANITIZER_FREEBSD || SANITIZER_NETBSD
111
kono
parents:
diff changeset
139 # define WRAP(x) __interceptor_ ## x
kono
parents:
diff changeset
140 # define WRAPPER_NAME(x) "__interceptor_" #x
kono
parents:
diff changeset
141 # define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default")))
kono
parents:
diff changeset
142 // FreeBSD's dynamic linker (incompliantly) gives non-weak symbols higher
kono
parents:
diff changeset
143 // priority than weak ones so weak aliases won't work for indirect calls
kono
parents:
diff changeset
144 // in position-independent (-fPIC / -fPIE) mode.
kono
parents:
diff changeset
145 # define DECLARE_WRAPPER(ret_type, func, ...) \
kono
parents:
diff changeset
146 extern "C" ret_type func(__VA_ARGS__) \
kono
parents:
diff changeset
147 __attribute__((alias("__interceptor_" #func), visibility("default")));
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
148 #elif !SANITIZER_FUCHSIA
111
kono
parents:
diff changeset
149 # define WRAP(x) __interceptor_ ## x
kono
parents:
diff changeset
150 # define WRAPPER_NAME(x) "__interceptor_" #x
kono
parents:
diff changeset
151 # define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default")))
kono
parents:
diff changeset
152 # define DECLARE_WRAPPER(ret_type, func, ...) \
kono
parents:
diff changeset
153 extern "C" ret_type func(__VA_ARGS__) \
kono
parents:
diff changeset
154 __attribute__((weak, alias("__interceptor_" #func), visibility("default")));
kono
parents:
diff changeset
155 #endif
kono
parents:
diff changeset
156
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
157 #if SANITIZER_FUCHSIA
111
kono
parents:
diff changeset
158 // There is no general interception at all on Fuchsia.
kono
parents:
diff changeset
159 // Sanitizer runtimes just define functions directly to preempt them,
kono
parents:
diff changeset
160 // and have bespoke ways to access the underlying libc functions.
kono
parents:
diff changeset
161 # include <zircon/sanitizer.h>
kono
parents:
diff changeset
162 # define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default")))
kono
parents:
diff changeset
163 # define REAL(x) __unsanitized_##x
kono
parents:
diff changeset
164 # define DECLARE_REAL(ret_type, func, ...)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
165 #elif SANITIZER_RTEMS
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
166 # define REAL(x) __real_ ## x
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
167 # define DECLARE_REAL(ret_type, func, ...) \
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
168 extern "C" ret_type REAL(func)(__VA_ARGS__);
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
169 #elif !SANITIZER_MAC
111
kono
parents:
diff changeset
170 # define PTR_TO_REAL(x) real_##x
kono
parents:
diff changeset
171 # define REAL(x) __interception::PTR_TO_REAL(x)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
172 # define FUNC_TYPE(x) x##_type
111
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 # define DECLARE_REAL(ret_type, func, ...) \
kono
parents:
diff changeset
175 typedef ret_type (*FUNC_TYPE(func))(__VA_ARGS__); \
kono
parents:
diff changeset
176 namespace __interception { \
kono
parents:
diff changeset
177 extern FUNC_TYPE(func) PTR_TO_REAL(func); \
kono
parents:
diff changeset
178 }
kono
parents:
diff changeset
179 # define ASSIGN_REAL(dst, src) REAL(dst) = REAL(src)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
180 #else // SANITIZER_MAC
111
kono
parents:
diff changeset
181 # define REAL(x) x
kono
parents:
diff changeset
182 # define DECLARE_REAL(ret_type, func, ...) \
kono
parents:
diff changeset
183 extern "C" ret_type func(__VA_ARGS__);
kono
parents:
diff changeset
184 # define ASSIGN_REAL(x, y)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
185 #endif // SANITIZER_MAC
111
kono
parents:
diff changeset
186
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
187 #if !SANITIZER_FUCHSIA && !SANITIZER_RTEMS
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
188 # define DECLARE_REAL_AND_INTERCEPTOR(ret_type, func, ...) \
111
kono
parents:
diff changeset
189 DECLARE_REAL(ret_type, func, __VA_ARGS__) \
kono
parents:
diff changeset
190 extern "C" ret_type WRAP(func)(__VA_ARGS__);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
191 // Declare an interceptor and its wrapper defined in a different translation
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
192 // unit (ex. asm).
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
193 # define DECLARE_EXTERN_INTERCEPTOR_AND_WRAPPER(ret_type, func, ...) \
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
194 extern "C" ret_type WRAP(func)(__VA_ARGS__); \
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
195 extern "C" ret_type func(__VA_ARGS__);
111
kono
parents:
diff changeset
196 #else
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
197 # define DECLARE_REAL_AND_INTERCEPTOR(ret_type, func, ...)
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
198 # define DECLARE_EXTERN_INTERCEPTOR_AND_WRAPPER(ret_type, func, ...)
111
kono
parents:
diff changeset
199 #endif
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 // Generally, you don't need to use DEFINE_REAL by itself, as INTERCEPTOR
kono
parents:
diff changeset
202 // macros does its job. In exceptional cases you may need to call REAL(foo)
kono
parents:
diff changeset
203 // without defining INTERCEPTOR(..., foo, ...). For example, if you override
kono
parents:
diff changeset
204 // foo with an interceptor for other function.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
205 #if !SANITIZER_MAC && !SANITIZER_FUCHSIA && !SANITIZER_RTEMS
111
kono
parents:
diff changeset
206 # define DEFINE_REAL(ret_type, func, ...) \
kono
parents:
diff changeset
207 typedef ret_type (*FUNC_TYPE(func))(__VA_ARGS__); \
kono
parents:
diff changeset
208 namespace __interception { \
kono
parents:
diff changeset
209 FUNC_TYPE(func) PTR_TO_REAL(func); \
kono
parents:
diff changeset
210 }
kono
parents:
diff changeset
211 #else
kono
parents:
diff changeset
212 # define DEFINE_REAL(ret_type, func, ...)
kono
parents:
diff changeset
213 #endif
kono
parents:
diff changeset
214
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
215 #if SANITIZER_FUCHSIA
111
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 // We need to define the __interceptor_func name just to get
kono
parents:
diff changeset
218 // sanitizer_common/scripts/gen_dynamic_list.py to export func.
kono
parents:
diff changeset
219 // But we don't need to export __interceptor_func to get that.
kono
parents:
diff changeset
220 #define INTERCEPTOR(ret_type, func, ...) \
kono
parents:
diff changeset
221 extern "C"[[ gnu::alias(#func), gnu::visibility("hidden") ]] ret_type \
kono
parents:
diff changeset
222 __interceptor_##func(__VA_ARGS__); \
kono
parents:
diff changeset
223 extern "C" INTERCEPTOR_ATTRIBUTE ret_type func(__VA_ARGS__)
kono
parents:
diff changeset
224
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
225 #elif !SANITIZER_MAC
111
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 #define INTERCEPTOR(ret_type, func, ...) \
kono
parents:
diff changeset
228 DEFINE_REAL(ret_type, func, __VA_ARGS__) \
kono
parents:
diff changeset
229 DECLARE_WRAPPER(ret_type, func, __VA_ARGS__) \
kono
parents:
diff changeset
230 extern "C" \
kono
parents:
diff changeset
231 INTERCEPTOR_ATTRIBUTE \
kono
parents:
diff changeset
232 ret_type WRAP(func)(__VA_ARGS__)
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 // We don't need INTERCEPTOR_WITH_SUFFIX on non-Darwin for now.
kono
parents:
diff changeset
235 #define INTERCEPTOR_WITH_SUFFIX(ret_type, func, ...) \
kono
parents:
diff changeset
236 INTERCEPTOR(ret_type, func, __VA_ARGS__)
kono
parents:
diff changeset
237
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
238 #else // SANITIZER_MAC
111
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 #define INTERCEPTOR_ZZZ(suffix, ret_type, func, ...) \
kono
parents:
diff changeset
241 extern "C" ret_type func(__VA_ARGS__) suffix; \
kono
parents:
diff changeset
242 extern "C" ret_type WRAP(func)(__VA_ARGS__); \
kono
parents:
diff changeset
243 INTERPOSER(func); \
kono
parents:
diff changeset
244 extern "C" INTERCEPTOR_ATTRIBUTE ret_type WRAP(func)(__VA_ARGS__)
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 #define INTERCEPTOR(ret_type, func, ...) \
kono
parents:
diff changeset
247 INTERCEPTOR_ZZZ(/*no symbol variants*/, ret_type, func, __VA_ARGS__)
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 #define INTERCEPTOR_WITH_SUFFIX(ret_type, func, ...) \
kono
parents:
diff changeset
250 INTERCEPTOR_ZZZ(__DARWIN_ALIAS_C(func), ret_type, func, __VA_ARGS__)
kono
parents:
diff changeset
251
kono
parents:
diff changeset
252 // Override |overridee| with |overrider|.
kono
parents:
diff changeset
253 #define OVERRIDE_FUNCTION(overridee, overrider) \
kono
parents:
diff changeset
254 INTERPOSER_2(overridee, WRAP(overrider))
kono
parents:
diff changeset
255 #endif
kono
parents:
diff changeset
256
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
257 #if SANITIZER_WINDOWS
111
kono
parents:
diff changeset
258 # define INTERCEPTOR_WINAPI(ret_type, func, ...) \
kono
parents:
diff changeset
259 typedef ret_type (__stdcall *FUNC_TYPE(func))(__VA_ARGS__); \
kono
parents:
diff changeset
260 namespace __interception { \
kono
parents:
diff changeset
261 FUNC_TYPE(func) PTR_TO_REAL(func); \
kono
parents:
diff changeset
262 } \
kono
parents:
diff changeset
263 extern "C" \
kono
parents:
diff changeset
264 INTERCEPTOR_ATTRIBUTE \
kono
parents:
diff changeset
265 ret_type __stdcall WRAP(func)(__VA_ARGS__)
kono
parents:
diff changeset
266 #endif
kono
parents:
diff changeset
267
kono
parents:
diff changeset
268 // ISO C++ forbids casting between pointer-to-function and pointer-to-object,
kono
parents:
diff changeset
269 // so we use casting via an integral type __interception::uptr,
kono
parents:
diff changeset
270 // assuming that system is POSIX-compliant. Using other hacks seem
kono
parents:
diff changeset
271 // challenging, as we don't even pass function type to
kono
parents:
diff changeset
272 // INTERCEPT_FUNCTION macro, only its name.
kono
parents:
diff changeset
273 namespace __interception {
kono
parents:
diff changeset
274 #if defined(_WIN64)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
275 typedef unsigned long long uptr;
111
kono
parents:
diff changeset
276 #else
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
277 typedef unsigned long uptr;
111
kono
parents:
diff changeset
278 #endif // _WIN64
kono
parents:
diff changeset
279 } // namespace __interception
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 #define INCLUDED_FROM_INTERCEPTION_LIB
kono
parents:
diff changeset
282
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
283 #if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
284 SANITIZER_OPENBSD || SANITIZER_SOLARIS
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
285
111
kono
parents:
diff changeset
286 # include "interception_linux.h"
kono
parents:
diff changeset
287 # define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func)
kono
parents:
diff changeset
288 # define INTERCEPT_FUNCTION_VER(func, symver) \
kono
parents:
diff changeset
289 INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
290 #elif SANITIZER_MAC
111
kono
parents:
diff changeset
291 # include "interception_mac.h"
kono
parents:
diff changeset
292 # define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_MAC(func)
kono
parents:
diff changeset
293 # define INTERCEPT_FUNCTION_VER(func, symver) \
kono
parents:
diff changeset
294 INTERCEPT_FUNCTION_VER_MAC(func, symver)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
295 #elif SANITIZER_WINDOWS
111
kono
parents:
diff changeset
296 # include "interception_win.h"
kono
parents:
diff changeset
297 # define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_WIN(func)
kono
parents:
diff changeset
298 # define INTERCEPT_FUNCTION_VER(func, symver) \
kono
parents:
diff changeset
299 INTERCEPT_FUNCTION_VER_WIN(func, symver)
kono
parents:
diff changeset
300 #endif
kono
parents:
diff changeset
301
kono
parents:
diff changeset
302 #undef INCLUDED_FROM_INTERCEPTION_LIB
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 #endif // INTERCEPTION_H