mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:27:44 +00:00
Kernel: Add MM helper for shrinking a virtual range to page boundaries
This commit is contained in:
parent
6f4d745452
commit
4c6fd454d0
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() };
|
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…
Add table
Add a link
Reference in a new issue