asan_interceptors.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //===-- asan_interceptors.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. // ASan-private header for asan_interceptors.cc
  11. //===----------------------------------------------------------------------===//
  12. #ifndef ASAN_INTERCEPTORS_H
  13. #define ASAN_INTERCEPTORS_H
  14. #include "asan_internal.h"
  15. #include "sanitizer_common/sanitizer_interception.h"
  16. #include "sanitizer_common/sanitizer_platform_interceptors.h"
  17. // Use macro to describe if specific function should be
  18. // intercepted on a given platform.
  19. #if !SANITIZER_WINDOWS
  20. # define ASAN_INTERCEPT_ATOLL_AND_STRTOLL 1
  21. # define ASAN_INTERCEPT__LONGJMP 1
  22. # define ASAN_INTERCEPT_STRDUP 1
  23. # define ASAN_INTERCEPT_INDEX 1
  24. # define ASAN_INTERCEPT_PTHREAD_CREATE 1
  25. # define ASAN_INTERCEPT_FORK 1
  26. #else
  27. # define ASAN_INTERCEPT_ATOLL_AND_STRTOLL 0
  28. # define ASAN_INTERCEPT__LONGJMP 0
  29. # define ASAN_INTERCEPT_STRDUP 0
  30. # define ASAN_INTERCEPT_INDEX 0
  31. # define ASAN_INTERCEPT_PTHREAD_CREATE 0
  32. # define ASAN_INTERCEPT_FORK 0
  33. #endif
  34. #if SANITIZER_FREEBSD || SANITIZER_LINUX
  35. # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 1
  36. #else
  37. # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 0
  38. #endif
  39. #if !SANITIZER_MAC
  40. # define ASAN_INTERCEPT_STRNLEN 1
  41. #else
  42. # define ASAN_INTERCEPT_STRNLEN 0
  43. #endif
  44. #if SANITIZER_LINUX && !SANITIZER_ANDROID
  45. # define ASAN_INTERCEPT_SWAPCONTEXT 1
  46. #else
  47. # define ASAN_INTERCEPT_SWAPCONTEXT 0
  48. #endif
  49. #if !SANITIZER_WINDOWS
  50. # define ASAN_INTERCEPT_SIGNAL_AND_SIGACTION 1
  51. #else
  52. # define ASAN_INTERCEPT_SIGNAL_AND_SIGACTION 0
  53. #endif
  54. #if !SANITIZER_WINDOWS
  55. # define ASAN_INTERCEPT_SIGLONGJMP 1
  56. #else
  57. # define ASAN_INTERCEPT_SIGLONGJMP 0
  58. #endif
  59. // Android bug: https://code.google.com/p/android/issues/detail?id=61799
  60. #if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && \
  61. !(SANITIZER_ANDROID && defined(__i386))
  62. # define ASAN_INTERCEPT___CXA_THROW 1
  63. #else
  64. # define ASAN_INTERCEPT___CXA_THROW 0
  65. #endif
  66. #if !SANITIZER_WINDOWS
  67. # define ASAN_INTERCEPT___CXA_ATEXIT 1
  68. #else
  69. # define ASAN_INTERCEPT___CXA_ATEXIT 0
  70. #endif
  71. DECLARE_REAL(int, memcmp, const void *a1, const void *a2, uptr size)
  72. DECLARE_REAL(void*, memcpy, void *to, const void *from, uptr size)
  73. DECLARE_REAL(void*, memset, void *block, int c, uptr size)
  74. DECLARE_REAL(char*, strchr, const char *str, int c)
  75. DECLARE_REAL(SIZE_T, strlen, const char *s)
  76. DECLARE_REAL(char*, strncpy, char *to, const char *from, uptr size)
  77. DECLARE_REAL(uptr, strnlen, const char *s, uptr maxlen)
  78. DECLARE_REAL(char*, strstr, const char *s1, const char *s2)
  79. struct sigaction;
  80. DECLARE_REAL(int, sigaction, int signum, const struct sigaction *act,
  81. struct sigaction *oldact)
  82. namespace __asan {
  83. void InitializeAsanInterceptors();
  84. #define ENSURE_ASAN_INITED() do { \
  85. CHECK(!asan_init_is_running); \
  86. if (UNLIKELY(!asan_inited)) { \
  87. AsanInitFromRtl(); \
  88. } \
  89. } while (0)
  90. } // namespace __asan
  91. #endif // ASAN_INTERCEPTORS_H