blob: 224d961eefe047ede630c49d8050304cd843421a [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.
38bool OverrideFunction(void *old_func, void *new_func, void **orig_old_func);
39} // namespace __interception
40
41# define OVERRIDE_FUNCTION_MAC(old_func, new_func) \
42 ::__interception::OverrideFunction((void*)old_func, (void*)new_func, \
43 (void**)&REAL(old_func))
44# define INTERCEPT_FUNCTION_MAC(func) OVERRIDE_FUNCTION_MAC(func, WRAP(func))
45
46#endif // INTERCEPTION_MAC_H
47#endif // __APPLE__