Merge pull request #80 from wheremyfoodat/stacc-the-raccs

Fix mem allocation bug, improve IOFile
This commit is contained in:
wheremyfoodat 2023-07-07 17:07:23 +03:00 committed by GitHub
commit 682d59f2f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View file

@ -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");

View file

@ -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

View file

@ -21,7 +21,7 @@
#include <unistd.h> // 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();
}