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-exception 6 // 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_OPENBSD || SANITIZER_SOLARIS 16 17 #if !defined(INCLUDED_FROM_INTERCEPTION_LIB) 18 # error "interception_linux.h should be included from interception library only" 19 #endif 20 21 #ifndef INTERCEPTION_LINUX_H 22 #define INTERCEPTION_LINUX_H 23 24 namespace __interception { 25 // returns true if a function with the given name was found. 26 bool GetRealFunctionAddress(const char *func_name, uptr *func_addr, 27 uptr real, uptr wrapper); 28 void *GetFuncAddrVer(const char *func_name, const char *ver); 29 } // namespace __interception 30 31 #define INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func) \ 32 ::__interception::GetRealFunctionAddress( \ 33 #func, (::__interception::uptr *)&__interception::PTR_TO_REAL(func), \ 34 (::__interception::uptr) & (func), \ 35 (::__interception::uptr) & WRAP(func)) 36 37 // Android, Solaris and OpenBSD do not have dlvsym 38 #if !SANITIZER_ANDROID && !SANITIZER_SOLARIS && !SANITIZER_OPENBSD 39 #define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \ 40 (::__interception::real_##func = (func##_type)( \ 41 unsigned long)::__interception::GetFuncAddrVer(#func, symver)) 42 #else 43 #define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \ 44 INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func) 45 #endif // !SANITIZER_ANDROID && !SANITIZER_SOLARIS 46 47 #endif // INTERCEPTION_LINUX_H 48 #endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || 49 // SANITIZER_OPENBSD || SANITIZER_SOLARIS 50