Module Name: src Committed By: matt Date: Sun Aug 23 04:04:35 UTC 2009
Modified Files: src/sys/arch/mips/include [matt-nb5-mips64]: signal.h src/sys/arch/mips/mips [matt-nb5-mips64]: compat_13_machdep.c compat_16_machdep.c Log Message: In non-O32 kernels, make these syscalls return ENOSYS or sigexit(l, SIGILL) when called by non-O32 programs. Marshall the 64bits registers to and from their 32bit equivs and deal with FP differences. To generate a diff of this commit: cvs rdiff -u -r1.27.92.1 -r1.27.92.2 src/sys/arch/mips/include/signal.h cvs rdiff -u -r1.16.20.1 -r1.16.20.2 \ src/sys/arch/mips/mips/compat_13_machdep.c cvs rdiff -u -r1.12.14.1 -r1.12.14.2 \ src/sys/arch/mips/mips/compat_16_machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/mips/include/signal.h diff -u src/sys/arch/mips/include/signal.h:1.27.92.1 src/sys/arch/mips/include/signal.h:1.27.92.2 --- src/sys/arch/mips/include/signal.h:1.27.92.1 Sun Aug 16 03:33:58 2009 +++ src/sys/arch/mips/include/signal.h Sun Aug 23 04:04:35 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: signal.h,v 1.27.92.1 2009/08/16 03:33:58 matt Exp $ */ +/* $NetBSD: signal.h,v 1.27.92.2 2009/08/23 04:04:35 matt Exp $ */ /* * Copyright (c) 1992, 1993 @@ -86,18 +86,22 @@ #endif /* _KERNEL && COMPAT_13 */ #if defined(_LIBC) || (defined(_KERNEL) && (defined(COMPAT_16) || defined(COMPAT_ULTRIX))) +/* + * Only need an O32 version. + */ struct sigcontext { int sc_onstack; /* sigstack state to restore */ int __sc_mask13; /* signal mask to restore (old style) */ - mips_reg_t sc_pc; /* pc at time of signal */ - mips_reg_t sc_regs[32]; /* processor regs 0 to 31 */ - mips_reg_t mullo, mulhi;/* mullo and mulhi registers... */ + int sc_pc; /* pc at time of signal */ + int sc_regs[32]; /* processor regs 0 to 31 */ + int mullo, mulhi; /* mullo and mulhi registers... */ int sc_fpused; /* fp has been used */ - mips_fpreg_t sc_fpregs[33]; /* fp regs 0 to 31 and csr */ + int sc_fpregs[33]; /* fp regs 0 to 31 and csr */ int sc_fpc_eir; /* floating point exception instruction reg */ - long sc_xxx[8]; /* XXX reserved */ + int sc_xxx[8]; /* XXX reserved */ sigset_t sc_mask; /* signal mask to restore (new style) */ }; + #endif /* _LIBC || _KERNEL */ #endif /* !_LANGUAGE_ASSEMBLY */ Index: src/sys/arch/mips/mips/compat_13_machdep.c diff -u src/sys/arch/mips/mips/compat_13_machdep.c:1.16.20.1 src/sys/arch/mips/mips/compat_13_machdep.c:1.16.20.2 --- src/sys/arch/mips/mips/compat_13_machdep.c:1.16.20.1 Thu Aug 20 21:49:24 2009 +++ src/sys/arch/mips/mips/compat_13_machdep.c Sun Aug 23 04:04:35 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: compat_13_machdep.c,v 1.16.20.1 2009/08/20 21:49:24 matt Exp $ */ +/* $NetBSD: compat_13_machdep.c,v 1.16.20.2 2009/08/23 04:04:35 matt Exp $ */ /* * Copyright 1996 The Board of Trustees of The Leland Stanford @@ -15,7 +15,7 @@ #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: compat_13_machdep.c,v 1.16.20.1 2009/08/20 21:49:24 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: compat_13_machdep.c,v 1.16.20.2 2009/08/23 04:04:35 matt Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -39,6 +39,10 @@ #define SDB_FPSTATE 0x04 #endif +#if !defined(__mips_o32) +#define fpreg fpreg_oabi +#endif + int compat_13_sys_sigreturn(struct lwp *l, const struct compat_13_sys_sigreturn_args *uap, register_t *retval) { @@ -51,6 +55,11 @@ struct frame *f; sigset_t mask; +#if !defined(__mips_o32) + if (p->p_md.md_abi != _MIPS_BSD_ABI_O32) + return ENOSYS; +#endif + /* * The trampoline code hands us the context. * It is unsafe to keep track of it ourselves, in the event that a @@ -64,7 +73,7 @@ if ((error = copyin(scp, &ksc, sizeof(ksc))) != 0) return (error); - if ((u_int)ksc.sc_regs[_R_ZERO] != 0xacedbadeU)/* magic number */ + if ((uint32_t)ksc.sc_regs[_R_ZERO] != 0xacedbadeU)/* magic number */ return (EINVAL); /* Resture the register context. */ @@ -72,10 +81,16 @@ f->f_regs[_R_PC] = ksc.sc_pc; f->f_regs[_R_MULLO] = ksc.mullo; f->f_regs[_R_MULHI] = ksc.mulhi; +#if defined(__mips_o32) memcpy(&f->f_regs[1], &scp->sc_regs[1], sizeof(scp->sc_regs) - sizeof(scp->sc_regs[0])); +#else + for (size_t i = 1; i < __arraycount(scp->sc_regs); i++) + f->f_regs[i] = scp->sc_regs[i]; +#endif if (scp->sc_fpused) - l->l_addr->u_pcb.pcb_fpregs = *(struct fpreg *)scp->sc_fpregs; + *(struct fpreg *)&l->l_addr->u_pcb.pcb_fpregs = + *(struct fpreg *)scp->sc_fpregs; mutex_enter(p->p_lock); Index: src/sys/arch/mips/mips/compat_16_machdep.c diff -u src/sys/arch/mips/mips/compat_16_machdep.c:1.12.14.1 src/sys/arch/mips/mips/compat_16_machdep.c:1.12.14.2 --- src/sys/arch/mips/mips/compat_16_machdep.c:1.12.14.1 Thu Aug 20 21:45:59 2009 +++ src/sys/arch/mips/mips/compat_16_machdep.c Sun Aug 23 04:04:35 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: compat_16_machdep.c,v 1.12.14.1 2009/08/20 21:45:59 matt Exp $ */ +/* $NetBSD: compat_16_machdep.c,v 1.12.14.2 2009/08/23 04:04:35 matt Exp $ */ /*- * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc. @@ -45,7 +45,7 @@ #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: compat_16_machdep.c,v 1.12.14.1 2009/08/20 21:45:59 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: compat_16_machdep.c,v 1.12.14.2 2009/08/23 04:04:35 matt Exp $"); #include "opt_cputype.h" #include "opt_compat_netbsd.h" @@ -69,6 +69,10 @@ #include <mips/regnum.h> #include <mips/frame.h> +#if !defined(__mips_o32) +#define fpreg fpreg_oabi +#endif + #ifdef DEBUG int sigdebug = 0; int sigpid = 0; @@ -88,10 +92,15 @@ struct proc *p = l->l_proc; struct sigacts *ps = p->p_sigacts; int onstack, error; - struct sigcontext *scp = getframe(l, sig, &onstack), ksc; + struct sigcontext *scp = getframe(l, sig, &onstack); + struct sigcontext ksc; struct frame *f = l->l_md.md_regs; sig_t catcher = SIGACTION(p, sig).sa_handler; +#if !defined(__mips_o32) + if (p->p_md.md_abi != _MIPS_BSD_API_O32) + sigexit(l, SIGILL); +#endif scp--; @@ -109,21 +118,23 @@ /* Save register context. */ ksc.sc_regs[_R_ZERO] = 0xACEDBADE; /* magic number */ +#if defined(__mips_o32) memcpy(&ksc.sc_regs[1], &f->f_regs[1], sizeof(ksc.sc_regs) - sizeof(ksc.sc_regs[0])); +#else + for (size_t i = 1; i < 32; i++) + ksc.sc_regs[i] = f->f_regs[i]; +#endif /* Save the FP state, if necessary, then copy it. */ #ifndef SOFTFLOAT ksc.sc_fpused = l->l_md.md_flags & MDP_FPUSED; if (ksc.sc_fpused) { /* if FPU has current state, save it first */ - if (l == fpcurlwp) - savefpregs(l); - *(struct fpreg *)ksc.sc_fpregs = l->l_addr->u_pcb.pcb_fpregs; + savefpregs(l); } -#else - *(struct fpreg *)ksc.sc_fpregs = l->l_addr->u_pcb.pcb_fpregs; #endif + *(struct fpreg *)ksc.sc_fpregs = *(struct fpreg *)&l->l_addr->u_pcb.pcb_fpregs; /* Save signal stack. */ ksc.sc_onstack = l->l_sigstk.ss_flags & SS_ONSTACK; @@ -225,6 +236,11 @@ struct proc *p = l->l_proc; int error; +#if !defined(__mips_o32) + if (p->p_md.md_abi != _MIPS_BSD_API_O32) + return ENOSYS; +#endif + /* * The trampoline code hands us the context. * It is unsafe to keep track of it ourselves, in the event that a @@ -246,19 +262,21 @@ f->f_regs[_R_PC] = ksc.sc_pc; f->f_regs[_R_MULLO] = ksc.mullo; f->f_regs[_R_MULHI] = ksc.mulhi; +#if defined(__mips_o32) memcpy(&f->f_regs[1], &scp->sc_regs[1], sizeof(scp->sc_regs) - sizeof(scp->sc_regs[0])); +#else + for (size_t i = 1; i < __arraycount(f->f_regs); i++) + f->f_regs[i] = ksc.sc_regs[i]; +#endif #ifndef SOFTFLOAT if (scp->sc_fpused) { /* Disable the FPU to fault in FP registers. */ f->f_regs[_R_SR] &= ~MIPS_SR_COP_1_BIT; - if (l == fpcurlwp) - fpcurlwp = NULL; - l->l_addr->u_pcb.pcb_fpregs = *(struct fpreg *)scp->sc_fpregs; + fpcurlwp = &lwp0; } -#else - l->l_addr->u_pcb.pcb_fpregs = *(struct fpreg *)scp->sc_fpregs; #endif + *(struct fpreg *)&l->l_addr->u_pcb.pcb_fpregs = *(struct fpreg *)scp->sc_fpregs; mutex_enter(p->p_lock); /* Restore signal stack. */