diff --git a/sys/arch/vax/include/Makefile b/sys/arch/vax/include/Makefile index a1f951501b7a..601698afa167 100644 --- a/sys/arch/vax/include/Makefile +++ b/sys/arch/vax/include/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.26 2007/02/16 01:34:02 matt Exp $ +# $NetBSD: Makefile,v 1.27 2007/02/16 02:17:42 ad Exp $ INCSDIR= /usr/include/vax @@ -17,7 +17,7 @@ INCS= ansi.h aout_machdep.h asm.h \ nexus.h param.h pcb.h pmap.h pmc.h \ proc.h profile.h psl.h pte.h ptrace.h \ qdioctl.h qdreg.h qduser.h qevent.h \ - reg.h rpb.h rsp.h \ + reg.h rpb.h rsp.h rwlock.h \ scb.h setjmp.h sid.h signal.h stdarg.h \ trap.h types.h \ uvax.h \ diff --git a/sys/arch/vax/include/userret.h b/sys/arch/vax/include/userret.h index 6572674571b9..dd0dab3b46c2 100644 --- a/sys/arch/vax/include/userret.h +++ b/sys/arch/vax/include/userret.h @@ -1,4 +1,4 @@ -/* $NetBSD: userret.h,v 1.2 2007/02/09 21:55:13 ad Exp $ */ +/* $NetBSD: userret.h,v 1.3 2007/02/16 02:17:42 ad Exp $ */ /* * Copyright (c) 1994 Ludd, University of Lule}, Sweden. @@ -40,33 +40,24 @@ userret(struct lwp *, struct trapframe *, u_quad_t); static __inline void userret(struct lwp *l, struct trapframe *frame, u_quad_t oticks) { - int sig; struct proc *p = l->l_proc; /* Take pending signals. */ - while ((sig = CURSIG(l)) != 0) - postsig(sig); - l->l_priority = l->l_usrpri; - if (curcpu()->ci_want_resched) { - /* - * We are being preempted. - */ - preempt(0); - while ((sig = CURSIG(l)) != 0) - postsig(sig); + for (;;) { + if ((l->l_flag & L_USERRET) != 0) + lwp_userret(l); + if (!curcpu()->ci_want_resched) + break; + preempt(); } - /* Invoke per-process kernel-exit handling, if any */ - if (p->p_userret) - (p->p_userret)(l, p->p_userret_arg); - /* * If profiling, charge system time to the trapped pc. */ - if (p->p_flag & P_PROFIL) { + if ((p->p_stflag & PST_PROFIL) != 0) { extern int psratio; - addupc_task(p, frame->pc, + addupc_task(l, frame->pc, (int)(p->p_sticks - oticks) * psratio); } diff --git a/sys/arch/vax/vax/sig_machdep.c b/sys/arch/vax/vax/sig_machdep.c index cbfc5aed6897..3c303b65c4d8 100644 --- a/sys/arch/vax/vax/sig_machdep.c +++ b/sys/arch/vax/vax/sig_machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: sig_machdep.c,v 1.7 2007/02/09 21:55:13 ad Exp $ */ +/* $NetBSD: sig_machdep.c,v 1.8 2007/02/16 02:17:42 ad Exp $ */ /* * Copyright (c) 1982, 1986, 1990 The Regents of the University of California. @@ -83,7 +83,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.7 2007/02/09 21:55:13 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.8 2007/02/16 02:17:42 ad Exp $"); #include "opt_ddb.h" #include "opt_compat_netbsd.h" @@ -192,13 +192,16 @@ compat_13_sys_sigreturn(struct lwp *l, void *v, register_t *retval) (ksc.sc_ps & PSL_CM)) { return (EINVAL); } + + mutex_enter(&p->p_smutex); if (ksc.sc_onstack & SS_ONSTACK) - p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK; + l->l_sigstk.ss_flags |= SS_ONSTACK; else - p->p_sigctx.ps_sigstk.ss_flags &= ~SS_ONSTACK; + l->l_sigstk.ss_flags &= ~SS_ONSTACK; native_sigset13_to_sigset(&ksc.sc_mask, &mask); - (void) sigprocmask1(p, SIG_SETMASK, &mask, 0); + (void) sigprocmask1(l, SIG_SETMASK, &mask, 0); + mutex_exit(&p->p_smutex); scf->fp = ksc.sc_fp; scf->ap = ksc.sc_ap; @@ -224,6 +227,8 @@ setupstack_oldsigcontext(const ksiginfo_t *ksi, const sigset_t *mask, int vers, { struct sigcontext sigctx; struct otrampframe tramp; + struct proc *p = l->l_proc; + boolean_t error; sigctx.sc_pc = tf->pc; sigctx.sc_ps = tf->psl; @@ -247,12 +252,17 @@ setupstack_oldsigcontext(const ksiginfo_t *ksi, const sigset_t *mask, int vers, tramp.r0 = tramp.r1 = tramp.r2 = tramp.r3 = tramp.r4 = tramp.r5 = 0; tramp.pc = (register_t)handler; tramp.arg = sp; + sendsig_reset(l, ksi->ksi_signo); + mutex_exit(&p->p_smutex); /* Point stack pointer at pc in trampoline. */ sp =- 8; - if (copyout(&tramp, (caddr_t)tramp.scp - sizeof(tramp), sizeof(tramp)) != 0 || - copyout(&sigctx, (caddr_t)tramp.scp, sizeof(sigctx)) != 0) + error = (copyout(&tramp, (caddr_t)tramp.scp - sizeof(tramp), sizeof(tramp)) != 0 || + copyout(&sigctx, (caddr_t)tramp.scp, sizeof(sigctx)) != 0); + + mutex_enter(&p->p_smutex); + if (error) return 0; return sp; @@ -282,12 +292,15 @@ compat_16_sys___sigreturn14(struct lwp *l, void *v, register_t *retval) (ksc.sc_ps & PSL_CM)) { return (EINVAL); } + + mutex_enter(&p->p_smutex); if (ksc.sc_onstack & SS_ONSTACK) - p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK; + l->l_sigstk.ss_flags |= SS_ONSTACK; else - p->p_sigctx.ps_sigstk.ss_flags &= ~SS_ONSTACK; + l->l_sigstk.ss_flags &= ~SS_ONSTACK; /* Restore signal mask. */ - (void) sigprocmask1(p, SIG_SETMASK, &ksc.sc_mask, 0); + (void) sigprocmask1(l, SIG_SETMASK, &ksc.sc_mask, 0); + mutex_exit(&p->p_smutex); scf->fp = ksc.sc_fp; scf->ap = ksc.sc_ap; @@ -327,6 +340,8 @@ setupstack_sigcontext2(const ksiginfo_t *ksi, const sigset_t *mask, int vers, { struct trampoline2 tramp; struct sigcontext sigctx; + struct proc *p = l->l_proc; + boolean_t error; /* The sigcontext struct will be passed back to sigreturn(). */ sigctx.sc_pc = tf->pc; @@ -344,13 +359,18 @@ setupstack_sigcontext2(const ksiginfo_t *ksi, const sigset_t *mask, int vers, tramp.code = (register_t)ksi->ksi_addr; tramp.scp = sp; sp -= sizeof(tramp); + sendsig_reset(l, ksi->ksi_signo); + mutex_exit(&p->p_smutex); /* Store the handler in the trapframe. */ tf->fp = handler; /* Copy out the sigcontext and trampoline. */ - if (copyout(&sigctx, (char *)tramp.scp, sizeof(sigctx)) != 0 || - copyout(&tramp, (char *)sp, sizeof(tramp)) != 0) + error = (copyout(&sigctx, (char *)tramp.scp, sizeof(sigctx)) != 0 || + copyout(&tramp, (char *)sp, sizeof(tramp)) != 0); + + mutex_enter(&p->p_smutex); + if (error) return 0; /* return updated stack pointer */ @@ -386,7 +406,9 @@ setupstack_siginfo3(const ksiginfo_t *ksi, const sigset_t *mask, int vers, vaddr_t handler) { struct trampoline3 tramp; + struct proc *p = l->l_proc; ucontext_t uc; + boolean_t error; /* * Arguments given to the signal handler. @@ -402,14 +424,19 @@ setupstack_siginfo3(const ksiginfo_t *ksi, const sigset_t *mask, int vers, uc.uc_sigmask = *mask; uc.uc_link = NULL; memset(&uc.uc_stack, 0, sizeof(uc.uc_stack)); + sendsig_reset(l, ksi->ksi_signo); + mutex_exit(&p->p_smutex); cpu_getmcontext(l, &uc.uc_mcontext, &uc.uc_flags); tf->fp = handler; /* Copy the context to the stack. */ - if (copyout(&uc, (char *)tramp.ucp, sizeof(uc)) != 0 || + error = (copyout(&uc, (char *)tramp.ucp, sizeof(uc)) != 0 || copyout(&ksi->ksi_info, (char *)tramp.sip, sizeof(ksi->ksi_info)) != 0 || - copyout(&tramp, (char *)sp, sizeof(tramp)) != 0) + copyout(&tramp, (char *)sp, sizeof(tramp)) != 0); + + mutex_enter(&p->p_smutex); + if (error) sigexit(l, SIGILL); return sp; @@ -421,7 +448,7 @@ sendsig(const ksiginfo_t *ksi, const sigset_t *mask) struct lwp *l = curlwp; struct proc *p = l->l_proc; struct trapframe *tf = l->l_addr->u_pcb.framep; - struct sigaltstack *ss = &p->p_sigctx.ps_sigstk; + struct sigaltstack *ss = &l->l_sigstk; const struct sigact_sigdesc *sd = &p->p_sigacts->sa_sigdesc[ksi->ksi_signo]; vaddr_t sp; diff --git a/sys/arch/vax/vax/syscall.c b/sys/arch/vax/vax/syscall.c index a88d4928ac6f..b1b73f74d101 100644 --- a/sys/arch/vax/vax/syscall.c +++ b/sys/arch/vax/vax/syscall.c @@ -1,4 +1,4 @@ -/* $NetBSD: syscall.c,v 1.3 2007/02/09 21:55:13 ad Exp $ */ +/* $NetBSD: syscall.c,v 1.4 2007/02/16 02:17:42 ad Exp $ */ /* * Copyright (c) 1994 Ludd, University of Lule}, Sweden. @@ -33,7 +33,7 @@ /* All bugs are subject to removal without further notice */ #include -__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.3 2007/02/09 21:55:13 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.4 2007/02/16 02:17:42 ad Exp $"); #include "opt_multiprocessor.h" @@ -117,17 +117,20 @@ syscall_plain(struct trapframe *frame) rval[0] = 0; rval[1] = frame->r1; - KERNEL_PROC_LOCK(l); if (callp->sy_narg) { err = copyin((char*)frame->ap + 4, args, callp->sy_argsize); - if (err) { - KERNEL_PROC_UNLOCK(l); + if (err) goto bad; - } } - err = (*callp->sy_call)(curlwp, args, rval); - KERNEL_PROC_UNLOCK(l); + if ((callp->sy_flags & SYCALL_MPSAFE) != 0) + err = (*callp->sy_call)(curlwp, args, rval); + else { + KERNEL_LOCK(1, l); + err = (*callp->sy_call)(curlwp, args, rval); + KERNEL_UNLOCK_LAST(l); + } + exptr = l->l_addr->u_pcb.framep; TDB(("return %s pc %lx, psl %lx, sp %lx, pid %d, err %d r0 %d, r1 %d, " @@ -195,21 +198,24 @@ syscall_fancy(struct trapframe *frame) rval[0] = 0; rval[1] = frame->r1; - KERNEL_PROC_LOCK(l); if (callp->sy_narg) { err = copyin((char*)frame->ap + 4, args, callp->sy_argsize); - if (err) { - KERNEL_PROC_UNLOCK(l); + if (err) goto bad; - } } + KERNEL_LOCK(1, l); if ((err = trace_enter(l, frame->code, frame->code, NULL, args)) != 0) goto out; - err = (*callp->sy_call)(curlwp, args, rval); -out: - KERNEL_PROC_UNLOCK(l); + if ((callp->sy_flags & SYCALL_MPSAFE) == 0) { + err = (*callp->sy_call)(curlwp, args, rval); + out: + KERNEL_UNLOCK_LAST(l); + } else { + KERNEL_UNLOCK_LAST(l); + err = (*callp->sy_call)(curlwp, args, rval); + } exptr = l->l_addr->u_pcb.framep; TDB(("return %s pc %lx, psl %lx, sp %lx, pid %d, err %d r0 %d, r1 %d, " "frame %p\n", syscallnames[exptr->code], exptr->pc, exptr->psl, @@ -245,14 +251,11 @@ child_return(void *arg) { struct lwp *l = arg; - KERNEL_PROC_UNLOCK(l); + KERNEL_UNLOCK_LAST(l); userret(l, l->l_addr->u_pcb.framep, 0); #ifdef KTRACE - if (KTRPOINT(l->l_proc, KTR_SYSRET)) { - KERNEL_PROC_LOCK(l); + if (KTRPOINT(l->l_proc, KTR_SYSRET)) ktrsysret(l, SYS_fork, 0, 0); - KERNEL_PROC_UNLOCK(l); - } #endif } diff --git a/sys/arch/vax/vax/trap.c b/sys/arch/vax/vax/trap.c index daf729d5d7ab..7a649e4e8d4b 100644 --- a/sys/arch/vax/vax/trap.c +++ b/sys/arch/vax/vax/trap.c @@ -1,4 +1,4 @@ -/* $NetBSD: trap.c,v 1.106 2007/02/09 21:55:13 ad Exp $ */ +/* $NetBSD: trap.c,v 1.107 2007/02/16 02:17:42 ad Exp $ */ /* * Copyright (c) 1994 Ludd, University of Lule}, Sweden. @@ -33,7 +33,7 @@ /* All bugs are subject to removal without further notice */ #include -__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.106 2007/02/09 21:55:13 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.107 2007/02/16 02:17:42 ad Exp $"); #include "opt_ddb.h" #include "opt_ktrace.h" @@ -214,14 +214,14 @@ if(faultdebug)printf("trap accflt type %lx, code %lx, pc %lx, psl %lx\n", ftype = VM_PROT_READ; if (umode) - KERNEL_PROC_LOCK(l); + KERNEL_LOCK(1, l); else - KERNEL_LOCK(LK_CANRECURSE|LK_EXCLUSIVE); + KERNEL_LOCK(1, NULL); rv = uvm_fault(map, addr, ftype); if (rv != 0) { if (umode == 0) { - KERNEL_UNLOCK(); + KERNEL_UNLOCK_ONE(NULL); FAULTCHK; panic("Segv in kernel mode: pc %x addr %x", (u_int)frame->pc, (u_int)frame->code); @@ -245,9 +245,9 @@ if(faultdebug)printf("trap accflt type %lx, code %lx, pc %lx, psl %lx\n", uvm_grow(p, addr); } if (umode) - KERNEL_PROC_UNLOCK(l); + KERNEL_UNLOCK_LAST(l); else - KERNEL_UNLOCK(); + KERNEL_UNLOCK_ONE(NULL); break; case T_BPTFLT|T_USER: @@ -301,14 +301,14 @@ if(faultdebug)printf("trap accflt type %lx, code %lx, pc %lx, psl %lx\n", printf("pid %d.%d (%s): sig %d: type %lx, code %lx, pc %lx, psl %lx\n", p->p_pid, l->l_lid, p->p_comm, sig, frame->trap, frame->code, frame->pc, frame->psl); - KERNEL_PROC_LOCK(l); + KERNEL_LOCK(1, l); KSI_INIT_TRAP(&ksi); ksi.ksi_signo = sig; ksi.ksi_trap = frame->trap; ksi.ksi_addr = (void *)frame->code; ksi.ksi_code = code; trapsignal(l, &ksi); - KERNEL_PROC_UNLOCK(l); + KERNEL_UNLOCK_LAST(l); } if (umode == 0)