]>
Commit | Line | Data |
---|---|---|
1 | /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*- | |
2 | * | |
3 | * Copyright (c) 2004-2009 Apple Inc. All rights reserved. | |
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> | |
26 | #include <sys/stat.h> | |
27 | ||
28 | #include "ImageLoader.h" | |
29 | #include "mach-o/dyld_priv.h" | |
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; | |
42 | bool useFallbackPaths; | |
43 | bool useLdLibraryPath; | |
44 | bool implicitRPath; | |
45 | bool matchByInstallName; | |
46 | bool dontLoad; | |
47 | bool mustBeBundle; | |
48 | bool mustBeDylib; | |
49 | bool canBePIE; | |
50 | const char* origin; // path for expanding @loader_path | |
51 | const ImageLoader::RPathChain* rpath; // paths for expanding @rpath | |
52 | }; | |
53 | ||
54 | ||
55 | ||
56 | typedef void (*ImageCallback)(const struct mach_header* mh, intptr_t slide); | |
57 | typedef void (*UndefinedHandler)(const char* symbolName); | |
58 | typedef const char* (*ImageLocator)(const char* dllName); | |
59 | ||
60 | ||
61 | extern ImageLoader::LinkContext gLinkContext; | |
62 | extern struct dyld_all_image_infos* gProcessInfo; | |
63 | extern bool gLogAPIs; | |
64 | #if DYLD_SHARED_CACHE_SUPPORT | |
65 | extern bool gSharedCacheOverridden; | |
66 | #endif | |
67 | extern const struct LibSystemHelpers* gLibSystemHelpers; | |
68 | #if SUPPORT_OLD_CRT_INITIALIZATION | |
69 | extern bool gRunInitializersOldWay; | |
70 | #endif | |
71 | extern void registerAddCallback(ImageCallback func); | |
72 | extern void registerRemoveCallback(ImageCallback func); | |
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, bool neverUnload, const ImageLoader::RPathChain& loaderRPaths); | |
77 | extern void runInitializers(ImageLoader* image); | |
78 | extern void runImageStaticTerminators(ImageLoader* image); | |
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* findImageContainingSymbol(const void* symbol); | |
86 | extern ImageLoader* findImageByName(const char* path); | |
87 | extern ImageLoader* findLoadedImageByInstallPath(const char* path); | |
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); | |
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*); | |
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 | |
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(); | |
103 | extern void processDyldEnvironmentVariable(const char* key, const char* value, const char* mainDir); | |
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(); | |
107 | extern int openSharedCacheFile(); | |
108 | extern const void* imMemorySharedCacheHeader(); | |
109 | extern uintptr_t fastBindLazySymbol(ImageLoader** imageLoaderCache, uintptr_t lazyBindingInfoOffset); | |
110 | #if DYLD_SHARED_CACHE_SUPPORT | |
111 | extern bool inSharedCache(const char* path); | |
112 | #endif | |
113 | #if LOG_BINDINGS | |
114 | extern void logBindings(const char* format, ...); | |
115 | #endif | |
116 | extern bool processIsRestricted(); | |
117 | extern const char* getStandardSharedCacheFilePath(); | |
118 | extern int my_stat(const char* path, struct stat* buf); | |
119 | extern int my_open(const char* path, int flag, int other); | |
120 | } | |
121 |