]> git.saurik.com Git - apple/dyld.git/blob - include/mach-o/dyld_priv.h
dyld-360.22.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 //
50 // Possible state changes for which you can register to be notified
51 //
52 enum dyld_image_states
53 {
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
61 };
62
63 //
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
68 //
69 typedef const char* (*dyld_image_state_change_handler)(enum dyld_image_states state, uint32_t infoCount, const struct dyld_image_info info[]);
70
71 //
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
78 // requested state.
79 //
80 extern void
81 dyld_register_image_state_change_handler(enum dyld_image_states state, bool batch, dyld_image_state_change_handler handler);
82
83
84 //
85 // Possible thread-local variable state changes for which you can register to be notified
86 //
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
90 };
91
92 //
93 // Info about thread-local variable storage.
94 //
95 typedef struct {
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
99 } dyld_tlv_info;
100
101 #if __BLOCKS__
102
103 //
104 // Callback that notes changes to thread-local variable storage.
105 //
106 typedef void (^dyld_tlv_state_change_handler)(enum dyld_tlv_states state, const dyld_tlv_info *info);
107
108 //
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
115 //
116 extern void
117 dyld_register_tlv_state_change_handler(enum dyld_tlv_states state, dyld_tlv_state_change_handler handler);
118
119 //
120 // Enumerate the current thread-local variable storage allocated for the current thread.
121 // Exists in Mac OS X 10.7 and later
122 //
123 extern void
124 dyld_enumerate_tlv_storage(dyld_tlv_state_change_handler handler);
125
126 #endif
127
128
129 //
130 // get slide for a given loaded mach_header
131 // Mac OS X 10.6 and later
132 //
133 extern intptr_t _dyld_get_image_slide(const struct mach_header* mh);
134
135
136 //
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
140 //
141 const struct dyld_all_image_infos* _dyld_get_all_image_infos();
142
143
144
145 struct dyld_unwind_sections
146 {
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;
152 };
153
154
155 //
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
162 //
163 // Exists in Mac OS X 10.6 and later
164 extern bool _dyld_find_unwind_sections(void* addr, struct dyld_unwind_sections* info);
165
166
167 //
168 // This is an optimized form of dladdr() that only returns the dli_fname field.
169 //
170 // Exists in Mac OS X 10.6 and later
171 extern const char* dyld_image_path_containing_address(const void* addr);
172
173
174 //
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.
177 //
178 // Exists in Mac OS X 10.11 and later
179 extern const struct mach_header* dyld_image_header_containing_address(const void* addr);
180
181
182
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
192
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
213
214
215 //
216 // This finds the SDK version a binary was built against.
217 // Returns zero on error, or if SDK version could not be determined.
218 //
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);
222
223
224 //
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.
227 //
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().
231 //
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();
235
236
237 // Watch OS only.
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);
241
242
243 //
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.
246 //
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);
250
251
252 //
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.
255 //
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();
259
260
261
262
263 //
264 // Returns if any OS dylib has overridden its copy in the shared cache
265 //
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();
269
270
271
272 //
273 // Returns if the process is setuid or is code signed with entitlements.
274 //
275 // Exists in Mac OS X 10.9 and later
276 extern bool dyld_process_is_restricted();
277
278
279
280 //
281 // Returns path used by dyld for standard dyld shared cache file for the current arch.
282 //
283 // Exists in Mac OS X 10.11 and later
284 extern const char* dyld_shared_cache_file_path();
285
286
287
288 //
289 // <rdar://problem/13820686> for OpenGL to tell dyld it is ok to deallocate a memory based image when done.
290 //
291 // Exists in Mac OS X 10.9 and later
292 #define NSLINKMODULE_OPTION_CAN_UNLOAD 0x20
293
294
295 //
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.
301 //
302 struct dyld_interpose_tuple {
303 const void* replacement;
304 const void* replacee;
305 };
306 extern void dyld_dynamic_interpose(const struct mach_header* mh, const struct dyld_interpose_tuple array[], size_t count);
307
308
309
310 #if __cplusplus
311 }
312 #endif /* __cplusplus */
313
314 #endif /* _MACH_O_DYLD_PRIV_H_ */