From 7c00ac637afc7a33e095a9eccb161c0d671d84ef Mon Sep 17 00:00:00 2001 From: "Daniel R." <47796739+polybiusproxy@users.noreply.github.com> Date: Sat, 12 Oct 2024 16:35:12 +0200 Subject: [PATCH] core: Fix mmap being unable to map GPU memory --- src/core/address_space.cpp | 26 +++++++++++------------ src/core/libraries/kernel/file_system.cpp | 18 ++++++++-------- src/core/libraries/kernel/libkernel.cpp | 1 + src/core/memory.h | 2 +- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/core/address_space.cpp b/src/core/address_space.cpp index b2cb95a5..8ba99e32 100644 --- a/src/core/address_space.cpp +++ b/src/core/address_space.cpp @@ -30,14 +30,13 @@ static constexpr size_t BackingSize = SCE_KERNEL_MAIN_DMEM_SIZE_PRO; #ifdef _WIN32 [[nodiscard]] constexpr u64 ToWindowsProt(Core::MemoryProt prot) { - switch (prot) { - case Core::MemoryProt::NoAccess: - default: - return PAGE_NOACCESS; - case Core::MemoryProt::CpuRead: - return PAGE_READONLY; - case Core::MemoryProt::CpuReadWrite: + if (True(prot & Core::MemoryProt::CpuReadWrite) || + True(prot & Core::MemoryProt::GpuReadWrite)) { return PAGE_READWRITE; + } else if (True(prot & Core::MemoryProt::CpuRead) || True(prot & Core::MemoryProt::GpuRead)) { + return PAGE_READONLY; + } else { + return PAGE_NOACCESS; } } @@ -290,14 +289,13 @@ enum PosixPageProtection { }; [[nodiscard]] constexpr PosixPageProtection ToPosixProt(Core::MemoryProt prot) { - switch (prot) { - case Core::MemoryProt::NoAccess: - default: - return PAGE_NOACCESS; - case Core::MemoryProt::CpuRead: - return PAGE_READONLY; - case Core::MemoryProt::CpuReadWrite: + if (True(prot & Core::MemoryProt::CpuReadWrite) || + True(prot & Core::MemoryProt::GpuReadWrite)) { return PAGE_READWRITE; + } else if (True(prot & Core::MemoryProt::CpuRead) || True(prot & Core::MemoryProt::GpuRead)) { + return PAGE_READONLY; + } else { + return PAGE_NOACCESS; } } diff --git a/src/core/libraries/kernel/file_system.cpp b/src/core/libraries/kernel/file_system.cpp index e2093ce2..7f86ee54 100644 --- a/src/core/libraries/kernel/file_system.cpp +++ b/src/core/libraries/kernel/file_system.cpp @@ -321,26 +321,26 @@ int PS4_SYSV_ABI sceKernelRmdir(const char* path) { const std::filesystem::path dir_name = mnt->GetHostPath(path, &ro); if (dir_name.empty()) { - LOG_INFO(Kernel_Fs, "Failed to remove directory: {}, permission denied", - fmt::UTF(dir_name.u8string())); + LOG_ERROR(Kernel_Fs, "Failed to remove directory: {}, permission denied", + fmt::UTF(dir_name.u8string())); return SCE_KERNEL_ERROR_EACCES; } if (ro) { - LOG_INFO(Kernel_Fs, "Failed to remove directory: {}, directory is read only", - fmt::UTF(dir_name.u8string())); + LOG_ERROR(Kernel_Fs, "Failed to remove directory: {}, directory is read only", + fmt::UTF(dir_name.u8string())); return SCE_KERNEL_ERROR_EROFS; } if (!std::filesystem::is_directory(dir_name)) { - LOG_INFO(Kernel_Fs, "Failed to remove directory: {}, path is not a directory", - fmt::UTF(dir_name.u8string())); + LOG_ERROR(Kernel_Fs, "Failed to remove directory: {}, path is not a directory", + fmt::UTF(dir_name.u8string())); return ORBIS_KERNEL_ERROR_ENOTDIR; } if (!std::filesystem::exists(dir_name)) { - LOG_INFO(Kernel_Fs, "Failed to remove directory: {}, no such file or directory", - fmt::UTF(dir_name.u8string())); + LOG_ERROR(Kernel_Fs, "Failed to remove directory: {}, no such file or directory", + fmt::UTF(dir_name.u8string())); return ORBIS_KERNEL_ERROR_ENOENT; } @@ -348,7 +348,7 @@ int PS4_SYSV_ABI sceKernelRmdir(const char* path) { int result = std::filesystem::remove_all(dir_name, ec); if (!ec) { - LOG_DEBUG(Kernel_Fs, "Removed directory: {}", fmt::UTF(dir_name.u8string())); + LOG_INFO(Kernel_Fs, "Removed directory: {}", fmt::UTF(dir_name.u8string())); return ORBIS_OK; } LOG_ERROR(Kernel_Fs, "Failed to remove directory: {}, error_code={}", diff --git a/src/core/libraries/kernel/libkernel.cpp b/src/core/libraries/kernel/libkernel.cpp index 72f8f1d1..b013f29b 100644 --- a/src/core/libraries/kernel/libkernel.cpp +++ b/src/core/libraries/kernel/libkernel.cpp @@ -157,6 +157,7 @@ void SetPosixErrno(int e) { g_posix_errno = e; } } + int PS4_SYSV_ABI sceKernelMmap(void* addr, u64 len, int prot, int flags, int fd, size_t offset, void** res) { LOG_INFO(Kernel_Vmm, "called addr = {}, len = {}, prot = {}, flags = {}, fd = {}, offset = {}", diff --git a/src/core/memory.h b/src/core/memory.h index 752209cf..320aa367 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -28,7 +28,7 @@ enum class MemoryProt : u32 { CpuReadWrite = 2, GpuRead = 16, GpuWrite = 32, - GpuReadWrite = 38, + GpuReadWrite = 48, }; DECLARE_ENUM_FLAG_OPERATORS(MemoryProt)