]> git.saurik.com Git - apple/dyld.git/blob - dyld3/PathOverrides.h
dyld-832.7.1.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)) const;
46 bool contains(const char* path) const;
47
48 private:
49 enum { kAllocationSize = 32*1024 };
50
51 PathPool* _next;
52 char* _current;
53 size_t _bytesFree;
54 char _buffer[];
55 };
56
57
58 class VIS_HIDDEN PathOverrides
59 {
60 public:
61 #if !BUILDING_LIBDYLD
62 // libdyld is never unloaded
63 ~PathOverrides();
64 #endif
65 enum class FallbackPathMode { classic, restricted, none };
66
67 void setFallbackPathHandling(FallbackPathMode mode);
68 void setEnvVars(const char* envp[], const dyld3::MachOFile* mainExe, const char* mainExePath);
69 void setMainExecutable(const dyld3::MachOFile* mainExe, const char* mainExePath);
70 void forEachPathVariant(const char* requestedPath, bool pathIsInDyldCacheWhichCannotBeOverridden, void (^handler)(const char* possiblePath, bool isFallbackPath, bool& stop),
71 Platform plat=MachOFile::currentPlatform()) const;
72
73 void forEachEnvVar(void (^handler)(const char* envVar)) const;
74 void forEachExecutableEnvVar(void (^handler)(const char* envVar)) const;
75 void forEachInsertedDylib(void (^handler)(const char* dylibPath, bool &stop)) const;
76
77 private:
78 void setString(const char*& var, const char* value);
79 const char* addString(const char* str);
80 static void forEachInColonList(const char* list1, const char* list2, void (^callback)(const char* path, bool& stop));
81 void addEnvVar(const char* keyEqualsValue, bool forExecutable);
82 const char* getFrameworkPartialPath(const char* path) const;
83 static const char* getLibraryLeafName(const char* path);
84 void handleListEnvVar(const char* key, const char** list, void (^handler)(const char* envVar)) const;
85 void handleEnvVar(const char* key, const char* value, void (^handler)(const char* envVar)) const;
86 void forEachDylibFallback(Platform platform, void (^handler)(const char* fallbackDir, bool& stop)) const;
87 void forEachFrameworkFallback(Platform platform, void (^handler)(const char* fallbackDir, bool& stop)) const;
88 void forEachImageSuffix(const char* path, bool isFallbackPath, bool pathIsInDyldCacheWhichCannotBeOverridden, bool& stop, void (^handler)(const char* possiblePath, bool isFallbackPath, bool& stop)) const;
89 void addSuffix(const char* path, const char* suffix, char* result) const;
90
91 PathPool* _pathPool = nullptr;
92 const char* _dylibPathOverridesEnv = nullptr;
93 const char* _frameworkPathOverridesEnv = nullptr;
94 const char* _dylibPathFallbacksEnv = nullptr;
95 const char* _frameworkPathFallbacksEnv = nullptr;
96 const char* _dylibPathOverridesExeLC = nullptr;
97 const char* _frameworkPathOverridesExeLC = nullptr;
98 const char* _dylibPathFallbacksExeLC = nullptr;
99 const char* _frameworkPathFallbacksExeLC = nullptr;
100 const char* _insertedDylibs = nullptr;
101 const char* _imageSuffix = nullptr;
102 const char* _rootPath = nullptr; // simulator only
103 FallbackPathMode _fallbackPathMode = FallbackPathMode::classic;
104 };
105
106 #if BUILDING_LIBDYLD
107 extern PathOverrides gPathOverrides;
108 #endif
109
110
111 } // namespace closure
112 } // namespace dyld3
113
114 #endif // __DYLD_PATH_OVERRIDES_H__
115
116