]>
Commit | Line | Data |
---|---|---|
549e2197 | 1 | //===-- interception_linux.h ------------------------------------*- C++ -*-===// |
2 | // | |
2fc4da48 | 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 | |
549e2197 | 6 | // |
7 | //===----------------------------------------------------------------------===// | |
8 | // | |
9 | // This file is a part of AddressSanitizer, an address sanity checker. | |
10 | // | |
11 | // Windows-specific interception methods. | |
12 | //===----------------------------------------------------------------------===// | |
13 | ||
d2ef4bee | 14 | #if SANITIZER_WINDOWS |
549e2197 | 15 | |
16 | #if !defined(INCLUDED_FROM_INTERCEPTION_LIB) | |
17 | # error "interception_win.h should be included from interception library only" | |
18 | #endif | |
19 | ||
20 | #ifndef INTERCEPTION_WIN_H | |
21 | #define INTERCEPTION_WIN_H | |
22 | ||
23 | namespace __interception { | |
a9586c9c | 24 | // All the functions in the OverrideFunction() family return true on success, |
25 | // false on failure (including "couldn't find the function"). | |
549e2197 | 26 | |
a9586c9c | 27 | // Overrides a function by its address. |
28 | bool OverrideFunction(uptr old_func, uptr new_func, uptr *orig_old_func = 0); | |
29 | ||
30 | // Overrides a function in a system DLL or DLL CRT by its exported name. | |
31 | bool OverrideFunction(const char *name, uptr new_func, uptr *orig_old_func = 0); | |
5645a48f | 32 | |
33 | // Windows-only replacement for GetProcAddress. Useful for some sanitizers. | |
34 | uptr InternalGetProcAddress(void *module, const char *func_name); | |
35 | ||
23e39437 | 36 | // Overrides a function only when it is called from a specific DLL. For example, |
37 | // this is used to override calls to HeapAlloc/HeapFree from ucrtbase without | |
38 | // affecting other third party libraries. | |
39 | bool OverrideImportedFunction(const char *module_to_patch, | |
40 | const char *imported_module, | |
41 | const char *function_name, uptr new_function, | |
42 | uptr *orig_old_func); | |
43 | ||
44 | #if !SANITIZER_WINDOWS64 | |
45 | // Exposed for unittests | |
46 | bool OverrideFunctionWithDetour( | |
47 | uptr old_func, uptr new_func, uptr *orig_old_func); | |
48 | #endif | |
49 | ||
50 | // Exposed for unittests | |
51 | bool OverrideFunctionWithRedirectJump( | |
52 | uptr old_func, uptr new_func, uptr *orig_old_func); | |
53 | bool OverrideFunctionWithHotPatch( | |
54 | uptr old_func, uptr new_func, uptr *orig_old_func); | |
55 | bool OverrideFunctionWithTrampoline( | |
56 | uptr old_func, uptr new_func, uptr *orig_old_func); | |
57 | ||
58 | // Exposed for unittests | |
59 | void TestOnlyReleaseTrampolineRegions(); | |
60 | ||
549e2197 | 61 | } // namespace __interception |
62 | ||
a9586c9c | 63 | #if defined(INTERCEPTION_DYNAMIC_CRT) |
64 | #define INTERCEPT_FUNCTION_WIN(func) \ | |
65 | ::__interception::OverrideFunction(#func, \ | |
66 | (::__interception::uptr)WRAP(func), \ | |
67 | (::__interception::uptr *)&REAL(func)) | |
549e2197 | 68 | #else |
a9586c9c | 69 | #define INTERCEPT_FUNCTION_WIN(func) \ |
70 | ::__interception::OverrideFunction((::__interception::uptr)func, \ | |
71 | (::__interception::uptr)WRAP(func), \ | |
72 | (::__interception::uptr *)&REAL(func)) | |
549e2197 | 73 | #endif |
74 | ||
a9586c9c | 75 | #define INTERCEPT_FUNCTION_VER_WIN(func, symver) INTERCEPT_FUNCTION_WIN(func) |
4fc7b5ac | 76 | |
23e39437 | 77 | #define INTERCEPT_FUNCTION_DLLIMPORT(user_dll, provider_dll, func) \ |
78 | ::__interception::OverrideImportedFunction( \ | |
79 | user_dll, provider_dll, #func, (::__interception::uptr)WRAP(func), \ | |
80 | (::__interception::uptr *)&REAL(func)) | |
81 | ||
549e2197 | 82 | #endif // INTERCEPTION_WIN_H |
d2ef4bee | 83 | #endif // SANITIZER_WINDOWS |