xref: /freebsd/lib/libc/gen/makecontext.3 (revision d21e322d563e0fd1f92c22205c2ced4bcd22dc23)
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.\"
36868983b0SEdward Tomasz Napierala.Dd March 23, 2020
37a892767bSArchie Cobbs.Dt MAKECONTEXT 3
38a892767bSArchie Cobbs.Os
39a892767bSArchie Cobbs.Sh NAME
40304d1f73SRuslan Ermilov.Nm makecontext , swapcontext
41a892767bSArchie Cobbs.Nd modify and exchange user thread contexts
42a892767bSArchie Cobbs.Sh LIBRARY
43a892767bSArchie Cobbs.Lb libc
44a892767bSArchie Cobbs.Sh SYNOPSIS
45a892767bSArchie Cobbs.In ucontext.h
46a892767bSArchie Cobbs.Ft void
47304d1f73SRuslan Ermilov.Fo makecontext
48304d1f73SRuslan Ermilov.Fa "ucontext_t *ucp"
49304d1f73SRuslan Ermilov.Fa "void \*[lp]*func\*[rp]\*[lp]void\*[rp]"
50304d1f73SRuslan Ermilov.Fa "int argc" ...
51304d1f73SRuslan Ermilov.Fc
52a892767bSArchie Cobbs.Ft int
53a892767bSArchie Cobbs.Fn swapcontext "ucontext_t *oucp" "const ucontext_t *ucp"
54a892767bSArchie Cobbs.Sh DESCRIPTION
5595f4226bSRuslan ErmilovThe
56a892767bSArchie Cobbs.Fn makecontext
5795f4226bSRuslan Ermilovfunction
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.
662efeeba5SRuslan ErmilovThe
67a892767bSArchie Cobbs.Fa argc
682efeeba5SRuslan Ermilovargument
697193311bSJohn Baldwinmust be equal to the number of additional arguments of type
707193311bSJohn Baldwin.Vt int
717193311bSJohn Baldwinprovided to
72a892767bSArchie Cobbs.Fn makecontext
737193311bSJohn Baldwinand also equal to the number of arguments of type
747193311bSJohn Baldwin.Vt int
757193311bSJohn Baldwinto
767193311bSJohn Baldwin.Fn func ;
777193311bSJohn Baldwinotherwise ,
787193311bSJohn Baldwinthe behavior is undefined.
79a892767bSArchie Cobbs.Pp
802efeeba5SRuslan ErmilovThe
81a892767bSArchie Cobbs.Fa "ucp->uc_link"
822efeeba5SRuslan Ermilovargument
83a892767bSArchie Cobbsmust be initialized before calling
84a892767bSArchie Cobbs.Fn makecontext
85a892767bSArchie Cobbsand determines the action to take when
86a892767bSArchie Cobbs.Fn func
87a892767bSArchie Cobbsreturns:
88a892767bSArchie Cobbsif equal to
89a892767bSArchie Cobbs.Dv NULL ,
90a892767bSArchie Cobbsthe process exits;
91a892767bSArchie Cobbsotherwise,
92a892767bSArchie Cobbs.Fn setcontext "ucp->uc_link"
93a892767bSArchie Cobbsis implicitly invoked.
94a892767bSArchie Cobbs.Pp
9595f4226bSRuslan ErmilovThe
96a892767bSArchie Cobbs.Fn swapcontext
9795f4226bSRuslan Ermilovfunction
98a892767bSArchie Cobbssaves the current thread context in
99a892767bSArchie Cobbs.Fa "*oucp"
100a892767bSArchie Cobbsand makes
101a892767bSArchie Cobbs.Fa "*ucp"
102a892767bSArchie Cobbsthe currently active context.
103a892767bSArchie Cobbs.Sh RETURN VALUES
104a892767bSArchie CobbsIf successful,
105a892767bSArchie Cobbs.Fn swapcontext
106a892767bSArchie Cobbsreturns zero;
107304d1f73SRuslan Ermilovotherwise \-1 is returned and the global variable
108a892767bSArchie Cobbs.Va errno
109a892767bSArchie Cobbsis set appropriately.
110a892767bSArchie Cobbs.Sh ERRORS
11195f4226bSRuslan ErmilovThe
112a892767bSArchie Cobbs.Fn swapcontext
11395f4226bSRuslan Ermilovfunction
114a892767bSArchie Cobbswill fail if:
115a892767bSArchie Cobbs.Bl -tag -width Er
116a892767bSArchie Cobbs.It Bq Er ENOMEM
117a892767bSArchie CobbsThere is not enough stack space in
118a892767bSArchie Cobbs.Fa ucp
119a892767bSArchie Cobbsto complete the operation.
120a892767bSArchie Cobbs.El
121a892767bSArchie Cobbs.Sh SEE ALSO
122a892767bSArchie Cobbs.Xr setcontext 3 ,
123a892767bSArchie Cobbs.Xr ucontext 3
124868983b0SEdward Tomasz Napierala.Sh STANDARDS
125868983b0SEdward Tomasz NapieralaThe
126868983b0SEdward Tomasz Napierala.Fn makecontext
127868983b0SEdward Tomasz Napieralaand
128868983b0SEdward Tomasz Napierala.Fn swapcontext
129868983b0SEdward Tomasz Napieralafunctions conform to
130868983b0SEdward Tomasz Napierala.St -xsh5
131868983b0SEdward Tomasz Napieralaand
132868983b0SEdward Tomasz Napierala.St -p1003.1-2001 .
133868983b0SEdward Tomasz Napierala.Pp
134868983b0SEdward Tomasz NapieralaThe
135868983b0SEdward Tomasz Napierala.St -p1003.1-2004
136868983b0SEdward Tomasz Napieralarevision marked the functions
137868983b0SEdward Tomasz Napierala.Fn makecontext
138868983b0SEdward Tomasz Napieralaand
139868983b0SEdward Tomasz Napierala.Fn swapcontext
140868983b0SEdward Tomasz Napieralaas obsolete, citing portability issues and recommending the use of
141868983b0SEdward Tomasz Napierala.Tn POSIX
142868983b0SEdward Tomasz Napieralathreads instead.
143868983b0SEdward Tomasz NapieralaThe
144868983b0SEdward Tomasz Napierala.St -p1003.1-2008
145868983b0SEdward Tomasz Napieralarevision removed the functions from the specification.
146868983b0SEdward Tomasz Napierala.Pp
147868983b0SEdward Tomasz Napierala.Bf -symbolic
148868983b0SEdward Tomasz NapieralaThe standard does not clearly define the type of integer arguments
149868983b0SEdward Tomasz Napieralapassed to
150868983b0SEdward Tomasz Napierala.Fa func
151868983b0SEdward Tomasz Napieralavia
152868983b0SEdward Tomasz Napierala.Fn makecontext ;
153868983b0SEdward Tomasz Napieralaportable applications should not rely on the implementation detail that
154868983b0SEdward Tomasz Napieralait may be possible to pass pointer arguments to functions.
155*d21e322dSGraham Percival.Ef
156868983b0SEdward Tomasz Napierala.Sh HISTORY
157868983b0SEdward Tomasz NapieralaThe
158868983b0SEdward Tomasz Napierala.Fn makecontext
159868983b0SEdward Tomasz Napieralaand
160868983b0SEdward Tomasz Napierala.Fn swapcontext
161868983b0SEdward Tomasz Napieralafunctions first appeared in
162868983b0SEdward Tomasz Napierala.At V.4 .
163