Home | History | Annotate | Line # | Download | only in pmap
pmap.h revision 1.6
      1 /*	$NetBSD: pmap.h,v 1.6 2008/01/02 17:23:32 yamt 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 /*
     74  * if the definition of the kbit structure (and the accessor macros)
     75  * is already established, don't redefine it.
     76  */
     77 #ifndef struct_kbit
     78 
     79 /*
     80  * stolen (and munged) from #include <uvm/uvm_object.h>
     81  */
     82 #define UVM_OBJ_IS_VNODE(uobj)    ((uobj)->pgops == uvm_vnodeops)
     83 #define UVM_OBJ_IS_AOBJ(uobj)     ((uobj)->pgops == aobj_pager)
     84 #define UVM_OBJ_IS_DEVICE(uobj)   ((uobj)->pgops == uvm_deviceops)
     85 #define UVM_OBJ_IS_UBCPAGER(uobj) ((uobj)->pgops == ubc_pager)
     86 
     87 /*
     88  * stolen from #include <uvm/uvm_amap.h>
     89  */
     90 #define PPREF_NONE ((int *) -1)
     91 
     92 /* the size of the object in the kernel */
     93 #define S(x)	((x)->k_size)
     94 /* the address of the object in kernel, two forms */
     95 #define A(x)	((x)->k_addr.k_addr_ul)
     96 #define P(x)	((x)->k_addr.k_addr_p)
     97 /* the data from the kernel */
     98 #define D(x,d)	(&((x)->k_data.d))
     99 
    100 /* suck the data from the kernel */
    101 #define _KDEREFOK(kd, addr, dst, sz) \
    102 	(kvm_read((kd), (addr), (dst), (sz)) == (sz))
    103 #define _KDEREF(kd, addr, dst, sz) do { \
    104 	if (!_KDEREFOK((kd), (addr), (dst), (sz))) \
    105 		errx(1, "trying to read %lu bytes from %lx: %s", \
    106 		    (unsigned long)(sz), (addr), kvm_geterr(kd)); \
    107 } while (0/*CONSTCOND*/)
    108 
    109 /* suck the data using the structure */
    110 #define KDEREFOK(kd, item) _KDEREFOK((kd), A(item), D(item, data), S(item))
    111 #define KDEREF(kd, item) _KDEREF((kd), A(item), D(item, data), S(item))
    112 
    113 struct kbit {
    114 	/*
    115 	 * size of data chunk
    116 	 */
    117 	size_t k_size;
    118 
    119 	/*
    120 	 * something for printf() and something for kvm_read()
    121 	 */
    122 	union {
    123 		void *k_addr_p;
    124 		u_long k_addr_ul;
    125 	} k_addr;
    126 
    127 	/*
    128 	 * where we actually put the "stuff"
    129 	 */
    130 	union {
    131 		char data[1];
    132 		struct vmspace vmspace;
    133 		struct vm_map vm_map;
    134 		struct vm_map_entry vm_map_entry;
    135 		struct vnode vnode;
    136 		struct uvm_object uvm_object;
    137 		struct mount mount;
    138 		struct namecache namecache;
    139 		struct inode inode;
    140 		struct iso_node iso_node;
    141 		struct uvm_device uvm_device;
    142 		struct vm_amap amap;
    143 		struct vm_anon anon;
    144 	} k_data;
    145 };
    146 #define struct_kbit
    147 #endif /* struct_kbit */
    148 
    149 /*
    150  * this is the *actual* module interface
    151  */
    152 
    153 void process_map(kvm_t *, struct kinfo_proc2 *,
    154 				   struct kbit *, const char *);
    155 void dump_vm_map(kvm_t *, struct kinfo_proc2 *,
    156 				   struct kbit *, struct kbit *, const char *);
    157 size_t dump_vm_map_entry(kvm_t *, struct kinfo_proc2 *,
    158 					   struct kbit *, struct kbit *, int);
    159 void dump_amap(kvm_t *, struct kbit *);
    160