No empty .Rs/.Re
[netbsd-mini2440.git] / sys / uvm / uvm_coredump.c
blob767daf1b5cd3b81becd522673c89cfa84a435f02
1 /* $NetBSD: uvm_glue.c,v 1.133 2008/06/25 19:20:56 ad Exp $ */
3 /*
4 * Copyright (c) 1997 Charles D. Cranor and Washington University.
5 * Copyright (c) 1991, 1993, The Regents of the University of California.
7 * All rights reserved.
9 * This code is derived from software contributed to Berkeley by
10 * The Mach Operating System project at Carnegie-Mellon University.
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.
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.
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
45 * Copyright (c) 1987, 1990 Carnegie-Mellon University.
46 * All rights reserved.
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.
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.
58 * Carnegie Mellon requests users of this software to return to
60 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
61 * School of Computer Science
62 * Carnegie Mellon University
63 * Pittsburgh PA 15213-3890
65 * any improvements or extensions that they make and grant Carnegie the
66 * rights to redistribute these changes.
69 #include <sys/cdefs.h>
70 __KERNEL_RCSID(0, "$NetBSD: uvm_glue.c,v 1.133 2008/06/25 19:20:56 ad Exp $");
73 * uvm_coredump.c: glue functions for coredump
76 #include <sys/param.h>
77 #include <sys/systm.h>
78 #include <sys/proc.h>
80 #include <uvm/uvm.h>
83 * uvm_coredump_walkmap: walk a process's map for the purpose of dumping
84 * a core file.
87 int
88 uvm_coredump_walkmap(struct proc *p, void *iocookie,
89 int (*func)(struct proc *, void *, struct uvm_coredump_state *),
90 void *cookie)
92 struct uvm_coredump_state state;
93 struct vmspace *vm = p->p_vmspace;
94 struct vm_map *map = &vm->vm_map;
95 struct vm_map_entry *entry;
96 int error;
98 entry = NULL;
99 vm_map_lock_read(map);
100 state.end = 0;
101 for (;;) {
102 if (entry == NULL)
103 entry = map->header.next;
104 else if (!uvm_map_lookup_entry(map, state.end, &entry))
105 entry = entry->next;
106 if (entry == &map->header)
107 break;
109 state.cookie = cookie;
110 if (state.end > entry->start) {
111 state.start = state.end;
112 } else {
113 state.start = entry->start;
115 state.realend = entry->end;
116 state.end = entry->end;
117 state.prot = entry->protection;
118 state.flags = 0;
121 * Dump the region unless one of the following is true:
123 * (1) the region has neither object nor amap behind it
124 * (ie. it has never been accessed).
126 * (2) the region has no amap and is read-only
127 * (eg. an executable text section).
129 * (3) the region's object is a device.
131 * (4) the region is unreadable by the process.
134 KASSERT(!UVM_ET_ISSUBMAP(entry));
135 KASSERT(state.start < VM_MAXUSER_ADDRESS);
136 KASSERT(state.end <= VM_MAXUSER_ADDRESS);
137 if (entry->object.uvm_obj == NULL &&
138 entry->aref.ar_amap == NULL) {
139 state.realend = state.start;
140 } else if ((entry->protection & VM_PROT_WRITE) == 0 &&
141 entry->aref.ar_amap == NULL) {
142 state.realend = state.start;
143 } else if (entry->object.uvm_obj != NULL &&
144 UVM_OBJ_IS_DEVICE(entry->object.uvm_obj)) {
145 state.realend = state.start;
146 } else if ((entry->protection & VM_PROT_READ) == 0) {
147 state.realend = state.start;
148 } else {
149 if (state.start >= (vaddr_t)vm->vm_maxsaddr)
150 state.flags |= UVM_COREDUMP_STACK;
153 * If this an anonymous entry, only dump instantiated
154 * pages.
156 if (entry->object.uvm_obj == NULL) {
157 vaddr_t end;
159 amap_lock(entry->aref.ar_amap);
160 for (end = state.start;
161 end < state.end; end += PAGE_SIZE) {
162 struct vm_anon *anon;
163 anon = amap_lookup(&entry->aref,
164 end - entry->start);
166 * If we have already encountered an
167 * uninstantiated page, stop at the
168 * first instantied page.
170 if (anon != NULL &&
171 state.realend != state.end) {
172 state.end = end;
173 break;
177 * If this page is the first
178 * uninstantiated page, mark this as
179 * the real ending point. Continue to
180 * counting uninstantiated pages.
182 if (anon == NULL &&
183 state.realend == state.end) {
184 state.realend = end;
187 amap_unlock(entry->aref.ar_amap);
192 vm_map_unlock_read(map);
193 error = (*func)(p, iocookie, &state);
194 if (error)
195 return (error);
196 vm_map_lock_read(map);
198 vm_map_unlock_read(map);
200 return (0);