annotate libsanitizer/interception/interception_win.h @ 144:8f4e72ab4e11

fix segmentation fault caused by nothing next cur_op to end
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 21:23:56 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 //===-- interception_linux.h ------------------------------------*- C++ -*-===//
kono
parents:
diff changeset
2 //
kono
parents:
diff changeset
3 // This file is distributed under the University of Illinois Open Source
kono
parents:
diff changeset
4 // License. See LICENSE.TXT for details.
kono
parents:
diff changeset
5 //
kono
parents:
diff changeset
6 //===----------------------------------------------------------------------===//
kono
parents:
diff changeset
7 //
kono
parents:
diff changeset
8 // This file is a part of AddressSanitizer, an address sanity checker.
kono
parents:
diff changeset
9 //
kono
parents:
diff changeset
10 // Windows-specific interception methods.
kono
parents:
diff changeset
11 //===----------------------------------------------------------------------===//
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 #ifdef _WIN32
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 #if !defined(INCLUDED_FROM_INTERCEPTION_LIB)
kono
parents:
diff changeset
16 # error "interception_win.h should be included from interception library only"
kono
parents:
diff changeset
17 #endif
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 #ifndef INTERCEPTION_WIN_H
kono
parents:
diff changeset
20 #define INTERCEPTION_WIN_H
kono
parents:
diff changeset
21
kono
parents:
diff changeset
22 namespace __interception {
kono
parents:
diff changeset
23 // All the functions in the OverrideFunction() family return true on success,
kono
parents:
diff changeset
24 // false on failure (including "couldn't find the function").
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 // Overrides a function by its address.
kono
parents:
diff changeset
27 bool OverrideFunction(uptr old_func, uptr new_func, uptr *orig_old_func = 0);
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 // Overrides a function in a system DLL or DLL CRT by its exported name.
kono
parents:
diff changeset
30 bool OverrideFunction(const char *name, uptr new_func, uptr *orig_old_func = 0);
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 // Windows-only replacement for GetProcAddress. Useful for some sanitizers.
kono
parents:
diff changeset
33 uptr InternalGetProcAddress(void *module, const char *func_name);
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 // Overrides a function only when it is called from a specific DLL. For example,
kono
parents:
diff changeset
36 // this is used to override calls to HeapAlloc/HeapFree from ucrtbase without
kono
parents:
diff changeset
37 // affecting other third party libraries.
kono
parents:
diff changeset
38 bool OverrideImportedFunction(const char *module_to_patch,
kono
parents:
diff changeset
39 const char *imported_module,
kono
parents:
diff changeset
40 const char *function_name, uptr new_function,
kono
parents:
diff changeset
41 uptr *orig_old_func);
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 #if !SANITIZER_WINDOWS64
kono
parents:
diff changeset
44 // Exposed for unittests
kono
parents:
diff changeset
45 bool OverrideFunctionWithDetour(
kono
parents:
diff changeset
46 uptr old_func, uptr new_func, uptr *orig_old_func);
kono
parents:
diff changeset
47 #endif
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 // Exposed for unittests
kono
parents:
diff changeset
50 bool OverrideFunctionWithRedirectJump(
kono
parents:
diff changeset
51 uptr old_func, uptr new_func, uptr *orig_old_func);
kono
parents:
diff changeset
52 bool OverrideFunctionWithHotPatch(
kono
parents:
diff changeset
53 uptr old_func, uptr new_func, uptr *orig_old_func);
kono
parents:
diff changeset
54 bool OverrideFunctionWithTrampoline(
kono
parents:
diff changeset
55 uptr old_func, uptr new_func, uptr *orig_old_func);
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 // Exposed for unittests
kono
parents:
diff changeset
58 void TestOnlyReleaseTrampolineRegions();
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 } // namespace __interception
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 #if defined(INTERCEPTION_DYNAMIC_CRT)
kono
parents:
diff changeset
63 #define INTERCEPT_FUNCTION_WIN(func) \
kono
parents:
diff changeset
64 ::__interception::OverrideFunction(#func, \
kono
parents:
diff changeset
65 (::__interception::uptr)WRAP(func), \
kono
parents:
diff changeset
66 (::__interception::uptr *)&REAL(func))
kono
parents:
diff changeset
67 #else
kono
parents:
diff changeset
68 #define INTERCEPT_FUNCTION_WIN(func) \
kono
parents:
diff changeset
69 ::__interception::OverrideFunction((::__interception::uptr)func, \
kono
parents:
diff changeset
70 (::__interception::uptr)WRAP(func), \
kono
parents:
diff changeset
71 (::__interception::uptr *)&REAL(func))
kono
parents:
diff changeset
72 #endif
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 #define INTERCEPT_FUNCTION_VER_WIN(func, symver) INTERCEPT_FUNCTION_WIN(func)
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 #define INTERCEPT_FUNCTION_DLLIMPORT(user_dll, provider_dll, func) \
kono
parents:
diff changeset
77 ::__interception::OverrideImportedFunction( \
kono
parents:
diff changeset
78 user_dll, provider_dll, #func, (::__interception::uptr)WRAP(func), \
kono
parents:
diff changeset
79 (::__interception::uptr *)&REAL(func))
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 #endif // INTERCEPTION_WIN_H
kono
parents:
diff changeset
82 #endif // _WIN32