Source-Changes-HG archive

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

[src/netbsd-1-4]: src/sys/arch/i386/i386 Pull up revision 1.58 (via patch, re...



details:   https://anonhg.NetBSD.org/src/rev/308bfe44bdce
branches:  netbsd-1-4
changeset: 471307:308bfe44bdce
user:      he <he%NetBSD.org@localhost>
date:      Sun Jul 29 18:20:14 2001 +0000

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

diffstat:

 sys/arch/i386/i386/sys_machdep.c |  74 ++++++++++++++++++++++++---------------
 1 files changed, 46 insertions(+), 28 deletions(-)

diffs (147 lines):

diff -r 7f76e75a430b -r 308bfe44bdce sys/arch/i386/i386/sys_machdep.c
--- a/sys/arch/i386/i386/sys_machdep.c  Thu Jul 19 13:54:05 2001 +0000
+++ b/sys/arch/i386/i386/sys_machdep.c  Sun Jul 29 18:20:14 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_machdep.c,v 1.47.2.1 2001/01/17 16:34:32 he Exp $  */
+/*     $NetBSD: sys_machdep.c,v 1.47.2.2 2001/07/29 18:20:14 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>
@@ -251,7 +252,7 @@
        struct pcb *pcb = &p->p_addr->u_pcb;
        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);
@@ -266,6 +267,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;
+
        /* allocate user ldt */
        if (pcb->pcb_ldt == 0 || (ua.start + ua.num) > pcb->pcb_ldt_len) {
                size_t old_len, new_len;
@@ -310,12 +318,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:
@@ -325,22 +332,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:
@@ -354,34 +368,38 @@
                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);
+                               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;
-
-               pcb->pcb_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