2 * Copyright (c) 1993 Jan-Simon Pendry
4 * The Regents of the University of California. All rights reserved.
6 * This code is derived from software contributed to Berkeley by
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)procfs_status.c 8.3 (Berkeley) 2/17/94
38 #include "opt_compat.h"
40 #include <sys/param.h>
41 #include <sys/systm.h>
43 #include <sys/filedesc.h>
44 #include <sys/malloc.h>
45 #include <sys/mount.h>
46 #include <sys/mutex.h>
50 #include <sys/vnode.h>
52 #include <fs/pseudofs/pseudofs.h>
53 #include <fs/procfs/procfs.h>
56 #include <vm/vm_extern.h>
58 #include <vm/vm_map.h>
59 #include <vm/vm_page.h>
60 #include <vm/vm_object.h>
63 #include <sys/procfs.h>
64 #include <machine/fpu.h>
65 #include <compat/ia32/ia32_reg.h>
67 extern struct sysentvec ia32_freebsd_sysvec;
71 #define MEBUFFERSIZE 256
74 * The map entries can *almost* be read with programs like cat. However,
75 * large maps need special programs to read. It is not easy to implement
76 * a program that can sense the required size of the buffer, and then
77 * subsequently do a read with the appropriate size. This operation cannot
78 * be atomic. The best that we can do is to allow the program to do a read
79 * with an arbitrarily large buffer, and return as much as we can. We can
80 * return an error code if the buffer is too small (EFBIG), then the program
81 * can try a bigger buffer.
84 procfs_doprocmap(PFS_FILL_ARGS)
88 vm_map_entry_t entry, tmp_entry;
90 char *fullpath, *freepath;
92 unsigned int last_timestamp;
98 error = p_candebug(td, p);
103 if (uio->uio_rw != UIO_READ)
107 if (curthread->td_proc->p_sysent == &ia32_freebsd_sysvec) {
108 if (p->p_sysent != &ia32_freebsd_sysvec)
114 vm = vmspace_acquire_ref(p);
118 vm_map_lock_read(map);
119 for (entry = map->header.next; entry != &map->header;
120 entry = entry->next) {
121 vm_object_t obj, tobj, lobj;
122 int ref_count, shadow_count, flags;
123 vm_offset_t e_start, e_end, addr;
124 int resident, privateresident;
126 vm_eflags_t e_eflags;
129 if (entry->eflags & MAP_ENTRY_IS_SUB_MAP)
132 e_eflags = entry->eflags;
133 e_prot = entry->protection;
134 e_start = entry->start;
137 obj = entry->object.vm_object;
140 if (obj->shadow_count == 1)
141 privateresident = obj->resident_page_count;
146 while (addr < entry->end) {
147 if (pmap_extract(map->pmap, addr))
152 for (lobj = tobj = obj; tobj; tobj = tobj->backing_object) {
154 VM_OBJECT_LOCK(tobj);
156 VM_OBJECT_UNLOCK(lobj);
159 last_timestamp = map->timestamp;
160 vm_map_unlock_read(map);
165 switch (lobj->type) {
186 VM_OBJECT_UNLOCK(lobj);
189 ref_count = obj->ref_count;
190 shadow_count = obj->shadow_count;
191 VM_OBJECT_UNLOCK(obj);
193 vn_fullpath(td, vp, &fullpath, &freepath);
194 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
196 VFS_UNLOCK_GIANT(vfslocked);
207 * start, end, resident, private resident, cow, access, type.
209 error = sbuf_printf(sb,
210 "0x%lx 0x%lx %d %d %p %s%s%s %d %d 0x%x %s %s %s %s\n",
211 (u_long)e_start, (u_long)e_end,
212 resident, privateresident,
214 wrap32 ? NULL : obj, /* Hide 64 bit value */
218 (e_prot & VM_PROT_READ)?"r":"-",
219 (e_prot & VM_PROT_WRITE)?"w":"-",
220 (e_prot & VM_PROT_EXECUTE)?"x":"-",
221 ref_count, shadow_count, flags,
222 (e_eflags & MAP_ENTRY_COW)?"COW":"NCOW",
223 (e_eflags & MAP_ENTRY_NEEDS_COPY)?"NC":"NNC",
226 if (freepath != NULL)
227 free(freepath, M_TEMP);
228 vm_map_lock_read(map);
233 if (last_timestamp != map->timestamp) {
235 * Look again for the entry because the map was
236 * modified while it was unlocked. Specifically,
237 * the entry may have been clipped, merged, or deleted.
239 vm_map_lookup_entry(map, e_end - 1, &tmp_entry);
243 vm_map_unlock_read(map);