1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
3 * Copyright (c) 2004-2013 Apple Inc. All rights reserved.
5 * @APPLE_LICENSE_HEADER_START@
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
22 * @APPLE_LICENSE_HEADER_END@
26 #ifndef __DYLD_SYSCALL_HELPERS__
27 #define __DYLD_SYSCALL_HELPERS__
29 #include <sys/cdefs.h>
32 #if __has_include(<libamfi.h>)
36 extern int amfi_check_dyld_policy_self(uint64_t input_flags
, uint64_t* output_flags
);
39 #include <libkern/OSAtomic.h>
41 #include <mach/mach.h>
42 #include <mach/mach_time.h>
43 #include <mach-o/loader.h>
46 #include <sys/fcntl.h>
47 #include <sys/ioctl.h>
48 #include <sys/kdebug_private.h>
52 #include <System/sys/reason.h>
54 #define DYLD_SYSCALL_VTABLE_ENTRY(x) __typeof__ (x) *x
60 // This file contains the table of function pointers the host dyld supplies
61 // to the iOS simulator dyld.
66 DYLD_SYSCALL_VTABLE_ENTRY(open
);
67 DYLD_SYSCALL_VTABLE_ENTRY(close
);
68 DYLD_SYSCALL_VTABLE_ENTRY(pread
);
69 DYLD_SYSCALL_VTABLE_ENTRY(write
);
70 DYLD_SYSCALL_VTABLE_ENTRY(mmap
);
71 DYLD_SYSCALL_VTABLE_ENTRY(munmap
);
72 DYLD_SYSCALL_VTABLE_ENTRY(madvise
);
73 DYLD_SYSCALL_VTABLE_ENTRY(stat
);
74 DYLD_SYSCALL_VTABLE_ENTRY(fcntl
);
75 DYLD_SYSCALL_VTABLE_ENTRY(ioctl
);
76 DYLD_SYSCALL_VTABLE_ENTRY(issetugid
);
77 DYLD_SYSCALL_VTABLE_ENTRY(getcwd
);
78 DYLD_SYSCALL_VTABLE_ENTRY(realpath
);
79 DYLD_SYSCALL_VTABLE_ENTRY(vm_allocate
);
80 DYLD_SYSCALL_VTABLE_ENTRY(vm_deallocate
);
81 DYLD_SYSCALL_VTABLE_ENTRY(vm_protect
);
82 void (*vlog
)(const char* format
, va_list list
);
83 void (*vwarn
)(const char* format
, va_list list
);
84 DYLD_SYSCALL_VTABLE_ENTRY(pthread_mutex_lock
);
85 DYLD_SYSCALL_VTABLE_ENTRY(pthread_mutex_unlock
);
86 DYLD_SYSCALL_VTABLE_ENTRY(mach_thread_self
);
87 DYLD_SYSCALL_VTABLE_ENTRY(mach_port_deallocate
);
88 DYLD_SYSCALL_VTABLE_ENTRY(task_self_trap
);
89 DYLD_SYSCALL_VTABLE_ENTRY(mach_timebase_info
);
90 #if OSATOMIC_USE_INLINED
91 bool (*OSAtomicCompareAndSwapPtrBarrier
)(void* old
, void* nw
, void * volatile *value
);
92 void (*OSMemoryBarrier
)(void);
94 #pragma clang diagnostic push
95 #pragma clang diagnostic ignored "-Wdeprecated"
96 DYLD_SYSCALL_VTABLE_ENTRY(OSAtomicCompareAndSwapPtrBarrier
);
97 DYLD_SYSCALL_VTABLE_ENTRY(OSMemoryBarrier
);
98 #pragma clang diagnostic pop
100 void* (*getProcessInfo
)(void); // returns dyld_all_image_infos*;
101 int* (*errnoAddress
)(void);
102 DYLD_SYSCALL_VTABLE_ENTRY(mach_absolute_time
);
103 // Added in version 2
104 DYLD_SYSCALL_VTABLE_ENTRY(thread_switch
);
105 // Added in version 3
106 DYLD_SYSCALL_VTABLE_ENTRY(opendir
);
107 DYLD_SYSCALL_VTABLE_ENTRY(readdir_r
);
108 DYLD_SYSCALL_VTABLE_ENTRY(closedir
);
109 // Added in version 4
110 void (*coresymbolication_load_notifier
)(void *connection
, uint64_t load_timestamp
, const char *image_path
, const struct mach_header
*mach_header
);
111 void (*coresymbolication_unload_notifier
)(void *connection
, uint64_t unload_timestamp
, const char *image_path
, const struct mach_header
*mach_header
);
112 // Added in version 5
113 DYLD_SYSCALL_VTABLE_ENTRY(proc_regionfilename
);
114 DYLD_SYSCALL_VTABLE_ENTRY(getpid
);
115 DYLD_SYSCALL_VTABLE_ENTRY(mach_port_insert_right
);
116 DYLD_SYSCALL_VTABLE_ENTRY(mach_port_allocate
);
117 DYLD_SYSCALL_VTABLE_ENTRY(mach_msg
);
118 // Added in version 6
119 DYLD_SYSCALL_VTABLE_ENTRY(abort_with_payload
);
121 DYLD_SYSCALL_VTABLE_ENTRY(task_register_dyld_image_infos
);
122 DYLD_SYSCALL_VTABLE_ENTRY(task_unregister_dyld_image_infos
);
123 DYLD_SYSCALL_VTABLE_ENTRY(task_get_dyld_image_infos
);
124 DYLD_SYSCALL_VTABLE_ENTRY(task_register_dyld_shared_cache_image_info
);
125 DYLD_SYSCALL_VTABLE_ENTRY(task_register_dyld_set_dyld_state
);
126 DYLD_SYSCALL_VTABLE_ENTRY(task_register_dyld_get_process_state
);
127 DYLD_SYSCALL_VTABLE_ENTRY(task_info
);
128 DYLD_SYSCALL_VTABLE_ENTRY(thread_info
);
130 DYLD_SYSCALL_VTABLE_ENTRY(kdebug_is_enabled
);
131 DYLD_SYSCALL_VTABLE_ENTRY(kdebug_trace
);
133 DYLD_SYSCALL_VTABLE_ENTRY(kdebug_trace_string
);
135 DYLD_SYSCALL_VTABLE_ENTRY(amfi_check_dyld_policy_self
);
137 void (*notifyMonitoringDyldMain
)(void);
138 void (*notifyMonitoringDyld
)(bool unloading
, unsigned imageCount
, const struct mach_header
* loadAddresses
[], const char* imagePaths
[]);
140 DYLD_SYSCALL_VTABLE_ENTRY(mach_msg_destroy
);
141 DYLD_SYSCALL_VTABLE_ENTRY(mach_port_construct
);
142 DYLD_SYSCALL_VTABLE_ENTRY(mach_port_destruct
);
144 DYLD_SYSCALL_VTABLE_ENTRY(fstat
);
145 DYLD_SYSCALL_VTABLE_ENTRY(vm_copy
);
147 extern const struct SyscallHelpers
* gSyscallHelpers
;