1
0
Files
irix-657m-src/eoe/man/man2/getcontext.2
2022-09-29 17:59:04 +03:00

67 lines
2.4 KiB
Groff

'\"macro stdmacro
.if n .pH g2.sigpending @(#)getcontext 40.12 of 1/3/91
.\" Copyright 1991 UNIX System Laboratories, Inc.
.\" Copyright 1989, 1990 AT&T
.nr X
.if \nX=0 .ds x} getcontext 2 "" "\&"
.if \nX=1 .ds x} getcontext 2 ""
.if \nX=2 .ds x} getcontext 2 "" "\&"
.if \nX=3 .ds x} getcontext "" "" "\&"
.TH \*(x}
.SH NAME
\f4getcontext\f1, \f4setcontext\f1 \- get and set current user context
.SH SYNOPSIS
.nf
\f4#include <ucontext.h>\f1
.sp .5
\f4int getcontext(ucontext_t \(**ucp);\f1
.sp .5
\f4int setcontext(ucontext_t \(**ucp);\f1
.fi
.SH DESCRIPTION
These functions, along with those defined in \f4makecontext\fP(3C),
are useful for implementing user level context switching
between multiple threads of control within a process.
.PP
\f4getcontext\fP
initializes the structure pointed to by \f2ucp\f1 to the current
user context of the calling process. The user context is defined by
\f4ucontext\fP(5)
and includes the contents of the calling process's machine registers,
signal mask and execution stack.
.PP
\f4setcontext\fP
restores the user context pointed to by
.IR ucp .
The call to
\f4setcontext\fP
does not return; program execution resumes at the point specified
by the context structure passed to \f4setcontext\fP.
The context structure should have been one created either
by a prior call to \f4getcontext\fP or \f4makecontext\fP
or passed as the third argument to a signal handler [see \f4sigaction\fP(2)].
If the context structure was one created with \f4getcontext\fP,
program execution continues as if the corresponding call of
\f4getcontext\fP
had just returned. If the context structure was one created with
\f4makecontext\fP,
program execution continues with the function specified to
\f4makecontext\fP.
.SH "NOTES"
When a signal handler is executed, the current user context is saved
and a new context is created by the kernel. If the process leaves
the signal handler via \f4longjmp\fP(3C)
the original context will not be restored, and future calls to
\f4getcontext\fP
will not be reliable. Signal handlers should use
\f4siglongjmp\fP(3C)
or \f4setcontext\fP instead.
.SH "DIAGNOSTICS"
On successful completion,
\f4setcontext\fP does not return and \f4getcontext\fP
returns 0.
Otherwise, a value
of -1 is returned and \f4errno\fP is set to indicate the error.
.SH "SEE ALSO"
\f4sigaction\fP(2), \f4sigaltstack\fP(2), \f4sigprocmask\fP(2), \f4makecontext\fP(3C), \f4ucontext\fP(5).