From 6588f6764ff347a6a8176a0ddb7e165ade8352d5 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Fri, 7 Jul 2023 16:50:55 +0300 Subject: [PATCH 1/2] Fix TLS again --- src/core/memory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/memory.cpp b/src/core/memory.cpp index abea7606..00f28eba 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -37,8 +37,8 @@ void Memory::reset() { u32 basePaddrForTLS = tlsBaseOpt.value(); for (int i = 0; i < appResourceLimits.maxThreads; i++) { u32 vaddr = VirtualAddrs::TLSBase + i * VirtualAddrs::TLSSize; - basePaddrForTLS += VirtualAddrs::TLSSize; allocateMemory(vaddr, basePaddrForTLS, VirtualAddrs::TLSSize, true); + basePaddrForTLS += VirtualAddrs::TLSSize; } // Initialize shared memory blocks and reserve memory for them From b7ce9874873a56cc9b4d810e768948e6c4ecb7ba Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Fri, 7 Jul 2023 16:51:14 +0300 Subject: [PATCH 2/2] IOFile: Allow multiple opens on the same object --- include/io_file.hpp | 2 +- src/io_file.cpp | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/io_file.hpp b/include/io_file.hpp index 0e5d7c53..8a54dfaa 100644 --- a/include/io_file.hpp +++ b/include/io_file.hpp @@ -8,7 +8,7 @@ class IOFile { static inline std::filesystem::path appData = ""; // Directory for holding app data. AppData on Windows public: - IOFile() {} + IOFile() : handle(nullptr) {} IOFile(FILE* handle) : handle(handle) {} IOFile(const std::filesystem::path& path, const char* permissions = "rb"); diff --git a/src/io_file.cpp b/src/io_file.cpp index e3f04dc0..3d797782 100644 --- a/src/io_file.cpp +++ b/src/io_file.cpp @@ -21,7 +21,7 @@ #include // For ftruncate #endif -IOFile::IOFile(const std::filesystem::path& path, const char* permissions) { open(path, permissions); } +IOFile::IOFile(const std::filesystem::path& path, const char* permissions) : handle(nullptr) { open(path, permissions); } bool IOFile::open(const std::filesystem::path& path, const char* permissions) { const auto str = path.string(); // For some reason converting paths directly with c_str() doesn't work @@ -29,6 +29,12 @@ bool IOFile::open(const std::filesystem::path& path, const char* permissions) { } bool IOFile::open(const char* filename, const char* permissions) { + // If this IOFile is already bound to an open file descriptor, release the file descriptor + // To avoid leaking it and/or erroneously locking the file + if (isOpen()) { + close(); + } + handle = std::fopen(filename, permissions); return isOpen(); }