Module Name:    src
Committed By:   bouyer
Date:           Sun Oct 18 15:20:43 UTC 2009

Modified Files:
        src/sys/arch/amd64/amd64 [netbsd-4]: machdep.c
        src/sys/arch/i386/i386 [netbsd-4]: machdep.c
        src/sys/arch/i386/isa [netbsd-4]: npx.c

Log Message:
Pull up following revision(s) (requested by mlelstv in ticket #1363):
        sys/arch/i386/isa/npx.c: revision 1.132 via patch
        sys/arch/amd64/amd64/fpu.c: revision 1.29 via patch
        sys/arch/amd64/amd64/machdep.c: revision 1.105 via patch
        sys/arch/i386/i386/machdep.c: revision 1.647 via patch
PR port-i386/39299 FPU use in signal handlers is unsafe
Ensure FP state is reset, if FP is used in a signal handler.
Fixes PR kern/39299 for 32bit code.


To generate a diff of this commit:
cvs rdiff -u -r1.44.2.5 -r1.44.2.6 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.586.2.5 -r1.586.2.6 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.115 -r1.115.2.1 src/sys/arch/i386/isa/npx.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/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.44.2.5 src/sys/arch/amd64/amd64/machdep.c:1.44.2.6
--- src/sys/arch/amd64/amd64/machdep.c:1.44.2.5	Sat Nov 22 16:33:41 2008
+++ src/sys/arch/amd64/amd64/machdep.c	Sun Oct 18 15:20:42 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.44.2.5 2008/11/22 16:33:41 bouyer Exp $	*/
+/*	$NetBSD: machdep.c,v 1.44.2.6 2009/10/18 15:20:42 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000 The NetBSD Foundation, Inc.
@@ -72,7 +72,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.44.2.5 2008/11/22 16:33:41 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.44.2.6 2009/10/18 15:20:42 bouyer Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_ddb.h"
@@ -518,6 +518,9 @@
 
 	buildcontext(l, catcher, fp);
 
+	/* Ensure FP state is reset, if FP is used. */
+	l->l_md.md_flags &= ~MDP_USEDFPU;
+
 	tf->tf_rdi = sig;
 	tf->tf_rsi = (uint64_t)&fp->sf_si;
 	tf->tf_rdx = tf->tf_r15 = (uint64_t)&fp->sf_uc;

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.586.2.5 src/sys/arch/i386/i386/machdep.c:1.586.2.6
--- src/sys/arch/i386/i386/machdep.c:1.586.2.5	Tue Aug 28 11:46:26 2007
+++ src/sys/arch/i386/i386/machdep.c	Sun Oct 18 15:20:42 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.586.2.5 2007/08/28 11:46:26 liamjfoy Exp $	*/
+/*	$NetBSD: machdep.c,v 1.586.2.6 2009/10/18 15:20:42 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006 The NetBSD Foundation, Inc.
@@ -72,7 +72,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.586.2.5 2007/08/28 11:46:26 liamjfoy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.586.2.6 2009/10/18 15:20:42 bouyer Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_ibcs2.h"
@@ -810,6 +810,12 @@
 
 	buildcontext(l, sel, catcher, fp);
 
+#if NNPX > 0
+	/* make sure we get a clean FPU */
+	npxsave_lwp(l, 0);
+	l->l_md.md_flags &= ~MDL_USEDFPU;
+#endif
+
 	/* Remember that we're now on the signal stack. */
 	if (onstack)
 		p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;

Index: src/sys/arch/i386/isa/npx.c
diff -u src/sys/arch/i386/isa/npx.c:1.115 src/sys/arch/i386/isa/npx.c:1.115.2.1
--- src/sys/arch/i386/isa/npx.c:1.115	Thu Nov 16 01:32:38 2006
+++ src/sys/arch/i386/isa/npx.c	Sun Oct 18 15:20:42 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: npx.c,v 1.115 2006/11/16 01:32:38 christos Exp $	*/
+/*	$NetBSD: npx.c,v 1.115.2.1 2009/10/18 15:20:42 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1991 The Regents of the University of California.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npx.c,v 1.115 2006/11/16 01:32:38 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npx.c,v 1.115.2.1 2009/10/18 15:20:42 bouyer Exp $");
 
 #if 0
 #define IPRINTF(x)	printf x
@@ -565,7 +565,14 @@
 	splx(s);
 
 	if ((l->l_md.md_flags & MDL_USEDFPU) == 0) {
-		fldcw(&l->l_addr->u_pcb.pcb_savefpu.sv_xmm.sv_env.en_cw);
+		fninit();
+		if (i386_use_fxsave) {
+			fldcw(&l->l_addr->u_pcb.pcb_savefpu.
+			    sv_xmm.sv_env.en_cw);
+		} else {
+			fldcw(&l->l_addr->u_pcb.pcb_savefpu.
+			    sv_87.sv_env.en_cw);
+		}
 		l->l_md.md_flags |= MDL_USEDFPU;
 	} else {
 		/*

Reply via email to