2 * Copyright (c) 2017 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
26 #ifndef __DYLD_PATH_OVERRIDES_H__
27 #define __DYLD_PATH_OVERRIDES_H__
32 #include "MachOFile.h"
39 class VIS_HIDDEN PathPool
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;
49 enum { kAllocationSize
= 32*1024 };
58 class VIS_HIDDEN PathOverrides
62 // libdyld is never unloaded
65 enum class FallbackPathMode
{ classic
, restricted
, none
};
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;
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;
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;
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
;
107 extern PathOverrides gPathOverrides
;
111 } // namespace closure
114 #endif // __DYLD_PATH_OVERRIDES_H__