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.Dd March 23, 2020 37.Dt MAKECONTEXT 3 38.Os 39.Sh NAME 40.Nm makecontext , swapcontext 41.Nd modify and exchange user thread contexts 42.Sh LIBRARY 43.Lb libc 44.Sh SYNOPSIS 45.In ucontext.h 46.Ft void 47.Fo makecontext 48.Fa "ucontext_t *ucp" 49.Fa "void \*[lp]*func\*[rp]\*[lp]void\*[rp]" 50.Fa "int argc" ... 51.Fc 52.Ft int 53.Fn swapcontext "ucontext_t *oucp" "const ucontext_t *ucp" 54.Sh DESCRIPTION 55The 56.Fn makecontext 57function 58modifies the user thread context pointed to by 59.Fa ucp , 60which must have previously been initialized by a call to 61.Xr getcontext 3 62and had a stack allocated for it. 63The context is modified so that it will continue execution by invoking 64.Fn func 65with the arguments provided. 66The 67.Fa argc 68argument 69must be equal to the number of additional arguments of type 70.Vt int 71provided to 72.Fn makecontext 73and also equal to the number of arguments of type 74.Vt int 75to 76.Fn func ; 77otherwise , 78the behavior is undefined. 79.Pp 80The 81.Fa "ucp->uc_link" 82argument 83must be initialized before calling 84.Fn makecontext 85and determines the action to take when 86.Fn func 87returns: 88if equal to 89.Dv NULL , 90the process exits; 91otherwise, 92.Fn setcontext "ucp->uc_link" 93is implicitly invoked. 94.Pp 95The 96.Fn swapcontext 97function 98saves the current thread context in 99.Fa "*oucp" 100and makes 101.Fa "*ucp" 102the currently active context. 103.Sh RETURN VALUES 104If successful, 105.Fn swapcontext 106returns zero; 107otherwise \-1 is returned and the global variable 108.Va errno 109is set appropriately. 110.Sh ERRORS 111The 112.Fn swapcontext 113function 114will fail if: 115.Bl -tag -width Er 116.It Bq Er ENOMEM 117There is not enough stack space in 118.Fa ucp 119to complete the operation. 120.El 121.Sh SEE ALSO 122.Xr setcontext 3 , 123.Xr ucontext 3 124.Sh STANDARDS 125The 126.Fn makecontext 127and 128.Fn swapcontext 129functions conform to 130.St -xsh5 131and 132.St -p1003.1-2001 . 133.Pp 134The 135.St -p1003.1-2004 136revision marked the functions 137.Fn makecontext 138and 139.Fn swapcontext 140as obsolete, citing portability issues and recommending the use of 141.Tn POSIX 142threads instead. 143The 144.St -p1003.1-2008 145revision removed the functions from the specification. 146.Pp 147.Bf -symbolic 148The standard does not clearly define the type of integer arguments 149passed to 150.Fa func 151via 152.Fn makecontext ; 153portable applications should not rely on the implementation detail that 154it may be possible to pass pointer arguments to functions. 155.Sh HISTORY 156The 157.Fn makecontext 158and 159.Fn swapcontext 160functions first appeared in 161.At V.4 . 162