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