1 .\" Copyright (C) 2001 Andries Brouwer (aeb@cwi.nl)
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH GETCONTEXT 3 2017-09-15 "Linux" "Linux Programmer's Manual"
27 getcontext, setcontext \- get or set the user context
29 .B #include <ucontext.h>
31 .BI "int getcontext(ucontext_t *" ucp );
33 .BI "int setcontext(const ucontext_t *" ucp );
35 In a System V-like environment, one has the two types
41 and the four functions
47 that allow user-level context switching between multiple
48 threads of control within a process.
52 type is machine-dependent and opaque.
55 type is a structure that has at least
60 typedef struct ucontext_t {
61 struct ucontext_t *uc_link;
64 mcontext_t uc_mcontext;
78 points to the context that will be resumed
79 when the current context terminates (in case the current context
84 set of signals blocked in this context (see
87 is the stack used by this context (see
92 machine-specific representation of the saved context,
93 that includes the calling thread's machine registers.
97 initializes the structure
100 to the currently active context.
104 restores the user context
107 A successful call does not return.
108 The context should have been obtained by a call of
112 or passed as third argument to a signal
115 If the context was obtained by a call of
117 program execution continues as if this call just returned.
119 If the context was obtained by a call of
121 program execution continues by a call to the function
123 specified as the second argument of that call to
127 returns, we continue with the
129 member of the structure
132 first argument of that call to
134 When this member is NULL, the thread exits.
136 If the context was obtained by a call to a signal handler,
137 then old standard text says that "program execution continues with the
138 program instruction following the instruction interrupted
140 However, this sentence was removed in SUSv2,
141 and the present verdict is "the result is unspecified".
148 On error, both return \-1 and set
154 For an explanation of the terms used in this section, see
160 Interface Attribute Value
164 T} Thread safety MT-Safe race:ucp
168 POSIX.1-2008 removes the specification of
170 citing portability issues, and
171 recommending that applications be rewritten to use POSIX threads instead.
173 The earliest incarnation of this mechanism was the
174 .BR setjmp (3)/ longjmp (3)
176 Since that does not define
177 the handling of the signal context, the next stage was the
178 .BR sigsetjmp (3)/ siglongjmp (3)
180 The present mechanism gives much more control.
182 there is no easy way to detect whether a return from
184 is from the first call, or via a
187 The user has to invent her own bookkeeping device, and a register
188 variable won't do since registers are restored.
190 When a signal occurs, the current user context is saved and
191 a new context is created by the kernel for the signal handler.
192 Do not leave the handler using
194 it is undefined what would happen with contexts.