uvm_glue.c revision 1.44.2.21 1 /* $NetBSD: uvm_glue.c,v 1.44.2.21 2002/12/15 18:23:18 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1997 Charles D. Cranor and Washington University.
5 * Copyright (c) 1991, 1993, The Regents of the University of California.
6 *
7 * All rights reserved.
8 *
9 * This code is derived from software contributed to Berkeley by
10 * The Mach Operating System project at Carnegie-Mellon University.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by Charles D. Cranor,
23 * Washington University, the University of California, Berkeley and
24 * its contributors.
25 * 4. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * SUCH DAMAGE.
40 *
41 * @(#)vm_glue.c 8.6 (Berkeley) 1/5/94
42 * from: Id: uvm_glue.c,v 1.1.2.8 1998/02/07 01:16:54 chs Exp
43 *
44 *
45 * Copyright (c) 1987, 1990 Carnegie-Mellon University.
46 * All rights reserved.
47 *
48 * Permission to use, copy, modify and distribute this software and
49 * its documentation is hereby granted, provided that both the copyright
50 * notice and this permission notice appear in all copies of the
51 * software, derivative works or modified versions, and any portions
52 * thereof, and that both notices appear in supporting documentation.
53 *
54 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
55 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
56 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
57 *
58 * Carnegie Mellon requests users of this software to return to
59 *
60 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
61 * School of Computer Science
62 * Carnegie Mellon University
63 * Pittsburgh PA 15213-3890
64 *
65 * any improvements or extensions that they make and grant Carnegie the
66 * rights to redistribute these changes.
67 */
68
69 #include <sys/cdefs.h>
70 __KERNEL_RCSID(0, "$NetBSD: uvm_glue.c,v 1.44.2.21 2002/12/15 18:23:18 thorpej Exp $");
71
72 #include "opt_kgdb.h"
73 #include "opt_kstack.h"
74 #include "opt_sysv.h"
75 #include "opt_uvmhist.h"
76
77 /*
78 * uvm_glue.c: glue functions
79 */
80
81 #include <sys/param.h>
82 #include <sys/systm.h>
83 #include <sys/proc.h>
84 #include <sys/resourcevar.h>
85 #include <sys/buf.h>
86 #include <sys/user.h>
87 #ifdef SYSVSHM
88 #include <sys/shm.h>
89 #endif
90
91 #include <uvm/uvm.h>
92
93 #include <machine/cpu.h>
94
95 /*
96 * local prototypes
97 */
98
99 static void uvm_swapout __P((struct lwp *));
100
101 #define UVM_NUAREA_MAX 16
102 void *uvm_uareas;
103 int uvm_nuarea;
104
105 /*
106 * XXXCDC: do these really belong here?
107 */
108
109 int readbuffers = 0; /* allow KGDB to read kern buffer pool */
110 /* XXX: see uvm_kernacc */
111
112
113 /*
114 * uvm_kernacc: can the kernel access a region of memory
115 *
116 * - called from malloc [DIAGNOSTIC], and /dev/kmem driver (mem.c)
117 */
118
119 boolean_t
120 uvm_kernacc(addr, len, rw)
121 caddr_t addr;
122 size_t len;
123 int rw;
124 {
125 boolean_t rv;
126 vaddr_t saddr, eaddr;
127 vm_prot_t prot = rw == B_READ ? VM_PROT_READ : VM_PROT_WRITE;
128
129 saddr = trunc_page((vaddr_t)addr);
130 eaddr = round_page((vaddr_t)addr + len);
131 vm_map_lock_read(kernel_map);
132 rv = uvm_map_checkprot(kernel_map, saddr, eaddr, prot);
133 vm_map_unlock_read(kernel_map);
134
135 /*
136 * XXX there are still some things (e.g. the buffer cache) that
137 * are managed behind the VM system's back so even though an
138 * address is accessible in the mind of the VM system, there may
139 * not be physical pages where the VM thinks there is. This can
140 * lead to bogus allocation of pages in the kernel address space
141 * or worse, inconsistencies at the pmap level. We only worry
142 * about the buffer cache for now.
143 */
144 if (!readbuffers && rv && (eaddr > (vaddr_t)buffers &&
145 saddr < (vaddr_t)buffers + MAXBSIZE * nbuf))
146 rv = FALSE;
147 return(rv);
148 }
149
150 /*
151 * uvm_useracc: can the user access it?
152 *
153 * - called from physio() and sys___sysctl().
154 */
155
156 boolean_t
157 uvm_useracc(addr, len, rw)
158 caddr_t addr;
159 size_t len;
160 int rw;
161 {
162 struct vm_map *map;
163 boolean_t rv;
164 vm_prot_t prot = rw == B_READ ? VM_PROT_READ : VM_PROT_WRITE;
165
166 /* XXX curproc */
167 map = &curproc->p_vmspace->vm_map;
168
169 vm_map_lock_read(map);
170 rv = uvm_map_checkprot(map, trunc_page((vaddr_t)addr),
171 round_page((vaddr_t)addr + len), prot);
172 vm_map_unlock_read(map);
173
174 return(rv);
175 }
176
177 #ifdef KGDB
178 /*
179 * Change protections on kernel pages from addr to addr+len
180 * (presumably so debugger can plant a breakpoint).
181 *
182 * We force the protection change at the pmap level. If we were
183 * to use vm_map_protect a change to allow writing would be lazily-
184 * applied meaning we would still take a protection fault, something
185 * we really don't want to do. It would also fragment the kernel
186 * map unnecessarily. We cannot use pmap_protect since it also won't
187 * enforce a write-enable request. Using pmap_enter is the only way
188 * we can ensure the change takes place properly.
189 */
190 void
191 uvm_chgkprot(addr, len, rw)
192 caddr_t addr;
193 size_t len;
194 int rw;
195 {
196 vm_prot_t prot;
197 paddr_t pa;
198 vaddr_t sva, eva;
199
200 prot = rw == B_READ ? VM_PROT_READ : VM_PROT_READ|VM_PROT_WRITE;
201 eva = round_page((vaddr_t)addr + len);
202 for (sva = trunc_page((vaddr_t)addr); sva < eva; sva += PAGE_SIZE) {
203 /*
204 * Extract physical address for the page.
205 */
206 if (pmap_extract(pmap_kernel(), sva, &pa) == FALSE)
207 panic("chgkprot: invalid page");
208 pmap_enter(pmap_kernel(), sva, pa, prot, PMAP_WIRED);
209 }
210 pmap_update(pmap_kernel());
211 }
212 #endif
213
214 /*
215 * uvm_vslock: wire user memory for I/O
216 *
217 * - called from physio and sys___sysctl
218 * - XXXCDC: consider nuking this (or making it a macro?)
219 */
220
221 int
222 uvm_vslock(p, addr, len, access_type)
223 struct proc *p;
224 caddr_t addr;
225 size_t len;
226 vm_prot_t access_type;
227 {
228 struct vm_map *map;
229 vaddr_t start, end;
230 int error;
231
232 map = &p->p_vmspace->vm_map;
233 start = trunc_page((vaddr_t)addr);
234 end = round_page((vaddr_t)addr + len);
235 error = uvm_fault_wire(map, start, end, VM_FAULT_WIRE, access_type);
236 return error;
237 }
238
239 /*
240 * uvm_vsunlock: unwire user memory wired by uvm_vslock()
241 *
242 * - called from physio and sys___sysctl
243 * - XXXCDC: consider nuking this (or making it a macro?)
244 */
245
246 void
247 uvm_vsunlock(p, addr, len)
248 struct proc *p;
249 caddr_t addr;
250 size_t len;
251 {
252 uvm_fault_unwire(&p->p_vmspace->vm_map, trunc_page((vaddr_t)addr),
253 round_page((vaddr_t)addr + len));
254 }
255
256 /*
257 * uvm_proc_fork: fork a virtual address space
258 *
259 * - the address space is copied as per parent map's inherit values
260 */
261 void
262 uvm_proc_fork(p1, p2, shared)
263 struct proc *p1, *p2;
264 boolean_t shared;
265 {
266
267 if (shared == TRUE) {
268 p2->p_vmspace = NULL;
269 uvmspace_share(p1, p2);
270 } else {
271 p2->p_vmspace = uvmspace_fork(p1->p_vmspace);
272 }
273
274 cpu_proc_fork(p1, p2);
275 }
276
277
278 /*
279 * uvm_lwp_fork: fork a thread
280 *
281 * - a new "user" structure is allocated for the child process
282 * [filled in by MD layer...]
283 * - if specified, the child gets a new user stack described by
284 * stack and stacksize
285 * - NOTE: the kernel stack may be at a different location in the child
286 * process, and thus addresses of automatic variables may be invalid
287 * after cpu_lwp_fork returns in the child process. We do nothing here
288 * after cpu_lwp_fork returns.
289 * - XXXCDC: we need a way for this to return a failure value rather
290 * than just hang
291 */
292 void
293 uvm_lwp_fork(l1, l2, stack, stacksize, func, arg)
294 struct lwp *l1, *l2;
295 void *stack;
296 size_t stacksize;
297 void (*func) __P((void *));
298 void *arg;
299 {
300 struct user *up = l2->l_addr;
301 int error;
302
303 /*
304 * Wire down the U-area for the process, which contains the PCB
305 * and the kernel stack. Wired state is stored in l->l_flag's
306 * L_INMEM bit rather than in the vm_map_entry's wired count
307 * to prevent kernel_map fragmentation. If we reused a cached U-area,
308 * L_INMEM will already be set and we don't need to do anything.
309 *
310 * Note the kernel stack gets read/write accesses right off the bat.
311 */
312
313 if ((l2->l_flag & L_INMEM) == 0) {
314 error = uvm_fault_wire(kernel_map, (vaddr_t)up,
315 (vaddr_t)up + USPACE, VM_FAULT_WIRE,
316 VM_PROT_READ | VM_PROT_WRITE);
317 if (error)
318 panic("uvm_lwp_fork: uvm_fault_wire failed: %d", error);
319 l2->l_flag |= L_INMEM;
320 }
321
322 #ifdef KSTACK_CHECK_MAGIC
323 /*
324 * fill stack with magic number
325 */
326 kstack_setup_magic(p2);
327 #endif
328
329 /*
330 * cpu_lwp_fork() copy and update the pcb, and make the child ready
331 * to run. If this is a normal user fork, the child will exit
332 * directly to user mode via child_return() on its first time
333 * slice and will not return here. If this is a kernel thread,
334 * the specified entry point will be executed.
335 */
336 cpu_lwp_fork(l1, l2, stack, stacksize, func, arg);
337 }
338
339 /*
340 * uvm_exit: exit a virtual address space
341 *
342 * - the process passed to us is a dead (pre-zombie) process; we
343 * are running on a different context now (the reaper).
344 * - we must run in a separate thread because freeing the vmspace
345 * of the dead process may block.
346 */
347
348 void
349 uvm_proc_exit(p)
350 struct proc *p;
351 {
352 uvmspace_free(p->p_vmspace);
353 }
354
355 void
356 uvm_lwp_exit(l)
357 struct lwp *l;
358 {
359 vaddr_t va = (vaddr_t)l->l_addr;
360
361 l->l_flag &= ~L_INMEM;
362 uvm_uarea_free(va);
363 l->l_addr = NULL;
364 }
365
366 /*
367 * uvm_uarea_alloc: allocate a u-area
368 */
369
370 boolean_t
371 uvm_uarea_alloc(vaddr_t *uaddrp)
372 {
373 vaddr_t uaddr;
374
375 #ifndef USPACE_ALIGN
376 #define USPACE_ALIGN 0
377 #endif
378
379 uaddr = (vaddr_t)uvm_uareas;
380 if (uaddr) {
381 uvm_uareas = *(void **)uvm_uareas;
382 uvm_nuarea--;
383 *uaddrp = uaddr;
384 return TRUE;
385 } else {
386 *uaddrp = uvm_km_valloc_align(kernel_map, USPACE, USPACE_ALIGN);
387 return FALSE;
388 }
389 }
390
391 /*
392 * uvm_uarea_free: free a u-area
393 */
394
395 void
396 uvm_uarea_free(vaddr_t uaddr)
397 {
398
399 if (uvm_nuarea < UVM_NUAREA_MAX) {
400 *(void **)uaddr = uvm_uareas;
401 uvm_uareas = (void *)uaddr;
402 uvm_nuarea++;
403 } else {
404 uvm_km_free(kernel_map, uaddr, USPACE);
405 }
406 }
407
408 /*
409 * uvm_init_limit: init per-process VM limits
410 *
411 * - called for process 0 and then inherited by all others.
412 */
413
414 void
415 uvm_init_limits(p)
416 struct proc *p;
417 {
418
419 /*
420 * Set up the initial limits on process VM. Set the maximum
421 * resident set size to be all of (reasonably) available memory.
422 * This causes any single, large process to start random page
423 * replacement once it fills memory.
424 */
425
426 p->p_rlimit[RLIMIT_STACK].rlim_cur = DFLSSIZ;
427 p->p_rlimit[RLIMIT_STACK].rlim_max = MAXSSIZ;
428 p->p_rlimit[RLIMIT_DATA].rlim_cur = DFLDSIZ;
429 p->p_rlimit[RLIMIT_DATA].rlim_max = MAXDSIZ;
430 p->p_rlimit[RLIMIT_RSS].rlim_cur = ptoa(uvmexp.free);
431 }
432
433 #ifdef DEBUG
434 int enableswap = 1;
435 int swapdebug = 0;
436 #define SDB_FOLLOW 1
437 #define SDB_SWAPIN 2
438 #define SDB_SWAPOUT 4
439 #endif
440
441 /*
442 * uvm_swapin: swap in a process's u-area.
443 */
444
445 void
446 uvm_swapin(l)
447 struct lwp *l;
448 {
449 vaddr_t addr;
450 int s, error;
451
452 addr = (vaddr_t)l->l_addr;
453 /* make L_INMEM true */
454 error = uvm_fault_wire(kernel_map, addr, addr + USPACE, VM_FAULT_WIRE,
455 VM_PROT_READ | VM_PROT_WRITE);
456 if (error) {
457 panic("uvm_swapin: rewiring stack failed: %d", error);
458 }
459
460 /*
461 * Some architectures need to be notified when the user area has
462 * moved to new physical page(s) (e.g. see mips/mips/vm_machdep.c).
463 */
464 cpu_swapin(l);
465 SCHED_LOCK(s);
466 if (l->l_stat == LSRUN)
467 setrunqueue(l);
468 l->l_flag |= L_INMEM;
469 SCHED_UNLOCK(s);
470 l->l_swtime = 0;
471 ++uvmexp.swapins;
472 }
473
474 /*
475 * uvm_scheduler: process zero main loop
476 *
477 * - attempt to swapin every swaped-out, runnable process in order of
478 * priority.
479 * - if not enough memory, wake the pagedaemon and let it clear space.
480 */
481
482 void
483 uvm_scheduler()
484 {
485 struct lwp *l, *ll;
486 int pri;
487 int ppri;
488
489 loop:
490 #ifdef DEBUG
491 while (!enableswap)
492 tsleep(&proc0, PVM, "noswap", 0);
493 #endif
494 ll = NULL; /* process to choose */
495 ppri = INT_MIN; /* its priority */
496 proclist_lock_read();
497
498 LIST_FOREACH(l, &alllwp, l_list) {
499 /* is it a runnable swapped out process? */
500 if (l->l_stat == LSRUN && (l->l_flag & L_INMEM) == 0) {
501 pri = l->l_swtime + l->l_slptime -
502 (l->l_proc->p_nice - NZERO) * 8;
503 if (pri > ppri) { /* higher priority? remember it. */
504 ll = l;
505 ppri = pri;
506 }
507 }
508 }
509 /*
510 * XXXSMP: possible unlock/sleep race between here and the
511 * "scheduler" tsleep below..
512 */
513 proclist_unlock_read();
514
515 #ifdef DEBUG
516 if (swapdebug & SDB_FOLLOW)
517 printf("scheduler: running, procp %p pri %d\n", ll, ppri);
518 #endif
519 /*
520 * Nothing to do, back to sleep
521 */
522 if ((l = ll) == NULL) {
523 tsleep(&proc0, PVM, "scheduler", 0);
524 goto loop;
525 }
526
527 /*
528 * we have found swapped out process which we would like to bring
529 * back in.
530 *
531 * XXX: this part is really bogus cuz we could deadlock on memory
532 * despite our feeble check
533 */
534 if (uvmexp.free > atop(USPACE)) {
535 #ifdef DEBUG
536 if (swapdebug & SDB_SWAPIN)
537 printf("swapin: pid %d(%s)@%p, pri %d free %d\n",
538 l->l_proc->p_pid, l->l_proc->p_comm, l->l_addr, ppri, uvmexp.free);
539 #endif
540 uvm_swapin(l);
541 goto loop;
542 }
543 /*
544 * not enough memory, jab the pageout daemon and wait til the coast
545 * is clear
546 */
547 #ifdef DEBUG
548 if (swapdebug & SDB_FOLLOW)
549 printf("scheduler: no room for pid %d(%s), free %d\n",
550 l->l_proc->p_pid, l->l_proc->p_comm, uvmexp.free);
551 #endif
552 uvm_wait("schedpwait");
553 #ifdef DEBUG
554 if (swapdebug & SDB_FOLLOW)
555 printf("scheduler: room again, free %d\n", uvmexp.free);
556 #endif
557 goto loop;
558 }
559
560 /*
561 * swappable: is LWP "l" swappable?
562 */
563
564 #define swappable(l) \
565 (((l)->l_flag & (L_INMEM)) && \
566 ((((l)->l_proc->p_flag) & (P_SYSTEM | P_WEXIT)) == 0) && \
567 (l)->l_holdcnt == 0)
568
569 /*
570 * swapout_threads: find threads that can be swapped and unwire their
571 * u-areas.
572 *
573 * - called by the pagedaemon
574 * - try and swap at least one processs
575 * - processes that are sleeping or stopped for maxslp or more seconds
576 * are swapped... otherwise the longest-sleeping or stopped process
577 * is swapped, otherwise the longest resident process...
578 */
579
580 void
581 uvm_swapout_threads()
582 {
583 struct lwp *l;
584 struct lwp *outl, *outl2;
585 int outpri, outpri2;
586 int didswap = 0;
587 extern int maxslp;
588 /* XXXCDC: should move off to uvmexp. or uvm., also in uvm_meter */
589
590 #ifdef DEBUG
591 if (!enableswap)
592 return;
593 #endif
594
595 /*
596 * outl/outpri : stop/sleep thread with largest sleeptime < maxslp
597 * outl2/outpri2: the longest resident thread (its swap time)
598 */
599 outl = outl2 = NULL;
600 outpri = outpri2 = 0;
601 proclist_lock_read();
602 LIST_FOREACH(l, &alllwp, l_list) {
603 if (!swappable(l))
604 continue;
605 switch (l->l_stat) {
606 case LSRUN:
607 case LSONPROC:
608 if (l->l_swtime > outpri2) {
609 outl2 = l;
610 outpri2 = l->l_swtime;
611 }
612 continue;
613
614 case LSSLEEP:
615 case LSSTOP:
616 if (l->l_slptime >= maxslp) {
617 uvm_swapout(l);
618 didswap++;
619 } else if (l->l_slptime > outpri) {
620 outl = l;
621 outpri = l->l_slptime;
622 }
623 continue;
624 }
625 }
626 proclist_unlock_read();
627
628 /*
629 * If we didn't get rid of any real duds, toss out the next most
630 * likely sleeping/stopped or running candidate. We only do this
631 * if we are real low on memory since we don't gain much by doing
632 * it (USPACE bytes).
633 */
634 if (didswap == 0 && uvmexp.free <= atop(round_page(USPACE))) {
635 if ((l = outl) == NULL)
636 l = outl2;
637 #ifdef DEBUG
638 if (swapdebug & SDB_SWAPOUT)
639 printf("swapout_threads: no duds, try procp %p\n", l);
640 #endif
641 if (l)
642 uvm_swapout(l);
643 }
644 }
645
646 /*
647 * uvm_swapout: swap out lwp "l"
648 *
649 * - currently "swapout" means "unwire U-area" and "pmap_collect()"
650 * the pmap.
651 * - XXXCDC: should deactivate all process' private anonymous memory
652 */
653
654 static void
655 uvm_swapout(l)
656 struct lwp *l;
657 {
658 vaddr_t addr;
659 int s;
660 struct proc *p = l->l_proc;
661
662 #ifdef DEBUG
663 if (swapdebug & SDB_SWAPOUT)
664 printf("swapout: lid %d.%d(%s)@%p, stat %x pri %d free %d\n",
665 p->p_pid, l->l_lid, p->p_comm, l->l_addr, l->l_stat,
666 l->l_slptime, uvmexp.free);
667 #endif
668
669 /*
670 * Do any machine-specific actions necessary before swapout.
671 * This can include saving floating point state, etc.
672 */
673 cpu_swapout(l);
674
675 /*
676 * Mark it as (potentially) swapped out.
677 */
678 SCHED_LOCK(s);
679 l->l_flag &= ~L_INMEM;
680 if (l->l_stat == LSRUN)
681 remrunqueue(l);
682 SCHED_UNLOCK(s);
683 l->l_swtime = 0;
684 p->p_stats->p_ru.ru_nswap++;
685 ++uvmexp.swapouts;
686
687 /*
688 * Unwire the to-be-swapped process's user struct and kernel stack.
689 */
690 addr = (vaddr_t)l->l_addr;
691 uvm_fault_unwire(kernel_map, addr, addr + USPACE); /* !L_INMEM */
692 pmap_collect(vm_map_pmap(&p->p_vmspace->vm_map));
693 }
694
695 /*
696 * uvm_coredump_walkmap: walk a process's map for the purpose of dumping
697 * a core file.
698 */
699
700 int
701 uvm_coredump_walkmap(p, vp, cred, func, cookie)
702 struct proc *p;
703 struct vnode *vp;
704 struct ucred *cred;
705 int (*func)(struct proc *, struct vnode *, struct ucred *,
706 struct uvm_coredump_state *);
707 void *cookie;
708 {
709 struct uvm_coredump_state state;
710 struct vmspace *vm = p->p_vmspace;
711 struct vm_map *map = &vm->vm_map;
712 struct vm_map_entry *entry;
713 vaddr_t maxstack;
714 int error;
715
716 maxstack = trunc_page(USRSTACK - ctob(vm->vm_ssize));
717
718 for (entry = map->header.next; entry != &map->header;
719 entry = entry->next) {
720 /* Should never happen for a user process. */
721 if (UVM_ET_ISSUBMAP(entry))
722 panic("uvm_coredump_walkmap: user process with "
723 "submap?");
724
725 state.cookie = cookie;
726 state.start = entry->start;
727 state.end = entry->end;
728 state.prot = entry->protection;
729 state.flags = 0;
730
731 if (state.start >= VM_MAXUSER_ADDRESS)
732 continue;
733
734 if (state.end > VM_MAXUSER_ADDRESS)
735 state.end = VM_MAXUSER_ADDRESS;
736
737 if (state.start >= (vaddr_t)vm->vm_maxsaddr) {
738 if (state.end <= maxstack)
739 continue;
740 if (state.start < maxstack)
741 state.start = maxstack;
742 state.flags |= UVM_COREDUMP_STACK;
743 }
744
745 if ((entry->protection & VM_PROT_WRITE) == 0)
746 state.flags |= UVM_COREDUMP_NODUMP;
747
748 if (entry->object.uvm_obj != NULL &&
749 entry->object.uvm_obj->pgops == &uvm_deviceops)
750 state.flags |= UVM_COREDUMP_NODUMP;
751
752 error = (*func)(p, vp, cred, &state);
753 if (error)
754 return (error);
755 }
756
757 return (0);
758 }
759