23 lines
486 B
C
23 lines
486 B
C
|
#pragma once
|
||
|
|
||
|
#include <stdint.h>
|
||
|
|
||
|
#ifndef PAGE_SIZE
|
||
|
#define PAGE_SIZE 4096
|
||
|
#endif
|
||
|
|
||
|
inline uintptr_t get_top_of_stack(uintptr_t bottom, uintptr_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;
|
||
|
}
|