]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - lib/libc/gen/makecontext.3
MFC 328630:
[FreeBSD/stable/10.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 .\" $FreeBSD$
37 .\"
38 .Dd January 31, 2018
39 .Dt MAKECONTEXT 3
40 .Os
41 .Sh NAME
42 .Nm makecontext , swapcontext
43 .Nd modify and exchange user thread contexts
44 .Sh LIBRARY
45 .Lb libc
46 .Sh SYNOPSIS
47 .In ucontext.h
48 .Ft void
49 .Fo makecontext
50 .Fa "ucontext_t *ucp"
51 .Fa "void \*[lp]*func\*[rp]\*[lp]void\*[rp]"
52 .Fa "int argc" ...
53 .Fc
54 .Ft int
55 .Fn swapcontext "ucontext_t *oucp" "const ucontext_t *ucp"
56 .Sh DESCRIPTION
57 The
58 .Fn makecontext
59 function
60 modifies the user thread context pointed to by
61 .Fa ucp ,
62 which must have previously been initialized by a call to
63 .Xr getcontext 3
64 and had a stack allocated for it.
65 The context is modified so that it will continue execution by invoking
66 .Fn func
67 with the arguments provided.
68 The
69 .Fa argc
70 argument
71 must be equal to the number of additional arguments of type
72 .Vt int
73 provided to
74 .Fn makecontext
75 and also equal to the number of arguments of type
76 .Vt int
77 to
78 .Fn func ;
79 otherwise ,
80 the behavior is undefined.
81 .Pp
82 The
83 .Fa "ucp->uc_link"
84 argument
85 must be initialized before calling
86 .Fn makecontext
87 and determines the action to take when
88 .Fn func
89 returns:
90 if equal to
91 .Dv NULL ,
92 the process exits;
93 otherwise,
94 .Fn setcontext "ucp->uc_link"
95 is implicitly invoked.
96 .Pp
97 The
98 .Fn swapcontext
99 function
100 saves the current thread context in
101 .Fa "*oucp"
102 and makes
103 .Fa "*ucp"
104 the currently active context.
105 .Sh RETURN VALUES
106 If successful,
107 .Fn swapcontext
108 returns zero;
109 otherwise \-1 is returned and the global variable
110 .Va errno
111 is set appropriately.
112 .Sh ERRORS
113 The
114 .Fn swapcontext
115 function
116 will fail if:
117 .Bl -tag -width Er
118 .It Bq Er ENOMEM
119 There is not enough stack space in
120 .Fa ucp
121 to complete the operation.
122 .El
123 .Sh SEE ALSO
124 .Xr setcontext 3 ,
125 .Xr ucontext 3