MAKECONTEXT(3)

NAME
makecontext, swapcontext - manipulate user contexts

LIBRARY
libc

SYNOPSIS
#include <ucontext.h>
void
makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...);
int
swapcontext(ucontext_t *oucp, const ucontext_t *ucp);

DESCRIPTION
The makecontext(3), swapcontext(3), getcontext(3), and setcontext(3) together form a set of functions that allow user-level context switching between multiple threads of control within a process.

The makecontext() function modifies the user thread pointed to by ucp to continue execution by invoking function func and passing that function a number of argc integer arguments. The value of argc must match the number of integer arguments passed to func, otherwise the behavior is undefined. Context ucp must have been initialized by a call to getcontext(3) and have a stack allocated for it. The address of the stack must be assigned to ucp->uc_stack.ss_sp and the size of the stack to ucp->uc_stack.ss_size. The ucp->uc_link member is used to determine which successor context is run after the context modified by makecontext() returns. If left NULL, the process exits.

The swapcontext() function saves the current context in the context structure pointed to by oucp and sets the context to the context structure pointed to by ucp.

RETURN VALUES
When successful, swapcontext() returns 0. Otherwise, -1 is returned and errno is set to indicate the error. Note that a successful call to swapcontext() actually does not return. Only after returning to the context that called swapcontext(), it appears as if swapcontext() returned 0.

ERRORS

[EFAULT]
    Either the ucp or oucp is a NULL pointer.

[EINVAL]
    The context is not properly initialized.

[ENOMEM]
    The ucp argument does not have enough stack left to complete the operation.

SEE ALSO
getcontext(3), setcontext(3)

STANDARDS
The makecontext(), and swapcontext() functions conform to xsh5 and p1003.1-2001.

AUTHORS
Thomas Veerman