]>
Commit | Line | Data |
---|---|---|
0959b6d4 A |
1 | /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*- |
2 | * | |
412ebb8e | 3 | * Copyright (c) 2004-2009 Apple Inc. All rights reserved. |
0959b6d4 A |
4 | * |
5 | * @APPLE_LICENSE_HEADER_START@ | |
6 | * | |
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 | |
12 | * file. | |
13 | * | |
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. | |
21 | * | |
22 | * @APPLE_LICENSE_HEADER_END@ | |
23 | */ | |
24 | ||
25 | #include <stdint.h> | |
2fd3f4e8 | 26 | #include <sys/stat.h> |
9f83892a | 27 | #include <dlfcn.h> |
6cae9b63 | 28 | #include <uuid/uuid.h> |
cf998323 | 29 | #include <mach-o/dyld_priv.h> |
0959b6d4 A |
30 | |
31 | #include "ImageLoader.h" | |
32 | ||
33 | ||
34 | ||
35 | // | |
36 | // dyld functions available when implementing dyld API's | |
37 | // | |
38 | // | |
39 | namespace dyld { | |
40 | ||
41 | struct LoadContext | |
42 | { | |
43 | bool useSearchPaths; | |
39a8cd10 | 44 | bool useFallbackPaths; |
0959b6d4 | 45 | bool useLdLibraryPath; |
bac542e6 | 46 | bool implicitRPath; |
0959b6d4 A |
47 | bool matchByInstallName; |
48 | bool dontLoad; | |
49 | bool mustBeBundle; | |
50 | bool mustBeDylib; | |
39a8cd10 | 51 | bool canBePIE; |
bac542e6 A |
52 | const char* origin; // path for expanding @loader_path |
53 | const ImageLoader::RPathChain* rpath; // paths for expanding @rpath | |
0959b6d4 A |
54 | }; |
55 | ||
56 | ||
57 | ||
58 | typedef void (*ImageCallback)(const struct mach_header* mh, intptr_t slide); | |
6cae9b63 | 59 | typedef void (*LoadImageCallback)(const mach_header* mh, const char* path, bool unloadable); |
cf998323 A |
60 | typedef void (*LoadImageBulkCallback)(unsigned count, const mach_header* mhs[], const char* paths[]); |
61 | ||
0959b6d4 | 62 | typedef void (*UndefinedHandler)(const char* symbolName); |
bac542e6 | 63 | typedef const char* (*ImageLocator)(const char* dllName); |
0959b6d4 A |
64 | |
65 | ||
66 | extern ImageLoader::LinkContext gLinkContext; | |
2fd3f4e8 | 67 | extern struct dyld_all_image_infos* gProcessInfo; |
0959b6d4 | 68 | extern bool gLogAPIs; |
9f83892a A |
69 | #if SUPPORT_ACCELERATE_TABLES |
70 | extern bool gLogAppAPIs; | |
71 | #endif | |
412ebb8e | 72 | extern bool gSharedCacheOverridden; |
bac542e6 A |
73 | extern const struct LibSystemHelpers* gLibSystemHelpers; |
74 | #if SUPPORT_OLD_CRT_INITIALIZATION | |
75 | extern bool gRunInitializersOldWay; | |
76 | #endif | |
0959b6d4 A |
77 | extern void registerAddCallback(ImageCallback func); |
78 | extern void registerRemoveCallback(ImageCallback func); | |
0959b6d4 | 79 | extern void registerUndefinedHandler(UndefinedHandler); |
6cae9b63 | 80 | extern void registerLoadCallback(LoadImageCallback func); |
cf998323 | 81 | extern void registerBulkLoadCallback(LoadImageBulkCallback func); |
0959b6d4 | 82 | extern void initializeMainExecutable(); |
9f83892a A |
83 | extern void preflight(ImageLoader* image, const ImageLoader::RPathChain& loaderRPaths, unsigned cacheIndex); |
84 | extern void link(ImageLoader* image, bool forceLazysBound, bool neverUnload, const ImageLoader::RPathChain& loaderRPaths, unsigned cacheIndex); | |
bac542e6 | 85 | extern void runInitializers(ImageLoader* image); |
19894a12 | 86 | extern void runImageStaticTerminators(ImageLoader* image); |
0959b6d4 | 87 | extern const char* getExecutablePath(); |
bac542e6 | 88 | extern bool validImage(const ImageLoader*); |
0959b6d4 A |
89 | extern ImageLoader* getIndexedImage(uint32_t index); |
90 | extern uint32_t getImageCount(); | |
91 | extern ImageLoader* findImageByMachHeader(const struct mach_header* target); | |
92 | extern ImageLoader* findImageContainingAddress(const void* addr); | |
39a8cd10 | 93 | extern ImageLoader* findImageContainingSymbol(const void* symbol); |
0959b6d4 A |
94 | extern ImageLoader* findImageByName(const char* path); |
95 | extern ImageLoader* findLoadedImageByInstallPath(const char* path); | |
bac542e6 A |
96 | extern bool flatFindExportedSymbol(const char* name, const ImageLoader::Symbol** sym, const ImageLoader** image); |
97 | extern bool flatFindExportedSymbolWithHint(const char* name, const char* librarySubstring, const ImageLoader::Symbol** sym, const ImageLoader** image); | |
9f83892a | 98 | extern ImageLoader* load(const char* path, const LoadContext& context, unsigned& cacheIndex); |
0959b6d4 A |
99 | extern ImageLoader* loadFromMemory(const uint8_t* mem, uint64_t len, const char* moduleName); |
100 | extern void removeImage(ImageLoader* image); | |
101 | extern ImageLoader* cloneImage(ImageLoader* image); | |
102 | extern void forEachImageDo( void (*)(ImageLoader*, void*), void*); | |
19894a12 A |
103 | extern uintptr_t _main(const macho_header* mainExecutableMH, uintptr_t mainExecutableSlide, int argc, const char* argv[], const char* envp[], |
104 | const char* apple[], uintptr_t* startGlue) __attribute__((noinline)); // <rdar://problem/113 | |
0959b6d4 A |
105 | extern void halt(const char* message) __attribute__((noreturn)); |
106 | extern void setErrorMessage(const char* msg); | |
107 | extern const char* getErrorMessage(); | |
108 | extern void clearErrorMessage(); | |
109 | extern bool mainExecutablePrebound(); | |
110 | extern ImageLoader* mainExecutable(); | |
412ebb8e | 111 | extern void processDyldEnvironmentVariable(const char* key, const char* value, const char* mainDir); |
bac542e6 A |
112 | extern void registerImageStateSingleChangeHandler(dyld_image_states state, dyld_image_state_change_handler handler); |
113 | extern void registerImageStateBatchChangeHandler(dyld_image_states state, dyld_image_state_change_handler handler); | |
9f83892a A |
114 | extern void registerObjCNotifiers(_dyld_objc_notify_mapped, _dyld_objc_notify_init, _dyld_objc_notify_unmapped); |
115 | extern bool sharedCacheUUID(uuid_t uuid); | |
bac542e6 | 116 | extern void garbageCollectImages(); |
2028a915 | 117 | extern const void* imMemorySharedCacheHeader(); |
39a8cd10 A |
118 | extern uintptr_t fastBindLazySymbol(ImageLoader** imageLoaderCache, uintptr_t lazyBindingInfoOffset); |
119 | extern bool inSharedCache(const char* path); | |
412ebb8e A |
120 | #if LOG_BINDINGS |
121 | extern void logBindings(const char* format, ...); | |
122 | #endif | |
2fd3f4e8 | 123 | extern bool processIsRestricted(); |
df9d6cf7 | 124 | extern const char* getStandardSharedCacheFilePath(); |
cf998323 | 125 | extern bool hasInsertedOrInterposingLibraries(); |
9f83892a A |
126 | bool sandboxBlockedOpen(const char* path); |
127 | bool sandboxBlockedMmap(const char* path); | |
128 | bool sandboxBlockedStat(const char* path); | |
cf998323 | 129 | void setMainEntry(void (*main)()); |
9f83892a A |
130 | |
131 | #if SUPPORT_ACCELERATE_TABLES | |
132 | bool dlopenFromCache(const char* path, int mode, void** handle); | |
133 | bool makeCacheHandle(ImageLoader* image, unsigned cacheIndex, int mode, void** result); | |
134 | void* dlsymFromCache(void* handle, const char* symName, unsigned index); | |
135 | bool isCacheHandle(void* handle); | |
136 | bool addressInCache(const void* address, const mach_header** mh, const char** path, unsigned* index=NULL); | |
137 | bool findUnwindSections(const void* addr, dyld_unwind_sections* info); | |
138 | bool dladdrFromCache(const void* address, Dl_info* info); | |
139 | bool isPathInCache(const char* path); | |
140 | const char* getPathFromIndex(unsigned cacheIndex); | |
141 | #endif | |
bc3b7c8c A |
142 | #if defined(__x86_64__) |
143 | bool isTranslated(); | |
144 | #endif | |
2fd3f4e8 | 145 | } |