1 /* $NetBSD: pmap.h,v 1.3 2003/04/04 03:49:20 atatat Exp $ */ 2 3 /* 4 * Copyright (c) 2002, 2003 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 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /* 40 * only pull in the headers once. if we attempt to pull them in 41 * again, we get namespace collisions on some structures, and we don't 42 * want to redefine some of them since it will affect the layout of 43 * the the struct kbit. 44 */ 45 #ifndef PMAP_HEADERS 46 47 #include <err.h> 48 #include <kvm.h> 49 #include <stddef.h> 50 #include <stdlib.h> 51 52 #include <sys/types.h> 53 #include <sys/param.h> 54 #include <sys/time.h> 55 #include <sys/vnode.h> 56 #include <sys/mount.h> 57 #include <sys/uio.h> 58 #include <sys/namei.h> 59 #include <sys/sysctl.h> 60 61 #include <uvm/uvm.h> 62 #include <uvm/uvm_device.h> 63 64 #include <ufs/ufs/inode.h> 65 #undef doff_t 66 #undef IN_ACCESS 67 #include <isofs/cd9660/iso.h> 68 #include <isofs/cd9660/cd9660_node.h> 69 70 #define PMAP_HEADERS 71 #endif /* PMAP_HEADERS */ 72 73 #ifndef CONCAT 74 #define CONCAT(x,y) __CONCAT(x,y) 75 #endif 76 #ifndef PMAPFUNC 77 #define PMAPFUNC(x,y) CONCAT(x,CONCAT(_,y)) 78 #endif 79 80 /* 81 * if the definition of the kbit structure (and the accessor macros) 82 * is already established, don't redefine it. 83 */ 84 #ifndef struct_kbit 85 86 /* 87 * stolen (and munged) from #include <uvm/uvm_object.h> 88 */ 89 #define UVM_OBJ_IS_VNODE(uobj) ((uobj)->pgops == uvm_vnodeops) 90 #define UVM_OBJ_IS_AOBJ(uobj) ((uobj)->pgops == aobj_pager) 91 #define UVM_OBJ_IS_DEVICE(uobj) ((uobj)->pgops == uvm_deviceops) 92 #define UVM_OBJ_IS_UBCPAGER(uobj) ((uobj)->pgops == ubc_pager) 93 94 /* 95 * stolen from #include <uvm/uvm_amap.h> 96 */ 97 #define PPREF_NONE ((int *) -1) 98 99 /* the size of the object in the kernel */ 100 #define S(x) ((x)->k_size) 101 /* the address of the object in kernel, two forms */ 102 #define A(x) ((x)->k_addr.k_addr_ul) 103 #define P(x) ((x)->k_addr.k_addr_p) 104 /* the data from the kernel */ 105 #define D(x,d) (&((x)->k_data.d)) 106 107 /* suck the data from the kernel */ 108 #define _KDEREF(kd, addr, dst, sz) do { \ 109 ssize_t len; \ 110 len = kvm_read((kd), (addr), (dst), (sz)); \ 111 if (len != (sz)) \ 112 errx(1, "trying to read %lu bytes from %lx: %s", \ 113 (unsigned long)(sz), (addr), kvm_geterr(kd)); \ 114 } while (0/*CONSTCOND*/) 115 116 /* suck the data using the structure */ 117 #define KDEREF(kd, item) _KDEREF((kd), A(item), D(item, data), S(item)) 118 119 struct kbit { 120 /* 121 * size of data chunk 122 */ 123 size_t k_size; 124 125 /* 126 * something for printf() and something for kvm_read() 127 */ 128 union { 129 void *k_addr_p; 130 u_long k_addr_ul; 131 } k_addr; 132 133 /* 134 * where we actually put the "stuff" 135 */ 136 union { 137 char data[1]; 138 struct vmspace vmspace; 139 struct vm_map vm_map; 140 struct vm_map_entry vm_map_entry; 141 struct vnode vnode; 142 struct uvm_object uvm_object; 143 struct mount mount; 144 struct namecache namecache; 145 struct inode inode; 146 struct iso_node iso_node; 147 struct uvm_device uvm_device; 148 struct vm_amap amap; 149 struct vm_anon anon; 150 } k_data; 151 }; 152 #define struct_kbit 153 #endif /* struct_kbit */ 154 155 /* 156 * VERSION, if not defined, defaults to "regular" or "lockdebug" (if 157 * LOCKDEBUG is defined) 158 */ 159 #ifndef VERSION 160 #ifndef LOCKDEBUG 161 #define VERSION regular 162 #else /* LOCKDEBUG */ 163 #define VERSION lockdebug 164 #endif /* LOCKDEBUG */ 165 #define undef_VERSION 166 #endif /* VERSION */ 167 168 /* 169 * this is the *actual* module interface 170 */ 171 172 void PMAPFUNC(process_map,VERSION)(kvm_t *, struct kinfo_proc2 *, 173 struct kbit *, const char *); 174 void PMAPFUNC(dump_vm_map,VERSION)(kvm_t *, struct kinfo_proc2 *, 175 struct kbit *, struct kbit *, const char *); 176 size_t PMAPFUNC(dump_vm_map_entry,VERSION)(kvm_t *, struct kinfo_proc2 *, 177 struct kbit *, struct kbit *, int); 178 void PMAPFUNC(dump_amap,VERSION)(kvm_t *, struct kbit *); 179 180 /* 181 * if we defined VERSION here, we should undef it now that we're done. 182 */ 183 #ifdef undef_VERSION 184 #undef VERSION 185 #undef undef_VERSION 186 #endif /* undef_VERSION */ 187