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