From 075cd423edee4bb0ddc1066f15fab4d2bf2393fa Mon Sep 17 00:00:00 2001 From: Stefanos Kornilios Mitsis Poiitidis Date: Tue, 23 Feb 2021 12:06:25 +0200 Subject: [PATCH] AOTIR: Review feedback --- .../FEXCore/Source/Interface/Core/Core.cpp | 4 +++- Source/Tests/ELFLoader.cpp | 9 +++----- Source/Tests/LinuxSyscalls/x32/Memory.cpp | 21 +++-------------- Source/Tests/LinuxSyscalls/x64/Memory.cpp | 23 ++++--------------- 4 files changed, 13 insertions(+), 44 deletions(-) diff --git a/External/FEXCore/Source/Interface/Core/Core.cpp b/External/FEXCore/Source/Interface/Core/Core.cpp index 1a9df7142..5d664fcf2 100644 --- a/External/FEXCore/Source/Interface/Core/Core.cpp +++ b/External/FEXCore/Source/Interface/Core/Core.cpp @@ -24,6 +24,7 @@ #include #include +#include #include "Interface/Core/GdbServer.h" @@ -1239,7 +1240,8 @@ namespace FEXCore::Context { void Context::AddNamedRegion(uintptr_t Base, uintptr_t Size, uintptr_t Offset, const std::string &filename) { // TODO: Support overlapping maps and region splitting - auto base_filename = filename.substr(filename.find_last_of("/\\") + 1); + auto base_filename = std::filesystem::path(filename).filename().string(); + if (base_filename.size()) { auto filename_hash = fasthash64(filename.c_str(), filename.size(), 0xBAADF00D); diff --git a/Source/Tests/ELFLoader.cpp b/Source/Tests/ELFLoader.cpp index 9ff302602..35301692b 100644 --- a/Source/Tests/ELFLoader.cpp +++ b/Source/Tests/ELFLoader.cpp @@ -293,14 +293,12 @@ int main(int argc, char **argv, char **const envp) { }); } - std::string base_filename = Program.substr(Program.find_last_of("/\\") + 1) + ".fex-emu.iraot"; - if (AOTIRLoad() || AOTIRCapture()) { LogMan::Msg::I("Warning: AOTIR is experimental, and might lead to crashes. Capture doesn't work with programs that fork."); } FEXCore::Context::SetAOTIRLoader(CTX, [](const std::string &fileid) -> std::unique_ptr { - auto filepath = std::string(getenv("HOME")) + "/.fex-emu/aotir/" + fileid; + auto filepath = std::filesystem::path(getenv("HOME")) / ".fex-emu" / "aotir" / fileid; return std::make_unique(filepath, std::ios::in | std::ios::binary); }); @@ -308,11 +306,10 @@ int main(int argc, char **argv, char **const envp) { FEXCore::Context::RunUntilExit(CTX); if (AOTIRCapture()) { - mkdir((std::string(getenv("HOME")) + "/.fex-emu/").c_str(), 0700); - mkdir((std::string(getenv("HOME")) + "/.fex-emu/aotir").c_str(), 0700); + std::filesystem::create_directories(std::filesystem::path(getenv("HOME")) / ".fex-emu" / "aotir"); auto WroteCache = FEXCore::Context::WriteAOTIR(CTX, [](const std::string& fileid) -> std::unique_ptr { - auto filepath = std::string(getenv("HOME")) + "/.fex-emu/aotir/" + fileid; + auto filepath = std::filesystem::path(getenv("HOME")) / ".fex-emu" / "aotir" / fileid; auto AOTWrite = std::make_unique(filepath, std::ios::out | std::ios::binary); if (*AOTWrite) { std::filesystem::resize_file(filepath, 0); diff --git a/Source/Tests/LinuxSyscalls/x32/Memory.cpp b/Source/Tests/LinuxSyscalls/x32/Memory.cpp index ff8d95662..1d9f62453 100644 --- a/Source/Tests/LinuxSyscalls/x32/Memory.cpp +++ b/Source/Tests/LinuxSyscalls/x32/Memory.cpp @@ -9,27 +9,12 @@ #include #include #include +#include static std::string get_fdpath(int fd) { - std::vector buf(400); - ssize_t len; - - std::string fdToName = "/proc/self/fd/" + std::to_string(fd); - - do - { - buf.resize(buf.size() + 100); - len = ::readlink(fdToName.c_str(), &(buf[0]), buf.size()); - } while (buf.size() == len); - - if (len > 0) - { - buf[len] = '\0'; - return (std::string(&(buf[0]))); - } - /* handle error */ - return ""; + std::error_code ec; + return std::filesystem::canonical(std::filesystem::path("/proc/self/fd") / std::to_string(fd), ec).string(); } namespace FEX::HLE::x32 { diff --git a/Source/Tests/LinuxSyscalls/x64/Memory.cpp b/Source/Tests/LinuxSyscalls/x64/Memory.cpp index 2efb5e215..d5e19f061 100644 --- a/Source/Tests/LinuxSyscalls/x64/Memory.cpp +++ b/Source/Tests/LinuxSyscalls/x64/Memory.cpp @@ -11,27 +11,12 @@ #include #include #include +#include -std::string get_fdpath(int fd) +static std::string get_fdpath(int fd) { - std::vector buf(400); - ssize_t len; - - std::string fdToName = "/proc/self/fd/" + std::to_string(fd); - - do - { - buf.resize(buf.size() + 100); - len = ::readlink(fdToName.c_str(), &(buf[0]), buf.size()); - } while (buf.size() == len); - - if (len > 0) - { - buf[len] = '\0'; - return (std::string(&(buf[0]))); - } - /* handle error */ - return ""; + std::error_code ec; + return std::filesystem::canonical(std::filesystem::path("/proc/self/fd") / std::to_string(fd), ec).string(); } namespace FEX::HLE::x64 {