minix/man/man3/getcontext.3

137 lines
2.8 KiB
Groff
Raw Normal View History

2010-07-15 10:48:24 +02:00
.Dd Mar 2, 2010
.Dt GETCONTEXT 3
.Os
.Sh NAME
.Nm getcontext ,
.Nm setcontext
.Nd get and set current user context
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In ucontext.h
.Ft int
.Fn getcontext "ucontext_t *ucp"
.Ft int
.Fn setcontext "const ucontext_t *ucp"
.Sh DESCRIPTION
The
2010-07-15 10:48:24 +02:00
.Xr makecontext 3
,
2010-07-15 10:48:24 +02:00
.Xr swapcontext 3
,
2010-07-15 10:48:24 +02:00
.Xr getcontext 3
, and
2010-07-15 10:48:24 +02:00
.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
.Vt ucontext_t
type is a structure that has at least the following members:
.Bd -offset 4n -literal
typedef struct __ucontext {
2010-07-15 10:48:24 +02:00
ucontext_t *uc_link;
sigset_t uc_sigmask;
stack_t uc_stack;
mcontext_t uc_mcontext;
...
} ucontext_t;
2010-07-15 10:48:24 +02:00
.Ed
2010-07-15 10:48:24 +02:00
with
.Vt sigset_t
and
.Vt stack_t
defined in
.In signal.h .
Here
.Va uc_link
points to the context that will be resumed when the current context returns (if
.Va uc_link
is NULL, the process exits),
.Va uc_sigmask
is the set of signals blocked in this context,
.Va uc_stack
is the stack used by this context (when the context was modified by
.Xr makecontext 3 ),
and
.Va uc_mcontext
is the machine-specific representation of the saved context. The
.Vt mcontext_t
type is machine-dependent and opaque.
.Pp
MINIX 3 has an additional
.Va uc_flags
member that supports the following flags:
.Pp
.Bd -offset 4n -literal
UCF_IGNSIGM /* Current signal mask is not stored or restored */
UCF_IGNFPU /* FPU state is not stored or restored for this context */
2010-07-15 10:48:24 +02:00
.Ed
.Pp
Not storing and restoring the signal mask and/or FPU state speeds up context switching considerably.
2010-07-15 10:48:24 +02:00
.Pp
The
2010-07-15 10:48:24 +02:00
.Fn getcontext
function initializes the structure pointed to by
.Va ucp
to the current user context of the calling thread.
.Pp
The
2010-07-15 10:48:24 +02:00
.Fn setcontext
function restores the user context pointed to by
.Va ucp .
A succesful call does not return; program execution resumes at the point specified by the
.Va ucp
argument passed to
.Fn setcontext .
The
.Va ucp
argument should be created either by a prior call to
.Fn getcontext
or
2010-07-15 10:48:24 +02:00
.Fn makecontext .
If the
.Va ucp
argument was created with
.Fn getcontext ,
program execution continues as if the corresponding call of
2010-07-15 10:48:24 +02:00
.Fn getcontext
had just returned. If the
.Va ucp
argument was created with
.Fn makecontext ,
program execution continues with the function passed to
2010-07-15 10:48:24 +02:00
.Fn makecontext .
2010-07-15 10:48:24 +02:00
.Sh RETURN VALUES
When successful,
2010-07-15 10:48:24 +02:00
.Fn getcontext
returns 0 and
2010-07-15 10:48:24 +02:00
.Fn setcontext
does not return. Otherwise, both return -1 and
2010-07-15 10:48:24 +02:00
.Va errno
is set to indicate the error.
2010-07-15 10:48:24 +02:00
.Sh ERRORS
.Bl -tag -width Er
.It Bq Er EINVAL
The context is not properly initialized.
2010-07-15 10:48:24 +02:00
.It Bq Er EFAULT
.Va ucp
is a NULL pointer.
.El
.Sh SEE ALSO
.Xr makecontext 3 ,
.Xr swapcontext 3
.Sh STANDARDS
The
.Fn getcontext ,
and
.Fn setcontext
functions conform to
.St -xsh5
and
.St -p1003.1-2001 .
.Sh AUTHORS
Thomas Veerman