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