xref: /dflybsd-src/lib/libc/gen/getcontext.3 (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
1*86d7f5d3SJohn Marino.\" Copyright (c) 2002 Packet Design, LLC.
2*86d7f5d3SJohn Marino.\" All rights reserved.
3*86d7f5d3SJohn Marino.\"
4*86d7f5d3SJohn Marino.\" Subject to the following obligations and disclaimer of warranty,
5*86d7f5d3SJohn Marino.\" use and redistribution of this software, in source or object code
6*86d7f5d3SJohn Marino.\" forms, with or without modifications are expressly permitted by
7*86d7f5d3SJohn Marino.\" Packet Design; provided, however, that:
8*86d7f5d3SJohn Marino.\"
9*86d7f5d3SJohn Marino.\"    (i)  Any and all reproductions of the source or object code
10*86d7f5d3SJohn Marino.\"         must include the copyright notice above and the following
11*86d7f5d3SJohn Marino.\"         disclaimer of warranties; and
12*86d7f5d3SJohn Marino.\"    (ii) No rights are granted, in any manner or form, to use
13*86d7f5d3SJohn Marino.\"         Packet Design trademarks, including the mark "PACKET DESIGN"
14*86d7f5d3SJohn Marino.\"         on advertising, endorsements, or otherwise except as such
15*86d7f5d3SJohn Marino.\"         appears in the above copyright notice or in the software.
16*86d7f5d3SJohn Marino.\"
17*86d7f5d3SJohn Marino.\" THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
18*86d7f5d3SJohn Marino.\" TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
19*86d7f5d3SJohn Marino.\" REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
20*86d7f5d3SJohn Marino.\" THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
21*86d7f5d3SJohn Marino.\" WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
22*86d7f5d3SJohn Marino.\" OR NON-INFRINGEMENT.  PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
23*86d7f5d3SJohn Marino.\" OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
24*86d7f5d3SJohn Marino.\" OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
25*86d7f5d3SJohn Marino.\" RELIABILITY OR OTHERWISE.  IN NO EVENT SHALL PACKET DESIGN BE
26*86d7f5d3SJohn Marino.\" LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
27*86d7f5d3SJohn Marino.\" OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
28*86d7f5d3SJohn Marino.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
29*86d7f5d3SJohn Marino.\" DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
30*86d7f5d3SJohn Marino.\" USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
31*86d7f5d3SJohn Marino.\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32*86d7f5d3SJohn Marino.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
33*86d7f5d3SJohn Marino.\" THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
34*86d7f5d3SJohn Marino.\" THE POSSIBILITY OF SUCH DAMAGE.
35*86d7f5d3SJohn Marino.\"
36*86d7f5d3SJohn Marino.\" $FreeBSD: src/lib/libc/gen/getcontext.3,v 1.3 2004/12/03 14:10:04 rse Exp $
37*86d7f5d3SJohn Marino.\" $DragonFly: src/lib/libc/gen/getcontext.3,v 1.1 2007/01/16 07:16:23 dillon Exp $
38*86d7f5d3SJohn Marino.\"
39*86d7f5d3SJohn Marino.Dd September 10, 2002
40*86d7f5d3SJohn Marino.Dt GETCONTEXT 3
41*86d7f5d3SJohn Marino.Os
42*86d7f5d3SJohn Marino.Sh NAME
43*86d7f5d3SJohn Marino.Nm getcontext , setcontext
44*86d7f5d3SJohn Marino.Nd get and set user thread context
45*86d7f5d3SJohn Marino.Sh LIBRARY
46*86d7f5d3SJohn Marino.Lb libc
47*86d7f5d3SJohn Marino.Sh SYNOPSIS
48*86d7f5d3SJohn Marino.In ucontext.h
49*86d7f5d3SJohn Marino.Ft int
50*86d7f5d3SJohn Marino.Fn getcontext "ucontext_t *ucp"
51*86d7f5d3SJohn Marino.Ft int
52*86d7f5d3SJohn Marino.Fn setcontext "const ucontext_t *ucp"
53*86d7f5d3SJohn Marino.Sh DESCRIPTION
54*86d7f5d3SJohn MarinoThe
55*86d7f5d3SJohn Marino.Fn getcontext
56*86d7f5d3SJohn Marinofunction
57*86d7f5d3SJohn Marinosaves the current thread's execution context in the structure pointed to by
58*86d7f5d3SJohn Marino.Fa ucp .
59*86d7f5d3SJohn MarinoThis saved context may then later be restored by calling
60*86d7f5d3SJohn Marino.Fn setcontext .
61*86d7f5d3SJohn Marino.Pp
62*86d7f5d3SJohn MarinoThe
63*86d7f5d3SJohn Marino.Fn setcontext
64*86d7f5d3SJohn Marinofunction
65*86d7f5d3SJohn Marinomakes a previously saved thread context the current thread context, i.e.,
66*86d7f5d3SJohn Marinothe current context is lost and
67*86d7f5d3SJohn Marino.Fn setcontext
68*86d7f5d3SJohn Marinodoes not return.
69*86d7f5d3SJohn MarinoInstead, execution continues in the context specified by
70*86d7f5d3SJohn Marino.Fa ucp ,
71*86d7f5d3SJohn Marinowhich must have been previously initialized by a call to
72*86d7f5d3SJohn Marino.Fn getcontext ,
73*86d7f5d3SJohn Marino.Xr makecontext 3 ,
74*86d7f5d3SJohn Marinoor by being passed as an argument to a signal handler (see
75*86d7f5d3SJohn Marino.Xr sigaction 2 ) .
76*86d7f5d3SJohn Marino.Pp
77*86d7f5d3SJohn MarinoIf
78*86d7f5d3SJohn Marino.Fa ucp
79*86d7f5d3SJohn Marinowas initialized by
80*86d7f5d3SJohn Marino.Fn getcontext ,
81*86d7f5d3SJohn Marinothen execution continues as if the original
82*86d7f5d3SJohn Marino.Fn getcontext
83*86d7f5d3SJohn Marinocall had just returned (again).
84*86d7f5d3SJohn Marino.Pp
85*86d7f5d3SJohn MarinoIf
86*86d7f5d3SJohn Marino.Fa ucp
87*86d7f5d3SJohn Marinowas initialized by
88*86d7f5d3SJohn Marino.Xr makecontext 3 ,
89*86d7f5d3SJohn Marinoexecution continues with the invocation of the function specified to
90*86d7f5d3SJohn Marino.Xr makecontext 3 .
91*86d7f5d3SJohn MarinoWhen that function returns,
92*86d7f5d3SJohn Marino.Fa "ucp->uc_link"
93*86d7f5d3SJohn Marinodetermines what happens next:
94*86d7f5d3SJohn Marinoif
95*86d7f5d3SJohn Marino.Fa "ucp->uc_link"
96*86d7f5d3SJohn Marinois
97*86d7f5d3SJohn Marino.Dv NULL ,
98*86d7f5d3SJohn Marinothe process exits;
99*86d7f5d3SJohn Marinootherwise,
100*86d7f5d3SJohn Marino.Fn setcontext "ucp->uc_link"
101*86d7f5d3SJohn Marinois implicitly invoked.
102*86d7f5d3SJohn Marino.Pp
103*86d7f5d3SJohn MarinoIf
104*86d7f5d3SJohn Marino.Fa ucp
105*86d7f5d3SJohn Marinowas initialized by the invocation of a signal handler, execution continues
106*86d7f5d3SJohn Marinoat the point the thread was interrupted by the signal.
107*86d7f5d3SJohn Marino.Sh RETURN VALUES
108*86d7f5d3SJohn MarinoIf successful,
109*86d7f5d3SJohn Marino.Fn getcontext
110*86d7f5d3SJohn Marinoreturns zero and
111*86d7f5d3SJohn Marino.Fn setcontext
112*86d7f5d3SJohn Marinodoes not return; otherwise \-1 is returned.
113*86d7f5d3SJohn Marino.Sh ERRORS
114*86d7f5d3SJohn MarinoNo errors are defined for
115*86d7f5d3SJohn Marino.Fn getcontext
116*86d7f5d3SJohn Marinoor
117*86d7f5d3SJohn Marino.Fn setcontext .
118*86d7f5d3SJohn Marino.Sh SEE ALSO
119*86d7f5d3SJohn Marino.Xr sigaction 2 ,
120*86d7f5d3SJohn Marino.Xr sigaltstack 2 ,
121*86d7f5d3SJohn Marino.Xr makecontext 3 ,
122*86d7f5d3SJohn Marino.Xr ucontext 3
123