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