dyld-832.7.1.tar.gz
[apple/dyld.git] / dyld3 / APIs.h
1 /*
2 * Copyright (c) 2017 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25
26 #ifndef __DYLD_APIS_H__
27 #define __DYLD_APIS_H__
28
29 #include <string.h>
30 #include <stdint.h>
31 #include <pthread.h>
32 #include <uuid/uuid.h>
33 #include <mach-o/dyld_priv.h>
34
35 #include "dlfcn.h"
36
37
38 #define TEMP_HIDDEN __attribute__((visibility("hidden")))
39
40 //
41 // The implementation of all dyld load/unload API's must hold a global lock
42 // so that the next load/unload does start until the current is complete.
43 // This lock is recursive so that initializers can call dlopen().
44 // This is done using the macros DYLD_LOCK_THIS_BLOCK.
45 // Example:
46 //
47 // void dyld_load_api() {
48 // DYLD_LOAD_LOCK_THIS_BLOCK;
49 // // free to do stuff here
50 // // that accesses dyld internal data structures
51 // }
52 //
53 //
54
55 #define DYLD_LOAD_LOCK_THIS_BLOCK RecursiveAutoLock _dyld_load_lock;
56
57 namespace dyld3 {
58
59 class __attribute__((visibility("hidden"))) RecursiveAutoLock
60 {
61 public:
62 RecursiveAutoLock() {
63 pthread_mutex_lock(&_sMutex);
64 }
65 ~RecursiveAutoLock() {
66 pthread_mutex_unlock(&_sMutex);
67 }
68 private:
69 static pthread_mutex_t _sMutex;
70 };
71
72
73
74
75 uint32_t _dyld_image_count() TEMP_HIDDEN;
76
77 const mach_header* _dyld_get_image_header(uint32_t imageIndex) TEMP_HIDDEN;
78
79 intptr_t _dyld_get_image_slide(const mach_header* mh) TEMP_HIDDEN;
80
81 intptr_t _dyld_get_image_vmaddr_slide(uint32_t imageIndex) TEMP_HIDDEN;
82
83 const char* _dyld_get_image_name(uint32_t imageIndex) TEMP_HIDDEN;
84
85 const struct mach_header * _dyld_get_prog_image_header() TEMP_HIDDEN;
86
87 int32_t NSVersionOfLinkTimeLibrary(const char* libraryName) TEMP_HIDDEN;
88
89 int32_t NSVersionOfRunTimeLibrary(const char* libraryName) TEMP_HIDDEN;
90
91 uint32_t dyld_get_program_sdk_watch_os_version() TEMP_HIDDEN;
92 uint32_t dyld_get_program_min_watch_os_version() TEMP_HIDDEN;
93
94 uint32_t dyld_get_program_sdk_bridge_os_version() TEMP_HIDDEN;
95 uint32_t dyld_get_program_min_bridge_os_version() TEMP_HIDDEN;
96
97
98 uint32_t dyld_get_sdk_version(const mach_header* mh) TEMP_HIDDEN;
99
100
101 uint32_t dyld_get_program_sdk_version() TEMP_HIDDEN;
102 uint32_t dyld_get_min_os_version(const mach_header* mh) TEMP_HIDDEN;
103
104 uint32_t dyld_get_program_min_os_version() TEMP_HIDDEN;
105
106 dyld_platform_t dyld_get_active_platform(void) TEMP_HIDDEN;
107 dyld_platform_t dyld_get_base_platform(dyld_platform_t platform) TEMP_HIDDEN;
108 bool dyld_is_simulator_platform(dyld_platform_t platform) TEMP_HIDDEN;
109 bool dyld_sdk_at_least(const struct mach_header* mh, dyld_build_version_t version) TEMP_HIDDEN;
110 bool dyld_minos_at_least(const struct mach_header* mh, dyld_build_version_t version) TEMP_HIDDEN;
111 bool dyld_program_sdk_at_least(dyld_build_version_t version) TEMP_HIDDEN;
112 bool dyld_program_minos_at_least(dyld_build_version_t version) TEMP_HIDDEN;
113 void dyld_get_image_versions(const struct mach_header* mh, void (^callback)(dyld_platform_t platform, uint32_t sdk_version, uint32_t min_version)) TEMP_HIDDEN;
114
115 bool _dyld_get_image_uuid(const mach_header* mh, uuid_t uuid) TEMP_HIDDEN;
116
117 int _NSGetExecutablePath(char* buf, uint32_t* bufsize) TEMP_HIDDEN;
118
119 void _dyld_register_func_for_add_image(void (*func)(const mach_header *mh, intptr_t vmaddr_slide)) TEMP_HIDDEN;
120
121 void _dyld_register_func_for_remove_image(void (*func)(const mach_header *mh, intptr_t vmaddr_slide)) TEMP_HIDDEN;
122
123 void _dyld_objc_notify_register(_dyld_objc_notify_mapped mapped,
124 _dyld_objc_notify_init init,
125 _dyld_objc_notify_unmapped unmapped) TEMP_HIDDEN;
126
127 const mach_header* dyld_image_header_containing_address(const void* addr) TEMP_HIDDEN;
128
129 const mach_header* _dyld_get_image_header_containing_address(const void* address) TEMP_HIDDEN;
130
131 bool _dyld_image_containing_address(const void* address) TEMP_HIDDEN;
132
133 const char* dyld_image_path_containing_address(const void* addr) TEMP_HIDDEN;
134
135 bool _dyld_is_memory_immutable(const void* addr, size_t length) TEMP_HIDDEN;
136
137
138 int dladdr(const void* addr, Dl_info* info) TEMP_HIDDEN;
139
140 char* dlerror() TEMP_HIDDEN;
141
142 int dlclose(void* handle) TEMP_HIDDEN;
143
144 void* dlopen_internal(const char* path, int mode, void* callerAddress) TEMP_HIDDEN;
145
146 bool dlopen_preflight_internal(const char* path) TEMP_HIDDEN;
147
148 void* dlsym_internal(void* handle, const char* symbolName, void* callerAddress) TEMP_HIDDEN;
149
150 const struct dyld_all_image_infos* _dyld_get_all_image_infos() TEMP_HIDDEN;
151
152 bool dyld_shared_cache_some_image_overridden() TEMP_HIDDEN;
153
154 bool _dyld_get_shared_cache_uuid(uuid_t uuid) TEMP_HIDDEN;
155
156 const void* _dyld_get_shared_cache_range(size_t* length) TEMP_HIDDEN;
157
158 bool _dyld_shared_cache_optimized() TEMP_HIDDEN;
159
160 bool _dyld_shared_cache_is_locally_built() TEMP_HIDDEN;
161
162 uint32_t _dyld_launch_mode() TEMP_HIDDEN;
163
164 bool dyld_need_closure(const char* execPath, const char* dataContainerRootDir) TEMP_HIDDEN;
165
166 void _dyld_images_for_addresses(unsigned count, const void* addresses[], struct dyld_image_uuid_offset infos[]) TEMP_HIDDEN;
167
168 void _dyld_register_for_image_loads(void (*func)(const mach_header* mh, const char* path, bool unloadable)) TEMP_HIDDEN;
169
170 void _dyld_register_for_bulk_image_loads(void (*func)(unsigned imageCount, const struct mach_header* mhs[], const char* paths[])) TEMP_HIDDEN;
171
172 bool _dyld_find_unwind_sections(void* addr, dyld_unwind_sections* info) TEMP_HIDDEN;
173
174 bool dyld_process_is_restricted() TEMP_HIDDEN;
175
176 const char* dyld_shared_cache_file_path() TEMP_HIDDEN;
177
178 bool dyld_has_inserted_or_interposing_libraries() TEMP_HIDDEN;
179
180 void dyld_dynamic_interpose(const mach_header* mh, const dyld_interpose_tuple array[], size_t count) TEMP_HIDDEN;
181
182 int dyld_shared_cache_find_iterate_text(const uuid_t cacheUuid, const char* extraSearchDirs[], void (^callback)(const dyld_shared_cache_dylib_text_info* info)) TEMP_HIDDEN;
183
184 int dyld_shared_cache_iterate_text(const uuid_t cacheUuid, void (^callback)(const dyld_shared_cache_dylib_text_info* info)) TEMP_HIDDEN;
185
186 void _dyld_atfork_prepare() TEMP_HIDDEN;
187 void _dyld_atfork_parent() TEMP_HIDDEN;
188 void _dyld_fork_child() TEMP_HIDDEN;
189
190 void _dyld_missing_symbol_abort() TEMP_HIDDEN;
191
192 const char* _dyld_get_objc_selector(const char* selName) TEMP_HIDDEN;
193
194 void _dyld_for_each_objc_class(const char* className,
195 void (^callback)(void* classPtr, bool isLoaded, bool* stop)) TEMP_HIDDEN;
196
197 void _dyld_for_each_objc_protocol(const char* protocolName,
198 void (^callback)(void* protocolPtr, bool isLoaded, bool* stop)) TEMP_HIDDEN;
199
200 void _dyld_register_driverkit_main(void (*mainFunc)())TEMP_HIDDEN;
201
202 // only in macOS and deprecated
203 #if TARGET_OS_OSX
204 NSObjectFileImageReturnCode NSCreateObjectFileImageFromFile(const char* pathName, NSObjectFileImage *objectFileImage) TEMP_HIDDEN;
205 NSObjectFileImageReturnCode NSCreateObjectFileImageFromMemory(const void *address, size_t size, NSObjectFileImage *objectFileImage) TEMP_HIDDEN;
206 bool NSDestroyObjectFileImage(NSObjectFileImage objectFileImage) TEMP_HIDDEN;
207 uint32_t NSSymbolDefinitionCountInObjectFileImage(NSObjectFileImage objectFileImage) TEMP_HIDDEN;
208 const char* NSSymbolDefinitionNameInObjectFileImage(NSObjectFileImage objectFileImage, uint32_t ordinal) TEMP_HIDDEN;
209 uint32_t NSSymbolReferenceCountInObjectFileImage(NSObjectFileImage objectFileImage) TEMP_HIDDEN;
210 const char* NSSymbolReferenceNameInObjectFileImage(NSObjectFileImage objectFileImage, uint32_t ordinal, bool *tentative_definition) TEMP_HIDDEN;
211 bool NSIsSymbolDefinedInObjectFileImage(NSObjectFileImage objectFileImage, const char* symbolName) TEMP_HIDDEN;
212 void* NSGetSectionDataInObjectFileImage(NSObjectFileImage objectFileImage, const char* segmentName, const char* sectionName, size_t *size) TEMP_HIDDEN;
213 const char* NSNameOfModule(NSModule m) TEMP_HIDDEN;
214 const char* NSLibraryNameForModule(NSModule m) TEMP_HIDDEN;
215 NSModule NSLinkModule(NSObjectFileImage objectFileImage, const char* moduleName, uint32_t options) TEMP_HIDDEN;
216 bool NSUnLinkModule(NSModule module, uint32_t options) TEMP_HIDDEN;
217 bool NSIsSymbolNameDefined(const char* symbolName) TEMP_HIDDEN;
218 bool NSIsSymbolNameDefinedWithHint(const char* symbolName, const char* libraryNameHint) TEMP_HIDDEN;
219 bool NSIsSymbolNameDefinedInImage(const struct mach_header* image, const char* symbolName) TEMP_HIDDEN;
220 NSSymbol NSLookupAndBindSymbol(const char* symbolName) TEMP_HIDDEN;
221 NSSymbol NSLookupAndBindSymbolWithHint(const char* symbolName, const char* libraryNameHint) TEMP_HIDDEN;
222 NSSymbol NSLookupSymbolInModule(NSModule module, const char* symbolName) TEMP_HIDDEN;
223 NSSymbol NSLookupSymbolInImage(const struct mach_header* image, const char* symbolName, uint32_t options) TEMP_HIDDEN;
224 const char* NSNameOfSymbol(NSSymbol symbol) TEMP_HIDDEN;
225 void* NSAddressOfSymbol(NSSymbol symbol) TEMP_HIDDEN;
226 NSModule NSModuleForSymbol(NSSymbol symbol) TEMP_HIDDEN;
227 void NSLinkEditError(NSLinkEditErrors *c, int *errorNumber, const char** fileName, const char** errorString) TEMP_HIDDEN;
228 bool NSAddLibrary(const char* pathName) TEMP_HIDDEN;
229 bool NSAddLibraryWithSearching(const char* pathName) TEMP_HIDDEN;
230 const struct mach_header* NSAddImage(const char* image_name, uint32_t options) TEMP_HIDDEN;
231 void NSInstallLinkEditErrorHandlers(const NSLinkEditErrorHandlers *handlers) TEMP_HIDDEN;
232 bool _dyld_present(void) TEMP_HIDDEN;
233 bool _dyld_launched_prebound(void) TEMP_HIDDEN;
234 bool _dyld_all_twolevel_modules_prebound(void) TEMP_HIDDEN;
235 bool _dyld_bind_fully_image_containing_address(const void* address) TEMP_HIDDEN;
236 bool _dyld_image_containing_address(const void* address) TEMP_HIDDEN;
237 void _dyld_lookup_and_bind(const char* symbol_name, void **address, NSModule* module) TEMP_HIDDEN;
238 void _dyld_lookup_and_bind_with_hint(const char* symbol_name, const char* library_name_hint, void** address, NSModule* module) TEMP_HIDDEN;
239 void _dyld_lookup_and_bind_fully(const char* symbol_name, void** address, NSModule* module) TEMP_HIDDEN;
240 const struct mach_header* _dyld_get_image_header_containing_address(const void* address) TEMP_HIDDEN;
241 #endif
242
243 } // namespace dyld3
244
245 #endif // __DYLD_APIS_H__
246
247