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