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