pmap.h revision 1.14 1 1.14 mlelstv /* $NetBSD: pmap.h,v 1.14 2022/08/21 07:46:52 mlelstv Exp $ */
2 1.1 atatat
3 1.1 atatat /*
4 1.12 ad * Copyright (c) 2002, 2003, 2020 The NetBSD Foundation, Inc.
5 1.1 atatat * All rights reserved.
6 1.1 atatat *
7 1.1 atatat * This code is derived from software contributed to The NetBSD Foundation
8 1.1 atatat * by Andrew Brown.
9 1.1 atatat *
10 1.1 atatat * Redistribution and use in source and binary forms, with or without
11 1.1 atatat * modification, are permitted provided that the following conditions
12 1.1 atatat * are met:
13 1.1 atatat * 1. Redistributions of source code must retain the above copyright
14 1.1 atatat * notice, this list of conditions and the following disclaimer.
15 1.1 atatat * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 atatat * notice, this list of conditions and the following disclaimer in the
17 1.1 atatat * documentation and/or other materials provided with the distribution.
18 1.1 atatat *
19 1.1 atatat * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 atatat * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 atatat * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 atatat * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 atatat * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 atatat * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 atatat * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 atatat * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 atatat * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 atatat * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 atatat * POSSIBILITY OF SUCH DAMAGE.
30 1.1 atatat */
31 1.1 atatat
32 1.1 atatat /*
33 1.1 atatat * only pull in the headers once. if we attempt to pull them in
34 1.1 atatat * again, we get namespace collisions on some structures, and we don't
35 1.1 atatat * want to redefine some of them since it will affect the layout of
36 1.5 simonb * the struct kbit.
37 1.1 atatat */
38 1.1 atatat #ifndef PMAP_HEADERS
39 1.1 atatat
40 1.1 atatat #include <err.h>
41 1.1 atatat #include <kvm.h>
42 1.1 atatat #include <stddef.h>
43 1.1 atatat #include <stdlib.h>
44 1.1 atatat
45 1.1 atatat #include <sys/types.h>
46 1.1 atatat #include <sys/param.h>
47 1.1 atatat #include <sys/time.h>
48 1.1 atatat #include <sys/vnode.h>
49 1.12 ad #include <sys/vnode_impl.h>
50 1.10 chs #define __EXPOSE_MOUNT
51 1.1 atatat #include <sys/mount.h>
52 1.1 atatat #include <sys/uio.h>
53 1.11 christos #define __NAMECACHE_PRIVATE
54 1.1 atatat #include <sys/namei.h>
55 1.1 atatat #include <sys/sysctl.h>
56 1.1 atatat
57 1.1 atatat #include <uvm/uvm.h>
58 1.1 atatat #include <uvm/uvm_device.h>
59 1.1 atatat
60 1.1 atatat #include <ufs/ufs/inode.h>
61 1.1 atatat #undef doff_t
62 1.1 atatat #undef IN_ACCESS
63 1.1 atatat #include <isofs/cd9660/iso.h>
64 1.1 atatat #include <isofs/cd9660/cd9660_node.h>
65 1.1 atatat
66 1.1 atatat #define PMAP_HEADERS
67 1.1 atatat #endif /* PMAP_HEADERS */
68 1.1 atatat
69 1.1 atatat /*
70 1.1 atatat * if the definition of the kbit structure (and the accessor macros)
71 1.1 atatat * is already established, don't redefine it.
72 1.1 atatat */
73 1.1 atatat #ifndef struct_kbit
74 1.1 atatat
75 1.1 atatat /*
76 1.1 atatat * stolen (and munged) from #include <uvm/uvm_object.h>
77 1.1 atatat */
78 1.1 atatat #define UVM_OBJ_IS_VNODE(uobj) ((uobj)->pgops == uvm_vnodeops)
79 1.1 atatat #define UVM_OBJ_IS_AOBJ(uobj) ((uobj)->pgops == aobj_pager)
80 1.1 atatat #define UVM_OBJ_IS_DEVICE(uobj) ((uobj)->pgops == uvm_deviceops)
81 1.1 atatat #define UVM_OBJ_IS_UBCPAGER(uobj) ((uobj)->pgops == ubc_pager)
82 1.1 atatat
83 1.2 atatat /*
84 1.2 atatat * stolen from #include <uvm/uvm_amap.h>
85 1.2 atatat */
86 1.2 atatat #define PPREF_NONE ((int *) -1)
87 1.2 atatat
88 1.1 atatat /* the size of the object in the kernel */
89 1.1 atatat #define S(x) ((x)->k_size)
90 1.1 atatat /* the address of the object in kernel, two forms */
91 1.1 atatat #define A(x) ((x)->k_addr.k_addr_ul)
92 1.1 atatat #define P(x) ((x)->k_addr.k_addr_p)
93 1.1 atatat /* the data from the kernel */
94 1.1 atatat #define D(x,d) (&((x)->k_data.d))
95 1.1 atatat
96 1.1 atatat /* suck the data from the kernel */
97 1.4 atatat #define _KDEREFOK(kd, addr, dst, sz) \
98 1.8 lukem ((size_t)kvm_read((kd), (addr), (dst), (sz)) == (size_t)(sz))
99 1.1 atatat #define _KDEREF(kd, addr, dst, sz) do { \
100 1.4 atatat if (!_KDEREFOK((kd), (addr), (dst), (sz))) \
101 1.13 chs errx(1, "reading from kmem failed: %s", kvm_geterr(kd)); \
102 1.1 atatat } while (0/*CONSTCOND*/)
103 1.1 atatat
104 1.1 atatat /* suck the data using the structure */
105 1.4 atatat #define KDEREFOK(kd, item) _KDEREFOK((kd), A(item), D(item, data), S(item))
106 1.1 atatat #define KDEREF(kd, item) _KDEREF((kd), A(item), D(item, data), S(item))
107 1.1 atatat
108 1.1 atatat struct kbit {
109 1.1 atatat /*
110 1.1 atatat * size of data chunk
111 1.1 atatat */
112 1.1 atatat size_t k_size;
113 1.1 atatat
114 1.1 atatat /*
115 1.1 atatat * something for printf() and something for kvm_read()
116 1.1 atatat */
117 1.1 atatat union {
118 1.1 atatat void *k_addr_p;
119 1.1 atatat u_long k_addr_ul;
120 1.1 atatat } k_addr;
121 1.1 atatat
122 1.1 atatat /*
123 1.1 atatat * where we actually put the "stuff"
124 1.1 atatat */
125 1.1 atatat union {
126 1.1 atatat char data[1];
127 1.1 atatat struct vmspace vmspace;
128 1.1 atatat struct vm_map vm_map;
129 1.1 atatat struct vm_map_entry vm_map_entry;
130 1.1 atatat struct vnode vnode;
131 1.1 atatat struct uvm_object uvm_object;
132 1.1 atatat struct mount mount;
133 1.1 atatat struct namecache namecache;
134 1.1 atatat struct inode inode;
135 1.1 atatat struct iso_node iso_node;
136 1.1 atatat struct uvm_device uvm_device;
137 1.2 atatat struct vm_amap amap;
138 1.2 atatat struct vm_anon anon;
139 1.1 atatat } k_data;
140 1.1 atatat };
141 1.1 atatat #define struct_kbit
142 1.1 atatat #endif /* struct_kbit */
143 1.1 atatat
144 1.1 atatat /*
145 1.1 atatat * this is the *actual* module interface
146 1.1 atatat */
147 1.3 atatat
148 1.6 yamt void process_map(kvm_t *, struct kinfo_proc2 *,
149 1.14 mlelstv struct kbit *, const char *);
150 1.6 yamt void dump_vm_map(kvm_t *, struct kinfo_proc2 *,
151 1.14 mlelstv struct kbit *, struct kbit *, const char *);
152 1.14 mlelstv size_t dump_vm_map_list(kvm_t *, struct kinfo_proc2 *,
153 1.14 mlelstv struct kbit *, struct kbit *, struct kbit *);
154 1.14 mlelstv size_t dump_vm_map_tree(kvm_t *, struct kinfo_proc2 *,
155 1.14 mlelstv struct kbit *, struct kbit *, struct kbit *);
156 1.14 mlelstv size_t dump_vm_map_node(kvm_t *, int lvl, struct kinfo_proc2 *,
157 1.14 mlelstv struct kbit *, struct kbit *, struct vm_map_entry *);
158 1.6 yamt size_t dump_vm_map_entry(kvm_t *, struct kinfo_proc2 *,
159 1.14 mlelstv struct kbit *, struct kbit *, int);
160 1.14 mlelstv
161 1.6 yamt void dump_amap(kvm_t *, struct kbit *);
162