This source file includes following definitions.
- sys_obreak
- uvm_grow
- sys_ovadvise
- uvm_coredump
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 #include <sys/param.h>
54 #include <sys/systm.h>
55 #include <sys/proc.h>
56 #include <sys/resourcevar.h>
57 #include <sys/vnode.h>
58 #include <sys/core.h>
59
60 #include <sys/mount.h>
61 #include <sys/syscallargs.h>
62
63 #include <uvm/uvm.h>
64
65
66
67
68
69 int
70 sys_obreak(p, v, retval)
71 struct proc *p;
72 void *v;
73 register_t *retval;
74 {
75 struct sys_obreak_args
76
77 *uap = v;
78 struct vmspace *vm = p->p_vmspace;
79 vaddr_t new, old;
80 int error;
81
82 old = (vaddr_t)vm->vm_daddr;
83 new = round_page((vaddr_t)SCARG(uap, nsize));
84 if ((new - old) > p->p_rlimit[RLIMIT_DATA].rlim_cur)
85 return (ENOMEM);
86
87 old = round_page(old + ptoa(vm->vm_dsize));
88
89 if (new == old)
90 return (0);
91
92
93
94
95 if (new > old) {
96 error = uvm_map(&vm->vm_map, &old, new - old, NULL,
97 UVM_UNKNOWN_OFFSET, 0,
98 UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_RWX, UVM_INH_COPY,
99 UVM_ADV_NORMAL, UVM_FLAG_AMAPPAD|UVM_FLAG_FIXED|
100 UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW));
101 if (error) {
102 uprintf("sbrk: grow %ld failed, error = %d\n",
103 new - old, error);
104 return (ENOMEM);
105 }
106 vm->vm_dsize += atop(new - old);
107 } else {
108 uvm_deallocate(&vm->vm_map, new, old - new);
109 vm->vm_dsize -= atop(old - new);
110 }
111
112 return (0);
113 }
114
115
116
117
118
119 void
120 uvm_grow(p, sp)
121 struct proc *p;
122 vaddr_t sp;
123 {
124 struct vmspace *vm = p->p_vmspace;
125 int si;
126
127
128
129
130 if (sp < (vaddr_t)vm->vm_maxsaddr)
131 return;
132
133
134
135
136 #ifdef MACHINE_STACK_GROWS_UP
137 if (sp < USRSTACK + ctob(vm->vm_ssize))
138 #else
139 if (sp >= USRSTACK - ctob(vm->vm_ssize))
140 #endif
141 return;
142
143
144
145
146 #ifdef MACHINE_STACK_GROWS_UP
147 si = btoc(sp - USRSTACK) - vm->vm_ssize;
148 #else
149 si = btoc(USRSTACK - sp) - vm->vm_ssize;
150 #endif
151 if (vm->vm_ssize + si <= btoc(p->p_rlimit[RLIMIT_STACK].rlim_cur))
152 vm->vm_ssize += si;
153 }
154
155
156
157
158
159
160 int
161 sys_ovadvise(p, v, retval)
162 struct proc *p;
163 void *v;
164 register_t *retval;
165 {
166 #if 0
167 struct sys_ovadvise_args
168
169 *uap = v;
170 #endif
171
172 return (EINVAL);
173 }
174
175
176
177
178
179 int
180 uvm_coredump(p, vp, cred, chdr)
181 struct proc *p;
182 struct vnode *vp;
183 struct ucred *cred;
184 struct core *chdr;
185 {
186 struct vmspace *vm = p->p_vmspace;
187 vm_map_t map = &vm->vm_map;
188 vm_map_entry_t entry;
189 vaddr_t start, end;
190 struct coreseg cseg;
191 off_t offset;
192 int flag, error = 0;
193
194 offset = chdr->c_hdrsize + chdr->c_seghdrsize + chdr->c_cpusize;
195
196 for (entry = map->header.next; entry != &map->header;
197 entry = entry->next) {
198
199
200 if (UVM_ET_ISSUBMAP(entry)) {
201 panic("uvm_coredump: user process with submap?");
202 }
203
204 if (!(entry->protection & VM_PROT_WRITE))
205 continue;
206
207
208
209
210 if (entry->object.uvm_obj != NULL &&
211 UVM_OBJ_IS_DEVICE(entry->object.uvm_obj))
212 continue;
213
214 start = entry->start;
215 end = entry->end;
216
217 if (start >= VM_MAXUSER_ADDRESS)
218 continue;
219
220 if (end > VM_MAXUSER_ADDRESS)
221 end = VM_MAXUSER_ADDRESS;
222
223 #ifdef MACHINE_STACK_GROWS_UP
224 if (USRSTACK <= start && start < (USRSTACK + MAXSSIZ)) {
225 end = round_page(USRSTACK + ctob(vm->vm_ssize));
226 if (start >= end)
227 continue;
228 start = USRSTACK;
229 #else
230 if (start >= (vaddr_t)vm->vm_maxsaddr) {
231 start = trunc_page(USRSTACK - ctob(vm->vm_ssize));
232
233 if (start >= end)
234 continue;
235 #endif
236 flag = CORE_STACK;
237 } else
238 flag = CORE_DATA;
239
240
241
242
243 CORE_SETMAGIC(cseg, CORESEGMAGIC, CORE_GETMID(*chdr), flag);
244 cseg.c_addr = start;
245 cseg.c_size = end - start;
246
247 error = vn_rdwr(UIO_WRITE, vp,
248 (caddr_t)&cseg, chdr->c_seghdrsize,
249 offset, UIO_SYSSPACE,
250 IO_NODELOCKED|IO_UNIT, cred, NULL, p);
251
252
253
254
255 if (error && error != EFAULT)
256 break;
257
258 offset += chdr->c_seghdrsize;
259 error = vn_rdwr(UIO_WRITE, vp,
260 (caddr_t)(u_long)cseg.c_addr, (int)cseg.c_size,
261 offset, UIO_USERSPACE,
262 IO_NODELOCKED|IO_UNIT, cred, NULL, p);
263 if (error)
264 break;
265
266 offset += cseg.c_size;
267 chdr->c_nseg++;
268 }
269
270 return (error);
271 }
272