xref: /freebsd/lib/libc/gen/makecontext.3 (revision 304d1f73fe42cfcdd62440886708ff6b79c6975a)
1a892767bSArchie Cobbs.\" Copyright (c) 2002 Packet Design, LLC.
2a892767bSArchie Cobbs.\" All rights reserved.
3a892767bSArchie Cobbs.\"
4a892767bSArchie Cobbs.\" Subject to the following obligations and disclaimer of warranty,
5a892767bSArchie Cobbs.\" use and redistribution of this software, in source or object code
6a892767bSArchie Cobbs.\" forms, with or without modifications are expressly permitted by
7a892767bSArchie Cobbs.\" Packet Design; provided, however, that:
8a892767bSArchie Cobbs.\"
9a892767bSArchie Cobbs.\"    (i)  Any and all reproductions of the source or object code
10a892767bSArchie Cobbs.\"         must include the copyright notice above and the following
11a892767bSArchie Cobbs.\"         disclaimer of warranties; and
12a892767bSArchie Cobbs.\"    (ii) No rights are granted, in any manner or form, to use
13a892767bSArchie Cobbs.\"         Packet Design trademarks, including the mark "PACKET DESIGN"
14a892767bSArchie Cobbs.\"         on advertising, endorsements, or otherwise except as such
15a892767bSArchie Cobbs.\"         appears in the above copyright notice or in the software.
16a892767bSArchie Cobbs.\"
17a892767bSArchie Cobbs.\" THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
18a892767bSArchie Cobbs.\" TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
19a892767bSArchie Cobbs.\" REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
20a892767bSArchie Cobbs.\" THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
21a892767bSArchie Cobbs.\" WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
22a892767bSArchie Cobbs.\" OR NON-INFRINGEMENT.  PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
23a892767bSArchie Cobbs.\" OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
24a892767bSArchie Cobbs.\" OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
25a892767bSArchie Cobbs.\" RELIABILITY OR OTHERWISE.  IN NO EVENT SHALL PACKET DESIGN BE
26a892767bSArchie Cobbs.\" LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
27a892767bSArchie Cobbs.\" OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
28a892767bSArchie Cobbs.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
29a892767bSArchie Cobbs.\" DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
30a892767bSArchie Cobbs.\" USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
31a892767bSArchie Cobbs.\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32a892767bSArchie Cobbs.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
33a892767bSArchie Cobbs.\" THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
34a892767bSArchie Cobbs.\" THE POSSIBILITY OF SUCH DAMAGE.
35a892767bSArchie Cobbs.\"
36a892767bSArchie Cobbs.\" $FreeBSD$
37a892767bSArchie Cobbs.\"
38304d1f73SRuslan Ermilov.Dd September 10, 2002
39a892767bSArchie Cobbs.Dt MAKECONTEXT 3
40a892767bSArchie Cobbs.Os
41a892767bSArchie Cobbs.Sh NAME
42304d1f73SRuslan Ermilov.Nm makecontext , swapcontext
43a892767bSArchie Cobbs.Nd modify and exchange user thread contexts
44a892767bSArchie Cobbs.Sh LIBRARY
45a892767bSArchie Cobbs.Lb libc
46a892767bSArchie Cobbs.Sh SYNOPSIS
47a892767bSArchie Cobbs.In ucontext.h
48a892767bSArchie Cobbs.Ft void
49304d1f73SRuslan Ermilov.Fo makecontext
50304d1f73SRuslan Ermilov.Fa "ucontext_t *ucp"
51304d1f73SRuslan Ermilov.Fa "void \*[lp]*func\*[rp]\*[lp]void\*[rp]"
52304d1f73SRuslan Ermilov.Fa "int argc" ...
53304d1f73SRuslan Ermilov.Fc
54a892767bSArchie Cobbs.Ft int
55a892767bSArchie Cobbs.Fn swapcontext "ucontext_t *oucp" "const ucontext_t *ucp"
56a892767bSArchie Cobbs.Sh DESCRIPTION
57a892767bSArchie Cobbs.Fn makecontext
58a892767bSArchie Cobbsmodifies the user thread context pointed to by
59a892767bSArchie Cobbs.Fa ucp ,
60a892767bSArchie Cobbswhich must have previously been initialized by a call to
61304d1f73SRuslan Ermilov.Xr getcontext 3
62a892767bSArchie Cobbsand had a stack allocated for it.
63a892767bSArchie CobbsThe context is modified so that it will continue execution by invoking
64a892767bSArchie Cobbs.Fn func
65a892767bSArchie Cobbswith the arguments provided.
66a892767bSArchie Cobbs.Fa argc
67a892767bSArchie Cobbsmust be equal to the number of additional arguments provided to
68a892767bSArchie Cobbs.Fn makecontext
69a892767bSArchie Cobbsand also equal to the number of parameters to
70a892767bSArchie Cobbs.Fn func ,
71a892767bSArchie Cobbsor else the behavior is undefined.
72a892767bSArchie Cobbs.Pp
73a892767bSArchie Cobbs.Fa "ucp->uc_link"
74a892767bSArchie Cobbsmust be initialized before calling
75a892767bSArchie Cobbs.Fn makecontext
76a892767bSArchie Cobbsand determines the action to take when
77a892767bSArchie Cobbs.Fn func
78a892767bSArchie Cobbsreturns:
79a892767bSArchie Cobbsif equal to
80a892767bSArchie Cobbs.Dv NULL ,
81a892767bSArchie Cobbsthe process exits;
82a892767bSArchie Cobbsotherwise,
83a892767bSArchie Cobbs.Fn setcontext "ucp->uc_link"
84a892767bSArchie Cobbsis implicitly invoked.
85a892767bSArchie Cobbs.Pp
86a892767bSArchie Cobbs.Fn swapcontext
87a892767bSArchie Cobbssaves the current thread context in
88a892767bSArchie Cobbs.Fa "*oucp"
89a892767bSArchie Cobbsand makes
90a892767bSArchie Cobbs.Fa "*ucp"
91a892767bSArchie Cobbsthe currently active context.
92a892767bSArchie Cobbs.Sh RETURN VALUES
93a892767bSArchie CobbsIf successful,
94a892767bSArchie Cobbs.Fn swapcontext
95a892767bSArchie Cobbsreturns zero;
96304d1f73SRuslan Ermilovotherwise \-1 is returned and the global variable
97a892767bSArchie Cobbs.Va errno
98a892767bSArchie Cobbsis set appropriately.
99a892767bSArchie Cobbs.Sh ERRORS
100a892767bSArchie Cobbs.Fn swapcontext
101a892767bSArchie Cobbswill fail if:
102a892767bSArchie Cobbs.Bl -tag -width Er
103a892767bSArchie Cobbs.It Bq Er ENOMEM
104a892767bSArchie CobbsThere is not enough stack space in
105a892767bSArchie Cobbs.Fa ucp
106a892767bSArchie Cobbsto complete the operation.
107a892767bSArchie Cobbs.El
108a892767bSArchie Cobbs.Sh SEE ALSO
109a892767bSArchie Cobbs.Xr setcontext 3 ,
110a892767bSArchie Cobbs.Xr ucontext 3
111