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