Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/nathanw_sa]: src/sys * Include <sys/sigtypes.h> rather than <sys/signal....
details: https://anonhg.NetBSD.org/src/rev/9e1fb99da0d2
branches: nathanw_sa
changeset: 506756:9e1fb99da0d2
user: thorpej <thorpej%NetBSD.org@localhost>
date: Thu Jan 16 03:14:50 2003 +0000
description:
* Include <sys/sigtypes.h> rather than <sys/signal.h> in <sys/ucontext.h>.
* Define _UCONTEXT_TO_SIGCONTEXT() and _SIGCONTEXT_TO_UCONTEXT()
macros for converting a ucontext -> sigcontext and back again.
These macros in turn use machine-dependent macros _MCONTEXT_TO_SIGCONTEXT()
and _SIGCONTEXT_TO_MCONTEXT() provided by <machine/signal.h>.
The conversion process is not 100% accurate, but should be close enough.
Also note that the mcontext conversion may not be enough for all platforms
(m68k is a good example of this). These macros should be used only if
you really know what you're doing.
diffstat:
sys/arch/alpha/include/signal.h | 40 ++++++++++-
sys/arch/arm/include/signal.h | 25 ++++++-
sys/arch/i386/include/signal.h | 53 ++++++++++++++-
sys/arch/m68k/include/signal.h | 106 ++++++++++++++++++++++++++++-
sys/arch/mips/include/signal.h | 47 ++++++++++++-
sys/arch/powerpc/include/signal.h | 37 +++++++++-
sys/arch/sh3/include/signal.h | 138 ++++++++++++++++++++++++++++++++++++++
sys/arch/sparc/include/signal.h | 50 +++++++++++++-
sys/arch/vax/include/signal.h | 26 ++++++-
sys/sys/ucontext.h | 48 +++++++++++-
10 files changed, 554 insertions(+), 16 deletions(-)
diffs (truncated from 717 to 300 lines):
diff -r edc06dd935af -r 9e1fb99da0d2 sys/arch/alpha/include/signal.h
--- a/sys/arch/alpha/include/signal.h Thu Jan 16 03:07:47 2003 +0000
+++ b/sys/arch/alpha/include/signal.h Thu Jan 16 03:14:50 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: signal.h,v 1.5 1998/09/13 01:51:30 thorpej Exp $ */
+/* $NetBSD: signal.h,v 1.5.24.1 2003/01/16 03:14:50 thorpej Exp $ */
/*
* Copyright (c) 1994, 1995 Carnegie-Mellon University.
@@ -77,5 +77,43 @@
sigset_t sc_mask; /* signal mask to restore (new style) */
};
+/*
+ * The following macros are used to convert from a ucontext to sigcontext,
+ * and vice-versa. This is for building a sigcontext to deliver to old-style
+ * signal handlers, and converting back (in the event the handler modifies
+ * the context).
+ */
+#define _MCONTEXT_TO_SIGCONTEXT(uc, sc) \
+do { \
+ (sc)->sc_pc = (uc)->uc_mcontext.__gregs[_REG_PC]; \
+ (sc)->sc_ps = (uc)->uc_mcontext.__gregs[_REG_PS]; \
+ memcpy(&(sc)->sc_regs, &(uc)->uc_mcontext.__gregs, \
+ 31 * sizeof(unsigned long)); \
+ if ((uc)->uc_flags & _UC_FPU) { \
+ (sc)->sc_ownedfp = 1; \
+ memcpy(&(sc)->sc_fpregs, \
+ &(uc)->uc_mcontext.__fpregs.__fp_fr, \
+ 31 * sizeof(unsigned long)); \
+ (sc)->sc_fpcr = (uc)->uc_mcontext.__fpregs.__fp_fpcr; \
+ /* XXX sc_fp_control */ \
+ } else \
+ (sc)->sc_ownedfp = 0; \
+} while (/*CONSTCOND*/0)
+
+#define _SIGCONTEXT_TO_MCONTEXT(sc, uc) \
+do { \
+ (uc)->uc_mcontext.__gregs[_REG_PC] = (sc)->sc_pc; \
+ (uc)->uc_mcontext.__gregs[_REG_PS] = (sc)->sc_ps; \
+ memcpy(&(uc)->uc_mcontext.__gregs, &(sc)->sc_regs, \
+ 31 * sizeof(unsigned long)); \
+ if ((sc)->sc_ownedfp) { \
+ memcpy(&(uc)->uc_mcontext.__fpregs.__fp_fr, \
+ &(sc)->sc_fpregs, 31 * sizeof(unsigned long)); \
+ (sc)->sc_fpcr = (uc)->uc_mcontext.__fpregs.__fp_fpcr; \
+ /* XXX sc_fp_control */ \
+ (uc)->uc_flags |= _UC_FPU; \
+ } \
+} while (/*CONSTCOND*/0)
+
#endif /* !_ANSI_SOURCE && !_POSIX_C_SOURCE && !_XOPEN_SOURCE */
#endif /* !_ALPHA_SIGNAL_H_*/
diff -r edc06dd935af -r 9e1fb99da0d2 sys/arch/arm/include/signal.h
--- a/sys/arch/arm/include/signal.h Thu Jan 16 03:07:47 2003 +0000
+++ b/sys/arch/arm/include/signal.h Thu Jan 16 03:14:50 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: signal.h,v 1.1 2001/01/13 17:02:37 bjh21 Exp $ */
+/* $NetBSD: signal.h,v 1.1.10.1 2003/01/16 03:14:53 thorpej Exp $ */
/*
* Copyright (c) 1994-1996 Mark Brinicombe.
@@ -113,6 +113,29 @@
sigset_t sc_mask; /* signal mask to restore (new style) */
};
+/*
+ * The following macros are used to convert from a ucontext to sigcontext,
+ * and vice-versa. This is for building a sigcontext to deliver to old-style
+ * signal handlers, and converting back (in the event the handler modifies
+ * the context).
+ */
+#define _MCONTEXT_TO_SIGCONTEXT(uc, sc) \
+do { \
+ (sc)->sc_spsr = (uc)->uc_mcontext.__gregs[_REG_CPSR]; \
+ memcpy(&(sc)->sc_r0, (uc)->uc_mcontext.__gregs, \
+ 15 * sizeof(unsigned int)); \
+ (sc)->sc_svc_lr = 0; /* XXX */ \
+ (sc)->sc_pc = (uc)->uc_mcontext.__gregs[_REG_PC]; \
+} while (/*CONSTCOND*/0)
+
+#define _SIGCONTEXT_TO_MCONTEXT(sc, uc) \
+do { \
+ (uc)->uc_mcontext.__gregs[_REG_CPSR] = (sc)->sc_spsr; \
+ memcpy((uc)->uc_mcontext.__gregs, &(sc)->sc_r0, \
+ 15 * sizeof(unsigned int)); \
+ (uc)->uc_mcontext.__gregs[_REG_PC] = (sc)->sc_pc; \
+} while (/*CONSTCOND*/0)
+
#endif /* !_LOCORE */
/* Signals codes */
diff -r edc06dd935af -r 9e1fb99da0d2 sys/arch/i386/include/signal.h
--- a/sys/arch/i386/include/signal.h Thu Jan 16 03:07:47 2003 +0000
+++ b/sys/arch/i386/include/signal.h Thu Jan 16 03:14:50 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: signal.h,v 1.14 1998/09/14 02:50:12 thorpej Exp $ */
+/* $NetBSD: signal.h,v 1.14.26.1 2003/01/16 03:14:53 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1991 Regents of the University of California.
@@ -110,6 +110,57 @@
sigset_t sc_mask; /* signal mask to restore (new style) */
};
+/*
+ * The following macros are used to convert from a ucontext to sigcontext,
+ * and vice-versa. This is for building a sigcontext to deliver to old-style
+ * signal handlers, and converting back (in the event the handler modifies
+ * the context).
+ */
+#define _MCONTEXT_TO_SIGCONTEXT(uc, sc) \
+do { \
+ (sc)->sc_gs = (uc)->uc_mcontext.__gregs[_REG_GS]; \
+ (sc)->sc_fs = (uc)->uc_mcontext.__gregs[_REG_FS]; \
+ (sc)->sc_es = (uc)->uc_mcontext.__gregs[_REG_ES]; \
+ (sc)->sc_ds = (uc)->uc_mcontext.__gregs[_REG_DS]; \
+ (sc)->sc_edi = (uc)->uc_mcontext.__gregs[_REG_EDI]; \
+ (sc)->sc_esi = (uc)->uc_mcontext.__gregs[_REG_ESI]; \
+ (sc)->sc_ebp = (uc)->uc_mcontext.__gregs[_REG_EBP]; \
+ (sc)->sc_ebx = (uc)->uc_mcontext.__gregs[_REG_EBX]; \
+ (sc)->sc_edx = (uc)->uc_mcontext.__gregs[_REG_EDX]; \
+ (sc)->sc_ecx = (uc)->uc_mcontext.__gregs[_REG_ECX]; \
+ (sc)->sc_eax = (uc)->uc_mcontext.__gregs[_REG_EAX]; \
+ (sc)->sc_eip = (uc)->uc_mcontext.__gregs[_REG_EIP]; \
+ (sc)->sc_cs = (uc)->uc_mcontext.__gregs[_REG_CS]; \
+ (sc)->sc_eflags = (uc)->uc_mcontext.__gregs[_REG_EFL]; \
+ (sc)->sc_esp = (uc)->uc_mcontext.__gregs[_REG_UESP]; \
+ (sc)->sc_ss = (uc)->uc_mcontext.__gregs[_REG_SS]; \
+ (sc)->sc_trapno = (uc)->uc_mcontext.__gregs[_REG_TRAPNO]; \
+ (sc)->sc_err = (uc)->uc_mcontext.__gregs[_REG_ERR]; \
+} while (/*CONSTCOND*/0)
+
+#define _SIGCONTEXT_TO_MCONTEXT(sc, uc) \
+do { \
+ (uc)->uc_mcontext.__gregs[_REG_GS] = (sc)->sc_gs; \
+ (uc)->uc_mcontext.__gregs[_REG_FS] = (sc)->sc_fs; \
+ (uc)->uc_mcontext.__gregs[_REG_ES] = (sc)->sc_es; \
+ (uc)->uc_mcontext.__gregs[_REG_DS] = (sc)->sc_ds; \
+ (uc)->uc_mcontext.__gregs[_REG_EDI] = (sc)->sc_edi; \
+ (uc)->uc_mcontext.__gregs[_REG_ESI] = (sc)->sc_esi; \
+ (uc)->uc_mcontext.__gregs[_REG_EBP] = (sc)->sc_ebp; \
+ (uc)->uc_mcontext.__gregs[_REG_EBX] = (sc)->sc_ebx; \
+ (uc)->uc_mcontext.__gregs[_REG_EDX] = (sc)->sc_edx; \
+ (uc)->uc_mcontext.__gregs[_REG_ECX] = (sc)->sc_ecx; \
+ (uc)->uc_mcontext.__gregs[_REG_EAX] = (sc)->sc_eax; \
+ (uc)->uc_mcontext.__gregs[_REG_EIP] = (sc)->sc_eip; \
+ (uc)->uc_mcontext.__gregs[_REG_CS] = (sc)->sc_cs; \
+ (uc)->uc_mcontext.__gregs[_REG_EFL] = (sc)->sc_eflags; \
+ (uc)->uc_mcontext.__gregs[_REG_UESP] = (sc)->sc_esp; \
+ (uc)->uc_mcontext.__gregs[_REG_UESP] = (sc)->sc_esp; \
+ (uc)->uc_mcontext.__gregs[_REG_SS] = (sc)->sc_ss; \
+ (uc)->uc_mcontext.__gregs[_REG_TRAPNO] = (sc)->sc_trapno; \
+ (uc)->uc_mcontext.__gregs[_REG_ERR] = (sc)->sc_err; \
+} while (/*CONSTCOND*/0)
+
#define sc_sp sc_esp
#define sc_fp sc_ebp
#define sc_pc sc_eip
diff -r edc06dd935af -r 9e1fb99da0d2 sys/arch/m68k/include/signal.h
--- a/sys/arch/m68k/include/signal.h Thu Jan 16 03:07:47 2003 +0000
+++ b/sys/arch/m68k/include/signal.h Thu Jan 16 03:14:50 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: signal.h,v 1.8.30.1 2002/08/01 02:42:15 nathanw Exp $ */
+/* $NetBSD: signal.h,v 1.8.30.2 2003/01/16 03:14:55 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1991 Regents of the University of California.
@@ -77,7 +77,32 @@
sigset_t sc_mask; /* signal mask to restore (new style) */
};
-#if defined(_KERNEL) && defined(__M68K_SIGNAL_PRIVATE)
+/*
+ * The following macros are used to convert from a ucontext to sigcontext,
+ * and vice-versa. This is for building a sigcontext to deliver to old-style
+ * signal handlers, and converting back (in the event the handler modifies
+ * the context).
+ *
+ * On m68k, we also need the sigstate conversion macros below.
+ */
+#define _MCONTEXT_TO_SIGCONTEXT(uc, sc) \
+do { \
+ (sc)->sc_sp = (uc)->uc_mcontext.__gregs[_REG_A7]; \
+ (sc)->sc_fp = (uc)->uc_mcontext.__gregs[_REG_A6]; \
+ /* sc_ap points to sigstate */ \
+ (sc)->sc_pc = (uc)->uc_mcontext.__gregs[_REG_PC]; \
+ (sc)->sc_ps = (uc)->uc_mcontext.__gregs[_REG_PS]; \
+} while (/*CONSTCOND*/0)
+
+#define _SIGCONTEXT_TO_MCONTEXT(sc, uc) \
+do { \
+ (uc)->uc_mcontext.__gregs[_REG_A7] = (sc)->sc_sp; \
+ (uc)->uc_mcontext.__gregs[_REG_A6] = (sc)->sc_fp; \
+ (uc)->uc_mcontext.__gregs[_REG_PC] = (sc)->sc_pc; \
+ (uc)->uc_mcontext.__gregs[_REG_PS] = (sc)->sc_ps; \
+} while (/*CONSTCOND*/0)
+
+#if defined(__M68K_SIGNAL_PRIVATE)
#include <m68k/frame.h>
/*
@@ -93,6 +118,83 @@
#define SS_FPSTATE 0x02
#define SS_USERREGS 0x04
+#ifdef _KERNEL
+#define _SIGSTATE_EXFRAMESIZE(fmt) exframesize[(fmt)]
+#endif
+
+#define _MCONTEXT_TO_SIGSTATE(uc, ss) \
+do { \
+ (ss)->ss_flags = SS_USERREGS; \
+ memcpy(&(ss)->ss_frame.f_regs, &(uc)->uc_mcontext.__gregs, \
+ 16 * sizeof(unsigned int)); \
+ (ss)->ss_frame.f_pc = (uc)->uc_mcontext.__gregs[_REG_PC]; \
+ (ss)->ss_frame.f_sr = (uc)->uc_mcontext.__gregs[_REG_PS]; \
+ (ss)->ss_frame.f_pad = 0; \
+ (ss)->ss_frame.f_stackadj = 0; \
+ (ss)->ss_frame.f_format = \
+ (uc)->uc_mcontext.__mc_pad.__mc_frame.__mcf_format; \
+ if ((ss)->ss_frame.f_format >= FMT4) { \
+ (ss)->ss_flags |= SS_RTEFRAME; \
+ (ss)->ss_frame.f_vector = \
+ (uc)->uc_mcontext.__mc_pad.__mc_frame.__mcf_vector; \
+ memcpy(&(ss)->ss_frame.F_u, \
+ &(uc)->uc_mcontext.__mc_pad.__mc_frame.__mcf_exframe,\
+ _SIGSTATE_EXFRAMESIZE((ss)->ss_frame.f_format)); \
+ } \
+ \
+ (ss)->ss_fpstate.FPF_u1 = \
+ (uc)->uc_mcontext.__mc_pad.__mc_frame.__mcf_fpf_u1; \
+ if ((uc)->uc_flags & _UC_FPU) { /* non-null FP frame */ \
+ (ss)->ss_fpstate.FPF_u2 = \
+ (uc)->uc_mcontext.__mc_pad.__mc_frame.__mcf_fpf_u2; \
+ memcpy(&(ss)->ss_fpstate.fpf_regs, \
+ &(uc)->uc_mcontext.__fpregs.__fp_fpregs, \
+ sizeof((ss)->ss_fpstate.fpf_regs)); \
+ (ss)->ss_fpstate.fpf_fpcr = \
+ (uc)->uc_mcontext.__fpregs.__fp_pcr; \
+ (ss)->ss_fpstate.fpf_fpsr = \
+ (uc)->uc_mcontext.__fpregs.__fp_psr; \
+ (ss)->ss_fpstate.fpf_fpiar = \
+ (uc)->uc_mcontext.__fpregs.__fp_piaddr; \
+ (ss)->ss_flags |= SS_FPSTATE; \
+ } \
+} while (/*CONSTCOND*/0)
+
+#define _SIGSTATE_TO_MCONTEXT(ss, uc) \
+do { \
+ memcpy(&(uc)->uc_mcontext.__gregs, &(ss)->ss_frame.f_regs, \
+ 16 * sizeof(unsigned int)); \
+ (uc)->uc_mcontext.__gregs[_REG_PC] = (ss)->ss_frame.f_pc; \
+ (uc)->uc_mcontext.__gregs[_REG_PS] = (ss)->ss_frame.f_sr; \
+ (uc)->uc_mcontext.__mc_pad.__mc_frame.__mcf_format = \
+ (ss)->ss_frame.f_format; \
+ if ((ss)->ss_flags & SS_RTEFRAME) { \
+ (uc)->uc_mcontext.__mc_pad.__mc_frame.__mcf_vector = \
+ (ss)->ss_frame.f_vector; \
+ memcpy(&(uc)->uc_mcontext.__mc_pad.__mc_frame.__mcf_exframe,\
+ &(ss)->ss_frame.F_u, \
+ _SIGSTATE_EXFRAMESIZE((ss)->ss_frame.f_format)); \
+ } \
+ \
+ (uc)->uc_mcontext.__mc_pad.__mc_frame.__mcf_fpf_u1 = \
+ (ss)->ss_fpstate.FPF_u1; \
+ if ((ss)->ss_flags & SS_FPSTATE) { \
+ (uc)->uc_mcontext.__mc_pad.__mc_frame.__mcf_fpf_u2 = \
+ (ss)->ss_fpstate.FPF_u2; \
+ memcpy(&(uc)->uc_mcontext.__fpregs.__fp_fpregs, \
+ &(ss)->ss_fpstate.fpf_regs, \
+ sizeof((ss)->ss_fpstate.fpf_regs)); \
+ (uc)->uc_mcontext.__fpregs.__fp_pcr = \
+ (ss)->ss_fpstate.fpf_fpcr; \
+ (uc)->uc_mcontext.__fpregs.__fp_psr = \
+ (ss)->ss_fpstate.fpf_fpsr; \
+ (uc)->uc_mcontext.__fpregs.__fp_piaddr = \
+ (ss)->ss_fpstate.fpf_fpiar; \
+ (uc)->uc_flags |= _UC_FPU; \
+ } else \
+ (uc)->uc_flags &= ~_UC_FPU; \
+} while (/*CONSTCOND*/0)
+
/*
* Stack frame layout when delivering a signal.
*/
diff -r edc06dd935af -r 9e1fb99da0d2 sys/arch/mips/include/signal.h
--- a/sys/arch/mips/include/signal.h Thu Jan 16 03:07:47 2003 +0000
+++ b/sys/arch/mips/include/signal.h Thu Jan 16 03:14:50 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: signal.h,v 1.14.20.1 2002/04/01 07:41:00 nathanw Exp $ */
+/* $NetBSD: signal.h,v 1.14.20.2 2003/01/16 03:14:55 thorpej Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -89,6 +89,51 @@
sigset_t sc_mask; /* signal mask to restore (new style) */
};
+/*
Home |
Main Index |
Thread Index |
Old Index