1.\" 2.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for 3.\" permission to reproduce portions of its copyrighted documentation. 4.\" Original documentation from The Open Group can be obtained online at 5.\" http://www.opengroup.org/bookstore/. 6.\" 7.\" The Institute of Electrical and Electronics Engineers and The Open 8.\" Group, have given us permission to reprint portions of their 9.\" documentation. 10.\" 11.\" In the following statement, the phrase ``this text'' refers to portions 12.\" of the system documentation. 13.\" 14.\" Portions of this text are reprinted and reproduced in electronic form 15.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition, 16.\" Standard for Information Technology -- Portable Operating System 17.\" Interface (POSIX), The Open Group Base Specifications Issue 6, 18.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics 19.\" Engineers, Inc and The Open Group. In the event of any discrepancy 20.\" between these versions and the original IEEE and The Open Group 21.\" Standard, the original IEEE and The Open Group Standard is the referee 22.\" document. The original Standard can be obtained online at 23.\" http://www.opengroup.org/unix/online.html. 24.\" 25.\" This notice shall appear on any product containing this material. 26.\" 27.\" The contents of this file are subject to the terms of the 28.\" Common Development and Distribution License (the "License"). 29.\" You may not use this file except in compliance with the License. 30.\" 31.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 32.\" or http://www.opensolaris.org/os/licensing. 33.\" See the License for the specific language governing permissions 34.\" and limitations under the License. 35.\" 36.\" When distributing Covered Code, include this CDDL HEADER in each 37.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. 38.\" If applicable, add the following below this CDDL HEADER, with the 39.\" fields enclosed by brackets "[]" replaced with your own identifying 40.\" information: Portions Copyright [yyyy] [name of copyright owner] 41.\" 42.\" 43.\" Copyright 1989 AT&T 44.\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. 45.\" Copyright (c) 2001, Sun Microsystems, Inc. All Rights Reserved. 46.\" Copyright 2022 OmniOS Community Edition (OmniOSce) Association. 47.\" 48.Dd November 24, 2022 49.Dt GETCONTEXT 2 50.Os 51.Sh NAME 52.Nm getcontext , 53.Nm setcontext 54.Nd get and set current user context 55.Sh SYNOPSIS 56.In ucontext.h 57.Ft int 58.Fo getcontext 59.Fa "ucontext_t *ucp" 60.Fc 61.Ft int 62.Fo setcontext 63.Fa "const ucontext_t *ucp" 64.Fc 65.Sh DESCRIPTION 66The 67.Fn getcontext 68function initializes the structure pointed to by 69.Fa ucp 70to the current user context of the calling process. 71The 72.Vt ucontext_t 73type that 74.Fa ucp 75points to defines the user context and includes the contents of the calling 76process' machine registers, the signal mask, and the current execution stack. 77.Pp 78The 79.Fn setcontext 80function restores the user context pointed to by 81.Fa ucp . 82A successful call to 83.Fn setcontext 84does not return; program execution resumes at the point specified by the 85.Fa ucp 86argument passed to 87.Fn setcontext . 88The 89.Fa ucp 90argument should be created either by a prior call to 91.Fn getcontext , 92or by being passed as an argument to a signal handler. 93If the 94.Fa ucp 95argument was created with 96.Fn getcontext , 97program execution continues as if the corresponding call of 98.Fn getcontext 99had just returned. 100If the 101.Fa ucp 102argument was created with 103.Xr makecontext 3C , 104program execution continues with the function passed to 105.Xr makecontext 3C . 106When that function returns, the process continues as if after a call to 107.Fn setcontext 108with the 109.Fa ucp 110argument that was input to 111.Xr makecontext 3C . 112If the 113.Fa ucp 114argument was passed to a signal handler, program execution continues with the 115program instruction following the instruction interrupted by the signal. 116If the 117.Fa uc_link 118member of the 119.Vt ucontext_t 120structure pointed to by the 121.Fa ucp 122argument is 123.Dv NULL , 124then this context is the main context, and the process 125will exit when this context returns. 126The effects of passing a 127.Fa ucp 128argument obtained from any other source are unspecified. 129.Sh RETURN VALUES 130On successful completion, 131.Fn setcontext 132does not return and 133.Fn getcontext 134returns 0. 135Otherwise, -1 is returned. 136.Sh ERRORS 137No errors are defined. 138.Sh USAGE 139When a signal handler is executed, the current user context is saved and a new 140context is created. 141If the thread leaves the signal handler via 142.Xr longjmp 3C , 143then it is unspecified whether the context at the time of the corresponding 144.Xr setjmp 3C 145call is restored and thus whether future calls to 146.Fn getcontext 147will provide an accurate representation of the current context, since the 148context restored by 149.Xr longjmp 3C 150may not contain all the information that 151.Fn setcontext 152requires. 153Signal handlers should use 154.Xr siglongjmp 3C 155instead. 156.Pp 157Portable applications should not modify or access the 158.Fa uc_mcontext 159member of 160.Vt ucontext_t . 161A portable application cannot assume that context includes any process-wide 162static data, possibly including 163.Va errno . 164Users manipulating contexts should take care to handle these explicitly when 165required. 166.Sh INTERFACE STABILITY 167.Sy Committed 168.Sh SEE ALSO 169.Xr sigaction 2 , 170.Xr sigaltstack 2 , 171.Xr sigprocmask 2 , 172.Xr bsd_signal 3C , 173.Xr makecontext 3C , 174.Xr setjmp 3C , 175.Xr sigsetjmp 3C , 176.Xr ucontext.h 3HEAD , 177.Xr attributes 7 , 178.Xr standards 7 179