blob: d3f774bede9f054fdfab5e530d145aee6bd4c78f [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
Kostya Serebryany04f2bf02014-02-24 08:37:41 +000015#if defined(__linux__) || defined(__FreeBSD__)
Alexey Samsonov8489f2a2012-02-08 19:52:01 +000016
17#if !defined(INCLUDED_FROM_INTERCEPTION_LIB)
Timur Iskhodzhanov3a32ed92012-02-22 08:56:25 +000018# error "interception_linux.h should be included from interception library only"
Alexey Samsonov8489f2a2012-02-08 19:52:01 +000019#endif
20
21#ifndef INTERCEPTION_LINUX_H
22#define INTERCEPTION_LINUX_H
23
24namespace __interception {
25// returns true if a function with the given name was found.
Alexey Samsonov0f840bd2012-08-02 11:19:13 +000026bool GetRealFunctionAddress(const char *func_name, uptr *func_addr,
27 uptr real, uptr wrapper);
Dmitry Vyukov3a6c7ce2013-09-02 18:06:28 +000028void *GetFuncAddrVer(const char *func_name, const char *ver);
Alexey Samsonov8489f2a2012-02-08 19:52:01 +000029} // namespace __interception
30
Kostya Serebryany04f2bf02014-02-24 08:37:41 +000031#define INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func) \
Evgeniy Stepanov66297ca2013-12-20 12:20:15 +000032 ::__interception::GetRealFunctionAddress( \
33 #func, (::__interception::uptr *)&__interception::PTR_TO_REAL(func), \
34 (::__interception::uptr) & (func), \
35 (::__interception::uptr) & WRAP(func))
Alexey Samsonov8489f2a2012-02-08 19:52:01 +000036
Dmitry Vyukov23b80ab2013-09-03 07:53:49 +000037#if !defined(__ANDROID__) // android does not have dlvsym
Kostya Serebryany04f2bf02014-02-24 08:37:41 +000038# define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \
Alexey Samsonovedecc382013-10-16 08:20:31 +000039 ::__interception::real_##func = (func##_f)(unsigned long) \
Evgeniy Stepanov90e12a62013-11-12 10:21:52 +000040 ::__interception::GetFuncAddrVer(#func, symver)
Alexey Samsonovedecc382013-10-16 08:20:31 +000041#else
Kostya Serebryany04f2bf02014-02-24 08:37:41 +000042# define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \
43 INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func)
Dmitry Vyukov23b80ab2013-09-03 07:53:49 +000044#endif // !defined(__ANDROID__)
Dmitry Vyukov3a6c7ce2013-09-02 18:06:28 +000045
Alexey Samsonov8489f2a2012-02-08 19:52:01 +000046#endif // INTERCEPTION_LINUX_H
Kostya Serebryany04f2bf02014-02-24 08:37:41 +000047#endif // __linux__ || __FreeBSD__