Path: blob/main/contrib/llvm-project/compiler-rt/lib/interception/interception_win.h
35262 views
//===-- interception_linux.h ------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of AddressSanitizer, an address sanity checker.9//10// Windows-specific interception methods.11//===----------------------------------------------------------------------===//1213#if SANITIZER_WINDOWS1415#if !defined(INCLUDED_FROM_INTERCEPTION_LIB)16# error "interception_win.h should be included from interception library only"17#endif1819#ifndef INTERCEPTION_WIN_H20#define INTERCEPTION_WIN_H2122namespace __interception {23// All the functions in the OverrideFunction() family return true on success,24// false on failure (including "couldn't find the function").2526// Overrides a function by its address.27bool OverrideFunction(uptr old_func, uptr new_func, uptr *orig_old_func = 0);2829// Overrides a function in a system DLL or DLL CRT by its exported name.30bool OverrideFunction(const char *name, uptr new_func, uptr *orig_old_func = 0);3132// Windows-only replacement for GetProcAddress. Useful for some sanitizers.33uptr InternalGetProcAddress(void *module, const char *func_name);3435// Overrides a function only when it is called from a specific DLL. For example,36// this is used to override calls to HeapAlloc/HeapFree from ucrtbase without37// affecting other third party libraries.38bool OverrideImportedFunction(const char *module_to_patch,39const char *imported_module,40const char *function_name, uptr new_function,41uptr *orig_old_func);4243// Sets a callback to be used for reporting errors by interception_win. The44// callback will be called with printf-like arguments. Intended to be used with45// __sanitizer::Report. Pass nullptr to disable error reporting (default).46void SetErrorReportCallback(void (*callback)(const char *format, ...));4748#if !SANITIZER_WINDOWS6449// Exposed for unittests50bool OverrideFunctionWithDetour(51uptr old_func, uptr new_func, uptr *orig_old_func);52#endif5354// Exposed for unittests55bool OverrideFunctionWithRedirectJump(56uptr old_func, uptr new_func, uptr *orig_old_func);57bool OverrideFunctionWithHotPatch(58uptr old_func, uptr new_func, uptr *orig_old_func);59bool OverrideFunctionWithTrampoline(60uptr old_func, uptr new_func, uptr *orig_old_func);6162// Exposed for unittests63void TestOnlyReleaseTrampolineRegions();6465} // namespace __interception6667#if defined(INTERCEPTION_DYNAMIC_CRT)68#define INTERCEPT_FUNCTION_WIN(func) \69::__interception::OverrideFunction(#func, \70(::__interception::uptr)WRAP(func), \71(::__interception::uptr *)&REAL(func))72#else73#define INTERCEPT_FUNCTION_WIN(func) \74::__interception::OverrideFunction((::__interception::uptr)func, \75(::__interception::uptr)WRAP(func), \76(::__interception::uptr *)&REAL(func))77#endif7879#define INTERCEPT_FUNCTION_VER_WIN(func, symver) INTERCEPT_FUNCTION_WIN(func)8081#define INTERCEPT_FUNCTION_DLLIMPORT(user_dll, provider_dll, func) \82::__interception::OverrideImportedFunction( \83user_dll, provider_dll, #func, (::__interception::uptr)WRAP(func), \84(::__interception::uptr *)&REAL(func))8586#endif // INTERCEPTION_WIN_H87#endif // SANITIZER_WINDOWS888990