Kostya Serebryany | 019b76f | 2011-11-30 01:07:02 | [diff] [blame] | 1 | //===-- 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 Serebryany | 5dfa4da | 2011-12-01 21:40:52 | [diff] [blame] | 14 | #ifdef __APPLE__ |
| 15 | |
Kostya Serebryany | 019b76f | 2011-11-30 01:07:02 | [diff] [blame] | 16 | #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 Potapenko | bd53f59 | 2012-01-13 16:13:58 | [diff] [blame^] | 23 | #include <mach/mach_error.h> |
Kostya Serebryany | 019b76f | 2011-11-30 01:07:02 | [diff] [blame] | 24 | #include <setjmp.h> |
| 25 | |
| 26 | typedef void* pthread_workqueue_t; |
| 27 | typedef void* pthread_workitem_handle_t; |
| 28 | |
| 29 | typedef void (*dispatch_function_t)(void *block); |
| 30 | typedef void* (*worker_t)(void *block); |
| 31 | typedef int (*dispatch_async_f_f)(dispatch_queue_t dq, void *ctxt, |
| 32 | dispatch_function_t func); |
| 33 | typedef int (*dispatch_sync_f_f)(dispatch_queue_t dq, void *ctxt, |
| 34 | dispatch_function_t func); |
| 35 | typedef int (*dispatch_after_f_f)(dispatch_time_t when, |
| 36 | dispatch_queue_t dq, void *ctxt, |
| 37 | dispatch_function_t func); |
| 38 | typedef void (*dispatch_barrier_async_f_f)(dispatch_queue_t dq, |
| 39 | void *ctxt, |
| 40 | dispatch_function_t func); |
| 41 | typedef void (*dispatch_group_async_f_f)(dispatch_group_t group, |
| 42 | dispatch_queue_t dq, |
| 43 | void *ctxt, dispatch_function_t func); |
| 44 | typedef 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. |
| 50 | typedef struct { |
| 51 | void *block; |
| 52 | dispatch_function_t func; |
| 53 | int parent_tid; |
| 54 | } asan_block_context_t; |
| 55 | |
| 56 | |
| 57 | extern "C" { |
Alexander Potapenko | bd53f59 | 2012-01-13 16:13:58 | [diff] [blame^] | 58 | |
| 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. |
| 64 | mach_error_t __asan_allocate_island(void **ptr, size_t unused_size, void *unused_hint); |
| 65 | mach_error_t __asan_deallocate_island(void *ptr); |
| 66 | |
Kostya Serebryany | 019b76f | 2011-11-30 01:07:02 | [diff] [blame] | 67 | // dispatch_barrier_async_f() is not declared in <dispatch/dispatch.h>. |
| 68 | void dispatch_barrier_async_f(dispatch_queue_t dq, |
| 69 | void *ctxt, dispatch_function_t func); |
| 70 | // Neither is pthread_workqueue_additem_np(). |
| 71 | int 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 | |
| 75 | int WRAP(dispatch_async_f)(dispatch_queue_t dq, |
| 76 | void *ctxt, |
| 77 | dispatch_function_t func); |
| 78 | int WRAP(dispatch_sync_f)(dispatch_queue_t dq, |
| 79 | void *ctxt, |
| 80 | dispatch_function_t func); |
| 81 | int WRAP(dispatch_after_f)(dispatch_time_t when, |
| 82 | dispatch_queue_t dq, |
| 83 | void *ctxt, |
| 84 | dispatch_function_t func); |
| 85 | void WRAP(dispatch_barrier_async_f)(dispatch_queue_t dq, |
| 86 | void *ctxt, dispatch_function_t func); |
| 87 | void WRAP(dispatch_group_async_f)(dispatch_group_t group, |
| 88 | dispatch_queue_t dq, |
| 89 | void *ctxt, dispatch_function_t func); |
| 90 | int 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 Serebryany | 5dfa4da | 2011-12-01 21:40:52 | [diff] [blame] | 96 | |
| 97 | #endif // __APPLE__ |