From 143dbba562d3230d3dfc4d16a6a55a480e6c09b4 Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Wed, 22 Dec 2021 11:27:57 +0100 Subject: [PATCH] UserspaceEmulator: Replace intersecting ranges if MAP_FIXED is specified This commit changes UserspaceEmulator to match the behavior that the kernel has since ce1bf37. --- Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp b/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp index 974fda2eb3..7a46c74e78 100644 --- a/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp +++ b/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp @@ -874,9 +874,11 @@ u32 Emulator::virt$mmap(u32 params_addr) if (params.flags & MAP_RANDOMIZED) { result = m_range_allocator.allocate_randomized(requested_size, params.alignment); } else if (params.flags & MAP_FIXED) { - if (params.addr) + if (params.addr) { + // If MAP_FIXED is specified, existing mappings that intersect the requested range are removed. + virt$munmap(params.addr, requested_size); result = m_range_allocator.allocate_specific(VirtualAddress { params.addr }, requested_size); - else { + } else { // mmap(nullptr, …, MAP_FIXED) is technically okay, but tends to be a bug. // Therefore, refuse to be helpful. reportln("\n=={}== \033[31;1mTried to mmap at nullptr with MAP_FIXED.\033[0m, {:#x} bytes.", getpid(), params.size);