From 7597f4a8fc2a06ee1bd97f47d87b546c418a7222 Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Wed, 11 Dec 2013 00:47:22 +0100 Subject: [PATCH] . use netbsd sigframe, sigcontext struct . netbsd sigframe *contains* sigcontext; use that directly in kernel sigsend . drop two fields from minix x86 stackframe.h (process context) that were unused, retadr and st use in-sigframe sigcontext Change-Id: Ib59d699596dc3a78163dee59f19730482fdddf11 --- include/arch/i386/include/stackframe.h | 4 +- kernel/arch/earm/arch_system.c | 7 +- kernel/arch/i386/arch_system.c | 6 +- kernel/arch/i386/procoffsets.cf | 2 - kernel/arch/i386/sconst.h | 3 +- kernel/proto.h | 4 +- kernel/system/do_sigreturn.c | 47 +++++- kernel/system/do_sigsend.c | 90 ++++++---- lib/libc/arch/arm/sys-minix/__sigreturn.S | 3 +- lib/libc/sys-minix/sigprocmask.c | 3 +- lib/libc/sys-minix/sigreturn.c | 1 + lib/libc/sys-minix/statvfs.c | 1 + lib/libvassert/vassert.c | 1 + sys/arch/arm/include/frame.h | 6 +- sys/arch/arm/include/signal.h | 193 +++++++++++++++++----- sys/arch/evbarm/include/Makefile | 2 +- sys/arch/evbarm/include/frame.h | 3 + sys/arch/i386/include/Makefile | 2 +- sys/arch/i386/include/frame.h | 13 +- sys/arch/i386/include/signal.h | 153 ++++++++++++----- sys/arch/i386/include/trap.h | 3 + test/test47.c | 9 +- 22 files changed, 411 insertions(+), 145 deletions(-) create mode 100644 sys/arch/evbarm/include/frame.h create mode 100644 sys/arch/i386/include/trap.h diff --git a/include/arch/i386/include/stackframe.h b/include/arch/i386/include/stackframe.h index e00dc70a0..149fdf5ff 100644 --- a/include/arch/i386/include/stackframe.h +++ b/include/arch/i386/include/stackframe.h @@ -22,12 +22,12 @@ struct stackframe_s { reg_t di; /* di through cx are not accessed in C */ reg_t si; /* order is to match pusha/popa */ reg_t fp; /* bp */ - reg_t st; /* hole for another copy of sp */ +/* reg_t st; */ /* hole for another copy of sp */ reg_t bx; /* | */ reg_t dx; /* | */ reg_t cx; /* | */ reg_t retreg; /* ax and above are all pushed by save */ - reg_t retadr; /* return address for assembly code save() */ +/* reg_t retadr; */ /* return address for assembly code save() */ reg_t pc; /* ^ last item pushed by interrupt */ reg_t cs; /* | */ reg_t psw; /* | */ diff --git a/kernel/arch/earm/arch_system.c b/kernel/arch/earm/arch_system.c index 142f4d756..9399c2e4c 100644 --- a/kernel/arch/earm/arch_system.c +++ b/kernel/arch/earm/arch_system.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -55,7 +56,9 @@ void arch_proc_setcontext(struct proc *p, struct stackframe_s *state, int isuser, int trapstyle) { assert(sizeof(p->p_reg) == sizeof(*state)); - memcpy(&p->p_reg, state, sizeof(*state)); + if(state != &p->p_reg) { + memcpy(&p->p_reg, state, sizeof(*state)); + } /* further code is instructed to not touch the context * any more @@ -167,7 +170,7 @@ struct proc * arch_finish_switch_to_user(void) return p; } -void fpu_sigcontext(struct proc *pr, struct sigframe *fr, struct sigcontext *sc) +void fpu_sigcontext(struct proc *pr, struct sigframe_sigcontext *fr, struct sigcontext *sc) { } diff --git a/kernel/arch/i386/arch_system.c b/kernel/arch/i386/arch_system.c index f14d32ae1..edffee577 100644 --- a/kernel/arch/i386/arch_system.c +++ b/kernel/arch/i386/arch_system.c @@ -538,7 +538,9 @@ void arch_proc_setcontext(struct proc *p, struct stackframe_s *state, /* someone wants to totally re-initialize process state */ assert(sizeof(p->p_reg) == sizeof(*state)); - memcpy(&p->p_reg, state, sizeof(*state)); + if(state != &p->p_reg) { + memcpy(&p->p_reg, state, sizeof(*state)); + } /* further code is instructed to not touch the context * any more @@ -614,7 +616,7 @@ void restore_user_context(struct proc *p) NOT_REACHABLE; } -void fpu_sigcontext(struct proc *pr, struct sigframe *fr, struct sigcontext *sc) +void fpu_sigcontext(struct proc *pr, struct sigframe_sigcontext *fr, struct sigcontext *sc) { int fp_error; diff --git a/kernel/arch/i386/procoffsets.cf b/kernel/arch/i386/procoffsets.cf index 3d21913eb..6c17c0c1a 100644 --- a/kernel/arch/i386/procoffsets.cf +++ b/kernel/arch/i386/procoffsets.cf @@ -5,12 +5,10 @@ struct proc member DIREG p_reg.di member SIREG p_reg.si member BPREG p_reg.fp -member STREG p_reg.st member BXREG p_reg.bx member DXREG p_reg.dx member CXREG p_reg.cx member AXREG p_reg.retreg -member RETADR p_reg.retadr member PCREG p_reg.pc member CSREG p_reg.cs member PSWREG p_reg.psw diff --git a/kernel/arch/i386/sconst.h b/kernel/arch/i386/sconst.h index 280038591..971cab2d4 100644 --- a/kernel/arch/i386/sconst.h +++ b/kernel/arch/i386/sconst.h @@ -35,8 +35,7 @@ movl (8 + displ)(%esp), tmp ;\ movl tmp, PSWREG(pptr) ;\ movl (12 + displ)(%esp), tmp ;\ - movl tmp, SPREG(pptr) ;\ - movl tmp, STREG(pptr) + movl tmp, SPREG(pptr) /* * restore kernel segments. %cs is already set and %fs, %gs are not used */ diff --git a/kernel/proto.h b/kernel/proto.h index 8de351bc2..22ce09521 100644 --- a/kernel/proto.h +++ b/kernel/proto.h @@ -8,6 +8,8 @@ #include #include +#include +#include /* Struct declarations. */ struct proc; @@ -35,7 +37,7 @@ void context_stop_idle(void); int restore_fpu(struct proc *); void save_fpu(struct proc *); void save_local_fpu(struct proc *, int retain); -void fpu_sigcontext(struct proc *, struct sigframe *fr, struct +void fpu_sigcontext(struct proc *, struct sigframe_sigcontext *fr, struct sigcontext *sc); /* main.c */ diff --git a/kernel/system/do_sigreturn.c b/kernel/system/do_sigreturn.c index 09fc7d65d..061c23562 100644 --- a/kernel/system/do_sigreturn.c +++ b/kernel/system/do_sigreturn.c @@ -37,22 +37,51 @@ int do_sigreturn(struct proc * caller, message * m_ptr) #if defined(__i386__) /* Restore user bits of psw from sc, maintain system bits from proc. */ - sc.sc_psw = (sc.sc_psw & X86_FLAGS_USER) | + sc.sc_eflags = (sc.sc_eflags & X86_FLAGS_USER) | (rp->p_reg.psw & ~X86_FLAGS_USER); #endif #if defined(__i386__) - /* Don't panic kernel if user gave bad selectors. */ - sc.sc_cs = rp->p_reg.cs; - sc.sc_ds = rp->p_reg.ds; - sc.sc_es = rp->p_reg.es; - sc.sc_ss = rp->p_reg.ss; - sc.sc_fs = rp->p_reg.fs; - sc.sc_gs = rp->p_reg.gs; + /* Write back registers we allow to be restored, i.e. + * not the segment ones. + */ + rp->p_reg.di = sc.sc_edi; + rp->p_reg.si = sc.sc_esi; + rp->p_reg.fp = sc.sc_ebp; + rp->p_reg.bx = sc.sc_ebx; + rp->p_reg.dx = sc.sc_edx; + rp->p_reg.cx = sc.sc_ecx; + rp->p_reg.retreg = sc.sc_eax; + rp->p_reg.pc = sc.sc_eip; + rp->p_reg.psw = sc.sc_eflags; + rp->p_reg.sp = sc.sc_esp; +#endif + +#if defined(__arm__) + rp->p_reg.psr = sc.sc_spsr; + rp->p_reg.retreg = sc.sc_r0; + rp->p_reg.r1 = sc.sc_r1; + rp->p_reg.r2 = sc.sc_r2; + rp->p_reg.r3 = sc.sc_r3; + rp->p_reg.r4 = sc.sc_r4; + rp->p_reg.r5 = sc.sc_r5; + rp->p_reg.r6 = sc.sc_r6; + rp->p_reg.r7 = sc.sc_r7; + rp->p_reg.r8 = sc.sc_r8; + rp->p_reg.r9 = sc.sc_r9; + rp->p_reg.r10 = sc.sc_r10; + rp->p_reg.fp = sc.sc_r11; + rp->p_reg.r12 = sc.sc_r12; + rp->p_reg.sp = sc.sc_usr_sp; + rp->p_reg.lr = sc.sc_usr_lr; + rp->p_reg.pc = sc.sc_pc; #endif /* Restore the registers. */ - arch_proc_setcontext(rp, &sc.sc_regs, 1, sc.trap_style); + arch_proc_setcontext(rp, &rp->p_reg, 1, sc.trap_style); + + if(sc.sc_magic != SC_MAGIC) { printf("kernel sigreturn: corrupt signal context\n"); } + #if defined(__i386__) if (sc.sc_flags & MF_FPU_INITIALIZED) { diff --git a/kernel/system/do_sigsend.c b/kernel/system/do_sigsend.c index 430a2b083..ea1573413 100644 --- a/kernel/system/do_sigsend.c +++ b/kernel/system/do_sigsend.c @@ -22,8 +22,7 @@ int do_sigsend(struct proc * caller, message * m_ptr) struct sigmsg smsg; register struct proc *rp; - struct sigcontext sc, *scp; - struct sigframe fr, *frp; + struct sigframe_sigcontext fr, *frp; int proc_nr, r; if (!isokendpt(m_ptr->m_sigcalls.endpt, &proc_nr)) return EINVAL; @@ -36,17 +35,41 @@ int do_sigsend(struct proc * caller, message * m_ptr) (vir_bytes)&smsg, (phys_bytes) sizeof(struct sigmsg))) != OK) return r; - /* Compute the user stack pointer where sigcontext will be stored. */ + /* Compute the user stack pointer where sigframe will start. */ smsg.sm_stkptr = arch_get_sp(rp); - scp = (struct sigcontext *) smsg.sm_stkptr - 1; + frp = (struct sigframe_sigcontext *) smsg.sm_stkptr - 1; /* Copy the registers to the sigcontext structure. */ - memcpy(&sc.sc_regs, (char *) &rp->p_reg, sizeof(sigregs)); + memset(&fr, 0, sizeof(fr)); + fr.sf_scp = &frp->sf_sc; #if defined(__i386__) - sc.trap_style = rp->p_seg.p_kern_trap_style; + fr.sf_sc.sc_gs = rp->p_reg.gs; + fr.sf_sc.sc_fs = rp->p_reg.fs; + fr.sf_sc.sc_es = rp->p_reg.es; + fr.sf_sc.sc_ds = rp->p_reg.ds; + fr.sf_sc.sc_edi = rp->p_reg.di; + fr.sf_sc.sc_esi = rp->p_reg.si; + fr.sf_sc.sc_ebp = rp->p_reg.fp; + fr.sf_sc.sc_ebx = rp->p_reg.bx; + fr.sf_sc.sc_edx = rp->p_reg.dx; + fr.sf_sc.sc_ecx = rp->p_reg.cx; + fr.sf_sc.sc_eax = rp->p_reg.retreg; + fr.sf_sc.sc_eip = rp->p_reg.pc; + fr.sf_sc.sc_cs = rp->p_reg.cs; + fr.sf_sc.sc_eflags = rp->p_reg.psw; + fr.sf_sc.sc_esp = rp->p_reg.sp; + fr.sf_sc.sc_ss = rp->p_reg.ss; + fr.sf_fp = rp->p_reg.fp; + fr.sf_signum = smsg.sm_signo; + rp->p_reg.fp = (reg_t) &frp->sf_fp; + fr.sf_scpcopy = fr.sf_scp; + fr.sf_ra_sigreturn = smsg.sm_sigreturn; + fr.sf_ra= rp->p_reg.pc; - if (sc.trap_style == KTS_NONE) { + fr.sf_sc.trap_style = rp->p_seg.p_kern_trap_style; + + if (fr.sf_sc.trap_style == KTS_NONE) { printf("do_sigsend: sigsend an unsaved process\n"); return EINVAL; } @@ -54,43 +77,50 @@ int do_sigsend(struct proc * caller, message * m_ptr) if (proc_used_fpu(rp)) { /* save the FPU context before saving it to the sig context */ save_fpu(rp); - memcpy(&sc.sc_fpu_state, rp->p_seg.fpu_state, FPU_XFP_SIZE); + memcpy(&fr.sf_sc.sc_fpu_state, rp->p_seg.fpu_state, FPU_XFP_SIZE); } #endif - /* Finish the sigcontext initialization. */ - sc.sc_mask = smsg.sm_mask; - sc.sc_flags = rp->p_misc_flags & MF_FPU_INITIALIZED; +#if defined(__arm__) + fr.sf_sc.sc_spsr = rp->p_reg.psr; + fr.sf_sc.sc_r0 = rp->p_reg.retreg; + fr.sf_sc.sc_r1 = rp->p_reg.r1; + fr.sf_sc.sc_r2 = rp->p_reg.r2; + fr.sf_sc.sc_r3 = rp->p_reg.r3; + fr.sf_sc.sc_r4 = rp->p_reg.r4; + fr.sf_sc.sc_r5 = rp->p_reg.r5; + fr.sf_sc.sc_r6 = rp->p_reg.r6; + fr.sf_sc.sc_r7 = rp->p_reg.r7; + fr.sf_sc.sc_r8 = rp->p_reg.r8; + fr.sf_sc.sc_r9 = rp->p_reg.r9; + fr.sf_sc.sc_r10 = rp->p_reg.r10; + fr.sf_sc.sc_r11 = rp->p_reg.fp; + fr.sf_sc.sc_r12 = rp->p_reg.r12; + fr.sf_sc.sc_usr_sp = rp->p_reg.sp; + fr.sf_sc.sc_usr_lr = rp->p_reg.lr; + fr.sf_sc.sc_svc_lr = 0; /* ? */ + fr.sf_sc.sc_pc = rp->p_reg.pc; /* R15 */ +#endif - /* Copy the sigcontext structure to the user's stack. */ - if ((r = data_copy_vmcheck(caller, KERNEL, (vir_bytes)&sc, - m_ptr->m_sigcalls.endpt, (vir_bytes)scp, - (vir_bytes)sizeof(struct sigcontext))) != OK) - return r; + /* Finish the sigcontext initialization. */ + fr.sf_sc.sc_mask = smsg.sm_mask; + fr.sf_sc.sc_flags = rp->p_misc_flags & MF_FPU_INITIALIZED; + fr.sf_sc.sc_magic = SC_MAGIC; /* Initialize the sigframe structure. */ - frp = (struct sigframe *) scp - 1; - fr.sf_scpcopy = scp; - fr.sf_retadr2= (void (*)()) rp->p_reg.pc; - fr.sf_fp = rp->p_reg.fp; - rp->p_reg.fp = (reg_t) &frp->sf_fp; - fr.sf_scp = scp; - fpu_sigcontext(rp, &fr, &sc); - - fr.sf_signo = smsg.sm_signo; - fr.sf_retadr = (void (*)()) smsg.sm_sigreturn; + fpu_sigcontext(rp, &fr, &fr.sf_sc); #if defined(__arm__) /* use the ARM link register to set the return address from the signal * handler */ - rp->p_reg.lr = (reg_t) fr.sf_retadr; + rp->p_reg.lr = (reg_t) smsg.sm_sigreturn; if(rp->p_reg.lr & 1) { printf("sigsend: LSB LR makes no sense.\n"); } /* pass signal handler parameters in registers */ - rp->p_reg.retreg = (reg_t) fr.sf_signo; - rp->p_reg.r1 = (reg_t) fr.sf_code; + rp->p_reg.retreg = (reg_t) smsg.sm_signo; + rp->p_reg.r1 = 0; /* sf_code */ rp->p_reg.r2 = (reg_t) fr.sf_scp; rp->p_misc_flags |= MF_CONTEXT_SET; #endif @@ -98,7 +128,7 @@ int do_sigsend(struct proc * caller, message * m_ptr) /* Copy the sigframe structure to the user's stack. */ if ((r = data_copy_vmcheck(caller, KERNEL, (vir_bytes)&fr, m_ptr->m_sigcalls.endpt, (vir_bytes)frp, - (vir_bytes)sizeof(struct sigframe))) != OK) + (vir_bytes)sizeof(struct sigframe_sigcontext))) != OK) return r; /* Reset user registers to execute the signal handler. */ diff --git a/lib/libc/arch/arm/sys-minix/__sigreturn.S b/lib/libc/arch/arm/sys-minix/__sigreturn.S index 9eee41635..05d287735 100644 --- a/lib/libc/arch/arm/sys-minix/__sigreturn.S +++ b/lib/libc/arch/arm/sys-minix/__sigreturn.S @@ -5,6 +5,5 @@ IMPORT(_sigreturn) ENTRY(__sigreturn) - add sp, sp, #24 /* make sp point to sigframe.sf_scpcopy */ - pop {r0} /* load it into r0 as parameter */ + pop {r0} /* load sigframe.sf_scp into r0 as parameter */ b _C_LABEL(_sigreturn) /* _sigreturn(struct sigcontext *sf_scpcopy) */ diff --git a/lib/libc/sys-minix/sigprocmask.c b/lib/libc/sys-minix/sigprocmask.c index a84aa8076..ee3f0edf5 100644 --- a/lib/libc/sys-minix/sigprocmask.c +++ b/lib/libc/sys-minix/sigprocmask.c @@ -1,6 +1,7 @@ #include -#include +#include #include +#include #include #include #include "namespace.h" diff --git a/lib/libc/sys-minix/sigreturn.c b/lib/libc/sys-minix/sigreturn.c index 7b907425c..f0cbf4f6b 100644 --- a/lib/libc/sys-minix/sigreturn.c +++ b/lib/libc/sys-minix/sigreturn.c @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff --git a/lib/libc/sys-minix/statvfs.c b/lib/libc/sys-minix/statvfs.c index 97a50b851..901c7f06c 100644 --- a/lib/libc/sys-minix/statvfs.c +++ b/lib/libc/sys-minix/statvfs.c @@ -2,6 +2,7 @@ #include #include "namespace.h" +#include #include #include diff --git a/lib/libvassert/vassert.c b/lib/libvassert/vassert.c index 695c5b10c..31f789609 100644 --- a/lib/libvassert/vassert.c +++ b/lib/libvassert/vassert.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "vassert.h" VAssert_StateWrapper vassert_state ALIGNED(VASSERT_PAGE_SIZE); diff --git a/sys/arch/arm/include/frame.h b/sys/arch/arm/include/frame.h index 69222a12d..421889cd3 100644 --- a/sys/arch/arm/include/frame.h +++ b/sys/arch/arm/include/frame.h @@ -88,12 +88,16 @@ typedef struct trapframe { /* * Signal frame. Pushed onto user stack before calling sigcode. */ -#ifdef COMPAT_16 +#if defined(COMPAT_16) || defined(__minix) struct sigframe_sigcontext { +#ifdef __minix + struct sigcontext *sf_scp; /* Let sigreturn find sigcontext */ +#endif struct sigcontext sf_sc; }; #endif + /* the pointers are use in the trampoline code to locate the ucontext */ struct sigframe_siginfo { siginfo_t sf_si; /* actual saved siginfo */ diff --git a/sys/arch/arm/include/signal.h b/sys/arch/arm/include/signal.h index 5ff12d707..88368a335 100644 --- a/sys/arch/arm/include/signal.h +++ b/sys/arch/arm/include/signal.h @@ -1,59 +1,172 @@ -#ifndef _ARM_SIGNAL_H_ -#define _ARM_SIGNAL_H_ +/* $NetBSD: signal.h,v 1.12 2011/06/30 20:09:20 wiz Exp $ */ + +/* + * Copyright (c) 1994-1996 Mark Brinicombe. + * Copyright (c) 1994 Brini. + * All rights reserved. + * + * This code is derived from software written for Brini by Mark Brinicombe + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Brini. + * 4. The name of the company nor the name of the author may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * RiscBSD kernel project + * + * signal.h + * + * Architecture dependent signal types and structures + * + * Created : 30/09/94 + */ + +#ifndef _ARM32_SIGNAL_H_ +#define _ARM32_SIGNAL_H_ #include +#ifndef _LOCORE typedef int sig_atomic_t; +#endif -/* The following structure should match the stackframe_s structure used - * by the kernel's context switching code. Floating point registers should - * be added in a different struct. +#if defined(_NETBSD_SOURCE) + +#ifndef _LOCORE +/* + * Information pushed on stack when a signal is delivered. + * This is used by the kernel to restore state following + * execution of the signal handler. It is also made available + * to the handler to allow it to restore state properly if + * a non-standard exit is performed. */ -#include +#if defined(__LIBC12_SOURCE__) || defined(_KERNEL) +struct sigcontext13 { + int sc_onstack; /* sigstack state to restore */ + int sc_mask; /* signal mask to restore (old style) */ -typedef struct stackframe_s sigregs; -struct sigframe { /* stack frame created for signalled process */ - void (*sf_retadr)(void); - int sf_signo; - int sf_code; - struct sigcontext *sf_scp; - int sf_fp; - void (*sf_retadr2)(void); - struct sigcontext *sf_scpcopy; + unsigned int sc_spsr; + unsigned int sc_r0; + unsigned int sc_r1; + unsigned int sc_r2; + unsigned int sc_r3; + unsigned int sc_r4; + unsigned int sc_r5; + unsigned int sc_r6; + unsigned int sc_r7; + unsigned int sc_r8; + unsigned int sc_r9; + unsigned int sc_r10; + unsigned int sc_r11; + unsigned int sc_r12; + unsigned int sc_usr_sp; + unsigned int sc_usr_lr; + unsigned int sc_svc_lr; + unsigned int sc_pc; }; +#endif /* __LIBC12_SOURCE__ || _KERNEL */ struct sigcontext { - int trap_style; /* how should context be restored? KTS_* */ - int sc_flags; /* sigstack state to restore (including - * MF_FPU_INITIALIZED) - */ - sigset_t sc_mask; /* signal mask to restore */ - sigregs sc_regs; /* register set to restore */ + int sc_onstack; /* sigstack state to restore */ + int __sc_mask13; /* signal mask to restore (old style) */ + + unsigned int sc_spsr; + unsigned int sc_r0; + unsigned int sc_r1; + unsigned int sc_r2; + unsigned int sc_r3; + unsigned int sc_r4; + unsigned int sc_r5; + unsigned int sc_r6; + unsigned int sc_r7; + unsigned int sc_r8; + unsigned int sc_r9; + unsigned int sc_r10; + unsigned int sc_r11; + unsigned int sc_r12; + unsigned int sc_usr_sp; + unsigned int sc_usr_lr; + unsigned int sc_svc_lr; + unsigned int sc_pc; + + sigset_t sc_mask; /* signal mask to restore (new style) */ +#ifdef __minix +#define SC_MAGIC 0xc0ffee2 + int sc_magic; + int sc_flags; + int trap_style; +#endif }; -#define sc_retreg sc_regs.retreg -#define sc_r1 sc_regs.r1 -#define sc_r2 sc_regs.r2 -#define sc_r3 sc_regs.r3 -#define sc_r4 sc_regs.r4 -#define sc_r5 sc_regs.r5 -#define sc_r6 sc_regs.r6 -#define sc_r7 sc_regs.r7 -#define sc_r8 sc_regs.r8 -#define sc_r9 sc_regs.r9 -#define sc_r10 sc_regs.r10 -#define sc_fp sc_regs.fp -#define sc_r12 sc_regs.r12 -#define sc_sp sc_regs.sp -#define sc_lr sc_regs.lr -#define sc_pc sc_regs.pc -#define sc_psr sc_regs.psr +#endif /* !_LOCORE */ -#if defined(__minix) && defined(_NETBSD_SOURCE) +/* Signals codes */ + +/* + * SIGFPE codes + * + * see ieeefp.h for definition of FP exception codes + */ + +#define SIG_CODE_FPE_CODE_MASK 0x00000f00 /* Mask for exception code */ +#define SIG_CODE_FPE_CODE_SHIFT 8 /* Shift for exception code */ +#define SIG_CODE_FPE_TYPE_MASK 0x000000ff /* Mask for specific code */ + +/* + * SIGILL codes + * + * the signal code is the instruction that raised the signal + */ + +/* + * SIGBUS and SIGSEGV codes + * + * The signal code is combination of the fault address and the fault code. + * + * The fault code is the coproc #15 fault status code + * + * The exception to this is a SIGBUS or SIGSEGV from a prefetch abort. + * In this case the fault status code is not valid so the TYPE_MASK + * should be treated as undefined (in practice it is the bottom 4 bits + * of the fault address). + */ + +#define SIG_CODE_BUS_ADDR_MASK 0xfffffff0 +#define SIG_CODE_BUS_TYPE_MASK 0x0000000f +#define SIG_CODE_SEGV_ADDR_MASK SIG_CODE_BUS_ADDR_MASK +#define SIG_CODE_SEGV_TYPE_MASK SIG_CODE_BUS_TYPE_MASK + +#endif /* _NETBSD_SOURCE */ + +#if defined(__minix) __BEGIN_DECLS int sigreturn(struct sigcontext *_scp); __END_DECLS -#endif /* defined(__minix) && defined(_NETBSD_SOURCE) */ +#endif /* defined(__minix) */ #endif /* !_ARM_SIGNAL_H_ */ + +/* End of signal.h */ diff --git a/sys/arch/evbarm/include/Makefile b/sys/arch/evbarm/include/Makefile index 227150e4c..f3e2e4830 100644 --- a/sys/arch/evbarm/include/Makefile +++ b/sys/arch/evbarm/include/Makefile @@ -7,7 +7,7 @@ INCS= ansi.h asm.h \ cdefs.h cpu.h \ disklabel.h \ elf_machdep.h endian.h endian_machdep.h \ - float.h \ + float.h frame.h \ ieee.h ieeefp.h \ int_const.h int_fmtio.h int_limits.h int_mwgwtypes.h int_types.h \ \ diff --git a/sys/arch/evbarm/include/frame.h b/sys/arch/evbarm/include/frame.h new file mode 100644 index 000000000..eaec052b5 --- /dev/null +++ b/sys/arch/evbarm/include/frame.h @@ -0,0 +1,3 @@ +/* $NetBSD: frame.h,v 1.2 2001/11/25 15:56:04 thorpej Exp $ */ + +#include diff --git a/sys/arch/i386/include/Makefile b/sys/arch/i386/include/Makefile index cdc4d2e21..f5ddebda2 100644 --- a/sys/arch/i386/include/Makefile +++ b/sys/arch/i386/include/Makefile @@ -17,7 +17,7 @@ INCS= ansi.h asm.h \ limits.h \ math.h mcontext.h mutex.h multiboot.h \ npx.h \ - param.h pio.h profile.h ptrace.h \ + param.h pio.h profile.h ptrace.h trap.h \ \ rwlock.h \ setjmp.h signal.h \ diff --git a/sys/arch/i386/include/frame.h b/sys/arch/i386/include/frame.h index b4b99e107..81995ec25 100644 --- a/sys/arch/i386/include/frame.h +++ b/sys/arch/i386/include/frame.h @@ -144,15 +144,26 @@ struct switchframe { int sf_eip; }; -#ifdef _KERNEL +#if defined(_KERNEL) || defined(__minix) /* * Old-style signal frame */ struct sigframe_sigcontext { +#ifdef __minix + /* ret addr + stackframe for handler */ + int sf_ra_sigreturn; /* first return to sigreturn */ +#else int sf_ra; /* return address for handler */ +#endif int sf_signum; /* "signum" argument for handler */ int sf_code; /* "code" argument for handler */ struct sigcontext *sf_scp; /* "scp" argument for handler */ +#ifdef __minix + /* ret addr + stackframe for sigreturn */ + uint32_t sf_fp; /* saved FP */ + int sf_ra; /* actual return address for handler */ + struct sigcontext *sf_scpcopy; /* minix scp copy */ +#endif struct sigcontext sf_sc; /* actual saved context */ }; #endif diff --git a/sys/arch/i386/include/signal.h b/sys/arch/i386/include/signal.h index ee5d49533..7201a3f39 100644 --- a/sys/arch/i386/include/signal.h +++ b/sys/arch/i386/include/signal.h @@ -1,63 +1,128 @@ +/* $NetBSD: signal.h,v 1.29 2008/11/19 18:35:59 ad Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 1991 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)signal.h 7.16 (Berkeley) 3/17/91 + */ + #ifndef _I386_SIGNAL_H_ #define _I386_SIGNAL_H_ #include +#ifdef __minix +#include +#endif + typedef int sig_atomic_t; -/* The following structure should match the stackframe_s structure used - * by the kernel's context switching code. Floating point registers should - * be added in a different struct. +#if defined(_NETBSD_SOURCE) +/* + * Get the "code" values */ +#include -#include -#include +#if defined(_KERNEL) || defined(__minix) +/* + * Information pushed on stack when a signal is delivered. + * This is used by the kernel to restore state following + * execution of the signal handler. It is also made available + * to the handler to allow it to restore state properly if + * a non-standard exit is performed. + */ +struct sigcontext13 { + int sc_gs; + int sc_fs; + int sc_es; + int sc_ds; + int sc_edi; + int sc_esi; + int sc_ebp; + int sc_ebx; + int sc_edx; + int sc_ecx; + int sc_eax; + /* XXX */ + int sc_eip; + int sc_cs; + int sc_eflags; + int sc_esp; + int sc_ss; -typedef struct stackframe_s sigregs; -struct sigframe { /* stack frame created for signalled process */ - void (*sf_retadr)(void); - int sf_signo; - int sf_code; - struct sigcontext *sf_scp; - int sf_fp; - void (*sf_retadr2)(void); - struct sigcontext *sf_scpcopy; + int sc_onstack; /* sigstack state to restore */ + int sc_mask; /* signal mask to restore (old style) */ + + int sc_trapno; /* XXX should be above */ + int sc_err; }; struct sigcontext { - int trap_style; /* how should context be restored? KTS_* */ - int sc_flags; /* sigstack state to restore (including - * MF_FPU_INITIALIZED) - */ - sigset_t sc_mask; /* signal mask to restore */ - sigregs sc_regs; /* register set to restore */ - union fpu_state_u sc_fpu_state; + int sc_gs; + int sc_fs; + int sc_es; + int sc_ds; + int sc_edi; + int sc_esi; + int sc_ebp; + int sc_ebx; + int sc_edx; + int sc_ecx; + int sc_eax; + /* XXX */ + int sc_eip; + int sc_cs; + int sc_eflags; + int sc_esp; + int sc_ss; + + int sc_onstack; /* sigstack state to restore */ + int __sc_mask13; /* signal mask to restore (old style) */ + + int sc_trapno; /* XXX should be above */ + int sc_err; + + sigset_t sc_mask; /* signal mask to restore (new style) */ +#ifdef __minix + union fpu_state_u sc_fpu_state; + int trap_style; /* KTS_* method of entering kernel */ + int sc_flags; /* MF_FPU_INITIALIZED if fpu state valid */ +#define SC_MAGIC 0xc0ffee1 + int sc_magic; +#endif }; +#endif /* _KERNEL */ -#define sc_gs sc_regs.gs -#define sc_fs sc_regs.fs -#define sc_es sc_regs.es -#define sc_ds sc_regs.ds -#define sc_di sc_regs.di -#define sc_si sc_regs.si -#define sc_fp sc_regs.bp -#define sc_st sc_regs.st /* stack top -- used in kernel */ -#define sc_bx sc_regs.bx -#define sc_dx sc_regs.dx -#define sc_cx sc_regs.cx -#define sc_retreg sc_regs.retreg -#define sc_retadr sc_regs.retadr /* return address to caller of - save -- used in kernel */ -#define sc_pc sc_regs.pc -#define sc_cs sc_regs.cs -#define sc_psw sc_regs.psw -#define sc_sp sc_regs.sp -#define sc_ss sc_regs.ss - -#if defined(__minix) && defined(_NETBSD_SOURCE) +#if defined(__minix) __BEGIN_DECLS -int sigreturn(struct sigcontext *_scp); +int sigreturn(struct sigcontext *_scp); __END_DECLS -#endif /* defined(__minix) && defined(_NETBSD_SOURCE) */ +#endif /* defined(__minix) */ +#endif /* _NETBSD_SOURCE */ #endif /* !_I386_SIGNAL_H_ */ diff --git a/sys/arch/i386/include/trap.h b/sys/arch/i386/include/trap.h new file mode 100644 index 000000000..adf4e9564 --- /dev/null +++ b/sys/arch/i386/include/trap.h @@ -0,0 +1,3 @@ +/* $NetBSD: trap.h,v 1.7 2003/02/26 21:29:03 fvdl Exp $ */ + +#include diff --git a/test/test47.c b/test/test47.c index 98aaacfef..5e1d76348 100644 --- a/test/test47.c +++ b/test/test47.c @@ -5,6 +5,7 @@ #include #include #include +#include int max_error = 4; #include "common.h" @@ -17,12 +18,12 @@ int max_error = 4; static void signal_handler(int signum) { - struct sigframe *sigframe; + struct sigframe_sigcontext *sigframe; /* report signal */ - sigframe = (struct sigframe *) ((char *) &signum - - (char *) &((struct sigframe *) NULL)->sf_signo); - printf("Signal %d at 0x%x\n", signum, sigframe->sf_scp->sc_regs.pc); + sigframe = (struct sigframe_sigcontext *) ((char *) &signum - + (char *) &((struct sigframe_sigcontext *) NULL)->sf_signum); + printf("Signal %d at 0x%x\n", signum, sigframe->sf_scp->sc_eip); /* count as error */ e(0);