Print this page
15254 %ymm registers not restored after signal handler
15367 x86 getfpregs() summons corrupting %xmm ghosts
15333 want x86 /proc xregs support (libc_db, libproc, mdb, etc.)
15336 want libc functions for extended ucontext_t
15334 want ps_lwphandle-specific reg routines
15328 FPU_CW_INIT mistreats reserved bit
15335 i86pc fpu_subr.c isn't really platform-specific
15332 setcontext(2) isn't actually noreturn
15331 need <sys/stdalign.h>
Change-Id: I7060aa86042dfb989f77fc3323c065ea2eafa9ad
Conflicts:
usr/src/uts/common/fs/proc/prcontrol.c
usr/src/uts/intel/os/archdep.c
usr/src/uts/intel/sys/ucontext.h
usr/src/uts/intel/syscall/getcontext.c
*** 42,66 ****
.\"
.\" Copyright 1989 AT&T
.\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
.\" Copyright (c) 2001, Sun Microsystems, Inc. All Rights Reserved.
.\" Copyright 2022 OmniOS Community Edition (OmniOSce) Association.
.\"
! .Dd November 24, 2022
.Dt GETCONTEXT 2
.Os
.Sh NAME
.Nm getcontext ,
.Nm setcontext
.Nd get and set current user context
.Sh SYNOPSIS
.In ucontext.h
.Ft int
.Fo getcontext
.Fa "ucontext_t *ucp"
.Fc
.Ft int
.Fo setcontext
.Fa "const ucontext_t *ucp"
.Fc
.Sh DESCRIPTION
The
--- 42,73 ----
.\"
.\" Copyright 1989 AT&T
.\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
.\" Copyright (c) 2001, Sun Microsystems, Inc. All Rights Reserved.
.\" Copyright 2022 OmniOS Community Edition (OmniOSce) Association.
+ .\" Copyright 2023 Oxide Computer Company
.\"
! .Dd January 24, 2022
.Dt GETCONTEXT 2
.Os
.Sh NAME
.Nm getcontext ,
+ .Nm getcontext_extd ,
.Nm setcontext
.Nd get and set current user context
.Sh SYNOPSIS
.In ucontext.h
.Ft int
.Fo getcontext
.Fa "ucontext_t *ucp"
.Fc
.Ft int
+ .Fo getcontext_extd
+ .Fa "ucontext_t *ucp"
+ .Fa "uint32_t flags"
+ .Fc
+ .Ft int
.Fo setcontext
.Fa "const ucontext_t *ucp"
.Fc
.Sh DESCRIPTION
The
*** 74,83 ****
--- 81,144 ----
.Fa ucp
points to defines the user context and includes the contents of the calling
process' machine registers, the signal mask, and the current execution stack.
.Pp
The
+ .Vt ucontext_t
+ structure is a part of the system ABI.
+ However, most architectures have added additional register states such as the
+ extended vector and floating point registers that are not part of that.
+ To facilitate getting that state
+ .Pq such as the x86 xsave area
+ the
+ .Fn getcontext_extd
+ function exists.
+ Once called, the context will be initialized and is suitable for use in other
+ context operations just as though one had called
+ .Fn getcontext .
+ .Pp
+ Unlike the
+ .Fn getcontext
+ function,
+ .Fn getcontext_extd
+ assumes that callers have previously initialized
+ .Fa ucp
+ and thus it treats additional members
+ .Po
+ such as the
+ .Fa uc_xsave
+ member on x86
+ .Pc
+ as potentially valid.
+ To allow for all extended states to be copied out,
+ .Fa ucp
+ must be allocated with
+ .Xr ucontext_alloc 3C .
+ Otherwise whether it is declared on the stack, as global data, allocated
+ dynamically, or part of a structure,
+ .Fa ucp
+ must be zeroed through a call to
+ .Xr bzero 3C
+ or
+ .Xr memset 3C
+ prior to calling
+ .Fn getcontext_extd .
+ Improper initialization can lead to memory safety bugs, making it critical that
+ this is done.
+ .Pp
+ The
+ .Fa flags
+ member must be zero and is present to allow for what is copied out to change in
+ the future.
+ This indicates that the system should attempt to copy out all extended states,
+ though if the
+ .Vt ucontext_t
+ was not allocated with
+ .Xr ucontext_alloc 3C ,
+ some extended states may not be.
+ .Pp
+ The
.Fn setcontext
function restores the user context pointed to by
.Fa ucp .
A successful call to
.Fn setcontext
*** 129,142 ****
.Sh RETURN VALUES
On successful completion,
.Fn setcontext
does not return and
.Fn getcontext
returns 0.
Otherwise, -1 is returned.
.Sh ERRORS
! No errors are defined.
.Sh USAGE
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
.Xr longjmp 3C ,
--- 190,220 ----
.Sh RETURN VALUES
On successful completion,
.Fn setcontext
does not return and
.Fn getcontext
+ and
+ .Fn getcontext_extd
returns 0.
Otherwise, -1 is returned.
.Sh ERRORS
! No errors are defined for
! .Fn getcontext
! or
! .Fn setcontext .
! .Pp
! The
! .Fn getcontext_extd
! function only sets
! .Va errno
! in some circumstances when it fails.
! The function may fail if:
! .Bl -tag -width Er
! .It Er EINVAL
! .Fa flags
! had invalid values.
! .El
.Sh USAGE
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
.Xr longjmp 3C ,
*** 171,178 ****
--- 249,257 ----
.Xr sigprocmask 2 ,
.Xr bsd_signal 3C ,
.Xr makecontext 3C ,
.Xr setjmp 3C ,
.Xr sigsetjmp 3C ,
+ .Xr ucontext_alloc 3C ,
.Xr ucontext.h 3HEAD ,
.Xr attributes 7 ,
.Xr standards 7