111
|
1 //===-- sanitizer_win_weak_interception.h ---------------------------------===//
|
|
2 //
|
145
|
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
|
111
|
6 //
|
|
7 //===----------------------------------------------------------------------===//
|
|
8 // This header provide helper macros to delegate calls of weak functions to the
|
|
9 // implementation in the main executable when a strong definition is present.
|
|
10 //===----------------------------------------------------------------------===//
|
|
11 #ifndef SANITIZER_WIN_WEAK_INTERCEPTION_H
|
|
12 #define SANITIZER_WIN_WEAK_INTERCEPTION_H
|
|
13 #include "sanitizer_internal_defs.h"
|
|
14
|
|
15 namespace __sanitizer {
|
|
16 int interceptWhenPossible(uptr dll_function, const char *real_function);
|
|
17 }
|
|
18
|
|
19 // ----------------- Function interception helper macros -------------------- //
|
|
20 // Weak functions, could be redefined in the main executable, but that is not
|
|
21 // necessary, so we shouldn't die if we can not find a reference.
|
|
22 #define INTERCEPT_WEAK(Name) interceptWhenPossible((uptr) Name, #Name);
|
|
23
|
|
24 #define INTERCEPT_SANITIZER_WEAK_FUNCTION(Name) \
|
|
25 static int intercept_##Name() { \
|
|
26 return __sanitizer::interceptWhenPossible((__sanitizer::uptr) Name, #Name);\
|
|
27 } \
|
|
28 __pragma(section(".WEAK$M", long, read)) \
|
|
29 __declspec(allocate(".WEAK$M")) int (*__weak_intercept_##Name)() = \
|
|
30 intercept_##Name;
|
|
31
|
|
32 #endif // SANITIZER_WIN_WEAK_INTERCEPTION_H
|