17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
5bdf0047Roger A. Faulkner * Common Development and Distribution License (the "License").
6bdf0047Roger A. Faulkner * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
217c478bdstevel@tonic-gate
227c478bdstevel@tonic-gate/*
23bc0e913Gordon Ross * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
24bc0e913Gordon Ross *
25bdf0047Roger A. Faulkner * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
267c478bdstevel@tonic-gate * Use is subject to license terms.
277c478bdstevel@tonic-gate */
287c478bdstevel@tonic-gate
29bdf0047Roger A. Faulkner/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
30bdf0047Roger A. Faulkner/*	  All Rights Reserved  	*/
31bdf0047Roger A. Faulkner
327c478bdstevel@tonic-gate#ifndef _SYS_UCONTEXT_H
337c478bdstevel@tonic-gate#define	_SYS_UCONTEXT_H
347c478bdstevel@tonic-gate
357c478bdstevel@tonic-gate#include <sys/feature_tests.h>
367c478bdstevel@tonic-gate
377c478bdstevel@tonic-gate#include <sys/types.h>
38bc0e913Gordon Ross#include <sys/mcontext.h>
397c478bdstevel@tonic-gate#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
407c478bdstevel@tonic-gate#include <sys/signal.h>
417c478bdstevel@tonic-gate#endif
427c478bdstevel@tonic-gate
437c478bdstevel@tonic-gate#ifdef	__cplusplus
447c478bdstevel@tonic-gateextern "C" {
457c478bdstevel@tonic-gate#endif
467c478bdstevel@tonic-gate
477c478bdstevel@tonic-gate/*
487c478bdstevel@tonic-gate * Inclusion of <sys/signal.h> for sigset_t and stack_t definitions
497c478bdstevel@tonic-gate * breaks XPG4v2 namespace.  Therefore we must duplicate the defines
507c478bdstevel@tonic-gate * for these types here when _XPG4_2 is defined.
517c478bdstevel@tonic-gate */
527c478bdstevel@tonic-gate
537c478bdstevel@tonic-gate#if defined(_XPG4_2) && !defined(__EXTENSIONS__)
547c478bdstevel@tonic-gate#ifndef	_SIGSET_T
557c478bdstevel@tonic-gate#define	_SIGSET_T
567c478bdstevel@tonic-gatetypedef	struct {	/* signal set type */
577c478bdstevel@tonic-gate	unsigned int	__sigbits[4];
587c478bdstevel@tonic-gate} sigset_t;
597c478bdstevel@tonic-gate#endif /* _SIGSET_T */
607c478bdstevel@tonic-gate
617c478bdstevel@tonic-gate#ifndef	_STACK_T
627c478bdstevel@tonic-gate#define	_STACK_T
637c478bdstevel@tonic-gatetypedef	struct {
647c478bdstevel@tonic-gate	void	*ss_sp;
657c478bdstevel@tonic-gate	size_t	ss_size;
667c478bdstevel@tonic-gate	int	ss_flags;
677c478bdstevel@tonic-gate} stack_t;
687c478bdstevel@tonic-gate
697c478bdstevel@tonic-gate#endif /* _STACK_T */
707c478bdstevel@tonic-gate#endif /* defined(_XPG4_2) && !defined(__EXTENSIONS__) */
717c478bdstevel@tonic-gate
727c478bdstevel@tonic-gate#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
737c478bdstevel@tonic-gatetypedef	struct ucontext ucontext_t;
747c478bdstevel@tonic-gate#else
757c478bdstevel@tonic-gatetypedef	struct __ucontext ucontext_t;
767c478bdstevel@tonic-gate#endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
777c478bdstevel@tonic-gate
787c478bdstevel@tonic-gate#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
797c478bdstevel@tonic-gatestruct	ucontext {
807c478bdstevel@tonic-gate#else
817c478bdstevel@tonic-gatestruct	__ucontext {
827c478bdstevel@tonic-gate#endif
837c478bdstevel@tonic-gate	uint_t		uc_flags;
847c478bdstevel@tonic-gate	ucontext_t	*uc_link;
857c478bdstevel@tonic-gate	sigset_t   	uc_sigmask;
867c478bdstevel@tonic-gate	stack_t 	uc_stack;
877c478bdstevel@tonic-gate	mcontext_t	uc_mcontext;
887c478bdstevel@tonic-gate#ifdef	__sparcv9
897c478bdstevel@tonic-gate	long		uc_filler[4];
907c478bdstevel@tonic-gate#else	/* __sparcv9 */
917c478bdstevel@tonic-gate	long		uc_filler[23];
927c478bdstevel@tonic-gate#endif	/* __sparcv9 */
937c478bdstevel@tonic-gate};
947c478bdstevel@tonic-gate
957c478bdstevel@tonic-gate#ifdef _SYSCALL32
967c478bdstevel@tonic-gate
977c478bdstevel@tonic-gate/* Kernel view of user ILP32 ucontext structure */
987c478bdstevel@tonic-gate
997c478bdstevel@tonic-gatetypedef struct ucontext32 {
1007c478bdstevel@tonic-gate	uint32_t	uc_flags;
1017c478bdstevel@tonic-gate	caddr32_t	uc_link;
102bdf0047Roger A. Faulkner	sigset_t	uc_sigmask;
1037c478bdstevel@tonic-gate	stack32_t	uc_stack;
1047c478bdstevel@tonic-gate	mcontext32_t	uc_mcontext;
1057c478bdstevel@tonic-gate	int32_t		uc_filler[23];
1067c478bdstevel@tonic-gate} ucontext32_t;
1077c478bdstevel@tonic-gate
1087c478bdstevel@tonic-gate#ifdef _KERNEL
1097c478bdstevel@tonic-gateextern void ucontext_32ton(const ucontext32_t *, ucontext_t *,
110bc0e913Gordon Ross    const struct fq32 *, struct _fq *);
1117c478bdstevel@tonic-gateextern void fpuregset_nto32(const fpregset_t *, fpregset32_t *, struct fq32 *);
1127c478bdstevel@tonic-gate#endif
1137c478bdstevel@tonic-gate
1147c478bdstevel@tonic-gate#endif	/* _SYSCALL32 */
1157c478bdstevel@tonic-gate
1167c478bdstevel@tonic-gate#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
1177c478bdstevel@tonic-gate#define	GETCONTEXT	0
1187c478bdstevel@tonic-gate#define	SETCONTEXT	1
1197c478bdstevel@tonic-gate#define	GETUSTACK	2
1207c478bdstevel@tonic-gate#define	SETUSTACK	3
1217c478bdstevel@tonic-gate
1227c478bdstevel@tonic-gate/*
1237c478bdstevel@tonic-gate * values for uc_flags
1247c478bdstevel@tonic-gate * these are implementation dependent flags, that should be hidden
1257c478bdstevel@tonic-gate * from the user interface, defining which elements of ucontext
1267c478bdstevel@tonic-gate * are valid, and should be restored on call to setcontext
1277c478bdstevel@tonic-gate */
1287c478bdstevel@tonic-gate
1297c478bdstevel@tonic-gate#define	UC_SIGMASK	0x01
1307c478bdstevel@tonic-gate#define	UC_STACK	0x02
1317c478bdstevel@tonic-gate#define	UC_CPU		0x04
1327c478bdstevel@tonic-gate#define	UC_MAU		0x08
1337c478bdstevel@tonic-gate#define	UC_FPU		UC_MAU
1347c478bdstevel@tonic-gate#define	UC_INTR		0x10
1357c478bdstevel@tonic-gate#define	UC_ASR		0x20
1367c478bdstevel@tonic-gate
1377c478bdstevel@tonic-gate#define	UC_MCONTEXT	(UC_CPU|UC_FPU|UC_ASR)
1387c478bdstevel@tonic-gate
1397c478bdstevel@tonic-gate/*
1407c478bdstevel@tonic-gate * UC_ALL specifies the default context
1417c478bdstevel@tonic-gate */
1427c478bdstevel@tonic-gate
1437c478bdstevel@tonic-gate#define	UC_ALL		(UC_SIGMASK|UC_STACK|UC_MCONTEXT)
1447c478bdstevel@tonic-gate#endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
1457c478bdstevel@tonic-gate
1467c478bdstevel@tonic-gate#ifdef _KERNEL
147bdf0047Roger A. Faulknerextern void savecontext(ucontext_t *, const k_sigset_t *);
1487c478bdstevel@tonic-gateextern void restorecontext(ucontext_t *);
1497c478bdstevel@tonic-gate
1507c478bdstevel@tonic-gate#ifdef _SYSCALL32
151bdf0047Roger A. Faulknerextern void savecontext32(ucontext32_t *, const k_sigset_t *, struct fq32 *);
1527c478bdstevel@tonic-gate#endif
1537c478bdstevel@tonic-gate#endif
1547c478bdstevel@tonic-gate
1557c478bdstevel@tonic-gate#ifdef	__cplusplus
1567c478bdstevel@tonic-gate}
1577c478bdstevel@tonic-gate#endif
1587c478bdstevel@tonic-gate
1597c478bdstevel@tonic-gate#endif /* _SYS_UCONTEXT_H */
160