28#define STACK_FLAGS MAP_PRIVATE | MAP_ANONYMOUS
30#define STACK_FLAGS MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_STACK
39 const size_t usable = (desired_size + os_page_size - 1) & ~(os_page_size - 1);
41 const size_t total = usable + os_page_size;
53 PANIC_IF(end == MAP_FAILED,
"Failed to allocate the stack for the fiber subsystem");
55 if (mprotect(end, os_page_size, PROT_NONE) == -1) {
57 PANIC(
"Failed to allocate the guard page for the fiber subsystem");
60 const uintptr_t start = (uintptr_t)end + (uintptr_t)
total;
61 const uintptr_t limit = (uintptr_t)end + (uintptr_t)os_page_size;
63 srn_fiber_stack_t stack = {.start = (
void *)start, .limit = (
void *)limit, .guard = end};
size_t srn_mm_get_os_page_size(void)
Retutrns the OS page size.
AI Generated (🤦) Fiber subsystem overview.
#define SRN_FIBER_DEFAULT_STACK_SIZE
Default size of every fiber stack.
srn_fiber_stack_t srn_fiber_stack_alloc(size_t size)
Allocate a stack of at least size usable bytes plus a guard page, or SRN_FIBER_DEFAULT_STACK_SIZE whe...
void srn_fiber_stack_free(srn_fiber_stack_t stack)
One stack per fiber, mapped with a guard page at the low end so an overflow faults deterministically ...
void * guard
The protected page to detect stack overflows.
void * start
High end, stack pointer initialises to this address.
#define PANIC_IF(cond, msg)