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
));
48 enum { kAllocationSize
= 32*1024 };
57 class VIS_HIDDEN PathOverrides
61 // libdyld is never unloaded
64 enum class FallbackPathMode
{ classic
, restricted
, none
};
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
, void (^handler
)(const char* possiblePath
, bool isFallbackPath
, bool& stop
),
70 Platform plat
=MachOFile::currentPlatform()) const;
72 uint32_t envVarCount() const;
73 void forEachEnvVar(void (^handler
)(const char* envVar
)) const;
74 void forEachInsertedDylib(void (^handler
)(const char* dylibPath
)) const;
77 void setString(const char*& var
, const char* value
);
78 const char* addString(const char* str
);
79 static void forEachInColonList(const char* list
, void (^callback
)(const char* path
, bool& stop
));
80 void addEnvVar(const char* keyEqualsValue
);
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& stop
, void (^handler
)(const char* possiblePath
, bool isFallbackPath
, bool& stop
)) const;
88 void addSuffix(const char* path
, const char* suffix
, char* result
) const;
90 PathPool
* _pathPool
= nullptr;
91 const char* _dylibPathOverrides
= nullptr;
92 const char* _frameworkPathOverrides
= nullptr;
93 const char* _dylibPathFallbacks
= nullptr;
94 const char* _frameworkPathFallbacks
= nullptr;
95 const char* _insertedDylibs
= nullptr;
96 const char* _imageSuffix
= nullptr;
97 const char* _rootPath
= nullptr; // simulator only
98 FallbackPathMode _fallbackPathMode
= FallbackPathMode::classic
;
102 extern PathOverrides gPathOverrides
;
106 } // namespace closure
109 #endif // __DYLD_PATH_OVERRIDES_H__