Index: head/lib/libc/gen/getcontext.3 =================================================================== --- head/lib/libc/gen/getcontext.3 (revision 359247) +++ head/lib/libc/gen/getcontext.3 (revision 359248) @@ -1,150 +1,182 @@ .\" Copyright (c) 2002 Packet Design, LLC. .\" All rights reserved. .\" .\" Subject to the following obligations and disclaimer of warranty, .\" use and redistribution of this software, in source or object code .\" forms, with or without modifications are expressly permitted by .\" Packet Design; provided, however, that: .\" .\" (i) Any and all reproductions of the source or object code .\" must include the copyright notice above and the following .\" disclaimer of warranties; and .\" (ii) No rights are granted, in any manner or form, to use .\" Packet Design trademarks, including the mark "PACKET DESIGN" .\" on advertising, endorsements, or otherwise except as such .\" appears in the above copyright notice or in the software. .\" .\" THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND .\" TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO .\" REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING .\" THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED .\" WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, .\" OR NON-INFRINGEMENT. PACKET DESIGN DOES NOT WARRANT, GUARANTEE, .\" OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS .\" OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, .\" RELIABILITY OR OTHERWISE. IN NO EVENT SHALL PACKET DESIGN BE .\" LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE .\" OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT, .\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL .\" DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF .\" USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF .\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF .\" THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF .\" THE POSSIBILITY OF SUCH DAMAGE. .\" .\" $FreeBSD$ .\" -.Dd March 13, 2013 +.Dd March 23, 2020 .Dt GETCONTEXT 3 .Os .Sh NAME .Nm getcontext , getcontextx , setcontext .Nd get and set user thread context .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In ucontext.h .Ft int .Fn getcontext "ucontext_t *ucp" .Ft ucontext_t * .Fn getcontextx "void" .Ft int .Fn setcontext "const ucontext_t *ucp" .Sh DESCRIPTION The .Fn getcontext function saves the current thread's execution context in the structure pointed to by .Fa ucp . This saved context may then later be restored by calling .Fn setcontext . .Pp The .Fn getcontextx function saves the current execution context in the newly allocated structure .Vt ucontext_t , which is returned on success. If architecture defines additional CPU states that can be stored in extended blocks referenced from the .Vt ucontext_t , the memory for them may be allocated and their context also stored. Memory returned by .Fn getcontextx function shall be freed using .Fn free 3 . .Pp The .Fn setcontext function makes a previously saved thread context the current thread context, i.e., the current context is lost and .Fn setcontext does not return. Instead, execution continues in the context specified by .Fa ucp , which must have been previously initialized by a call to .Fn getcontext , .Xr makecontext 3 , or by being passed as an argument to a signal handler (see .Xr sigaction 2 ) . .Pp If .Fa ucp was initialized by .Fn getcontext , then execution continues as if the original .Fn getcontext call had just returned (again). .Pp If .Fa ucp was initialized by .Xr makecontext 3 , execution continues with the invocation of the function specified to .Xr makecontext 3 . When that function returns, .Fa "ucp->uc_link" determines what happens next: if .Fa "ucp->uc_link" is .Dv NULL , the process exits; otherwise, .Fn setcontext "ucp->uc_link" is implicitly invoked. .Pp If .Fa ucp was initialized by the invocation of a signal handler, execution continues at the point the thread was interrupted by the signal. .Sh RETURN VALUES If successful, .Fn getcontext returns zero and .Fn setcontext does not return; otherwise \-1 is returned. The .Fn getcontextx returns pointer to the allocated and initialized context on success, and .Va NULL on failure. .Sh ERRORS No errors are defined for .Fn getcontext or .Fn setcontext . The .Fn getcontextx may return the following errors in .Va errno : .Bl -tag -width Er .It Bq Er ENOMEM No memory was available to allocate for the context or some extended state. .El .Sh SEE ALSO .Xr sigaction 2 , .Xr sigaltstack 2 , .Xr makecontext 3 , .Xr ucontext 3 +.Sh STANDARDS +The +.Fn getcontext +and +.Fn setcontext +functions conform to +.St -xsh5 +and +.St -p1003.1-2001 . +The +.Va errno +indications are an extension to the standard. +.Pp +The +.St -p1003.1-2004 +revision marked the functions +.Fn getcontext +and +.Fn setcontext +as obsolete, citing portability issues and recommending the use of +.Tn POSIX +threads instead. +The +.St -p1003.1-2008 +revision removed the functions from the specification. +.Sh HISTORY +The +.Fn getcontext +and +.Fn setcontext +functions first appeared in +.At V.4 . Index: head/lib/libc/gen/makecontext.3 =================================================================== --- head/lib/libc/gen/makecontext.3 (revision 359247) +++ head/lib/libc/gen/makecontext.3 (revision 359248) @@ -1,125 +1,163 @@ .\" Copyright (c) 2002 Packet Design, LLC. .\" All rights reserved. .\" .\" Subject to the following obligations and disclaimer of warranty, .\" use and redistribution of this software, in source or object code .\" forms, with or without modifications are expressly permitted by .\" Packet Design; provided, however, that: .\" .\" (i) Any and all reproductions of the source or object code .\" must include the copyright notice above and the following .\" disclaimer of warranties; and .\" (ii) No rights are granted, in any manner or form, to use .\" Packet Design trademarks, including the mark "PACKET DESIGN" .\" on advertising, endorsements, or otherwise except as such .\" appears in the above copyright notice or in the software. .\" .\" THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND .\" TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO .\" REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING .\" THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED .\" WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, .\" OR NON-INFRINGEMENT. PACKET DESIGN DOES NOT WARRANT, GUARANTEE, .\" OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS .\" OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, .\" RELIABILITY OR OTHERWISE. IN NO EVENT SHALL PACKET DESIGN BE .\" LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE .\" OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT, .\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL .\" DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF .\" USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF .\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF .\" THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF .\" THE POSSIBILITY OF SUCH DAMAGE. .\" .\" $FreeBSD$ .\" -.Dd January 31, 2018 +.Dd March 23, 2020 .Dt MAKECONTEXT 3 .Os .Sh NAME .Nm makecontext , swapcontext .Nd modify and exchange user thread contexts .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In ucontext.h .Ft void .Fo makecontext .Fa "ucontext_t *ucp" .Fa "void \*[lp]*func\*[rp]\*[lp]void\*[rp]" .Fa "int argc" ... .Fc .Ft int .Fn swapcontext "ucontext_t *oucp" "const ucontext_t *ucp" .Sh DESCRIPTION The .Fn makecontext function modifies the user thread context pointed to by .Fa ucp , which must have previously been initialized by a call to .Xr getcontext 3 and had a stack allocated for it. The context is modified so that it will continue execution by invoking .Fn func with the arguments provided. The .Fa argc argument must be equal to the number of additional arguments of type .Vt int provided to .Fn makecontext and also equal to the number of arguments of type .Vt int to .Fn func ; otherwise , the behavior is undefined. .Pp The .Fa "ucp->uc_link" argument must be initialized before calling .Fn makecontext and determines the action to take when .Fn func returns: if equal to .Dv NULL , the process exits; otherwise, .Fn setcontext "ucp->uc_link" is implicitly invoked. .Pp The .Fn swapcontext function saves the current thread context in .Fa "*oucp" and makes .Fa "*ucp" the currently active context. .Sh RETURN VALUES If successful, .Fn swapcontext returns zero; otherwise \-1 is returned and the global variable .Va errno is set appropriately. .Sh ERRORS The .Fn swapcontext function will fail if: .Bl -tag -width Er .It Bq Er ENOMEM There is not enough stack space in .Fa ucp to complete the operation. .El .Sh SEE ALSO .Xr setcontext 3 , .Xr ucontext 3 +.Sh STANDARDS +The +.Fn makecontext +and +.Fn swapcontext +functions conform to +.St -xsh5 +and +.St -p1003.1-2001 . +.Pp +The +.St -p1003.1-2004 +revision marked the functions +.Fn makecontext +and +.Fn swapcontext +as obsolete, citing portability issues and recommending the use of +.Tn POSIX +threads instead. +The +.St -p1003.1-2008 +revision removed the functions from the specification. +.Pp +.Bf -symbolic +The standard does not clearly define the type of integer arguments +passed to +.Fa func +via +.Fn makecontext ; +portable applications should not rely on the implementation detail that +it may be possible to pass pointer arguments to functions. +.Sh HISTORY +The +.Fn makecontext +and +.Fn swapcontext +functions first appeared in +.At V.4 . Index: head/lib/libc/gen/ucontext.3 =================================================================== --- head/lib/libc/gen/ucontext.3 (revision 359247) +++ head/lib/libc/gen/ucontext.3 (revision 359248) @@ -1,111 +1,123 @@ .\" Copyright (c) 2002 Packet Design, LLC. .\" All rights reserved. .\" .\" Subject to the following obligations and disclaimer of warranty, .\" use and redistribution of this software, in source or object code .\" forms, with or without modifications are expressly permitted by .\" Packet Design; provided, however, that: .\" .\" (i) Any and all reproductions of the source or object code .\" must include the copyright notice above and the following .\" disclaimer of warranties; and .\" (ii) No rights are granted, in any manner or form, to use .\" Packet Design trademarks, including the mark "PACKET DESIGN" .\" on advertising, endorsements, or otherwise except as such .\" appears in the above copyright notice or in the software. .\" .\" THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND .\" TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO .\" REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING .\" THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED .\" WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, .\" OR NON-INFRINGEMENT. PACKET DESIGN DOES NOT WARRANT, GUARANTEE, .\" OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS .\" OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, .\" RELIABILITY OR OTHERWISE. IN NO EVENT SHALL PACKET DESIGN BE .\" LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE .\" OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT, .\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL .\" DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF .\" USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF .\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF .\" THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF .\" THE POSSIBILITY OF SUCH DAMAGE. .\" .\" $FreeBSD$ .\" -.Dd September 10, 2002 +.Dd March 23, 2020 .Dt UCONTEXT 3 .Os .Sh NAME .Nm ucontext .Nd user thread context .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In ucontext.h .Sh DESCRIPTION The .Vt ucontext_t type is a structure type suitable for holding the context for a user thread of execution. A thread's context includes its stack, saved registers, and list of blocked signals. .Pp The .Vt ucontext_t structure contains at least these fields: .Pp .Bl -tag -width ".Va mcontext_t\ \ uc_mcontext" -offset 3n -compact .It Va "ucontext_t *uc_link" context to assume when this one returns .It Va "sigset_t uc_sigmask" signals being blocked .It Va "stack_t uc_stack" stack area .It Va "mcontext_t uc_mcontext" saved registers .El .Pp The .Va uc_link field points to the context to resume when this context's entry point function returns. If .Va uc_link is equal to .Dv NULL , then the process exits when this context returns. .Pp The .Va uc_mcontext field is machine-dependent and should be treated as opaque by portable applications. .Pp The following functions are defined to manipulate .Vt ucontext_t structures: .Pp .Bl -item -offset 3n -compact .It .Ft int .Fn getcontext "ucontext_t *" ; .It .Ft "ucontext_t *" .Fn getcontextx "void" ; .It .Ft int .Fn setcontext "const ucontext_t *" ; .It .Ft void .Fn makecontext "ucontext_t *" "void \*[lp]*\*[rp]\*[lp]void\*[rp]" int ... ; .It .Ft int .Fn swapcontext "ucontext_t *" "const ucontext_t *" ; .El .Sh SEE ALSO .Xr sigaltstack 2 , .Xr getcontext 3 , .Xr getcontextx 3 , .Xr makecontext 3 +.Sh STANDARDS +The +.Vt ucontext_t +type conforms to +.St -xsh5 +and +.St -p1003.1-2001 . +The +.St -p1003.1-2008 +revision removed the +.Vt ucontext_t +from the specification.