Home | History | Annotate | Line # | Download | only in pmap
pmap.h revision 1.5
      1 /*	$NetBSD: pmap.h,v 1.5 2004/04/23 02:58:29 simonb 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 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 _KDEREFOK(kd, addr, dst, sz) \
    109 	(kvm_read((kd), (addr), (dst), (sz)) == (sz))
    110 #define _KDEREF(kd, addr, dst, sz) do { \
    111 	if (!_KDEREFOK((kd), (addr), (dst), (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 KDEREFOK(kd, item) _KDEREFOK((kd), A(item), D(item, data), S(item))
    118 #define KDEREF(kd, item) _KDEREF((kd), A(item), D(item, data), S(item))
    119 
    120 struct kbit {
    121 	/*
    122 	 * size of data chunk
    123 	 */
    124 	size_t k_size;
    125 
    126 	/*
    127 	 * something for printf() and something for kvm_read()
    128 	 */
    129 	union {
    130 		void *k_addr_p;
    131 		u_long k_addr_ul;
    132 	} k_addr;
    133 
    134 	/*
    135 	 * where we actually put the "stuff"
    136 	 */
    137 	union {
    138 		char data[1];
    139 		struct vmspace vmspace;
    140 		struct vm_map vm_map;
    141 		struct vm_map_entry vm_map_entry;
    142 		struct vnode vnode;
    143 		struct uvm_object uvm_object;
    144 		struct mount mount;
    145 		struct namecache namecache;
    146 		struct inode inode;
    147 		struct iso_node iso_node;
    148 		struct uvm_device uvm_device;
    149 		struct vm_amap amap;
    150 		struct vm_anon anon;
    151 	} k_data;
    152 };
    153 #define struct_kbit
    154 #endif /* struct_kbit */
    155 
    156 /*
    157  * VERSION, if not defined, defaults to "regular" or "lockdebug" (if
    158  * LOCKDEBUG is defined)
    159  */
    160 #ifndef VERSION
    161 #ifndef LOCKDEBUG
    162 #define VERSION regular
    163 #else /* LOCKDEBUG */
    164 #define VERSION lockdebug
    165 #endif /* LOCKDEBUG */
    166 #define undef_VERSION
    167 #endif /* VERSION */
    168 
    169 /*
    170  * this is the *actual* module interface
    171  */
    172 
    173 void PMAPFUNC(process_map,VERSION)(kvm_t *, struct kinfo_proc2 *,
    174 				   struct kbit *, const char *);
    175 void PMAPFUNC(dump_vm_map,VERSION)(kvm_t *, struct kinfo_proc2 *,
    176 				   struct kbit *, struct kbit *, const char *);
    177 size_t PMAPFUNC(dump_vm_map_entry,VERSION)(kvm_t *, struct kinfo_proc2 *,
    178 					   struct kbit *, struct kbit *, int);
    179 void PMAPFUNC(dump_amap,VERSION)(kvm_t *, struct kbit *);
    180 
    181 /*
    182  * if we defined VERSION here, we should undef it now that we're done.
    183  */
    184 #ifdef undef_VERSION
    185 #undef VERSION
    186 #undef undef_VERSION
    187 #endif /* undef_VERSION */
    188