]> git.saurik.com Git - apple/dyld.git/blob - src/dyld.h
dyld-519.2.2.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 extern bool gSharedCacheOverridden;
69 extern const struct LibSystemHelpers* gLibSystemHelpers;
70 #if SUPPORT_OLD_CRT_INITIALIZATION
71 extern bool gRunInitializersOldWay;
72 #endif
73 extern void registerAddCallback(ImageCallback func);
74 extern void registerRemoveCallback(ImageCallback func);
75 extern void registerUndefinedHandler(UndefinedHandler);
76 extern void initializeMainExecutable();
77 extern void preflight(ImageLoader* image, const ImageLoader::RPathChain& loaderRPaths, unsigned cacheIndex);
78 extern void link(ImageLoader* image, bool forceLazysBound, bool neverUnload, const ImageLoader::RPathChain& loaderRPaths, unsigned cacheIndex);
79 extern void runInitializers(ImageLoader* image);
80 extern void runImageStaticTerminators(ImageLoader* image);
81 extern const char* getExecutablePath();
82 extern bool validImage(const ImageLoader*);
83 extern ImageLoader* getIndexedImage(uint32_t index);
84 extern uint32_t getImageCount();
85 extern ImageLoader* findImageByMachHeader(const struct mach_header* target);
86 extern ImageLoader* findImageContainingAddress(const void* addr);
87 extern ImageLoader* findImageContainingSymbol(const void* symbol);
88 extern ImageLoader* findImageByName(const char* path);
89 extern ImageLoader* findLoadedImageByInstallPath(const char* path);
90 extern bool flatFindExportedSymbol(const char* name, const ImageLoader::Symbol** sym, const ImageLoader** image);
91 extern bool flatFindExportedSymbolWithHint(const char* name, const char* librarySubstring, const ImageLoader::Symbol** sym, const ImageLoader** image);
92 extern ImageLoader* load(const char* path, const LoadContext& context, unsigned& cacheIndex);
93 extern ImageLoader* loadFromMemory(const uint8_t* mem, uint64_t len, const char* moduleName);
94 extern void removeImage(ImageLoader* image);
95 extern ImageLoader* cloneImage(ImageLoader* image);
96 extern void forEachImageDo( void (*)(ImageLoader*, void*), void*);
97 extern uintptr_t _main(const macho_header* mainExecutableMH, uintptr_t mainExecutableSlide, int argc, const char* argv[], const char* envp[],
98 const char* apple[], uintptr_t* startGlue) __attribute__((noinline)); // <rdar://problem/113
99 extern void halt(const char* message) __attribute__((noreturn));
100 extern void setErrorMessage(const char* msg);
101 extern const char* getErrorMessage();
102 extern void clearErrorMessage();
103 extern bool mainExecutablePrebound();
104 extern ImageLoader* mainExecutable();
105 extern void processDyldEnvironmentVariable(const char* key, const char* value, const char* mainDir);
106 extern void registerImageStateSingleChangeHandler(dyld_image_states state, dyld_image_state_change_handler handler);
107 extern void registerImageStateBatchChangeHandler(dyld_image_states state, dyld_image_state_change_handler handler);
108 extern void registerObjCNotifiers(_dyld_objc_notify_mapped, _dyld_objc_notify_init, _dyld_objc_notify_unmapped);
109 extern bool sharedCacheUUID(uuid_t uuid);
110 extern void garbageCollectImages();
111 extern const void* imMemorySharedCacheHeader();
112 extern uintptr_t fastBindLazySymbol(ImageLoader** imageLoaderCache, uintptr_t lazyBindingInfoOffset);
113 extern bool inSharedCache(const char* path);
114 #if LOG_BINDINGS
115 extern void logBindings(const char* format, ...);
116 #endif
117 extern bool processIsRestricted();
118 extern const char* getStandardSharedCacheFilePath();
119 extern int my_stat(const char* path, struct stat* buf);
120 extern int my_open(const char* path, int flag, int other);
121 bool sandboxBlockedOpen(const char* path);
122 bool sandboxBlockedMmap(const char* path);
123 bool sandboxBlockedStat(const char* path);
124
125 #if SUPPORT_ACCELERATE_TABLES
126 bool dlopenFromCache(const char* path, int mode, void** handle);
127 bool makeCacheHandle(ImageLoader* image, unsigned cacheIndex, int mode, void** result);
128 void* dlsymFromCache(void* handle, const char* symName, unsigned index);
129 bool isCacheHandle(void* handle);
130 bool addressInCache(const void* address, const mach_header** mh, const char** path, unsigned* index=NULL);
131 bool findUnwindSections(const void* addr, dyld_unwind_sections* info);
132 bool dladdrFromCache(const void* address, Dl_info* info);
133 bool isPathInCache(const char* path);
134 const char* getPathFromIndex(unsigned cacheIndex);
135 #endif
136 }
137