1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:17:36 +00:00

Kernel: Remove allocate_region() functions that don't take a Range

Let's force callers to provide a VM range when allocating a region.
This makes ENOMEM error handling more visible and removes implicit
VM allocation which felt a bit magical.
This commit is contained in:
Andreas Kling 2021-01-26 14:13:57 +01:00
parent d697d33fa6
commit 1e25d2b734
5 changed files with 41 additions and 25 deletions

View file

@ -404,10 +404,14 @@ void* Process::sys$mremap(Userspace<const Syscall::SC_mremap_params*> user_param
auto old_name = old_region->name();
auto old_prot = region_access_flags_to_prot(old_region->access());
NonnullRefPtr inode = static_cast<SharedInodeVMObject&>(old_region->vmobject()).inode();
// Unmap without deallocating the VM range since we're going to reuse it.
old_region->unmap(Region::ShouldDeallocateVirtualMemoryRange::No);
deallocate_region(*old_region);
auto new_vmobject = PrivateInodeVMObject::create_with_inode(inode);
auto new_region_or_error = allocate_region_with_vmobject(range.base(), range.size(), new_vmobject, 0, old_name, old_prot, false);
auto new_region_or_error = allocate_region_with_vmobject(range, new_vmobject, 0, old_name, old_prot, false);
if (new_region_or_error.is_error())
return (void*)new_region_or_error.error().error();
auto& new_region = *new_region_or_error.value();
@ -439,7 +443,11 @@ void* Process::sys$allocate_tls(size_t size)
});
ASSERT(main_thread);
auto region_or_error = allocate_region({}, size, String(), PROT_READ | PROT_WRITE);
auto range = allocate_range({}, size);
if (!range.is_valid())
return (void*)-ENOMEM;
auto region_or_error = allocate_region(range, String(), PROT_READ | PROT_WRITE);
if (region_or_error.is_error())
return (void*)region_or_error.error().error();