xco_platform_internal.h (1362B)
1 /* 2 * xco_platform.h — generic platform interface for xco.c. 3 * 4 * Declares the two primitives the platform layer must implement, plus 5 * the (forward-declared) context type. xco.c never derefs values of 6 * this type — it only passes pointers around — so the forward 7 * declaration is enough here. The full struct lives in the platform- 8 * specific xco_platform.c (under platform/<name>/). 9 */ 10 11 #ifndef XCO_PLATFORM_H 12 #define XCO_PLATFORM_H 13 14 #include <stddef.h> 15 #include <stdint.h> 16 17 typedef struct xco_platform_ctx xco_platform_ctx_t; 18 19 /* Initialize *ctx so that the next switch into it begins executing 20 * entry(value), where value is the uintptr_t handed to the switch. 21 * stack_base must be XCO_STACK_ALIGN-aligned. entry must not return. */ 22 void xco_platform_init(xco_platform_ctx_t *ctx, 23 void *stack_base, size_t stack_len, 24 void (*entry)(uintptr_t)); 25 26 /* Save callee-saved state into *from, restore it from *to, and hand 27 * `value` to *to — as the return value of *to's previous switch, or 28 * as entry's argument on first switch into a fresh context. Returns 29 * the value passed by the next switch back to *from. */ 30 uintptr_t xco_platform_switch(xco_platform_ctx_t *from, 31 xco_platform_ctx_t *to, 32 uintptr_t value); 33 34 #endif /* XCO_PLATFORM_H */