MAKECONTEXT(3) Library Functions Manual MAKECONTEXT(3)

makecontext, swapcontextmodify and exchange user thread contexts

Standard C Library (libc, -lc)

#include <ucontext.h>

void
makecontext(ucontext_t *ucp, void (*func)(), int argc, ...);

int
swapcontext(ucontext_t *oucp, const ucontext_t *ucp);

The () function modifies the user thread context pointed to by ucp, which must have previously been initialized by a call to getcontext(3) and had a stack allocated for it. The context is modified so that it will continue execution by invoking () with the arguments (of type int) provided. The argc argument must be equal to the number of additional arguments provided to makecontext() and also equal to the number of arguments to func(), or else the behavior is undefined.

The ucp->uc_link argument must be initialized before calling () and determines the action to take when () returns: if equal to NULL, the process exits; otherwise, (ucp->uc_link) is implicitly invoked.

The () function saves the current thread context in *oucp and makes *ucp the currently active context.

If successful, swapcontext() returns zero; otherwise -1 is returned and the global variable errno is set appropriately.

The swapcontext() function will fail if:

[]
There is not enough stack space in ucp to complete the operation.

setcontext(3), ucontext(3)

September 10, 2002 macOS 15.2