Visit The New, Modern Unix Linux Community

Linux and UNIX Man Pages

Test Your Knowledge in Computers #1010
Difficulty: Easy
The number 200 in base 8 equals 128 in base 10.
True or False?
Linux & Unix Commands - Search Man Pages

setcontext(3) [freebsd man page]

GETCONTEXT(3)						   BSD Library Functions Manual 					     GETCONTEXT(3)

NAME
getcontext, getcontextx, setcontext -- get and set user thread context LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <ucontext.h> int getcontext(ucontext_t *ucp); ucontext_t * getcontextx(void); int setcontext(const ucontext_t *ucp); DESCRIPTION
The getcontext() function saves the current thread's execution context in the structure pointed to by ucp. This saved context may then later be restored by calling setcontext(). The getcontextx() function saves the current execution context in the newly allocated structure ucontext_t, which is returned on success. If architecture defines additional CPU states that can be stored in extended blocks referenced from the ucontext_t, the memory for them may be allocated and their context also stored. Memory returned by getcontextx() function shall be freed using free(3). The setcontext() function makes a previously saved thread context the current thread context, i.e., the current context is lost and setcontext() does not return. Instead, execution continues in the context specified by ucp, which must have been previously initialized by a call to getcontext(), makecontext(3), or by being passed as an argument to a signal handler (see sigaction(2)). If ucp was initialized by getcontext(), then execution continues as if the original getcontext() call had just returned (again). If ucp was initialized by makecontext(3), execution continues with the invocation of the function specified to makecontext(3). When that function returns, ucp->uc_link determines what happens next: if ucp->uc_link is NULL, the process exits; otherwise, setcontext(ucp->uc_link) is implicitly invoked. If ucp was initialized by the invocation of a signal handler, execution continues at the point the thread was interrupted by the signal. RETURN VALUES
If successful, getcontext() returns zero and setcontext() does not return; otherwise -1 is returned. The getcontextx() returns pointer to the allocated and initialized context on success, and NULL on failure. ERRORS
No errors are defined for getcontext() or setcontext(). The getcontextx() may return the following errors in errno: [ENOMEM] No memory was available to allocate for the context or some extended state. SEE ALSO
sigaction(2), sigaltstack(2), makecontext(3), ucontext(3) BSD
March 13, 2013 BSD

Check Out this Related Man Page

GETCONTEXT(2)						      BSD System Calls Manual						     GETCONTEXT(2)

NAME
getcontext, setcontext -- get and set current user context LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <ucontext.h> int getcontext(ucontext_t *ucp); int setcontext(const ucontext_t *ucp); DESCRIPTION
The getcontext() function initializes the object pointed to by ucp to the current user context of the calling thread. The user context defines a thread's execution environment and includes the contents of its machine registers, its signal mask, and its current execution stack. The setcontext() function restores the user context defined in the object pointed to by ucp as most recently initialized by a previous call to either getcontext() or makecontext(3). If successful, execution of the program resumes as defined in the ucp argument, and setcontext() will not return. If ucp was initialized by the getcontext() function, program execution continues as if the corresponding invocation of getcontext() had just returned (successfully). If ucp was initialized by the makecontext(3) function, program execution continues with the function (and function arguments) passed to makecontext(3). RETURN VALUES
On successful completion, getcontext() returns 0 and setcontext() does not return. Otherwise a value of -1 is returned and errno is set to indicate the error. ERRORS
The getcontext() and setcontext() functions will fail if: [EFAULT] The ucp argument points to an invalid address. The setcontext() function will fail if: [EINVAL] The contents of the datum pointed to by ucp are invalid. SEE ALSO
sigprocmask(2), longjmp(3), makecontext(3), setjmp(3), swapcontext(3) STANDARDS
The getcontext() and setcontext() functions conform to X/Open System Interfaces and Headers Issue 5 (``XSH5'') and IEEE Std 1003.1-2001 (``POSIX.1''). The errno indications are an extension to the standard. The IEEE Std 1003.1-2004 (``POSIX.1'') revision marked the functions getcontext() and setcontext() as obsolete, citing portability issues and recommending the use of POSIX threads instead. The IEEE Std 1003.1-2008 (``POSIX.1'') revision removed the functions from the specification. HISTORY
The getcontext() and setcontext() functions first appeared in AT&T System V Release 4 UNIX. BSD
April 28, 2010 BSD

Featured Tech Videos