Kernel: Add MM helper for shrinking a virtual range to page boundaries

This commit is contained in:
Idan Horowitz 2023-12-24 15:52:15 +02:00 committed by Andreas Kling
parent 6f4d745452
commit 4c6fd454d0
Notes: sideshowbarker 2024-07-17 06:51:10 +09:00

View file

@ -321,4 +321,18 @@ inline ErrorOr<Memory::VirtualRange> expand_range_to_page_boundaries(FlatPtr add
return Memory::VirtualRange { base, end - base.get() };
}
inline ErrorOr<Memory::VirtualRange> shrink_range_to_page_boundaries(FlatPtr address, size_t size)
{
if ((address + size) < address)
return EINVAL;
auto base = TRY(Memory::page_round_up(address));
auto end = Memory::page_round_down(address + size);
if (end < base)
return EINVAL;
return Memory::VirtualRange { VirtualAddress(base), end - base };
}
}