Module Name:    src
Committed By:   msaitoh
Date:           Mon Nov 16 13:39:47 UTC 2015

Modified Files:
        src/sys/arch/sparc64/sparc64 [netbsd-7-0]: locore.s netbsd32_machdep.c
            vm_machdep.c

Log Message:
Pull up following revision(s) (requested by martin in ticket #1028):
        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.369.2.2 -r1.369.2.2.2.1 \
    src/sys/arch/sparc64/sparc64/locore.s
cvs rdiff -u -r1.103 -r1.103.8.1 \
    src/sys/arch/sparc64/sparc64/netbsd32_machdep.c
cvs rdiff -u -r1.100 -r1.100.8.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.369.2.2 src/sys/arch/sparc64/sparc64/locore.s:1.369.2.2.2.1
--- src/sys/arch/sparc64/sparc64/locore.s:1.369.2.2	Mon Mar  9 07:54:12 2015
+++ src/sys/arch/sparc64/sparc64/locore.s	Mon Nov 16 13:39:47 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.s,v 1.369.2.2 2015/03/09 07:54:12 snj Exp $	*/
+/*	$NetBSD: locore.s,v 1.369.2.2.2.1 2015/11/16 13:39:47 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2006-2010 Matthew R. Green
@@ -5764,12 +5764,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.103 src/sys/arch/sparc64/sparc64/netbsd32_machdep.c:1.103.8.1
--- src/sys/arch/sparc64/sparc64/netbsd32_machdep.c:1.103	Fri Mar  7 22:51:27 2014
+++ src/sys/arch/sparc64/sparc64/netbsd32_machdep.c	Mon Nov 16 13:39:47 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.103 2014/03/07 22:51:27 nakayama Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.103.8.1 2015/11/16 13:39:47 msaitoh 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.103 2014/03/07 22:51:27 nakayama Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.103.8.1 2015/11/16 13:39:47 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -319,6 +319,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;
@@ -339,15 +340,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);
 
@@ -362,9 +364,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);
@@ -1327,7 +1330,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.100 src/sys/arch/sparc64/sparc64/vm_machdep.c:1.100.8.1
--- src/sys/arch/sparc64/sparc64/vm_machdep.c:1.100	Sun Sep 15 16:04:16 2013
+++ src/sys/arch/sparc64/sparc64/vm_machdep.c	Mon Nov 16 13:39:47 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm_machdep.c,v 1.100 2013/09/15 16:04:16 martin Exp $ */
+/*	$NetBSD: vm_machdep.c,v 1.100.8.1 2015/11/16 13:39:47 msaitoh 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.100 2013/09/15 16:04:16 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.100.8.1 2015/11/16 13:39:47 msaitoh Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -247,6 +247,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.

Reply via email to