From 183c5d9e225c8ff38173b02190ecbffa46b41928 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sat, 18 Jul 2020 09:16:59 +1200 Subject: [PATCH] Filesystem HLE: Intercept /proc/${getpid}/exe too --- .../FEXCore/Source/Interface/HLE/FileManagement.cpp | 11 ++++++++++- .../FEXCore/Source/Interface/HLE/FileManagement.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/External/FEXCore/Source/Interface/HLE/FileManagement.cpp b/External/FEXCore/Source/Interface/HLE/FileManagement.cpp index 7edc8b0ee..c6ed3fd6f 100644 --- a/External/FEXCore/Source/Interface/HLE/FileManagement.cpp +++ b/External/FEXCore/Source/Interface/HLE/FileManagement.cpp @@ -19,6 +19,15 @@ namespace FEXCore { FileManager::FileManager(FEXCore::Context::Context *ctx) : CTX {ctx} , EmuFD {ctx} { + + // calculate the non-self link to exe + // Some executables do getpid, stat("/proc/$pid/exe") + int pid = getpid(); + + char buf[50]; + snprintf(buf, 50, "/proc/%i/exe", pid); + + PidSelfPath = std::string(buf); } FileManager::~FileManager() { @@ -85,7 +94,7 @@ uint64_t FileManager::FAccessat(int dirfd, const char *pathname, int mode, int f } uint64_t FileManager::Readlink(const char *pathname, char *buf, size_t bufsiz) { - if (strcmp(pathname, "/proc/self/exe") == 0) { + if (strcmp(pathname, "/proc/self/exe") == 0 || strcmp(pathname, PidSelfPath.c_str()) == 0) { strncpy(buf, Filename.c_str(), bufsiz); return std::min(bufsiz, Filename.size()); } diff --git a/External/FEXCore/Source/Interface/HLE/FileManagement.h b/External/FEXCore/Source/Interface/HLE/FileManagement.h index f68040d80..0c50778fe 100644 --- a/External/FEXCore/Source/Interface/HLE/FileManagement.h +++ b/External/FEXCore/Source/Interface/HLE/FileManagement.h @@ -49,6 +49,7 @@ private: std::unordered_map FDToNameMap; std::string Filename; + std::string PidSelfPath; std::string GetEmulatedPath(const char *pathname); }; }