1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-19 12:57:39 +00:00

Kernel: Fix mmap with specific address for file backed mappings

This commit is contained in:
Itamar 2020-12-16 20:52:47 +02:00 committed by Andreas Kling
parent 79818bbf8e
commit d64d0451e5

View file

@ -133,18 +133,22 @@ void* Process::sys$mmap(Userspace<const Syscall::SC_mmap_params*> user_params)
return (void*)-EINVAL; return (void*)-EINVAL;
Region* region = nullptr; Region* region = nullptr;
Optional<Range> range;
auto range = allocate_range(VirtualAddress(addr), size, alignment); if (map_purgeable || map_anonymous) {
if (!range.is_valid()) range = allocate_range(VirtualAddress(addr), size, alignment);
return (void*)-ENOMEM; if (!range.value().is_valid())
return (void*)-ENOMEM;
}
if (map_purgeable) { if (map_purgeable) {
auto vmobject = PurgeableVMObject::create_with_size(size); auto vmobject = PurgeableVMObject::create_with_size(size);
region = allocate_region_with_vmobject(range, vmobject, 0, !name.is_null() ? name : "mmap (purgeable)", prot); region = allocate_region_with_vmobject(range.value(), vmobject, 0, !name.is_null() ? name : "mmap (purgeable)", prot);
if (!region && (!map_fixed && addr != 0)) if (!region && (!map_fixed && addr != 0))
region = allocate_region_with_vmobject({}, size, vmobject, 0, !name.is_null() ? name : "mmap (purgeable)", prot); region = allocate_region_with_vmobject({}, size, vmobject, 0, !name.is_null() ? name : "mmap (purgeable)", prot);
} else if (map_anonymous) { } else if (map_anonymous) {
region = allocate_region(range, !name.is_null() ? name : "mmap", prot, false);
region = allocate_region(range.value(), !name.is_null() ? name : "mmap", prot, false);
if (!region && (!map_fixed && addr != 0)) if (!region && (!map_fixed && addr != 0))
region = allocate_region(allocate_range({}, size), !name.is_null() ? name : "mmap", prot, false); region = allocate_region(allocate_range({}, size), !name.is_null() ? name : "mmap", prot, false);
} else { } else {