56 lines · c
1//===-- interception_linux.h ------------------------------------*- C++ -*-===//2//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-exception6//7//===----------------------------------------------------------------------===//8//9// This file is a part of AddressSanitizer, an address sanity checker.10//11// Linux-specific interception methods.12//===----------------------------------------------------------------------===//13 14#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \15 SANITIZER_SOLARIS || SANITIZER_HAIKU16 17#if !defined(INCLUDED_FROM_INTERCEPTION_LIB)18# error interception_linux.h should be included from interception library only19#endif20 21#ifndef INTERCEPTION_LINUX_H22#define INTERCEPTION_LINUX_H23 24namespace __interception {25bool InterceptFunction(const char *name, uptr *ptr_to_real, uptr func,26 uptr trampoline);27bool InterceptFunction(const char *name, const char *ver, uptr *ptr_to_real,28 uptr func, uptr trampoline);29} // namespace __interception30 31// Cast func to type of REAL(func) before casting to uptr in case it is an32// overloaded function, which is the case for some glibc functions when33// _FORTIFY_SOURCE is used. This disambiguates which overload to use.34#define INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func) \35 ::__interception::InterceptFunction( \36 #func, (::__interception::uptr *)&REAL(func), \37 (::__interception::uptr)(decltype(REAL(func)))&(func), \38 (::__interception::uptr) &TRAMPOLINE(func))39 40// dlvsym is a GNU extension supported by some other platforms.41#if SANITIZER_GLIBC || SANITIZER_FREEBSD || SANITIZER_NETBSD42#define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \43 ::__interception::InterceptFunction( \44 #func, symver, \45 (::__interception::uptr *)&REAL(func), \46 (::__interception::uptr)(decltype(REAL(func)))&(func), \47 (::__interception::uptr)&TRAMPOLINE(func))48#else49#define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \50 INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func)51#endif // SANITIZER_GLIBC || SANITIZER_FREEBSD || SANITIZER_NETBSD52 53#endif // INTERCEPTION_LINUX_H54#endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD ||55 // SANITIZER_SOLARIS || SANITIZER_HAIKU56