]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - lib/libc/gen/getcontext.3
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.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$
37 .\"
38 .Dd March 13, 2013
39 .Dt GETCONTEXT 3
40 .Os
41 .Sh NAME
42 .Nm getcontext , getcontextx , setcontext
43 .Nd get and set user thread context
44 .Sh LIBRARY
45 .Lb libc
46 .Sh SYNOPSIS
47 .In ucontext.h
48 .Ft int
49 .Fn getcontext "ucontext_t *ucp"
50 .Ft ucontext_t *
51 .Fn getcontextx "void"
52 .Ft int
53 .Fn setcontext "const ucontext_t *ucp"
54 .Sh DESCRIPTION
55 The
56 .Fn getcontext
57 function
58 saves the current thread's execution context in the structure pointed to by
59 .Fa ucp .
60 This saved context may then later be restored by calling
61 .Fn setcontext .
62 .Pp
63 The
64 .Fn getcontextx
65 function saves the current execution context in the newly allocated structure
66 .Vt ucontext_t ,
67 which is returned on success.
68 If architecture defines additional CPU states that can be stored in extended
69 blocks referenced from the
70 .Vt ucontext_t ,
71 the memory for them may be allocated and their context also stored.
72 Memory returned by
73 .Fn getcontextx
74 function shall be freed using
75 .Fn free 3 .
76 .Pp
77 The
78 .Fn setcontext
79 function
80 makes a previously saved thread context the current thread context, i.e.,
81 the current context is lost and
82 .Fn setcontext
83 does not return.
84 Instead, execution continues in the context specified by
85 .Fa ucp ,
86 which must have been previously initialized by a call to
87 .Fn getcontext ,
88 .Xr makecontext 3 ,
89 or by being passed as an argument to a signal handler (see
90 .Xr sigaction 2 ) .
91 .Pp
92 If
93 .Fa ucp
94 was initialized by
95 .Fn getcontext ,
96 then execution continues as if the original
97 .Fn getcontext
98 call had just returned (again).
99 .Pp
100 If
101 .Fa ucp
102 was initialized by
103 .Xr makecontext 3 ,
104 execution continues with the invocation of the function specified to
105 .Xr makecontext 3 .
106 When that function returns,
107 .Fa "ucp->uc_link"
108 determines what happens next:
109 if
110 .Fa "ucp->uc_link"
111 is
112 .Dv NULL ,
113 the process exits;
114 otherwise,
115 .Fn setcontext "ucp->uc_link"
116 is implicitly invoked.
117 .Pp
118 If
119 .Fa ucp
120 was initialized by the invocation of a signal handler, execution continues
121 at the point the thread was interrupted by the signal.
122 .Sh RETURN VALUES
123 If successful,
124 .Fn getcontext
125 returns zero and
126 .Fn setcontext
127 does not return; otherwise \-1 is returned.
128 The
129 .Fn getcontextx
130 returns pointer to the allocated and initialized context on success, and
131 .Va NULL
132 on failure.
133 .Sh ERRORS
134 No errors are defined for
135 .Fn getcontext
136 or
137 .Fn setcontext .
138 The
139 .Fn getcontextx
140 may return the following errors in
141 .Va errno :
142 .Bl -tag -width Er
143 .It Bq Er ENOMEM
144 No memory was available to allocate for the context or some extended state.
145 .El
146 .Sh SEE ALSO
147 .Xr sigaction 2 ,
148 .Xr sigaltstack 2 ,
149 .Xr makecontext 3 ,
150 .Xr ucontext 3