]> git.saurik.com Git - apple/dyld.git/blob - include/mach-o/dyld_priv.h
dyld-421.2.tar.gz
[apple/dyld.git] / include / mach-o / dyld_priv.h
1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
2 *
3 * Copyright (c) 2003-2010 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 #ifndef _MACH_O_DYLD_PRIV_H_
25 #define _MACH_O_DYLD_PRIV_H_
26
27 #include <stdbool.h>
28 #include <Availability.h>
29 #include <mach-o/dyld.h>
30 #include <mach-o/dyld_images.h>
31
32 #if __cplusplus
33 extern "C" {
34 #endif /* __cplusplus */
35
36
37
38 //
39 // private interface between libSystem.dylib and dyld
40 //
41 extern int _dyld_func_lookup(const char* dyld_func_name, void **address);
42
43 //
44 // private interface between libSystem.dylib and dyld
45 //
46 extern void _dyld_fork_child();
47
48
49 // DEPRECATED
50 enum dyld_image_states
51 {
52 dyld_image_state_mapped = 10, // No batch notification for this
53 dyld_image_state_dependents_mapped = 20, // Only batch notification for this
54 dyld_image_state_rebased = 30,
55 dyld_image_state_bound = 40,
56 dyld_image_state_dependents_initialized = 45, // Only single notification for this
57 dyld_image_state_initialized = 50,
58 dyld_image_state_terminated = 60 // Only single notification for this
59 };
60
61 // DEPRECATED
62 typedef const char* (*dyld_image_state_change_handler)(enum dyld_image_states state, uint32_t infoCount, const struct dyld_image_info info[]);
63
64
65
66 typedef void (*_dyld_objc_notify_mapped)(unsigned count, const char* const paths[], const struct mach_header* const mh[]);
67 typedef void (*_dyld_objc_notify_init)(const char* path, const struct mach_header* mh);
68 typedef void (*_dyld_objc_notify_unmapped)(const char* path, const struct mach_header* mh);
69
70
71 //
72 // Note: only for use by objc runtime
73 // Register handlers to be called when objc images are mapped, unmapped, and initialized.
74 // Dyld will call back the "mapped" function with an array of images that contain an objc-image-info section.
75 // Those images that are dylibs will have the ref-counts automatically bumped, so objc will no longer need to
76 // call dlopen() on them to keep them from being unloaded. During the call to _dyld_objc_notify_register(),
77 // dyld will call the "mapped" function with already loaded objc images. During any later dlopen() call,
78 // dyld will also call the "mapped" function. Dyld will call the "init" function when dyld would be called
79 // initializers in that image. This is when objc calls any +load methods in that image.
80 //
81 void _dyld_objc_notify_register(_dyld_objc_notify_mapped mapped,
82 _dyld_objc_notify_init init,
83 _dyld_objc_notify_unmapped unmapped);
84
85
86
87 //
88 // Possible thread-local variable state changes for which you can register to be notified
89 //
90 enum dyld_tlv_states {
91 dyld_tlv_state_allocated = 10, // TLV range newly allocated
92 dyld_tlv_state_deallocated = 20 // TLV range about to be deallocated
93 };
94
95 //
96 // Info about thread-local variable storage.
97 //
98 typedef struct {
99 size_t info_size; // sizeof(dyld_tlv_info)
100 void * tlv_addr; // Base address of TLV storage
101 size_t tlv_size; // Byte size of TLV storage
102 } dyld_tlv_info;
103
104 #if __BLOCKS__
105
106 //
107 // Callback that notes changes to thread-local variable storage.
108 //
109 typedef void (^dyld_tlv_state_change_handler)(enum dyld_tlv_states state, const dyld_tlv_info *info);
110
111 //
112 // Register a handler to be called when a thread adds or removes storage for thread-local variables.
113 // The registered handler will only be called from and on behalf of the thread that owns the storage.
114 // The registered handler will NOT be called for any storage that was
115 // already allocated before dyld_register_tlv_state_change_handler() was
116 // called. Use dyld_enumerate_tlv_storage() to get that information.
117 // Exists in Mac OS X 10.7 and later
118 //
119 extern void
120 dyld_register_tlv_state_change_handler(enum dyld_tlv_states state, dyld_tlv_state_change_handler handler);
121
122 //
123 // Enumerate the current thread-local variable storage allocated for the current thread.
124 // Exists in Mac OS X 10.7 and later
125 //
126 extern void
127 dyld_enumerate_tlv_storage(dyld_tlv_state_change_handler handler);
128
129 #endif
130
131
132 //
133 // get slide for a given loaded mach_header
134 // Mac OS X 10.6 and later
135 //
136 extern intptr_t _dyld_get_image_slide(const struct mach_header* mh);
137
138
139 //
140 // get pointer to this process's dyld_all_image_infos
141 // Exists in Mac OS X 10.4 and later through _dyld_func_lookup()
142 // Exists in Mac OS X 10.6 and later through libSystem.dylib
143 //
144 const struct dyld_all_image_infos* _dyld_get_all_image_infos() __attribute__((deprecated));
145
146
147
148 struct dyld_unwind_sections
149 {
150 const struct mach_header* mh;
151 const void* dwarf_section;
152 uintptr_t dwarf_section_length;
153 const void* compact_unwind_section;
154 uintptr_t compact_unwind_section_length;
155 };
156
157
158 //
159 // Returns true iff some loaded mach-o image contains "addr".
160 // info->mh mach header of image containing addr
161 // info->dwarf_section pointer to start of __TEXT/__eh_frame section
162 // info->dwarf_section_length length of __TEXT/__eh_frame section
163 // info->compact_unwind_section pointer to start of __TEXT/__unwind_info section
164 // info->compact_unwind_section_length length of __TEXT/__unwind_info section
165 //
166 // Exists in Mac OS X 10.6 and later
167 extern bool _dyld_find_unwind_sections(void* addr, struct dyld_unwind_sections* info);
168
169
170 //
171 // This is an optimized form of dladdr() that only returns the dli_fname field.
172 //
173 // Exists in Mac OS X 10.6 and later
174 extern const char* dyld_image_path_containing_address(const void* addr);
175
176
177 //
178 // This is an optimized form of dladdr() that only returns the dli_fbase field.
179 // Return NULL, if address is not in any image tracked by dyld.
180 //
181 // Exists in Mac OS X 10.11 and later
182 extern const struct mach_header* dyld_image_header_containing_address(const void* addr);
183
184
185
186 // Convienence constants for return values from dyld_get_sdk_version() and friends.
187 #define DYLD_MACOSX_VERSION_10_4 0x000A0400
188 #define DYLD_MACOSX_VERSION_10_5 0x000A0500
189 #define DYLD_MACOSX_VERSION_10_6 0x000A0600
190 #define DYLD_MACOSX_VERSION_10_7 0x000A0700
191 #define DYLD_MACOSX_VERSION_10_8 0x000A0800
192 #define DYLD_MACOSX_VERSION_10_9 0x000A0900
193 #define DYLD_MACOSX_VERSION_10_10 0x000A0A00
194 #define DYLD_MACOSX_VERSION_10_11 0x000A0B00
195 #define DYLD_MACOSX_VERSION_10_12 0x000A0C00
196
197 #define DYLD_IOS_VERSION_2_0 0x00020000
198 #define DYLD_IOS_VERSION_2_1 0x00020100
199 #define DYLD_IOS_VERSION_2_2 0x00020200
200 #define DYLD_IOS_VERSION_3_0 0x00030000
201 #define DYLD_IOS_VERSION_3_1 0x00030100
202 #define DYLD_IOS_VERSION_3_2 0x00030200
203 #define DYLD_IOS_VERSION_4_0 0x00040000
204 #define DYLD_IOS_VERSION_4_1 0x00040100
205 #define DYLD_IOS_VERSION_4_2 0x00040200
206 #define DYLD_IOS_VERSION_4_3 0x00040300
207 #define DYLD_IOS_VERSION_5_0 0x00050000
208 #define DYLD_IOS_VERSION_5_1 0x00050100
209 #define DYLD_IOS_VERSION_6_0 0x00060000
210 #define DYLD_IOS_VERSION_6_1 0x00060100
211 #define DYLD_IOS_VERSION_7_0 0x00070000
212 #define DYLD_IOS_VERSION_7_1 0x00070100
213 #define DYLD_IOS_VERSION_8_0 0x00080000
214 #define DYLD_IOS_VERSION_8_1 0x00080100
215 #define DYLD_IOS_VERSION_8_2 0x00080200
216 #define DYLD_IOS_VERSION_8_3 0x00080300
217 #define DYLD_IOS_VERSION_8_4 0x00080400
218 #define DYLD_IOS_VERSION_9_0 0x00090000
219 #define DYLD_IOS_VERSION_9_1 0x00090100
220 #define DYLD_IOS_VERSION_9_2 0x00090200
221 #define DYLD_IOS_VERSION_9_3 0x00090300
222 #define DYLD_IOS_VERSION_10_0 0x000A0000
223
224
225 #define DYLD_WATCHOS_VERSION_1_0 0x00010000
226 #define DYLD_WATCHOS_VERSION_2_0 0x00020000
227 #define DYLD_WATCHOS_VERSION_2_1 0x00020100
228 #define DYLD_WATCHOS_VERSION_2_2 0x00020200
229 #define DYLD_WATCHOS_VERSION_3_0 0x00030000
230
231
232
233 //
234 // This finds the SDK version a binary was built against.
235 // Returns zero on error, or if SDK version could not be determined.
236 //
237 // Exists in Mac OS X 10.8 and later
238 // Exists in iOS 6.0 and later
239 extern uint32_t dyld_get_sdk_version(const struct mach_header* mh);
240
241
242 //
243 // This finds the SDK version that the main executable was built against.
244 // Returns zero on error, or if SDK version could not be determined.
245 //
246 // Note on WatchOS, this returns the equivalent iOS SDK version number
247 // (i.e an app built against WatchOS 2.0 SDK returne 9.0). To see the
248 // platform specific sdk version use dyld_get_program_sdk_watch_os_version().
249 //
250 // Exists in Mac OS X 10.8 and later
251 // Exists in iOS 6.0 and later
252 extern uint32_t dyld_get_program_sdk_version();
253
254
255 // Watch OS only.
256 // This finds the Watch OS SDK version that the main executable was built against.
257 // Exists in Watch OS 2.0 and later
258 extern uint32_t dyld_get_program_sdk_watch_os_version(); // __WATCHOS_AVAILABLE(2.0);
259
260
261 // Watch OS only.
262 // This finds the Watch min OS version that the main executable was built to run on.
263 // Note: dyld_get_program_min_os_version() returns the iOS equivalent (e.g. 9.0)
264 // whereas this returns the raw watchOS version (e.g. 2.0).
265 // Exists in Watch OS 3.0 and later
266 extern uint32_t dyld_get_program_min_watch_os_version(); // __WATCHOS_AVAILABLE(3.0);
267
268
269 //
270 // This finds the min OS version a binary was built to run on.
271 // Returns zero on error, or if no min OS recorded in binary.
272 //
273 // Exists in Mac OS X 10.8 and later
274 // Exists in iOS 6.0 and later
275 extern uint32_t dyld_get_min_os_version(const struct mach_header* mh);
276
277
278 //
279 // This finds the min OS version the main executable was built to run on.
280 // Returns zero on error, or if no min OS recorded in binary.
281 //
282 // Exists in Mac OS X 10.8 and later
283 // Exists in iOS 6.0 and later
284 extern uint32_t dyld_get_program_min_os_version();
285
286
287
288
289 //
290 // Returns if any OS dylib has overridden its copy in the shared cache
291 //
292 // Exists in iPhoneOS 3.1 and later
293 // Exists in Mac OS X 10.10 and later
294 extern bool dyld_shared_cache_some_image_overridden();
295
296
297
298 //
299 // Returns if the process is setuid or is code signed with entitlements.
300 //
301 // Exists in Mac OS X 10.9 and later
302 extern bool dyld_process_is_restricted();
303
304
305
306 //
307 // Returns path used by dyld for standard dyld shared cache file for the current arch.
308 //
309 // Exists in Mac OS X 10.11 and later
310 extern const char* dyld_shared_cache_file_path();
311
312
313
314 //
315 // <rdar://problem/13820686> for OpenGL to tell dyld it is ok to deallocate a memory based image when done.
316 //
317 // Exists in Mac OS X 10.9 and later
318 #define NSLINKMODULE_OPTION_CAN_UNLOAD 0x20
319
320
321 //
322 // Update all bindings on specified image.
323 // Looks for uses of 'replacement' and changes it to 'replacee'.
324 // NOTE: this is less safe than using static interposing via DYLD_INSERT_LIBRARIES
325 // because the running program may have already copy the pointer values to other
326 // locations that dyld does not know about.
327 //
328 struct dyld_interpose_tuple {
329 const void* replacement;
330 const void* replacee;
331 };
332 extern void dyld_dynamic_interpose(const struct mach_header* mh, const struct dyld_interpose_tuple array[], size_t count);
333
334
335 struct dyld_shared_cache_dylib_text_info {
336 uint64_t version; // current version 1
337 // following fields all exist in version 1
338 uint64_t loadAddressUnslid;
339 uint64_t textSegmentSize;
340 uuid_t dylibUuid;
341 const char* path; // pointer invalid at end of iterations
342 };
343 typedef struct dyld_shared_cache_dylib_text_info dyld_shared_cache_dylib_text_info;
344
345 //
346 // Given the UUID of a dyld shared cache file, this function will attempt to locate the cache
347 // file and if found iterate all images, returning info about each one. Returns 0 on success.
348 //
349 // Exists in Mac OS X 10.11 and later
350 // iOS 9.0 and later
351 extern int dyld_shared_cache_iterate_text(const uuid_t cacheUuid, void (^callback)(const dyld_shared_cache_dylib_text_info* info));
352
353
354 //
355 // Given the UUID of a dyld shared cache file, and a NULL terminated array of extra directory paths to search,
356 // this function will scan the standard and extra directories looking for a cache file that matches the UUID
357 // and if found iterate all images, returning info about each one. Returns 0 on success.
358 //
359 // Exists in Mac OS X 10.12 and later
360 // iOS 10.0 and later
361 extern int dyld_shared_cache_find_iterate_text(const uuid_t cacheUuid, const char* extraSearchDirs[], void (^callback)(const dyld_shared_cache_dylib_text_info* info));
362
363
364 //
365 // Returns if the specified address range is in a dyld owned memory
366 // that is mapped read-only and will never be unloaded.
367 //
368 // Exists in Mac OS X 10.12 and later
369 // iOS 10.0 and later
370 extern bool _dyld_is_memory_immutable(const void* addr, size_t length);
371
372
373 //
374 // Finds the UUID (from LC_UUID load command) of given image.
375 // Returns false if LC_UUID is missing or mach_header is malformed.
376 //
377 // Exists in Mac OS X 10.12 and later
378 // Exists in iOS 10.0 and later
379 extern bool _dyld_get_image_uuid(const struct mach_header* mh, uuid_t uuid);
380
381
382 //
383 // Gets the UUID of the dyld shared cache in the current process.
384 // Returns false if there is no dyld shared cache in use by the processes.
385 //
386 // Exists in Mac OS X 10.12 and later
387 // Exists in iOS 10.0 and later
388 extern bool _dyld_get_shared_cache_uuid(uuid_t uuid);
389
390
391
392 //
393 // When dyld must terminate a process because of a required dependent dylib
394 // could not be loaded or a symbol is missing, dyld calls abort_with_reason()
395 // using one of the following error codes.
396 //
397 #define DYLD_EXIT_REASON_DYLIB_MISSING 1
398 #define DYLD_EXIT_REASON_DYLIB_WRONG_ARCH 2
399 #define DYLD_EXIT_REASON_DYLIB_WRONG_VERSION 3
400 #define DYLD_EXIT_REASON_SYMBOL_MISSING 4
401 #define DYLD_EXIT_REASON_CODE_SIGNATURE 5
402 #define DYLD_EXIT_REASON_FILE_SYSTEM_SANDBOX 6
403 #define DYLD_EXIT_REASON_MALFORMED_MACHO 7
404 #define DYLD_EXIT_REASON_OTHER 9
405
406 //
407 // When it has more information about the termination, dyld will use abort_with_payload().
408 // The payload is a dyld_abort_payload structure. The fixed fields are offsets into the
409 // payload for the corresponding string. If the offset is zero, that string is not available.
410 //
411 struct dyld_abort_payload {
412 uint32_t version; // first version is 1
413 uint32_t flags; // 0x00000001 means dyld terminated at launch, backtrace not useful
414 uint32_t targetDylibPathOffset; // offset in payload of path string to dylib that could not be loaded
415 uint32_t clientPathOffset; // offset in payload of path string to image requesting dylib
416 uint32_t symbolOffset; // offset in payload of symbol string that could not be found
417 // string data
418 };
419 typedef struct dyld_abort_payload dyld_abort_payload;
420
421 #if __cplusplus
422 }
423 #endif /* __cplusplus */
424
425 #endif /* _MACH_O_DYLD_PRIV_H_ */