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 // Convienence constants for return values from dyld_get_sdk_version() and friends.
176 #define DYLD_MACOSX_VERSION_10_4 0x000A0400
177 #define DYLD_MACOSX_VERSION_10_5 0x000A0500
178 #define DYLD_MACOSX_VERSION_10_6 0x000A0600
179 #define DYLD_MACOSX_VERSION_10_7 0x000A0700
180 #define DYLD_MACOSX_VERSION_10_8 0x000A0800
181 #define DYLD_MACOSX_VERSION_10_9 0x000A0900
182 #define DYLD_MACOSX_VERSION_10_10 0x000A0A00
184 #define DYLD_IOS_VERSION_2_0 0x00020000
185 #define DYLD_IOS_VERSION_2_1 0x00020100
186 #define DYLD_IOS_VERSION_2_2 0x00020200
187 #define DYLD_IOS_VERSION_3_0 0x00030000
188 #define DYLD_IOS_VERSION_3_1 0x00030100
189 #define DYLD_IOS_VERSION_3_2 0x00030200
190 #define DYLD_IOS_VERSION_4_0 0x00040000
191 #define DYLD_IOS_VERSION_4_1 0x00040100
192 #define DYLD_IOS_VERSION_4_2 0x00040200
193 #define DYLD_IOS_VERSION_4_3 0x00040300
194 #define DYLD_IOS_VERSION_5_0 0x00050000
195 #define DYLD_IOS_VERSION_5_1 0x00050100
196 #define DYLD_IOS_VERSION_6_0 0x00060000
197 #define DYLD_IOS_VERSION_6_1 0x00060100
198 #define DYLD_IOS_VERSION_7_0 0x00070000
199 #define DYLD_IOS_VERSION_7_1 0x00070100
200 #define DYLD_IOS_VERSION_8_0 0x00080000
203 // This is finds the SDK version a binary was built against.
204 // Returns zero on error, or if SDK version could not be determined.
206 // Exists in Mac OS X 10.8 and later
207 // Exists in iOS 6.0 and later
208 extern uint32_t dyld_get_sdk_version(const struct mach_header
* mh
);
212 // This is finds the SDK version the main executable was built against.
213 // Returns zero on error, or if SDK version could not be determined.
215 // Exists in Mac OS X 10.8 and later
216 // Exists in iOS 6.0 and later
217 extern uint32_t dyld_get_program_sdk_version();
221 // This is finds the min OS version a binary was built to run on.
222 // Returns zero on error, or if no min OS recorded in binary.
224 // Exists in Mac OS X 10.8 and later
225 // Exists in iOS 6.0 and later
226 extern uint32_t dyld_get_min_os_version(const struct mach_header
* mh
);
230 // This is finds the min OS version the main executable was built to run on.
231 // Returns zero on error, or if no min OS recorded in binary.
233 // Exists in Mac OS X 10.8 and later
234 // Exists in iOS 6.0 and later
235 extern uint32_t dyld_get_program_min_os_version();
241 // Returns if any OS dylib has overridden its copy in the shared cache
243 // Exists in iPhoneOS 3.1 and later
244 // Exists in Mac OS X 10.10 and later
245 extern bool dyld_shared_cache_some_image_overridden();
250 // Returns if the process is setuid or is code signed with entitlements.
252 // Exists in Mac OS X 10.9 and later
253 extern bool dyld_process_is_restricted();
257 // <rdar://problem/13820686> for OpenGL to tell dyld it is ok to deallocate a memory based image when done.
259 // Exists in Mac OS X 10.9 and later
260 #define NSLINKMODULE_OPTION_CAN_UNLOAD 0x20
264 // Update all bindings on specified image.
265 // Looks for uses of 'replacement' and changes it to 'replacee'.
266 // NOTE: this is less safe than using static interposing via DYLD_INSERT_LIBRARIES
267 // because the running program may have already copy the pointer values to other
268 // locations that dyld does not know about.
270 struct dyld_interpose_tuple
{
271 const void* replacement
;
272 const void* replacee
;
274 extern void dyld_dynamic_interpose(const struct mach_header
* mh
, const struct dyld_interpose_tuple array
[], size_t count
);
280 #endif /* __cplusplus */
282 #endif /* _MACH_O_DYLD_PRIV_H_ */