|
PatchworkOS
|
Helpers for managing stacks. More...
Data Structures | |
| struct | stack_pointer_t |
| Structure to define a stack in memory. More... | |
Macros | |
| #define | STACK_POINTER_GUARD_PAGES 1 |
| The amount of guard pages to use for stacks. | |
Functions | |
| uint64_t | stack_pointer_init (stack_pointer_t *stack, uintptr_t maxAddress, uint64_t maxPages) |
| Initializes a stack pointer structure, does not allocate or map any memory. | |
| uint64_t | stack_pointer_init_buffer (stack_pointer_t *stack, void *buffer, uint64_t pages) |
| Initializes a stack pointer structure using a provided buffer, does not allocate or map any memory. | |
| void | stack_pointer_deinit (stack_pointer_t *stack, thread_t *thread) |
| Deinitializes a stack pointer structure and unmaps any mapped memory. | |
| void | stack_pointer_deinit_buffer (stack_pointer_t *stack) |
Deinitializes a stack pointer structure that was initialized using stack_pointer_init_buffer(). | |
| bool | stack_pointer_is_in_stack (stack_pointer_t *stack, uintptr_t addr, uint64_t length) |
| Check if an region is within the stack. | |
| bool | stack_pointer_overlaps_guard (stack_pointer_t *stack, uintptr_t addr, uint64_t length) |
| Check if an region overlaps the guard. | |
Helpers for managing stacks.
| #define STACK_POINTER_GUARD_PAGES 1 |
The amount of guard pages to use for stacks.
Definition at line 19 of file stack_pointer.h.
| void stack_pointer_deinit | ( | stack_pointer_t * | stack, |
| thread_t * | thread | ||
| ) |
Deinitializes a stack pointer structure and unmaps any mapped memory.
| stack | The stack pointer structure to deinitialize. |
| thread | The thread that owns the stack, used to get the address space to unmap the memory from. |
Definition at line 59 of file stack_pointer.c.
References BYTES_TO_PAGES, NULL, thread_t::process, process_t::space, stack, and vmm_unmap().
| void stack_pointer_deinit_buffer | ( | stack_pointer_t * | stack | ) |
Deinitializes a stack pointer structure that was initialized using stack_pointer_init_buffer().
This will not unmap any memory as the memory was provided by the caller.
| stack | The stack pointer structure to deinitialize. |
Definition at line 75 of file stack_pointer.c.
Referenced by cpu_init().
| uint64_t stack_pointer_init | ( | stack_pointer_t * | stack, |
| uintptr_t | maxAddress, | ||
| uint64_t | maxPages | ||
| ) |
Initializes a stack pointer structure, does not allocate or map any memory.
This is used to create stacks that grow dynamically, for example the kernel and user stacks of a thread.
| stack | The stack pointer structure to initialize. |
| maxAddress | The maximum address the stack will start at, must be page aligned. |
| maxPages | The maximum amount of pages the stack can grow to, must not be 0. |
0. On failure, ERR and errno is set. Definition at line 7 of file stack_pointer.c.
References EINVAL, EOVERFLOW, ERR, errno, maxPages, NULL, PAGE_SIZE, stack, STACK_POINTER_GUARD_PAGES, and VMM_IS_PAGE_ALIGNED.
Referenced by thread_init().
| uint64_t stack_pointer_init_buffer | ( | stack_pointer_t * | stack, |
| void * | buffer, | ||
| uint64_t | pages | ||
| ) |
Initializes a stack pointer structure using a provided buffer, does not allocate or map any memory.
This is used to create stacks that do not grow dynamically, for example the exception and double fault stacks of a CPU.
These stacks will not have a guard page.
Will not take ownership of the provided buffer.
| stack | The stack pointer structure to initialize. |
| buffer | The buffer to use for the stack, must be page aligned. |
| pages | The amount of pages the stack will use, must not be 0. |
0. On failure, ERR and errno is set. Definition at line 34 of file stack_pointer.c.
References buffer, EINVAL, EOVERFLOW, ERR, errno, memset(), NULL, PAGE_SIZE, stack, and VMM_IS_PAGE_ALIGNED.
Referenced by cpu_init().
| bool stack_pointer_is_in_stack | ( | stack_pointer_t * | stack, |
| uintptr_t | addr, | ||
| uint64_t | length | ||
| ) |
Check if an region is within the stack.
| stack | The stack pointer structure. |
| addr | The starting address of the region. |
| length | The length of the region, in bytes. |
true if the region is within the stack, false otherwise. Definition at line 89 of file stack_pointer.c.
Referenced by space_pin(), space_pin_terminated(), and thread_handle_page_fault().
| bool stack_pointer_overlaps_guard | ( | stack_pointer_t * | stack, |
| uintptr_t | addr, | ||
| uint64_t | length | ||
| ) |
Check if an region overlaps the guard.
| stack | The stack pointer structure. |
| addr | The starting address of the region. |
| length | The length of the region, in bytes. |
true if the region overlaps the guard, false otherwise. Definition at line 105 of file stack_pointer.c.