xref: /minix3/sys/sys/ucontext.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
184d9c625SLionel Sambuc /*	$NetBSD: ucontext.h,v 1.18 2013/03/06 18:16:58 pooka Exp $	*/
2f6aac1c3SLionel Sambuc 
3f6aac1c3SLionel Sambuc /*-
4f6aac1c3SLionel Sambuc  * Copyright (c) 1999, 2003 The NetBSD Foundation, Inc.
5f6aac1c3SLionel Sambuc  * All rights reserved.
6f6aac1c3SLionel Sambuc  *
7f6aac1c3SLionel Sambuc  * This code is derived from software contributed to The NetBSD Foundation
8f6aac1c3SLionel Sambuc  * by Klaus Klein, and by Jason R. Thorpe.
9f6aac1c3SLionel Sambuc  *
10f6aac1c3SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
11f6aac1c3SLionel Sambuc  * modification, are permitted provided that the following conditions
12f6aac1c3SLionel Sambuc  * are met:
13f6aac1c3SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
14f6aac1c3SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
15f6aac1c3SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
16f6aac1c3SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
17f6aac1c3SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
18f6aac1c3SLionel Sambuc  *
19f6aac1c3SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20f6aac1c3SLionel Sambuc  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21f6aac1c3SLionel Sambuc  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22f6aac1c3SLionel Sambuc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23f6aac1c3SLionel Sambuc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24f6aac1c3SLionel Sambuc  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25f6aac1c3SLionel Sambuc  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26f6aac1c3SLionel Sambuc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27f6aac1c3SLionel Sambuc  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28f6aac1c3SLionel Sambuc  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29f6aac1c3SLionel Sambuc  * POSSIBILITY OF SUCH DAMAGE.
30f6aac1c3SLionel Sambuc  */
31f6aac1c3SLionel Sambuc 
32f6aac1c3SLionel Sambuc #ifndef _SYS_UCONTEXT_H_
33f6aac1c3SLionel Sambuc #define _SYS_UCONTEXT_H_
34f6aac1c3SLionel Sambuc 
35f6aac1c3SLionel Sambuc #include <sys/sigtypes.h>
36f6aac1c3SLionel Sambuc #include <machine/mcontext.h>
37f6aac1c3SLionel Sambuc 
38f6aac1c3SLionel Sambuc typedef struct __ucontext	ucontext_t;
39f6aac1c3SLionel Sambuc 
40f6aac1c3SLionel Sambuc struct __ucontext {
41f6aac1c3SLionel Sambuc 	unsigned int	uc_flags;	/* properties */
42f6aac1c3SLionel Sambuc 	ucontext_t * 	uc_link;	/* context to resume */
43f6aac1c3SLionel Sambuc 	sigset_t	uc_sigmask;	/* signals blocked in this context */
44f6aac1c3SLionel Sambuc 	stack_t		uc_stack;	/* the stack used by this context */
4517587738SBen Gras 	mcontext_t	uc_mcontext;	/* machine state */
46f6aac1c3SLionel Sambuc #if defined(_UC_MACHINE_PAD)
47f6aac1c3SLionel Sambuc 	long		__uc_pad[_UC_MACHINE_PAD];
48f6aac1c3SLionel Sambuc #endif
49f6aac1c3SLionel Sambuc };
50f6aac1c3SLionel Sambuc 
51f6aac1c3SLionel Sambuc #ifndef _UC_UCONTEXT_ALIGN
52f6aac1c3SLionel Sambuc #define _UC_UCONTEXT_ALIGN (~0)
53f6aac1c3SLionel Sambuc #endif
54f6aac1c3SLionel Sambuc 
5517587738SBen Gras /* uc_flags */
5617587738SBen Gras #define _UC_SIGMASK	0x01		/* valid uc_sigmask */
5717587738SBen Gras #define _UC_STACK	0x02		/* valid uc_stack */
5817587738SBen Gras #define _UC_CPU		0x04		/* valid GPR context in uc_mcontext */
5917587738SBen Gras #define _UC_FPU		0x08		/* valid FPU context in uc_mcontext */
6084d9c625SLionel Sambuc #if defined(__minix)
6117587738SBen Gras #define	_UC_SWAPPED	0x10000
6217587738SBen Gras #define _UC_IGNFPU      0x20000
6317587738SBen Gras #define _UC_IGNSIGM     0x40000
6484d9c625SLionel Sambuc #endif /* defined(__minix) */
6517587738SBen Gras #define	_UC_MD		0x400f0020	/* MD bits.  see below */
66f6aac1c3SLionel Sambuc 
6717587738SBen Gras /*
6817587738SBen Gras  * if your port needs more MD bits, please try to choose bits from _UC_MD
6917587738SBen Gras  * first, rather than picking random unused bits.
7017587738SBen Gras  *
7117587738SBen Gras  * _UC_MD details
7217587738SBen Gras  *
7317587738SBen Gras  * 	_UC_TLSBASE	Context contains valid pthread private pointer
7417587738SBen Gras  *			All ports must define this MD flag
7517587738SBen Gras  * 			0x00040000	hppa, mips
7617587738SBen Gras  * 			0x00000020	alpha
7717587738SBen Gras  *			0x00080000	all other ports
7817587738SBen Gras  *
7917587738SBen Gras  *	_UC_SETSTACK	Context uses signal stack
8017587738SBen Gras  *			0x00020000	arm
8117587738SBen Gras  *			[undefined]	alpha, powerpc and vax
8217587738SBen Gras  *			0x00010000	other ports
8317587738SBen Gras  *
8417587738SBen Gras  *	_UC_CLRSTACK	Context does not use signal stack
8517587738SBen Gras  *			0x00040000	arm
8617587738SBen Gras  *			[undefined]	alpha, powerpc and vax
8717587738SBen Gras  *			0x00020000	other ports
8817587738SBen Gras  *
8917587738SBen Gras  *	_UC_POWERPC_VEC Context does not use signal stack
9017587738SBen Gras  *			0x00010000	powerpc only
9117587738SBen Gras  *
9217587738SBen Gras  *	_UC_POWERPC_SPE	Context contains valid SPE context
9317587738SBen Gras  *			0x00020000	powerpc only
9417587738SBen Gras  *
9517587738SBen Gras  *	_UC_M68K_UC_USER Used by m68k machdep code, but undocumented
9617587738SBen Gras  *			0x40000000	m68k only
9717587738SBen Gras  *
9817587738SBen Gras  *	_UC_ARM_VFP	Unused
9917587738SBen Gras  *			0x00010000	arm only
10017587738SBen Gras  *
10117587738SBen Gras  *	_UC_VM		Context contains valid virtual 8086 context
10217587738SBen Gras  *			0x00040000	i386, amd64 only
10317587738SBen Gras  *
10417587738SBen Gras  *	_UC_FXSAVE	Context contains FPU context in that
10517587738SBen Gras  *			is in FXSAVE format in XMM space
10617587738SBen Gras  *			0x00000020	i386, amd64 only
10717587738SBen Gras  */
10817587738SBen Gras 
10917587738SBen Gras #ifdef _KERNEL
11017587738SBen Gras struct lwp;
11117587738SBen Gras 
11217587738SBen Gras void	getucontext(struct lwp *, ucontext_t *);
11317587738SBen Gras int	setucontext(struct lwp *, const ucontext_t *);
11417587738SBen Gras void	cpu_getmcontext(struct lwp *, mcontext_t *, unsigned int *);
11517587738SBen Gras int	cpu_setmcontext(struct lwp *, const mcontext_t *, unsigned int);
11617587738SBen Gras int	cpu_mcontext_validate(struct lwp *, const mcontext_t *);
11784d9c625SLionel Sambuc 
118*0a6a1f1dSLionel Sambuc #ifdef __UCONTEXT_SIZE
11984d9c625SLionel Sambuc __CTASSERT(sizeof(ucontext_t) == __UCONTEXT_SIZE);
12084d9c625SLionel Sambuc #endif
12117587738SBen Gras #endif /* _KERNEL */
122f6aac1c3SLionel Sambuc 
123*0a6a1f1dSLionel Sambuc #if defined(__minix)
124f6aac1c3SLionel Sambuc __BEGIN_DECLS
125f6aac1c3SLionel Sambuc void resumecontext(ucontext_t *ucp);
126f6aac1c3SLionel Sambuc 
127f6aac1c3SLionel Sambuc /* These functions get and set ucontext structure through PM/kernel. They don't
128f6aac1c3SLionel Sambuc  * manipulate the stack. */
129f6aac1c3SLionel Sambuc int getuctx(ucontext_t *ucp);
130f6aac1c3SLionel Sambuc int setuctx(const ucontext_t *ucp);
131f6aac1c3SLionel Sambuc __END_DECLS
132*0a6a1f1dSLionel Sambuc #endif /* defined(__minix) */
133f6aac1c3SLionel Sambuc 
134f6aac1c3SLionel Sambuc #endif /* !_SYS_UCONTEXT_H_ */
135