]> git.saurik.com Git - apple/dyld.git/blob - src/dyldSyscallInterface.h
ad689a2f00d70abcee5c37e52d3bd39180642aef
[apple/dyld.git] / src / dyldSyscallInterface.h
1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
2 *
3 * Copyright (c) 2004-2013 Apple Inc. All rights reserved.
4 *
5 * @APPLE_LICENSE_HEADER_START@
6 *
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
12 * file.
13 *
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.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24
25
26 #ifndef __DYLD_SYSCALL_HELPERS__
27 #define __DYLD_SYSCALL_HELPERS__
28
29 #include <sys/cdefs.h>
30
31 #include <dirent.h>
32 #if __has_include(<libamfi.h>)
33 #include <libamfi.h>
34 #else
35 __BEGIN_DECLS
36 extern int amfi_check_dyld_policy_self(uint64_t input_flags, uint64_t* output_flags);
37 __END_DECLS
38 #endif
39 #include <libkern/OSAtomic.h>
40 #include <libproc.h>
41 #include <mach/mach.h>
42 #include <mach/mach_time.h>
43 #include <mach-o/loader.h>
44 #include <pthread.h>
45 #include <stdlib.h>
46 #include <sys/fcntl.h>
47 #include <sys/ioctl.h>
48 #include <sys/kdebug_private.h>
49 #include <sys/mman.h>
50 #include <sys/stat.h>
51 #include <unistd.h>
52 #include <System/sys/reason.h>
53
54 #define DYLD_SYSCALL_VTABLE_ENTRY(x) __typeof__ (x) *x
55
56 #if __cplusplus
57 namespace dyld {
58 #endif
59 //
60 // This file contains the table of function pointers the host dyld supplies
61 // to the iOS simulator dyld.
62 //
63 struct SyscallHelpers
64 {
65 uintptr_t version;
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);
93 #else
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
99 #endif
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);
120 // Add in version 7
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);
129 // Add in version 8
130 DYLD_SYSCALL_VTABLE_ENTRY(kdebug_is_enabled);
131 DYLD_SYSCALL_VTABLE_ENTRY(kdebug_trace);
132 // Add in version 9
133 DYLD_SYSCALL_VTABLE_ENTRY(kdebug_trace_string);
134 // Add in version 10
135 DYLD_SYSCALL_VTABLE_ENTRY(amfi_check_dyld_policy_self);
136 // Add in version 11
137 void (*notifyMonitoringDyldMain)(void);
138 void (*notifyMonitoringDyld)(bool unloading, unsigned imageCount, const struct mach_header* loadAddresses[], const char* imagePaths[]);
139 // Add in version 12
140 DYLD_SYSCALL_VTABLE_ENTRY(mach_msg_destroy);
141 DYLD_SYSCALL_VTABLE_ENTRY(mach_port_construct);
142 DYLD_SYSCALL_VTABLE_ENTRY(mach_port_destruct);
143 };
144 extern const struct SyscallHelpers* gSyscallHelpers;
145
146
147 #if __cplusplus
148 }
149 #endif
150
151 #endif