From 67dbe4b47dd65b9e9bced2d39017cab0b6cfe388 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Fri, 20 Dec 2024 11:52:46 -0800 Subject: [PATCH] FEXInterpreter: Punch through a /sys/fex/rootfs node Currently pressure-vessel does a bit of a bodge to get the x86 rootfs path when running inside of FEX. It does this by opening `/.` which works around our pseudo-overlayfs tracking. While this worked, it wasn't guaranteed to work forever. With #4225 working to fix more issues around how rootfs is laid out, it had to break this path (while adding a workaround for it to keep working). Give pressure-vessel a blessed path from the EmulatedFiles code paths to get a real fd back to the x86 rootfs, that way if we break this code path it is entirely our problem to fix. Still need to have a conversation with upstream pressure-vessel to see if they'll accept this path or if we need to do something different. We can also use this same mechanism in the future if we want to expose more FEX specific data to the application through this. --- External/fmt | 2 +- .../LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp | 6 ++++++ .../LinuxSyscalls/EmulatedFiles/EmulatedFiles.h | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/External/fmt b/External/fmt index 873670ba3f..0c9fce2ffe 160000 --- a/External/fmt +++ b/External/fmt @@ -1 +1 @@ -Subproject commit 873670ba3f9e7bc77ec2c1c94b04f1f8bef77e9f +Subproject commit 0c9fce2ffefecfdce794e1859584e25877b7b592 diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp index c84c9eaa2b..18e79add79 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp @@ -573,6 +573,12 @@ EmulatedFDManager::EmulatedFDManager(FEXCore::Context::Context* ctx) fextl::string procCmdLine = fextl::fmt::format("/proc/{}/cmdline", getpid()); FDReadCreators[procCmdLine] = cmdline_handler; + // FEX-Emu specific file handles + FDReadCreators["/sys/fex/rootfs"] = [&](FEXCore::Context::Context* ctx, int32_t fd, const char* pathname, int32_t flags, mode_t mode) -> int32_t { + // Redirect to the guest rootfs + return ::syscall(SYSCALL_DEF(openat), fd, LDPath().c_str(), flags, mode); + }; + if (ThreadsConfig > 1) { cpus_online = fextl::fmt::format("0-{}", ThreadsConfig - 1); } else { diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.h index a1ce479afe..155ec20725 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.h +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.h @@ -35,5 +35,7 @@ class EmulatedFDManager { static int32_t ProcAuxv(FEXCore::Context::Context* ctx, int32_t fd, const char* pathname, int32_t flags, mode_t mode); const uint32_t ThreadsConfig; + + FEX_CONFIG_OPT(LDPath, ROOTFS); }; } // namespace FEX::EmulatedFile