Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/x86/x86 Use a variable-sized memcpy, instead of cop...



details:   https://anonhg.NetBSD.org/src/rev/95e41a81b389
branches:  trunk
changeset: 320313:95e41a81b389
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sun Jul 01 08:32:41 2018 +0000

description:
Use a variable-sized memcpy, instead of copying the PCB and then adding
the extra bytes. The PCB embeds the biggest static FPU state, but our
real FPU state may be smaller (FNSAVE), so we don't need to memcpy the
extra unused bytes.

diffstat:

 sys/arch/x86/x86/fpu.c        |  17 +++++------------
 sys/arch/x86/x86/vm_machdep.c |  10 +++++-----
 2 files changed, 10 insertions(+), 17 deletions(-)

diffs (74 lines):

diff -r 12e5424be36b -r 95e41a81b389 sys/arch/x86/x86/fpu.c
--- a/sys/arch/x86/x86/fpu.c    Sun Jul 01 07:59:30 2018 +0000
+++ b/sys/arch/x86/x86/fpu.c    Sun Jul 01 08:32:41 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fpu.c,v 1.45 2018/07/01 07:18:56 maxv Exp $    */
+/*     $NetBSD: fpu.c,v 1.46 2018/07/01 08:32:41 maxv Exp $    */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.  All
@@ -96,7 +96,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.45 2018/07/01 07:18:56 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.46 2018/07/01 08:32:41 maxv Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -723,17 +723,10 @@
 void
 fpu_save_area_fork(struct pcb *pcb2, const struct pcb *pcb1)
 {
-       ssize_t extra;
+       const uint8_t *src = (const uint8_t *)&pcb1->pcb_savefpu;
+       uint8_t *dst = (uint8_t *)&pcb2->pcb_savefpu;
 
-       /*
-        * The pcb itself has been copied, but the xsave area
-        * extends further.
-        */
-       extra = offsetof(struct pcb, pcb_savefpu) + x86_fpu_save_size -
-           sizeof (struct pcb);
-
-       if (extra > 0)
-               memcpy(pcb2 + 1, pcb1 + 1, extra);
+       memcpy(dst, src, x86_fpu_save_size);
 
        KASSERT(pcb2->pcb_fpcpu == NULL);
 }
diff -r 12e5424be36b -r 95e41a81b389 sys/arch/x86/x86/vm_machdep.c
--- a/sys/arch/x86/x86/vm_machdep.c     Sun Jul 01 07:59:30 2018 +0000
+++ b/sys/arch/x86/x86/vm_machdep.c     Sun Jul 01 08:32:41 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vm_machdep.c,v 1.34 2018/06/19 07:23:44 maxv Exp $     */
+/*     $NetBSD: vm_machdep.c,v 1.35 2018/07/01 08:32:41 maxv Exp $     */
 
 /*-
  * Copyright (c) 1982, 1986 The Regents of the University of California.
@@ -80,7 +80,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.34 2018/06/19 07:23:44 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.35 2018/07/01 08:32:41 maxv Exp $");
 
 #include "opt_mtrr.h"
 
@@ -155,13 +155,13 @@
                KASSERT(l1 == &lwp0);
        }
 
-       /* Copy the PCB from parent. */
-       memcpy(pcb2, pcb1, sizeof(struct pcb));
+       /* Copy the PCB from parent, except the FPU state. */
+       memcpy(pcb2, pcb1, offsetof(struct pcb, pcb_savefpu));
 
        /* FPU state not installed. */
        pcb2->pcb_fpcpu = NULL;
 
-       /* Copy any additional fpu state */
+       /* Copy FPU state. */
        fpu_save_area_fork(pcb2, pcb1);
 
        /* Never inherit CPU Debug Registers */



Home | Main Index | Thread Index | Old Index