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 2014-04-08 "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 {
61 struct ucontext *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 .SS Multithreading (see pthreads(7))
159 functions are thread-safe.
162 POSIX.1-2008 removes the specification of
164 citing portability issues, and
165 recommending that applications be rewritten to use POSIX threads instead.
167 The earliest incarnation of this mechanism was the
168 .BR setjmp (3)/ longjmp (3)
170 Since that does not define
171 the handling of the signal context, the next stage was the
172 .BR sigsetjmp (3)/ siglongjmp (3)
174 The present mechanism gives much more control.
176 there is no easy way to detect whether a return from
178 is from the first call, or via a
181 The user has to invent her own bookkeeping device, and a register
182 variable won't do since registers are restored.
184 When a signal occurs, the current user context is saved and
185 a new context is created by the kernel for the signal handler.
186 Do not leave the handler using
188 it is undefined what would happen with contexts.
202 This page is part of release 3.68 of the Linux
205 A description of the project,
206 information about reporting bugs,
207 and the latest version of this page,
209 \%http://www.kernel.org/doc/man\-pages/.