xref: /netbsd-src/lib/libc/sys/getcontext.2 (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1.\"	$NetBSD: getcontext.2,v 1.4 2003/04/16 16:09:04 wiz Exp $
2.\"
3.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Klaus Klein.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"        This product includes software developed by the NetBSD
20.\"        Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.Dd October 28, 1999
38.Dt GETCONTEXT 2
39.Os
40.Sh NAME
41.Nm getcontext ,
42.Nm setcontext
43.Nd get and set current user context
44.Sh LIBRARY
45.Lb libc
46.Sh SYNOPSIS
47.In ucontext.h
48.Ft int
49.Fn getcontext "ucontext_t *ucp"
50.Ft int
51.Fn setcontext "const ucontext_t *ucp"
52.Sh DESCRIPTION
53The
54.Fn getcontext
55function initializes the object pointed to by
56.Fa ucp
57to the current user context of the calling thread.
58The user context defines a thread's execution environment and includes
59the contents of its machine registers,
60its signal mask,
61and its current execution stack.
62.Pp
63The
64.Fn setcontext
65function restores the user context defined in the object pointed to by
66.Fa ucp
67as most recently initialized by a previous call to either
68.Fn getcontext
69or
70.Xr makecontext 3 .
71.\" TODO: signal handler
72If successful, execution of the program resumes as defined in the
73.Fa ucp
74argument, and
75.Fn setcontext
76will not return.
77If
78.Fa ucp
79was initialized by the
80.Fn getcontext
81function, program execution continues as if the corresponding invocation of
82.Fn getcontext
83had just returned (successfully).
84If
85.Fa ucp
86was initialized by the
87.Xr makecontext 3
88function, program execution continues with the function (and function
89arguments) passed to
90.Xr makecontext 3 .
91.Sh RETURN VALUES
92On successful completion,
93.Fn getcontext
94returns 0 and
95.Fn setcontext
96does not return.
97Otherwise a value of \-1 is returned and
98.Va errno
99is set to indicate the error.
100.Sh ERRORS
101The
102.Fn getcontext
103and
104.Fn setcontext
105functions will fail if:
106.Bl -tag -width Er
107.It Bq Er EFAULT
108The
109.Fa ucp
110argument points to an invalid address.
111.El
112.Pp
113The
114.Fn setcontext
115function will fail if:
116.Bl -tag -width Er
117.It Bq Er EINVAL
118The contents of the datum pointed to by
119.Fa ucp
120are invalid.
121.El
122.Sh SEE ALSO
123.Xr sigprocmask 2 ,
124.Xr longjmp 3 ,
125.Xr makecontext 3 ,
126.Xr setjmp 3 ,
127.Xr swapcontext 3
128.Sh STANDARDS
129The
130.Fn getcontext
131and
132.Fn setcontext
133functions conform to
134.St -xsh5 .
135The
136.Va errno
137indications are an extension to the standard.
138.Sh HISTORY
139The
140.Fn getcontext
141and
142.Fn setcontext
143functions first appeared in
144.At V.4 .
145