2002-09-11 21:39:21 +00:00
|
|
|
.\" Copyright (c) 2002 Packet Design, LLC.
|
|
|
|
.\" All rights reserved.
|
2002-12-04 15:47:41 +00:00
|
|
|
.\"
|
2002-09-11 21:39:21 +00:00
|
|
|
.\" Subject to the following obligations and disclaimer of warranty,
|
|
|
|
.\" use and redistribution of this software, in source or object code
|
|
|
|
.\" forms, with or without modifications are expressly permitted by
|
|
|
|
.\" Packet Design; provided, however, that:
|
2002-12-04 15:47:41 +00:00
|
|
|
.\"
|
2002-09-11 21:39:21 +00:00
|
|
|
.\" (i) Any and all reproductions of the source or object code
|
|
|
|
.\" must include the copyright notice above and the following
|
|
|
|
.\" disclaimer of warranties; and
|
|
|
|
.\" (ii) No rights are granted, in any manner or form, to use
|
|
|
|
.\" Packet Design trademarks, including the mark "PACKET DESIGN"
|
|
|
|
.\" on advertising, endorsements, or otherwise except as such
|
|
|
|
.\" appears in the above copyright notice or in the software.
|
2002-12-04 15:47:41 +00:00
|
|
|
.\"
|
2002-09-11 21:39:21 +00:00
|
|
|
.\" THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
|
|
|
|
.\" TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
|
|
|
|
.\" REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
|
|
|
|
.\" THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
|
|
|
|
.\" WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
|
|
|
|
.\" OR NON-INFRINGEMENT. PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
|
|
|
|
.\" OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
|
|
|
|
.\" OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
|
|
|
|
.\" RELIABILITY OR OTHERWISE. IN NO EVENT SHALL PACKET DESIGN BE
|
|
|
|
.\" LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
|
|
|
|
.\" OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
|
|
|
|
.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
|
|
|
|
.\" USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
|
|
|
|
.\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
|
|
.\" THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
|
|
|
|
.\" THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" $FreeBSD$
|
|
|
|
.\"
|
2002-12-04 15:47:41 +00:00
|
|
|
.Dd September 10, 2002
|
2002-09-11 21:39:21 +00:00
|
|
|
.Dt GETCONTEXT 3
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
2002-12-04 15:47:41 +00:00
|
|
|
.Nm getcontext , setcontext
|
2002-09-11 21:39:21 +00:00
|
|
|
.Nd get and set user thread 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
|
2002-12-04 15:47:41 +00:00
|
|
|
The
|
2002-09-11 21:39:21 +00:00
|
|
|
.Fn getcontext
|
2002-12-04 15:47:41 +00:00
|
|
|
function
|
2002-09-11 21:39:21 +00:00
|
|
|
saves the current thread's execution context in the structure pointed to by
|
2002-12-04 15:47:41 +00:00
|
|
|
.Fa ucp .
|
2002-09-11 21:39:21 +00:00
|
|
|
This saved context may then later be restored by calling
|
|
|
|
.Fn setcontext .
|
|
|
|
.Pp
|
2002-12-04 15:47:41 +00:00
|
|
|
The
|
2002-09-11 21:39:21 +00:00
|
|
|
.Fn setcontext
|
2002-12-04 15:47:41 +00:00
|
|
|
function
|
2002-09-11 21:39:21 +00:00
|
|
|
makes a previously saved thread context the current thread context, i.e.,
|
|
|
|
the current context is lost and
|
|
|
|
.Fn setcontext
|
|
|
|
does not return.
|
|
|
|
Instead, execution continues in the context specified by
|
2002-12-04 15:47:41 +00:00
|
|
|
.Fa ucp ,
|
2002-09-11 21:39:21 +00:00
|
|
|
which must have been previously initialized by a call to
|
2004-12-03 14:10:04 +00:00
|
|
|
.Fn getcontext ,
|
2002-12-04 15:47:41 +00:00
|
|
|
.Xr makecontext 3 ,
|
2002-09-11 21:39:21 +00:00
|
|
|
or by being passed as an argument to a signal handler (see
|
2002-12-04 15:47:41 +00:00
|
|
|
.Xr sigaction 2 ) .
|
2002-09-11 21:39:21 +00:00
|
|
|
.Pp
|
|
|
|
If
|
|
|
|
.Fa ucp
|
|
|
|
was initialized by
|
|
|
|
.Fn getcontext ,
|
|
|
|
then execution continues as if the original
|
|
|
|
.Fn getcontext
|
|
|
|
call had just returned (again).
|
|
|
|
.Pp
|
|
|
|
If
|
|
|
|
.Fa ucp
|
|
|
|
was initialized by
|
2002-12-04 15:47:41 +00:00
|
|
|
.Xr makecontext 3 ,
|
2002-09-11 21:39:21 +00:00
|
|
|
execution continues with the invocation of the function specified to
|
2002-12-04 15:47:41 +00:00
|
|
|
.Xr makecontext 3 .
|
2002-09-11 21:39:21 +00:00
|
|
|
When that function returns,
|
|
|
|
.Fa "ucp->uc_link"
|
|
|
|
determines what happens next:
|
|
|
|
if
|
|
|
|
.Fa "ucp->uc_link"
|
|
|
|
is
|
|
|
|
.Dv NULL ,
|
|
|
|
the process exits;
|
|
|
|
otherwise,
|
|
|
|
.Fn setcontext "ucp->uc_link"
|
|
|
|
is implicitly invoked.
|
|
|
|
.Pp
|
|
|
|
If
|
|
|
|
.Fa ucp
|
|
|
|
was initialized by the invocation of a signal handler, execution continues
|
|
|
|
at the point the thread was interrupted by the signal.
|
|
|
|
.Sh RETURN VALUES
|
|
|
|
If successful,
|
|
|
|
.Fn getcontext
|
|
|
|
returns zero and
|
|
|
|
.Fn setcontext
|
2002-12-04 15:47:41 +00:00
|
|
|
does not return; otherwise \-1 is returned.
|
2002-09-11 21:39:21 +00:00
|
|
|
.Sh ERRORS
|
|
|
|
No errors are defined for
|
|
|
|
.Fn getcontext
|
|
|
|
or
|
|
|
|
.Fn setcontext .
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr sigaction 2 ,
|
|
|
|
.Xr sigaltstack 2 ,
|
|
|
|
.Xr makecontext 3 ,
|
|
|
|
.Xr ucontext 3
|