#pragma once #include #include #ifndef PAGE_SIZE #define PAGE_SIZE 4096 #endif inline uintptr_t get_top_of_stack(uintptr_t bottom, size_t stack_pages) { return bottom + (stack_pages * PAGE_SIZE) - sizeof(uintptr_t); } inline uintptr_t round_down_to_nearest_page(uintptr_t addr) { return addr - (addr % PAGE_SIZE); } inline uintptr_t round_up_to_nearest_page(uintptr_t addr) { if (addr % PAGE_SIZE) return addr + (PAGE_SIZE - (addr % PAGE_SIZE)); return addr; }