]>
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> |
0959b6d4 A |
27 | |
28 | #include "ImageLoader.h" | |
bac542e6 | 29 | #include "mach-o/dyld_priv.h" |
0959b6d4 A |
30 | |
31 | ||
32 | ||
33 | // | |
34 | // dyld functions available when implementing dyld API's | |
35 | // | |
36 | // | |
37 | namespace dyld { | |
38 | ||
39 | struct LoadContext | |
40 | { | |
41 | bool useSearchPaths; | |
39a8cd10 | 42 | bool useFallbackPaths; |
0959b6d4 | 43 | bool useLdLibraryPath; |
bac542e6 | 44 | bool implicitRPath; |
0959b6d4 A |
45 | bool matchByInstallName; |
46 | bool dontLoad; | |
47 | bool mustBeBundle; | |
48 | bool mustBeDylib; | |
39a8cd10 | 49 | bool canBePIE; |
bac542e6 A |
50 | const char* origin; // path for expanding @loader_path |
51 | const ImageLoader::RPathChain* rpath; // paths for expanding @rpath | |
0959b6d4 A |
52 | }; |
53 | ||
54 | ||
55 | ||
56 | typedef void (*ImageCallback)(const struct mach_header* mh, intptr_t slide); | |
0959b6d4 | 57 | typedef void (*UndefinedHandler)(const char* symbolName); |
bac542e6 | 58 | typedef const char* (*ImageLocator)(const char* dllName); |
0959b6d4 A |
59 | |
60 | ||
61 | extern ImageLoader::LinkContext gLinkContext; | |
2fd3f4e8 | 62 | extern struct dyld_all_image_infos* gProcessInfo; |
0959b6d4 | 63 | extern bool gLogAPIs; |
2fd3f4e8 | 64 | #if DYLD_SHARED_CACHE_SUPPORT |
412ebb8e | 65 | extern bool gSharedCacheOverridden; |
2fd3f4e8 | 66 | #endif |
bac542e6 A |
67 | extern const struct LibSystemHelpers* gLibSystemHelpers; |
68 | #if SUPPORT_OLD_CRT_INITIALIZATION | |
69 | extern bool gRunInitializersOldWay; | |
70 | #endif | |
0959b6d4 A |
71 | extern void registerAddCallback(ImageCallback func); |
72 | extern void registerRemoveCallback(ImageCallback func); | |
0959b6d4 A |
73 | extern void registerUndefinedHandler(UndefinedHandler); |
74 | extern void initializeMainExecutable(); | |
bac542e6 | 75 | extern void preflight(ImageLoader* image, const ImageLoader::RPathChain& loaderRPaths); |
2fd3f4e8 | 76 | extern void link(ImageLoader* image, bool forceLazysBound, bool neverUnload, const ImageLoader::RPathChain& loaderRPaths); |
bac542e6 | 77 | extern void runInitializers(ImageLoader* image); |
19894a12 | 78 | extern void runImageStaticTerminators(ImageLoader* image); |
0959b6d4 | 79 | extern const char* getExecutablePath(); |
bac542e6 | 80 | extern bool validImage(const ImageLoader*); |
0959b6d4 A |
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); | |
39a8cd10 | 85 | extern ImageLoader* findImageContainingSymbol(const void* symbol); |
0959b6d4 A |
86 | extern ImageLoader* findImageByName(const char* path); |
87 | extern ImageLoader* findLoadedImageByInstallPath(const char* path); | |
bac542e6 A |
88 | extern bool flatFindExportedSymbol(const char* name, const ImageLoader::Symbol** sym, const ImageLoader** image); |
89 | extern bool flatFindExportedSymbolWithHint(const char* name, const char* librarySubstring, const ImageLoader::Symbol** sym, const ImageLoader** image); | |
0959b6d4 A |
90 | extern ImageLoader* load(const char* path, const LoadContext& context); |
91 | extern ImageLoader* loadFromMemory(const uint8_t* mem, uint64_t len, const char* moduleName); | |
92 | extern void removeImage(ImageLoader* image); | |
93 | extern ImageLoader* cloneImage(ImageLoader* image); | |
94 | extern void forEachImageDo( void (*)(ImageLoader*, void*), void*); | |
19894a12 A |
95 | extern uintptr_t _main(const macho_header* mainExecutableMH, uintptr_t mainExecutableSlide, int argc, const char* argv[], const char* envp[], |
96 | const char* apple[], uintptr_t* startGlue) __attribute__((noinline)); // <rdar://problem/113 | |
0959b6d4 A |
97 | extern void halt(const char* message) __attribute__((noreturn)); |
98 | extern void setErrorMessage(const char* msg); | |
99 | extern const char* getErrorMessage(); | |
100 | extern void clearErrorMessage(); | |
101 | extern bool mainExecutablePrebound(); | |
102 | extern ImageLoader* mainExecutable(); | |
412ebb8e | 103 | extern void processDyldEnvironmentVariable(const char* key, const char* value, const char* mainDir); |
bac542e6 A |
104 | extern void registerImageStateSingleChangeHandler(dyld_image_states state, dyld_image_state_change_handler handler); |
105 | extern void registerImageStateBatchChangeHandler(dyld_image_states state, dyld_image_state_change_handler handler); | |
106 | extern void garbageCollectImages(); | |
2028a915 A |
107 | extern int openSharedCacheFile(); |
108 | extern const void* imMemorySharedCacheHeader(); | |
39a8cd10 | 109 | extern uintptr_t fastBindLazySymbol(ImageLoader** imageLoaderCache, uintptr_t lazyBindingInfoOffset); |
2fd3f4e8 | 110 | #if DYLD_SHARED_CACHE_SUPPORT |
39a8cd10 | 111 | extern bool inSharedCache(const char* path); |
2fd3f4e8 | 112 | #endif |
412ebb8e A |
113 | #if LOG_BINDINGS |
114 | extern void logBindings(const char* format, ...); | |
115 | #endif | |
2fd3f4e8 | 116 | extern bool processIsRestricted(); |
df9d6cf7 | 117 | extern const char* getStandardSharedCacheFilePath(); |
2fd3f4e8 A |
118 | extern int my_stat(const char* path, struct stat* buf); |
119 | extern int my_open(const char* path, int flag, int other); | |
120 | } | |
0959b6d4 | 121 |