]> git.saurik.com Git - apple/dyld.git/blob - src/dyld2.h
dyld-750.5.tar.gz
[apple/dyld.git] / src / dyld2.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 #include <uuid/uuid.h>
29 #include <mach-o/dyld_priv.h>
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;
44 bool useFallbackPaths;
45 bool useLdLibraryPath;
46 bool implicitRPath;
47 bool matchByInstallName;
48 bool dontLoad;
49 bool mustBeBundle;
50 bool mustBeDylib;
51 bool canBePIE;
52 const char* origin; // path for expanding @loader_path
53 const ImageLoader::RPathChain* rpath; // paths for expanding @rpath
54 };
55
56
57
58 typedef void (*ImageCallback)(const struct mach_header* mh, intptr_t slide);
59 typedef void (*LoadImageCallback)(const mach_header* mh, const char* path, bool unloadable);
60 typedef void (*LoadImageBulkCallback)(unsigned count, const mach_header* mhs[], const char* paths[]);
61
62 typedef void (*UndefinedHandler)(const char* symbolName);
63 typedef const char* (*ImageLocator)(const char* dllName);
64
65
66 extern ImageLoader::LinkContext gLinkContext;
67 extern struct dyld_all_image_infos* gProcessInfo;
68 extern bool gLogAPIs;
69 #if SUPPORT_ACCELERATE_TABLES
70 extern bool gLogAppAPIs;
71 #endif
72 extern bool gSharedCacheOverridden;
73 extern const struct LibSystemHelpers* gLibSystemHelpers;
74 #if SUPPORT_OLD_CRT_INITIALIZATION
75 extern bool gRunInitializersOldWay;
76 #endif
77 extern void registerAddCallback(ImageCallback func);
78 extern void registerRemoveCallback(ImageCallback func);
79 extern void registerUndefinedHandler(UndefinedHandler);
80 extern void registerLoadCallback(LoadImageCallback func);
81 extern void registerBulkLoadCallback(LoadImageBulkCallback func);
82 extern void initializeMainExecutable();
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);
85 extern void runInitializers(ImageLoader* image);
86 extern void runImageStaticTerminators(ImageLoader* image);
87 extern const char* getExecutablePath();
88 extern bool validImage(const ImageLoader*);
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);
93 extern ImageLoader* findImageContainingSymbol(const void* symbol);
94 extern ImageLoader* findImageByName(const char* path);
95 extern ImageLoader* findLoadedImageByInstallPath(const char* path);
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);
98 extern ImageLoader* load(const char* path, const LoadContext& context, unsigned& cacheIndex);
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*);
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
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();
111 extern void processDyldEnvironmentVariable(const char* key, const char* value, const char* mainDir);
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);
114 extern void registerObjCNotifiers(_dyld_objc_notify_mapped, _dyld_objc_notify_init, _dyld_objc_notify_unmapped);
115 extern bool sharedCacheUUID(uuid_t uuid);
116 extern void garbageCollectImages();
117 extern const void* imMemorySharedCacheHeader();
118 extern uintptr_t fastBindLazySymbol(ImageLoader** imageLoaderCache, uintptr_t lazyBindingInfoOffset);
119 extern bool inSharedCache(const char* path);
120 #if LOG_BINDINGS
121 extern void logBindings(const char* format, ...);
122 #endif
123 extern bool processIsRestricted();
124 extern const char* getStandardSharedCacheFilePath();
125 extern bool hasInsertedOrInterposingLibraries();
126 extern int my_stat(const char* path, struct stat* buf);
127 extern int my_open(const char* path, int flag, int other);
128 bool sandboxBlockedOpen(const char* path);
129 bool sandboxBlockedMmap(const char* path);
130 bool sandboxBlockedStat(const char* path);
131 void setMainEntry(void (*main)());
132
133 #if SUPPORT_ACCELERATE_TABLES
134 bool dlopenFromCache(const char* path, int mode, void** handle);
135 bool makeCacheHandle(ImageLoader* image, unsigned cacheIndex, int mode, void** result);
136 void* dlsymFromCache(void* handle, const char* symName, unsigned index);
137 bool isCacheHandle(void* handle);
138 bool addressInCache(const void* address, const mach_header** mh, const char** path, unsigned* index=NULL);
139 bool findUnwindSections(const void* addr, dyld_unwind_sections* info);
140 bool dladdrFromCache(const void* address, Dl_info* info);
141 bool isPathInCache(const char* path);
142 const char* getPathFromIndex(unsigned cacheIndex);
143 #endif
144 }