Alexey Samsonov | 8489f2a | 2012-02-08 19:52:01 +0000 | [diff] [blame] | 1 | //===-- interception_mac.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 | // Mac-specific interception methods. |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifdef __APPLE__ |
| 16 | |
| 17 | #if !defined(INCLUDED_FROM_INTERCEPTION_LIB) |
| 18 | # error "interception_mac.h should be included from interception.h only" |
| 19 | #endif |
| 20 | |
| 21 | #ifndef INTERCEPTION_MAC_H |
| 22 | #define INTERCEPTION_MAC_H |
| 23 | |
| 24 | #include <mach/mach_error.h> |
| 25 | #include <stddef.h> |
| 26 | |
| 27 | // Allocate memory for the escape island. This cannot be moved to |
| 28 | // mach_override, because each user of interceptors may specify its |
| 29 | // own memory range for escape islands. |
| 30 | extern "C" { |
| 31 | mach_error_t __interception_allocate_island(void **ptr, size_t unused_size, |
| 32 | void *unused_hint); |
| 33 | mach_error_t __interception_deallocate_island(void *ptr); |
| 34 | } // extern "C" |
| 35 | |
| 36 | namespace __interception { |
| 37 | // returns true if the old function existed. |
Alexey Samsonov | 0f840bd | 2012-08-02 11:19:13 +0000 | [diff] [blame^] | 38 | bool OverrideFunction(uptr old_func, uptr new_func, uptr *orig_old_func); |
Alexey Samsonov | 8489f2a | 2012-02-08 19:52:01 +0000 | [diff] [blame] | 39 | } // namespace __interception |
| 40 | |
| 41 | # define OVERRIDE_FUNCTION_MAC(old_func, new_func) \ |
Alexey Samsonov | 0f840bd | 2012-08-02 11:19:13 +0000 | [diff] [blame^] | 42 | ::__interception::OverrideFunction( \ |
| 43 | (::__interception::uptr)old_func, \ |
| 44 | (::__interception::uptr)new_func, \ |
| 45 | (::__interception::uptr*)&REAL(old_func)) |
Alexey Samsonov | 8489f2a | 2012-02-08 19:52:01 +0000 | [diff] [blame] | 46 | # define INTERCEPT_FUNCTION_MAC(func) OVERRIDE_FUNCTION_MAC(func, WRAP(func)) |
| 47 | |
| 48 | #endif // INTERCEPTION_MAC_H |
| 49 | #endif // __APPLE__ |