Home | History | Annotate | Line # | Download | only in pmap
pmap.h revision 1.10
      1  1.10     chs /*	$NetBSD: pmap.h,v 1.10 2017/06/09 00:13:29 chs Exp $ */
      2   1.1  atatat 
      3   1.1  atatat /*
      4   1.1  atatat  * Copyright (c) 2002, 2003 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.10     chs #define __EXPOSE_MOUNT
     50   1.1  atatat #include <sys/mount.h>
     51   1.1  atatat #include <sys/uio.h>
     52   1.1  atatat #include <sys/namei.h>
     53   1.1  atatat #include <sys/sysctl.h>
     54   1.1  atatat 
     55   1.1  atatat #include <uvm/uvm.h>
     56   1.1  atatat #include <uvm/uvm_device.h>
     57   1.1  atatat 
     58   1.1  atatat #include <ufs/ufs/inode.h>
     59   1.1  atatat #undef doff_t
     60   1.1  atatat #undef IN_ACCESS
     61   1.1  atatat #include <isofs/cd9660/iso.h>
     62   1.1  atatat #include <isofs/cd9660/cd9660_node.h>
     63   1.1  atatat 
     64   1.1  atatat #define PMAP_HEADERS
     65   1.1  atatat #endif /* PMAP_HEADERS */
     66   1.1  atatat 
     67   1.1  atatat /*
     68   1.1  atatat  * if the definition of the kbit structure (and the accessor macros)
     69   1.1  atatat  * is already established, don't redefine it.
     70   1.1  atatat  */
     71   1.1  atatat #ifndef struct_kbit
     72   1.1  atatat 
     73   1.1  atatat /*
     74   1.1  atatat  * stolen (and munged) from #include <uvm/uvm_object.h>
     75   1.1  atatat  */
     76   1.1  atatat #define UVM_OBJ_IS_VNODE(uobj)    ((uobj)->pgops == uvm_vnodeops)
     77   1.1  atatat #define UVM_OBJ_IS_AOBJ(uobj)     ((uobj)->pgops == aobj_pager)
     78   1.1  atatat #define UVM_OBJ_IS_DEVICE(uobj)   ((uobj)->pgops == uvm_deviceops)
     79   1.1  atatat #define UVM_OBJ_IS_UBCPAGER(uobj) ((uobj)->pgops == ubc_pager)
     80   1.1  atatat 
     81   1.2  atatat /*
     82   1.2  atatat  * stolen from #include <uvm/uvm_amap.h>
     83   1.2  atatat  */
     84   1.2  atatat #define PPREF_NONE ((int *) -1)
     85   1.2  atatat 
     86   1.1  atatat /* the size of the object in the kernel */
     87   1.1  atatat #define S(x)	((x)->k_size)
     88   1.1  atatat /* the address of the object in kernel, two forms */
     89   1.1  atatat #define A(x)	((x)->k_addr.k_addr_ul)
     90   1.1  atatat #define P(x)	((x)->k_addr.k_addr_p)
     91   1.1  atatat /* the data from the kernel */
     92   1.1  atatat #define D(x,d)	(&((x)->k_data.d))
     93   1.1  atatat 
     94   1.1  atatat /* suck the data from the kernel */
     95   1.4  atatat #define _KDEREFOK(kd, addr, dst, sz) \
     96   1.8   lukem 	((size_t)kvm_read((kd), (addr), (dst), (sz)) == (size_t)(sz))
     97   1.1  atatat #define _KDEREF(kd, addr, dst, sz) do { \
     98   1.4  atatat 	if (!_KDEREFOK((kd), (addr), (dst), (sz))) \
     99   1.9     mrg 		errx(1, "trying to read %lu (%s) bytes from %lx: %s", \
    100   1.9     mrg 		    (unsigned long)(sz), #sz, (addr), kvm_geterr(kd)); \
    101   1.1  atatat } while (0/*CONSTCOND*/)
    102   1.1  atatat 
    103   1.1  atatat /* suck the data using the structure */
    104   1.4  atatat #define KDEREFOK(kd, item) _KDEREFOK((kd), A(item), D(item, data), S(item))
    105   1.1  atatat #define KDEREF(kd, item) _KDEREF((kd), A(item), D(item, data), S(item))
    106   1.1  atatat 
    107   1.1  atatat struct kbit {
    108   1.1  atatat 	/*
    109   1.1  atatat 	 * size of data chunk
    110   1.1  atatat 	 */
    111   1.1  atatat 	size_t k_size;
    112   1.1  atatat 
    113   1.1  atatat 	/*
    114   1.1  atatat 	 * something for printf() and something for kvm_read()
    115   1.1  atatat 	 */
    116   1.1  atatat 	union {
    117   1.1  atatat 		void *k_addr_p;
    118   1.1  atatat 		u_long k_addr_ul;
    119   1.1  atatat 	} k_addr;
    120   1.1  atatat 
    121   1.1  atatat 	/*
    122   1.1  atatat 	 * where we actually put the "stuff"
    123   1.1  atatat 	 */
    124   1.1  atatat 	union {
    125   1.1  atatat 		char data[1];
    126   1.1  atatat 		struct vmspace vmspace;
    127   1.1  atatat 		struct vm_map vm_map;
    128   1.1  atatat 		struct vm_map_entry vm_map_entry;
    129   1.1  atatat 		struct vnode vnode;
    130   1.1  atatat 		struct uvm_object uvm_object;
    131   1.1  atatat 		struct mount mount;
    132   1.1  atatat 		struct namecache namecache;
    133   1.1  atatat 		struct inode inode;
    134   1.1  atatat 		struct iso_node iso_node;
    135   1.1  atatat 		struct uvm_device uvm_device;
    136   1.2  atatat 		struct vm_amap amap;
    137   1.2  atatat 		struct vm_anon anon;
    138   1.1  atatat 	} k_data;
    139   1.1  atatat };
    140   1.1  atatat #define struct_kbit
    141   1.1  atatat #endif /* struct_kbit */
    142   1.1  atatat 
    143   1.1  atatat /*
    144   1.1  atatat  * this is the *actual* module interface
    145   1.1  atatat  */
    146   1.3  atatat 
    147   1.6    yamt void process_map(kvm_t *, struct kinfo_proc2 *,
    148   1.3  atatat 				   struct kbit *, const char *);
    149   1.6    yamt void dump_vm_map(kvm_t *, struct kinfo_proc2 *,
    150   1.3  atatat 				   struct kbit *, struct kbit *, const char *);
    151   1.6    yamt size_t dump_vm_map_entry(kvm_t *, struct kinfo_proc2 *,
    152   1.3  atatat 					   struct kbit *, struct kbit *, int);
    153   1.6    yamt void dump_amap(kvm_t *, struct kbit *);
    154