]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/sanitizer_common/sanitizer_win_weak_interception.h
MFV: r323381
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / sanitizer_common / sanitizer_win_weak_interception.h
1 //===-- sanitizer_win_weak_interception.h ---------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // This header provide helper macros to delegate calls of weak functions to the
10 // implementation in the main executable when a strong definition is present.
11 //===----------------------------------------------------------------------===//
12 #ifndef SANITIZER_WIN_WEAK_INTERCEPTION_H
13 #define SANITIZER_WIN_WEAK_INTERCEPTION_H
14 #include "sanitizer_internal_defs.h"
15
16 namespace __sanitizer {
17 int interceptWhenPossible(uptr dll_function, const char *real_function);
18 }
19
20 // ----------------- Function interception helper macros -------------------- //
21 // Weak functions, could be redefined in the main executable, but that is not
22 // necessary, so we shouldn't die if we can not find a reference.
23 #define INTERCEPT_WEAK(Name) interceptWhenPossible((uptr) Name, #Name);
24
25 #define INTERCEPT_SANITIZER_WEAK_FUNCTION(Name)                                \
26   static int intercept_##Name() {                                              \
27     return __sanitizer::interceptWhenPossible((__sanitizer::uptr) Name, #Name);\
28   }                                                                            \
29   __pragma(section(".WEAK$M", long, read))                                     \
30   __declspec(allocate(".WEAK$M")) int (*__weak_intercept_##Name)() =           \
31       intercept_##Name;
32
33 #endif // SANITIZER_WIN_WEAK_INTERCEPTION_H