dyld-195.5.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 #if __IPHONE_OS_VERSION_MIN_REQUIRED
182 //
183 // Returns if any OS dylib has overridden its copy in the shared cache
184 //
185 // Exists in iPhoneOS 3.1 and later
186 extern bool dyld_shared_cache_some_image_overridden();
187 #endif
188
189
190
191 #if __cplusplus
192 }
193 #endif /* __cplusplus */
194
195 #endif /* _MACH_O_DYLD_PRIV_H_ */