]> git.saurik.com Git - apple/dyld.git/blob - src/dyld.h
dyld-433.5.tar.gz
[apple/dyld.git] / src / dyld.h
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 #include <dlfcn.h>
28
29 #include "ImageLoader.h"
30 #include "mach-o/dyld_priv.h"
31
32
33
34 //
35 // dyld functions available when implementing dyld API's
36 //
37 //
38 namespace dyld {
39
40 struct LoadContext
41 {
42 bool useSearchPaths;
43 bool useFallbackPaths;
44 bool useLdLibraryPath;
45 bool implicitRPath;
46 bool matchByInstallName;
47 bool dontLoad;
48 bool mustBeBundle;
49 bool mustBeDylib;
50 bool canBePIE;
51 const char* origin; // path for expanding @loader_path
52 const ImageLoader::RPathChain* rpath; // paths for expanding @rpath
53 };
54
55
56
57 typedef void (*ImageCallback)(const struct mach_header* mh, intptr_t slide);
58 typedef void (*UndefinedHandler)(const char* symbolName);
59 typedef const char* (*ImageLocator)(const char* dllName);
60
61
62 extern ImageLoader::LinkContext gLinkContext;
63 extern struct dyld_all_image_infos* gProcessInfo;
64 extern bool gLogAPIs;
65 #if SUPPORT_ACCELERATE_TABLES
66 extern bool gLogAppAPIs;
67 #endif
68 #if DYLD_SHARED_CACHE_SUPPORT
69 extern bool gSharedCacheOverridden;
70 #endif
71 extern const struct LibSystemHelpers* gLibSystemHelpers;
72 #if SUPPORT_OLD_CRT_INITIALIZATION
73 extern bool gRunInitializersOldWay;
74 #endif
75 extern void registerAddCallback(ImageCallback func);
76 extern void registerRemoveCallback(ImageCallback func);
77 extern void registerUndefinedHandler(UndefinedHandler);
78 extern void initializeMainExecutable();
79 extern void preflight(ImageLoader* image, const ImageLoader::RPathChain& loaderRPaths, unsigned cacheIndex);
80 extern void link(ImageLoader* image, bool forceLazysBound, bool neverUnload, const ImageLoader::RPathChain& loaderRPaths, unsigned cacheIndex);
81 extern void runInitializers(ImageLoader* image);
82 extern void runImageStaticTerminators(ImageLoader* image);
83 extern const char* getExecutablePath();
84 extern bool validImage(const ImageLoader*);
85 extern ImageLoader* getIndexedImage(uint32_t index);
86 extern uint32_t getImageCount();
87 extern ImageLoader* findImageByMachHeader(const struct mach_header* target);
88 extern ImageLoader* findImageContainingAddress(const void* addr);
89 extern ImageLoader* findImageContainingSymbol(const void* symbol);
90 extern ImageLoader* findImageByName(const char* path);
91 extern ImageLoader* findLoadedImageByInstallPath(const char* path);
92 extern bool flatFindExportedSymbol(const char* name, const ImageLoader::Symbol** sym, const ImageLoader** image);
93 extern bool flatFindExportedSymbolWithHint(const char* name, const char* librarySubstring, const ImageLoader::Symbol** sym, const ImageLoader** image);
94 extern ImageLoader* load(const char* path, const LoadContext& context, unsigned& cacheIndex);
95 extern ImageLoader* loadFromMemory(const uint8_t* mem, uint64_t len, const char* moduleName);
96 extern void removeImage(ImageLoader* image);
97 extern ImageLoader* cloneImage(ImageLoader* image);
98 extern void forEachImageDo( void (*)(ImageLoader*, void*), void*);
99 extern uintptr_t _main(const macho_header* mainExecutableMH, uintptr_t mainExecutableSlide, int argc, const char* argv[], const char* envp[],
100 const char* apple[], uintptr_t* startGlue) __attribute__((noinline)); // <rdar://problem/113
101 extern void halt(const char* message) __attribute__((noreturn));
102 extern void setErrorMessage(const char* msg);
103 extern const char* getErrorMessage();
104 extern void clearErrorMessage();
105 extern bool mainExecutablePrebound();
106 extern ImageLoader* mainExecutable();
107 extern void processDyldEnvironmentVariable(const char* key, const char* value, const char* mainDir);
108 extern void registerImageStateSingleChangeHandler(dyld_image_states state, dyld_image_state_change_handler handler);
109 extern void registerImageStateBatchChangeHandler(dyld_image_states state, dyld_image_state_change_handler handler);
110 extern void registerObjCNotifiers(_dyld_objc_notify_mapped, _dyld_objc_notify_init, _dyld_objc_notify_unmapped);
111 extern bool sharedCacheUUID(uuid_t uuid);
112 extern void garbageCollectImages();
113 extern int openSharedCacheFile();
114 extern const void* imMemorySharedCacheHeader();
115 extern uintptr_t fastBindLazySymbol(ImageLoader** imageLoaderCache, uintptr_t lazyBindingInfoOffset);
116 #if DYLD_SHARED_CACHE_SUPPORT
117 extern bool inSharedCache(const char* path);
118 #endif
119 #if LOG_BINDINGS
120 extern void logBindings(const char* format, ...);
121 #endif
122 extern bool processIsRestricted();
123 extern const char* getStandardSharedCacheFilePath();
124 extern int my_stat(const char* path, struct stat* buf);
125 extern int my_open(const char* path, int flag, int other);
126 bool sandboxBlockedOpen(const char* path);
127 bool sandboxBlockedMmap(const char* path);
128 bool sandboxBlockedStat(const char* path);
129
130 #if SUPPORT_ACCELERATE_TABLES
131 bool dlopenFromCache(const char* path, int mode, void** handle);
132 bool makeCacheHandle(ImageLoader* image, unsigned cacheIndex, int mode, void** result);
133 void* dlsymFromCache(void* handle, const char* symName, unsigned index);
134 bool isCacheHandle(void* handle);
135 bool addressInCache(const void* address, const mach_header** mh, const char** path, unsigned* index=NULL);
136 bool findUnwindSections(const void* addr, dyld_unwind_sections* info);
137 bool dladdrFromCache(const void* address, Dl_info* info);
138 bool isPathInCache(const char* path);
139 const char* getPathFromIndex(unsigned cacheIndex);
140 #endif
141 }
142