xref: /netbsd/sys/sys/ucontext.h (revision 3a7634de)
1 /*	$NetBSD: ucontext.h,v 1.19 2018/02/27 23:09:02 uwe Exp $	*/
2 
3 /*-
4  * Copyright (c) 1999, 2003 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Klaus Klein, and by Jason R. Thorpe.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _SYS_UCONTEXT_H_
33 #define _SYS_UCONTEXT_H_
34 
35 #include <sys/sigtypes.h>
36 #include <machine/mcontext.h>
37 
38 typedef struct __ucontext	ucontext_t;
39 
40 struct __ucontext {
41 	unsigned int	uc_flags;	/* properties */
42 	ucontext_t * 	uc_link;	/* context to resume */
43 	sigset_t	uc_sigmask;	/* signals blocked in this context */
44 	stack_t		uc_stack;	/* the stack used by this context */
45 	mcontext_t	uc_mcontext;	/* machine state */
46 #if defined(_UC_MACHINE_PAD)
47 	long		__uc_pad[_UC_MACHINE_PAD];
48 #endif
49 };
50 
51 #ifndef _UC_UCONTEXT_ALIGN
52 #define _UC_UCONTEXT_ALIGN (~0)
53 #endif
54 
55 /* uc_flags */
56 #define _UC_SIGMASK	0x01		/* valid uc_sigmask */
57 #define _UC_STACK	0x02		/* valid uc_stack */
58 #define _UC_CPU		0x04		/* valid GPR context in uc_mcontext */
59 #define _UC_FPU		0x08		/* valid FPU context in uc_mcontext */
60 #define	_UC_MD		0x400f0020	/* MD bits.  see below */
61 
62 /*
63  * if your port needs more MD bits, please try to choose bits from _UC_MD
64  * first, rather than picking random unused bits.
65  *
66  * _UC_MD details
67  *
68  * 	_UC_TLSBASE	Context contains valid pthread private pointer
69  *			All ports must define this MD flag
70  * 			0x00040000	hppa, mips
71  * 			0x00000020	alpha
72  *			0x00080000	all other ports
73  *
74  *	_UC_SETSTACK	Context uses signal stack
75  *			0x00020000	arm
76  *			[undefined]	alpha, powerpc and vax
77  *			0x00010000	other ports
78  *
79  *	_UC_CLRSTACK	Context does not use signal stack
80  *			0x00040000	arm
81  *			[undefined]	alpha, powerpc and vax
82  *			0x00020000	other ports
83  *
84  *	_UC_POWERPC_VEC Context contains valid AltiVec context
85  *			0x00010000	powerpc only
86  *
87  *	_UC_POWERPC_SPE	Context contains valid SPE context
88  *			0x00020000	powerpc only
89  *
90  *	_UC_M68K_UC_USER Used by m68k machdep code, but undocumented
91  *			0x40000000	m68k only
92  *
93  *	_UC_ARM_VFP	Unused
94  *			0x00010000	arm only
95  *
96  *	_UC_VM		Context contains valid virtual 8086 context
97  *			0x00040000	i386, amd64 only
98  *
99  *	_UC_FXSAVE	Context contains FPU context in that
100  *			is in FXSAVE format in XMM space
101  *			0x00000020	i386, amd64 only
102  */
103 
104 #ifdef _KERNEL
105 struct lwp;
106 
107 void	getucontext(struct lwp *, ucontext_t *);
108 int	setucontext(struct lwp *, const ucontext_t *);
109 void	cpu_getmcontext(struct lwp *, mcontext_t *, unsigned int *);
110 int	cpu_setmcontext(struct lwp *, const mcontext_t *, unsigned int);
111 int	cpu_mcontext_validate(struct lwp *, const mcontext_t *);
112 
113 #ifdef __UCONTEXT_SIZE
114 __CTASSERT(sizeof(ucontext_t) == __UCONTEXT_SIZE);
115 #endif
116 #endif /* _KERNEL */
117 
118 #endif /* !_SYS_UCONTEXT_H_ */
119