From 55099c0aac8ce1ab4c238a1fe7b34c1d4f7f9084 Mon Sep 17 00:00:00 2001 From: Stephen Miller Date: Mon, 26 May 2025 21:18:47 -0500 Subject: [PATCH] Properly handle GPU access rights Since my first commit restricts GPU mappings to memory areas with GPU access permissions, we also need to be updating the GPU mappings appropriately during Protect calls too. --- src/core/memory.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 50bfbfe71..d1d8689d6 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -578,6 +578,18 @@ s64 MemoryManager::ProtectBytes(VAddr addr, VirtualMemoryArea vma_base, size_t s return ORBIS_KERNEL_ERROR_EINVAL; } + if (vma_base.prot < MemoryProt::GpuRead && prot >= MemoryProt::GpuRead) { + // New protection will give the GPU access to this VMA, perform a rasterizer map + ASSERT_MSG(IsValidGpuMapping(addr, size), "Invalid address for GPU mapping"); + rasterizer->MapMemory(addr, size); + } + + if (vma_base.prot >= MemoryProt::GpuRead && prot < MemoryProt::GpuRead) { + // New protection will remove the GPU's access to this VMA, perform a rasterizer unmap + ASSERT_MSG(IsValidGpuMapping(addr, size), "Invalid address for GPU unmap"); + rasterizer->UnmapMemory(addr, size); + } + // Change protection vma_base.prot = prot;