minix/man/man3/makecontext.3

98 lines
2.2 KiB
Groff
Raw Normal View History

2010-07-15 10:48:24 +02:00
.Dd Mar 2, 2010
.Dt MAKECONTEXT 3
.Os
.Sh NAME
.Nm makecontext ,
.Nm swapcontext
.Nd manipulate user contexts
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In ucontext.h
.Ft void
.Fn makecontext "ucontext_t *ucp" "void (*func)(void)" "int argc" ...
.Ft int
.Fn swapcontext "ucontext_t *oucp" "const ucontext_t *ucp"
.Sh DESCRIPTION
The
2010-07-15 10:48:24 +02:00
.Xr makecontext 3 ,
.Xr swapcontext 3 ,
.Xr getcontext 3 ,
and
.Xr setcontext 3
together form a set of functions that allow user-level context switching between multiple threads of control within a process.
2010-07-15 10:48:24 +02:00
.Pp
The
2010-07-15 10:48:24 +02:00
.Fn makecontext
function modifies the user thread pointed to by
2010-07-15 10:48:24 +02:00
.Va ucp
to continue execution by invoking function
2010-07-15 10:48:24 +02:00
.Va func
and passing that function a number of
2010-07-15 10:48:24 +02:00
.Va argc
integer arguments. The value of
2010-07-15 10:48:24 +02:00
.Va argc
must match the number of integer arguments passed to
2010-07-15 10:48:24 +02:00
.Va func ,
otherwise the behavior is undefined. Context
.Va ucp
must have been initialized by a call to
2010-07-15 10:48:24 +02:00
.Xr getcontext 3
and have a stack allocated for it. The address of the stack must be assigned to
.Va ucp->uc_stack.ss_sp
and the size of the stack to
.Va ucp->uc_stack.ss_size .
The
.Va ucp->uc_link
member is used to determine which successor context is run after the context modified by
.Fn makecontext
returns. If left NULL, the process exits.
2010-07-15 10:48:24 +02:00
.Pp
The
2010-07-15 10:48:24 +02:00
.Fn swapcontext
function saves the current context in the context structure pointed to by
2010-07-15 10:48:24 +02:00
.Va oucp
and sets the context to the context structure pointed to by
.Va ucp .
.Sh RETURN VALUES
When successful,
2010-07-15 10:48:24 +02:00
.Fn swapcontext
returns 0. Otherwise, -1 is returned and
2010-07-15 10:48:24 +02:00
.Va errno
is set to indicate the error. Note that a successful call to
2010-07-15 10:48:24 +02:00
.Fn swapcontext
actually does not return. Only after returning to the context that called
2010-07-15 10:48:24 +02:00
.Fn swapcontext ,
it appears as if
.Fn swapcontext
returned 0.
2010-07-15 10:48:24 +02:00
.Sh ERRORS
.Bl -tag -width Er
.It Bq Er EFAULT
Either the
.Va ucp
or
.Va oucp
is a NULL pointer.
.It Bq Er EINVAL
The context is not properly initialized.
2010-07-15 10:48:24 +02:00
.It Bq Er ENOMEM
The
.Va ucp
argument does not have enough stack left to complete the operation.
.El
.Sh SEE ALSO
.Xr getcontext 3 ,
.Xr setcontext 3
.Sh STANDARDS
The
.Fn makecontext ,
and
.Fn swapcontext
functions conform to
.St -xsh5
and
.St -p1003.1-2001 .
.Sh AUTHORS
Thomas Veerman