xref: /illumos-gate/usr/src/uts/intel/sys/ucontext.h (revision ed093b41)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5bdf0047cSRoger A. Faulkner  * Common Development and Distribution License (the "License").
6bdf0047cSRoger A. Faulkner  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate 
227c478bd9Sstevel@tonic-gate /*
23bc0e9132SGordon Ross  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
24*ed093b41SRobert Mustacchi  * Copyright 2023 Oxide Computer Company
25bc0e9132SGordon Ross  *
26bdf0047cSRoger A. Faulkner  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
277c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
30bdf0047cSRoger A. Faulkner /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
31b4203d75SMarcel Telka /*	  All Rights Reserved	*/
32bdf0047cSRoger A. Faulkner 
337c478bd9Sstevel@tonic-gate #ifndef _SYS_UCONTEXT_H
347c478bd9Sstevel@tonic-gate #define	_SYS_UCONTEXT_H
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #include <sys/types.h>
39bc0e9132SGordon Ross #include <sys/mcontext.h>
407c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
417c478bd9Sstevel@tonic-gate #include <sys/signal.h>
427c478bd9Sstevel@tonic-gate #endif
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
457c478bd9Sstevel@tonic-gate extern "C" {
467c478bd9Sstevel@tonic-gate #endif
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate /*
497c478bd9Sstevel@tonic-gate  * Inclusion of <sys/signal.h> for sigset_t and stack_t definitions
507c478bd9Sstevel@tonic-gate  * breaks XPG4v2 namespace.  Therefore we must duplicate the defines
517c478bd9Sstevel@tonic-gate  * for these types here when _XPG4_2 is defined.
527c478bd9Sstevel@tonic-gate  */
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate #if defined(_XPG4_2) && !defined(__EXTENSIONS__)
557c478bd9Sstevel@tonic-gate #ifndef	_SIGSET_T
567c478bd9Sstevel@tonic-gate #define	_SIGSET_T
577c478bd9Sstevel@tonic-gate typedef	struct {	/* signal set type */
587c478bd9Sstevel@tonic-gate 	unsigned long	__sigbits[4];
597c478bd9Sstevel@tonic-gate } sigset_t;
607c478bd9Sstevel@tonic-gate #endif /* _SIGSET_T */
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate #ifndef	_STACK_T
637c478bd9Sstevel@tonic-gate #define	_STACK_T
647c478bd9Sstevel@tonic-gate typedef	struct {
657c478bd9Sstevel@tonic-gate 	void	*ss_sp;
667c478bd9Sstevel@tonic-gate 	size_t	ss_size;
677c478bd9Sstevel@tonic-gate 	int	ss_flags;
687c478bd9Sstevel@tonic-gate } stack_t;
697c478bd9Sstevel@tonic-gate #endif /* _STACK_T */
707c478bd9Sstevel@tonic-gate #endif /* defined(_XPG4_2) && !defined(__EXTENSIONS__) */
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
737c478bd9Sstevel@tonic-gate typedef	struct ucontext ucontext_t;
747c478bd9Sstevel@tonic-gate #else
757c478bd9Sstevel@tonic-gate typedef	struct __ucontext ucontext_t;
767c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
797c478bd9Sstevel@tonic-gate struct	ucontext {
807c478bd9Sstevel@tonic-gate #else
817c478bd9Sstevel@tonic-gate struct	__ucontext {
827c478bd9Sstevel@tonic-gate #endif
837c478bd9Sstevel@tonic-gate 	unsigned long	uc_flags;
847c478bd9Sstevel@tonic-gate 	ucontext_t	*uc_link;
85*ed093b41SRobert Mustacchi 	sigset_t	uc_sigmask;
86*ed093b41SRobert Mustacchi 	stack_t		uc_stack;
87*ed093b41SRobert Mustacchi 	mcontext_t	uc_mcontext;
88*ed093b41SRobert Mustacchi 	/*
89*ed093b41SRobert Mustacchi 	 * The first three entries have been borrowed by the lx brand right now.
90*ed093b41SRobert Mustacchi 	 * That should be consolidated into a single uc_brand entry with a
91*ed093b41SRobert Mustacchi 	 * UC_BRAND flag. Until such time, to help folks downstream who have the
92*ed093b41SRobert Mustacchi 	 * lx brand, we leave them as is.
93*ed093b41SRobert Mustacchi 	 */
94*ed093b41SRobert Mustacchi 	long		uc_filler[3];
95*ed093b41SRobert Mustacchi 	long		uc_xsave;
96*ed093b41SRobert Mustacchi 	long		uc_filler1;
977c478bd9Sstevel@tonic-gate };
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate /* Kernel view of user ILP32 ucontext structure */
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate typedef struct ucontext32 {
1047c478bd9Sstevel@tonic-gate 	uint32_t	uc_flags;
1057c478bd9Sstevel@tonic-gate 	caddr32_t	uc_link;
106bdf0047cSRoger A. Faulkner 	sigset_t	uc_sigmask;
1077c478bd9Sstevel@tonic-gate 	stack32_t	uc_stack;
1087c478bd9Sstevel@tonic-gate 	mcontext32_t	uc_mcontext;
109*ed093b41SRobert Mustacchi 	int32_t		uc_filler[3];
110*ed093b41SRobert Mustacchi 	int32_t		uc_xsave;
111*ed093b41SRobert Mustacchi 	int32_t		uc_filler1;
1127c478bd9Sstevel@tonic-gate } ucontext32_t;
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
1157c478bd9Sstevel@tonic-gate extern void ucontext_nto32(const ucontext_t *src, ucontext32_t *dest);
1167c478bd9Sstevel@tonic-gate extern void ucontext_32ton(const ucontext32_t *src, ucontext_t *dest);
1177c478bd9Sstevel@tonic-gate #endif
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
1227c478bd9Sstevel@tonic-gate #define	GETCONTEXT	0
1237c478bd9Sstevel@tonic-gate #define	SETCONTEXT	1
1247c478bd9Sstevel@tonic-gate #define	GETUSTACK	2
1257c478bd9Sstevel@tonic-gate #define	SETUSTACK	3
126*ed093b41SRobert Mustacchi #define	GETCONTEXT_EXTD	4
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate  * values for uc_flags
1307c478bd9Sstevel@tonic-gate  * these are implementation dependent flags, that should be hidden
1317c478bd9Sstevel@tonic-gate  * from the user interface, defining which elements of ucontext
1327c478bd9Sstevel@tonic-gate  * are valid, and should be restored on call to setcontext
1337c478bd9Sstevel@tonic-gate  */
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate #define	UC_SIGMASK	0x01
1367c478bd9Sstevel@tonic-gate #define	UC_STACK	0x02
1377c478bd9Sstevel@tonic-gate #define	UC_CPU		0x04
1387c478bd9Sstevel@tonic-gate #define	UC_MAU		0x08
1397c478bd9Sstevel@tonic-gate #define	UC_FPU		UC_MAU
140*ed093b41SRobert Mustacchi #define	UC_XSAVE	0x10
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate #define	UC_MCONTEXT	(UC_CPU|UC_FPU)
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate /*
1457c478bd9Sstevel@tonic-gate  * UC_ALL specifies the default context
1467c478bd9Sstevel@tonic-gate  */
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate #define	UC_ALL		(UC_SIGMASK|UC_STACK|UC_MCONTEXT)
1497c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate #ifdef _KERNEL
152*ed093b41SRobert Mustacchi /*
153*ed093b41SRobert Mustacchi  * This structure is the private header for the xsave data that we end up
154*ed093b41SRobert Mustacchi  * sending to the stack. This is basically our own compressed form. See,
155*ed093b41SRobert Mustacchi  * uts/intel/os/fpu.c for more information. To help maintain the private nature,
156*ed093b41SRobert Mustacchi  * this is unfortunately duplicated in the xsave tests. If you change this you
157*ed093b41SRobert Mustacchi  * must update test/os-tests/tests/xsave/xsave_util.h.
158*ed093b41SRobert Mustacchi  */
159*ed093b41SRobert Mustacchi #define	UC_XSAVE_VERS	(('u' << 24) | ('c' << 16) | 0x01)
160*ed093b41SRobert Mustacchi typedef struct uc_xsave {
161*ed093b41SRobert Mustacchi 	uint32_t ucx_vers;
162*ed093b41SRobert Mustacchi 	uint32_t ucx_len;
163*ed093b41SRobert Mustacchi 	uint64_t ucx_bv;
164*ed093b41SRobert Mustacchi } uc_xsave_t;
165*ed093b41SRobert Mustacchi 
166*ed093b41SRobert Mustacchi typedef enum {
167*ed093b41SRobert Mustacchi 	/*
168*ed093b41SRobert Mustacchi 	 * Do a boring old savecontext() where we assume that only the data
169*ed093b41SRobert Mustacchi 	 * structure that we're given must be filled in.
170*ed093b41SRobert Mustacchi 	 */
171*ed093b41SRobert Mustacchi 	SAVECTXT_F_NONE = 0,
172*ed093b41SRobert Mustacchi 	/*
173*ed093b41SRobert Mustacchi 	 * Indicate that we should treat the ucontext_t as having valid user
174*ed093b41SRobert Mustacchi 	 * pointers for copying out extended state. Currently this means that we
175*ed093b41SRobert Mustacchi 	 * treat the uc_xsave member as something that points to a user address.
176*ed093b41SRobert Mustacchi 	 */
177*ed093b41SRobert Mustacchi 	SAVECTXT_F_EXTD	= 1 << 0,
178*ed093b41SRobert Mustacchi 	/*
179*ed093b41SRobert Mustacchi 	 * This indicates that we shouldn't do normal copyout handling and need
180*ed093b41SRobert Mustacchi 	 * to actually avoid potentially triggering a watchpoint because we're
181*ed093b41SRobert Mustacchi 	 * probably in signal handling context.
182*ed093b41SRobert Mustacchi 	 */
183*ed093b41SRobert Mustacchi 	SAVECTXT_F_ONFAULT = 1 << 1
184*ed093b41SRobert Mustacchi } savecontext_flags_t;
185*ed093b41SRobert Mustacchi 
186*ed093b41SRobert Mustacchi int savecontext(ucontext_t *, const k_sigset_t *, savecontext_flags_t);
1877c478bd9Sstevel@tonic-gate void restorecontext(ucontext_t *);
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
190*ed093b41SRobert Mustacchi extern int savecontext32(ucontext32_t *, const k_sigset_t *,
191*ed093b41SRobert Mustacchi     savecontext_flags_t);
1927c478bd9Sstevel@tonic-gate #endif
1937c478bd9Sstevel@tonic-gate #endif
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1967c478bd9Sstevel@tonic-gate }
1977c478bd9Sstevel@tonic-gate #endif
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate #endif /* _SYS_UCONTEXT_H */
200