|
PatchworkOS
|
Structure to define a stack in memory. More...
#include <stack_pointer.h>
Data Fields | |
| uintptr_t | top |
| The top of the stack, this address is not inclusive. | |
| uintptr_t | bottom |
| The bottom of the stack, this address is inclusive. | |
| uintptr_t | guardTop |
| The top of the guard page, this address is inclusive. | |
| uintptr_t | guardBottom |
| The bottom of the guard page, this address is inclusive. | |
| uintptr_t | lastPageFault |
| The last page that caused a page fault, used to prevent infinite loops. | |
Structure to define a stack in memory.
A stack is defined as a region of page aligned memory that includes a guard page to catch stack overflows. The region of memory starts unmapped and when a page fault occurs within the stack region a new page is mapped to the faulting address.
The guard page is always the page just below the bottom of the stack, and is never mapped. If a thread tries to access the guard page a page fault will occur, which can be used to detect stack overflows.
The exception to the above is when using stack_pointer_init_buffer() to create a stack from a provided buffer, in this case there is no guard page and the entire region starts mapped.
Note that in x86 the stack grows downwards, so we start at the top and grow towards the bottom and that the "push" operation moves the stack pointer first then writes to the location of the stack pointer, this means we actually set the inital stack pointer to be the address just outside the top of the stack.
Definition at line 38 of file stack_pointer.h.
| uintptr_t stack_pointer_t::bottom |
The bottom of the stack, this address is inclusive.
Definition at line 41 of file stack_pointer.h.
Referenced by cpu_init(), and cpu_stacks_overflow_check().
| uintptr_t stack_pointer_t::guardBottom |
The bottom of the guard page, this address is inclusive.
Definition at line 43 of file stack_pointer.h.
Referenced by panic().
| uintptr_t stack_pointer_t::guardTop |
The top of the guard page, this address is inclusive.
Definition at line 42 of file stack_pointer.h.
| uintptr_t stack_pointer_t::lastPageFault |
The last page that caused a page fault, used to prevent infinite loops.
Definition at line 44 of file stack_pointer.h.
| uintptr_t stack_pointer_t::top |
The top of the stack, this address is not inclusive.
Definition at line 40 of file stack_pointer.h.
Referenced by init_early(), loader_setup_argv(), loader_spawn(), loader_thread_create(), sched_cpu_ctx_init(), syscall_ctx_init(), and trampoline_c_entry().