2010-03-12 16:58:41 +01:00
.TH MAKECONTEXT 3 "Mar 2, 2010"
.SH NAME
makecontext, swapcontext \- manipulate user contexts
.SH SYNOPSIS
.nf
.ft B
#include <ucontext.h>
void makecontext(ucontext\_ t *\fI ucp\fP , void \fI (*func)(void)\fP , int \fI argc\fP , ...)
int swapcontext(ucontext\_ t *\fI oucp\fP , const ucontext\_ t *\fI ucp\fP )
.SH DESCRIPTION
The
.BR makecontext (3)
,
.BR swapcontext (3)
,
.BR getcontext (3)
, and
.BR setcontext (3)
together form a set of functions that allow user-level context switching between multiple threads of control within a process.
.PP
The
.BR makecontext ()
function modifies the user thread pointed to by
.I ucp
to continue execution by invoking function
.I func
and passing that function a number of
.I argc
integer arguments. The value of
.I argc
must match the number of integer arguments passed to
.I func
, otherwise the behavior is undefined. Context
.I ucp
must have been initialized by a call to
.BR getcontext (3)
2010-06-11 13:17:31 +02:00
and have a stack allocated for it. The address of the stack must be assigned to \fI ucp\- >uc_stack.ss_sp\fP and the size of the stack to \fI ucp\- >uc_stack.ss_size\fP . The \fI ucp\- >uc_link\fP member is used to determine which successor context is run after the context modified by
2010-03-12 16:58:41 +01:00
.BR makecontext ()
returns. If left NULL, the process exits.
.PP
The
.BR swapcontext ()
function saves the current context in the context structure pointed to by
.I oucp
and sets the context to the context structure pointed to by \fI ucp\fP .
.SH "RETURN VALUE"
When successful,
.BR swapcontext ()
returns 0. Otherwise, -1 is returned and
.I errno
2010-06-11 13:17:31 +02:00
is set to indicate the error. Note that a successful call to
2010-03-12 16:58:41 +01:00
.BR swapcontext ()
actually does not return. Only after returning to the context that called
.BR swapcontext ()
, it appears as if
.BR swapcontext ()
returned 0.
.SH "ERRORS"
.TP 15
[EFAULT]
Either the \fI ucp\fP or \fI oucp\fP is a NULL pointer.
.TP 15
[EINVAL]
The context is not properly initialized.
.TP 15
[ENOMEM]
The \fI ucp\fP argument does not have enough stack left to complete the operation.
.SH "SEE ALSO"
.BR getcontext (3).
.SH "AUTHORS"
Thomas Veerman