Deleted Added
full compact
vm_unix.c (118771) vm_unix.c (125454)
1/*
2 * Copyright (c) 1988 University of Utah.
3 * Copyright (c) 1991, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * the Systems Programming Group of the University of Utah Computer
8 * Science Department.

--- 31 unchanged lines hidden (view full) ---

40 * @(#)vm_unix.c 8.1 (Berkeley) 6/11/93
41 */
42
43/*
44 * Traditional sbrk/grow interface to VM
45 */
46
47#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1988 University of Utah.
3 * Copyright (c) 1991, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * the Systems Programming Group of the University of Utah Computer
8 * Science Department.

--- 31 unchanged lines hidden (view full) ---

40 * @(#)vm_unix.c 8.1 (Berkeley) 6/11/93
41 */
42
43/*
44 * Traditional sbrk/grow interface to VM
45 */
46
47#include <sys/cdefs.h>
48__FBSDID("$FreeBSD: head/sys/vm/vm_unix.c 118771 2003-08-11 07:14:08Z bms $");
48__FBSDID("$FreeBSD: head/sys/vm/vm_unix.c 125454 2004-02-04 21:52:57Z jhb $");
49
50#include <sys/param.h>
51#include <sys/lock.h>
52#include <sys/mutex.h>
53#include <sys/proc.h>
54#include <sys/resourcevar.h>
55#include <sys/sysproto.h>
56#include <sys/systm.h>

--- 15 unchanged lines hidden (view full) ---

72/* ARGSUSED */
73int
74obreak(td, uap)
75 struct thread *td;
76 struct obreak_args *uap;
77{
78 struct vmspace *vm = td->td_proc->p_vmspace;
79 vm_offset_t new, old, base;
49
50#include <sys/param.h>
51#include <sys/lock.h>
52#include <sys/mutex.h>
53#include <sys/proc.h>
54#include <sys/resourcevar.h>
55#include <sys/sysproto.h>
56#include <sys/systm.h>

--- 15 unchanged lines hidden (view full) ---

72/* ARGSUSED */
73int
74obreak(td, uap)
75 struct thread *td;
76 struct obreak_args *uap;
77{
78 struct vmspace *vm = td->td_proc->p_vmspace;
79 vm_offset_t new, old, base;
80 rlim_t datalim, vmemlim;
80 int rv;
81 int error = 0;
82 boolean_t do_map_wirefuture;
83
81 int rv;
82 int error = 0;
83 boolean_t do_map_wirefuture;
84
85 PROC_LOCK(td->td_proc);
86 datalim = lim_cur(td->td_proc, RLIMIT_DATA);
87 vmemlim = lim_cur(td->td_proc, RLIMIT_VMEM);
88 PROC_UNLOCK(td->td_proc);
89
84 do_map_wirefuture = FALSE;
85 new = round_page((vm_offset_t)uap->nsize);
86 vm_map_lock(&vm->vm_map);
87
88 base = round_page((vm_offset_t) vm->vm_daddr);
89 old = base + ctob(vm->vm_dsize);
90 if (new > base) {
91 /*
92 * Check the resource limit, but allow a process to reduce
93 * its usage, even if it remains over the limit.
94 */
90 do_map_wirefuture = FALSE;
91 new = round_page((vm_offset_t)uap->nsize);
92 vm_map_lock(&vm->vm_map);
93
94 base = round_page((vm_offset_t) vm->vm_daddr);
95 old = base + ctob(vm->vm_dsize);
96 if (new > base) {
97 /*
98 * Check the resource limit, but allow a process to reduce
99 * its usage, even if it remains over the limit.
100 */
95 if (new - base > td->td_proc->p_rlimit[RLIMIT_DATA].rlim_cur &&
96 new > old) {
101 if (new - base > datalim && new > old) {
97 error = ENOMEM;
98 goto done;
99 }
100 if (new > vm_map_max(&vm->vm_map)) {
101 error = ENOMEM;
102 goto done;
103 }
104 } else if (new < base) {
105 /*
106 * This is simply an invalid value. If someone wants to
107 * do fancy address space manipulations, mmap and munmap
108 * can do most of what the user would want.
109 */
110 error = EINVAL;
111 goto done;
112 }
113 if (new > old) {
102 error = ENOMEM;
103 goto done;
104 }
105 if (new > vm_map_max(&vm->vm_map)) {
106 error = ENOMEM;
107 goto done;
108 }
109 } else if (new < base) {
110 /*
111 * This is simply an invalid value. If someone wants to
112 * do fancy address space manipulations, mmap and munmap
113 * can do most of what the user would want.
114 */
115 error = EINVAL;
116 goto done;
117 }
118 if (new > old) {
114 if (vm->vm_map.size + (new - old) >
115 td->td_proc->p_rlimit[RLIMIT_VMEM].rlim_cur) {
119 if (vm->vm_map.size + (new - old) > vmemlim) {
116 error = ENOMEM;
117 goto done;
118 }
119 rv = vm_map_insert(&vm->vm_map, NULL, 0, old, new,
120 VM_PROT_ALL, VM_PROT_ALL, 0);
121 if (rv != KERN_SUCCESS) {
122 error = ENOMEM;
123 goto done;

--- 53 unchanged lines hidden ---
120 error = ENOMEM;
121 goto done;
122 }
123 rv = vm_map_insert(&vm->vm_map, NULL, 0, old, new,
124 VM_PROT_ALL, VM_PROT_ALL, 0);
125 if (rv != KERN_SUCCESS) {
126 error = ENOMEM;
127 goto done;

--- 53 unchanged lines hidden ---