1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
3 * Copyright (c) 2003-2010 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@
24 #ifndef _MACH_O_DYLD_PRIV_H_
25 #define _MACH_O_DYLD_PRIV_H_
28 #include <Availability.h>
29 #include <mach-o/dyld.h>
30 #include <mach-o/dyld_images.h>
34 #endif /* __cplusplus */
39 // private interface between libSystem.dylib and dyld
41 extern int _dyld_func_lookup(const char* dyld_func_name
, void **address
);
44 // private interface between libSystem.dylib and dyld
46 extern void _dyld_fork_child();
50 enum dyld_image_states
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
62 typedef const char* (*dyld_image_state_change_handler
)(enum dyld_image_states state
, uint32_t infoCount
, const struct dyld_image_info info
[]);
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
);
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.
81 void _dyld_objc_notify_register(_dyld_objc_notify_mapped mapped
,
82 _dyld_objc_notify_init init
,
83 _dyld_objc_notify_unmapped unmapped
);
88 // Possible thread-local variable state changes for which you can register to be notified
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
96 // Info about thread-local variable storage.
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
107 // Callback that notes changes to thread-local variable storage.
109 typedef void (^dyld_tlv_state_change_handler
)(enum dyld_tlv_states state
, const dyld_tlv_info
*info
);
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
120 dyld_register_tlv_state_change_handler(enum dyld_tlv_states state
, dyld_tlv_state_change_handler handler
);
123 // Enumerate the current thread-local variable storage allocated for the current thread.
124 // Exists in Mac OS X 10.7 and later
127 dyld_enumerate_tlv_storage(dyld_tlv_state_change_handler handler
);
133 // get slide for a given loaded mach_header
134 // Mac OS X 10.6 and later
136 extern intptr_t _dyld_get_image_slide(const struct mach_header
* mh
);
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
144 const struct dyld_all_image_infos
* _dyld_get_all_image_infos() __attribute__((deprecated
));
148 struct dyld_unwind_sections
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
;
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
166 // Exists in Mac OS X 10.6 and later
167 extern bool _dyld_find_unwind_sections(void* addr
, struct dyld_unwind_sections
* info
);
171 // This is an optimized form of dladdr() that only returns the dli_fname field.
173 // Exists in Mac OS X 10.6 and later
174 extern const char* dyld_image_path_containing_address(const void* addr
);
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.
181 // Exists in Mac OS X 10.11 and later
182 extern const struct mach_header
* dyld_image_header_containing_address(const void* addr
);
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
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
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
234 // This finds the SDK version a binary was built against.
235 // Returns zero on error, or if SDK version could not be determined.
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
);
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.
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().
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();
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);
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);
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.
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
);
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.
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();
290 // Returns if any OS dylib has overridden its copy in the shared cache
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();
299 // Returns if the process is setuid or is code signed with entitlements.
301 // Exists in Mac OS X 10.9 and later
302 extern bool dyld_process_is_restricted();
307 // Returns path used by dyld for standard dyld shared cache file for the current arch.
309 // Exists in Mac OS X 10.11 and later
310 extern const char* dyld_shared_cache_file_path();
315 // <rdar://problem/13820686> for OpenGL to tell dyld it is ok to deallocate a memory based image when done.
317 // Exists in Mac OS X 10.9 and later
318 #define NSLINKMODULE_OPTION_CAN_UNLOAD 0x20
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.
328 struct dyld_interpose_tuple
{
329 const void* replacement
;
330 const void* replacee
;
332 extern void dyld_dynamic_interpose(const struct mach_header
* mh
, const struct dyld_interpose_tuple array
[], size_t count
);
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
;
341 const char* path
; // pointer invalid at end of iterations
343 typedef struct dyld_shared_cache_dylib_text_info dyld_shared_cache_dylib_text_info
;
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.
349 // Exists in Mac OS X 10.11 and later
351 extern int dyld_shared_cache_iterate_text(const uuid_t cacheUuid
, void (^callback
)(const dyld_shared_cache_dylib_text_info
* info
));
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.
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
));
365 // Returns if the specified address range is in a dyld owned memory
366 // that is mapped read-only and will never be unloaded.
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
);
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.
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
);
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.
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
);
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.
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
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.
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
419 typedef struct dyld_abort_payload dyld_abort_payload
;
423 #endif /* __cplusplus */
425 #endif /* _MACH_O_DYLD_PRIV_H_ */