diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2000-06-30 01:07:50 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2000-06-30 01:07:50 +0000 |
commit | af9ce558c89778cbf5373813fab0b05d9b14f91a (patch) | |
tree | 4ca037eac6cd5b949b025ab72b8fd0af31de5a07 /sys | |
parent | e5a0c77fed01ed5196af92fd7ee909c7013e5a94 (diff) |
Don't cast to int when checking if we have exceeded our rlimit in sbrk.
Plus misc cleanup.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/uvm/uvm_unix.c | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/sys/uvm/uvm_unix.c b/sys/uvm/uvm_unix.c index 7d206b608bc..6cc5d3ae25a 100644 --- a/sys/uvm/uvm_unix.c +++ b/sys/uvm/uvm_unix.c @@ -76,48 +76,43 @@ sys_obreak(p, v, retval) struct sys_obreak_args /* { syscallarg(char *) nsize; } */ *uap = v; - register struct vmspace *vm = p->p_vmspace; + struct vmspace *vm = p->p_vmspace; vaddr_t new, old; int rv; - register int diff; + long diff; old = (vaddr_t)vm->vm_daddr; new = round_page(SCARG(uap, nsize)); - if ((int)(new - old) > p->p_rlimit[RLIMIT_DATA].rlim_cur) + if ((rlim_t)(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)); + } else { + rv = uvm_deallocate(&vm->vm_map, new, -diff); + } - if (rv != KERN_SUCCESS) { - uprintf("sbrk: grow failed, return = %d\n", rv); - return(ENOMEM); - } - vm->vm_dsize += btoc(diff); - - } else if (diff < 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); + vm->vm_dsize += atop(diff); + if (rv != KERN_SUCCESS) { + uprintf("sbrk: %s failed, return = %d\n", + diff > 0 ? "grow" : "shrink", rv); + return(ENOMEM); } - return(0); + + return (0); } /* |