blob: 7c941f81b837666957123872088e7196191da987 [file] [log] [blame]
Kostya Serebryany019b76f2011-11-30 01:07:021//===-- asan_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// ASan-private header for asan_mac.cc
13//===----------------------------------------------------------------------===//
Kostya Serebryany5dfa4da2011-12-01 21:40:5214#ifdef __APPLE__
15
Kostya Serebryany019b76f2011-11-30 01:07:0216#ifndef ASAN_MAC_H
17#define ASAN_MAC_H
18
19#include "asan_interceptors.h"
20
21// TODO(glider): need to check if the OS X version is 10.6 or greater.
22#include <dispatch/dispatch.h>
Alexander Potapenkobd53f592012-01-13 16:13:5823#include <mach/mach_error.h>
Kostya Serebryany019b76f2011-11-30 01:07:0224#include <setjmp.h>
25
26typedef void* pthread_workqueue_t;
27typedef void* pthread_workitem_handle_t;
28
29typedef void (*dispatch_function_t)(void *block);
30typedef void* (*worker_t)(void *block);
31typedef int (*dispatch_async_f_f)(dispatch_queue_t dq, void *ctxt,
32 dispatch_function_t func);
33typedef int (*dispatch_sync_f_f)(dispatch_queue_t dq, void *ctxt,
34 dispatch_function_t func);
35typedef int (*dispatch_after_f_f)(dispatch_time_t when,
36 dispatch_queue_t dq, void *ctxt,
37 dispatch_function_t func);
38typedef void (*dispatch_barrier_async_f_f)(dispatch_queue_t dq,
39 void *ctxt,
40 dispatch_function_t func);
41typedef void (*dispatch_group_async_f_f)(dispatch_group_t group,
42 dispatch_queue_t dq,
43 void *ctxt, dispatch_function_t func);
44typedef int (*pthread_workqueue_additem_np_f)(pthread_workqueue_t workq,
45 void *(*workitem_func)(void *), void * workitem_arg,
46 pthread_workitem_handle_t * itemhandlep, unsigned int *gencountp);
47
48
49// A wrapper for the ObjC blocks used to support libdispatch.
50typedef struct {
51 void *block;
52 dispatch_function_t func;
53 int parent_tid;
54} asan_block_context_t;
55
56
57extern "C" {
Alexander Potapenkobd53f592012-01-13 16:13:5858
59// Allocate memory for the escape island. This cannot be moved to
60// mach_override, because the allocator needs to know about the ASan shadow
61// mappings.
62// TODO(glider): in order to place a relative jump the allocated memory should
63// be within 2 Gb from the hint address.
64mach_error_t __asan_allocate_island(void **ptr, size_t unused_size, void *unused_hint);
65mach_error_t __asan_deallocate_island(void *ptr);
66
Kostya Serebryany019b76f2011-11-30 01:07:0267// dispatch_barrier_async_f() is not declared in <dispatch/dispatch.h>.
68void dispatch_barrier_async_f(dispatch_queue_t dq,
69 void *ctxt, dispatch_function_t func);
70// Neither is pthread_workqueue_additem_np().
71int pthread_workqueue_additem_np(pthread_workqueue_t workq,
72 void *(*workitem_func)(void *), void * workitem_arg,
73 pthread_workitem_handle_t * itemhandlep, unsigned int *gencountp);
74
75int WRAP(dispatch_async_f)(dispatch_queue_t dq,
76 void *ctxt,
77 dispatch_function_t func);
78int WRAP(dispatch_sync_f)(dispatch_queue_t dq,
79 void *ctxt,
80 dispatch_function_t func);
81int WRAP(dispatch_after_f)(dispatch_time_t when,
82 dispatch_queue_t dq,
83 void *ctxt,
84 dispatch_function_t func);
85void WRAP(dispatch_barrier_async_f)(dispatch_queue_t dq,
86 void *ctxt, dispatch_function_t func);
87void WRAP(dispatch_group_async_f)(dispatch_group_t group,
88 dispatch_queue_t dq,
89 void *ctxt, dispatch_function_t func);
90int WRAP(pthread_workqueue_additem_np)(pthread_workqueue_t workq,
91 void *(*workitem_func)(void *), void * workitem_arg,
92 pthread_workitem_handle_t * itemhandlep, unsigned int *gencountp);
93}
94
95#endif // ASAN_MAC_H
Kostya Serebryany5dfa4da2011-12-01 21:40:5296
97#endif // __APPLE__