blob: 6e9e80817cb3678844fc295b1d612b0a3b980b10 [file] [log] [blame]
Alexey Samsonov8489f2a2012-02-08 19:52:01 +00001//===-- 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.
Alexey Samsonov0f840bd2012-08-02 11:19:13 +000038bool OverrideFunction(uptr old_func, uptr new_func, uptr *orig_old_func);
Alexey Samsonov8489f2a2012-02-08 19:52:01 +000039} // namespace __interception
40
41# define OVERRIDE_FUNCTION_MAC(old_func, new_func) \
Alexey Samsonov0f840bd2012-08-02 11:19:13 +000042 ::__interception::OverrideFunction( \
43 (::__interception::uptr)old_func, \
44 (::__interception::uptr)new_func, \
Alexey Samsonov4787d0f2012-09-12 14:10:14 +000045 (::__interception::uptr*)((::__interception::uptr)&REAL(old_func)))
Alexey Samsonov8489f2a2012-02-08 19:52:01 +000046# define INTERCEPT_FUNCTION_MAC(func) OVERRIDE_FUNCTION_MAC(func, WRAP(func))
47
48#endif // INTERCEPTION_MAC_H
49#endif // __APPLE__