From 3ff7cf19c0fa4b1ff43efa48cc842cce57701778 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Tue, 7 Mar 2023 18:14:56 -0800 Subject: [PATCH] FM: Remove unused FD to Name mapping This was completely unused so this just reduces some syscall signal mutex locking around FD operations. --- Source/Tests/LinuxSyscalls/FileManagement.cpp | 37 ------------------- Source/Tests/LinuxSyscalls/FileManagement.h | 6 --- Source/Tests/LinuxSyscalls/Syscalls.cpp | 4 -- 3 files changed, 47 deletions(-) diff --git a/Source/Tests/LinuxSyscalls/FileManagement.cpp b/Source/Tests/LinuxSyscalls/FileManagement.cpp index 0c59d562f..f4b7a2718 100644 --- a/Source/Tests/LinuxSyscalls/FileManagement.cpp +++ b/Source/Tests/LinuxSyscalls/FileManagement.cpp @@ -513,19 +513,10 @@ uint64_t FileManager::Open(const char *pathname, int flags, uint32_t mode) { fd = ::open(SelfPath, flags, mode); } - if (fd != -1) { - FHU::ScopedSignalMaskWithMutex lk(FDLock); - FDToNameMap.insert_or_assign(fd, SelfPath); - } - return fd; } uint64_t FileManager::Close(int fd) { - { - FHU::ScopedSignalMaskWithMutex lk(FDLock); - FDToNameMap.erase(fd); - } return ::close(fd); } @@ -533,15 +524,6 @@ uint64_t FileManager::CloseRange(unsigned int first, unsigned int last, unsigned #ifndef CLOSE_RANGE_CLOEXEC #define CLOSE_RANGE_CLOEXEC (1U << 2) #endif - if (!(flags & CLOSE_RANGE_CLOEXEC)) { - // If the flag was set then it doesn't actually close the FDs - // Just sets the flag on a range - FHU::ScopedSignalMaskWithMutex lk(FDLock); - auto Lower = FDToNameMap.lower_bound(first); - auto Upper = FDToNameMap.upper_bound(last); - // We remove from first to last inclusive - FDToNameMap.erase(Lower, Upper); - } return ::syscall(SYSCALL_DEF(close_range), first, last, flags); } @@ -748,11 +730,6 @@ uint64_t FileManager::Openat([[maybe_unused]] int dirfs, const char *pathname, i fd = ::syscall(SYSCALL_DEF(openat), dirfs, SelfPath, flags, mode); } - if (fd != -1) { - FHU::ScopedSignalMaskWithMutex lk(FDLock); - FDToNameMap.insert_or_assign(fd, SelfPath); - } - return fd; } @@ -777,11 +754,6 @@ uint64_t FileManager::Openat2(int dirfs, const char *pathname, FEX::HLE::open_ho fd = ::syscall(SYSCALL_DEF(openat2), dirfs, SelfPath, how, usize); } - if (fd != -1) { - FHU::ScopedSignalMaskWithMutex lk(FDLock); - FDToNameMap.insert_or_assign(fd, SelfPath); - } - return fd; } @@ -854,13 +826,4 @@ uint64_t FileManager::NewFSStatAt64(int dirfd, const char *pathname, struct stat return ::fstatat64(dirfd, SelfPath, buf, flag); } -std::string *FileManager::FindFDName(int fd) { - FHU::ScopedSignalMaskWithMutex lk(FDLock); - auto it = FDToNameMap.find(fd); - if (it == FDToNameMap.end()) { - return nullptr; - } - return &it->second; -} - } diff --git a/Source/Tests/LinuxSyscalls/FileManagement.h b/Source/Tests/LinuxSyscalls/FileManagement.h index c2d782c51..fe4d25831 100644 --- a/Source/Tests/LinuxSyscalls/FileManagement.h +++ b/Source/Tests/LinuxSyscalls/FileManagement.h @@ -73,8 +73,6 @@ public: // vfs uint64_t Statfs(const char *path, void *buf); - std::string *FindFDName(int fd); - std::optional GetSelf(const char *Pathname); void UpdatePID(uint32_t PID) { CurrentPID = PID; } @@ -83,13 +81,9 @@ public: using FDPathTmpData = std::array; std::pair GetEmulatedFDPath(int dirfd, const char *pathname, bool FollowSymlink, FDPathTmpData &TmpFilename); - std::mutex *GetFDLock() { return &FDLock; } - private: FEX::EmulatedFile::EmulatedFDManager EmuFD; - std::mutex FDLock; - std::map FDToNameMap; std::map> ThunkOverlays; FEX_CONFIG_OPT(Filename, APP_FILENAME); diff --git a/Source/Tests/LinuxSyscalls/Syscalls.cpp b/Source/Tests/LinuxSyscalls/Syscalls.cpp index 52eccef33..f38b7847c 100644 --- a/Source/Tests/LinuxSyscalls/Syscalls.cpp +++ b/Source/Tests/LinuxSyscalls/Syscalls.cpp @@ -847,8 +847,6 @@ uint64_t UnimplementedSyscallSafe(FEXCore::Core::CpuStateFrame *Frame, uint64_t } void SyscallHandler::LockBeforeFork() { - FM.GetFDLock()->lock(); - // XXX shared_mutex has issues with locking and forks // VMATracking.Mutex.lock(); @@ -860,8 +858,6 @@ void SyscallHandler::UnlockAfterFork() { // XXX shared_mutex has issues with locking and forks // VMATracking.Mutex.unlock(); - - FM.GetFDLock()->unlock(); } static bool isHEX(char c) {