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 * 3. 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
35 * $FreeBSD: src/sys/miscfs/procfs/procfs_map.c,v 1.24.2.1 2001/08/04 13:12:24 rwatson Exp $
36 * $DragonFly: src/sys/vfs/procfs/procfs_map.c,v 1.7 2007/02/19 01:14:24 corecode Exp $
39 #include <sys/param.h>
40 #include <sys/systm.h>
42 #include <sys/vnode.h>
44 #include <vfs/procfs/procfs.h>
49 #include <vm/vm_map.h>
50 #include <vm/vm_page.h>
51 #include <vm/vm_object.h>
53 #include <machine/limits.h>
56 procfs_domap(struct proc
*curp
, struct lwp
*lp
, struct pfsnode
*pfs
,
59 struct proc
*p
= lp
->lwp_proc
;
60 ssize_t buflen
= uio
->uio_offset
+ uio
->uio_resid
;
62 char *fullpath
, *freepath
;
64 vm_map_t map
= &p
->p_vmspace
->vm_map
;
66 struct sbuf
*sb
= NULL
;
67 unsigned int last_timestamp
;
69 if (uio
->uio_rw
!= UIO_READ
)
74 if (uio
->uio_offset
< 0 || uio
->uio_resid
< 0 || buflen
>= INT_MAX
)
76 sb
= sbuf_new (sb
, NULL
, buflen
+1, 0);
81 * Lock the map so we can access it. Release the process token
82 * to avoid unnecessary token stalls while we are processing the
85 vm_map_lock_read(map
);
86 lwkt_reltoken(&p
->p_token
);
88 for (entry
= map
->header
.next
; entry
!= &map
->header
;
89 entry
= entry
->next
) {
90 vm_object_t obj
, tobj
, lobj
;
91 int ref_count
, shadow_count
, flags
;
92 vm_offset_t e_start
, e_end
;
95 int resident
, privateresident
;
99 switch(entry
->maptype
) {
100 case VM_MAPTYPE_NORMAL
:
101 case VM_MAPTYPE_VPAGETABLE
:
102 obj
= entry
->object
.vm_object
;
105 if (obj
->shadow_count
== 1)
106 privateresident
= obj
->resident_page_count
;
109 case VM_MAPTYPE_UKSMAP
:
117 e_eflags
= entry
->eflags
;
118 e_prot
= entry
->protection
;
119 e_start
= entry
->start
;
123 * Don't count resident pages, its impossible on 64-bit.
124 * A single mapping could be gigabytes or terrabytes.
128 pmap_t pmap
= vmspace_pmap(p
->p_vmspace
);
133 while (addr
< entry
->end
) {
134 if (pmap_extract(pmap
, addr
, NULL
))
141 while ((tobj
= lobj
->backing_object
) != NULL
) {
142 KKASSERT(tobj
!= obj
);
143 vm_object_hold(tobj
);
144 if (tobj
== lobj
->backing_object
) {
146 vm_object_lock_swap();
147 vm_object_drop(lobj
);
151 vm_object_drop(tobj
);
157 last_timestamp
= map
->timestamp
;
188 vm_object_drop(lobj
);
191 ref_count
= obj
->ref_count
;
192 shadow_count
= obj
->shadow_count
;
195 vn_fullpath(p
, vp
, &fullpath
, &freepath
, 1);
202 switch(entry
->maptype
) {
203 case VM_MAPTYPE_UNSPECIFIED
:
206 case VM_MAPTYPE_NORMAL
:
209 case VM_MAPTYPE_VPAGETABLE
:
212 case VM_MAPTYPE_SUBMAP
:
215 case VM_MAPTYPE_UKSMAP
:
226 * start, end, res, priv res, cow, access, type, (fullpath).
228 error
= sbuf_printf(sb
,
230 "0x%016lx 0x%016lx %d %d %p %s%s%s %d %d "
232 "0x%08lx 0x%08lx %d %d %p %s%s%s %d %d "
234 "0x%04x %s %s %s %s\n",
235 (u_long
)e_start
, (u_long
)e_end
,
236 resident
, privateresident
, obj
,
237 (e_prot
& VM_PROT_READ
)?"r":"-",
238 (e_prot
& VM_PROT_WRITE
)?"w":"-",
239 (e_prot
& VM_PROT_EXECUTE
)?"x":"-",
240 ref_count
, shadow_count
, flags
,
241 (e_eflags
& MAP_ENTRY_COW
)?"COW":"NCOW",
242 (e_eflags
& MAP_ENTRY_NEEDS_COPY
)?"NC":"NNC",
245 if (freepath
!= NULL
) {
246 kfree(freepath
, M_TEMP
);
250 vm_map_lock_read(map
);
256 if (last_timestamp
!= map
->timestamp
) {
257 vm_map_entry_t reentry
;
258 vm_map_lookup_entry(map
, e_start
, &reentry
);
262 vm_map_unlock_read(map
);
263 if (sbuf_finish(sb
) == 0)
264 buflen
= sbuf_len(sb
);
265 error
= uiomove_frombuf(sbuf_data(sb
), buflen
, uio
);
268 lwkt_gettoken(&p
->p_token
); /* re-acquire */
274 procfs_validmap(struct lwp
*lp
)
276 return ((lp
->lwp_proc
->p_flags
& P_SYSTEM
) == 0);