Chameleon

Chameleon Svn Source Tree

Root/branches/xZenu/src/include/mach-o/dyld.h

Source at commit 1322 created 12 years 9 months ago.
By meklort, Add doxygen to utils folder
1/*
2 * Copyright (c) 1999-2008 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23#ifndef _MACH_O_DYLD_H_
24#define _MACH_O_DYLD_H_
25
26
27#include <stddef.h>
28#include <stdint.h>
29#include <stdbool.h>
30
31#include <mach-o/loader.h>
32
33#if __cplusplus
34extern "C" {
35#endif
36
37/*
38 * The following functions allow you to iterate through all loaded images.
39 * This is not a thread safe operation. Another thread can add or remove
40 * an image during the iteration.
41 *
42 * Many uses of these routines can be replace by a call to dladdr() which
43 * will return the mach_header and name of an image, given an address in
44 * the image. dladdr() is thread safe.
45 */
46 extern uint32_t _dyld_image_count(void);
47 extern const struct mach_header* _dyld_get_image_header(uint32_t image_index);
48 extern intptr_t _dyld_get_image_vmaddr_slide(uint32_t image_index);
49 extern const char* _dyld_get_image_name(uint32_t image_index);
50
51
52/*
53 * The following functions allow you to install callbacks which will be called
54 * by dyld whenever an image is loaded or unloaded. During a call to _dyld_register_func_for_add_image()
55 * the callback func is called for every existing image. Later, it is called as each new image
56 * is loaded and bound (but initializers not yet run). The callback registered with
57 * _dyld_register_func_for_remove_image() is called after any terminators in an image are run
58 * and before the image is un-memory-mapped.
59 */
60 extern void _dyld_register_func_for_add_image(void (*func)(const struct mach_header* mh, intptr_t vmaddr_slide));
61 extern void _dyld_register_func_for_remove_image(void (*func)(const struct mach_header* mh, intptr_t vmaddr_slide));
62
63
64/*
65 * NSVersionOfRunTimeLibrary() returns the current_version number of the currently dylib
66 * specifed by the libraryName. The libraryName parameter would be "bar" for /path/libbar.3.dylib and
67 * "Foo" for /path/Foo.framework/Versions/A/Foo. It returns -1 if no such library is loaded.
68 */
69 extern int32_t NSVersionOfRunTimeLibrary(const char* libraryName);
70
71
72/*
73 * NSVersionOfRunTimeLibrary() returns the current_version number that the main executable was linked
74 * against at build time. The libraryName parameter would be "bar" for /path/libbar.3.dylib and
75 * "Foo" for /path/Foo.framework/Versions/A/Foo. It returns -1 if the main executable did not link
76 * against the specified library.
77 */
78 extern int32_t NSVersionOfLinkTimeLibrary(const char* libraryName);
79
80
81/*
82 * _NSGetExecutablePath() copies the path of the main executable into the buffer. The bufsize parameter
83 * should initially be the size of the buffer. The function returns 0 if the path was successfully copied,
84 * and *bufsize is left unchanged. It returns -1 if the buffer is not large enough, and *bufsize is set
85 * to the size required.
86 *
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.
90 */
91 extern int _NSGetExecutablePath(char* buf, uint32_t* bufsize);
92
93
94
95/*
96 * _dyld_moninit() is a private interface between dyld and libSystem.
97 */
98 extern void _dyld_moninit(void (*monaddition)(char *lowpc, char *highpc));
99
100
101
102
103
104/*
105 * The following dyld API's are deprecated as of Mac OS X 10.5. They are either
106 * no longer necessary or are superceeded by dlopen and friends in <dlfcn.h>.
107 * dlopen/dlsym/dlclose have been available since Mac OS X 10.3 and work with
108 * dylibs and bundles.
109 *
110 * NSAddImage -> dlopen
111 * NSLookupSymbolInImage -> dlsym
112 * NSCreateObjectFileImageFromFile -> dlopen
113 * NSDestroyObjectFileImage -> dlclose
114 * NSLinkModule -> not needed when dlopen used
115 * NSUnLinkModule -> not needed when dlclose used
116 * NSLookupSymbolInModule -> dlsym
117 * _dyld_image_containing_address -> dladdr
118 * NSLinkEditError -> dlerror
119 *
120 */
121
122#ifndef ENUM_DYLD_BOOL
123#define ENUM_DYLD_BOOL
124 #undef FALSE
125 #undef TRUE
126 enum DYLD_BOOL { FALSE, TRUE };
127#endif /* ENUM_DYLD_BOOL */
128
129
130/* Object file image API */
131typedef enum {
132 NSObjectFileImageFailure, /* for this a message is printed on stderr */
133 NSObjectFileImageSuccess,
134 NSObjectFileImageInappropriateFile,
135 NSObjectFileImageArch,
136 NSObjectFileImageFormat, /* for this a message is printed on stderr */
137 NSObjectFileImageAccess
138} NSObjectFileImageReturnCode;
139
140typedef struct __NSObjectFileImage* NSObjectFileImage;
141
142/* NSObjectFileImage can only be used with MH_BUNDLE files */
143 extern NSObjectFileImageReturnCode NSCreateObjectFileImageFromFile(const char* pathName, NSObjectFileImage *objectFileImage);
144 extern NSObjectFileImageReturnCode NSCreateObjectFileImageFromMemory(const void *address, size_t size, NSObjectFileImage *objectFileImage);
145 extern bool NSDestroyObjectFileImage(NSObjectFileImage objectFileImage);
146
147 extern uint32_t NSSymbolDefinitionCountInObjectFileImage(NSObjectFileImage objectFileImage);
148 extern const char* NSSymbolDefinitionNameInObjectFileImage(NSObjectFileImage objectFileImage, uint32_t ordinal);
149 extern uint32_t NSSymbolReferenceCountInObjectFileImage(NSObjectFileImage objectFileImage);
150 extern const char* NSSymbolReferenceNameInObjectFileImage(NSObjectFileImage objectFileImage, uint32_t ordinal, bool *tentative_definition);
151 extern bool NSIsSymbolDefinedInObjectFileImage(NSObjectFileImage objectFileImage, const char* symbolName);
152 extern void* NSGetSectionDataInObjectFileImage(NSObjectFileImage objectFileImage, const char* segmentName, const char* sectionName, size_t *size);
153 extern bool NSHasModInitObjectFileImage(NSObjectFileImage objectFileImage);
154
155typedef struct __NSModule* NSModule;
156 extern const char* NSNameOfModule(NSModule m);
157 extern const char* NSLibraryNameForModule(NSModule m);
158
159 extern NSModule NSLinkModule(NSObjectFileImage objectFileImage, const char* moduleName, uint32_t options);
160#define NSLINKMODULE_OPTION_NONE 0x0
161#define NSLINKMODULE_OPTION_BINDNOW 0x1
162#define NSLINKMODULE_OPTION_PRIVATE 0x2
163#define NSLINKMODULE_OPTION_RETURN_ON_ERROR 0x4
164#define NSLINKMODULE_OPTION_DONT_CALL_MOD_INIT_ROUTINES 0x8
165#define NSLINKMODULE_OPTION_TRAILING_PHYS_NAME 0x10
166
167 extern bool NSUnLinkModule(NSModule module, uint32_t options);
168#define NSUNLINKMODULE_OPTION_NONE 0x0
169#define NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED 0x1
170#define NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES0x2
171
172/* symbol API */
173typedef struct __NSSymbol* NSSymbol;
174 extern bool NSIsSymbolNameDefined(const char* symbolName);
175 extern bool NSIsSymbolNameDefinedWithHint(const char* symbolName, const char* libraryNameHint);
176 extern bool NSIsSymbolNameDefinedInImage(const struct mach_header* image, const char* symbolName);
177 extern NSSymbol NSLookupAndBindSymbol(const char* symbolName);
178 extern NSSymbol NSLookupAndBindSymbolWithHint(const char* symbolName, const char* libraryNameHint);
179 extern NSSymbol NSLookupSymbolInModule(NSModule module, const char* symbolName);
180 extern NSSymbol NSLookupSymbolInImage(const struct mach_header* image, const char* symbolName, uint32_t options);
181#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND 0x0
182#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW 0x1
183#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_FULLY 0x2
184#define NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 0x4
185 extern const char* NSNameOfSymbol(NSSymbol symbol);
186 extern void * NSAddressOfSymbol(NSSymbol symbol);
187 extern NSModule NSModuleForSymbol(NSSymbol symbol);
188
189/* error handling API */
190typedef enum {
191 NSLinkEditFileAccessError,
192 NSLinkEditFileFormatError,
193 NSLinkEditMachResourceError,
194 NSLinkEditUnixResourceError,
195 NSLinkEditOtherError,
196 NSLinkEditWarningError,
197 NSLinkEditMultiplyDefinedError,
198 NSLinkEditUndefinedError
199} NSLinkEditErrors;
200
201/*
202 * For the NSLinkEditErrors value NSLinkEditOtherError these are the values
203 * passed to the link edit error handler as the errorNumber (what would be an
204 * errno value for NSLinkEditUnixResourceError or a kern_return_t value for
205 * NSLinkEditMachResourceError).
206 */
207typedef enum {
208 NSOtherErrorRelocation,
209 NSOtherErrorLazyBind,
210 NSOtherErrorIndrLoop,
211 NSOtherErrorLazyInit,
212 NSOtherErrorInvalidArgs
213} NSOtherErrorNumbers;
214
215 extern void NSLinkEditError(NSLinkEditErrors *c, int *errorNumber, const char** fileName, const char** errorString);
216
217typedef struct {
218 void (*undefined)(const char* symbolName);
219 NSModule (*multiple)(NSSymbol s, NSModule oldModule, NSModule newModule);
220 void (*linkEdit)(NSLinkEditErrors errorClass, int errorNumber,
221 const char* fileName, const char* errorString);
222} NSLinkEditErrorHandlers;
223
224 extern void NSInstallLinkEditErrorHandlers(const NSLinkEditErrorHandlers *handlers);
225
226 extern bool NSAddLibrary(const char* pathName) ;
227 extern bool NSAddLibraryWithSearching(const char* pathName) ;
228 extern const struct mach_header* NSAddImage(const char* image_name, uint32_t options) ;
229#define NSADDIMAGE_OPTION_NONE 0x0
230#define NSADDIMAGE_OPTION_RETURN_ON_ERROR 0x1
231#define NSADDIMAGE_OPTION_WITH_SEARCHING 0x2
232#define NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED 0x4
233#define NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME0x8
234
235 extern bool _dyld_present(void) ;
236 extern bool _dyld_launched_prebound(void) ;
237 extern bool _dyld_all_twolevel_modules_prebound(void) ;
238 extern void _dyld_bind_objc_module(const void* objc_module) ;
239 extern bool _dyld_bind_fully_image_containing_address(const void* address) ;
240 extern bool _dyld_image_containing_address(const void* address) ;
241 extern void _dyld_lookup_and_bind(const char* symbol_name, void **address, NSModule* module) ;
242 extern void _dyld_lookup_and_bind_with_hint(const char* symbol_name, const char* library_name_hint, void** address, NSModule* module);
243 extern void _dyld_lookup_and_bind_fully(const char* symbol_name, void** address, NSModule* module);
244 extern const struct mach_header* _dyld_get_image_header_containing_address(const void* address);
245
246
247#if __cplusplus
248}
249#endif
250
251#endif /* _MACH_O_DYLD_H_ */
252

Archive Download this file

Revision: 1322