1//===-- asan_interceptors_dynamic.cc --------------------------------------===// 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// __DATA,__interpose section of the dynamic runtime library for Mac OS. 13//===----------------------------------------------------------------------===// 14 15#if defined(__APPLE__) 16 17#include "../asan_interceptors.h" 18#include "../asan_intercepted_functions.h" 19 20namespace __asan { 21 22#if !MAC_INTERPOSE_FUNCTIONS 23# error \ 24 Dynamic interposing library should be built with -DMAC_INTERPOSE_FUNCTIONS 25#endif 26 27#define INTERPOSE_FUNCTION(function) \ 28 { reinterpret_cast<const uptr>(WRAP(function)), \ 29 reinterpret_cast<const uptr>(function) } 30 31#define INTERPOSE_FUNCTION_2(function, wrapper) \ 32 { reinterpret_cast<const uptr>(wrapper), \ 33 reinterpret_cast<const uptr>(function) } 34 35struct interpose_substitution { 36 const uptr replacement; 37 const uptr original; 38}; 39 40__attribute__((used)) 41const interpose_substitution substitutions[] 42 __attribute__((section("__DATA, __interpose"))) = { 43 INTERPOSE_FUNCTION(strlen), 44 INTERPOSE_FUNCTION(memcmp), 45 INTERPOSE_FUNCTION(memcpy), 46 INTERPOSE_FUNCTION(memmove), 47 INTERPOSE_FUNCTION(memset), 48 INTERPOSE_FUNCTION(strchr), 49 INTERPOSE_FUNCTION(strcat), 50 INTERPOSE_FUNCTION(strncat), 51 INTERPOSE_FUNCTION(strcpy), 52 INTERPOSE_FUNCTION(strncpy), 53 INTERPOSE_FUNCTION(pthread_create), 54 INTERPOSE_FUNCTION(longjmp), 55#if ASAN_INTERCEPT__LONGJMP 56 INTERPOSE_FUNCTION(_longjmp), 57#endif 58#if ASAN_INTERCEPT_SIGLONGJMP 59 INTERPOSE_FUNCTION(siglongjmp), 60#endif 61#if ASAN_INTERCEPT_STRDUP 62 INTERPOSE_FUNCTION(strdup), 63#endif 64#if ASAN_INTERCEPT_STRNLEN 65 INTERPOSE_FUNCTION(strnlen), 66#endif 67#if ASAN_INTERCEPT_INDEX 68 INTERPOSE_FUNCTION_2(index, WRAP(strchr)), 69#endif 70 INTERPOSE_FUNCTION(strcmp), 71 INTERPOSE_FUNCTION(strncmp), 72#if ASAN_INTERCEPT_STRCASECMP_AND_STRNCASECMP 73 INTERPOSE_FUNCTION(strcasecmp), 74 INTERPOSE_FUNCTION(strncasecmp), 75#endif 76 INTERPOSE_FUNCTION(atoi), 77 INTERPOSE_FUNCTION(atol), 78 INTERPOSE_FUNCTION(strtol), 79#if ASAN_INTERCEPT_ATOLL_AND_STRTOLL 80 INTERPOSE_FUNCTION(atoll), 81 INTERPOSE_FUNCTION(strtoll), 82#endif 83#if ASAN_INTERCEPT_MLOCKX 84 INTERPOSE_FUNCTION(mlock), 85 INTERPOSE_FUNCTION(munlock), 86 INTERPOSE_FUNCTION(mlockall), 87 INTERPOSE_FUNCTION(munlockall), 88#endif 89 INTERPOSE_FUNCTION(dispatch_async_f), 90 INTERPOSE_FUNCTION(dispatch_sync_f), 91 INTERPOSE_FUNCTION(dispatch_after_f), 92 INTERPOSE_FUNCTION(dispatch_barrier_async_f), 93 INTERPOSE_FUNCTION(dispatch_group_async_f), 94 95 INTERPOSE_FUNCTION(dispatch_group_async), 96 INTERPOSE_FUNCTION(dispatch_async), 97 INTERPOSE_FUNCTION(dispatch_after), 98 INTERPOSE_FUNCTION(dispatch_source_set_event_handler), 99 INTERPOSE_FUNCTION(dispatch_source_set_cancel_handler), 100 101 INTERPOSE_FUNCTION(__CFInitialize), 102 INTERPOSE_FUNCTION(CFStringCreateCopy), 103 INTERPOSE_FUNCTION(free), 104}; 105 106} // namespace __asan 107 108#endif // __APPLE__ 109