2 * Copyright (c) 1999-2008 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 #ifndef _MACH_O_DYLD_H_
24 #define _MACH_O_DYLD_H_
31 #include <mach-o/loader.h>
32 #include <Availability.h>
39 * The following functions allow you to iterate through all loaded images.
40 * This is not a thread safe operation. Another thread can add or remove
41 * an image during the iteration.
43 * Many uses of these routines can be replace by a call to dladdr() which
44 * will return the mach_header and name of an image, given an address in
45 * the image. dladdr() is thread safe.
47 extern uint32_t _dyld_image_count(void) __OSX_AVAILABLE_STARTING(__MAC_10_1
, __IPHONE_2_0
);
48 extern const struct mach_header
* _dyld_get_image_header(uint32_t image_index
) __OSX_AVAILABLE_STARTING(__MAC_10_1
, __IPHONE_2_0
);
49 extern intptr_t _dyld_get_image_vmaddr_slide(uint32_t image_index
) __OSX_AVAILABLE_STARTING(__MAC_10_1
, __IPHONE_2_0
);
50 extern const char* _dyld_get_image_name(uint32_t image_index
) __OSX_AVAILABLE_STARTING(__MAC_10_1
, __IPHONE_2_0
);
54 * The following functions allow you to install callbacks which will be called
55 * by dyld whenever an image is loaded or unloaded. During a call to _dyld_register_func_for_add_image()
56 * the callback func is called for every existing image. Later, it is called as each new image
57 * is loaded and bound (but initializers not yet run). The callback registered with
58 * _dyld_register_func_for_remove_image() is called after any terminators in an image are run
59 * and before the image is un-memory-mapped.
61 extern void _dyld_register_func_for_add_image(void (*func
)(const struct mach_header
* mh
, intptr_t vmaddr_slide
)) __OSX_AVAILABLE_STARTING(__MAC_10_1
, __IPHONE_2_0
);
62 extern void _dyld_register_func_for_remove_image(void (*func
)(const struct mach_header
* mh
, intptr_t vmaddr_slide
)) __OSX_AVAILABLE_STARTING(__MAC_10_1
, __IPHONE_2_0
);
66 * NSVersionOfRunTimeLibrary() returns the current_version number of the currently dylib
67 * specifed by the libraryName. The libraryName parameter would be "bar" for /path/libbar.3.dylib and
68 * "Foo" for /path/Foo.framework/Versions/A/Foo. It returns -1 if no such library is loaded.
70 extern int32_t NSVersionOfRunTimeLibrary(const char* libraryName
) __OSX_AVAILABLE_STARTING(__MAC_10_1
, __IPHONE_2_0
);
74 * NSVersionOfRunTimeLibrary() returns the current_version number that the main executable was linked
75 * against at build time. The libraryName parameter would be "bar" for /path/libbar.3.dylib and
76 * "Foo" for /path/Foo.framework/Versions/A/Foo. It returns -1 if the main executable did not link
77 * against the specified library.
79 extern int32_t NSVersionOfLinkTimeLibrary(const char* libraryName
) __OSX_AVAILABLE_STARTING(__MAC_10_1
, __IPHONE_2_0
);
83 * _NSGetExecutablePath() copies the path of the main executable into the buffer. The bufsize parameter
84 * should initially be the size of the buffer. The function returns 0 if the path was successfully copied.
85 * It returns -1 if the buffer is not large enough, and *bufsize is set to the size required.
87 * Note that _NSGetExecutablePath will return "a path" to the executable not a "real path" to the executable.
88 * That is the path may be a symbolic link and not the real file. With deep directories the total bufsize
89 * needed could be more than MAXPATHLEN.
91 extern int _NSGetExecutablePath(char* buf
, uint32_t* bufsize
) __OSX_AVAILABLE_STARTING(__MAC_10_2
, __IPHONE_2_0
);
96 * _dyld_moninit() and _dyld_func_lookup() are private interface between
99 extern void _dyld_moninit(void (*monaddition
)(char *lowpc
, char *highpc
)) __OSX_AVAILABLE_STARTING(__MAC_10_1
, __IPHONE_2_0
);
100 extern int _dyld_func_lookup(const char* dyld_func_name
, void **address
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_6
,__IPHONE_NA
,__IPHONE_NA
);
107 * The following dyld API's are deprecated as of Mac OS X 10.5. They are either
108 * no longer necessary or are superceeded by dlopen and friends in <dlfcn.h>.
109 * dlopen/dlsym/dlclose have been available since Mac OS X 10.3 and work with
110 * dylibs and bundles.
112 * NSAddImage -> dlopen
113 * NSLookupSymbolInImage -> dlsym
114 * NSCreateObjectFileImageFromFile -> dlopen
115 * NSDestroyObjectFileImage -> dlclose
116 * NSLinkModule -> not needed when dlopen used
117 * NSUnLinkModule -> not needed when dlclose used
118 * NSLookupSymbolInModule -> dlsym
119 * _dyld_image_containing_address -> dladdr
120 * NSLinkEditError -> dlerror
124 #ifndef ENUM_DYLD_BOOL
125 #define ENUM_DYLD_BOOL
128 enum DYLD_BOOL
{ FALSE
, TRUE
};
129 #endif /* ENUM_DYLD_BOOL */
132 /* Object file image API */
134 NSObjectFileImageFailure
, /* for this a message is printed on stderr */
135 NSObjectFileImageSuccess
,
136 NSObjectFileImageInappropriateFile
,
137 NSObjectFileImageArch
,
138 NSObjectFileImageFormat
, /* for this a message is printed on stderr */
139 NSObjectFileImageAccess
140 } NSObjectFileImageReturnCode
;
142 typedef struct __NSObjectFileImage
* NSObjectFileImage
;
144 /* NSObjectFileImage can only be used with MH_BUNDLE files */
145 extern NSObjectFileImageReturnCode
NSCreateObjectFileImageFromFile(const char* pathName
, NSObjectFileImage
*objectFileImage
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
146 extern NSObjectFileImageReturnCode
NSCreateObjectFileImageFromMemory(const void *address
, size_t size
, NSObjectFileImage
*objectFileImage
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
147 extern bool NSDestroyObjectFileImage(NSObjectFileImage objectFileImage
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
149 extern uint32_t NSSymbolDefinitionCountInObjectFileImage(NSObjectFileImage objectFileImage
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
150 extern const char* NSSymbolDefinitionNameInObjectFileImage(NSObjectFileImage objectFileImage
, uint32_t ordinal
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
151 extern uint32_t NSSymbolReferenceCountInObjectFileImage(NSObjectFileImage objectFileImage
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
152 extern const char* NSSymbolReferenceNameInObjectFileImage(NSObjectFileImage objectFileImage
, uint32_t ordinal
, bool *tentative_definition
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
153 extern bool NSIsSymbolDefinedInObjectFileImage(NSObjectFileImage objectFileImage
, const char* symbolName
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_4
,__IPHONE_NA
,__IPHONE_NA
);
154 extern void* NSGetSectionDataInObjectFileImage(NSObjectFileImage objectFileImage
, const char* segmentName
, const char* sectionName
, size_t *size
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
155 extern bool NSHasModInitObjectFileImage(NSObjectFileImage objectFileImage
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_3
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
157 typedef struct __NSModule
* NSModule
;
158 extern const char* NSNameOfModule(NSModule m
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
159 extern const char* NSLibraryNameForModule(NSModule m
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
161 extern NSModule
NSLinkModule(NSObjectFileImage objectFileImage
, const char* moduleName
, uint32_t options
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
162 #define NSLINKMODULE_OPTION_NONE 0x0
163 #define NSLINKMODULE_OPTION_BINDNOW 0x1
164 #define NSLINKMODULE_OPTION_PRIVATE 0x2
165 #define NSLINKMODULE_OPTION_RETURN_ON_ERROR 0x4
166 #define NSLINKMODULE_OPTION_DONT_CALL_MOD_INIT_ROUTINES 0x8
167 #define NSLINKMODULE_OPTION_TRAILING_PHYS_NAME 0x10
169 extern bool NSUnLinkModule(NSModule module
, uint32_t options
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
170 #define NSUNLINKMODULE_OPTION_NONE 0x0
171 #define NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED 0x1
172 #define NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES 0x2
175 typedef struct __NSSymbol
* NSSymbol
;
176 extern bool NSIsSymbolNameDefined(const char* symbolName
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_4
,__IPHONE_NA
,__IPHONE_NA
);
177 extern bool NSIsSymbolNameDefinedWithHint(const char* symbolName
, const char* libraryNameHint
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_4
,__IPHONE_NA
,__IPHONE_NA
);
178 extern bool NSIsSymbolNameDefinedInImage(const struct mach_header
* image
, const char* symbolName
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_4
,__IPHONE_NA
,__IPHONE_NA
);
179 extern NSSymbol
NSLookupAndBindSymbol(const char* symbolName
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_4
,__IPHONE_NA
,__IPHONE_NA
);
180 extern NSSymbol
NSLookupAndBindSymbolWithHint(const char* symbolName
, const char* libraryNameHint
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_4
,__IPHONE_NA
,__IPHONE_NA
);
181 extern NSSymbol
NSLookupSymbolInModule(NSModule module
, const char* symbolName
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
182 extern NSSymbol
NSLookupSymbolInImage(const struct mach_header
* image
, const char* symbolName
, uint32_t options
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
183 #define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND 0x0
184 #define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW 0x1
185 #define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_FULLY 0x2
186 #define NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 0x4
187 extern const char* NSNameOfSymbol(NSSymbol symbol
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
188 extern void * NSAddressOfSymbol(NSSymbol symbol
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
189 extern NSModule
NSModuleForSymbol(NSSymbol symbol
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
191 /* error handling API */
193 NSLinkEditFileAccessError
,
194 NSLinkEditFileFormatError
,
195 NSLinkEditMachResourceError
,
196 NSLinkEditUnixResourceError
,
197 NSLinkEditOtherError
,
198 NSLinkEditWarningError
,
199 NSLinkEditMultiplyDefinedError
,
200 NSLinkEditUndefinedError
204 * For the NSLinkEditErrors value NSLinkEditOtherError these are the values
205 * passed to the link edit error handler as the errorNumber (what would be an
206 * errno value for NSLinkEditUnixResourceError or a kern_return_t value for
207 * NSLinkEditMachResourceError).
210 NSOtherErrorRelocation
,
211 NSOtherErrorLazyBind
,
212 NSOtherErrorIndrLoop
,
213 NSOtherErrorLazyInit
,
214 NSOtherErrorInvalidArgs
215 } NSOtherErrorNumbers
;
217 extern void NSLinkEditError(NSLinkEditErrors
*c
, int *errorNumber
, const char** fileName
, const char** errorString
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
220 void (*undefined
)(const char* symbolName
);
221 NSModule (*multiple
)(NSSymbol s
, NSModule oldModule
, NSModule newModule
);
222 void (*linkEdit
)(NSLinkEditErrors errorClass
, int errorNumber
,
223 const char* fileName
, const char* errorString
);
224 } NSLinkEditErrorHandlers
;
226 extern void NSInstallLinkEditErrorHandlers(const NSLinkEditErrorHandlers
*handlers
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
228 extern bool NSAddLibrary(const char* pathName
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_4
,__IPHONE_NA
,__IPHONE_NA
);
229 extern bool NSAddLibraryWithSearching(const char* pathName
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_4
,__IPHONE_NA
,__IPHONE_NA
);
230 extern const struct mach_header
* NSAddImage(const char* image_name
, uint32_t options
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
231 #define NSADDIMAGE_OPTION_NONE 0x0
232 #define NSADDIMAGE_OPTION_RETURN_ON_ERROR 0x1
233 #define NSADDIMAGE_OPTION_WITH_SEARCHING 0x2
234 #define NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED 0x4
235 #define NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME 0x8
237 extern bool _dyld_present(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
238 extern bool _dyld_launched_prebound(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
239 extern bool _dyld_all_twolevel_modules_prebound(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_3
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
240 extern void _dyld_bind_objc_module(const void* objc_module
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
241 extern bool _dyld_bind_fully_image_containing_address(const void* address
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
242 extern bool _dyld_image_containing_address(const void* address
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_3
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
243 extern void _dyld_lookup_and_bind(const char* symbol_name
, void **address
, NSModule
* module
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_4
,__IPHONE_NA
,__IPHONE_NA
);
244 extern void _dyld_lookup_and_bind_with_hint(const char* symbol_name
, const char* library_name_hint
, void** address
, NSModule
* module
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_4
,__IPHONE_NA
,__IPHONE_NA
);
245 extern void _dyld_lookup_and_bind_fully(const char* symbol_name
, void** address
, NSModule
* module
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
247 extern const struct mach_header
* _dyld_get_image_header_containing_address(const void* address
) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_3
,__MAC_10_5
,__IPHONE_NA
,__IPHONE_NA
);
254 #endif /* _MACH_O_DYLD_H_ */