signal.h revision 1.17
11.17Sagc/*	$NetBSD: signal.h,v 1.17 2003/08/07 16:28:00 agc Exp $	*/
21.3Scgd
31.1Sbrezak/*
41.1Sbrezak * Copyright (c) 1982, 1986, 1989, 1991 Regents of the University of California.
51.1Sbrezak * All rights reserved.
61.1Sbrezak *
71.1Sbrezak * Redistribution and use in source and binary forms, with or without
81.1Sbrezak * modification, are permitted provided that the following conditions
91.1Sbrezak * are met:
101.1Sbrezak * 1. Redistributions of source code must retain the above copyright
111.1Sbrezak *    notice, this list of conditions and the following disclaimer.
121.1Sbrezak * 2. Redistributions in binary form must reproduce the above copyright
131.1Sbrezak *    notice, this list of conditions and the following disclaimer in the
141.1Sbrezak *    documentation and/or other materials provided with the distribution.
151.17Sagc * 3. Neither the name of the University nor the names of its contributors
161.1Sbrezak *    may be used to endorse or promote products derived from this software
171.1Sbrezak *    without specific prior written permission.
181.1Sbrezak *
191.1Sbrezak * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
201.1Sbrezak * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
211.1Sbrezak * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
221.1Sbrezak * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
231.1Sbrezak * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
241.1Sbrezak * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
251.1Sbrezak * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
261.1Sbrezak * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
271.1Sbrezak * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
281.1Sbrezak * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
291.1Sbrezak * SUCH DAMAGE.
301.1Sbrezak *
311.3Scgd *	@(#)signal.h	7.16 (Berkeley) 3/17/91
321.1Sbrezak */
331.1Sbrezak
341.2Smycroft#ifndef _I386_SIGNAL_H_
351.2Smycroft#define _I386_SIGNAL_H_
361.1Sbrezak
371.16Sbjh21#include <sys/featuretest.h>
381.16Sbjh21
391.1Sbrezaktypedef int sig_atomic_t;
401.1Sbrezak
411.16Sbjh21#if defined(_NETBSD_SOURCE)
421.1Sbrezak/*
431.1Sbrezak * Get the "code" values
441.1Sbrezak */
451.1Sbrezak#include <machine/trap.h>
461.1Sbrezak
471.1Sbrezak/*
481.1Sbrezak * Information pushed on stack when a signal is delivered.
491.1Sbrezak * This is used by the kernel to restore state following
501.1Sbrezak * execution of the signal handler.  It is also made available
511.1Sbrezak * to the handler to allow it to restore state properly if
521.1Sbrezak * a non-standard exit is performed.
531.1Sbrezak */
541.12Sthorpej#if defined(__LIBC12_SOURCE__) || defined(_KERNEL)
551.10Smycroftstruct sigcontext13 {
561.5Smycroft	int	sc_gs;
571.5Smycroft	int	sc_fs;
581.2Smycroft	int	sc_es;
591.2Smycroft	int	sc_ds;
601.2Smycroft	int	sc_edi;
611.2Smycroft	int	sc_esi;
621.2Smycroft	int	sc_ebp;
631.2Smycroft	int	sc_ebx;
641.2Smycroft	int	sc_edx;
651.2Smycroft	int	sc_ecx;
661.2Smycroft	int	sc_eax;
671.6Smycroft	/* XXX */
681.2Smycroft	int	sc_eip;
691.2Smycroft	int	sc_cs;
701.2Smycroft	int	sc_eflags;
711.2Smycroft	int	sc_esp;
721.2Smycroft	int	sc_ss;
731.5Smycroft
741.5Smycroft	int	sc_onstack;		/* sigstack state to restore */
751.13Sthorpej	int	sc_mask;		/* signal mask to restore (old style) */
761.6Smycroft
771.6Smycroft	int	sc_trapno;		/* XXX should be above */
781.6Smycroft	int	sc_err;
791.10Smycroft};
801.10Smycroft#endif
811.9Smycroft
821.10Smycroftstruct sigcontext {
831.10Smycroft	int	sc_gs;
841.10Smycroft	int	sc_fs;
851.10Smycroft	int	sc_es;
861.10Smycroft	int	sc_ds;
871.10Smycroft	int	sc_edi;
881.10Smycroft	int	sc_esi;
891.10Smycroft	int	sc_ebp;
901.10Smycroft	int	sc_ebx;
911.10Smycroft	int	sc_edx;
921.10Smycroft	int	sc_ecx;
931.10Smycroft	int	sc_eax;
941.10Smycroft	/* XXX */
951.10Smycroft	int	sc_eip;
961.10Smycroft	int	sc_cs;
971.10Smycroft	int	sc_eflags;
981.10Smycroft	int	sc_esp;
991.10Smycroft	int	sc_ss;
1001.10Smycroft
1011.10Smycroft	int	sc_onstack;		/* sigstack state to restore */
1021.14Sthorpej	int	__sc_mask13;		/* signal mask to restore (old style) */
1031.10Smycroft
1041.10Smycroft	int	sc_trapno;		/* XXX should be above */
1051.10Smycroft	int	sc_err;
1061.10Smycroft
1071.10Smycroft	sigset_t sc_mask;		/* signal mask to restore (new style) */
1081.1Sbrezak};
1091.15Sthorpej
1101.15Sthorpej/*
1111.15Sthorpej * The following macros are used to convert from a ucontext to sigcontext,
1121.15Sthorpej * and vice-versa.  This is for building a sigcontext to deliver to old-style
1131.15Sthorpej * signal handlers, and converting back (in the event the handler modifies
1141.15Sthorpej * the context).
1151.15Sthorpej */
1161.15Sthorpej#define	_MCONTEXT_TO_SIGCONTEXT(uc, sc)					\
1171.15Sthorpejdo {									\
1181.15Sthorpej	(sc)->sc_gs  = (uc)->uc_mcontext.__gregs[_REG_GS];		\
1191.15Sthorpej	(sc)->sc_fs  = (uc)->uc_mcontext.__gregs[_REG_FS];		\
1201.15Sthorpej	(sc)->sc_es  = (uc)->uc_mcontext.__gregs[_REG_ES];		\
1211.15Sthorpej	(sc)->sc_ds  = (uc)->uc_mcontext.__gregs[_REG_DS];		\
1221.15Sthorpej	(sc)->sc_edi = (uc)->uc_mcontext.__gregs[_REG_EDI];		\
1231.15Sthorpej	(sc)->sc_esi = (uc)->uc_mcontext.__gregs[_REG_ESI];		\
1241.15Sthorpej	(sc)->sc_ebp = (uc)->uc_mcontext.__gregs[_REG_EBP];		\
1251.15Sthorpej	(sc)->sc_ebx = (uc)->uc_mcontext.__gregs[_REG_EBX];		\
1261.15Sthorpej	(sc)->sc_edx = (uc)->uc_mcontext.__gregs[_REG_EDX];		\
1271.15Sthorpej	(sc)->sc_ecx = (uc)->uc_mcontext.__gregs[_REG_ECX];		\
1281.15Sthorpej	(sc)->sc_eax = (uc)->uc_mcontext.__gregs[_REG_EAX];		\
1291.15Sthorpej	(sc)->sc_eip = (uc)->uc_mcontext.__gregs[_REG_EIP];		\
1301.15Sthorpej	(sc)->sc_cs  = (uc)->uc_mcontext.__gregs[_REG_CS];		\
1311.15Sthorpej	(sc)->sc_eflags = (uc)->uc_mcontext.__gregs[_REG_EFL];		\
1321.15Sthorpej	(sc)->sc_esp = (uc)->uc_mcontext.__gregs[_REG_UESP];		\
1331.15Sthorpej	(sc)->sc_ss  = (uc)->uc_mcontext.__gregs[_REG_SS];		\
1341.15Sthorpej	(sc)->sc_trapno = (uc)->uc_mcontext.__gregs[_REG_TRAPNO];	\
1351.15Sthorpej	(sc)->sc_err = (uc)->uc_mcontext.__gregs[_REG_ERR];		\
1361.15Sthorpej} while (/*CONSTCOND*/0)
1371.15Sthorpej
1381.15Sthorpej#define	_SIGCONTEXT_TO_MCONTEXT(sc, uc)					\
1391.15Sthorpejdo {									\
1401.15Sthorpej	(uc)->uc_mcontext.__gregs[_REG_GS]  = (sc)->sc_gs;		\
1411.15Sthorpej	(uc)->uc_mcontext.__gregs[_REG_FS]  = (sc)->sc_fs;		\
1421.15Sthorpej	(uc)->uc_mcontext.__gregs[_REG_ES]  = (sc)->sc_es;		\
1431.15Sthorpej	(uc)->uc_mcontext.__gregs[_REG_DS]  = (sc)->sc_ds;		\
1441.15Sthorpej	(uc)->uc_mcontext.__gregs[_REG_EDI] = (sc)->sc_edi;		\
1451.15Sthorpej	(uc)->uc_mcontext.__gregs[_REG_ESI] = (sc)->sc_esi;		\
1461.15Sthorpej	(uc)->uc_mcontext.__gregs[_REG_EBP] = (sc)->sc_ebp;		\
1471.15Sthorpej	(uc)->uc_mcontext.__gregs[_REG_EBX] = (sc)->sc_ebx;		\
1481.15Sthorpej	(uc)->uc_mcontext.__gregs[_REG_EDX] = (sc)->sc_edx;		\
1491.15Sthorpej	(uc)->uc_mcontext.__gregs[_REG_ECX] = (sc)->sc_ecx;		\
1501.15Sthorpej	(uc)->uc_mcontext.__gregs[_REG_EAX] = (sc)->sc_eax;		\
1511.15Sthorpej	(uc)->uc_mcontext.__gregs[_REG_EIP] = (sc)->sc_eip;		\
1521.15Sthorpej	(uc)->uc_mcontext.__gregs[_REG_CS]  = (sc)->sc_cs;		\
1531.15Sthorpej	(uc)->uc_mcontext.__gregs[_REG_EFL] = (sc)->sc_eflags;		\
1541.15Sthorpej	(uc)->uc_mcontext.__gregs[_REG_UESP] = (sc)->sc_esp;		\
1551.15Sthorpej	(uc)->uc_mcontext.__gregs[_REG_UESP] = (sc)->sc_esp;		\
1561.15Sthorpej	(uc)->uc_mcontext.__gregs[_REG_SS]  = (sc)->sc_ss;		\
1571.15Sthorpej	(uc)->uc_mcontext.__gregs[_REG_TRAPNO] = (sc)->sc_trapno;	\
1581.15Sthorpej	(uc)->uc_mcontext.__gregs[_REG_ERR] = (sc)->sc_err;		\
1591.15Sthorpej} while (/*CONSTCOND*/0)
1601.1Sbrezak
1611.1Sbrezak#define sc_sp sc_esp
1621.1Sbrezak#define sc_fp sc_ebp
1631.1Sbrezak#define sc_pc sc_eip
1641.2Smycroft#define sc_ps sc_eflags
1651.1Sbrezak
1661.16Sbjh21#endif	/* _NETBSD_SOURCE */
1671.4Sjtc#endif	/* !_I386_SIGNAL_H_ */
168