GETCONTEXT(3) Library Functions Manual GETCONTEXT(3)

getcontext setcontextget and set current user context


#include <ucontext.h>

int getcontext(ucontext_t *ucp);
int setcontext(const ucontext_t *ucp);

The getcontext () function shall initialize the structure pointed to by ucp to the current user context of the calling thread. The ucontext_t type that ucp points to defines the user context and includes the contents of the calling thread's machine registers, the signal mask, and the current execution stack.

Upon successful completion, setcontext () shall not return and getcontext () shall return 0; otherwise, a value of -1 shall be returned.

No errors are defined.

Refer to makecontext(3).

When a signal handler is executed, the current user context is saved and a new context is created. If the thread leaves the signal handler via longjmp(3), then it is unspecified whether the context at the time of the corresponding setjmp(3) call is restored and thus whether future calls to getcontext () provide an accurate representation of the current context, since the context restored by longjmp(3) does not necessarily contain all the information that setcontext () requires. Signal handlers should use siglongjmp(3) or setcontext () instead.

Conforming applications should not modify or access the member of ucontext_t. A conforming application cannot assume that context includes any process-wide static data, possibly including . Users manipulating contexts should take care to handle these explicitly when required.

Use of contexts to create alternate stacks is not defined by this volume of IEEE Std 1003.1-2001 (“POSIX.1”).

The obsolescent functions getcontext (), makecontext(3), and swapcontext(3) can be replaced using POSIX threads functions.

None.

None.

bsd_signal(3), makecontext(3), setcontext(3), setjmp(3), sigaction(3), sigaltstack(3), siglongjmp(3), sigprocmask(3), sigsetjmp(3), the Base Definitions volume of IEEE Std 1003.1-2001 (“POSIX.1”), <ucontext.h>

First released in Issue 4, Version 2.

Moved from X/OPEN UNIX extension to BASE.

The following sentence was removed from the DESCRIPTION: "If the ucp argument was passed to a signal handler, program execution continues with the program instruction following the instruction interrupted by the signal."

IEEE Std 1003.1-2001 (“POSIX.1”)/Cor 2-2004, item XSH/TC2/D6/45 is applied, updating the SYNOPSIS and APPLICATION USAGE sections to note that the getcontext () and setcontext () functions are obsolescent.

footer end

January 1, 2004 posix.fail