Kernel: sys$mmap() without MAP_FIXED should consider address a hint

If we can't use that specific address, it's still okay to put it
anywhere else in VM.
This commit is contained in:
Andreas Kling 2021-01-27 20:48:38 +01:00
parent e2f9e557d3
commit 5ab27e4bdc
Notes: sideshowbarker 2024-07-18 22:49:04 +09:00

View file

@ -134,14 +134,17 @@ void* Process::sys$mmap(Userspace<const Syscall::SC_mmap_params*> user_params)
Region* region = nullptr;
auto range = allocate_range(VirtualAddress(addr), size, alignment);
if (!range.is_valid())
if (!range.is_valid()) {
if (addr && !map_fixed) {
// If there's an address but MAP_FIXED wasn't specified, the address is just a hint.
range = allocate_range({}, size, alignment);
}
return (void*)-ENOMEM;
}
if (map_anonymous) {
auto strategy = map_noreserve ? AllocationStrategy::None : AllocationStrategy::Reserve;
auto region_or_error = allocate_region(range, !name.is_null() ? name : "mmap", prot, strategy);
if (region_or_error.is_error() && (!map_fixed && addr != 0))
region_or_error = allocate_region(allocate_range({}, size), !name.is_null() ? name : "mmap", prot, strategy);
if (region_or_error.is_error())
return (void*)region_or_error.error().error();
region = region_or_error.value();