151791Smarcel/*- 251791Smarcel * Copyright (c) 1999 Marcel Moolenaar 351791Smarcel * All rights reserved. 451791Smarcel * 551791Smarcel * Redistribution and use in source and binary forms, with or without 651791Smarcel * modification, are permitted provided that the following conditions 751791Smarcel * are met: 851791Smarcel * 1. Redistributions of source code must retain the above copyright 951791Smarcel * notice, this list of conditions and the following disclaimer 1051791Smarcel * in this position and unchanged. 1151791Smarcel * 2. Redistributions in binary form must reproduce the above copyright 1251791Smarcel * notice, this list of conditions and the following disclaimer in the 1351791Smarcel * documentation and/or other materials provided with the distribution. 1451791Smarcel * 3. The name of the author may not be used to endorse or promote products 1551791Smarcel * derived from this software without specific prior written permission. 1651791Smarcel * 1751791Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1851791Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1951791Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2051791Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2151791Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2251791Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2351791Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2451791Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2551791Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2651791Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2751791Smarcel * 2851791Smarcel * $FreeBSD$ 2951791Smarcel */ 3051791Smarcel 3151791Smarcel#ifndef _SYS_UCONTEXT_H_ 3251942Smarcel#define _SYS_UCONTEXT_H_ 3351791Smarcel 34103411Smini#include <sys/signal.h> 3551791Smarcel#include <machine/ucontext.h> 3651791Smarcel 3751791Smarceltypedef struct __ucontext { 3851942Smarcel /* 3951980Smarcel * Keep the order of the first two fields. Also, 4051980Smarcel * keep them the first two fields in the structure. 4151942Smarcel * This way we can have a union with struct 4251942Smarcel * sigcontext and ucontext_t. This allows us to 4351942Smarcel * support them both at the same time. 4451942Smarcel * note: the union is not defined, though. 4551942Smarcel */ 4651942Smarcel sigset_t uc_sigmask; 4751942Smarcel mcontext_t uc_mcontext; 4851942Smarcel 4952140Sluoqi struct __ucontext *uc_link; 5051980Smarcel stack_t uc_stack; 51103411Smini int uc_flags; 52103411Smini#define UCF_SWAPPED 0x00000001 /* Used by swapcontext(3). */ 53103411Smini int __spare__[4]; 5451791Smarcel} ucontext_t; 5551791Smarcel 56105950Speter#if defined(_KERNEL) && defined(COMPAT_FREEBSD4) 57158471Sjhb#if defined(__i386__) 58105950Speterstruct ucontext4 { 59105950Speter sigset_t uc_sigmask; 60105950Speter struct mcontext4 uc_mcontext; 61105950Speter struct ucontext4 *uc_link; 62105950Speter stack_t uc_stack; 63105950Speter int __spare__[8]; 64105950Speter}; 65158471Sjhb#else /* __i386__ */ 66105950Speter#define ucontext4 ucontext 67158471Sjhb#endif /* __i386__ */ 68105950Speter#endif /* _KERNEL */ 69105950Speter 7089178Sdeischen#ifndef _KERNEL 71103068Sdfr 72103068Sdfr__BEGIN_DECLS 73103068Sdfr 74234785Sdimint getcontext(ucontext_t *) __returns_twice; 75230429Skibucontext_t *getcontextx(void); 7689178Sdeischenint setcontext(const ucontext_t *); 7789178Sdeischenvoid makecontext(ucontext_t *, void (*)(void), int, ...); 78103411Sminiint signalcontext(ucontext_t *, int, __sighandler_t *); 7989178Sdeischenint swapcontext(ucontext_t *, const ucontext_t *); 80103068Sdfr 81230429Skib#if __BSD_VISIBLE 82230864Skibint __getcontextx_size(void); 83251047Skibint __fillcontextx(char *ctx) __returns_twice; 84251047Skibint __fillcontextx2(char *ctx); 85230429Skib#endif 86230429Skib 87103068Sdfr__END_DECLS 88103068Sdfr 89106977Sdeischen#else /* _KERNEL */ 90106977Sdeischen 91106977Sdeischenstruct thread; 92106977Sdeischen 93122364Smarcel/* 94122364Smarcel * Flags for get_mcontext(). The low order 4 bits (i.e a mask of 0x0f) are 95122364Smarcel * reserved for use by machine independent code. All other bits are for use 96122364Smarcel * by machine dependent code. 97122364Smarcel */ 98122364Smarcel#define GET_MC_CLEAR_RET 1 99122364Smarcel 100106977Sdeischen/* Machine-dependent functions: */ 101122364Smarcelint get_mcontext(struct thread *, mcontext_t *, int); 102278347Skibint set_mcontext(struct thread *, mcontext_t *); 103106977Sdeischen 10489178Sdeischen#endif /* !_KERNEL */ 10589178Sdeischen 10651942Smarcel#endif /* !_SYS_UCONTEXT_H_ */ 107