diff --git a/kernel/include/misc/utils.h b/kernel/include/misc/utils.h index 0a97b1ff..510200eb 100644 --- a/kernel/include/misc/utils.h +++ b/kernel/include/misc/utils.h @@ -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); } \ No newline at end of file diff --git a/kernel/src/misc/utils.cpp b/kernel/src/misc/utils.cpp index 404deab5..6607f9fe 100644 --- a/kernel/src/misc/utils.cpp +++ b/kernel/src/misc/utils.cpp @@ -18,4 +18,15 @@ uint64_t Utilities::get_rflags() 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; } \ No newline at end of file