xref: /original-bsd/sys/vm/vm_unix.c (revision 02e832b2)
1 /*
2  * Copyright (c) 1988 University of Utah.
3  * Copyright (c) 1991 The Regents of the University of California.
4  * 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.
9  *
10  * %sccs.include.redist.c%
11  *
12  * from: Utah $Hdr: vm_unix.c 1.1 89/11/07$
13  *
14  *	@(#)vm_unix.c	7.4 (Berkeley) 07/10/92
15  */
16 
17 /*
18  * Traditional sbrk/grow interface to VM
19  */
20 #include <sys/param.h>
21 #include <sys/systm.h>
22 #include <sys/proc.h>
23 #include <sys/resourcevar.h>
24 
25 #include <vm/vm.h>
26 
27 struct obreak_args {
28 	char	*nsiz;
29 };
30 /* ARGSUSED */
31 int
32 obreak(p, uap, retval)
33 	struct proc *p;
34 	struct obreak_args *uap;
35 	int *retval;
36 {
37 	register struct vmspace *vm = p->p_vmspace;
38 	vm_offset_t new, old;
39 	int rv;
40 	register int diff;
41 
42 	old = (vm_offset_t)vm->vm_daddr;
43 	new = round_page(uap->nsiz);
44 	if ((int)(new - old) > p->p_rlimit[RLIMIT_DATA].rlim_cur)
45 		return(ENOMEM);
46 	old = round_page(old + ctob(vm->vm_dsize));
47 	diff = new - old;
48 	if (diff > 0) {
49 		rv = vm_allocate(&vm->vm_map, &old, diff, FALSE);
50 		if (rv != KERN_SUCCESS) {
51 			uprintf("sbrk: grow failed, return = %d\n", rv);
52 			return(ENOMEM);
53 		}
54 		vm->vm_dsize += btoc(diff);
55 	} else if (diff < 0) {
56 		diff = -diff;
57 		rv = vm_deallocate(&vm->vm_map, new, diff);
58 		if (rv != KERN_SUCCESS) {
59 			uprintf("sbrk: shrink failed, return = %d\n", rv);
60 			return(ENOMEM);
61 		}
62 		vm->vm_dsize -= btoc(diff);
63 	}
64 	return(0);
65 }
66 
67 /*
68  * Enlarge the "stack segment" to include the specified
69  * stack pointer for the process.
70  */
71 int
72 grow(p, sp)
73 	struct proc *p;
74 	unsigned sp;
75 {
76 	register struct vmspace *vm = p->p_vmspace;
77 	register int si;
78 
79 	/*
80 	 * For user defined stacks (from sendsig).
81 	 */
82 	if (sp < (unsigned)vm->vm_maxsaddr)
83 		return (0);
84 	/*
85 	 * For common case of already allocated (from trap).
86 	 */
87 	if (sp >= USRSTACK - ctob(vm->vm_ssize))
88 		return (1);
89 	/*
90 	 * Really need to check vs limit and increment stack size if ok.
91 	 */
92 	si = clrnd(btoc(USRSTACK-sp) - vm->vm_ssize);
93 	if (vm->vm_ssize + si > btoc(p->p_rlimit[RLIMIT_STACK].rlim_cur))
94 		return (0);
95 	vm->vm_ssize += si;
96 	return (1);
97 }
98 
99 struct ovadvise_args {
100 	int	anom;
101 };
102 /* ARGSUSED */
103 int
104 ovadvise(p, uap, retval)
105 	struct proc *p;
106 	struct ovadvise_args *uap;
107 	int *retval;
108 {
109 
110 	return (EINVAL);
111 }
112