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

Kernel: Move the expand_range_to_page_boundaries helper to MemoryManager

This helper can (and will) be used in more parts of the kernel besides
the mmap-family of syscalls.
This commit is contained in:
Idan Horowitz 2021-11-29 21:19:58 +02:00
parent ff6b43734c
commit 4ca39c7110
2 changed files with 21 additions and 21 deletions

View file

@ -329,4 +329,21 @@ inline bool PhysicalPage::is_lazy_committed_page() const
return this == &MM.lazy_committed_page();
}
inline ErrorOr<Memory::VirtualRange> expand_range_to_page_boundaries(FlatPtr address, size_t size)
{
if (Memory::page_round_up_would_wrap(size))
return EINVAL;
if ((address + size) < address)
return EINVAL;
if (Memory::page_round_up_would_wrap(address + size))
return EINVAL;
auto base = VirtualAddress { address }.page_base();
auto end = Memory::page_round_up(address + size);
return Memory::VirtualRange { base, end - base.get() };
}
}