From 3c6a70419354386d1701bb1d8a8ff87a5d96bb7c Mon Sep 17 00:00:00 2001 From: nisimura Date: Thu, 3 Dec 1998 06:28:45 +0000 Subject: [PATCH] - Use explicite structure member reference with 'struct frame' to alter register values of exception frame pointed with p->p_md.md_regs. - Local auto variable 'cpustate' in cpu_coredump() was never used correctly. --- sys/arch/mips/mips/compat_13_machdep.c | 20 +++--- sys/arch/mips/mips/cpu_exec.c | 4 +- sys/arch/mips/mips/mips_machdep.c | 89 +++++++++++++------------- sys/arch/mips/mips/vm_machdep.c | 21 +++--- 4 files changed, 65 insertions(+), 69 deletions(-) diff --git a/sys/arch/mips/mips/compat_13_machdep.c b/sys/arch/mips/mips/compat_13_machdep.c index 6d1cf11acfcc..fd4dab767387 100644 --- a/sys/arch/mips/mips/compat_13_machdep.c +++ b/sys/arch/mips/mips/compat_13_machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat_13_machdep.c,v 1.4 1998/10/02 18:49:00 drochner Exp $ */ +/* $NetBSD: compat_13_machdep.c,v 1.5 1998/12/03 06:28:46 nisimura Exp $ */ /* * Copyright 1996 The Board of Trustees of The Leland Stanford @@ -15,7 +15,7 @@ #include /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: compat_13_machdep.c,v 1.4 1998/10/02 18:49:00 drochner Exp $"); +__KERNEL_RCSID(0, "$NetBSD: compat_13_machdep.c,v 1.5 1998/12/03 06:28:46 nisimura Exp $"); #include #include @@ -45,9 +45,9 @@ compat_13_sys_sigreturn(p, v, retval) struct compat_13_sys_sigreturn_args /* { syscallarg(struct sigcontext13 *) sigcntxp; } */ *uap = v; - struct sigcontext13 *scp; - int error, *regs; - struct sigcontext13 ksc; + struct sigcontext13 *scp, ksc; + int error; + struct frame *f; sigset_t mask; /* @@ -67,11 +67,11 @@ compat_13_sys_sigreturn(p, v, retval) return (EINVAL); /* Resture the register context. */ - regs = p->p_md.md_regs; - regs[PC] = ksc.sc_pc; - regs[MULLO] = ksc.mullo; - regs[MULHI] = ksc.mulhi; - memcpy(®s[1], &scp->sc_regs[1], + f = (struct frame *)p->p_md.md_regs; + f->f_regs[PC] = ksc.sc_pc; + f->f_regs[MULLO] = ksc.mullo; + f->f_regs[MULHI] = ksc.mulhi; + memcpy(&f->f_regs[1], &scp->sc_regs[1], sizeof(scp->sc_regs) - sizeof(scp->sc_regs[0])); if (scp->sc_fpused) p->p_addr->u_pcb.pcb_fpregs = *(struct fpreg *)scp->sc_fpregs; diff --git a/sys/arch/mips/mips/cpu_exec.c b/sys/arch/mips/mips/cpu_exec.c index 8b77a04070a5..69b07fa45686 100644 --- a/sys/arch/mips/mips/cpu_exec.c +++ b/sys/arch/mips/mips/cpu_exec.c @@ -1,4 +1,4 @@ -/* $NetBSD: cpu_exec.c,v 1.17 1998/07/28 21:40:55 thorpej Exp $ */ +/* $NetBSD: cpu_exec.c,v 1.18 1998/12/03 06:28:45 nisimura Exp $ */ /* * Copyright (c) 1992, 1993 @@ -146,7 +146,7 @@ cpu_exec_ecoff_setregs(p, epp, stack) struct ecoff_exechdr *execp = (struct ecoff_exechdr *)epp->ep_hdr; setregs(p, epp, stack); - p->p_md.md_regs[GP] = execp->a.gp_value; + ((struct frame *)p->p_md.md_regs)->f_regs[GP] = execp->a.gp_value; } /* diff --git a/sys/arch/mips/mips/mips_machdep.c b/sys/arch/mips/mips/mips_machdep.c index 9786578c87fe..1250e34b98b7 100644 --- a/sys/arch/mips/mips/mips_machdep.c +++ b/sys/arch/mips/mips/mips_machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: mips_machdep.c,v 1.39 1998/11/02 07:43:37 simonb Exp $ */ +/* $NetBSD: mips_machdep.c,v 1.40 1998/12/03 06:28:45 nisimura Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -52,7 +52,7 @@ #include /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: mips_machdep.c,v 1.39 1998/11/02 07:43:37 simonb Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mips_machdep.c,v 1.40 1998/12/03 06:28:45 nisimura Exp $"); #include "opt_compat_netbsd.h" #include "opt_compat_ultrix.h" @@ -649,31 +649,30 @@ setregs(p, pack, stack) struct exec_package *pack; u_long stack; { - extern struct proc *fpcurproc; - - memset(p->p_md.md_regs, 0, sizeof(struct frame)); - memset(&p->p_addr->u_pcb.pcb_fpregs, 0, sizeof(struct fpreg)); - p->p_md.md_regs[SP] = stack; - p->p_md.md_regs[PC] = pack->ep_entry & ~3; - p->p_md.md_regs[T9] = pack->ep_entry & ~3; /* abicall requirement */ - p->p_md.md_regs[SR] = PSL_USERSET; - p->p_md.md_flags &= ~MDP_FPUSED; - if (fpcurproc == p) - fpcurproc = (struct proc *)0; - p->p_md.md_ss_addr = 0; + struct frame *f = (struct frame *)p->p_md.md_regs; + memset(f, 0, sizeof(struct frame)); + f->f_regs[SP] = stack; + f->f_regs[PC] = pack->ep_entry & ~3; + f->f_regs[T9] = pack->ep_entry & ~3; /* abicall requirement */ + f->f_regs[SR] = PSL_USERSET; /* - * Set up arguments for the dld-capable crt0: - * + * Set up arguments for the rtld-capable crt0: * a0 stack pointer * a1 rtld cleanup (filled in by dynamic loader) * a2 rtld object (filled in by dynamic loader) * a3 ps_strings */ - p->p_md.md_regs[A0] = stack; - p->p_md.md_regs[A1] = 0; - p->p_md.md_regs[A2] = 0; - p->p_md.md_regs[A3] = (u_long)PS_STRINGS; + f->f_regs[A0] = (mips_reg_t)stack; + f->f_regs[A1] = 0; + f->f_regs[A2] = 0; + f->f_regs[A3] = (mips_reg_t)PS_STRINGS; + + if (fpcurproc == p) + fpcurproc = (struct proc *)0; + memset(&p->p_addr->u_pcb.pcb_fpregs, 0, sizeof(struct fpreg)); + p->p_md.md_flags &= ~MDP_FPUSED; + p->p_md.md_ss_addr = 0; } /* @@ -708,12 +707,12 @@ sendsig(catcher, sig, mask, code) { struct proc *p = curproc; struct sigframe *fp; - int *regs; + struct frame *f; struct sigacts *psp = p->p_sigacts; int onstack; struct sigcontext ksc; - regs = p->p_md.md_regs; + f = (struct frame *)p->p_md.md_regs; /* Do we need to jump onto the signal stack? */ onstack = @@ -725,7 +724,7 @@ sendsig(catcher, sig, mask, code) fp = (struct sigframe *)((caddr_t)psp->ps_sigstk.ss_sp + psp->ps_sigstk.ss_size); else - fp = (struct sigframe *)regs[SP]; + fp = (struct sigframe *)f->f_regs[SP]; fp--; #ifdef DEBUG @@ -736,20 +735,18 @@ sendsig(catcher, sig, mask, code) #endif /* Build stack frame for signal trampoline. */ - ksc.sc_pc = regs[PC]; - ksc.mullo = regs[MULLO]; - ksc.mulhi = regs[MULHI]; + ksc.sc_pc = f->f_regs[PC]; + ksc.mullo = f->f_regs[MULLO]; + ksc.mulhi = f->f_regs[MULHI]; /* Save register context. */ ksc.sc_regs[ZERO] = 0xACEDBADE; /* magic number */ - memcpy(&ksc.sc_regs[1], ®s[1], + memcpy(&ksc.sc_regs[1], &f->f_regs[1], sizeof(ksc.sc_regs) - sizeof(ksc.sc_regs[0])); /* Save the floating-pointstate, if necessary, then copy it. */ ksc.sc_fpused = p->p_md.md_flags & MDP_FPUSED; if (ksc.sc_fpused) { - extern struct proc *fpcurproc; - /* if FPU has current state, save it first */ if (p == fpcurproc) savefpregs(p); @@ -788,17 +785,17 @@ sendsig(catcher, sig, mask, code) } /* Set up the registers to return to sigcode. */ - regs[A0] = sig; - regs[A1] = code; - regs[A2] = (int)&fp->sf_sc; - regs[A3] = (int)catcher; + f->f_regs[A0] = sig; + f->f_regs[A1] = code; + f->f_regs[A2] = (int)&fp->sf_sc; + f->f_regs[A3] = (int)catcher; - regs[PC] = (int)catcher; - regs[T9] = (int)catcher; - regs[SP] = (int)fp; + f->f_regs[PC] = (int)catcher; + f->f_regs[T9] = (int)catcher; + f->f_regs[SP] = (int)fp; /* Signal trampoline code is at base of user stack. */ - regs[RA] = (int)psp->ps_sigcode; + f->f_regs[RA] = (int)psp->ps_sigcode; /* Remember that we're now on the signal stack. */ if (onstack) @@ -832,9 +829,9 @@ sys___sigreturn14(p, v, retval) struct sys___sigreturn14_args /* { syscallarg(struct sigcontext *) sigcntxp; } */ *uap = v; - struct sigcontext *scp; - int error, *regs; - struct sigcontext ksc; + struct sigcontext *scp, ksc; + struct frame *f; + int error; /* * The trampoline code hands us the context. @@ -853,11 +850,11 @@ sys___sigreturn14(p, v, retval) return (EINVAL); /* Resture the register context. */ - regs = p->p_md.md_regs; - regs[PC] = ksc.sc_pc; - regs[MULLO] = ksc.mullo; - regs[MULHI] = ksc.mulhi; - memcpy(®s[1], &scp->sc_regs[1], + f = (struct frame *)p->p_md.md_regs; + f->f_regs[PC] = ksc.sc_pc; + f->f_regs[MULLO] = ksc.mullo; + f->f_regs[MULHI] = ksc.mulhi; + memcpy(&f->f_regs[1], &scp->sc_regs[1], sizeof(scp->sc_regs) - sizeof(scp->sc_regs[0])); if (scp->sc_fpused) p->p_addr->u_pcb.pcb_fpregs = *(struct fpreg *)scp->sc_fpregs; @@ -1246,7 +1243,7 @@ mips_init_proc0(space) u_long pa; int i; - bzero(space, 2 * USPACE); + memset(space, 0, 2 * USPACE); proc0.p_addr = proc0paddr = (struct user *)space; proc0.p_md.md_regs = proc0paddr->u_pcb.pcb_regs; diff --git a/sys/arch/mips/mips/vm_machdep.c b/sys/arch/mips/mips/vm_machdep.c index 12995ac1b310..0d3a163f6c85 100644 --- a/sys/arch/mips/mips/vm_machdep.c +++ b/sys/arch/mips/mips/vm_machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: vm_machdep.c,v 1.30 1998/11/11 06:41:27 thorpej Exp $ */ +/* $NetBSD: vm_machdep.c,v 1.31 1998/12/03 06:28:46 nisimura Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -43,7 +43,7 @@ */ #include /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.30 1998/11/11 06:41:27 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.31 1998/12/03 06:28:46 nisimura Exp $"); #include "opt_uvm.h" @@ -71,7 +71,6 @@ __KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.30 1998/11/11 06:41:27 thorpej Exp /* XXX will be declared in mips/include/cpu.h XXX */ extern struct proc *fpcurproc; -extern void savefpregs __P((struct proc *)); extern vm_offset_t kvtophys __P((vm_offset_t kva)); /* XXX */ @@ -125,10 +124,11 @@ cpu_set_kpc(p, pc, arg) void (*pc) __P((void *)); void *arg; { - p->p_addr->u_pcb.pcb_context[10] = - (int)proc_trampoline; /* RA */ - p->p_addr->u_pcb.pcb_context[0] = (int)pc; /* S0 */ - p->p_addr->u_pcb.pcb_context[1] = (int)arg; /* S1 */ + struct pcb *pcb = &p->p_addr->u_pcb; + + pcb->pcb_context[10] = (int)proc_trampoline; /* RA */ + pcb->pcb_context[0] = (int)pc; /* S0 */ + pcb->pcb_context[1] = (int)arg; /* S1 */ } /* @@ -208,7 +208,7 @@ cpu_coredump(p, vp, cred, chdr) cpustate.fpregs = p->p_addr->u_pcb.pcb_fpregs; } else - bzero((caddr_t)&cpustate.fpregs, sizeof(struct fpreg)); + memset(&cpustate.fpregs, 0, sizeof(struct fpreg)); CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU); cseg.c_addr = 0; @@ -219,9 +219,8 @@ cpu_coredump(p, vp, cred, chdr) if (error) return error; - error = vn_rdwr(UIO_WRITE, vp, - (caddr_t)(&(p -> p_addr -> u_pcb.pcb_regs)), - (off_t)chdr -> c_cpusize, + error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&cpustate, + (off_t)chdr->c_cpusize, (off_t)(chdr->c_hdrsize + chdr->c_seghdrsize), UIO_SYSSPACE, IO_NODELOCKED|IO_UNIT, cred, NULL, p);