Source-Changes-HG archive

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

[src/netbsd-1-5]: src/sys/uvm Pull up rev. 1.14:



details:   https://anonhg.NetBSD.org/src/rev/c6cb9ce71fde
branches:  netbsd-1-5
changeset: 488356:c6cb9ce71fde
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun Jul 02 17:41:17 2000 +0000

description:
Pull up rev. 1.14:
- Avoid an integer overflow when checking if we have exceeded our
  rlimit in sbrk.  Slightly modified from a patch from Artur Grabowski.
- Rearrange code slightly, partially from Artur Grabowski.
- Only adjust vm_dsize if the grow or shrink actually succeeds.

diffstat:

 sys/uvm/uvm_unix.c |  46 ++++++++++++++++++++++------------------------
 1 files changed, 22 insertions(+), 24 deletions(-)

diffs (77 lines):

diff -r 352d53b36701 -r c6cb9ce71fde sys/uvm/uvm_unix.c
--- a/sys/uvm/uvm_unix.c        Sun Jul 02 16:53:23 2000 +0000
+++ b/sys/uvm/uvm_unix.c        Sun Jul 02 17:41:17 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_unix.c,v 1.12 2000/03/30 12:31:50 augustss Exp $   */
+/*     $NetBSD: uvm_unix.c,v 1.12.4.1 2000/07/02 17:41:17 thorpej Exp $        */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -79,46 +79,44 @@
        } */ *uap = v;
        struct vmspace *vm = p->p_vmspace;
        vaddr_t new, old;
+       ssize_t diff;
        int rv;
-       int diff;
 
        old = (vaddr_t)vm->vm_daddr;
        new = round_page((vaddr_t)SCARG(uap, nsize));
-       if ((int)(new - old) > p->p_rlimit[RLIMIT_DATA].rlim_cur)
-               return(ENOMEM);
+       if ((new - old) > p->p_rlimit[RLIMIT_DATA].rlim_cur)
+               return (ENOMEM);
 
-       old = round_page(old + ctob(vm->vm_dsize));
+       old = round_page(old + ptoa(vm->vm_dsize));
        diff = new - old;
 
+       if (diff == 0)
+               return (0);
+
        /*
         * grow or shrink?
         */
-
        if (diff > 0) {
-
                rv = uvm_map(&vm->vm_map, &old, diff, NULL, UVM_UNKNOWN_OFFSET,
                    UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL, UVM_INH_COPY,
                    UVM_ADV_NORMAL, UVM_FLAG_AMAPPAD|UVM_FLAG_FIXED|
                    UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW)); 
-
-               if (rv != KERN_SUCCESS) {
-                       uprintf("sbrk: grow failed, return = %d\n", rv);
-                       return(ENOMEM);
+               if (rv == KERN_SUCCESS) {
+                       vm->vm_dsize += atop(diff);
+                       return (0);
                }
-               vm->vm_dsize += btoc(diff);
-
-       } else if (diff < 0) {
+       } else {
+               rv = uvm_deallocate(&vm->vm_map, new, -diff);
+               if (rv == KERN_SUCCESS) {
+                       vm->vm_dsize -= atop(-diff);
+                       return (0);
+               }
+       }
 
-               diff = -diff;
-               rv = uvm_deallocate(&vm->vm_map, new, diff);
-               if (rv != KERN_SUCCESS) {
-                       uprintf("sbrk: shrink failed, return = %d\n", rv);
-                       return(ENOMEM);
-               }
-               vm->vm_dsize -= btoc(diff);
-
-       }
-       return(0);
+       uprintf("sbrk: %s %ld failed, return = %d\n",
+           diff > 0 ? "grow" : "shrink",
+           (long)(diff > 0 ? diff : -diff), rv);
+       return (ENOMEM);
 }
 
 /*



Home | Main Index | Thread Index | Old Index