Kernel/Utilities: Add new round_{up,down}_to_nearest_page functions

This commit is contained in:
apio 2022-10-12 14:51:04 +02:00
parent baa71b09cc
commit 0f5910add7
2 changed files with 13 additions and 0 deletions

View File

@ -8,4 +8,6 @@ namespace Utilities
uint64_t get_rflags();
uint64_t get_top_of_stack(uint64_t bottom, uint64_t stack_pages);
uint64_t round_down_to_nearest_page(uint64_t addr);
uint64_t round_up_to_nearest_page(uint64_t addr);
}

View File

@ -19,3 +19,14 @@ uint64_t Utilities::get_top_of_stack(uint64_t bottom, uint64_t stack_pages)
{
return bottom + (stack_pages * PAGE_SIZE) - sizeof(uintptr_t);
}
uint64_t Utilities::round_down_to_nearest_page(uint64_t addr)
{
return addr - (addr % PAGE_SIZE);
}
uint64_t Utilities::round_up_to_nearest_page(uint64_t addr)
{
if (addr % PAGE_SIZE) return addr + (PAGE_SIZE - (addr % PAGE_SIZE));
return addr;
}