Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions common/Darwin/DarwinMisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,29 @@ void* HostSys::CreateSharedMemory(const char* name, size_t size)
return reinterpret_cast<void*>(static_cast<uintptr_t>(port));
}

void* HostSys::CreateMappingFromFile(FILE* file)
{
return reinterpret_cast<void*>(static_cast<uintptr_t>(fileno(file)));
}

void* HostSys::MapMapping(void* handle, size_t size, const PageProtectionMode& mode)
{
const u32 mmap_prot = (mode.CanWrite() ? (PROT_READ | PROT_WRITE) : (PROT_READ)) | (mode.CanExecute() ? PROT_EXEC : 0);

return mmap(nullptr, size, mmap_prot, MAP_PRIVATE, static_cast<int>(reinterpret_cast<intptr_t>(handle)), 0);
}

void HostSys::DestroyMapping(void* handle)
{
// The handle mmap requires is the same as the file descriptor.
return;
}

void HostSys::FlushMapping(void* handle, [[maybe_unused]] void* baseAddr, size_t size)
{
msync(handle, size, MS_SYNC);
}

void HostSys::DestroySharedMemory(void* ptr)
{
mach_port_deallocate(mach_task_self(), static_cast<mach_port_t>(reinterpret_cast<uintptr_t>(ptr)));
Expand Down
17 changes: 17 additions & 0 deletions common/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,23 @@ s64 FileSystem::FSize64(std::FILE* fp)
return -1;
}

bool FileSystem::FFlush(std::FILE *fp)
{
#ifdef _WIN32
HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(fp));
if(hFile != INVALID_HANDLE_VALUE)
{
if(FlushFileBuffers(hFile))
{
return true;
}
}
return false;
#else
return !std::fflush(fp);
#endif
}

s64 FileSystem::GetPathFileSize(const char* Path)
{
FILESYSTEM_STAT_DATA sd;
Expand Down
2 changes: 2 additions & 0 deletions common/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ namespace FileSystem
s64 FTell64(std::FILE* fp);
s64 FSize64(std::FILE* fp);

bool FFlush(std::FILE* fp);

int OpenFDFile(const char* filename, int flags, int mode, Error* error = nullptr);

/// Sharing modes for OpenSharedCFile().
Expand Down
6 changes: 6 additions & 0 deletions common/HostSys.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ namespace HostSys

extern std::string GetFileMappingName(const char* prefix);
extern void* CreateSharedMemory(const char* name, size_t size);

extern void* CreateMappingFromFile(FILE* file);
extern void* MapMapping(void* handle, size_t size, const PageProtectionMode& mode);
extern void DestroyMapping(void* handle);
extern void FlushMapping(void* handle, void* baseAddr, size_t size);

extern void DestroySharedMemory(void* ptr);
extern void* MapSharedMemory(void* handle, size_t offset, void* baseaddr, size_t size, const PageProtectionMode& mode);
extern void UnmapSharedMemory(void* baseaddr, size_t size);
Expand Down
21 changes: 21 additions & 0 deletions common/Linux/LnxHostSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,27 @@ void* HostSys::CreateSharedMemory(const char* name, size_t size)
return reinterpret_cast<void*>(static_cast<intptr_t>(fd));
}

void* HostSys::CreateMappingFromFile(FILE* file)
{
return reinterpret_cast<void*>(static_cast<intptr_t>(fileno(file)));
}

void* HostSys::MapMapping(void* handle, size_t size, const PageProtectionMode& mode)
{
return HostSys::MapSharedMemory(handle, 0, nullptr, size, mode);
}

void HostSys::DestroyMapping(void* handle)
{
// The handle mmap requires is the same as the file descriptor.
return;
}

void HostSys::FlushMapping(void* handle, [[maybe_unused]] void* baseAddr, size_t size)
{
msync(handle, size, MS_SYNC);
}

void HostSys::DestroySharedMemory(void* ptr)
{
close(static_cast<int>(reinterpret_cast<intptr_t>(ptr)));
Expand Down
22 changes: 22 additions & 0 deletions common/Windows/WinHostSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "fmt/format.h"

#include <io.h>
#include <mutex>

static DWORD ConvertToWinApi(const PageProtectionMode& mode)
Expand Down Expand Up @@ -71,6 +72,27 @@ void* HostSys::CreateSharedMemory(const char* name, size_t size)
static_cast<DWORD>(size >> 32), static_cast<DWORD>(size), StringUtil::UTF8StringToWideString(name).c_str()));
}

void* HostSys::CreateMappingFromFile(FILE* fd)
{
return static_cast<void*>(CreateFileMappingW(reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(fd))), NULL, PAGE_READWRITE,
0, 0, nullptr));
}

void* HostSys::MapMapping(void* handle, size_t size, const PageProtectionMode& mode)
{
return MapViewOfFile(static_cast<HANDLE>(handle), FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
}

void HostSys::DestroyMapping(void* handle)
{
CloseHandle(static_cast<HANDLE>(handle));
}

void HostSys::FlushMapping([[maybe_unused]] void* handle, void* baseAddr, size_t size)
{
FlushViewOfFile(baseAddr, size);
}

void HostSys::DestroySharedMemory(void* ptr)
{
CloseHandle(static_cast<HANDLE>(ptr));
Expand Down
2 changes: 0 additions & 2 deletions pcsx2/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -1141,8 +1141,6 @@ struct Pcsx2Config
bool GenerateFunctionHashes = true;

void LoadSave(SettingsWrapper& wrap);

friend auto operator<=>(const DebugAnalysisOptions& lhs, const DebugAnalysisOptions& rhs) = default;
};

// ------------------------------------------------------------------------
Expand Down
Loading