From f7aee889de76812f530051108263aaeb856a2fa9 Mon Sep 17 00:00:00 2001 From: Stephen Miller Date: Fri, 9 May 2025 19:19:48 -0500 Subject: [PATCH] Update MemoryPoolReserve Only difference between real hw and our code is behavior with addr = 0. --- src/core/libraries/kernel/memory.cpp | 4 ---- src/core/memory.cpp | 5 +++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/core/libraries/kernel/memory.cpp b/src/core/libraries/kernel/memory.cpp index a3258f7f1..603043ffb 100644 --- a/src/core/libraries/kernel/memory.cpp +++ b/src/core/libraries/kernel/memory.cpp @@ -425,10 +425,6 @@ s32 PS4_SYSV_ABI sceKernelMemoryPoolReserve(void* addrIn, size_t len, size_t ali LOG_INFO(Kernel_Vmm, "addrIn = {}, len = {:#x}, alignment = {:#x}, flags = {:#x}", fmt::ptr(addrIn), len, alignment, flags); - if (addrIn == nullptr) { - LOG_ERROR(Kernel_Vmm, "Address is invalid!"); - return ORBIS_KERNEL_ERROR_EINVAL; - } if (len == 0 || !Common::Is2MBAligned(len)) { LOG_ERROR(Kernel_Vmm, "Map size is either zero or not 2MB aligned!"); return ORBIS_KERNEL_ERROR_EINVAL; diff --git a/src/core/memory.cpp b/src/core/memory.cpp index ec7a44c16..1a1a8026d 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -213,8 +213,6 @@ void MemoryManager::Free(PAddr phys_addr, size_t size) { int MemoryManager::PoolReserve(void** out_addr, VAddr virtual_addr, size_t size, MemoryMapFlags flags, u64 alignment) { std::scoped_lock lk{mutex}; - - virtual_addr = (virtual_addr == 0) ? impl.SystemManagedVirtualBase() : virtual_addr; alignment = alignment > 0 ? alignment : 2_MB; VAddr mapped_addr = alignment > 0 ? Common::AlignUp(virtual_addr, alignment) : virtual_addr; @@ -234,6 +232,9 @@ int MemoryManager::PoolReserve(void** out_addr, VAddr virtual_addr, size_t size, // Find the first free area starting with provided virtual address. if (False(flags & MemoryMapFlags::Fixed)) { + // When MemoryMapFlags::Fixed is not specified, mappings default to searching for + // a free area starting from address 0x200000000 instead. + mapped_addr = mapped_addr < 0x200000000 ? 0x200000000 : mapped_addr; mapped_addr = SearchFree(mapped_addr, size, alignment); if (mapped_addr == -1) { // No suitable memory areas to map to