15b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov//===-- interception_linux.h ------------------------------------*- C++ -*-===// 25b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov// 35b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov// The LLVM Compiler Infrastructure 45b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov// 55b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov// This file is distributed under the University of Illinois Open Source 65b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov// License. See LICENSE.TXT for details. 75b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov// 85b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov//===----------------------------------------------------------------------===// 95b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov// 105b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov// This file is a part of AddressSanitizer, an address sanity checker. 115b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov// 125b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov// Linux-specific interception methods. 135b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov//===----------------------------------------------------------------------===// 145b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov 152d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines#if defined(__linux__) || defined(__FreeBSD__) 165b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov 175b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov#if !defined(INCLUDED_FROM_INTERCEPTION_LIB) 18e6b9ebba53038ac4d1e2377ebdd15359c28368cbTimur Iskhodzhanov# error "interception_linux.h should be included from interception library only" 195b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov#endif 205b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov 215b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov#ifndef INTERCEPTION_LINUX_H 225b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov#define INTERCEPTION_LINUX_H 235b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov 245b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonovnamespace __interception { 255b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov// returns true if a function with the given name was found. 26592d3f707e02968c75fd6e90d06d24f5df99c8b9Alexey Samsonovbool GetRealFunctionAddress(const char *func_name, uptr *func_addr, 27592d3f707e02968c75fd6e90d06d24f5df99c8b9Alexey Samsonov uptr real, uptr wrapper); 28f061554e8bbfad5e29dcd9e81feb725b75869fa0Dmitry Vyukovvoid *GetFuncAddrVer(const char *func_name, const char *ver); 295b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov} // namespace __interception 305b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov 312d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines#define INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func) \ 322d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines ::__interception::GetRealFunctionAddress( \ 332d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines #func, (::__interception::uptr *)&__interception::PTR_TO_REAL(func), \ 342d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines (::__interception::uptr) & (func), \ 352d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines (::__interception::uptr) & WRAP(func)) 365b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov 372f913eef5770968386515855529e9b6244df1247Dmitry Vyukov#if !defined(__ANDROID__) // android does not have dlvsym 382d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines# define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \ 395e2d3776a314629680921abd1d55d89d95a2da90Alexey Samsonov ::__interception::real_##func = (func##_f)(unsigned long) \ 400797ff48ae6a585382b6ff8bda98dfa72874e4d0Evgeniy Stepanov ::__interception::GetFuncAddrVer(#func, symver) 415e2d3776a314629680921abd1d55d89d95a2da90Alexey Samsonov#else 422d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines# define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \ 432d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func) 442f913eef5770968386515855529e9b6244df1247Dmitry Vyukov#endif // !defined(__ANDROID__) 45f061554e8bbfad5e29dcd9e81feb725b75869fa0Dmitry Vyukov 465b29018cf422e7711fb760b733c32127397a43fcAlexey Samsonov#endif // INTERCEPTION_LINUX_H 472d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines#endif // __linux__ || __FreeBSD__ 48