Commit | Line | Data |
---|---|---|
619edcce KM |
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.1 (Berkeley) %G% | |
15 | */ | |
16 | ||
17 | /* | |
18 | * Traditional sbrk/grow interface to VM | |
19 | */ | |
20 | #include "param.h" | |
21 | #include "systm.h" | |
22 | #include "user.h" | |
23 | #include "proc.h" | |
24 | ||
25 | #include "../vm/vm_param.h" | |
26 | #include "machine/vmparam.h" | |
27 | ||
28 | /* ARGSUSED */ | |
29 | obreak(p, uap, retval) | |
30 | struct proc *p; | |
31 | struct args { | |
32 | char *nsiz; | |
33 | } *uap; | |
34 | int *retval; | |
35 | { | |
36 | vm_offset_t new, old; | |
37 | int rv; | |
38 | register int diff; | |
39 | ||
40 | old = (vm_offset_t)u.u_daddr; | |
41 | new = round_page(uap->nsiz); | |
42 | if ((int)(new - old) > u.u_rlimit[RLIMIT_DATA].rlim_cur) | |
43 | return(ENOMEM); | |
44 | old = round_page(old + ctob(u.u_dsize)); | |
45 | diff = new - old; | |
46 | if (diff > 0) { | |
47 | rv = vm_allocate(p->p_map, &old, diff, FALSE); | |
48 | if (rv != KERN_SUCCESS) { | |
49 | uprintf("sbrk: grow failed, return = %d\n", rv); | |
50 | return(ENOMEM); | |
51 | } | |
52 | u.u_dsize += btoc(diff); | |
53 | } else if (diff < 0) { | |
54 | diff = -diff; | |
55 | rv = vm_deallocate(p->p_map, new, diff); | |
56 | if (rv != KERN_SUCCESS) { | |
57 | uprintf("sbrk: shrink failed, return = %d\n", rv); | |
58 | return(ENOMEM); | |
59 | } | |
60 | u.u_dsize -= btoc(diff); | |
61 | } | |
62 | return(0); | |
63 | } | |
64 | ||
65 | /* | |
66 | * grow the stack to include the SP | |
67 | * true return if successful. | |
68 | */ | |
69 | grow(sp) | |
70 | unsigned sp; | |
71 | { | |
72 | register int si; | |
73 | ||
74 | /* | |
75 | * For user defined stacks (from sendsig). | |
76 | */ | |
77 | if (sp < (unsigned)u.u_maxsaddr) | |
78 | return (0); | |
79 | /* | |
80 | * For common case of already allocated (from trap). | |
81 | */ | |
82 | if (sp >= USRSTACK-ctob(u.u_ssize)) | |
83 | return (1); | |
84 | /* | |
85 | * Really need to check vs limit and increment stack size if ok. | |
86 | */ | |
87 | si = clrnd(btoc(USRSTACK-sp) - u.u_ssize); | |
88 | if (u.u_ssize+si > btoc(u.u_rlimit[RLIMIT_STACK].rlim_cur)) | |
89 | return (0); | |
90 | u.u_ssize += si; | |
91 | return (1); | |
92 | } | |
93 | ||
94 | /* ARGSUSED */ | |
95 | ovadvise(p, uap, retval) | |
96 | struct proc *p; | |
97 | struct args { | |
98 | int anom; | |
99 | } *uap; | |
100 | int *retval; | |
101 | { | |
102 | ||
103 | } |