Lines Matching +full:func +full:-

1 //===-- interception.h ------------------------------------------*- C++ -*-===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
72 // ---------------------
80 // function "func", the interceptor implementation is in ___interceptor_func,
82 // aliased (via a trampoline) by weak wrapper function "func".
86 // - provide a non-weak function "func" that performs interception;
87 // - if __interceptor_func exists, call it to perform the real functionality;
88 // - if it does not exist, figure out the real function and call it instead.
93 // - provide a non-weak function __interceptor_func that performs interception;
94 // - if ___interceptor_func exists, call it to perform the real functionality;
95 // - if it does not exist, figure out the real function and call it instead;
96 // - provide a weak function "func" that is an alias to __interceptor_func.
100 // thereof, may co-exist simultaneously.
103 // ----------------------
105 // This is not so on Mac OS, where the two-level namespace makes our replacement
116 // INTERCEPT_FUNCTION() is effectively a no-op on this system.
150 # define DECLARE_WRAPPER(ret_type, func, ...) argument
156 # define DECLARE_WRAPPER(ret_type, func, ...) \ argument
157 extern "C" ret_type func(__VA_ARGS__);
158 # define DECLARE_WRAPPER_WINAPI(ret_type, func, ...) \ argument
159 extern "C" __declspec(dllimport) ret_type __stdcall func(__VA_ARGS__);
164 // trampoline function. The function "func" is a weak alias to the trampoline
165 // (so that we may check if "func" was overridden), which calls the weak
169 // [wrapper "func": weak] --(alias)--> [TRAMPOLINE(func)]
171 // +--------(tail call)-------+
174 // [__interceptor_func: weak] --(alias)--> [WRAP(func)]
181 // FreeBSD's dynamic linker (incompliantly) gives non-weak symbols higher
183 // in position-independent (-fPIC / -fPIE) mode.
184 # define __ASM_WEAK_WRAPPER(func) ".globl " #func "\n" argument
186 # define __ASM_WEAK_WRAPPER(func) ".weak " #func "\n" argument
194 # define DECLARE_WRAPPER(ret_type, func, ...) \ argument
195 extern "C" ret_type func(__VA_ARGS__); \
196 extern "C" ret_type TRAMPOLINE(func)(__VA_ARGS__); \
197 extern "C" ret_type __interceptor_##func(__VA_ARGS__) \
198 INTERCEPTOR_ATTRIBUTE __attribute__((weak)) ALIAS(WRAP(func)); \
201 __ASM_WEAK_WRAPPER(func) \
202 ".set " #func ", " SANITIZER_STRINGIFY(TRAMPOLINE(func)) "\n" \
203 ".globl " SANITIZER_STRINGIFY(TRAMPOLINE(func)) "\n" \
204 ".type " SANITIZER_STRINGIFY(TRAMPOLINE(func)) ", " \
206 SANITIZER_STRINGIFY(TRAMPOLINE(func)) ":\n" \
208 C_ASM_TAIL_CALL(SANITIZER_STRINGIFY(TRAMPOLINE(func)), \
210 SANITIZER_STRINGIFY(ASM_PREEMPTIBLE_SYM(func))) "\n" \
212 ".size " SANITIZER_STRINGIFY(TRAMPOLINE(func)) ", " \
213 ".-" SANITIZER_STRINGIFY(TRAMPOLINE(func)) "\n" \
220 // [wrapper "func": weak] --(alias)--> [WRAP(func)]
229 # define DECLARE_WRAPPER(ret_type, func, ...) \ argument
230 extern "C" ret_type func(__VA_ARGS__) \
231 INTERCEPTOR_ATTRIBUTE __ATTRIBUTE_WEAK_WRAPPER ALIAS(WRAP(func));
242 # define DECLARE_REAL(ret_type, func, ...) argument
248 # define DECLARE_REAL(ret_type, func, ...) \ argument
249 typedef ret_type (*FUNC_TYPE(func))(__VA_ARGS__); \
251 extern FUNC_TYPE(func) PTR_TO_REAL(func); \
256 # define DECLARE_REAL(ret_type, func, ...) \ argument
257 extern "C" ret_type func(__VA_ARGS__);
262 # define DECLARE_REAL_AND_INTERCEPTOR(ret_type, func, ...) \ argument
263 DECLARE_REAL(ret_type, func, __VA_ARGS__) \
264 extern "C" ret_type TRAMPOLINE(func)(__VA_ARGS__); \
265 extern "C" ret_type WRAP(func)(__VA_ARGS__);
268 # define DECLARE_EXTERN_INTERCEPTOR_AND_WRAPPER(ret_type, func, ...) \ argument
269 extern "C" ret_type TRAMPOLINE(func)(__VA_ARGS__); \
270 extern "C" ret_type WRAP(func)(__VA_ARGS__); \
271 extern "C" ret_type func(__VA_ARGS__);
273 # define DECLARE_REAL_AND_INTERCEPTOR(ret_type, func, ...) argument
274 # define DECLARE_EXTERN_INTERCEPTOR_AND_WRAPPER(ret_type, func, ...) argument
282 # define DEFINE_REAL(ret_type, func, ...) \ argument
283 typedef ret_type (*FUNC_TYPE(func))(__VA_ARGS__); \
285 FUNC_TYPE(func) PTR_TO_REAL(func); \
288 # define DEFINE_REAL(ret_type, func, ...) argument
294 // sanitizer_common/scripts/gen_dynamic_list.py to export func.
296 #define INTERCEPTOR(ret_type, func, ...) \ argument
297 extern "C"[[ gnu::alias(#func), gnu::visibility("hidden") ]] ret_type \
298 __interceptor_##func(__VA_ARGS__); \
299 extern "C" INTERCEPTOR_ATTRIBUTE ret_type func(__VA_ARGS__)
303 #define INTERCEPTOR(ret_type, func, ...) \ argument
304 DEFINE_REAL(ret_type, func, __VA_ARGS__) \
305 DECLARE_WRAPPER(ret_type, func, __VA_ARGS__) \
306 extern "C" INTERCEPTOR_ATTRIBUTE ret_type WRAP(func)(__VA_ARGS__)
308 // We don't need INTERCEPTOR_WITH_SUFFIX on non-Darwin for now.
309 #define INTERCEPTOR_WITH_SUFFIX(ret_type, func, ...) \ argument
310 INTERCEPTOR(ret_type, func, __VA_ARGS__)
314 #define INTERCEPTOR_ZZZ(suffix, ret_type, func, ...) \ argument
315 extern "C" ret_type func(__VA_ARGS__) suffix; \
316 extern "C" ret_type WRAP(func)(__VA_ARGS__); \
317 INTERPOSER(func); \
318 extern "C" INTERCEPTOR_ATTRIBUTE ret_type WRAP(func)(__VA_ARGS__)
320 #define INTERCEPTOR(ret_type, func, ...) \ argument
321 INTERCEPTOR_ZZZ(/*no symbol variants*/, ret_type, func, __VA_ARGS__)
323 #define INTERCEPTOR_WITH_SUFFIX(ret_type, func, ...) \ argument
324 INTERCEPTOR_ZZZ(__DARWIN_ALIAS_C(func), ret_type, func, __VA_ARGS__)
332 # define INTERCEPTOR_WINAPI(ret_type, func, ...) \ argument
333 typedef ret_type (__stdcall *FUNC_TYPE(func))(__VA_ARGS__); \
335 FUNC_TYPE(func) PTR_TO_REAL(func); \
337 extern "C" INTERCEPTOR_ATTRIBUTE ret_type __stdcall WRAP(func)(__VA_ARGS__)
340 // ISO C++ forbids casting between pointer-to-function and pointer-to-object,
342 // assuming that system is POSIX-compliant. Using other hacks seem
355 // However, -static-pie (which is not common) cannot be detected at link time.
371 # define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func) argument
372 # define INTERCEPT_FUNCTION_VER(func, symver) \ argument
373 INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver)
376 # define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_MAC(func) argument
377 # define INTERCEPT_FUNCTION_VER(func, symver) \ argument
378 INTERCEPT_FUNCTION_VER_MAC(func, symver)
381 # define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_WIN(func) argument
382 # define INTERCEPT_FUNCTION_VER(func, symver) \ argument
383 INTERCEPT_FUNCTION_VER_WIN(func, symver)