Properly handle ENOMEM error return in MapMemory

Needed for Assassin's Creed Unity to behave properly.
This commit is contained in:
Stephen Miller 2025-05-12 13:39:36 -05:00
parent c0562a6b1b
commit e25011937f

View File

@ -383,12 +383,13 @@ int MemoryManager::MapMemory(void** out_addr, VAddr virtual_addr, size_t size, M
vma = FindVMA(unmap_addr)->second; vma = FindVMA(unmap_addr)->second;
} }
// This should return SCE_KERNEL_ERROR_ENOMEM but rarely happens.
vma = FindVMA(mapped_addr)->second; vma = FindVMA(mapped_addr)->second;
remaining_size = vma.base + vma.size - mapped_addr; remaining_size = vma.base + vma.size - mapped_addr;
ASSERT_MSG(!vma.IsMapped() && remaining_size >= size, if (vma.IsMapped() || remaining_size < size) {
"Memory region {:#x} to {:#x} isn't free enough to map region {:#x} to {:#x}", LOG_ERROR(Kernel_Vmm, "Not enough memory to map {:#x} bytes at address {:#x}", size,
vma.base, vma.base + vma.size, virtual_addr, virtual_addr + size); mapped_addr);
return ORBIS_KERNEL_ERROR_ENOMEM;
}
} }
// Find the first free area starting with provided virtual address. // Find the first free area starting with provided virtual address.