1#ifndef COROUTINE_UCONTEXT_CONTEXT_H
2#define COROUTINE_UCONTEXT_CONTEXT_H 1
17#define COROUTINE __attribute__((noreturn)) void
21#if INTPTR_MAX <= INT32_MAX
22#define COROUTINE_LIMITED_ADDRESS_SPACE
35COROUTINE coroutine_trampoline(
void * _start,
void * _context);
39 getcontext(&context->state);
42static inline void coroutine_initialize(
44 coroutine_start start,
48 assert(start && stack && size >= 1024);
50 coroutine_initialize_main(context);
52 context->state.uc_stack.ss_size = size;
54 context->state.uc_stack.ss_sp = (
char*)stack;
55 context->state.uc_stack.ss_flags = 0;
56 context->state.uc_link = NULL;
58 makecontext(&context->state, (
void(*)(
void))coroutine_trampoline, 2, (
void*)start, (
void*)context);
65 target->from = current;
66 swapcontext(¤t->state, &target->state);
67 target->from = previous;
74 context->state.uc_stack.ss_sp = NULL;
75 context->state.uc_stack.ss_size = 0;