Module Name: src Committed By: bouyer Date: Sun Nov 15 21:01:52 UTC 2015
Modified Files: src/sys/arch/sparc64/sparc64 [netbsd-6-0]: locore.s netbsd32_machdep.c vm_machdep.c Log Message: Pull up following revision(s) (requested by martin in ticket #1343): sys/arch/sparc64/sparc64/locore.s: revision 1.386 sys/arch/sparc64/sparc64/vm_machdep.c: revision 1.101 sys/arch/sparc64/sparc64/netbsd32_machdep.c: revision 1.105 sys/arch/sparc64/sparc64/netbsd32_machdep.c: revision 1.106 Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c: Remove special case handling for userland lwps from cpu_lwp_fork, instead do it in lwp_trampoline when we first return to userland. which was a stupid idea - since we did now set all fork child's %tstate (and thus %pstate when back in userland) to the current kernel's userland default. This meant we lost the address mask bit for 32bit processes and all memory model details for 64bit ones. Move it back to cpu_lwp_fork and fix the condition to only do it once when forking init. Fix kmem_free() size mismatch Convert siginfo to 32bit version before copying it out to 32bit userland. To generate a diff of this commit: cvs rdiff -u -r1.338.8.2.4.1 -r1.338.8.2.4.2 \ src/sys/arch/sparc64/sparc64/locore.s cvs rdiff -u -r1.96.2.1 -r1.96.2.1.4.1 \ src/sys/arch/sparc64/sparc64/netbsd32_machdep.c cvs rdiff -u -r1.98 -r1.98.12.1 src/sys/arch/sparc64/sparc64/vm_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/sparc64/sparc64/locore.s diff -u src/sys/arch/sparc64/sparc64/locore.s:1.338.8.2.4.1 src/sys/arch/sparc64/sparc64/locore.s:1.338.8.2.4.2 --- src/sys/arch/sparc64/sparc64/locore.s:1.338.8.2.4.1 Sat Dec 14 19:33:45 2013 +++ src/sys/arch/sparc64/sparc64/locore.s Sun Nov 15 21:01:52 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.s,v 1.338.8.2.4.1 2013/12/14 19:33:45 bouyer Exp $ */ +/* $NetBSD: locore.s,v 1.338.8.2.4.2 2015/11/15 21:01:52 bouyer Exp $ */ /* * Copyright (c) 2006-2010 Matthew R. Green @@ -5369,12 +5369,6 @@ ENTRY(lwp_trampoline) mov %l1, %o0 /* - * Going to userland - set proper tstate in trap frame - */ - set (ASI_PRIMARY_NO_FAULT<<TSTATE_ASI_SHIFT)|((PSTATE_USER)<<TSTATE_PSTATE_SHIFT), %g1 - stx %g1, [%sp + CC64FSZ + STKB + TF_TSTATE] - - /* * Here we finish up as in syscall, but simplified. */ ba,a,pt %icc, return_from_trap Index: src/sys/arch/sparc64/sparc64/netbsd32_machdep.c diff -u src/sys/arch/sparc64/sparc64/netbsd32_machdep.c:1.96.2.1 src/sys/arch/sparc64/sparc64/netbsd32_machdep.c:1.96.2.1.4.1 --- src/sys/arch/sparc64/sparc64/netbsd32_machdep.c:1.96.2.1 Mon May 21 15:25:56 2012 +++ src/sys/arch/sparc64/sparc64/netbsd32_machdep.c Sun Nov 15 21:01:52 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_machdep.c,v 1.96.2.1 2012/05/21 15:25:56 riz Exp $ */ +/* $NetBSD: netbsd32_machdep.c,v 1.96.2.1.4.1 2015/11/15 21:01:52 bouyer Exp $ */ /* * Copyright (c) 1998, 2001 Matthew R. Green @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.96.2.1 2012/05/21 15:25:56 riz Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.96.2.1.4.1 2015/11/15 21:01:52 bouyer Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -322,6 +322,7 @@ netbsd32_sendsig_siginfo(const ksiginfo_ int sig = ksi->ksi_signo; ucontext32_t uc; struct sparc32_sigframe_siginfo *fp; + siginfo32_t si32; netbsd32_intptr_t catcher; struct trapframe64 *tf = l->l_md.md_tf; struct rwindow32 *oldsp, *newsp; @@ -342,15 +343,16 @@ netbsd32_sendsig_siginfo(const ksiginfo_ else fp = (struct sparc32_sigframe_siginfo *)oldsp; fp = (struct sparc32_sigframe_siginfo*)((u_long)(fp - 1) & ~7); + /* * Build the signal context to be used by sigreturn. */ + memset(&uc, 0, sizeof uc); uc.uc_flags = _UC_SIGMASK | ((l->l_sigstk.ss_flags & SS_ONSTACK) ? _UC_SETSTACK : _UC_CLRSTACK); uc.uc_sigmask = *mask; uc.uc_link = (uint32_t)(uintptr_t)l->l_ctxlink; - memset(&uc.uc_stack, 0, sizeof(uc.uc_stack)); sendsig_reset(l, sig); @@ -365,9 +367,10 @@ netbsd32_sendsig_siginfo(const ksiginfo_ */ mutex_exit(p->p_lock); cpu_getmcontext32(l, &uc.uc_mcontext, &uc.uc_flags); + netbsd32_si_to_si32(&si32, (const siginfo_t *)&ksi->ksi_info); ucsz = (int)(intptr_t)&uc.__uc_pad - (int)(intptr_t)&uc; newsp = (struct rwindow32*)((intptr_t)fp - sizeof(struct frame32)); - error = (copyout(&ksi->ksi_info, &fp->sf_si, sizeof ksi->ksi_info) || + error = (copyout(&si32, &fp->sf_si, sizeof si32) || copyout(&uc, &fp->sf_uc, ucsz) || suword(&newsp->rw_in[6], (intptr_t)oldsp)); mutex_enter(p->p_lock); @@ -1367,7 +1370,8 @@ startlwp32(void *arg) error = cpu_setmcontext32(l, &uc->uc_mcontext, uc->uc_flags); KASSERT(error == 0); - kmem_free(uc, sizeof(ucontext32_t)); + /* Note: we are freeing ucontext_t, not ucontext32_t. */ + kmem_free(arg, sizeof(ucontext_t)); userret(l, 0, 0); } Index: src/sys/arch/sparc64/sparc64/vm_machdep.c diff -u src/sys/arch/sparc64/sparc64/vm_machdep.c:1.98 src/sys/arch/sparc64/sparc64/vm_machdep.c:1.98.12.1 --- src/sys/arch/sparc64/sparc64/vm_machdep.c:1.98 Sat Oct 8 08:49:07 2011 +++ src/sys/arch/sparc64/sparc64/vm_machdep.c Sun Nov 15 21:01:52 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: vm_machdep.c,v 1.98 2011/10/08 08:49:07 nakayama Exp $ */ +/* $NetBSD: vm_machdep.c,v 1.98.12.1 2015/11/15 21:01:52 bouyer Exp $ */ /* * Copyright (c) 1996-2002 Eduardo Horvath. All rights reserved. @@ -50,7 +50,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.98 2011/10/08 08:49:07 nakayama Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.98.12.1 2015/11/15 21:01:52 bouyer Exp $"); #include "opt_multiprocessor.h" @@ -263,6 +263,14 @@ cpu_lwp_fork(register struct lwp *l1, re tf2->tf_out[6] = (uint64_t)(u_long)stack + stacksize; /* + * Need to create a %tstate if we are forking our first userland + * process - in all other cases we inherit from the parent. + */ + if (l2->l_proc->p_pid == 1) + tf2->tf_tstate = (ASI_PRIMARY_NO_FAULT<<TSTATE_ASI_SHIFT) | + ((PSTATE_USER)<<TSTATE_PSTATE_SHIFT); + + /* * Set return values in child mode and clear condition code, * in case we end up running a signal handler before returning * to userland.