From a6ec84b493a2c7fe8446f607f9d470714c1a984e Mon Sep 17 00:00:00 2001 From: Stephen Miller Date: Tue, 27 May 2025 11:40:25 -0500 Subject: [PATCH] Fix Mprotect on free memory On real hardware, this just does nothing. If something did get protected, there's no way to query that information. Therefore, it seems pretty safe to just behave like munmap and return size here. --- src/core/memory.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/memory.cpp b/src/core/memory.cpp index d3bbdfb97..6ad4f8a13 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -563,8 +563,9 @@ s64 MemoryManager::ProtectBytes(VAddr addr, VirtualMemoryArea vma_base, size_t s vma_base.size - start_in_vma < size ? vma_base.size - start_in_vma : size; if (vma_base.type == VMAType::Free) { - LOG_ERROR(Kernel_Vmm, "Cannot change protection on free memory region"); - return ORBIS_KERNEL_ERROR_EINVAL; + // On PS4, protecting freed memory does nothing. + LOG_WARNING(Kernel_Vmm, "Attempting to protect free memory"); + return adjusted_size; } // Validate protection flags