1*3a7634deSuwe /* $NetBSD: ucontext.h,v 1.19 2018/02/27 23:09:02 uwe Exp $ */ 2b78f59b4Sthorpej 3b78f59b4Sthorpej /*- 4b78f59b4Sthorpej * Copyright (c) 1999, 2003 The NetBSD Foundation, Inc. 5b78f59b4Sthorpej * All rights reserved. 6b78f59b4Sthorpej * 7b78f59b4Sthorpej * This code is derived from software contributed to The NetBSD Foundation 8b78f59b4Sthorpej * by Klaus Klein, and by Jason R. Thorpe. 9b78f59b4Sthorpej * 10b78f59b4Sthorpej * Redistribution and use in source and binary forms, with or without 11b78f59b4Sthorpej * modification, are permitted provided that the following conditions 12b78f59b4Sthorpej * are met: 13b78f59b4Sthorpej * 1. Redistributions of source code must retain the above copyright 14b78f59b4Sthorpej * notice, this list of conditions and the following disclaimer. 15b78f59b4Sthorpej * 2. Redistributions in binary form must reproduce the above copyright 16b78f59b4Sthorpej * notice, this list of conditions and the following disclaimer in the 17b78f59b4Sthorpej * documentation and/or other materials provided with the distribution. 18b78f59b4Sthorpej * 19b78f59b4Sthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20b78f59b4Sthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21b78f59b4Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22b78f59b4Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23b78f59b4Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24b78f59b4Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25b78f59b4Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26b78f59b4Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27b78f59b4Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28b78f59b4Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29b78f59b4Sthorpej * POSSIBILITY OF SUCH DAMAGE. 30b78f59b4Sthorpej */ 31b78f59b4Sthorpej 32b78f59b4Sthorpej #ifndef _SYS_UCONTEXT_H_ 33b78f59b4Sthorpej #define _SYS_UCONTEXT_H_ 34b78f59b4Sthorpej 35b78f59b4Sthorpej #include <sys/sigtypes.h> 36b78f59b4Sthorpej #include <machine/mcontext.h> 37b78f59b4Sthorpej 38b78f59b4Sthorpej typedef struct __ucontext ucontext_t; 39b78f59b4Sthorpej 40b78f59b4Sthorpej struct __ucontext { 41b78f59b4Sthorpej unsigned int uc_flags; /* properties */ 42b78f59b4Sthorpej ucontext_t * uc_link; /* context to resume */ 43b78f59b4Sthorpej sigset_t uc_sigmask; /* signals blocked in this context */ 44b78f59b4Sthorpej stack_t uc_stack; /* the stack used by this context */ 45b78f59b4Sthorpej mcontext_t uc_mcontext; /* machine state */ 46b78f59b4Sthorpej #if defined(_UC_MACHINE_PAD) 47b78f59b4Sthorpej long __uc_pad[_UC_MACHINE_PAD]; 48b78f59b4Sthorpej #endif 49b78f59b4Sthorpej }; 50b78f59b4Sthorpej 5138cf5bc3Schs #ifndef _UC_UCONTEXT_ALIGN 5238cf5bc3Schs #define _UC_UCONTEXT_ALIGN (~0) 5338cf5bc3Schs #endif 5438cf5bc3Schs 55b78f59b4Sthorpej /* uc_flags */ 56b78f59b4Sthorpej #define _UC_SIGMASK 0x01 /* valid uc_sigmask */ 57b78f59b4Sthorpej #define _UC_STACK 0x02 /* valid uc_stack */ 58b78f59b4Sthorpej #define _UC_CPU 0x04 /* valid GPR context in uc_mcontext */ 59b78f59b4Sthorpej #define _UC_FPU 0x08 /* valid FPU context in uc_mcontext */ 602332652fSmanu #define _UC_MD 0x400f0020 /* MD bits. see below */ 61e0d891d6Syamt 62e0d891d6Syamt /* 63e0d891d6Syamt * if your port needs more MD bits, please try to choose bits from _UC_MD 64e0d891d6Syamt * first, rather than picking random unused bits. 652332652fSmanu * 662332652fSmanu * _UC_MD details 672332652fSmanu * 682332652fSmanu * _UC_TLSBASE Context contains valid pthread private pointer 692332652fSmanu * All ports must define this MD flag 702332652fSmanu * 0x00040000 hppa, mips 712332652fSmanu * 0x00000020 alpha 722332652fSmanu * 0x00080000 all other ports 732332652fSmanu * 742332652fSmanu * _UC_SETSTACK Context uses signal stack 752332652fSmanu * 0x00020000 arm 762332652fSmanu * [undefined] alpha, powerpc and vax 772332652fSmanu * 0x00010000 other ports 782332652fSmanu * 792332652fSmanu * _UC_CLRSTACK Context does not use signal stack 802332652fSmanu * 0x00040000 arm 812332652fSmanu * [undefined] alpha, powerpc and vax 822332652fSmanu * 0x00020000 other ports 832332652fSmanu * 84*3a7634deSuwe * _UC_POWERPC_VEC Context contains valid AltiVec context 852332652fSmanu * 0x00010000 powerpc only 862332652fSmanu * 872332652fSmanu * _UC_POWERPC_SPE Context contains valid SPE context 882332652fSmanu * 0x00020000 powerpc only 892332652fSmanu * 902332652fSmanu * _UC_M68K_UC_USER Used by m68k machdep code, but undocumented 912332652fSmanu * 0x40000000 m68k only 922332652fSmanu * 932332652fSmanu * _UC_ARM_VFP Unused 942332652fSmanu * 0x00010000 arm only 952332652fSmanu * 962332652fSmanu * _UC_VM Context contains valid virtual 8086 context 972332652fSmanu * 0x00040000 i386, amd64 only 982332652fSmanu * 992332652fSmanu * _UC_FXSAVE Context contains FPU context in that 1002332652fSmanu * is in FXSAVE format in XMM space 1012332652fSmanu * 0x00000020 i386, amd64 only 102e0d891d6Syamt */ 103b78f59b4Sthorpej 104b78f59b4Sthorpej #ifdef _KERNEL 105b78f59b4Sthorpej struct lwp; 106ffc3f24bSkleink 107b78f59b4Sthorpej void getucontext(struct lwp *, ucontext_t *); 108b78f59b4Sthorpej int setucontext(struct lwp *, const ucontext_t *); 109b78f59b4Sthorpej void cpu_getmcontext(struct lwp *, mcontext_t *, unsigned int *); 110b78f59b4Sthorpej int cpu_setmcontext(struct lwp *, const mcontext_t *, unsigned int); 1117a8d7e23Smartin int cpu_mcontext_validate(struct lwp *, const mcontext_t *); 112a48f5177Spooka 113a48f5177Spooka #ifdef __UCONTEXT_SIZE 114a48f5177Spooka __CTASSERT(sizeof(ucontext_t) == __UCONTEXT_SIZE); 115a48f5177Spooka #endif 116b78f59b4Sthorpej #endif /* _KERNEL */ 117b78f59b4Sthorpej 118b78f59b4Sthorpej #endif /* !_SYS_UCONTEXT_H_ */ 119