mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Kernel: Add MM helper for shrinking a virtual range to page boundaries
This commit is contained in:
parent
6f4d745452
commit
4c6fd454d0
Notes:
sideshowbarker
2024-07-17 06:51:10 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/4c6fd454d0 Pull-request: https://github.com/SerenityOS/serenity/pull/22418
1 changed files with 14 additions and 0 deletions
|
@ -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 };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue