diff --git a/FEXCore/Source/Interface/Config/Config.cpp b/FEXCore/Source/Interface/Config/Config.cpp index cb2e54231..75103bf12 100644 --- a/FEXCore/Source/Interface/Config/Config.cpp +++ b/FEXCore/Source/Interface/Config/Config.cpp @@ -334,9 +334,14 @@ void ReloadMetaLayer() { FEXCore::Config::EraseSet(FEXCore::Config::CONFIG_ROOTFS, ExpandedString); } else if (!PathName->empty()) { // If the filesystem doesn't exist then let's see if it exists in the fex-emu folder - fextl::string NamedRootFS = GetDataDirectory(false) + "RootFS/" + *PathName; - if (FHU::Filesystem::Exists(NamedRootFS)) { - FEXCore::Config::EraseSet(FEXCore::Config::CONFIG_ROOTFS, NamedRootFS); + const auto PathNameCopy = *PathName; + for (auto Global : {true, false}) { + for (auto DirectoryFetchers : {GetDataDirectory, GetConfigDirectory}) { + fextl::string NamedRootFS = DirectoryFetchers(Global) + "RootFS/" + PathNameCopy; + if (FHU::Filesystem::Exists(NamedRootFS)) { + FEXCore::Config::EraseSet(FEXCore::Config::CONFIG_ROOTFS, NamedRootFS); + } + } } } } @@ -356,9 +361,14 @@ void ReloadMetaLayer() { FEXCore::Config::EraseSet(FEXCore::Config::CONFIG_THUNKCONFIG, ExpandedString); } else if (!PathName->empty()) { // If the filesystem doesn't exist then let's see if it exists in the fex-emu folder - fextl::string NamedConfig = GetDataDirectory(false) + "ThunkConfigs/" + *PathName; - if (FHU::Filesystem::Exists(NamedConfig)) { - FEXCore::Config::EraseSet(FEXCore::Config::CONFIG_THUNKCONFIG, NamedConfig); + const auto PathNameCopy = *PathName; + for (auto Global : {true, false}) { + for (auto DirectoryFetchers : {GetDataDirectory, GetConfigDirectory}) { + fextl::string NamedConfig = DirectoryFetchers(Global) + "ThunkConfigs/" + PathNameCopy; + if (FHU::Filesystem::Exists(NamedConfig)) { + FEXCore::Config::EraseSet(FEXCore::Config::CONFIG_THUNKCONFIG, NamedConfig); + } + } } } } diff --git a/Source/Tools/CommonTools/PortabilityInfo.h b/Source/Tools/CommonTools/PortabilityInfo.h new file mode 100644 index 000000000..13e01080c --- /dev/null +++ b/Source/Tools/CommonTools/PortabilityInfo.h @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: MIT +#pragma once +#include "Common/Config.h" + +namespace FEX { +static inline FEX::Config::PortableInformation ReadPortabilityInformation() { + const FEX::Config::PortableInformation BadResult {false, {}}; + const char* PortableConfig = getenv("FEX_PORTABLE"); + if (!PortableConfig) { + return BadResult; + } + + uint32_t Value {}; + std::string_view PortableView {PortableConfig}; + + if (std::from_chars(PortableView.data(), PortableView.data() + PortableView.size(), Value).ec != std::errc {} || Value == 0) { + return BadResult; + } + + // Read the FEXInterpreter path from `/proc/self/exe` which is always a symlink to the absolute path of the executable running. + // This way we can get the parent path that the application is executing from. + char SelfPath[PATH_MAX]; + auto Result = readlink("/proc/self/exe", SelfPath, PATH_MAX); + if (Result == -1) { + return BadResult; + } + + std::string_view SelfPathView {SelfPath, std::min(PATH_MAX, Result)}; + + // Extract the absolute path from the FEXInterpreter path + return {true, fextl::string {SelfPathView.substr(0, SelfPathView.find_last_of('/') + 1)}}; +} +} // namespace FEX diff --git a/Source/Tools/FEXLoader/FEXLoader.cpp b/Source/Tools/FEXLoader/FEXLoader.cpp index f905df9ee..6de4ba572 100644 --- a/Source/Tools/FEXLoader/FEXLoader.cpp +++ b/Source/Tools/FEXLoader/FEXLoader.cpp @@ -11,6 +11,7 @@ $end_info$ #include "Common/FEXServerClient.h" #include "Common/Config.h" #include "Common/HostFeatures.h" +#include "PortabilityInfo.h" #include "ELFCodeLoader.h" #include "VDSO_Emulation.h" #include "LinuxSyscalls/GdbServer.h" @@ -176,34 +177,6 @@ bool InterpreterHandler(fextl::string* Filename, const fextl::string& RootFS, fe return true; } -FEX::Config::PortableInformation ReadPortabilityInformation() { - const FEX::Config::PortableInformation BadResult {false, {}}; - const char* PortableConfig = getenv("FEX_PORTABLE"); - if (!PortableConfig) { - return BadResult; - } - - uint32_t Value {}; - std::string_view PortableView {PortableConfig}; - - if (std::from_chars(PortableView.data(), PortableView.data() + PortableView.size(), Value).ec != std::errc {} || Value == 0) { - return BadResult; - } - - // Read the FEXInterpreter path from `/proc/self/exe` which is always a symlink to the absolute path of the executable running. - // This way we can get the parent path that the application is executing from. - char SelfPath[PATH_MAX]; - auto Result = readlink("/proc/self/exe", SelfPath, PATH_MAX); - if (Result == -1) { - return BadResult; - } - - std::string_view SelfPathView {SelfPath, std::min(PATH_MAX, Result)}; - - // Extract the absolute path from the FEXInterpreter path - return {true, fextl::string {SelfPathView.substr(0, SelfPathView.find_last_of('/') + 1)}}; -} - bool RanAsInterpreter(bool ExecutedWithFD) { return ExecutedWithFD || FEXLOADER_AS_INTERPRETER; } @@ -323,7 +296,7 @@ int main(int argc, char** argv, char** const envp) { const bool ExecutedWithFD = getauxval(AT_EXECFD) != 0; const bool IsInterpreter = RanAsInterpreter(ExecutedWithFD); - const auto PortableInfo = ReadPortabilityInformation(); + const auto PortableInfo = FEX::ReadPortabilityInformation(); const bool InterpreterInstalled = QueryInterpreterInstalled(ExecutedWithFD, PortableInfo); int FEXFD {StealFEXFDFromEnv("FEX_EXECVEFD")}; diff --git a/Source/Tools/FEXServer/CMakeLists.txt b/Source/Tools/FEXServer/CMakeLists.txt index dc3e8de13..e967b114e 100644 --- a/Source/Tools/FEXServer/CMakeLists.txt +++ b/Source/Tools/FEXServer/CMakeLists.txt @@ -12,7 +12,7 @@ target_include_directories(${NAME} PRIVATE ${CMAKE_BINARY_DIR}/generated ${CMAKE_SOURCE_DIR}/Source/) -target_link_libraries(${NAME} PRIVATE FEXCore Common JemallocDummy ${PTHREAD_LIB}) +target_link_libraries(${NAME} PRIVATE FEXCore Common CommonTools JemallocDummy ${PTHREAD_LIB}) if (CMAKE_BUILD_TYPE MATCHES "RELEASE") target_link_options(${NAME} diff --git a/Source/Tools/FEXServer/Main.cpp b/Source/Tools/FEXServer/Main.cpp index 255debb2c..be82dc978 100644 --- a/Source/Tools/FEXServer/Main.cpp +++ b/Source/Tools/FEXServer/Main.cpp @@ -2,6 +2,7 @@ #include "ArgumentLoader.h" #include "Logger.h" #include "PipeScanner.h" +#include "PortabilityInfo.h" #include "ProcessPipe.h" #include "SquashFS.h" #include "Common/ArgumentLoader.h" @@ -117,7 +118,7 @@ int main(int argc, char** argv, char** const envp) { } auto ArgsLoader = fextl::make_unique(FEX::ArgLoader::ArgLoader::LoadType::WITHOUT_FEXLOADER_PARSER, argc, argv); - FEX::Config::LoadConfig(std::move(ArgsLoader), {}, envp); + FEX::Config::LoadConfig(std::move(ArgsLoader), {}, envp, FEX::ReadPortabilityInformation()); // Reload the meta layer FEXCore::Config::ReloadMetaLayer();