dyld-239.3.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 //
45 // _dyld_moninit() is a private interface between libSystem.dylib and dyld
46 //
47 extern void _dyld_moninit(void (*monaddition)(char *lowpc, char *highpc));
48
49 //
50 // private interface between libSystem.dylib and dyld
51 //
52 extern void _dyld_fork_child();
53
54
55 //
56 // Possible state changes for which you can register to be notified
57 //
58 enum dyld_image_states
59 {
60 dyld_image_state_mapped = 10, // No batch notification for this
61 dyld_image_state_dependents_mapped = 20, // Only batch notification for this
62 dyld_image_state_rebased = 30,
63 dyld_image_state_bound = 40,
64 dyld_image_state_dependents_initialized = 45, // Only single notification for this
65 dyld_image_state_initialized = 50,
66 dyld_image_state_terminated = 60 // Only single notification for this
67 };
68
69 //
70 // Callback that provides a bottom-up array of images
71 // For dyld_image_state_[dependents_]mapped state only, returning non-NULL will cause dyld to abort loading all those images
72 // and append the returned string to its load failure error message. dyld does not free the string, so
73 // it should be a literal string or a static buffer
74 //
75 typedef const char* (*dyld_image_state_change_handler)(enum dyld_image_states state, uint32_t infoCount, const struct dyld_image_info info[]);
76
77 //
78 // Register a handler to be called when any image changes to the requested state.
79 // If 'batch' is true, the callback is called with an array of all images that are in the requested state sorted by dependency.
80 // If 'batch' is false, the callback is called with one image at a time as each image transitions to the the requested state.
81 // During the call to this function, the handler may be called back with existing images and the handler should
82 // not return a string, since there is no load to abort. In batch mode, existing images at or past the request
83 // state supplied in the callback. In non-batch mode, the callback is called for each image exactly in the
84 // requested state.
85 //
86 extern void
87 dyld_register_image_state_change_handler(enum dyld_image_states state, bool batch, dyld_image_state_change_handler handler);
88
89
90 //
91 // Possible thread-local variable state changes for which you can register to be notified
92 //
93 enum dyld_tlv_states {
94 dyld_tlv_state_allocated = 10, // TLV range newly allocated
95 dyld_tlv_state_deallocated = 20 // TLV range about to be deallocated
96 };
97
98 //
99 // Info about thread-local variable storage.
100 //
101 typedef struct {
102 size_t info_size; // sizeof(dyld_tlv_info)
103 void * tlv_addr; // Base address of TLV storage
104 size_t tlv_size; // Byte size of TLV storage
105 } dyld_tlv_info;
106
107 #if __BLOCKS__
108
109 //
110 // Callback that notes changes to thread-local variable storage.
111 //
112 typedef void (^dyld_tlv_state_change_handler)(enum dyld_tlv_states state, const dyld_tlv_info *info);
113
114 //
115 // Register a handler to be called when a thread adds or removes storage for thread-local variables.
116 // The registered handler will only be called from and on behalf of the thread that owns the storage.
117 // The registered handler will NOT be called for any storage that was
118 // already allocated before dyld_register_tlv_state_change_handler() was
119 // called. Use dyld_enumerate_tlv_storage() to get that information.
120 // Exists in Mac OS X 10.7 and later
121 //
122 extern void
123 dyld_register_tlv_state_change_handler(enum dyld_tlv_states state, dyld_tlv_state_change_handler handler);
124
125 //
126 // Enumerate the current thread-local variable storage allocated for the current thread.
127 // Exists in Mac OS X 10.7 and later
128 //
129 extern void
130 dyld_enumerate_tlv_storage(dyld_tlv_state_change_handler handler);
131
132 #endif
133
134
135 //
136 // get slide for a given loaded mach_header
137 // Mac OS X 10.6 and later
138 //
139 extern intptr_t _dyld_get_image_slide(const struct mach_header* mh);
140
141
142 //
143 // get pointer to this process's dyld_all_image_infos
144 // Exists in Mac OS X 10.4 and later through _dyld_func_lookup()
145 // Exists in Mac OS X 10.6 and later through libSystem.dylib
146 //
147 const struct dyld_all_image_infos* _dyld_get_all_image_infos();
148
149
150
151 struct dyld_unwind_sections
152 {
153 const struct mach_header* mh;
154 const void* dwarf_section;
155 uintptr_t dwarf_section_length;
156 const void* compact_unwind_section;
157 uintptr_t compact_unwind_section_length;
158 };
159
160
161 //
162 // Returns true iff some loaded mach-o image contains "addr".
163 // info->mh mach header of image containing addr
164 // info->dwarf_section pointer to start of __TEXT/__eh_frame section
165 // info->dwarf_section_length length of __TEXT/__eh_frame section
166 // info->compact_unwind_section pointer to start of __TEXT/__unwind_info section
167 // info->compact_unwind_section_length length of __TEXT/__unwind_info section
168 //
169 // Exists in Mac OS X 10.6 and later
170 extern bool _dyld_find_unwind_sections(void* addr, struct dyld_unwind_sections* info);
171
172
173 //
174 // This is an optimized form of dladdr() that only returns the dli_fname field.
175 //
176 // Exists in Mac OS X 10.6 and later
177 extern const char* dyld_image_path_containing_address(const void* addr);
178
179
180
181 // Convienence constants for return values from dyld_get_sdk_version() and friends.
182 #define DYLD_MACOSX_VERSION_10_4 0x000A0400
183 #define DYLD_MACOSX_VERSION_10_5 0x000A0500
184 #define DYLD_MACOSX_VERSION_10_6 0x000A0600
185 #define DYLD_MACOSX_VERSION_10_7 0x000A0700
186 #define DYLD_MACOSX_VERSION_10_8 0x000A0800
187 #define DYLD_MACOSX_VERSION_10_9 0x000A0900
188
189 #define DYLD_IOS_VERSION_2_0 0x00020000
190 #define DYLD_IOS_VERSION_2_1 0x00020100
191 #define DYLD_IOS_VERSION_2_2 0x00020200
192 #define DYLD_IOS_VERSION_3_0 0x00030000
193 #define DYLD_IOS_VERSION_3_1 0x00030100
194 #define DYLD_IOS_VERSION_3_2 0x00030200
195 #define DYLD_IOS_VERSION_4_0 0x00040000
196 #define DYLD_IOS_VERSION_4_1 0x00040100
197 #define DYLD_IOS_VERSION_4_2 0x00040200
198 #define DYLD_IOS_VERSION_4_3 0x00040300
199 #define DYLD_IOS_VERSION_5_0 0x00050000
200 #define DYLD_IOS_VERSION_5_1 0x00050100
201 #define DYLD_IOS_VERSION_6_0 0x00060000
202 #define DYLD_IOS_VERSION_6_1 0x00060100
203 #define DYLD_IOS_VERSION_7_0 0x00070000
204
205 //
206 // This is finds the SDK version a binary was built against.
207 // Returns zero on error, or if SDK version could not be determined.
208 //
209 // Exists in Mac OS X 10.8 and later
210 // Exists in iOS 6.0 and later
211 extern uint32_t dyld_get_sdk_version(const struct mach_header* mh);
212
213
214 //
215 // This is finds the SDK version the main executable was built against.
216 // Returns zero on error, or if SDK version could not be determined.
217 //
218 // Exists in Mac OS X 10.8 and later
219 // Exists in iOS 6.0 and later
220 extern uint32_t dyld_get_program_sdk_version();
221
222
223 //
224 // This is finds the min OS version a binary was built to run on.
225 // Returns zero on error, or if no min OS recorded in binary.
226 //
227 // Exists in Mac OS X 10.8 and later
228 // Exists in iOS 6.0 and later
229 extern uint32_t dyld_get_min_os_version(const struct mach_header* mh);
230
231
232 //
233 // This is finds the min OS version the main executable was built to run on.
234 // Returns zero on error, or if no min OS recorded in binary.
235 //
236 // Exists in Mac OS X 10.8 and later
237 // Exists in iOS 6.0 and later
238 extern uint32_t dyld_get_program_min_os_version();
239
240
241
242
243 #if __IPHONE_OS_VERSION_MIN_REQUIRED
244 //
245 // Returns if any OS dylib has overridden its copy in the shared cache
246 //
247 // Exists in iPhoneOS 3.1 and later
248 extern bool dyld_shared_cache_some_image_overridden();
249 #endif
250
251
252
253 //
254 // Returns if the process is setuid or is code signed with entitlements.
255 //
256 // Exists in Mac OS X 10.9 and later
257 extern bool dyld_process_is_restricted();
258
259
260 //
261 // <rdar://problem/13820686> for OpenGL to tell dyld it is ok to deallocate a memory based image when done.
262 //
263 // Exists in Mac OS X 10.9 and later
264 #define NSLINKMODULE_OPTION_CAN_UNLOAD 0x20
265
266
267
268 #if __cplusplus
269 }
270 #endif /* __cplusplus */
271
272 #endif /* _MACH_O_DYLD_PRIV_H_ */