]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/gen/makecontext.3
libsys: move errno to libsys
[FreeBSD/FreeBSD.git] / lib / libc / gen / makecontext.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 .Dd March 23, 2020
37 .Dt MAKECONTEXT 3
38 .Os
39 .Sh NAME
40 .Nm makecontext , swapcontext
41 .Nd modify and exchange user thread contexts
42 .Sh LIBRARY
43 .Lb libc
44 .Sh SYNOPSIS
45 .In ucontext.h
46 .Ft void
47 .Fo makecontext
48 .Fa "ucontext_t *ucp"
49 .Fa "void \*[lp]*func\*[rp]\*[lp]void\*[rp]"
50 .Fa "int argc" ...
51 .Fc
52 .Ft int
53 .Fn swapcontext "ucontext_t *oucp" "const ucontext_t *ucp"
54 .Sh DESCRIPTION
55 The
56 .Fn makecontext
57 function
58 modifies the user thread context pointed to by
59 .Fa ucp ,
60 which must have previously been initialized by a call to
61 .Xr getcontext 3
62 and had a stack allocated for it.
63 The context is modified so that it will continue execution by invoking
64 .Fn func
65 with the arguments provided.
66 The
67 .Fa argc
68 argument
69 must be equal to the number of additional arguments of type
70 .Vt int
71 provided to
72 .Fn makecontext
73 and also equal to the number of arguments of type
74 .Vt int
75 to
76 .Fn func ;
77 otherwise ,
78 the behavior is undefined.
79 .Pp
80 The
81 .Fa "ucp->uc_link"
82 argument
83 must be initialized before calling
84 .Fn makecontext
85 and determines the action to take when
86 .Fn func
87 returns:
88 if equal to
89 .Dv NULL ,
90 the process exits;
91 otherwise,
92 .Fn setcontext "ucp->uc_link"
93 is implicitly invoked.
94 .Pp
95 The
96 .Fn swapcontext
97 function
98 saves the current thread context in
99 .Fa "*oucp"
100 and makes
101 .Fa "*ucp"
102 the currently active context.
103 .Sh RETURN VALUES
104 If successful,
105 .Fn swapcontext
106 returns zero;
107 otherwise \-1 is returned and the global variable
108 .Va errno
109 is set appropriately.
110 .Sh ERRORS
111 The
112 .Fn swapcontext
113 function
114 will fail if:
115 .Bl -tag -width Er
116 .It Bq Er ENOMEM
117 There is not enough stack space in
118 .Fa ucp
119 to complete the operation.
120 .El
121 .Sh SEE ALSO
122 .Xr setcontext 3 ,
123 .Xr ucontext 3
124 .Sh STANDARDS
125 The
126 .Fn makecontext
127 and
128 .Fn swapcontext
129 functions conform to
130 .St -xsh5
131 and
132 .St -p1003.1-2001 .
133 .Pp
134 The
135 .St -p1003.1-2004
136 revision marked the functions
137 .Fn makecontext
138 and
139 .Fn swapcontext
140 as obsolete, citing portability issues and recommending the use of
141 .Tn POSIX
142 threads instead.
143 The
144 .St -p1003.1-2008
145 revision removed the functions from the specification.
146 .Pp
147 .Bf -symbolic
148 The standard does not clearly define the type of integer arguments
149 passed to
150 .Fa func
151 via
152 .Fn makecontext ;
153 portable applications should not rely on the implementation detail that
154 it may be possible to pass pointer arguments to functions.
155 .Sh HISTORY
156 The
157 .Fn makecontext
158 and
159 .Fn swapcontext
160 functions first appeared in
161 .At V.4 .