1GETCONTEXT(3P) POSIX Programmer's Manual GETCONTEXT(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 getcontext, setcontext - get and set current user context
13
15 #include <ucontext.h>
16
17 int getcontext(ucontext_t *ucp);
18 int setcontext(const ucontext_t *ucp);
19
20
22 The getcontext() function shall initialize the structure pointed to by
23 ucp to the current user context of the calling thread. The ucontext_t
24 type that ucp points to defines the user context and includes the con‐
25 tents of the calling thread's machine registers, the signal mask, and
26 the current execution stack.
27
28 The setcontext() function shall restore the user context pointed to by
29 ucp. A successful call to setcontext() shall not return; program execu‐
30 tion resumes at the point specified by the ucp argument passed to set‐
31 context(). The ucp argument should be created either by a prior call to
32 getcontext() or makecontext(), or by being passed as an argument to a
33 signal handler. If the ucp argument was created with getcontext(), pro‐
34 gram execution continues as if the corresponding call of getcontext()
35 had just returned. If the ucp argument was created with makecontext(),
36 program execution continues with the function passed to makecontext().
37 When that function returns, the thread shall continue as if after a
38 call to setcontext() with the ucp argument that was input to makecon‐
39 text(). If the uc_link member of the ucontext_t structure pointed to by
40 the ucp argument is equal to 0, then this context is the main context,
41 and the thread shall exit when this context returns. The effects of
42 passing a ucp argument obtained from any other source are unspecified.
43
45 Upon successful completion, setcontext() shall not return and getcon‐
46 text() shall return 0; otherwise, a value of -1 shall be returned.
47
49 No errors are defined.
50
51 The following sections are informative.
52
54 Refer to makecontext().
55
57 When a signal handler is executed, the current user context is saved
58 and a new context is created. If the thread leaves the signal handler
59 via longjmp(), then it is unspecified whether the context at the time
60 of the corresponding setjmp() call is restored and thus whether future
61 calls to getcontext() provide an accurate representation of the current
62 context, since the context restored by longjmp() does not necessarily
63 contain all the information that setcontext() requires. Signal handlers
64 should use siglongjmp() or setcontext() instead.
65
66 Conforming applications should not modify or access the uc_mcontext
67 member of ucontext_t. A conforming application cannot assume that con‐
68 text includes any process-wide static data, possibly including errno.
69 Users manipulating contexts should take care to handle these explicitly
70 when required.
71
72 Use of contexts to create alternate stacks is not defined by this vol‐
73 ume of IEEE Std 1003.1-2001.
74
76 None.
77
79 None.
80
82 bsd_signal(), makecontext(), setcontext(), setjmp(), sigaction(),
83 sigaltstack(), siglongjmp(), sigprocmask(), sigsetjmp(), the Base Defi‐
84 nitions volume of IEEE Std 1003.1-2001, <ucontext.h>
85
87 Portions of this text are reprinted and reproduced in electronic form
88 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
89 -- Portable Operating System Interface (POSIX), The Open Group Base
90 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
91 Electrical and Electronics Engineers, Inc and The Open Group. In the
92 event of any discrepancy between this version and the original IEEE and
93 The Open Group Standard, the original IEEE and The Open Group Standard
94 is the referee document. The original Standard can be obtained online
95 at http://www.opengroup.org/unix/online.html .
96
97
98
99IEEE/The Open Group 2003 GETCONTEXT(3P)