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 // Possible state changes for which you can register to be notified
52 enum dyld_image_states
54 dyld_image_state_mapped
= 10, // No batch notification for this
55 dyld_image_state_dependents_mapped
= 20, // Only batch notification for this
56 dyld_image_state_rebased
= 30,
57 dyld_image_state_bound
= 40,
58 dyld_image_state_dependents_initialized
= 45, // Only single notification for this
59 dyld_image_state_initialized
= 50,
60 dyld_image_state_terminated
= 60 // Only single notification for this
64 // Callback that provides a bottom-up array of images
65 // For dyld_image_state_[dependents_]mapped state only, returning non-NULL will cause dyld to abort loading all those images
66 // and append the returned string to its load failure error message. dyld does not free the string, so
67 // it should be a literal string or a static buffer
69 typedef const char* (*dyld_image_state_change_handler
)(enum dyld_image_states state
, uint32_t infoCount
, const struct dyld_image_info info
[]);
72 // Register a handler to be called when any image changes to the requested state.
73 // If 'batch' is true, the callback is called with an array of all images that are in the requested state sorted by dependency.
74 // If 'batch' is false, the callback is called with one image at a time as each image transitions to the the requested state.
75 // During the call to this function, the handler may be called back with existing images and the handler should
76 // not return a string, since there is no load to abort. In batch mode, existing images at or past the request
77 // state supplied in the callback. In non-batch mode, the callback is called for each image exactly in the
81 dyld_register_image_state_change_handler(enum dyld_image_states state
, bool batch
, dyld_image_state_change_handler handler
);
85 // Possible thread-local variable state changes for which you can register to be notified
87 enum dyld_tlv_states
{
88 dyld_tlv_state_allocated
= 10, // TLV range newly allocated
89 dyld_tlv_state_deallocated
= 20 // TLV range about to be deallocated
93 // Info about thread-local variable storage.
96 size_t info_size
; // sizeof(dyld_tlv_info)
97 void * tlv_addr
; // Base address of TLV storage
98 size_t tlv_size
; // Byte size of TLV storage
104 // Callback that notes changes to thread-local variable storage.
106 typedef void (^dyld_tlv_state_change_handler
)(enum dyld_tlv_states state
, const dyld_tlv_info
*info
);
109 // Register a handler to be called when a thread adds or removes storage for thread-local variables.
110 // The registered handler will only be called from and on behalf of the thread that owns the storage.
111 // The registered handler will NOT be called for any storage that was
112 // already allocated before dyld_register_tlv_state_change_handler() was
113 // called. Use dyld_enumerate_tlv_storage() to get that information.
114 // Exists in Mac OS X 10.7 and later
117 dyld_register_tlv_state_change_handler(enum dyld_tlv_states state
, dyld_tlv_state_change_handler handler
);
120 // Enumerate the current thread-local variable storage allocated for the current thread.
121 // Exists in Mac OS X 10.7 and later
124 dyld_enumerate_tlv_storage(dyld_tlv_state_change_handler handler
);
130 // get slide for a given loaded mach_header
131 // Mac OS X 10.6 and later
133 extern intptr_t _dyld_get_image_slide(const struct mach_header
* mh
);
137 // get pointer to this process's dyld_all_image_infos
138 // Exists in Mac OS X 10.4 and later through _dyld_func_lookup()
139 // Exists in Mac OS X 10.6 and later through libSystem.dylib
141 const struct dyld_all_image_infos
* _dyld_get_all_image_infos();
145 struct dyld_unwind_sections
147 const struct mach_header
* mh
;
148 const void* dwarf_section
;
149 uintptr_t dwarf_section_length
;
150 const void* compact_unwind_section
;
151 uintptr_t compact_unwind_section_length
;
156 // Returns true iff some loaded mach-o image contains "addr".
157 // info->mh mach header of image containing addr
158 // info->dwarf_section pointer to start of __TEXT/__eh_frame section
159 // info->dwarf_section_length length of __TEXT/__eh_frame section
160 // info->compact_unwind_section pointer to start of __TEXT/__unwind_info section
161 // info->compact_unwind_section_length length of __TEXT/__unwind_info section
163 // Exists in Mac OS X 10.6 and later
164 extern bool _dyld_find_unwind_sections(void* addr
, struct dyld_unwind_sections
* info
);
168 // This is an optimized form of dladdr() that only returns the dli_fname field.
170 // Exists in Mac OS X 10.6 and later
171 extern const char* dyld_image_path_containing_address(const void* addr
);
175 // This is an optimized form of dladdr() that only returns the dli_fbase field.
176 // Return NULL, if address is not in any image tracked by dyld.
178 // Exists in Mac OS X 10.11 and later
179 extern const struct mach_header
* dyld_image_header_containing_address(const void* addr
);
183 // Convienence constants for return values from dyld_get_sdk_version() and friends.
184 #define DYLD_MACOSX_VERSION_10_4 0x000A0400
185 #define DYLD_MACOSX_VERSION_10_5 0x000A0500
186 #define DYLD_MACOSX_VERSION_10_6 0x000A0600
187 #define DYLD_MACOSX_VERSION_10_7 0x000A0700
188 #define DYLD_MACOSX_VERSION_10_8 0x000A0800
189 #define DYLD_MACOSX_VERSION_10_9 0x000A0900
190 #define DYLD_MACOSX_VERSION_10_10 0x000A0A00
191 #define DYLD_MACOSX_VERSION_10_11 0x000A0B00
193 #define DYLD_IOS_VERSION_2_0 0x00020000
194 #define DYLD_IOS_VERSION_2_1 0x00020100
195 #define DYLD_IOS_VERSION_2_2 0x00020200
196 #define DYLD_IOS_VERSION_3_0 0x00030000
197 #define DYLD_IOS_VERSION_3_1 0x00030100
198 #define DYLD_IOS_VERSION_3_2 0x00030200
199 #define DYLD_IOS_VERSION_4_0 0x00040000
200 #define DYLD_IOS_VERSION_4_1 0x00040100
201 #define DYLD_IOS_VERSION_4_2 0x00040200
202 #define DYLD_IOS_VERSION_4_3 0x00040300
203 #define DYLD_IOS_VERSION_5_0 0x00050000
204 #define DYLD_IOS_VERSION_5_1 0x00050100
205 #define DYLD_IOS_VERSION_6_0 0x00060000
206 #define DYLD_IOS_VERSION_6_1 0x00060100
207 #define DYLD_IOS_VERSION_7_0 0x00070000
208 #define DYLD_IOS_VERSION_7_1 0x00070100
209 #define DYLD_IOS_VERSION_8_0 0x00080000
210 #define DYLD_IOS_VERSION_8_1 0x00080100
211 #define DYLD_IOS_VERSION_8_2 0x00080200
212 #define DYLD_IOS_VERSION_9_0 0x00090000
216 // This finds the SDK version a binary was built against.
217 // Returns zero on error, or if SDK version could not be determined.
219 // Exists in Mac OS X 10.8 and later
220 // Exists in iOS 6.0 and later
221 extern uint32_t dyld_get_sdk_version(const struct mach_header
* mh
);
225 // This finds the SDK version that the main executable was built against.
226 // Returns zero on error, or if SDK version could not be determined.
228 // Note on WatchOS, this returns the equivalent iOS SDK version number
229 // (i.e an app built against WatchOS 2.0 SDK returne 9.0). To see the
230 // platform specific sdk version use dyld_get_program_sdk_watch_os_version().
232 // Exists in Mac OS X 10.8 and later
233 // Exists in iOS 6.0 and later
234 extern uint32_t dyld_get_program_sdk_version();
238 // This finds the Watch OS SDK version that the main executable was built against.
239 // Exists in Watch OS 2.0 and later
240 extern uint32_t dyld_get_program_sdk_watch_os_version(); // __WATCHOS_AVAILABLE(2.0);
244 // This finds the min OS version a binary was built to run on.
245 // Returns zero on error, or if no min OS recorded in binary.
247 // Exists in Mac OS X 10.8 and later
248 // Exists in iOS 6.0 and later
249 extern uint32_t dyld_get_min_os_version(const struct mach_header
* mh
);
253 // This finds the min OS version the main executable was built to run on.
254 // Returns zero on error, or if no min OS recorded in binary.
256 // Exists in Mac OS X 10.8 and later
257 // Exists in iOS 6.0 and later
258 extern uint32_t dyld_get_program_min_os_version();
264 // Returns if any OS dylib has overridden its copy in the shared cache
266 // Exists in iPhoneOS 3.1 and later
267 // Exists in Mac OS X 10.10 and later
268 extern bool dyld_shared_cache_some_image_overridden();
273 // Returns if the process is setuid or is code signed with entitlements.
275 // Exists in Mac OS X 10.9 and later
276 extern bool dyld_process_is_restricted();
281 // Returns path used by dyld for standard dyld shared cache file for the current arch.
283 // Exists in Mac OS X 10.11 and later
284 extern const char* dyld_shared_cache_file_path();
289 // <rdar://problem/13820686> for OpenGL to tell dyld it is ok to deallocate a memory based image when done.
291 // Exists in Mac OS X 10.9 and later
292 #define NSLINKMODULE_OPTION_CAN_UNLOAD 0x20
296 // Update all bindings on specified image.
297 // Looks for uses of 'replacement' and changes it to 'replacee'.
298 // NOTE: this is less safe than using static interposing via DYLD_INSERT_LIBRARIES
299 // because the running program may have already copy the pointer values to other
300 // locations that dyld does not know about.
302 struct dyld_interpose_tuple
{
303 const void* replacement
;
304 const void* replacee
;
306 extern void dyld_dynamic_interpose(const struct mach_header
* mh
, const struct dyld_interpose_tuple array
[], size_t count
);
312 #endif /* __cplusplus */
314 #endif /* _MACH_O_DYLD_PRIV_H_ */