1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
3 * Copyright (c) 2004-2006 Apple Computer, 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@
27 #include "ImageLoader.h"
28 #include "mach-o/dyld_priv.h"
33 // dyld functions available when implementing dyld API's
41 bool useLdLibraryPath
;
43 bool matchByInstallName
;
48 const char* origin
; // path for expanding @loader_path
49 const ImageLoader::RPathChain
* rpath
; // paths for expanding @rpath
54 typedef void (*ImageCallback
)(const struct mach_header
* mh
, intptr_t slide
);
55 typedef void (*BundleNotificationCallBack
)(const char* imageName
, ImageLoader
* image
);
56 typedef ImageLoader
* (*BundleLocatorCallBack
)(const char* symbolName
);
57 typedef void (*UndefinedHandler
)(const char* symbolName
);
58 typedef const char* (*ImageLocator
)(const char* dllName
);
61 extern ImageLoader::LinkContext gLinkContext
;
63 extern bool gSharedCacheNotFound
;
64 extern bool gSharedCacheNeedsUpdating
;
65 extern bool gSharedCacheDontNotify
;
66 extern const struct LibSystemHelpers
* gLibSystemHelpers
;
67 #if SUPPORT_OLD_CRT_INITIALIZATION
68 extern bool gRunInitializersOldWay
;
70 extern void registerAddCallback(ImageCallback func
);
71 extern void registerRemoveCallback(ImageCallback func
);
72 extern void registerZeroLinkHandlers(BundleNotificationCallBack
, BundleLocatorCallBack
);
73 extern void registerUndefinedHandler(UndefinedHandler
);
74 extern void initializeMainExecutable();
75 extern void preflight(ImageLoader
* image
, const ImageLoader::RPathChain
& loaderRPaths
);
76 extern void link(ImageLoader
* image
, bool forceLazysBound
, const ImageLoader::RPathChain
& loaderRPaths
);
77 extern void runInitializers(ImageLoader
* image
);
78 extern void runTerminators(void*);
79 extern const char* getExecutablePath();
80 extern bool validImage(const ImageLoader
*);
81 extern ImageLoader
* getIndexedImage(uint32_t index
);
82 extern uint32_t getImageCount();
83 extern ImageLoader
* findImageByMachHeader(const struct mach_header
* target
);
84 extern ImageLoader
* findImageContainingAddress(const void* addr
);
85 extern ImageLoader
* findImageByName(const char* path
);
86 extern ImageLoader
* findLoadedImageByInstallPath(const char* path
);
87 extern bool flatFindExportedSymbol(const char* name
, const ImageLoader::Symbol
** sym
, const ImageLoader
** image
);
88 extern bool flatFindExportedSymbolWithHint(const char* name
, const char* librarySubstring
, const ImageLoader::Symbol
** sym
, const ImageLoader
** image
);
89 extern ImageLoader
* load(const char* path
, const LoadContext
& context
);
90 extern ImageLoader
* loadFromMemory(const uint8_t* mem
, uint64_t len
, const char* moduleName
);
91 extern void removeImage(ImageLoader
* image
);
92 extern ImageLoader
* cloneImage(ImageLoader
* image
);
93 extern void forEachImageDo( void (*)(ImageLoader
*, void*), void*);
94 extern uintptr_t _main(const struct mach_header
* mainExecutableMH
, uintptr_t mainExecutableSlide
, int argc
, const char* argv
[], const char* envp
[], const char* apple
[]);
95 extern void halt(const char* message
) __attribute__((noreturn
));
96 extern void setErrorMessage(const char* msg
);
97 extern const char* getErrorMessage();
98 extern void clearErrorMessage();
99 extern bool mainExecutablePrebound();
100 extern ImageLoader
* mainExecutable();
101 extern void processDyldEnvironmentVarible(const char* key
, const char* value
);
102 extern void registerImageStateSingleChangeHandler(dyld_image_states state
, dyld_image_state_change_handler handler
);
103 extern void registerImageStateBatchChangeHandler(dyld_image_states state
, dyld_image_state_change_handler handler
);
104 extern void garbageCollectImages();