1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
3 * Copyright (c) 2004-2009 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@
26 // This file implements that API's in <mach-o/dyld.h>
30 #define __STDC_LIMIT_MACROS
34 #include <sys/param.h>
35 #include <sys/mount.h>
36 #include <Availability.h>
43 #include <mach/mach.h>
45 #include <sys/sysctl.h>
46 #include <mach/mach_traps.h> // for task_self_trap()
49 #include "mach-o/dyld_images.h"
50 #include "mach-o/dyld.h"
51 #include "mach-o/dyld_priv.h"
53 #include "ImageLoader.h"
55 #include "dyldLibSystemInterface.h"
57 #undef _POSIX_C_SOURCE
60 // from dyldExceptions.c
61 extern "C" void __Unwind_SjLj_SetThreadKey(pthread_key_t key
);
64 extern void addImagesToAllImages(uint32_t infoCount
, const dyld_image_info info
[]);
66 // deprecated APIs are still availble on Mac OS X, but not on iPhone OS
67 #if __IPHONE_OS_VERSION_MIN_REQUIRED
68 #define DEPRECATED_APIS_SUPPORTED 0
70 #define DEPRECATED_APIS_SUPPORTED 1
73 static bool sDynamicInterposing
= false;
75 #if DEPRECATED_APIS_SUPPORTED
76 static char sLastErrorFilePath
[1024];
77 static NSLinkEditErrors sLastErrorFileCode
;
78 static int sLastErrorNo
;
81 // In 10.3.x and earlier all the NSObjectFileImage API's were implemeneted in libSystem.dylib
82 // Beginning in 10.4 the NSObjectFileImage API's are implemented in dyld and libSystem just forwards
83 // This conditional keeps support for old libSystem's which needed some help implementing the API's
84 #define OLD_LIBSYSTEM_SUPPORT (__i386__)
86 // The following functions have no prototype in any header. They are special cases
87 // where _dyld_func_lookup() is used directly.
88 static void _dyld_make_delayed_module_initializer_calls();
89 static void registerThreadHelpers(const dyld::LibSystemHelpers
*);
90 #if DEPRECATED_APIS_SUPPORTED
91 static void _dyld_install_handlers(void* undefined
, void* multiple
, void* linkEdit
);
92 #if OLD_LIBSYSTEM_SUPPORT
93 static NSModule
_dyld_link_module(NSObjectFileImage object_addr
, size_t object_size
, const char* moduleName
, uint32_t options
);
95 static void _dyld_register_binding_handler(void * (*)(const char *, const char *, void *), ImageLoader::BindingOptions
);
96 static bool NSMakePrivateModulePublic(NSModule
module);
97 static void _dyld_call_module_initializers_for_dylib(const struct mach_header
* mh_dylib_header
);
99 // The following functions are dyld API's, but since dyld links with a static copy of libc.a
100 // the public name cannot be used.
101 static void client_dyld_lookup_and_bind(const char* symbolName
, void** address
, NSModule
* module);
102 static bool client_NSIsSymbolNameDefined(const char* symbolName
);
103 #endif // DEPRECATED_APIS_SUPPORTED
104 #if SUPPORT_ZERO_COST_EXCEPTIONS
105 static bool client_dyld_find_unwind_sections(void* addr
, dyld_unwind_sections
* info
);
108 static void unimplemented()
110 dyld::halt("unimplemented dyld function\n");
115 void* implementation
;
118 static struct dyld_func dyld_funcs
[] = {
119 {"__dyld_register_func_for_add_image", (void*)_dyld_register_func_for_add_image
},
120 {"__dyld_register_func_for_remove_image", (void*)_dyld_register_func_for_remove_image
},
121 {"__dyld_dladdr", (void*)dladdr
},
122 {"__dyld_dlclose", (void*)dlclose
},
123 {"__dyld_dlerror", (void*)dlerror
},
124 {"__dyld_dlopen", (void*)dlopen
},
125 {"__dyld_dlsym", (void*)dlsym
},
126 {"__dyld_dlopen_preflight", (void*)dlopen_preflight
},
127 {"__dyld_image_count", (void*)_dyld_image_count
},
128 {"__dyld_get_image_header", (void*)_dyld_get_image_header
},
129 {"__dyld_get_image_vmaddr_slide", (void*)_dyld_get_image_vmaddr_slide
},
130 {"__dyld_get_image_name", (void*)_dyld_get_image_name
},
131 {"__dyld_get_image_slide", (void*)_dyld_get_image_slide
},
132 {"__dyld__NSGetExecutablePath", (void*)_NSGetExecutablePath
},
135 {"__dyld_dyld_register_image_state_change_handler", (void*)dyld_register_image_state_change_handler
},
136 {"__dyld_register_thread_helpers", (void*)registerThreadHelpers
},
137 {"__dyld_fork_child", (void*)_dyld_fork_child
},
138 {"__dyld_make_delayed_module_initializer_calls", (void*)_dyld_make_delayed_module_initializer_calls
},
139 {"__dyld_get_all_image_infos", (void*)_dyld_get_all_image_infos
},
140 #if SUPPORT_ZERO_COST_EXCEPTIONS
141 {"__dyld_find_unwind_sections", (void*)client_dyld_find_unwind_sections
},
143 #if __i386__ || __x86_64__ || __arm__ || __arm64__
144 {"__dyld_fast_stub_entry", (void*)dyld::fastBindLazySymbol
},
146 {"__dyld_image_path_containing_address", (void*)dyld_image_path_containing_address
},
147 {"__dyld_shared_cache_some_image_overridden", (void*)dyld_shared_cache_some_image_overridden
},
148 {"__dyld_process_is_restricted", (void*)dyld::processIsRestricted
},
149 {"__dyld_dynamic_interpose", (void*)dyld_dynamic_interpose
},
150 #if DYLD_SHARED_CACHE_SUPPORT
151 {"__dyld_shared_cache_file_path", (void*)dyld::getStandardSharedCacheFilePath
},
153 {"__dyld_get_image_header_containing_address", (void*)dyld_image_header_containing_address
},
156 #if DEPRECATED_APIS_SUPPORTED
157 {"__dyld_lookup_and_bind", (void*)client_dyld_lookup_and_bind
},
158 {"__dyld_lookup_and_bind_with_hint", (void*)_dyld_lookup_and_bind_with_hint
},
159 {"__dyld_lookup_and_bind_fully", (void*)_dyld_lookup_and_bind_fully
},
160 {"__dyld_install_handlers", (void*)_dyld_install_handlers
},
161 {"__dyld_link_edit_error", (void*)NSLinkEditError
},
162 {"__dyld_unlink_module", (void*)NSUnLinkModule
},
163 {"__dyld_bind_objc_module", (void*)_dyld_bind_objc_module
},
164 {"__dyld_bind_fully_image_containing_address", (void*)_dyld_bind_fully_image_containing_address
},
165 {"__dyld_image_containing_address", (void*)_dyld_image_containing_address
},
166 {"__dyld_register_binding_handler", (void*)_dyld_register_binding_handler
},
167 {"__dyld_NSNameOfSymbol", (void*)NSNameOfSymbol
},
168 {"__dyld_NSAddressOfSymbol", (void*)NSAddressOfSymbol
},
169 {"__dyld_NSModuleForSymbol", (void*)NSModuleForSymbol
},
170 {"__dyld_NSLookupAndBindSymbol", (void*)NSLookupAndBindSymbol
},
171 {"__dyld_NSLookupAndBindSymbolWithHint", (void*)NSLookupAndBindSymbolWithHint
},
172 {"__dyld_NSLookupSymbolInModule", (void*)NSLookupSymbolInModule
},
173 {"__dyld_NSLookupSymbolInImage", (void*)NSLookupSymbolInImage
},
174 {"__dyld_NSMakePrivateModulePublic", (void*)NSMakePrivateModulePublic
},
175 {"__dyld_NSIsSymbolNameDefined", (void*)client_NSIsSymbolNameDefined
},
176 {"__dyld_NSIsSymbolNameDefinedWithHint", (void*)NSIsSymbolNameDefinedWithHint
},
177 {"__dyld_NSIsSymbolNameDefinedInImage", (void*)NSIsSymbolNameDefinedInImage
},
178 {"__dyld_NSNameOfModule", (void*)NSNameOfModule
},
179 {"__dyld_NSLibraryNameForModule", (void*)NSLibraryNameForModule
},
180 {"__dyld_NSAddLibrary", (void*)NSAddLibrary
},
181 {"__dyld_NSAddLibraryWithSearching", (void*)NSAddLibraryWithSearching
},
182 {"__dyld_NSAddImage", (void*)NSAddImage
},
183 {"__dyld_launched_prebound", (void*)_dyld_launched_prebound
},
184 {"__dyld_all_twolevel_modules_prebound", (void*)_dyld_all_twolevel_modules_prebound
},
185 {"__dyld_call_module_initializers_for_dylib", (void*)_dyld_call_module_initializers_for_dylib
},
186 {"__dyld_NSCreateObjectFileImageFromFile", (void*)NSCreateObjectFileImageFromFile
},
187 {"__dyld_NSCreateObjectFileImageFromMemory", (void*)NSCreateObjectFileImageFromMemory
},
188 {"__dyld_NSDestroyObjectFileImage", (void*)NSDestroyObjectFileImage
},
189 {"__dyld_NSLinkModule", (void*)NSLinkModule
},
190 {"__dyld_NSHasModInitObjectFileImage", (void*)NSHasModInitObjectFileImage
},
191 {"__dyld_NSSymbolDefinitionCountInObjectFileImage", (void*)NSSymbolDefinitionCountInObjectFileImage
},
192 {"__dyld_NSSymbolDefinitionNameInObjectFileImage", (void*)NSSymbolDefinitionNameInObjectFileImage
},
193 {"__dyld_NSIsSymbolDefinedInObjectFileImage", (void*)NSIsSymbolDefinedInObjectFileImage
},
194 {"__dyld_NSSymbolReferenceNameInObjectFileImage", (void*)NSSymbolReferenceNameInObjectFileImage
},
195 {"__dyld_NSSymbolReferenceCountInObjectFileImage", (void*)NSSymbolReferenceCountInObjectFileImage
},
196 {"__dyld_NSGetSectionDataInObjectFileImage", (void*)NSGetSectionDataInObjectFileImage
},
197 #if OLD_LIBSYSTEM_SUPPORT
198 {"__dyld_link_module", (void*)_dyld_link_module
},
200 #endif //DEPRECATED_APIS_SUPPORTED
207 #if DEPRECATED_APIS_SUPPORTED
209 static void dyldAPIhalt(const char* apiName
, const char* errorMsg
)
211 dyld::log("dyld: %s() error\n", apiName
);
212 dyld::halt(errorMsg
);
215 // dyld's abstract type NSSymbol is implemented as const ImageLoader::Symbol*
216 inline NSSymbol
SymbolToNSSymbol(const ImageLoader::Symbol
* sym
)
218 return (NSSymbol
)sym
;
220 inline const ImageLoader::Symbol
* NSSymbolToSymbol(NSSymbol sym
)
222 return (const ImageLoader::Symbol
*)sym
;
225 // dyld's abstract type NSModule is implemented as ImageLoader*
226 inline NSModule
ImageLoaderToNSModule(const ImageLoader
* image
)
228 return (NSModule
)image
;
230 inline ImageLoader
* NSModuleToImageLoader(NSModule
module)
232 ImageLoader
* image
= (ImageLoader
*)module;
233 if ( dyld::validImage(image
) )
238 // actual definition for opaque type
239 struct __NSObjectFileImage
242 const void* imageBaseAddress
; // not used with OFI created from files
243 size_t imageLength
; // not used with OFI created from files
247 VECTOR_NEVER_DESTRUCTED(NSObjectFileImage
);
248 static std::vector
<NSObjectFileImage
> sObjectFileImages
;
253 // __NSObjectFileImage are deleted in NSDestroyObjectFileImage()
254 // The contained image is delete in one of two places:
255 // NSUnLinkModule deletes the image if there is no __NSObjectFileImage with a reference to it
256 // NSDestroyObjectFileImage deletes the image if image is not in list of valid images
261 static void setLastError(NSLinkEditErrors code
, int errnum
, const char* file
, const char* message
)
263 dyld::setErrorMessage(message
);
264 strncpy(sLastErrorFilePath
, file
, 1024);
265 sLastErrorFilePath
[1023] = '\0';
266 sLastErrorFileCode
= code
;
267 sLastErrorNo
= errnum
;
270 #endif // DEPRECATED_APIS_SUPPORTED
273 *_dyld_NSGetExecutablePath is the dyld side of _NSGetExecutablePath which
274 * copies the path of the executable into the buffer and returns 0 if the path
275 * was successfully copied in the provided buffer. If the buffer is not large
276 * enough, -1 is returned and the expected buffer size is copied in *bufsize.
277 * Note that _NSGetExecutablePath will return "a path" to the executable not a
278 * "real path" to the executable. That is the path may be a symbolic link and
279 * not the real file. And with deep directories the total bufsize needed could
280 * be more than MAXPATHLEN.
282 int _NSGetExecutablePath(char* buf
, uint32_t *bufsize
)
284 if ( dyld::gLogAPIs
)
285 dyld::log("%s(...)\n", __func__
);
286 const char* exePath
= dyld::getExecutablePath();
287 if(*bufsize
< strlen(exePath
) + 1){
288 *bufsize
= (uint32_t)(strlen(exePath
) + 1);
291 strcpy(buf
, exePath
);
295 uint32_t _dyld_image_count(void)
297 if ( dyld::gLogAPIs
)
298 dyld::log("%s()\n", __func__
);
299 return dyld::getImageCount();
302 const struct mach_header
* _dyld_get_image_header(uint32_t image_index
)
304 if ( dyld::gLogAPIs
)
305 dyld::log("%s(%u)\n", __func__
, image_index
);
306 ImageLoader
* image
= dyld::getIndexedImage(image_index
);
308 return (struct mach_header
*)image
->machHeader();
313 intptr_t _dyld_get_image_vmaddr_slide(uint32_t image_index
)
315 if ( dyld::gLogAPIs
)
316 dyld::log("%s(%u)\n", __func__
, image_index
);
317 ImageLoader
* image
= dyld::getIndexedImage(image_index
);
319 return image
->getSlide();
324 intptr_t _dyld_get_image_slide(const struct mach_header
* mh
)
326 if ( dyld::gLogAPIs
)
327 dyld::log("%s(%p)\n", __func__
, mh
);
328 ImageLoader
* image
= dyld::findImageByMachHeader(mh
);
330 return image
->getSlide();
336 const char* _dyld_get_image_name(uint32_t image_index
)
338 if ( dyld::gLogAPIs
)
339 dyld::log("%s(%u)\n", __func__
, image_index
);
340 ImageLoader
* image
= dyld::getIndexedImage(image_index
);
342 return image
->getRealPath();
347 const struct mach_header
* dyld_image_header_containing_address(const void* address
)
349 if ( dyld::gLogAPIs
)
350 dyld::log("%s(%p)\n", __func__
, address
);
351 ImageLoader
* image
= dyld::findImageContainingAddress(address
);
353 return image
->machHeader();
358 void _dyld_register_func_for_add_image(void (*func
)(const struct mach_header
*mh
, intptr_t vmaddr_slide
))
360 if ( dyld::gLogAPIs
)
361 dyld::log("%s(%p)\n", __func__
, (void *)func
);
362 dyld::registerAddCallback(func
);
365 void _dyld_register_func_for_remove_image(void (*func
)(const struct mach_header
*mh
, intptr_t vmaddr_slide
))
367 if ( dyld::gLogAPIs
)
368 dyld::log("%s(%p)\n", __func__
, (void *)func
);
369 dyld::registerRemoveCallback(func
);
374 // called by crt before main() by programs linked with 10.4 or earlier crt1.o
375 static void _dyld_make_delayed_module_initializer_calls()
377 if ( dyld::gLogAPIs
)
378 dyld::log("%s()\n", __func__
);
380 #if SUPPORT_OLD_CRT_INITIALIZATION
381 if ( dyld::gRunInitializersOldWay
)
382 dyld::initializeMainExecutable();
388 #if DEPRECATED_APIS_SUPPORTED
391 // _dyld_call_module_initializers_for_dylib() is the dyld side of
392 // __initialize_Cplusplus() which is in dylib1.o.
393 // It is intended to only be called inside -init rouintes.
394 // -init routines are called before module initializers (what C++
395 // initializers use). Calling __initialize_Cplusplus() in a -init
396 // routine causes the module initializers for an image to be called
397 // which then allows C++ to be used inside a -init routine
399 static void _dyld_call_module_initializers_for_dylib(const struct mach_header
* mh_dylib_header
)
401 if ( dyld::gLogAPIs
)
402 dyld::log("__initialize_Cplusplus()\n");
404 // for now, do nothing...
408 void _dyld_lookup_and_bind_fully(const char* symbolName
, void** address
, NSModule
* module)
410 if ( dyld::gLogAPIs
)
411 dyld::log("%s(\"%s\", %p, %p)\n", __func__
, symbolName
, address
, module);
413 const ImageLoader::Symbol
* sym
;
414 dyld::clearErrorMessage();
415 if ( dyld::flatFindExportedSymbol(symbolName
, &sym
, (const ImageLoader
**)&image
) ) {
417 image
->bindAllLazyPointers(dyld::gLinkContext
, true);
418 if ( address
!= NULL
)
419 *address
= (void*)image
->getExportedSymbolAddress(sym
, dyld::gLinkContext
);
421 *module = ImageLoaderToNSModule(image
);
423 catch (const char* msg
) {
424 dyldAPIhalt(__func__
, msg
);
428 // on failure to find symbol return NULLs
429 if ( address
!= NULL
)
436 // Note: This cannot have public name because dyld is built with a static copy of libc.a
437 // which calls dyld_lookup_and_bind() and expects to find dyld's symbols not host process
438 static void client_dyld_lookup_and_bind(const char* symbolName
, void** address
, NSModule
* module)
440 if ( dyld::gLogAPIs
)
441 dyld::log("_dyld_lookup_and_bind(\"%s\", %p, %p)\n", symbolName
, address
, module);
442 const ImageLoader
* image
;
443 const ImageLoader::Symbol
* sym
;
444 if ( dyld::flatFindExportedSymbol(symbolName
, &sym
, &image
) ) {
445 if ( address
!= NULL
)
446 *address
= (void*)image
->getExportedSymbolAddress(sym
, dyld::gLinkContext
);
448 *module = ImageLoaderToNSModule(image
);
451 // on failure to find symbol return NULLs
452 if ( address
!= NULL
)
459 void _dyld_lookup_and_bind_with_hint(const char* symbolName
, const char* library_name_hint
, void** address
, NSModule
* module)
461 if ( dyld::gLogAPIs
)
462 dyld::log("%s(\"%s\", \"%s\", %p, %p)\n", __func__
, symbolName
, library_name_hint
, address
, module);
463 const ImageLoader
* image
;
464 const ImageLoader::Symbol
* sym
;
465 // Look for library whose path contains the hint. If that fails search everywhere
466 if ( dyld::flatFindExportedSymbolWithHint(symbolName
, library_name_hint
, &sym
, &image
)
467 || dyld::flatFindExportedSymbol(symbolName
, &sym
, &image
) ) {
468 if ( address
!= NULL
)
469 *address
= (void*)image
->getExportedSymbolAddress(sym
, dyld::gLinkContext
);
471 *module = ImageLoaderToNSModule(image
);
474 // on failure to find symbol return NULLs
475 if ( address
!= NULL
)
483 NSSymbol
NSLookupAndBindSymbol(const char *symbolName
)
485 if ( dyld::gLogAPIs
)
486 dyld::log("%s(\"%s\")\n", __func__
, symbolName
);
487 const ImageLoader
* image
;
488 const ImageLoader::Symbol
* sym
;
489 if ( dyld::flatFindExportedSymbol(symbolName
, &sym
, &image
) ) {
490 return SymbolToNSSymbol(sym
);
492 // return NULL on failure
496 NSSymbol
NSLookupAndBindSymbolWithHint(const char* symbolName
, const char* libraryNameHint
)
498 if ( dyld::gLogAPIs
)
499 dyld::log("%s(\"%s\", \"%s\")\n", __func__
, symbolName
, libraryNameHint
);
500 const ImageLoader
* image
;
501 const ImageLoader::Symbol
* sym
;
502 bool found
= dyld::flatFindExportedSymbolWithHint(symbolName
, libraryNameHint
, &sym
, &image
);
504 // hint failed, do slow search of all images
505 found
= dyld::flatFindExportedSymbol(symbolName
, &sym
, &image
);
508 return SymbolToNSSymbol(sym
);
510 // return NULL on failure and log
511 if ( dyld::gLogAPIs
)
512 dyld::log("%s(\"%s\", \"%s\") => NULL \n", __func__
, symbolName
, libraryNameHint
);
519 static __attribute__((noinline
))
520 const struct mach_header
* addImage(void* callerAddress
, const char* path
, bool search
, bool dontLoad
, bool matchInstallName
, bool abortOnError
)
522 ImageLoader
* image
= NULL
;
523 std::vector
<const char*> rpathsFromCallerImage
;
525 dyld::clearErrorMessage();
526 ImageLoader
* callerImage
= dyld::findImageContainingAddress(callerAddress
);
527 // like dlopen, use rpath from caller image and from main executable
528 if ( callerImage
!= NULL
)
529 callerImage
->getRPaths(dyld::gLinkContext
, rpathsFromCallerImage
);
530 ImageLoader::RPathChain
callersRPaths(NULL
, &rpathsFromCallerImage
);
531 if ( callerImage
!= dyld::mainExecutable() ) {
532 dyld::mainExecutable()->getRPaths(dyld::gLinkContext
, rpathsFromCallerImage
);
534 dyld::LoadContext context
;
535 context
.useSearchPaths
= search
;
536 context
.useFallbackPaths
= search
;
537 context
.useLdLibraryPath
= false;
538 context
.implicitRPath
= false;
539 context
.matchByInstallName
= matchInstallName
;
540 context
.dontLoad
= dontLoad
;
541 context
.mustBeBundle
= false;
542 context
.mustBeDylib
= true;
543 context
.canBePIE
= false;
544 context
.origin
= callerImage
!= NULL
? callerImage
->getPath() : NULL
; // caller's image's path
545 context
.rpath
= &callersRPaths
; // rpaths from caller and main executable
547 image
= load(path
, context
);
548 if ( image
!= NULL
) {
549 if ( context
.matchByInstallName
)
550 image
->setMatchInstallPath(true);
551 dyld::link(image
, false, false, callersRPaths
);
552 dyld::runInitializers(image
);
553 // images added with NSAddImage() can never be unloaded
554 image
->setNeverUnload();
557 catch (const char* msg
) {
558 dyld::garbageCollectImages();
560 char pathMsg
[strlen(msg
)+strlen(path
)+4];
561 strcpy(pathMsg
, msg
);
562 strcat(pathMsg
, " ");
563 strcat(pathMsg
, path
);
564 dyldAPIhalt("NSAddImage", pathMsg
);
566 // not halting, so set error state for NSLinkEditError to find
567 setLastError(NSLinkEditOtherError
, 0, path
, msg
);
568 free((void*)msg
); // our free() will do nothing if msg is a string literal
571 // free rpaths (getRPaths() malloc'ed each string)
572 for(std::vector
<const char*>::iterator it
=rpathsFromCallerImage
.begin(); it
!= rpathsFromCallerImage
.end(); ++it
) {
573 const char* str
= *it
;
579 return image
->machHeader();
583 const struct mach_header
* NSAddImage(const char* path
, uint32_t options
)
585 if ( dyld::gLogAPIs
)
586 dyld::log("%s(\"%s\", 0x%08X)\n", __func__
, path
, options
);
587 const bool dontLoad
= ( (options
& NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED
) != 0 );
588 const bool search
= ( (options
& NSADDIMAGE_OPTION_WITH_SEARCHING
) != 0 );
589 const bool matchInstallName
= ( (options
& NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME
) != 0 );
590 const bool abortOnError
= ( (options
& (NSADDIMAGE_OPTION_RETURN_ON_ERROR
|NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED
)) == 0 );
591 void* callerAddress
= __builtin_return_address(1); // note layers: 1: real client, 0: libSystem glue
592 return addImage(callerAddress
, path
, search
, dontLoad
, matchInstallName
, abortOnError
);
595 bool NSAddLibrary(const char* path
)
597 if ( dyld::gLogAPIs
)
598 dyld::log("%s(\"%s\")\n", __func__
, path
);
599 void* callerAddress
= __builtin_return_address(1); // note layers: 1: real client, 0: libSystem glue
600 return (addImage(callerAddress
, path
, false, false, false, false) != NULL
);
603 bool NSAddLibraryWithSearching(const char* path
)
605 if ( dyld::gLogAPIs
)
606 dyld::log("%s(\"%s\")\n", __func__
, path
);
607 void* callerAddress
= __builtin_return_address(1); // note layers: 1: real client, 0: libSystem glue
608 return (addImage(callerAddress
, path
, true, false, false, false) != NULL
);
613 //#define NSADDIMAGE_OPTION_NONE 0x0
614 //#define NSADDIMAGE_OPTION_RETURN_ON_ERROR 0x1
615 //#define NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME 0x8
617 bool NSIsSymbolNameDefinedInImage(const struct mach_header
* mh
, const char* symbolName
)
619 if ( dyld::gLogAPIs
)
620 dyld::log("%s(%p, \"%s\")\n", __func__
, (void *)mh
, symbolName
);
621 ImageLoader
* image
= dyld::findImageByMachHeader(mh
);
622 if ( image
!= NULL
) {
623 if ( image
->findExportedSymbol(symbolName
, true, NULL
) != NULL
)
630 NSSymbol
NSLookupSymbolInImage(const struct mach_header
* mh
, const char* symbolName
, uint32_t options
)
632 if ( dyld::gLogAPIs
)
633 dyld::log("%s(%p, \"%s\", 0x%08X)\n", __func__
, mh
, symbolName
, options
);
634 const ImageLoader::Symbol
* symbol
= NULL
;
635 dyld::clearErrorMessage();
636 ImageLoader
* image
= dyld::findImageByMachHeader(mh
);
637 if ( image
!= NULL
) {
639 if ( options
& NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_FULLY
) {
640 image
->bindAllLazyPointers(dyld::gLinkContext
, true);
642 else if ( options
& NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW
) {
643 image
->bindAllLazyPointers(dyld::gLinkContext
, false);
646 catch (const char* msg
) {
647 if ( (options
& NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR
) == 0 ) {
648 dyldAPIhalt(__func__
, msg
);
651 symbol
= image
->findExportedSymbol(symbolName
, true, NULL
);
653 if ( dyld::gLogAPIs
&& (symbol
== NULL
) )
654 dyld::log("%s(%p, \"%s\", 0x%08X) ==> NULL\n", __func__
, mh
, symbolName
, options
);
655 return SymbolToNSSymbol(symbol
);
659 // Note: This cannot have public name because dyld is built with a static copy of libc.a
660 // which calls NSIsSymbolNameDefined() and expects to find dyld's symbols not host process
661 static bool client_NSIsSymbolNameDefined(const char* symbolName
)
663 if ( dyld::gLogAPIs
)
664 dyld::log("NSIsSymbolNameDefined(\"%s\")\n", symbolName
);
665 const ImageLoader
* image
;
666 const ImageLoader::Symbol
* sym
;
667 return dyld::flatFindExportedSymbol(symbolName
, &sym
, &image
);
670 bool NSIsSymbolNameDefinedWithHint(const char* symbolName
, const char* libraryNameHint
)
672 if ( dyld::gLogAPIs
)
673 dyld::log("%s(\"%s\", \"%s\")\n", __func__
, symbolName
, libraryNameHint
);
674 const ImageLoader
* image
;
675 const ImageLoader::Symbol
* sym
;
676 bool found
= dyld::flatFindExportedSymbolWithHint(symbolName
, libraryNameHint
, &sym
, &image
);
678 // hint failed, do slow search of all images
679 found
= dyld::flatFindExportedSymbol(symbolName
, &sym
, &image
);
681 if ( !found
&& dyld::gLogAPIs
)
682 dyld::log("%s(\"%s\", \"%s\") => false \n", __func__
, symbolName
, libraryNameHint
);
686 const char* NSNameOfSymbol(NSSymbol symbol
)
688 if ( dyld::gLogAPIs
)
689 dyld::log("%s(%p)\n", __func__
, (void *)symbol
);
690 const char* result
= NULL
;
691 ImageLoader
* image
= dyld::findImageContainingSymbol(symbol
);
693 result
= image
->getExportedSymbolName(NSSymbolToSymbol(symbol
));
697 void* NSAddressOfSymbol(NSSymbol symbol
)
699 if ( dyld::gLogAPIs
)
700 dyld::log("%s(%p)\n", __func__
, (void *)symbol
);
701 if ( symbol
== NULL
)
704 ImageLoader
* image
= dyld::findImageContainingSymbol(symbol
);
706 result
= (void*)image
->getExportedSymbolAddress(NSSymbolToSymbol(symbol
), dyld::gLinkContext
);
710 NSModule
NSModuleForSymbol(NSSymbol symbol
)
712 if ( dyld::gLogAPIs
)
713 dyld::log("%s(%p)\n", __func__
, (void *)symbol
);
714 NSModule result
= NULL
;
715 ImageLoader
* image
= dyld::findImageContainingSymbol(symbol
);
717 result
= ImageLoaderToNSModule(image
);
724 bool _dyld_all_twolevel_modules_prebound(void)
726 if ( dyld::gLogAPIs
)
727 dyld::log("%s()\n", __func__
);
731 void _dyld_bind_objc_module(const void *objc_module
)
733 if ( dyld::gLogAPIs
)
734 dyld::log("%s(%p)\n", __func__
, objc_module
);
735 // do nothing, with new dyld everything already bound
739 bool _dyld_bind_fully_image_containing_address(const void* address
)
741 if ( dyld::gLogAPIs
)
742 dyld::log("%s(%p)\n", __func__
, address
);
743 dyld::clearErrorMessage();
744 ImageLoader
* image
= dyld::findImageContainingAddress(address
);
745 if ( image
!= NULL
) {
747 image
->bindAllLazyPointers(dyld::gLinkContext
, true);
750 catch (const char* msg
) {
751 dyldAPIhalt(__func__
, msg
);
757 bool _dyld_image_containing_address(const void* address
)
759 if ( dyld::gLogAPIs
)
760 dyld::log("%s(%p)\n", __func__
, address
);
761 ImageLoader
*imageLoader
= dyld::findImageContainingAddress(address
);
762 return (NULL
!= imageLoader
);
765 static NSObjectFileImage
createObjectImageFile(ImageLoader
* image
, const void* address
= NULL
, size_t len
=0)
767 NSObjectFileImage result
= new __NSObjectFileImage();
768 result
->image
= image
;
769 result
->imageBaseAddress
= address
;
770 result
->imageLength
= len
;
771 sObjectFileImages
.push_back(result
);
775 NSObjectFileImageReturnCode
NSCreateObjectFileImageFromFile(const char* pathName
, NSObjectFileImage
*objectFileImage
)
777 if ( dyld::gLogAPIs
)
778 dyld::log("%s(\"%s\", ...)\n", __func__
, pathName
);
780 void* callerAddress
= __builtin_return_address(1); // note layers: 1: real client, 0: libSystem glue
781 ImageLoader
* callerImage
= dyld::findImageContainingAddress(callerAddress
);
783 dyld::LoadContext context
;
784 context
.useSearchPaths
= false;
785 context
.useFallbackPaths
= false;
786 context
.useLdLibraryPath
= false;
787 context
.implicitRPath
= false;
788 context
.matchByInstallName
= false;
789 context
.dontLoad
= false;
790 context
.mustBeBundle
= true;
791 context
.mustBeDylib
= false;
792 context
.canBePIE
= false;
793 context
.origin
= callerImage
!= NULL
? callerImage
->getPath() : NULL
; // caller's image's path
794 context
.rpath
= NULL
; // support not yet implemented
796 ImageLoader
* image
= dyld::load(pathName
, context
);
797 // Note: We DO NOT link the image! NSLinkModule will do that
798 if ( image
!= NULL
) {
799 if ( !image
->isBundle() ) {
800 // the image must have been already loaded (since context.mustBeBundle will prevent it from being loaded)
801 return NSObjectFileImageInappropriateFile
;
803 *objectFileImage
= createObjectImageFile(image
);
804 return NSObjectFileImageSuccess
;
807 catch (const char* msg
) {
808 //dyld::log("dyld: NSCreateObjectFileImageFromFile() error: %s\n", msg);
809 dyld::garbageCollectImages();
811 return NSObjectFileImageInappropriateFile
;
813 return NSObjectFileImageFailure
;
817 NSObjectFileImageReturnCode
NSCreateObjectFileImageFromMemory(const void* address
, size_t size
, NSObjectFileImage
*objectFileImage
)
819 if ( dyld::gLogAPIs
)
820 dyld::log("%s(%p, %lu, %p)\n", __func__
, address
, size
, objectFileImage
);
823 ImageLoader
* image
= dyld::loadFromMemory((const uint8_t*)address
, size
, NULL
);
824 if ( ! image
->isBundle() ) {
825 // this API can only be used with bundles...
826 dyld::garbageCollectImages();
827 return NSObjectFileImageInappropriateFile
;
829 // Note: We DO NOT link the image! NSLinkModule will do that
830 if ( image
!= NULL
) {
831 *objectFileImage
= createObjectImageFile(image
, address
, size
);
832 return NSObjectFileImageSuccess
;
835 catch (const char* msg
) {
837 dyld::garbageCollectImages();
838 //dyld::log("dyld: NSCreateObjectFileImageFromMemory() error: %s\n", msg);
840 return NSObjectFileImageFailure
;
843 static bool validOFI(NSObjectFileImage objectFileImage
)
845 const int ofiCount
= sObjectFileImages
.size();
846 for (int i
=0; i
< ofiCount
; ++i
) {
847 if ( sObjectFileImages
[i
] == objectFileImage
)
853 bool NSDestroyObjectFileImage(NSObjectFileImage objectFileImage
)
855 if ( dyld::gLogAPIs
)
856 dyld::log("%s(%p)\n", __func__
, objectFileImage
);
858 if ( validOFI(objectFileImage
) ) {
859 // a failure during NSLinkModule will delete the image
860 if ( objectFileImage
->image
!= NULL
) {
861 // if the image has never been linked or has been unlinked, the image is not in the list of valid images
862 // and we should delete it
863 bool linkedImage
= dyld::validImage(objectFileImage
->image
);
864 if ( ! linkedImage
) {
865 ImageLoader::deleteImage(objectFileImage
->image
);
866 objectFileImage
->image
= NULL
;
870 // remove from list of ofi's
871 for (std::vector
<NSObjectFileImage
>::iterator it
=sObjectFileImages
.begin(); it
!= sObjectFileImages
.end(); it
++) {
872 if ( *it
== objectFileImage
) {
873 sObjectFileImages
.erase(it
);
878 // if object was created from a memory, release that memory
879 // NOTE: this is the way dyld has always done this. NSCreateObjectFileImageFromMemory() hands over ownership of the memory to dyld
880 if ( objectFileImage
->imageBaseAddress
!= NULL
) {
882 if ( (dyld::gLibSystemHelpers
!= NULL
) && (dyld::gLibSystemHelpers
->version
>= 6) ) {
883 size_t sz
= (*dyld::gLibSystemHelpers
->malloc_size
)(objectFileImage
->imageBaseAddress
);
885 (*dyld::gLibSystemHelpers
->free
)((void*)(objectFileImage
->imageBaseAddress
));
890 vm_deallocate(mach_task_self(), (vm_address_t
)objectFileImage
->imageBaseAddress
, objectFileImage
->imageLength
);
894 delete objectFileImage
;
901 bool NSHasModInitObjectFileImage(NSObjectFileImage objectFileImage
)
903 if ( dyld::gLogAPIs
)
904 dyld::log("%s(%p)\n", __func__
, objectFileImage
);
905 return objectFileImage
->image
->needsInitialization();
908 uint32_t NSSymbolDefinitionCountInObjectFileImage(NSObjectFileImage objectFileImage
)
910 if ( dyld::gLogAPIs
)
911 dyld::log("%s(%p)\n", __func__
, objectFileImage
);
912 return objectFileImage
->image
->getExportedSymbolCount();
915 const char* NSSymbolDefinitionNameInObjectFileImage(NSObjectFileImage objectFileImage
, uint32_t ordinal
)
917 if ( dyld::gLogAPIs
)
918 dyld::log("%s(%p,%d)\n", __func__
, objectFileImage
, ordinal
);
919 const ImageLoader::Symbol
* sym
= objectFileImage
->image
->getIndexedExportedSymbol(ordinal
);
920 return objectFileImage
->image
->getExportedSymbolName(sym
);
923 uint32_t NSSymbolReferenceCountInObjectFileImage(NSObjectFileImage objectFileImage
)
925 if ( dyld::gLogAPIs
)
926 dyld::log("%s(%p)\n", __func__
, objectFileImage
);
927 return objectFileImage
->image
->getImportedSymbolCount();
930 const char * NSSymbolReferenceNameInObjectFileImage(NSObjectFileImage objectFileImage
, uint32_t ordinal
,
931 bool* tentative_definition
)
933 if ( dyld::gLogAPIs
)
934 dyld::log("%s(%p,%d)\n", __func__
, objectFileImage
, ordinal
);
935 const ImageLoader::Symbol
* sym
= objectFileImage
->image
->getIndexedImportedSymbol(ordinal
);
936 if ( tentative_definition
!= NULL
) {
937 ImageLoader::ReferenceFlags flags
= objectFileImage
->image
->getImportedSymbolInfo(sym
);
938 if ( (flags
& ImageLoader::kTentativeDefinition
) != 0 )
939 *tentative_definition
= true;
941 *tentative_definition
= false;
943 return objectFileImage
->image
->getImportedSymbolName(sym
);
946 void* NSGetSectionDataInObjectFileImage(NSObjectFileImage objectFileImage
,
947 const char* segmentName
, const char* sectionName
, unsigned long* size
)
949 if ( dyld::gLogAPIs
)
950 dyld::log("%s(%p,%s, %s)\n", __func__
, objectFileImage
, segmentName
, sectionName
);
954 if ( objectFileImage
->image
->getSectionContent(segmentName
, sectionName
, &start
, &length
) ) {
964 bool NSIsSymbolDefinedInObjectFileImage(NSObjectFileImage objectFileImage
, const char* symbolName
)
966 if ( dyld::gLogAPIs
)
967 dyld::log("%s(%p,%s)\n", __func__
, objectFileImage
, symbolName
);
968 const ImageLoader::Symbol
* sym
= objectFileImage
->image
->findExportedSymbol(symbolName
, true, NULL
);
969 return ( sym
!= NULL
);
974 NSModule
NSLinkModule(NSObjectFileImage objectFileImage
, const char* moduleName
, uint32_t options
)
976 if ( dyld::gLogAPIs
)
977 dyld::log("%s(%p, \"%s\", 0x%08X)\n", __func__
, objectFileImage
, moduleName
, options
);
979 dyld::clearErrorMessage();
981 if ( (options
& NSLINKMODULE_OPTION_CAN_UNLOAD
) != 0 )
982 objectFileImage
->image
->setCanUnload();
984 // NSLinkModule allows a bundle to be link multpile times
985 // each link causes the bundle to be copied to a new address
986 if ( objectFileImage
->image
->isLinked() ) {
987 // already linked, so clone a new one and link it
988 objectFileImage
->image
= dyld::cloneImage(objectFileImage
->image
);
991 // for memory based images, set moduleName as the name anyone calling _dyld_get_image_name() will see
992 if ( objectFileImage
->image
->getPath() == NULL
) {
993 objectFileImage
->image
->setPath(moduleName
);
994 // <rdar://problem/8812589> dyld has NULL paths in image info array
995 dyld_image_info info
;
996 info
.imageLoadAddress
= objectFileImage
->image
->machHeader();
997 info
.imageFilePath
= moduleName
;
998 info
.imageFileModDate
= 0;
999 addImagesToAllImages(1, &info
);
1002 // support private bundles
1003 if ( (options
& NSLINKMODULE_OPTION_PRIVATE
) != 0 )
1004 objectFileImage
->image
->setHideExports();
1006 // set up linking options
1007 bool forceLazysBound
= ( (options
& NSLINKMODULE_OPTION_BINDNOW
) != 0 );
1009 // load libraries, rebase, bind, to make this image usable
1010 dyld::link(objectFileImage
->image
, forceLazysBound
, false, ImageLoader::RPathChain(NULL
,NULL
));
1012 // bump reference count to keep this bundle from being garbage collected
1013 objectFileImage
->image
->incrementDlopenReferenceCount();
1015 // run initializers unless magic flag says not to
1016 if ( (options
& NSLINKMODULE_OPTION_DONT_CALL_MOD_INIT_ROUTINES
) == 0 )
1017 dyld::runInitializers(objectFileImage
->image
);
1019 return ImageLoaderToNSModule(objectFileImage
->image
);
1021 catch (const char* msg
) {
1022 dyld::garbageCollectImages();
1023 if ( (options
& NSLINKMODULE_OPTION_RETURN_ON_ERROR
) == 0 )
1024 dyldAPIhalt(__func__
, msg
);
1025 // not halting, so set error state for NSLinkEditError to find
1026 setLastError(NSLinkEditOtherError
, 0, moduleName
, msg
);
1027 // dyld::link() deleted the image so lose our reference
1028 objectFileImage
->image
= NULL
;
1035 #if OLD_LIBSYSTEM_SUPPORT
1036 // This is for compatibility with old libSystems (libdyld.a) which process ObjectFileImages outside dyld
1037 static NSModule
_dyld_link_module(NSObjectFileImage object_addr
, size_t object_size
, const char* moduleName
, uint32_t options
)
1039 if ( dyld::gLogAPIs
)
1040 dyld::log("%s(%p, \"%s\", 0x%08X)\n", "NSLinkModule", object_addr
, moduleName
, options
); // note name/args translation
1041 ImageLoader
* image
= NULL
;
1042 dyld::clearErrorMessage();
1044 const char* imageName
= moduleName
;
1045 image
= dyld::loadFromMemory((const uint8_t*)object_addr
, object_size
, imageName
);
1047 if ( image
!= NULL
) {
1048 // support private bundles
1049 if ( (options
& NSLINKMODULE_OPTION_PRIVATE
) != 0 )
1050 image
->setHideExports();
1052 // set up linking options
1053 bool forceLazysBound
= ( (options
& NSLINKMODULE_OPTION_BINDNOW
) != 0 );
1055 // load libraries, rebase, bind, to make this image usable
1056 dyld::link(image
, forceLazysBound
, false, ImageLoader::RPathChain(NULL
,NULL
));
1058 // run initializers unless magic flag says not to
1059 if ( (options
& NSLINKMODULE_OPTION_DONT_CALL_MOD_INIT_ROUTINES
) == 0 )
1060 dyld::runInitializers(image
);
1063 catch (const char* msg
) {
1064 if ( (options
& NSLINKMODULE_OPTION_RETURN_ON_ERROR
) == 0 )
1065 dyldAPIhalt("NSLinkModule", msg
);
1066 // not halting, so set error state for NSLinkEditError to find
1067 setLastError(NSLinkEditOtherError
, 0, moduleName
, msg
);
1068 // if image was created for this bundle, destroy it
1069 if ( image
!= NULL
) {
1070 dyld::removeImage(image
);
1071 ImageLoader::deleteImage(image
);
1076 return ImageLoaderToNSModule(image
);
1080 NSSymbol
NSLookupSymbolInModule(NSModule
module, const char* symbolName
)
1082 if ( dyld::gLogAPIs
)
1083 dyld::log("%s(%p, \"%s\")\n", __func__
, (void *)module, symbolName
);
1084 ImageLoader
* image
= NSModuleToImageLoader(module);
1085 if ( image
== NULL
)
1087 return SymbolToNSSymbol(image
->findExportedSymbol(symbolName
, false, NULL
));
1090 const char* NSNameOfModule(NSModule
module)
1092 if ( dyld::gLogAPIs
)
1093 dyld::log("%s(%p)\n", __func__
, module);
1094 ImageLoader
* image
= NSModuleToImageLoader(module);
1095 if ( image
== NULL
)
1097 return image
->getPath();
1100 const char* NSLibraryNameForModule(NSModule
module)
1102 if ( dyld::gLogAPIs
)
1103 dyld::log("%s(%p)\n", __func__
, module);
1104 ImageLoader
* image
= NSModuleToImageLoader(module);
1105 if ( image
== NULL
)
1107 return image
->getPath();
1110 bool NSUnLinkModule(NSModule
module, uint32_t options
)
1112 if ( dyld::gLogAPIs
)
1113 dyld::log("%s(%p, 0x%08X)\n", __func__
, module, options
);
1114 if ( module == NULL
)
1116 ImageLoader
* image
= NSModuleToImageLoader(module);
1117 if ( image
== NULL
)
1119 dyld::runImageStaticTerminators(image
);
1120 if ( (dyld::gLibSystemHelpers
!= NULL
) && (dyld::gLibSystemHelpers
->version
>= 13) ) {
1121 __cxa_range_t ranges
[image
->segmentCount()];
1123 for (unsigned int j
=0; j
< image
->segmentCount(); ++j
) {
1124 if ( !image
->segExecutable(j
) )
1126 ranges
[rangeCount
].addr
= (const void*)image
->segActualLoadAddress(j
);
1127 ranges
[rangeCount
].length
= image
->segSize(j
);
1130 (*dyld::gLibSystemHelpers
->cxa_finalize_ranges
)(ranges
, rangeCount
);
1132 dyld::removeImage(image
);
1134 if ( (options
& NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED
) != 0 )
1135 image
->setLeaveMapped();
1137 // TODO: NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES
1139 // Only delete image if there is no ofi referencing it
1140 // That means the ofi was destroyed after linking, so no one is left to delete this image
1141 const int ofiCount
= sObjectFileImages
.size();
1143 for (int i
=0; i
< ofiCount
; ++i
) {
1144 NSObjectFileImage ofi
= sObjectFileImages
[i
];
1145 if ( ofi
->image
== image
)
1149 ImageLoader::deleteImage(image
);
1154 // internal name and parameters do not match public name and parameters...
1155 static void _dyld_install_handlers(void* undefined
, void* multiple
, void* linkEdit
)
1157 if ( dyld::gLogAPIs
)
1158 dyld::log("NSLinkEditErrorHandlers()\n");
1160 dyld::registerUndefinedHandler((dyld::UndefinedHandler
)undefined
);
1161 // no support for multiple or linkedit handlers
1167 void NSLinkEditError(NSLinkEditErrors
* c
, int* errorNumber
, const char** fileName
, const char** errorString
)
1170 *c
= sLastErrorFileCode
;
1171 *errorNumber
= sLastErrorNo
;
1172 *fileName
= sLastErrorFilePath
;
1173 *errorString
= dyld::getErrorMessage();
1178 static void _dyld_register_binding_handler(void * (*bindingHandler
)(const char *, const char *, void *), ImageLoader::BindingOptions bindingOptions
)
1180 if ( dyld::gLogAPIs
)
1181 dyld::log("%s()\n", __func__
);
1182 dyld::gLinkContext
.bindingHandler
= bindingHandler
;
1183 dyld::gLinkContext
.bindingOptions
= bindingOptions
;
1186 #endif //DEPRECATED_APIS_SUPPORTED
1189 // Call by fork() in libSystem after the kernel trap is done on the child side
1190 void _dyld_fork_child()
1192 if ( dyld::gLogAPIs
)
1193 dyld::log("%s()\n", __func__
);
1194 // The implementation of fork() in libSystem knows to reset the variable mach_task_self_
1195 // in libSystem for the child of a fork. But dyld is built with a static copy
1196 // of libc.a and has its own copy of mach_task_self_ which we reset here.
1198 // In mach_init.h mach_task_self() is #defined to mach_task_self_ and
1199 // in mach_init() mach_task_self_ is initialized to task_self_trap().
1201 extern mach_port_t mach_task_self_
;
1202 mach_task_self_
= task_self_trap();
1204 // If dyld is sending load/unload notices to CoreSymbolication, the shared memory
1205 // page is not copied on fork. <rdar://problem/6797342>
1206 // NULL the CoreSymbolication shared memory pointer to prevent a crash.
1207 dyld::gProcessInfo
->coreSymbolicationShmPage
= NULL
;
1208 // for safety, make sure child starts with clean systemOrderFlag
1209 dyld::gProcessInfo
->systemOrderFlag
= 0;
1213 #if DEPRECATED_APIS_SUPPORTED
1214 // returns true if prebinding was used in main executable
1215 bool _dyld_launched_prebound()
1217 if ( dyld::gLogAPIs
)
1218 dyld::log("%s()\n", __func__
);
1220 // ¥¥¥Êif we deprecate prebinding, we may want to consider always returning true or false here
1221 return dyld::mainExecutablePrebound();
1226 // _dyld_NSMakePrivateModulePublic() is the dyld side of the hack
1227 // NSMakePrivateModulePublic() needed for the dlopen() to turn it's
1228 // RTLD_LOCAL handles into RTLD_GLOBAL. It just simply turns off the private
1229 // flag on the image for this module. If the module was found and it was
1230 // private then everything worked and TRUE is returned else FALSE is returned.
1232 static bool NSMakePrivateModulePublic(NSModule
module)
1234 ImageLoader
* image
= NSModuleToImageLoader(module);
1235 if ( image
!= NULL
) {
1236 if ( image
->hasHiddenExports() ) {
1237 image
->setHideExports(false);
1244 #endif // DEPRECATED_APIS_SUPPORTED
1246 int _dyld_func_lookup(const char* name
, void** address
)
1248 for (const dyld_func
* p
= dyld_funcs
; p
->name
!= NULL
; ++p
) {
1249 if ( strcmp(p
->name
, name
) == 0 ) {
1250 if( p
->implementation
== unimplemented
)
1251 dyld::log("unimplemented dyld function: %s\n", p
->name
);
1252 *address
= p
->implementation
;
1261 static void registerThreadHelpers(const dyld::LibSystemHelpers
* helpers
)
1263 dyld::gLibSystemHelpers
= helpers
;
1265 // let gdb know it is safe to run code in inferior that might call malloc()
1266 dyld::gProcessInfo
->libSystemInitialized
= true;
1268 #if !SUPPORT_ZERO_COST_EXCEPTIONS
1269 if ( helpers
->version
>= 5 ) {
1270 // create key use by dyld exception handling
1272 int result
= helpers
->pthread_key_create(&key
, NULL
);
1274 __Unwind_SjLj_SetThreadKey(key
);
1280 static void dlerrorClear()
1282 if ( dyld::gLibSystemHelpers
!= NULL
) {
1283 // <rdar://problem/10595338> dlerror buffer leak
1284 // dlerrorClear() should not force allocation, but zero it if already allocated
1285 if ( dyld::gLibSystemHelpers
->version
>= 10 ) {
1286 if ( ! (*dyld::gLibSystemHelpers
->hasPerThreadBufferFor_dlerror
)() )
1290 // first char of buffer is flag whether string (starting at second char) is valid
1291 char* buffer
= (*dyld::gLibSystemHelpers
->getThreadBufferFor_dlerror
)(2);
1297 static void dlerrorSet(const char* msg
)
1299 if ( dyld::gLibSystemHelpers
!= NULL
) {
1300 // first char of buffer is flag whether string (starting at second char) is valid
1301 char* buffer
= (*dyld::gLibSystemHelpers
->getThreadBufferFor_dlerror
)(strlen(msg
)+2);
1303 strcpy(&buffer
[1], msg
);
1308 bool dlopen_preflight(const char* path
)
1310 if ( dyld::gLogAPIs
)
1311 dyld::log("%s(%s)\n", __func__
, path
);
1315 #if DYLD_SHARED_CACHE_SUPPORT
1316 // <rdar://problem/5910137> dlopen_preflight() on image in shared cache leaves it loaded but not objc initialized
1317 // if requested path is to something in the dyld shared cache, always succeed
1318 if ( dyld::inSharedCache(path
) )
1322 CRSetCrashLogMessage("dyld: in dlopen_preflight()");
1324 bool result
= false;
1325 std::vector
<const char*> rpathsFromCallerImage
;
1327 void* callerAddress
= __builtin_return_address(1); // note layers: 1: real client, 0: libSystem glue
1328 ImageLoader
* callerImage
= dyld::findImageContainingAddress(callerAddress
);
1329 // for dlopen, use rpath from caller image and from main executable
1330 if ( callerImage
!= NULL
)
1331 callerImage
->getRPaths(dyld::gLinkContext
, rpathsFromCallerImage
);
1332 ImageLoader::RPathChain
callersRPaths(NULL
, &rpathsFromCallerImage
);
1333 if ( callerImage
!= dyld::mainExecutable() ) {
1334 dyld::mainExecutable()->getRPaths(dyld::gLinkContext
, rpathsFromCallerImage
);
1337 ImageLoader
* image
= NULL
;
1338 const bool leafName
= (strchr(path
, '/') == NULL
);
1339 const bool absolutePath
= (path
[0] == '/');
1340 #if __IPHONE_OS_VERSION_MIN_REQUIRED
1341 char canonicalPath
[PATH_MAX
];
1342 // <rdar://problem/7017050> dlopen() not opening frameworks from shared cache with // or ./ in path
1344 // make path canonical if it contains a // or ./
1345 if ( (strstr(path
, "//") != NULL
) || (strstr(path
, "./") != NULL
) ) {
1346 const char* lastSlash
= strrchr(path
, '/');
1347 char dirPath
[PATH_MAX
];
1348 if ( strlcpy(dirPath
, path
, sizeof(dirPath
)) < sizeof(dirPath
) ) {
1349 dirPath
[lastSlash
-path
] = '\0';
1350 if ( realpath(dirPath
, canonicalPath
) ) {
1351 strlcat(canonicalPath
, "/", sizeof(canonicalPath
));
1352 if ( strlcat(canonicalPath
, lastSlash
+1, sizeof(canonicalPath
)) < sizeof(canonicalPath
) ) {
1353 // if all fit in buffer, use new canonical path
1354 path
= canonicalPath
;
1361 dyld::LoadContext context
;
1362 context
.useSearchPaths
= true;
1363 context
.useFallbackPaths
= leafName
; // a partial path implies don't use fallback paths
1364 context
.useLdLibraryPath
= leafName
; // a leafname implies should search
1365 context
.implicitRPath
= !absolutePath
; // a non-absolute path implies try rpath searching
1366 context
.matchByInstallName
= true;
1367 context
.dontLoad
= false;
1368 context
.mustBeBundle
= false;
1369 context
.mustBeDylib
= false;
1370 context
.canBePIE
= true;
1371 context
.origin
= callerImage
!= NULL
? callerImage
->getPath() : NULL
; // caller's image's path
1372 context
.rpath
= &callersRPaths
; // rpaths from caller and main executable
1374 image
= load(path
, context
);
1375 if ( image
!= NULL
) {
1376 dyld::preflight(image
, callersRPaths
); // image object deleted by dyld::preflight()
1380 catch (const char* msg
) {
1381 const char* str
= dyld::mkstringf("dlopen_preflight(%s): %s", path
, msg
);
1384 free((void*)msg
); // our free() will do nothing if msg is a string literal
1386 // free rpaths (getRPaths() malloc'ed each string)
1387 for(std::vector
<const char*>::iterator it
=rpathsFromCallerImage
.begin(); it
!= rpathsFromCallerImage
.end(); ++it
) {
1388 const char* str
= *it
;
1391 CRSetCrashLogMessage(NULL
);
1396 void* dlopen(const char* path
, int mode
)
1398 if ( dyld::gLogAPIs
)
1399 dyld::log("%s(%s, 0x%08X)\n", __func__
, ((path
==NULL
) ? "NULL" : path
), mode
);
1403 // passing NULL for path means return magic object
1404 if ( path
== NULL
) {
1405 // RTLD_FIRST means any dlsym() calls on the handle should only search that handle and not subsequent images
1406 if ( (mode
& RTLD_FIRST
) != 0 )
1407 return RTLD_MAIN_ONLY
;
1409 return RTLD_DEFAULT
;
1412 // acquire global dyld lock (dlopen is special - libSystem glue does not do locking)
1413 bool lockHeld
= false;
1414 if ( (dyld::gLibSystemHelpers
!= NULL
) && (dyld::gLibSystemHelpers
->version
>= 4) ) {
1415 dyld::gLibSystemHelpers
->acquireGlobalDyldLock();
1416 CRSetCrashLogMessage("dyld: in dlopen()");
1420 void* result
= NULL
;
1421 ImageLoader
* image
= NULL
;
1422 std::vector
<const char*> rpathsFromCallerImage
;
1423 ImageLoader::RPathChain
callersRPaths(NULL
, &rpathsFromCallerImage
);
1425 void* callerAddress
= __builtin_return_address(1); // note layers: 1: real client, 0: libSystem glue
1426 ImageLoader
* callerImage
= dyld::findImageContainingAddress(callerAddress
);
1427 if ( (mode
& RTLD_NOLOAD
) == 0 ) {
1428 // for dlopen, use rpath from caller image and from main executable
1429 if ( callerImage
!= NULL
)
1430 callerImage
->getRPaths(dyld::gLinkContext
, rpathsFromCallerImage
);
1431 if ( callerImage
!= dyld::mainExecutable() )
1432 dyld::mainExecutable()->getRPaths(dyld::gLinkContext
, rpathsFromCallerImage
);
1435 const bool leafName
= (strchr(path
, '/') == NULL
);
1436 const bool absolutePath
= (path
[0] == '/');
1437 #if __IPHONE_OS_VERSION_MIN_REQUIRED
1438 char canonicalPath
[PATH_MAX
];
1439 // <rdar://problem/7017050> dlopen() not opening frameworks from shared cache with // or ./ in path
1441 // make path canonical if it contains a // or ./
1442 if ( (strstr(path
, "//") != NULL
) || (strstr(path
, "./") != NULL
) ) {
1443 const char* lastSlash
= strrchr(path
, '/');
1444 char dirPath
[PATH_MAX
];
1445 if ( strlcpy(dirPath
, path
, sizeof(dirPath
)) < sizeof(dirPath
) ) {
1446 dirPath
[lastSlash
-path
] = '\0';
1447 if ( realpath(dirPath
, canonicalPath
) ) {
1448 strlcat(canonicalPath
, "/", sizeof(canonicalPath
));
1449 if ( strlcat(canonicalPath
, lastSlash
+1, sizeof(canonicalPath
)) < sizeof(canonicalPath
) ) {
1450 // if all fit in buffer, use new canonical path
1451 path
= canonicalPath
;
1458 dyld::LoadContext context
;
1459 context
.useSearchPaths
= true;
1460 context
.useFallbackPaths
= leafName
; // a partial path means no fallback paths
1461 context
.useLdLibraryPath
= leafName
; // a leafname implies should search
1462 context
.implicitRPath
= !absolutePath
; // a non-absolute path implies try rpath searching
1463 context
.matchByInstallName
= true;
1464 context
.dontLoad
= ( (mode
& RTLD_NOLOAD
) != 0 );
1465 context
.mustBeBundle
= false;
1466 context
.mustBeDylib
= false;
1467 context
.canBePIE
= true;
1468 context
.origin
= callerImage
!= NULL
? callerImage
->getPath() : NULL
; // caller's image's path
1469 context
.rpath
= &callersRPaths
; // rpaths from caller and main executable
1471 image
= load(path
, context
);
1472 if ( image
!= NULL
) {
1473 // bump reference count. Do this before link() so that if an initializer calls dlopen and fails
1474 // this image is not garbage collected
1475 image
->incrementDlopenReferenceCount();
1476 // link in all dependents
1477 if ( (mode
& RTLD_NOLOAD
) == 0 ) {
1478 bool alreadyLinked
= image
->isLinked();
1479 bool forceLazysBound
= ( (mode
& RTLD_NOW
) != 0 );
1480 dyld::link(image
, forceLazysBound
, false, callersRPaths
);
1481 if ( ! alreadyLinked
) {
1482 // only hide exports if image is not already in use
1483 if ( (mode
& RTLD_LOCAL
) != 0 )
1484 image
->setHideExports(true);
1488 // RTLD_NODELETE means don't unmap image even after dlclosed. This is what dlcompat did on Mac OS X 10.3
1489 // On other *nix OS's, it means dlclose() should do nothing, but the handle should be invalidated.
1490 // The subtle differences are:
1491 // 1) if the image has any termination routines, whether they are run during dlclose or when the process terminates
1492 // 2) If someone does a supsequent dlopen() on the same image, whether the same address should be used.
1493 if ( (mode
& RTLD_NODELETE
) != 0 )
1494 image
->setLeaveMapped();
1496 // release global dyld lock early, this enables initializers to do threaded operations
1498 CRSetCrashLogMessage(NULL
);
1499 dyld::gLibSystemHelpers
->releaseGlobalDyldLock();
1503 // RTLD_NOLOAD means dlopen should fail unless path is already loaded.
1504 // don't run initializers when RTLD_NOLOAD is set. This only matters if dlopen() is
1505 // called from within an initializer because it can cause initializers to run
1506 // out of order. Most uses of RTLD_NOLOAD are "probes". If they want initialzers
1507 // to run, then don't use RTLD_NOLOAD.
1508 if ( (mode
& RTLD_NOLOAD
) == 0 ) {
1510 dyld::runInitializers(image
);
1513 // RTLD_FIRST means any dlsym() calls on the handle should only search that handle and not subsequent images
1514 // this is tracked by setting the low bit of the handle, which is usually zero by malloc alignment
1515 if ( (mode
& RTLD_FIRST
) != 0 )
1516 result
= (void*)(((uintptr_t)image
)|1);
1521 catch (const char* msg
) {
1522 if ( image
!= NULL
) {
1523 // load() succeeded but, link() failed
1524 // back down reference count and do GC
1525 image
->decrementDlopenReferenceCount();
1526 if ( image
->dlopenCount() == 0 )
1527 dyld::garbageCollectImages();
1529 const char* str
= dyld::mkstringf("dlopen(%s, %d): %s", path
, mode
, msg
);
1530 if ( dyld::gLogAPIs
)
1531 dyld::log(" %s() failed, error: '%s'\n", __func__
, str
);
1534 free((void*)msg
); // our free() will do nothing if msg is a string literal
1537 // free rpaths (getRPaths() malloc'ed each string)
1538 for(std::vector
<const char*>::iterator it
=rpathsFromCallerImage
.begin(); it
!= rpathsFromCallerImage
.end(); ++it
) {
1539 const char* str
= *it
;
1543 // when context.dontLoad is set, load() returns NULL instead of throwing an exception
1544 if ( (mode
& RTLD_NOLOAD
) && (result
== NULL
) ) {
1545 dlerrorSet("image not already loaded");
1549 CRSetCrashLogMessage(NULL
);
1550 dyld::gLibSystemHelpers
->releaseGlobalDyldLock();
1552 if ( dyld::gLogAPIs
&& (result
!= NULL
) )
1553 dyld::log(" %s(%s) ==> %p\n", __func__
, path
, result
);
1559 int dlclose(void* handle
)
1561 if ( dyld::gLogAPIs
)
1562 dyld::log("%s(%p)\n", __func__
, handle
);
1564 // silently accept magic handles for main executable
1565 if ( handle
== RTLD_MAIN_ONLY
)
1567 if ( handle
== RTLD_DEFAULT
)
1570 ImageLoader
* image
= (ImageLoader
*)(((uintptr_t)handle
) & (-4)); // clear mode bits
1571 if ( dyld::validImage(image
) ) {
1573 // decrement use count
1574 if ( image
->decrementDlopenReferenceCount() ) {
1575 dlerrorSet("dlclose() called too many times");
1578 // remove image if reference count went to zero
1579 if ( image
->dlopenCount() == 0 )
1580 dyld::garbageCollectImages();
1584 dlerrorSet("invalid handle passed to dlclose()");
1591 int dladdr(const void* address
, Dl_info
* info
)
1593 if ( dyld::gLogAPIs
)
1594 dyld::log("%s(%p, %p)\n", __func__
, address
, info
);
1596 CRSetCrashLogMessage("dyld: in dladdr()");
1597 ImageLoader
* image
= dyld::findImageContainingAddress(address
);
1598 if ( image
!= NULL
) {
1599 info
->dli_fname
= image
->getRealPath();
1600 info
->dli_fbase
= (void*)image
->machHeader();
1601 if ( address
== info
->dli_fbase
) {
1602 // special case lookup of header
1603 info
->dli_sname
= "__dso_handle";
1604 info
->dli_saddr
= info
->dli_fbase
;
1605 CRSetCrashLogMessage(NULL
);
1606 return 1; // success
1608 // find closest symbol in the image
1609 info
->dli_sname
= image
->findClosestSymbol(address
, (const void**)&info
->dli_saddr
);
1610 // never return the mach_header symbol
1611 if ( info
->dli_saddr
== info
->dli_fbase
) {
1612 info
->dli_sname
= NULL
;
1613 info
->dli_saddr
= NULL
;
1614 CRSetCrashLogMessage(NULL
);
1615 return 1; // success
1617 if ( info
->dli_sname
!= NULL
) {
1618 if ( info
->dli_sname
[0] == '_' )
1619 info
->dli_sname
= info
->dli_sname
+1; // strip off leading underscore
1620 //dyld::log("dladdr(%p) => %p %s\n", address, info->dli_saddr, info->dli_sname);
1621 CRSetCrashLogMessage(NULL
);
1622 return 1; // success
1624 info
->dli_sname
= NULL
;
1625 info
->dli_saddr
= NULL
;
1626 CRSetCrashLogMessage(NULL
);
1627 return 1; // success
1629 CRSetCrashLogMessage(NULL
);
1630 return 0; // failure
1636 if ( dyld::gLogAPIs
)
1637 dyld::log("%s()\n", __func__
);
1639 if ( dyld::gLibSystemHelpers
!= NULL
) {
1640 // if using newer libdyld.dylib and buffer if buffer not yet allocated, return NULL
1641 if ( dyld::gLibSystemHelpers
->version
>= 10 ) {
1642 if ( ! (*dyld::gLibSystemHelpers
->hasPerThreadBufferFor_dlerror
)() )
1646 // first char of buffer is flag whether string (starting at second char) is valid
1647 char* buffer
= (*dyld::gLibSystemHelpers
->getThreadBufferFor_dlerror
)(2);
1648 if ( buffer
[0] != '\0' ) { // if valid buffer
1649 buffer
[0] = '\0'; // mark invalid, so next call to dlerror returns NULL
1650 return &buffer
[1]; // return message
1656 void* dlsym(void* handle
, const char* symbolName
)
1658 if ( dyld::gLogAPIs
)
1659 dyld::log("%s(%p, %s)\n", __func__
, handle
, symbolName
);
1661 CRSetCrashLogMessage("dyld: in dlsym()");
1664 const ImageLoader
* image
;
1665 const ImageLoader::Symbol
* sym
;
1667 // dlsym() assumes symbolName passed in is same as in C source code
1668 // dyld assumes all symbol names have an underscore prefix
1669 char underscoredName
[strlen(symbolName
)+2];
1670 underscoredName
[0] = '_';
1671 strcpy(&underscoredName
[1], symbolName
);
1673 // magic "search all" handle
1674 if ( handle
== RTLD_DEFAULT
) {
1675 if ( dyld::flatFindExportedSymbol(underscoredName
, &sym
, &image
) ) {
1676 CRSetCrashLogMessage(NULL
);
1677 return (void*)image
->getExportedSymbolAddress(sym
, dyld::gLinkContext
);
1679 const char* str
= dyld::mkstringf("dlsym(RTLD_DEFAULT, %s): symbol not found", symbolName
);
1682 CRSetCrashLogMessage(NULL
);
1686 // magic "search only main executable" handle
1687 if ( handle
== RTLD_MAIN_ONLY
) {
1688 image
= dyld::mainExecutable();
1689 sym
= image
->findExportedSymbol(underscoredName
, true, &image
); // search RTLD_FIRST way
1690 if ( sym
!= NULL
) {
1691 CRSetCrashLogMessage(NULL
);
1692 return (void*)image
->getExportedSymbolAddress(sym
, dyld::gLinkContext
);
1694 const char* str
= dyld::mkstringf("dlsym(RTLD_MAIN_ONLY, %s): symbol not found", symbolName
);
1697 CRSetCrashLogMessage(NULL
);
1701 // magic "search what I would see" handle
1702 if ( handle
== RTLD_NEXT
) {
1703 void* callerAddress
= __builtin_return_address(1); // note layers: 1: real client, 0: libSystem glue
1704 ImageLoader
* callerImage
= dyld::findImageContainingAddress(callerAddress
);
1705 sym
= callerImage
->findExportedSymbolInDependentImages(underscoredName
, dyld::gLinkContext
, &image
); // don't search image, but do search what it links against
1706 if ( sym
!= NULL
) {
1707 CRSetCrashLogMessage(NULL
);
1708 return (void*)image
->getExportedSymbolAddress(sym
, dyld::gLinkContext
);
1710 const char* str
= dyld::mkstringf("dlsym(RTLD_NEXT, %s): symbol not found", symbolName
);
1713 CRSetCrashLogMessage(NULL
);
1716 // magic "search me, then what I would see" handle
1717 if ( handle
== RTLD_SELF
) {
1718 void* callerAddress
= __builtin_return_address(1); // note layers: 1: real client, 0: libSystem glue
1719 ImageLoader
* callerImage
= dyld::findImageContainingAddress(callerAddress
);
1720 sym
= callerImage
->findExportedSymbolInImageOrDependentImages(underscoredName
, dyld::gLinkContext
, &image
); // search image and what it links against
1721 if ( sym
!= NULL
) {
1722 CRSetCrashLogMessage(NULL
);
1723 return (void*)image
->getExportedSymbolAddress(sym
, dyld::gLinkContext
);
1725 const char* str
= dyld::mkstringf("dlsym(RTLD_SELF, %s): symbol not found", symbolName
);
1728 CRSetCrashLogMessage(NULL
);
1732 image
= (ImageLoader
*)(((uintptr_t)handle
) & (-4)); // clear mode bits
1733 if ( dyld::validImage(image
) ) {
1734 if ( (((uintptr_t)handle
) & 1) != 0 )
1735 sym
= image
->findExportedSymbol(underscoredName
, true, &image
); // search RTLD_FIRST way
1737 sym
= image
->findExportedSymbolInImageOrDependentImages(underscoredName
, dyld::gLinkContext
, &image
); // search image and what it links against
1739 if ( sym
!= NULL
) {
1740 CRSetCrashLogMessage(NULL
);
1741 ImageLoader
* callerImage
= NULL
;
1742 if ( sDynamicInterposing
) {
1743 // only take time to look up caller, if dynamic interposing in use
1744 void* callerAddress
= __builtin_return_address(1); // note layers: 1: real client, 0: libSystem glue
1745 callerImage
= dyld::findImageContainingAddress(callerAddress
);
1747 return (void*)image
->getExportedSymbolAddress(sym
, dyld::gLinkContext
, callerImage
);
1749 const char* str
= dyld::mkstringf("dlsym(%p, %s): symbol not found", handle
, symbolName
);
1754 dlerrorSet("invalid handle passed to dlsym()");
1756 CRSetCrashLogMessage(NULL
);
1769 const struct dyld_all_image_infos
* _dyld_get_all_image_infos()
1771 return dyld::gProcessInfo
;
1774 #if SUPPORT_ZERO_COST_EXCEPTIONS
1775 static bool client_dyld_find_unwind_sections(void* addr
, dyld_unwind_sections
* info
)
1777 //if ( dyld::gLogAPIs )
1778 // dyld::log("%s(%p, %p)\n", __func__, addr, info);
1780 ImageLoader
* image
= dyld::findImageContainingAddress(addr
);
1781 if ( image
!= NULL
) {
1782 image
->getUnwindInfo(info
);
1790 void dyld_register_image_state_change_handler(dyld_image_states state
, bool batch
,
1791 dyld_image_state_change_handler handler
)
1793 if ( dyld::gLogAPIs
)
1794 dyld::log("%s(%d, %d, %p)\n", __func__
, state
, batch
, handler
);
1796 dyld::registerImageStateBatchChangeHandler(state
, handler
);
1798 dyld::registerImageStateSingleChangeHandler(state
, handler
);
1801 const char* dyld_image_path_containing_address(const void* address
)
1803 if ( dyld::gLogAPIs
)
1804 dyld::log("%s(%p)\n", __func__
, address
);
1806 ImageLoader
* image
= dyld::findImageContainingAddress(address
);
1807 if ( image
!= NULL
)
1808 return image
->getRealPath();
1814 bool dyld_shared_cache_some_image_overridden()
1816 #if DYLD_SHARED_CACHE_SUPPORT
1817 return dyld::gSharedCacheOverridden
;
1824 void dyld_dynamic_interpose(const struct mach_header
* mh
, const struct dyld_interpose_tuple array
[], size_t count
)
1828 if ( array
== NULL
)
1832 ImageLoader
* image
= dyld::findImageByMachHeader(mh
);
1833 if ( image
== NULL
)
1836 // make pass at bound references in this image and update them
1837 dyld::gLinkContext
.dynamicInterposeArray
= array
;
1838 dyld::gLinkContext
.dynamicInterposeCount
= count
;
1839 image
->dynamicInterpose(dyld::gLinkContext
);
1840 dyld::gLinkContext
.dynamicInterposeArray
= NULL
;
1841 dyld::gLinkContext
.dynamicInterposeCount
= 0;
1843 // leave interposing info so any future (lazy) binding will get it too
1844 image
->addDynamicInterposingTuples(array
, count
);
1846 sDynamicInterposing
= true;