1GETCONTEXT(P)              POSIX Programmer's Manual             GETCONTEXT(P)
2
3
4

NAME

6       getcontext, setcontext - get and set current user context
7

SYNOPSIS

9       #include <ucontext.h>
10
11       int getcontext(ucontext_t *ucp);
12       int setcontext(const ucontext_t *ucp);
13
14

DESCRIPTION

16       The  getcontext() function shall initialize the structure pointed to by
17       ucp to the current user context of the calling thread.  The  ucontext_t
18       type  that ucp points to defines the user context and includes the con‐
19       tents of the calling thread's machine registers, the signal  mask,  and
20       the current execution stack.
21
22       The  setcontext() function shall restore the user context pointed to by
23       ucp. A successful call to setcontext() shall not return; program execu‐
24       tion  resumes at the point specified by the ucp argument passed to set‐
25       context(). The ucp argument should be created either by a prior call to
26       getcontext()  or  makecontext(), or by being passed as an argument to a
27       signal handler. If the ucp argument was created with getcontext(), pro‐
28       gram  execution  continues as if the corresponding call of getcontext()
29       had just returned. If the ucp argument was created with  makecontext(),
30       program  execution continues with the function passed to makecontext().
31       When that function returns, the thread shall continue  as  if  after  a
32       call  to  setcontext() with the ucp argument that was input to makecon‐
33       text(). If the uc_link member of the ucontext_t structure pointed to by
34       the  ucp argument is equal to 0, then this context is the main context,
35       and the thread shall exit when this context  returns.  The  effects  of
36       passing a ucp argument obtained from any other source are unspecified.
37

RETURN VALUE

39       Upon  successful  completion, setcontext() shall not return and getcon‐
40       text() shall return 0; otherwise, a value of -1 shall be returned.
41

ERRORS

43       No errors are defined.
44
45       The following sections are informative.
46

EXAMPLES

48       Refer to makecontext() .
49

APPLICATION USAGE

51       When a signal handler is executed, the current user  context  is  saved
52       and  a  new context is created. If the thread leaves the signal handler
53       via longjmp(), then it is unspecified whether the context at  the  time
54       of  the corresponding setjmp() call is restored and thus whether future
55       calls to getcontext() provide an accurate representation of the current
56       context,  since  the context restored by longjmp() does not necessarily
57       contain all the information that setcontext() requires. Signal handlers
58       should use siglongjmp() or setcontext() instead.
59
60       Conforming  applications  should  not  modify or access the uc_mcontext
61       member of ucontext_t. A conforming application cannot assume that  con‐
62       text  includes  any process-wide static data, possibly including errno.
63       Users manipulating contexts should take care to handle these explicitly
64       when required.
65
66       Use  of contexts to create alternate stacks is not defined by this vol‐
67       ume of IEEE Std 1003.1-2001.
68

RATIONALE

70       None.
71

FUTURE DIRECTIONS

73       None.
74

SEE ALSO

76       bsd_signal() , makecontext() , setcontext() , setjmp() , sigaction()  ,
77       sigaltstack()  ,  siglongjmp() , sigprocmask() , sigsetjmp() , the Base
78       Definitions volume of IEEE Std 1003.1-2001, <ucontext.h>
79
81       Portions of this text are reprinted and reproduced in  electronic  form
82       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
83       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
84       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
85       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
86       event of any discrepancy between this version and the original IEEE and
87       The Open Group Standard, the original IEEE and The Open Group  Standard
88       is  the  referee document. The original Standard can be obtained online
89       at http://www.opengroup.org/unix/online.html .
90
91
92
93IEEE/The Open Group                  2003                        GETCONTEXT(P)
Impressum