blob: 765a186e58232d4fde3fd815d513222338fd0042 [file] [log] [blame]
Alexey Samsonov8489f2a2012-02-08 19:52:01 +00001//===-- 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// Linux-specific interception methods.
13//===----------------------------------------------------------------------===//
14
Kamil Rytarowski271018d2017-12-14 20:14:29 +000015#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
Kamil Rytarowski7e552452018-03-02 07:32:30 +000016 SANITIZER_OPENBSD || SANITIZER_SOLARIS
Alexey Samsonov8489f2a2012-02-08 19:52:01 +000017
18#if !defined(INCLUDED_FROM_INTERCEPTION_LIB)
Timur Iskhodzhanov3a32ed92012-02-22 08:56:25 +000019# error "interception_linux.h should be included from interception library only"
Alexey Samsonov8489f2a2012-02-08 19:52:01 +000020#endif
21
22#ifndef INTERCEPTION_LINUX_H
23#define INTERCEPTION_LINUX_H
24
25namespace __interception {
26// returns true if a function with the given name was found.
Alexey Samsonov0f840bd2012-08-02 11:19:13 +000027bool GetRealFunctionAddress(const char *func_name, uptr *func_addr,
28 uptr real, uptr wrapper);
Dmitry Vyukov3a6c7ce2013-09-02 18:06:28 +000029void *GetFuncAddrVer(const char *func_name, const char *ver);
Alexey Samsonov8489f2a2012-02-08 19:52:01 +000030} // namespace __interception
31
Kostya Serebryany04f2bf02014-02-24 08:37:41 +000032#define INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func) \
Evgeniy Stepanov66297ca2013-12-20 12:20:15 +000033 ::__interception::GetRealFunctionAddress( \
34 #func, (::__interception::uptr *)&__interception::PTR_TO_REAL(func), \
35 (::__interception::uptr) & (func), \
36 (::__interception::uptr) & WRAP(func))
Alexey Samsonov8489f2a2012-02-08 19:52:01 +000037
Kamil Rytarowski7e552452018-03-02 07:32:30 +000038// Android, Solaris and OpenBSD do not have dlvsym
39#if !SANITIZER_ANDROID && !SANITIZER_SOLARIS && !SANITIZER_OPENBSD
Evgeniy Stepanov9147de02015-09-22 21:34:44 +000040#define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \
Kuba Mracek975352c2018-10-22 20:54:48 +000041 (::__interception::real_##func = (func##_type)( \
Evgeniy Stepanov9147de02015-09-22 21:34:44 +000042 unsigned long)::__interception::GetFuncAddrVer(#func, symver))
Alexey Samsonovedecc382013-10-16 08:20:31 +000043#else
Evgeniy Stepanov9147de02015-09-22 21:34:44 +000044#define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \
45 INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func)
Kamil Rytarowski271018d2017-12-14 20:14:29 +000046#endif // !SANITIZER_ANDROID && !SANITIZER_SOLARIS
Dmitry Vyukov3a6c7ce2013-09-02 18:06:28 +000047
Alexey Samsonov8489f2a2012-02-08 19:52:01 +000048#endif // INTERCEPTION_LINUX_H
Kamil Rytarowski271018d2017-12-14 20:14:29 +000049#endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD ||
Kamil Rytarowski7e552452018-03-02 07:32:30 +000050 // SANITIZER_OPENBSD || SANITIZER_SOLARIS