Source-Changes-HG archive

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

[src/netbsd-1-5]: src/sys/arch/i386/i386 Pull up revision 1.58 (requested by ...



details:   https://anonhg.NetBSD.org/src/rev/90e4b085ff1a
branches:  netbsd-1-5
changeset: 491879:90e4b085ff1a
user:      he <he%NetBSD.org@localhost>
date:      Sun Jun 10 19:37:12 2001 +0000

description:
Pull up revision 1.58 (requested by sommerfeld):
  Copy in segment descriptors all at once rather than one at a time.

diffstat:

 sys/arch/i386/i386/sys_machdep.c |  78 +++++++++++++++++++++++++--------------
 1 files changed, 49 insertions(+), 29 deletions(-)

diffs (150 lines):

diff -r d496653c8d99 -r 90e4b085ff1a sys/arch/i386/i386/sys_machdep.c
--- a/sys/arch/i386/i386/sys_machdep.c  Sun Jun 10 19:13:33 2001 +0000
+++ b/sys/arch/i386/i386/sys_machdep.c  Sun Jun 10 19:37:12 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_machdep.c,v 1.48.14.1 2001/01/17 01:44:52 tv Exp $ */
+/*     $NetBSD: sys_machdep.c,v 1.48.14.2 2001/06/10 19:37:12 he Exp $ */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -89,6 +89,7 @@
 #include <sys/buf.h>
 #include <sys/trace.h>
 #include <sys/signal.h>
+#include <sys/malloc.h>
 
 #include <sys/mount.h>
 #include <sys/syscallargs.h>
@@ -238,7 +239,7 @@
        pmap_t pmap = p->p_vmspace->vm_map.pmap;
        int fsslot, gsslot;
        struct i386_set_ldt_args ua;
-       union descriptor desc;
+       union descriptor *descv;
 
        if ((error = copyin(args, &ua, sizeof(ua))) != 0)
                return (error);
@@ -253,6 +254,13 @@
        if (ua.start > 8192 || (ua.start + ua.num) > 8192)
                return (EINVAL);
 
+       descv = malloc(sizeof (*descv) * ua.num, M_TEMP, M_NOWAIT);
+       if (descv == NULL)
+               return (ENOMEM);
+
+       if ((error = copyin(ua.desc, descv, sizeof (*descv) * ua.num)) != 0)
+               goto out;
+       
        /*
         * XXX LOCKING
         */
@@ -308,12 +316,11 @@
 
        /* Check descriptors for access violations. */
        for (i = 0, n = ua.start; i < ua.num; i++, n++) {
-               if ((error = copyin(&ua.desc[i], &desc, sizeof(desc))) != 0)
-                       return (error);
+               union descriptor *desc = &descv[i];
 
-               switch (desc.sd.sd_type) {
+               switch (desc->sd.sd_type) {
                case SDT_SYSNULL:
-                       desc.sd.sd_p = 0;
+                       desc->sd.sd_p = 0;
                        break;
                case SDT_SYS286CGT:
                case SDT_SYS386CGT:
@@ -323,22 +330,29 @@
                         * part of the gdt.  Segments in the LDT are
                         * constrained (below) to be user segments.
                         */
-                       if (desc.gd.gd_p != 0 && !ISLDT(desc.gd.gd_selector) &&
-                           ((IDXSEL(desc.gd.gd_selector) >= NGDT) ||
-                            (gdt[IDXSEL(desc.gd.gd_selector)].sd.sd_dpl !=
-                                SEL_UPL)))
-                               return (EACCES);
+                       if (desc->gd.gd_p != 0 &&
+                           !ISLDT(desc->gd.gd_selector) &&
+                           ((IDXSEL(desc->gd.gd_selector) >= NGDT) ||
+                            (gdt[IDXSEL(desc->gd.gd_selector)].sd.sd_dpl !=
+                                SEL_UPL))) {
+                               error = EACCES;
+                               goto out;
+                       }
                        /* Can't replace in use descriptor with gate. */
-                       if (n == fsslot || n == gsslot)
-                               return (EBUSY);
+                       if (n == fsslot || n == gsslot) {
+                               error = EBUSY;
+                               goto out;
+                       }
                        break;
                case SDT_MEMEC:
                case SDT_MEMEAC:
                case SDT_MEMERC:
                case SDT_MEMERAC:
                        /* Must be "present" if executable and conforming. */
-                       if (desc.sd.sd_p == 0)
-                               return (EACCES);
+                       if (desc->sd.sd_p == 0) {
+                               error = EACCES;
+                               goto out;
+                       }
                        break;
                case SDT_MEMRO:
                case SDT_MEMROA:
@@ -352,34 +366,40 @@
                case SDT_MEMERA:
                        break;
                default:
-                       /* Only care if it's present. */
-                       if (desc.sd.sd_p != 0)
-                               return (EACCES);
+                       /*
+                        * Make sure that unknown descriptor types are
+                        * not marked present.
+                        */
+                       if (desc->sd.sd_p != 0) {
+                               error = EACCES;
+                               goto out;
+                       }
                        break;
                }
 
-               if (desc.sd.sd_p != 0) {
+               if (desc->sd.sd_p != 0) {
                        /* Only user (ring-3) descriptors may be present. */
-                       if (desc.sd.sd_dpl != SEL_UPL)
-                               return (EACCES);
+                       if (desc->sd.sd_dpl != SEL_UPL) {
+                               error = EACCES;
+                               goto out;
+                       }
                } else {
                        /* Must be "present" if in use. */
-                       if (n == fsslot || n == gsslot)
-                               return (EBUSY);
+                       if (n == fsslot || n == gsslot) {
+                               error = EACCES;
+                               goto out;
+                       }
                }
        }
 
        /* Now actually replace the descriptors. */
-       for (i = 0, n = ua.start; i < ua.num; i++, n++) {
-               if ((error = copyin(&ua.desc[i], &desc, sizeof(desc))) != 0)
-                       goto out;
-
-               pmap->pm_ldt[n] = desc;
-       }
+       for (i = 0, n = ua.start; i < ua.num; i++, n++)
+               pmap->pm_ldt[n] = descv[i];
 
        *retval = ua.start;
 
 out:
+       free(descv, M_TEMP);
        return (error);
 }
 #endif /* USER_LDT */



Home | Main Index | Thread Index | Old Index