2 .\" Copyright (C) 2001 Andries Brouwer (aeb@cwi.nl)
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .TH getcontext 3 (date) "Linux man-pages (unreleased)"
8 getcontext, setcontext \- get or set the user context
11 .RI ( libc ", " \-lc )
14 .B #include <ucontext.h>
16 .BI "int getcontext(ucontext_t *" ucp );
17 .BI "int setcontext(const ucontext_t *" ucp );
20 In a System V-like environment, one has the two types
26 and the four functions
32 that allow user-level context switching between multiple
33 threads of control within a process.
37 type is machine-dependent and opaque.
40 type is a structure that has at least
45 typedef struct ucontext_t {
46 struct ucontext_t *uc_link;
49 mcontext_t uc_mcontext;
63 points to the context that will be resumed
64 when the current context terminates (in case the current context
69 set of signals blocked in this context (see
72 is the stack used by this context (see
77 machine-specific representation of the saved context,
78 that includes the calling thread's machine registers.
82 initializes the structure
85 to the currently active context.
89 restores the user context
92 A successful call does not return.
93 The context should have been obtained by a call of
97 or received as the third argument to a signal
98 handler (see the discussion of the
103 If the context was obtained by a call of
105 program execution continues as if this call just returned.
107 If the context was obtained by a call of
109 program execution continues by a call to the function
111 specified as the second argument of that call to
115 returns, we continue with the
117 member of the structure
120 first argument of that call to
122 When this member is NULL, the thread exits.
124 If the context was obtained by a call to a signal handler,
125 then old standard text says that "program execution continues with the
126 program instruction following the instruction interrupted
128 However, this sentence was removed in SUSv2,
129 and the present verdict is "the result is unspecified".
136 On error, both return \-1 and set
138 to indicate the error.
142 For an explanation of the terms used in this section, see
150 Interface Attribute Value
154 T} Thread safety MT-Safe race:ucp
161 POSIX.1-2008 removes the specification of
163 citing portability issues, and
164 recommending that applications be rewritten to use POSIX threads instead.
166 The earliest incarnation of this mechanism was the
170 Since that does not define
171 the handling of the signal context, the next stage was the
175 The present mechanism gives much more control.
177 there is no easy way to detect whether a return from
179 is from the first call, or via a
182 The user has to invent their own bookkeeping device, and a register
183 variable won't do since registers are restored.
185 When a signal occurs, the current user context is saved and
186 a new context is created by the kernel for the signal handler.
187 Do not leave the handler using
189 it is undefined what would happen with contexts.