interception_mac.h revision 245614
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.
30extern "C" {
31mach_error_t __interception_allocate_island(void **ptr, size_t unused_size,
32                                            void *unused_hint);
33mach_error_t __interception_deallocate_island(void *ptr);
34}  // extern "C"
35
36namespace __interception {
37// returns true if the old function existed.
38bool OverrideFunction(uptr old_func, uptr new_func, uptr *orig_old_func);
39}  // namespace __interception
40
41# define OVERRIDE_FUNCTION_MAC(old_func, new_func) \
42    ::__interception::OverrideFunction( \
43          (::__interception::uptr)old_func, \
44          (::__interception::uptr)new_func, \
45          (::__interception::uptr*)((::__interception::uptr)&REAL(old_func)))
46# define INTERCEPT_FUNCTION_MAC(func) OVERRIDE_FUNCTION_MAC(func, WRAP(func))
47
48#endif  // INTERCEPTION_MAC_H
49#endif  // __APPLE__
50