Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 1 | //===-- asan_interceptors.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 | // ASan-private header for asan_interceptors.cc |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | #ifndef ASAN_INTERCEPTORS_H |
| 15 | #define ASAN_INTERCEPTORS_H |
| 16 | |
| 17 | #include "asan_internal.h" |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 18 | #include "interception/interception.h" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 19 | #include "sanitizer_common/sanitizer_platform_interceptors.h" |
| 20 | |
| 21 | // Use macro to describe if specific function should be |
| 22 | // intercepted on a given platform. |
| 23 | #if !SANITIZER_WINDOWS |
| 24 | # define ASAN_INTERCEPT_ATOLL_AND_STRTOLL 1 |
| 25 | # define ASAN_INTERCEPT__LONGJMP 1 |
| 26 | # define ASAN_INTERCEPT_STRDUP 1 |
| 27 | # define ASAN_INTERCEPT_INDEX 1 |
| 28 | # define ASAN_INTERCEPT_PTHREAD_CREATE 1 |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 29 | # define ASAN_INTERCEPT_FORK 1 |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 30 | #else |
| 31 | # define ASAN_INTERCEPT_ATOLL_AND_STRTOLL 0 |
| 32 | # define ASAN_INTERCEPT__LONGJMP 0 |
| 33 | # define ASAN_INTERCEPT_STRDUP 0 |
| 34 | # define ASAN_INTERCEPT_INDEX 0 |
| 35 | # define ASAN_INTERCEPT_PTHREAD_CREATE 0 |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 36 | # define ASAN_INTERCEPT_FORK 0 |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 37 | #endif |
| 38 | |
| 39 | #if SANITIZER_FREEBSD || SANITIZER_LINUX |
| 40 | # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 1 |
| 41 | #else |
| 42 | # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 0 |
| 43 | #endif |
| 44 | |
| 45 | #if !SANITIZER_MAC |
| 46 | # define ASAN_INTERCEPT_STRNLEN 1 |
| 47 | #else |
| 48 | # define ASAN_INTERCEPT_STRNLEN 0 |
| 49 | #endif |
| 50 | |
| 51 | #if SANITIZER_LINUX && !SANITIZER_ANDROID |
| 52 | # define ASAN_INTERCEPT_SWAPCONTEXT 1 |
| 53 | #else |
| 54 | # define ASAN_INTERCEPT_SWAPCONTEXT 0 |
| 55 | #endif |
| 56 | |
| 57 | #if !SANITIZER_WINDOWS |
| 58 | # define ASAN_INTERCEPT_SIGNAL_AND_SIGACTION 1 |
| 59 | #else |
| 60 | # define ASAN_INTERCEPT_SIGNAL_AND_SIGACTION 0 |
| 61 | #endif |
| 62 | |
| 63 | #if !SANITIZER_WINDOWS |
| 64 | # define ASAN_INTERCEPT_SIGLONGJMP 1 |
| 65 | #else |
| 66 | # define ASAN_INTERCEPT_SIGLONGJMP 0 |
| 67 | #endif |
| 68 | |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 69 | // Android bug: https://code.google.com/p/android/issues/detail?id=61799 |
| 70 | #if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && \ |
| 71 | !(SANITIZER_ANDROID && defined(__i386)) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 72 | # define ASAN_INTERCEPT___CXA_THROW 1 |
| 73 | #else |
| 74 | # define ASAN_INTERCEPT___CXA_THROW 0 |
| 75 | #endif |
| 76 | |
| 77 | #if !SANITIZER_WINDOWS |
| 78 | # define ASAN_INTERCEPT___CXA_ATEXIT 1 |
| 79 | #else |
| 80 | # define ASAN_INTERCEPT___CXA_ATEXIT 0 |
| 81 | #endif |
Alexey Samsonov | f2598fc | 2012-02-02 10:39:40 +0000 | [diff] [blame] | 82 | |
Chandler Carruth | 6bae39d | 2012-06-25 06:53:10 +0000 | [diff] [blame] | 83 | DECLARE_REAL(int, memcmp, const void *a1, const void *a2, uptr size) |
| 84 | DECLARE_REAL(void*, memcpy, void *to, const void *from, uptr size) |
| 85 | DECLARE_REAL(void*, memset, void *block, int c, uptr size) |
| 86 | DECLARE_REAL(char*, strchr, const char *str, int c) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 87 | DECLARE_REAL(SIZE_T, strlen, const char *s) |
Chandler Carruth | 6bae39d | 2012-06-25 06:53:10 +0000 | [diff] [blame] | 88 | DECLARE_REAL(char*, strncpy, char *to, const char *from, uptr size) |
| 89 | DECLARE_REAL(uptr, strnlen, const char *s, uptr maxlen) |
Alexander Potapenko | eb8c46e | 2012-08-24 09:22:05 +0000 | [diff] [blame] | 90 | DECLARE_REAL(char*, strstr, const char *s1, const char *s2) |
Alexey Samsonov | da13ba8 | 2012-02-16 17:00:45 +0000 | [diff] [blame] | 91 | struct sigaction; |
| 92 | DECLARE_REAL(int, sigaction, int signum, const struct sigaction *act, |
Chandler Carruth | 6bae39d | 2012-06-25 06:53:10 +0000 | [diff] [blame] | 93 | struct sigaction *oldact) |
Alexey Samsonov | 3389b8e | 2012-01-30 13:42:44 +0000 | [diff] [blame] | 94 | |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 95 | #if !SANITIZER_MAC |
| 96 | #define ASAN_INTERCEPT_FUNC(name) \ |
| 97 | do { \ |
| 98 | if ((!INTERCEPT_FUNCTION(name) || !REAL(name))) \ |
| 99 | VReport(1, "AddressSanitizer: failed to intercept '" #name "'\n"); \ |
| 100 | } while (0) |
| 101 | #else |
| 102 | // OS X interceptors don't need to be initialized with INTERCEPT_FUNCTION. |
| 103 | #define ASAN_INTERCEPT_FUNC(name) |
| 104 | #endif // SANITIZER_MAC |
| 105 | |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 106 | namespace __asan { |
| 107 | |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 108 | void InitializeAsanInterceptors(); |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 109 | void InitializePlatformInterceptors(); |
Alexey Samsonov | 5cf832d | 2012-03-21 12:29:54 +0000 | [diff] [blame] | 110 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 111 | #define ENSURE_ASAN_INITED() do { \ |
| 112 | CHECK(!asan_init_is_running); \ |
| 113 | if (UNLIKELY(!asan_inited)) { \ |
| 114 | AsanInitFromRtl(); \ |
| 115 | } \ |
| 116 | } while (0) |
| 117 | |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 118 | } // namespace __asan |
| 119 | |
| 120 | #endif // ASAN_INTERCEPTORS_H |