xref: /dflybsd-src/lib/libc/gen/getcontext.3 (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino.\" Copyright (c) 2002 Packet Design, LLC.
286d7f5d3SJohn Marino.\" All rights reserved.
386d7f5d3SJohn Marino.\"
486d7f5d3SJohn Marino.\" Subject to the following obligations and disclaimer of warranty,
586d7f5d3SJohn Marino.\" use and redistribution of this software, in source or object code
686d7f5d3SJohn Marino.\" forms, with or without modifications are expressly permitted by
786d7f5d3SJohn Marino.\" Packet Design; provided, however, that:
886d7f5d3SJohn Marino.\"
986d7f5d3SJohn Marino.\"    (i)  Any and all reproductions of the source or object code
1086d7f5d3SJohn Marino.\"         must include the copyright notice above and the following
1186d7f5d3SJohn Marino.\"         disclaimer of warranties; and
1286d7f5d3SJohn Marino.\"    (ii) No rights are granted, in any manner or form, to use
1386d7f5d3SJohn Marino.\"         Packet Design trademarks, including the mark "PACKET DESIGN"
1486d7f5d3SJohn Marino.\"         on advertising, endorsements, or otherwise except as such
1586d7f5d3SJohn Marino.\"         appears in the above copyright notice or in the software.
1686d7f5d3SJohn Marino.\"
1786d7f5d3SJohn Marino.\" THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
1886d7f5d3SJohn Marino.\" TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
1986d7f5d3SJohn Marino.\" REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
2086d7f5d3SJohn Marino.\" THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
2186d7f5d3SJohn Marino.\" WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
2286d7f5d3SJohn Marino.\" OR NON-INFRINGEMENT.  PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
2386d7f5d3SJohn Marino.\" OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
2486d7f5d3SJohn Marino.\" OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
2586d7f5d3SJohn Marino.\" RELIABILITY OR OTHERWISE.  IN NO EVENT SHALL PACKET DESIGN BE
2686d7f5d3SJohn Marino.\" LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
2786d7f5d3SJohn Marino.\" OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
2886d7f5d3SJohn Marino.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
2986d7f5d3SJohn Marino.\" DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
3086d7f5d3SJohn Marino.\" USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
3186d7f5d3SJohn Marino.\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3286d7f5d3SJohn Marino.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
3386d7f5d3SJohn Marino.\" THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
3486d7f5d3SJohn Marino.\" THE POSSIBILITY OF SUCH DAMAGE.
3586d7f5d3SJohn Marino.\"
3686d7f5d3SJohn Marino.\" $FreeBSD: src/lib/libc/gen/getcontext.3,v 1.3 2004/12/03 14:10:04 rse Exp $
3786d7f5d3SJohn Marino.\" $DragonFly: src/lib/libc/gen/getcontext.3,v 1.1 2007/01/16 07:16:23 dillon Exp $
3886d7f5d3SJohn Marino.\"
3986d7f5d3SJohn Marino.Dd September 10, 2002
4086d7f5d3SJohn Marino.Dt GETCONTEXT 3
4186d7f5d3SJohn Marino.Os
4286d7f5d3SJohn Marino.Sh NAME
4386d7f5d3SJohn Marino.Nm getcontext , setcontext
4486d7f5d3SJohn Marino.Nd get and set user thread context
4586d7f5d3SJohn Marino.Sh LIBRARY
4686d7f5d3SJohn Marino.Lb libc
4786d7f5d3SJohn Marino.Sh SYNOPSIS
4886d7f5d3SJohn Marino.In ucontext.h
4986d7f5d3SJohn Marino.Ft int
5086d7f5d3SJohn Marino.Fn getcontext "ucontext_t *ucp"
5186d7f5d3SJohn Marino.Ft int
5286d7f5d3SJohn Marino.Fn setcontext "const ucontext_t *ucp"
5386d7f5d3SJohn Marino.Sh DESCRIPTION
5486d7f5d3SJohn MarinoThe
5586d7f5d3SJohn Marino.Fn getcontext
5686d7f5d3SJohn Marinofunction
5786d7f5d3SJohn Marinosaves the current thread's execution context in the structure pointed to by
5886d7f5d3SJohn Marino.Fa ucp .
5986d7f5d3SJohn MarinoThis saved context may then later be restored by calling
6086d7f5d3SJohn Marino.Fn setcontext .
6186d7f5d3SJohn Marino.Pp
6286d7f5d3SJohn MarinoThe
6386d7f5d3SJohn Marino.Fn setcontext
6486d7f5d3SJohn Marinofunction
6586d7f5d3SJohn Marinomakes a previously saved thread context the current thread context, i.e.,
6686d7f5d3SJohn Marinothe current context is lost and
6786d7f5d3SJohn Marino.Fn setcontext
6886d7f5d3SJohn Marinodoes not return.
6986d7f5d3SJohn MarinoInstead, execution continues in the context specified by
7086d7f5d3SJohn Marino.Fa ucp ,
7186d7f5d3SJohn Marinowhich must have been previously initialized by a call to
7286d7f5d3SJohn Marino.Fn getcontext ,
7386d7f5d3SJohn Marino.Xr makecontext 3 ,
7486d7f5d3SJohn Marinoor by being passed as an argument to a signal handler (see
7586d7f5d3SJohn Marino.Xr sigaction 2 ) .
7686d7f5d3SJohn Marino.Pp
7786d7f5d3SJohn MarinoIf
7886d7f5d3SJohn Marino.Fa ucp
7986d7f5d3SJohn Marinowas initialized by
8086d7f5d3SJohn Marino.Fn getcontext ,
8186d7f5d3SJohn Marinothen execution continues as if the original
8286d7f5d3SJohn Marino.Fn getcontext
8386d7f5d3SJohn Marinocall had just returned (again).
8486d7f5d3SJohn Marino.Pp
8586d7f5d3SJohn MarinoIf
8686d7f5d3SJohn Marino.Fa ucp
8786d7f5d3SJohn Marinowas initialized by
8886d7f5d3SJohn Marino.Xr makecontext 3 ,
8986d7f5d3SJohn Marinoexecution continues with the invocation of the function specified to
9086d7f5d3SJohn Marino.Xr makecontext 3 .
9186d7f5d3SJohn MarinoWhen that function returns,
9286d7f5d3SJohn Marino.Fa "ucp->uc_link"
9386d7f5d3SJohn Marinodetermines what happens next:
9486d7f5d3SJohn Marinoif
9586d7f5d3SJohn Marino.Fa "ucp->uc_link"
9686d7f5d3SJohn Marinois
9786d7f5d3SJohn Marino.Dv NULL ,
9886d7f5d3SJohn Marinothe process exits;
9986d7f5d3SJohn Marinootherwise,
10086d7f5d3SJohn Marino.Fn setcontext "ucp->uc_link"
10186d7f5d3SJohn Marinois implicitly invoked.
10286d7f5d3SJohn Marino.Pp
10386d7f5d3SJohn MarinoIf
10486d7f5d3SJohn Marino.Fa ucp
10586d7f5d3SJohn Marinowas initialized by the invocation of a signal handler, execution continues
10686d7f5d3SJohn Marinoat the point the thread was interrupted by the signal.
10786d7f5d3SJohn Marino.Sh RETURN VALUES
10886d7f5d3SJohn MarinoIf successful,
10986d7f5d3SJohn Marino.Fn getcontext
11086d7f5d3SJohn Marinoreturns zero and
11186d7f5d3SJohn Marino.Fn setcontext
11286d7f5d3SJohn Marinodoes not return; otherwise \-1 is returned.
11386d7f5d3SJohn Marino.Sh ERRORS
11486d7f5d3SJohn MarinoNo errors are defined for
11586d7f5d3SJohn Marino.Fn getcontext
11686d7f5d3SJohn Marinoor
11786d7f5d3SJohn Marino.Fn setcontext .
11886d7f5d3SJohn Marino.Sh SEE ALSO
11986d7f5d3SJohn Marino.Xr sigaction 2 ,
12086d7f5d3SJohn Marino.Xr sigaltstack 2 ,
12186d7f5d3SJohn Marino.Xr makecontext 3 ,
12286d7f5d3SJohn Marino.Xr ucontext 3
123