xref: /freebsd/lib/libc/gen/makecontext.3 (revision a892767bc417eaeb25bb5be421237cbfb716c20b)
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 Sep 10, 2002
39.Dt MAKECONTEXT 3
40.Os
41.Sh NAME
42.Nm makecontext
43.Nm 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.Fn makecontext "ucontext_t *ucp" "void (*func)()" "int argc" "..."
51.Ft int
52.Fn swapcontext "ucontext_t *oucp" "const ucontext_t *ucp"
53.Sh DESCRIPTION
54.Fn makecontext
55modifies the user thread context pointed to by
56.Fa ucp ,
57which must have previously been initialized by a call to
58.Fn getcontext
59and had a stack allocated for it.
60The context is modified so that it will continue execution by invoking
61.Fn func
62with the arguments provided.
63.Fa argc
64must be equal to the number of additional arguments provided to
65.Fn makecontext
66and also equal to the number of parameters to
67.Fn func ,
68or else the behavior is undefined.
69.Pp
70.Fa "ucp->uc_link"
71must be initialized before calling
72.Fn makecontext
73and determines the action to take when
74.Fn func
75returns:
76if equal to
77.Dv NULL ,
78the process exits;
79otherwise,
80.Fn setcontext "ucp->uc_link"
81is implicitly invoked.
82.Pp
83.Fn swapcontext
84saves the current thread context in
85.Fa "*oucp"
86and makes
87.Fa "*ucp"
88the currently active context.
89.Sh RETURN VALUES
90If successful,
91.Fn swapcontext
92returns zero;
93otherwise -1 is returned and
94.Va errno
95is set appropriately.
96.Sh ERRORS
97.Fn swapcontext
98will fail if:
99.Bl -tag -width Er
100.It Bq Er ENOMEM
101There is not enough stack space in
102.Fa ucp
103to complete the operation.
104.El
105.Sh SEE ALSO
106.Xr setcontext 3 ,
107.Xr ucontext 3
108