interception_linux.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //===-- interception_linux.h ------------------------------------*- C++ -*-===//
  2. //
  3. // This file is distributed under the University of Illinois Open Source
  4. // License. See LICENSE.TXT for details.
  5. //
  6. //===----------------------------------------------------------------------===//
  7. //
  8. // This file is a part of AddressSanitizer, an address sanity checker.
  9. //
  10. // Linux-specific interception methods.
  11. //===----------------------------------------------------------------------===//
  12. #if defined(__linux__) || defined(__FreeBSD__)
  13. #if !defined(INCLUDED_FROM_INTERCEPTION_LIB)
  14. # error "interception_linux.h should be included from interception library only"
  15. #endif
  16. #ifndef INTERCEPTION_LINUX_H
  17. #define INTERCEPTION_LINUX_H
  18. namespace __interception {
  19. // returns true if a function with the given name was found.
  20. bool GetRealFunctionAddress(const char *func_name, uptr *func_addr,
  21. uptr real, uptr wrapper);
  22. void *GetFuncAddrVer(const char *func_name, const char *ver);
  23. } // namespace __interception
  24. #define INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func) \
  25. ::__interception::GetRealFunctionAddress( \
  26. #func, (::__interception::uptr *)&__interception::PTR_TO_REAL(func), \
  27. (::__interception::uptr) & (func), \
  28. (::__interception::uptr) & WRAP(func))
  29. #if !defined(__ANDROID__) // android does not have dlvsym
  30. # define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \
  31. ::__interception::real_##func = (func##_f)(unsigned long) \
  32. ::__interception::GetFuncAddrVer(#func, symver)
  33. #else
  34. # define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \
  35. INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func)
  36. #endif // !defined(__ANDROID__)
  37. #endif // INTERCEPTION_LINUX_H
  38. #endif // __linux__ || __FreeBSD__