]> git.saurik.com Git - apple/dyld.git/blob - dyld3/PathOverrides.h
dyld-733.8.tar.gz
[apple/dyld.git] / dyld3 / PathOverrides.h
1 /*
2 * Copyright (c) 2017 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25
26 #ifndef __DYLD_PATH_OVERRIDES_H__
27 #define __DYLD_PATH_OVERRIDES_H__
28
29 #include <stdint.h>
30
31 #include "Logging.h"
32 #include "MachOFile.h"
33
34
35 namespace dyld3 {
36 namespace closure {
37
38
39 class VIS_HIDDEN PathPool
40 {
41 public:
42 static PathPool* allocate();
43 static void deallocate(PathPool* pool);
44 const char* add(const char* path);
45 void forEachPath(void (^handler)(const char* path));
46
47 private:
48 enum { kAllocationSize = 32*1024 };
49
50 PathPool* _next;
51 char* _current;
52 size_t _bytesFree;
53 char _buffer[];
54 };
55
56
57 class VIS_HIDDEN PathOverrides
58 {
59 public:
60 #if !BUILDING_LIBDYLD
61 // libdyld is never unloaded
62 ~PathOverrides();
63 #endif
64 enum class FallbackPathMode { classic, restricted, none };
65
66 void setFallbackPathHandling(FallbackPathMode mode);
67 void setEnvVars(const char* envp[], const dyld3::MachOFile* mainExe, const char* mainExePath);
68 void setMainExecutable(const dyld3::MachOFile* mainExe, const char* mainExePath);
69 void forEachPathVariant(const char* requestedPath, bool pathIsInDyldCacheWhichCannotBeOverridden, void (^handler)(const char* possiblePath, bool isFallbackPath, bool& stop),
70 Platform plat=MachOFile::currentPlatform()) const;
71
72 void forEachEnvVar(void (^handler)(const char* envVar)) const;
73 void forEachExecutableEnvVar(void (^handler)(const char* envVar)) const;
74 void forEachInsertedDylib(void (^handler)(const char* dylibPath, bool &stop)) const;
75
76 private:
77 void setString(const char*& var, const char* value);
78 const char* addString(const char* str);
79 static void forEachInColonList(const char* list1, const char* list2, void (^callback)(const char* path, bool& stop));
80 void addEnvVar(const char* keyEqualsValue, bool forExecutable);
81 const char* getFrameworkPartialPath(const char* path) const;
82 static const char* getLibraryLeafName(const char* path);
83 void handleListEnvVar(const char* key, const char** list, void (^handler)(const char* envVar)) const;
84 void handleEnvVar(const char* key, const char* value, void (^handler)(const char* envVar)) const;
85 void forEachDylibFallback(Platform platform, void (^handler)(const char* fallbackDir, bool& stop)) const;
86 void forEachFrameworkFallback(Platform platform, void (^handler)(const char* fallbackDir, bool& stop)) const;
87 void forEachImageSuffix(const char* path, bool isFallbackPath, bool pathIsInDyldCacheWhichCannotBeOverridden, bool& stop, void (^handler)(const char* possiblePath, bool isFallbackPath, bool& stop)) const;
88 void addSuffix(const char* path, const char* suffix, char* result) const;
89
90 PathPool* _pathPool = nullptr;
91 const char* _dylibPathOverridesEnv = nullptr;
92 const char* _frameworkPathOverridesEnv = nullptr;
93 const char* _dylibPathFallbacksEnv = nullptr;
94 const char* _frameworkPathFallbacksEnv = nullptr;
95 const char* _dylibPathOverridesExeLC = nullptr;
96 const char* _frameworkPathOverridesExeLC = nullptr;
97 const char* _dylibPathFallbacksExeLC = nullptr;
98 const char* _frameworkPathFallbacksExeLC = nullptr;
99 const char* _insertedDylibs = nullptr;
100 const char* _imageSuffix = nullptr;
101 const char* _rootPath = nullptr; // simulator only
102 FallbackPathMode _fallbackPathMode = FallbackPathMode::classic;
103 };
104
105 #if BUILDING_LIBDYLD
106 extern PathOverrides gPathOverrides;
107 #endif
108
109
110 } // namespace closure
111 } // namespace dyld3
112
113 #endif // __DYLD_PATH_OVERRIDES_H__
114
115