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
);
45 // _dyld_moninit() is a private interface between libSystem.dylib and dyld
47 extern void _dyld_moninit(void (*monaddition
)(char *lowpc
, char *highpc
));
50 // private interface between libSystem.dylib and dyld
52 extern void _dyld_fork_child();
56 // Possible state changes for which you can register to be notified
58 enum dyld_image_states
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
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
75 typedef const char* (*dyld_image_state_change_handler
)(enum dyld_image_states state
, uint32_t infoCount
, const struct dyld_image_info info
[]);
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
87 dyld_register_image_state_change_handler(enum dyld_image_states state
, bool batch
, dyld_image_state_change_handler handler
);
91 // Possible thread-local variable state changes for which you can register to be notified
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
99 // Info about thread-local variable storage.
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
110 // Callback that notes changes to thread-local variable storage.
112 typedef void (^dyld_tlv_state_change_handler
)(enum dyld_tlv_states state
, const dyld_tlv_info
*info
);
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
123 dyld_register_tlv_state_change_handler(enum dyld_tlv_states state
, dyld_tlv_state_change_handler handler
);
126 // Enumerate the current thread-local variable storage allocated for the current thread.
127 // Exists in Mac OS X 10.7 and later
130 dyld_enumerate_tlv_storage(dyld_tlv_state_change_handler handler
);
136 // get slide for a given loaded mach_header
137 // Mac OS X 10.6 and later
139 extern intptr_t _dyld_get_image_slide(const struct mach_header
* mh
);
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
147 const struct dyld_all_image_infos
* _dyld_get_all_image_infos();
151 struct dyld_unwind_sections
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
;
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
169 // Exists in Mac OS X 10.6 and later
170 extern bool _dyld_find_unwind_sections(void* addr
, struct dyld_unwind_sections
* info
);
174 // This is an optimized form of dladdr() that only returns the dli_fname field.
176 // Exists in Mac OS X 10.6 and later
177 extern const char* dyld_image_path_containing_address(const void* addr
);
181 #if __IPHONE_OS_VERSION_MIN_REQUIRED
183 // Returns if any OS dylib has overridden its copy in the shared cache
185 // Exists in iPhoneOS 3.1 and later
186 extern bool dyld_shared_cache_some_image_overridden();
193 #endif /* __cplusplus */
195 #endif /* _MACH_O_DYLD_PRIV_H_ */