mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:18:12 +00:00
Kernel: Hoist VM range allocation up to sys$mmap() itself
Instead of letting each File subclass do range allocation in their mmap() override, do it up front in sys$mmap(). This makes us honor alignment requests for file-backed memory mappings and simplifies the code somwhat.
This commit is contained in:
parent
adcc1c1eff
commit
ab14b0ac64
13 changed files with 26 additions and 36 deletions
|
@ -133,16 +133,13 @@ void* Process::sys$mmap(Userspace<const Syscall::SC_mmap_params*> user_params)
|
|||
return (void*)-EINVAL;
|
||||
|
||||
Region* region = nullptr;
|
||||
Optional<Range> range;
|
||||
if (map_noreserve || map_anonymous) {
|
||||
range = allocate_range(VirtualAddress(addr), size, alignment);
|
||||
if (!range.value().is_valid())
|
||||
return (void*)-ENOMEM;
|
||||
}
|
||||
auto range = allocate_range(VirtualAddress(addr), size, alignment);
|
||||
if (!range.is_valid())
|
||||
return (void*)-ENOMEM;
|
||||
|
||||
if (map_anonymous) {
|
||||
auto strategy = map_noreserve ? AllocationStrategy::None : AllocationStrategy::Reserve;
|
||||
auto region_or_error = allocate_region(range.value(), !name.is_null() ? name : "mmap", prot, strategy);
|
||||
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())
|
||||
|
@ -169,13 +166,8 @@ void* Process::sys$mmap(Userspace<const Syscall::SC_mmap_params*> user_params)
|
|||
if (!validate_inode_mmap_prot(*this, prot, *description->inode(), map_shared))
|
||||
return (void*)-EACCES;
|
||||
}
|
||||
auto region_or_error = description->mmap(*this, VirtualAddress(addr), static_cast<size_t>(offset), size, prot, map_shared);
|
||||
if (region_or_error.is_error()) {
|
||||
// Fail if MAP_FIXED or address is 0, retry otherwise
|
||||
if (map_fixed || addr == 0)
|
||||
return (void*)region_or_error.error().error();
|
||||
region_or_error = description->mmap(*this, {}, static_cast<size_t>(offset), size, prot, map_shared);
|
||||
}
|
||||
|
||||
auto region_or_error = description->mmap(*this, range, static_cast<size_t>(offset), prot, map_shared);
|
||||
if (region_or_error.is_error())
|
||||
return (void*)region_or_error.error().error();
|
||||
region = region_or_error.value();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue