Attempt to handle MemoryMapFlags::NoOverwrite

Based on my interpretation of red_prig's descriptions. These changes are untested, as I'm not able to test right now.
This commit is contained in:
Stephen Miller 2025-05-15 13:37:34 -05:00 committed by GitHub
parent dc25dd6835
commit fbab952472
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -376,11 +376,17 @@ int MemoryManager::MapMemory(void** out_addr, VAddr virtual_addr, size_t size, M
// To account for this, unmap any reserved areas within this mapping range first. // To account for this, unmap any reserved areas within this mapping range first.
auto unmap_addr = mapped_addr; auto unmap_addr = mapped_addr;
auto unmap_size = size; auto unmap_size = size;
while (!vma.IsMapped() && unmap_addr < mapped_addr + size && remaining_size < size) { // If flag NoOverwrite is provided, allow overwriting mapped VMAs.
// Otherwise, we can only overwrite unmapped or reserved VMAs.
auto should_overwrite = False(flags & MemoryMapFlags::NoOverwrite) || !vma.IsMapped();
while (should_overwrite && unmap_addr < mapped_addr + size && remaining_size < size) {
auto unmapped = UnmapBytesFromEntry(unmap_addr, vma, unmap_size); auto unmapped = UnmapBytesFromEntry(unmap_addr, vma, unmap_size);
unmap_addr += unmapped; unmap_addr += unmapped;
unmap_size -= unmapped; unmap_size -= unmapped;
// Unmap addr should be the address of the next VMA
// if the previous VMA is fully unmapped.
vma = FindVMA(unmap_addr)->second; vma = FindVMA(unmap_addr)->second;
should_overwrite = False(flags & MemoryMapFlags::NoOverwrite) || !vma.IsMapped();
} }
vma = FindVMA(mapped_addr)->second; vma = FindVMA(mapped_addr)->second;