[Midnightbsd-cvs] src: lib/libkvm: update libkvm

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Tue Sep 30 19:54:17 EDT 2008


Log Message:
-----------
update libkvm

Modified Files:
--------------
    src/lib/libkvm:
        Makefile (r1.1.1.1 -> r1.2)
        kvm.3 (r1.1.1.1 -> r1.2)
        kvm.c (r1.1.1.2 -> r1.2)
        kvm.h (r1.1.1.1 -> r1.2)
        kvm_amd64.c (r1.1.1.1 -> r1.2)
        kvm_file.c (r1.1.1.1 -> r1.2)
        kvm_geterr.3 (r1.1.1.1 -> r1.2)
        kvm_getfiles.3 (r1.1.1.1 -> r1.2)
        kvm_getloadavg.3 (r1.1.1.1 -> r1.2)
        kvm_getloadavg.c (r1.1.1.1 -> r1.2)
        kvm_getprocs.3 (r1.1.1.1 -> r1.2)
        kvm_getswapinfo.c (r1.1.1.1 -> r1.2)
        kvm_i386.c (r1.1.1.1 -> r1.2)
        kvm_nlist.3 (r1.1.1.1 -> r1.2)
        kvm_open.3 (r1.1.1.1 -> r1.2)
        kvm_private.h (r1.1.1.1 -> r1.2)
        kvm_proc.c (r1.1.1.1 -> r1.2)
        kvm_read.3 (r1.1.1.1 -> r1.2)
        kvm_sparc.c (r1.1.1.1 -> r1.2)
        kvm_sparc64.c (r1.1.1.1 -> r1.2)

Added Files:
-----------
    src/lib/libkvm:
        kvm_minidump_amd64.c (r1.1)
        kvm_minidump_i386.c (r1.1)

Removed Files:
-------------
    src/lib/libkvm:
        kvm_alpha.c
        kvm_arm.c
        kvm_ia64.c
        kvm_powerpc.c

-------------- next part --------------
Index: kvm.c
===================================================================
RCS file: /home/cvs/src/lib/libkvm/kvm.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L lib/libkvm/kvm.c -L lib/libkvm/kvm.c -u -r1.1.1.2 -r1.2
--- lib/libkvm/kvm.c
+++ lib/libkvm/kvm.c
@@ -14,10 +14,6 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
  * 4. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
@@ -36,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libkvm/kvm.c,v 1.27.2.1 2006/01/24 04:05:47 csjp Exp $");
+__FBSDID("$FreeBSD: src/lib/libkvm/kvm.c,v 1.31 2007/06/15 11:35:11 simokawa Exp $");
 
 #if defined(LIBC_SCCS) && !defined(lint)
 #if 0
@@ -223,6 +219,8 @@
 		_kvm_syserr(kd, kd->program, "%s", uf);
 		goto failed;
 	}
+	if (strncmp(mf, _PATH_FWMEM, strlen(_PATH_FWMEM)) == 0)
+		kd->rawdump = 1;
 	if (_kvm_initvtop(kd) < 0)
 		goto failed;
 	return (kd);
@@ -307,6 +305,7 @@
 	struct nlist *p;
 	int nvalid;
 	struct kld_sym_lookup lookup;
+	int error;
 
 	/*
 	 * If we can't use the kld symbol lookup, revert to the
@@ -339,9 +338,13 @@
 		}
 	}
 	/*
-	 * Return the number of entries that weren't found.
+	 * Return the number of entries that weren't found. If they exist,
+	 * also fill internal error buffer.
 	 */
-	return ((p - nl) - nvalid);
+	error = ((p - nl) - nvalid);
+	if (error)
+		_kvm_syserr(kd, kd->program, "kvm_nlist");
+	return (error);
 }
 
 ssize_t
Index: kvm_proc.c
===================================================================
RCS file: /home/cvs/src/lib/libkvm/kvm_proc.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L lib/libkvm/kvm_proc.c -L lib/libkvm/kvm_proc.c -u -r1.1.1.1 -r1.2
--- lib/libkvm/kvm_proc.c
+++ lib/libkvm/kvm_proc.c
@@ -14,10 +14,6 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
  * 4. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
@@ -42,7 +38,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libkvm/kvm_proc.c,v 1.87 2005/06/24 00:37:04 peter Exp $");
+__FBSDID("$FreeBSD: src/lib/libkvm/kvm_proc.c,v 1.94 2007/09/21 04:11:34 jeff Exp $");
 
 /*
  * Proc traversal interface for kvm.  ps and w are (probably) the exclusive
@@ -89,6 +85,9 @@
 #define KREAD(kd, addr, obj) \
 	(kvm_read(kd, addr, (char *)(obj), sizeof(*obj)) != sizeof(*obj))
 
+static int ticks;
+static int hz;
+
 /*
  * Read proc's from memory file into buffer bp, which has space to hold
  * at most maxcnt procs.
@@ -113,8 +112,6 @@
 	struct ucred ucred;
 	struct prison pr;
 	struct thread mtd;
-	/*struct kse mke;*/
-	struct ksegrp mkg;
 	struct proc proc;
 	struct proc pproc;
 	struct timeval tv;
@@ -137,25 +134,6 @@
 				    TAILQ_FIRST(&proc.p_threads));
 				return (-1);
 			}
-			if ((proc.p_flag & P_SA) == 0) {
-				if (KREAD(kd,
-				    (u_long)TAILQ_FIRST(&proc.p_ksegrps),
-				    &mkg)) {
-					_kvm_err(kd, kd->program,
-					    "can't read ksegrp at %x",
-					    TAILQ_FIRST(&proc.p_ksegrps));
-					return (-1);
-				}
-#if 0
-				if (KREAD(kd,
-				    (u_long)TAILQ_FIRST(&mkg.kg_kseq), &mke)) {
-					_kvm_err(kd, kd->program,
-					    "can't read kse at %x",
-					    TAILQ_FIRST(&mkg.kg_kseq));
-					return (-1);
-				}
-#endif
-			}
 		}
 		if (KREAD(kd, (u_long)proc.p_ucred, &ucred) == 0) {
 			kp->ki_ruid = ucred.cr_ruid;
@@ -233,7 +211,8 @@
 			kp->ki_sigignore = sigacts.ps_sigignore;
 			kp->ki_sigcatch = sigacts.ps_sigcatch;
 		}
-		if ((proc.p_sflag & PS_INMEM) && proc.p_stats != NULL) {
+#if 0
+		if ((proc.p_flag & P_INMEM) && proc.p_stats != NULL) {
 			if (KREAD(kd, (u_long)proc.p_stats, &pstats)) {
 				_kvm_err(kd, kd->program,
 				    "can't read stats at %x", proc.p_stats);
@@ -253,6 +232,7 @@
 			timeradd(&kp->ki_childstime, &kp->ki_childutime,
 			    &kp->ki_childtime);
 		}
+#endif
 		if (proc.p_oppid)
 			kp->ki_ppid = proc.p_oppid;
 		else if (proc.p_pptr) {
@@ -374,6 +354,13 @@
 				    kp->ki_lockname, LOCKNAMELEN);
 			kp->ki_lockname[LOCKNAMELEN] = 0;
 		}
+		/*
+		 * XXX: This is plain wrong, rux_runtime has nothing
+		 * to do with struct bintime, rux_runtime is just a 64-bit
+		 * integer counter of cputicks.  What we need here is a way
+		 * to convert cputicks to usecs.  The kernel does it in
+		 * kern/kern_tc.c, but the function can't be just copied.
+		 */
 		bintime2timeval(&proc.p_rux.rux_runtime, &tv);
 		kp->ki_runtime = (u_int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
 		kp->ki_pid = proc.p_pid;
@@ -384,9 +371,9 @@
 		kp->ki_acflag = proc.p_acflag;
 		kp->ki_lock = proc.p_lock;
 		if (proc.p_state != PRS_ZOMBIE) {
-			kp->ki_swtime = proc.p_swtime;
+			kp->ki_swtime = (ticks - proc.p_swtick) / hz;
 			kp->ki_flag = proc.p_flag;
-			kp->ki_sflag = proc.p_sflag;
+			kp->ki_sflag = 0;
 			kp->ki_nice = proc.p_nice;
 			kp->ki_traceflag = proc.p_traceflag;
 			if (proc.p_state == PRS_NORMAL) { 
@@ -418,20 +405,8 @@
 			kp->ki_oncpu = mtd.td_oncpu;
 
 			if (!(proc.p_flag & P_SA)) {
-				/* stuff from the ksegrp */
-				kp->ki_slptime = mkg.kg_slptime;
-				kp->ki_pri.pri_class = mkg.kg_pri_class;
-				kp->ki_pri.pri_user = mkg.kg_user_pri;
-				kp->ki_estcpu = mkg.kg_estcpu;
-
-#if 0
-				/* Stuff from the kse */
-				kp->ki_pctcpu = mke.ke_pctcpu;
-				kp->ki_rqindex = mke.ke_rqindex;
-#else
 				kp->ki_pctcpu = 0;
 				kp->ki_rqindex = 0;
-#endif
 			} else {
 				kp->ki_tdflags = -1;
 				/* All the rest are 0 for now */
@@ -563,12 +538,14 @@
 liveout:
 		nprocs = size == 0 ? 0 : size / kd->procbase->ki_structsize;
 	} else {
-		struct nlist nl[4], *p;
+		struct nlist nl[6], *p;
 
 		nl[0].n_name = "_nprocs";
 		nl[1].n_name = "_allproc";
 		nl[2].n_name = "_zombproc";
-		nl[3].n_name = 0;
+		nl[3].n_name = "_ticks";
+		nl[4].n_name = "_hz";
+		nl[5].n_name = 0;
 
 		if (kvm_nlist(kd, nl) != 0) {
 			for (p = nl; p->n_type != 0; ++p)
@@ -581,6 +558,14 @@
 			_kvm_err(kd, kd->program, "can't read nprocs");
 			return (0);
 		}
+		if (KREAD(kd, nl[3].n_value, &ticks)) {
+			_kvm_err(kd, kd->program, "can't read ticks");
+			return (0);
+		}
+		if (KREAD(kd, nl[4].n_value, &hz)) {
+			_kvm_err(kd, kd->program, "can't read hz");
+			return (0);
+		}
 		size = nprocs * sizeof(struct kinfo_proc);
 		kd->procbase = (struct kinfo_proc *)_kvm_malloc(kd, size);
 		if (kd->procbase == 0)
Index: kvm_geterr.3
===================================================================
RCS file: /home/cvs/src/lib/libkvm/kvm_geterr.3,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L lib/libkvm/kvm_geterr.3 -L lib/libkvm/kvm_geterr.3 -u -r1.1.1.1 -r1.2
--- lib/libkvm/kvm_geterr.3
+++ lib/libkvm/kvm_geterr.3
@@ -13,10 +13,6 @@
 .\" 2. Redistributions in binary form must reproduce the above copyright
 .\"    notice, this list of conditions and the following disclaimer in the
 .\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
 .\" 4. Neither the name of the University nor the names of its contributors
 .\"    may be used to endorse or promote products derived from this software
 .\"    without specific prior written permission.
@@ -34,7 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)kvm_geterr.3	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libkvm/kvm_geterr.3,v 1.8 2005/01/20 09:17:06 ru Exp $
+.\" $FreeBSD: src/lib/libkvm/kvm_geterr.3,v 1.9 2007/01/08 17:35:36 imp Exp $
 .\"
 .Dd June 4, 1993
 .Dt KVM_GETERR 3
Index: kvm_amd64.c
===================================================================
RCS file: /home/cvs/src/lib/libkvm/kvm_amd64.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L lib/libkvm/kvm_amd64.c -L lib/libkvm/kvm_amd64.c -u -r1.1.1.1 -r1.2
--- lib/libkvm/kvm_amd64.c
+++ lib/libkvm/kvm_amd64.c
@@ -14,10 +14,6 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
  * 4. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
@@ -36,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libkvm/kvm_amd64.c,v 1.18.2.1 2005/10/26 00:06:58 peter Exp $");
+__FBSDID("$FreeBSD: src/lib/libkvm/kvm_amd64.c,v 1.22 2007/06/15 11:35:11 simokawa Exp $");
 
 #if defined(LIBC_SCCS) && !defined(lint)
 #if 0
@@ -73,7 +69,9 @@
 #define	ptob(x)		(amd64_ptob(x))
 #endif
 
+/* minidump must be the first item! */
 struct vmstate {
+	int		minidump;	/* 1 = minidump mode */
 	void		*mmapbase;
 	size_t		mmapsize;
 	pml4_entry_t	*PML4;
@@ -112,9 +110,16 @@
 _kvm_pa2off(kvm_t *kd, uint64_t pa, off_t *ofs)
 {
 	Elf_Ehdr *e = kd->vmst->mmapbase;
-	Elf_Phdr *p = (Elf_Phdr*)((char*)e + e->e_phoff);
-	int n = e->e_phnum;
+	Elf_Phdr *p;
+	int n;
 
+	if (kd->rawdump) {
+		*ofs = pa;
+		return (PAGE_SIZE - ((size_t)pa & PAGE_MASK));
+	}
+
+	p = (Elf_Phdr*)((char*)e + e->e_phoff);
+	n = e->e_phnum;
 	while (n && (pa < p->p_paddr || pa >= p->p_paddr + p->p_memsz))
 		p++, n--;
 	if (n == 0)
@@ -128,6 +133,8 @@
 {
 	struct vmstate *vm = kd->vmst;
 
+	if (kd->vmst->minidump)
+		return (_kvm_minidump_freevtop(kd));
 	if (vm->mmapbase != NULL)
 		munmap(vm->mmapbase, vm->mmapsize);
 	if (vm->PML4)
@@ -145,6 +152,11 @@
 	pml4_entry_t	*PML4;
 	Elf_Ehdr *ehdr;
 	size_t hdrsz;
+	char minihdr[8];
+
+	if (!kd->rawdump && pread(kd->pmfd, &minihdr, 8, 0) == 8)
+		if (memcmp(&minihdr, "minidump", 8) == 0)
+			return (_kvm_minidump_initvtop(kd));
 
 	kd->vmst = (struct vmstate *)_kvm_malloc(kd, sizeof(*kd->vmst));
 	if (kd->vmst == 0) {
@@ -153,13 +165,15 @@
 	}
 	kd->vmst->PML4 = 0;
 
-	if (_kvm_maphdrs(kd, sizeof(Elf_Ehdr)) == -1)
-		return (-1);
-
-	ehdr = kd->vmst->mmapbase;
-	hdrsz = ehdr->e_phoff + ehdr->e_phentsize * ehdr->e_phnum;
-	if (_kvm_maphdrs(kd, hdrsz) == -1)
-		return (-1);
+	if (kd->rawdump == 0) {
+		if (_kvm_maphdrs(kd, sizeof(Elf_Ehdr)) == -1)
+			return (-1);
+
+		ehdr = kd->vmst->mmapbase;
+		hdrsz = ehdr->e_phoff + ehdr->e_phentsize * ehdr->e_phnum;
+		if (_kvm_maphdrs(kd, hdrsz) == -1)
+			return (-1);
+	}
 
 	nlist[0].n_name = "kernbase";
 	nlist[1].n_name = 0;
@@ -333,6 +347,8 @@
 _kvm_kvatop(kvm_t *kd, u_long va, off_t *pa)
 {
 
+	if (kd->vmst->minidump)
+		return (_kvm_minidump_kvatop(kd, va, pa));
 	if (ISALIVE(kd)) {
 		_kvm_err(kd, 0, "kvm_kvatop called in live kernel!");
 		return (0);
--- lib/libkvm/kvm_alpha.c
+++ /dev/null
@@ -1,213 +0,0 @@
-/*	$NetBSD: kvm_alpha.c,v 1.7.2.1 1997/11/02 20:34:26 mellon Exp $	*/
-
-/*
- * Copyright (c) 1994, 1995 Carnegie-Mellon University.
- * All rights reserved.
- *
- * Author: Chris G. Demetriou
- * 
- * Permission to use, copy, modify and distribute this software and
- * its documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- * 
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 
- * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 
- * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- * 
- * Carnegie Mellon requests users of this software to return to
- *
- *  Software Distribution Coordinator  or  Software.Distribution at CS.CMU.EDU
- *  School of Computer Science
- *  Carnegie Mellon University
- *  Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie the
- * rights to redistribute these changes.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libkvm/kvm_alpha.c,v 1.8 2005/07/02 05:49:29 scottl Exp $");
-
-#include <sys/param.h>
-#include <sys/user.h>
-#include <sys/proc.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <unistd.h>
-#include <nlist.h>
-#include <kvm.h>
-
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-
-#include <limits.h>
-#include <stdlib.h>
-#include <machine/pmap.h>
-#include "kvm_private.h"
-
-static off_t   _kvm_pa2off(kvm_t *kd, u_long pa);
-
-struct vmstate {
-	u_int64_t       lev1map_pa;             /* PA of Lev1map */
-        u_int64_t       page_size;              /* Page size */
-        u_int64_t       nmemsegs;               /* Number of RAM segm */
-};
-
-void
-_kvm_freevtop(kd)
-	kvm_t *kd;
-{
-
-	/* Not actually used for anything right now, but safe. */
-	if (kd->vmst != 0)
-		free(kd->vmst);
-}
-
-int
-_kvm_initvtop(kd)
-	kvm_t *kd;
-{
-	struct vmstate *vm;
-	struct nlist nlist[2];
-	u_long pa;
-
-	vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm));
-	if (vm == 0) {
-		_kvm_err(kd, kd->program, "cannot allocate vm");
-		return (-1);
-	}
-	kd->vmst = vm;
-	vm->page_size = ALPHA_PGBYTES;
-
-	nlist[0].n_name = "_Lev1map";
-	nlist[1].n_name = 0;
-
-	if (kvm_nlist(kd, nlist) != 0) {
-		_kvm_err(kd, kd->program, "bad namelist");
-		return (-1);
-	}
-
-	if(!ISALIVE(kd)) {
-		if (kvm_read(kd, (nlist[0].n_value), &pa, sizeof(pa)) != sizeof(pa)) {
-			_kvm_err(kd, kd->program, "cannot read Lev1map");
-			return (-1);
-		}
-	} else 
-		if (kvm_read(kd, (nlist[0].n_value), &pa, sizeof(pa)) != sizeof(pa)) {
-			_kvm_err(kd, kd->program, "cannot read Lev1map");
-			return (-1);
-		}
-	vm->lev1map_pa = pa;
-	return (0);
-
-}
-
-int
-_kvm_kvatop(kd, va, pa)
-	kvm_t *kd;
-	u_long va;
-	off_t *pa;
-{
-	u_int64_t       lev1map_pa;             /* PA of Lev1map */
-        u_int64_t       page_size;
-	int rv, page_off;
-	alpha_pt_entry_t pte;
-	off_t pteoff;
-	struct vmstate *vm;
-	vm = kd->vmst ;
-	
-
-        if (ISALIVE(kd)) {
-                _kvm_err(kd, 0, "vatop called in live kernel!");
-                return(0);
-        }
-	lev1map_pa = vm->lev1map_pa;
-	page_size  = vm->page_size;
-
-	page_off = va & (page_size - 1);
-	if (va >= ALPHA_K0SEG_BASE && va <= ALPHA_K0SEG_END) {
-		/*
-		 * Direct-mapped address: just convert it.
-		 */
-
-		*pa = ALPHA_K0SEG_TO_PHYS(va);
-		rv = page_size - page_off;
-	} else if (va >= ALPHA_K1SEG_BASE && va <= ALPHA_K1SEG_END) {
-		/*
-		 * Real kernel virtual address: do the translation.
-		 */
-#define PTMASK			((1 << ALPHA_PTSHIFT) - 1)
-#define pmap_lev1_index(va)	(((va) >> ALPHA_L1SHIFT) & PTMASK)
-#define pmap_lev2_index(va)	(((va) >> ALPHA_L2SHIFT) & PTMASK)
-#define pmap_lev3_index(va)	(((va) >> ALPHA_L3SHIFT) & PTMASK)
-
-		/* Find and read the L1 PTE. */
-		pteoff = lev1map_pa +
-			pmap_lev1_index(va)  * sizeof(alpha_pt_entry_t);
-		if (lseek(kd->pmfd, _kvm_pa2off(kd, pteoff), 0) == -1 ||
-		    read(kd->pmfd, (char *)&pte, sizeof(pte)) != sizeof(pte)) {
-			_kvm_syserr(kd, 0, "could not read L1 PTE");
-			goto lose;
-		}
-
-		/* Find and read the L2 PTE. */
-		if ((pte & ALPHA_PTE_VALID) == 0) {
-			_kvm_err(kd, 0, "invalid translation (invalid L1 PTE)");
-			goto lose;
-		}
-		pteoff = ALPHA_PTE_TO_PFN(pte) * page_size +
-		    pmap_lev2_index(va) * sizeof(alpha_pt_entry_t);
-		if (lseek(kd->pmfd, _kvm_pa2off(kd, pteoff), 0) == -1 ||
-		    read(kd->pmfd, (char *)&pte, sizeof(pte)) != sizeof(pte)) {
-			_kvm_syserr(kd, 0, "could not read L2 PTE");
-			goto lose;
-		}
-
-		/* Find and read the L3 PTE. */
-		if ((pte & ALPHA_PTE_VALID) == 0) {
-			_kvm_err(kd, 0, "invalid translation (invalid L2 PTE)");
-			goto lose;
-		}
-		pteoff = ALPHA_PTE_TO_PFN(pte) * page_size +
-		    pmap_lev3_index(va) * sizeof(alpha_pt_entry_t);
-		if (lseek(kd->pmfd, _kvm_pa2off(kd, pteoff), 0) == -1 ||
-		    read(kd->pmfd, (char *)&pte, sizeof(pte)) != sizeof(pte)) {
-			_kvm_syserr(kd, 0, "could not read L3 PTE");
-			goto lose;
-		}
-
-		/* Fill in the PA. */
-		if ((pte & ALPHA_PTE_VALID) == 0) {
-			_kvm_err(kd, 0, "invalid translation (invalid L3 PTE)");
-			goto lose;
-		}
-		*pa = ALPHA_PTE_TO_PFN(pte) * page_size + page_off;
-		rv = page_size - page_off;
-	} else {
-		/*
-		 * Bogus address (not in KV space): punt.
-		 */
-
-		_kvm_err(kd, 0, "invalid kernel virtual address");
-lose:
-		*pa = -1;
-		rv = 0;
-	}
-
-	return (rv);
-}
-
-/*
- * Translate a physical address to a file-offset in the crash-dump.
- */
-off_t   
-_kvm_pa2off(kd, pa)
-	kvm_t *kd;
-	u_long pa;
-{
-	return ALPHA_K0SEG_TO_PHYS(pa);
-}
-
Index: kvm_file.c
===================================================================
RCS file: /home/cvs/src/lib/libkvm/kvm_file.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L lib/libkvm/kvm_file.c -L lib/libkvm/kvm_file.c -u -r1.1.1.1 -r1.2
--- lib/libkvm/kvm_file.c
+++ lib/libkvm/kvm_file.c
@@ -10,10 +10,6 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
  * 4. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
@@ -32,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libkvm/kvm_file.c,v 1.17 2003/07/31 21:44:31 phk Exp $");
+__FBSDID("$FreeBSD: src/lib/libkvm/kvm_file.c,v 1.18 2007/01/08 17:35:36 imp Exp $");
 
 #if defined(LIBC_SCCS) && !defined(lint)
 #if 0
Index: kvm_open.3
===================================================================
RCS file: /home/cvs/src/lib/libkvm/kvm_open.3,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L lib/libkvm/kvm_open.3 -L lib/libkvm/kvm_open.3 -u -r1.1.1.1 -r1.2
--- lib/libkvm/kvm_open.3
+++ lib/libkvm/kvm_open.3
@@ -13,10 +13,6 @@
 .\" 2. Redistributions in binary form must reproduce the above copyright
 .\"    notice, this list of conditions and the following disclaimer in the
 .\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
 .\" 4. Neither the name of the University nor the names of its contributors
 .\"    may be used to endorse or promote products derived from this software
 .\"    without specific prior written permission.
@@ -34,7 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)kvm_open.3	8.3 (Berkeley) 4/19/94
-.\" $FreeBSD: src/lib/libkvm/kvm_open.3,v 1.17 2005/01/20 09:17:06 ru Exp $
+.\" $FreeBSD: src/lib/libkvm/kvm_open.3,v 1.18 2007/01/08 17:35:36 imp Exp $
 .\"
 .Dd January 29, 2004
 .Dt KVM_OPEN 3
Index: kvm_i386.c
===================================================================
RCS file: /home/cvs/src/lib/libkvm/kvm_i386.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L lib/libkvm/kvm_i386.c -L lib/libkvm/kvm_i386.c -u -r1.1.1.1 -r1.2
--- lib/libkvm/kvm_i386.c
+++ lib/libkvm/kvm_i386.c
@@ -14,10 +14,6 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
  * 4. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
@@ -36,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libkvm/kvm_i386.c,v 1.17.2.1 2005/10/26 00:06:58 peter Exp $");
+__FBSDID("$FreeBSD: src/lib/libkvm/kvm_i386.c,v 1.21 2007/06/15 11:35:11 simokawa Exp $");
 
 #if defined(LIBC_SCCS) && !defined(lint)
 #if 0
@@ -78,7 +74,9 @@
 #define	NPTEPG_PAE	(PAGE_SIZE/sizeof(uint64_t))
 #define	NBPDR_PAE	(1<<PDRSHIFT_PAE)
 
+/* minidump must be the first item! */
 struct vmstate {
+	int		minidump;	/* 1 = minidump mode */
 	void		*mmapbase;
 	size_t		mmapsize;
 	void		*PTD;
@@ -118,9 +116,16 @@
 _kvm_pa2off(kvm_t *kd, uint64_t pa, off_t *ofs)
 {
 	Elf_Ehdr *e = kd->vmst->mmapbase;
-	Elf_Phdr *p = (Elf_Phdr*)((char*)e + e->e_phoff);
-	int n = e->e_phnum;
+	Elf_Phdr *p;
+	int n;
 
+	if (kd->rawdump) {
+		*ofs = pa;
+		return (PAGE_SIZE - ((size_t)pa & PAGE_MASK));
+	}
+
+	p = (Elf_Phdr*)((char*)e + e->e_phoff);
+	n = e->e_phnum;
 	while (n && (pa < p->p_paddr || pa >= p->p_paddr + p->p_memsz))
 		p++, n--;
 	if (n == 0)
@@ -134,6 +139,8 @@
 {
 	struct vmstate *vm = kd->vmst;
 
+	if (kd->vmst->minidump)
+		return (_kvm_minidump_freevtop(kd));
 	if (vm->mmapbase != NULL)
 		munmap(vm->mmapbase, vm->mmapsize);
 	if (vm->PTD)
@@ -152,6 +159,11 @@
 	Elf_Ehdr	*ehdr;
 	size_t		hdrsz;
 	int		i;
+	char		minihdr[8];
+
+	if (!kd->rawdump && pread(kd->pmfd, &minihdr, 8, 0) == 8)
+		if (memcmp(&minihdr, "minidump", 8) == 0)
+			return (_kvm_minidump_initvtop(kd));
 
 	kd->vmst = (struct vmstate *)_kvm_malloc(kd, sizeof(*kd->vmst));
 	if (kd->vmst == 0) {
@@ -160,13 +172,15 @@
 	}
 	kd->vmst->PTD = 0;
 
-	if (_kvm_maphdrs(kd, sizeof(Elf_Ehdr)) == -1)
-		return (-1);
+	if (kd->rawdump == 0) {
+		if (_kvm_maphdrs(kd, sizeof(Elf_Ehdr)) == -1)
+			return (-1);
 
-	ehdr = kd->vmst->mmapbase;
-	hdrsz = ehdr->e_phoff + ehdr->e_phentsize * ehdr->e_phnum;
-	if (_kvm_maphdrs(kd, hdrsz) == -1)
-		return (-1);
+		ehdr = kd->vmst->mmapbase;
+		hdrsz = ehdr->e_phoff + ehdr->e_phentsize * ehdr->e_phnum;
+		if (_kvm_maphdrs(kd, hdrsz) == -1)
+			return (-1);
+	}
 
 	nlist[0].n_name = "kernbase";
 	nlist[1].n_name = 0;
@@ -426,6 +440,8 @@
 _kvm_kvatop(kvm_t *kd, u_long va, off_t *pa)
 {
 
+	if (kd->vmst->minidump)
+		return (_kvm_minidump_kvatop(kd, va, pa));
 	if (ISALIVE(kd)) {
 		_kvm_err(kd, 0, "vatop called in live kernel!");
 		return (0);
Index: kvm_nlist.3
===================================================================
RCS file: /home/cvs/src/lib/libkvm/kvm_nlist.3,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L lib/libkvm/kvm_nlist.3 -L lib/libkvm/kvm_nlist.3 -u -r1.1.1.1 -r1.2
--- lib/libkvm/kvm_nlist.3
+++ lib/libkvm/kvm_nlist.3
@@ -13,10 +13,6 @@
 .\" 2. Redistributions in binary form must reproduce the above copyright
 .\"    notice, this list of conditions and the following disclaimer in the
 .\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
 .\" 4. Neither the name of the University nor the names of its contributors
 .\"    may be used to endorse or promote products derived from this software
 .\"    without specific prior written permission.
@@ -34,7 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)kvm_nlist.3	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libkvm/kvm_nlist.3,v 1.10 2004/07/02 23:52:16 ru Exp $
+.\" $FreeBSD: src/lib/libkvm/kvm_nlist.3,v 1.11 2007/01/08 17:35:36 imp Exp $
 .\"
 .Dd June 4, 1993
 .Dt KVM_NLIST 3
--- lib/libkvm/kvm_ia64.c
+++ /dev/null
@@ -1,209 +0,0 @@
-/* $FreeBSD: src/lib/libkvm/kvm_ia64.c,v 1.7 2005/06/29 22:39:41 peter Exp $ */
-/*	$NetBSD: kvm_alpha.c,v 1.7.2.1 1997/11/02 20:34:26 mellon Exp $	*/
-
-/*
- * Copyright (c) 1994, 1995 Carnegie-Mellon University.
- * All rights reserved.
- *
- * Author: Chris G. Demetriou
- * 
- * Permission to use, copy, modify and distribute this software and
- * its documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- * 
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 
- * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 
- * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- * 
- * Carnegie Mellon requests users of this software to return to
- *
- *  Software Distribution Coordinator  or  Software.Distribution at CS.CMU.EDU
- *  School of Computer Science
- *  Carnegie Mellon University
- *  Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie the
- * rights to redistribute these changes.
- */
-
-#include <sys/types.h>
-#include <sys/elf64.h>
-#include <sys/mman.h>
-
-#include <machine/pte.h>
-
-#include <kvm.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include "kvm_private.h"
-
-#define	REGION_BASE(n)		(((uint64_t)(n)) << 61)
-#define	REGION_ADDR(x)		((x) & ((1LL<<61)-1LL))
-
-#define	NKPTEPG(ps)		((ps) / sizeof(struct ia64_lpte))
-#define	KPTE_PTE_INDEX(va,ps)	(((va)/(ps)) % NKPTEPG(ps))
-#define	KPTE_DIR_INDEX(va,ps)	(((va)/(ps)) / NKPTEPG(ps))
-
-struct vmstate {
-	void	*mmapbase;
-	size_t	mmapsize;
-	size_t	pagesize;
-	u_long	kptdir;
-};
-
-/*
- * Map the ELF headers into the process' address space. We do this in two
- * steps: first the ELF header itself and using that information the whole
- * set of headers.
- */
-static int
-_kvm_maphdrs(kvm_t *kd, size_t sz)
-{
-	struct vmstate *vm = kd->vmst;
-
-	/* munmap() previous mmap(). */
-	if (vm->mmapbase != NULL) {
-		munmap(vm->mmapbase, vm->mmapsize);
-		vm->mmapbase = NULL;
-	}
-
-	vm->mmapsize = sz;
-	vm->mmapbase = mmap(NULL, sz, PROT_READ, MAP_PRIVATE, kd->pmfd, 0);
-	if (vm->mmapbase == MAP_FAILED) {
-		_kvm_err(kd, kd->program, "cannot mmap corefile");
-		return (-1);
-	}
-
-	return (0);
-}
-
-/*
- * Translate a physical memory address to a file-offset in the crash-dump.
- */
-static size_t
-_kvm_pa2off(kvm_t *kd, uint64_t pa, off_t *ofs, size_t pgsz)
-{
-	Elf64_Ehdr *e = kd->vmst->mmapbase;
-	Elf64_Phdr *p = (Elf64_Phdr*)((char*)e + e->e_phoff);
-	int n = e->e_phnum;
-
-	if (pa != REGION_ADDR(pa)) {
-		_kvm_err(kd, kd->program, "internal error");
-		return (0);
-	}
-
-	while (n && (pa < p->p_paddr || pa >= p->p_paddr + p->p_memsz))
-		p++, n--;
-	if (n == 0)
-		return (0);
-
-	*ofs = (pa - p->p_paddr) + p->p_offset;
-	if (pgsz == 0)
-		return (p->p_memsz - (pa - p->p_paddr));
-	return (pgsz - ((size_t)pa & (pgsz - 1)));
-}
-
-void
-_kvm_freevtop(kvm_t *kd)
-{
-	struct vmstate *vm = kd->vmst;
-
-	if (vm->mmapbase != NULL)
-		munmap(vm->mmapbase, vm->mmapsize);
-	free(vm);
-	kd->vmst = NULL;
-}
-
-int
-_kvm_initvtop(kvm_t *kd)
-{
-	struct nlist nlist[2];
-	uint64_t va;
-	Elf64_Ehdr *ehdr;
-	size_t hdrsz;
-
-	kd->vmst = (struct vmstate *)_kvm_malloc(kd, sizeof(*kd->vmst));
-	if (kd->vmst == NULL) {
-		_kvm_err(kd, kd->program, "cannot allocate vm");
-		return (-1);
-	}
-
-	kd->vmst->pagesize = getpagesize();
-
-	if (_kvm_maphdrs(kd, sizeof(Elf64_Ehdr)) == -1)
-		return (-1);
-
-	ehdr = kd->vmst->mmapbase;
-	hdrsz = ehdr->e_phoff + ehdr->e_phentsize * ehdr->e_phnum;
-	if (_kvm_maphdrs(kd, hdrsz) == -1)
-		return (-1);
-
-	/*
-	 * At this point we've got enough information to use kvm_read() for
-	 * direct mapped (ie region 6 and region 7) address, such as symbol
-	 * addresses/values.
-	 */
-
-	nlist[0].n_name = "ia64_kptdir";
-	nlist[1].n_name = 0;
-
-	if (kvm_nlist(kd, nlist) != 0) {
-		_kvm_err(kd, kd->program, "bad namelist");
-		return (-1);
-	}
-
-	if (kvm_read(kd, (nlist[0].n_value), &va, sizeof(va)) != sizeof(va)) {
-		_kvm_err(kd, kd->program, "cannot read kptdir");
-		return (-1);
-	}
-
-	if (va < REGION_BASE(6)) {
-		_kvm_err(kd, kd->program, "kptdir is itself virtual");
-		return (-1);
-	}
-
-	kd->vmst->kptdir = va;
-	return (0);
-}
-
-int
-_kvm_kvatop(kvm_t *kd, u_long va, off_t *pa)
-{
-	struct ia64_lpte pte;
-	uint64_t pgaddr, ptaddr;
-	size_t pgno, pgsz, ptno;
-
-	if (va >= REGION_BASE(6)) {
-		/* Regions 6 and 7: direct mapped. */
-		return (_kvm_pa2off(kd, REGION_ADDR(va), pa, 0));
-	} else if (va >= REGION_BASE(5)) {
-		/* Region 5: virtual. */
-		va = REGION_ADDR(va);
-		pgsz = kd->vmst->pagesize;
-		ptno = KPTE_DIR_INDEX(va, pgsz);
-		pgno = KPTE_PTE_INDEX(va, pgsz);
-		if (ptno >= (pgsz >> 3))
-			goto fail;
-		ptaddr = kd->vmst->kptdir + (ptno << 3);
-		if (kvm_read(kd, ptaddr, &pgaddr, 8) != 8)
-			goto fail;
-		if (pgaddr == 0)
-			goto fail;
-		pgaddr += (pgno * sizeof(pte));
-		if (kvm_read(kd, pgaddr, &pte, sizeof(pte)) != sizeof(pte))
-			goto fail;
-		if (!(pte.pte & PTE_PRESENT))
-			goto fail;
-		va = (pte.pte & PTE_PPN_MASK) + (va & (pgsz - 1));
-		return (_kvm_pa2off(kd, va, pa, pgsz));
-	}
-
- fail:
-	_kvm_err(kd, kd->program, "invalid kernel virtual address");
-	*pa = ~0UL;
-	return (0);
-}
Index: kvm_getprocs.3
===================================================================
RCS file: /home/cvs/src/lib/libkvm/kvm_getprocs.3,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L lib/libkvm/kvm_getprocs.3 -L lib/libkvm/kvm_getprocs.3 -u -r1.1.1.1 -r1.2
--- lib/libkvm/kvm_getprocs.3
+++ lib/libkvm/kvm_getprocs.3
@@ -13,10 +13,6 @@
 .\" 2. Redistributions in binary form must reproduce the above copyright
 .\"    notice, this list of conditions and the following disclaimer in the
 .\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
 .\" 4. Neither the name of the University nor the names of its contributors
 .\"    may be used to endorse or promote products derived from this software
 .\"    without specific prior written permission.
@@ -34,7 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)kvm_getprocs.3	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libkvm/kvm_getprocs.3,v 1.20 2005/01/20 09:17:06 ru Exp $
+.\" $FreeBSD: src/lib/libkvm/kvm_getprocs.3,v 1.21 2007/01/08 17:35:36 imp Exp $
 .\"
 .Dd September 27, 2003
 .Dt KVM_GETPROCS 3
Index: kvm_getloadavg.c
===================================================================
RCS file: /home/cvs/src/lib/libkvm/kvm_getloadavg.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L lib/libkvm/kvm_getloadavg.c -L lib/libkvm/kvm_getloadavg.c -u -r1.1.1.1 -r1.2
--- lib/libkvm/kvm_getloadavg.c
+++ lib/libkvm/kvm_getloadavg.c
@@ -10,10 +10,6 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
  * 4. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
@@ -32,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libkvm/kvm_getloadavg.c,v 1.9 2001/11/20 08:26:37 jhb Exp $");
+__FBSDID("$FreeBSD: src/lib/libkvm/kvm_getloadavg.c,v 1.10 2007/01/08 17:35:36 imp Exp $");
 
 #if defined(LIBC_SCCS) && !defined(lint)
 #if 0
Index: Makefile
===================================================================
RCS file: /home/cvs/src/lib/libkvm/Makefile,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L lib/libkvm/Makefile -L lib/libkvm/Makefile -u -r1.1.1.1 -r1.2
--- lib/libkvm/Makefile
+++ lib/libkvm/Makefile
@@ -1,11 +1,20 @@
 #	@(#)Makefile	8.1 (Berkeley) 6/4/93
-# $FreeBSD: src/lib/libkvm/Makefile,v 1.14 2003/08/18 15:25:38 obrien Exp $
+# $FreeBSD: src/lib/libkvm/Makefile,v 1.17 2006/10/09 05:12:54 kmacy Exp $
+# $MidnightBSD$
 
 LIB=	kvm
 SHLIBDIR?= /lib
 CFLAGS+=-DLIBC_SCCS -I${.CURDIR}
+
+.if ${MACHINE} == "sun4v"
+CFLAGS+=-DSUN4V
+.endif
+
 SRCS=	kvm.c kvm_${MACHINE_ARCH}.c kvm_file.c kvm_getloadavg.c \
 	kvm_getswapinfo.c kvm_proc.c
+.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386"
+SRCS+=	kvm_minidump_${MACHINE_ARCH}.c
+.endif
 INCS=	kvm.h
 
 MAN=	kvm.3 kvm_geterr.3 kvm_getfiles.3 kvm_getloadavg.3 kvm_getprocs.3 \
Index: kvm_sparc64.c
===================================================================
RCS file: /home/cvs/src/lib/libkvm/kvm_sparc64.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L lib/libkvm/kvm_sparc64.c -L lib/libkvm/kvm_sparc64.c -u -r1.1.1.1 -r1.2
--- lib/libkvm/kvm_sparc64.c
+++ lib/libkvm/kvm_sparc64.c
@@ -14,10 +14,6 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
  * 4. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
@@ -38,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libkvm/kvm_sparc64.c,v 1.7 2005/06/29 22:39:41 peter Exp $");
+__FBSDID("$FreeBSD: src/lib/libkvm/kvm_sparc64.c,v 1.9 2007/01/08 17:35:36 imp Exp $");
 
 #if defined(LIBC_SCCS) && !defined(lint)
 #if 0
@@ -194,7 +190,9 @@
 _kvm_kvatop(kvm_t *kd, u_long va, off_t *pa)
 {
 	struct vmstate *vm;
+#if !defined(SUN4V)
 	struct tte tte;
+#endif
 	off_t tte_off, pa_off;
 	u_long pg_off, vpn;
 	int rest;
@@ -202,6 +200,7 @@
 	pg_off = va & PAGE_MASK;
 	if (va >= VM_MIN_DIRECT_ADDRESS)
 		pa_off = TLB_DIRECT_TO_PHYS(va) & ~PAGE_MASK;
+#if !defined(SUN4V)
 	else {
 		vpn = btop(va);
 		tte_off = kd->vmst->vm_tsb_off +
@@ -212,6 +211,7 @@
 			goto invalid;
 		pa_off = TTE_GET_PA(&tte);
 	}
+#endif
 	rest = PAGE_SIZE - pg_off;
 	pa_off = _kvm_find_off(kd->vmst, pa_off, rest);
 	if (pa_off == KVM_OFF_NOTFOUND)
Index: kvm_getfiles.3
===================================================================
RCS file: /home/cvs/src/lib/libkvm/kvm_getfiles.3,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L lib/libkvm/kvm_getfiles.3 -L lib/libkvm/kvm_getfiles.3 -u -r1.1.1.1 -r1.2
--- lib/libkvm/kvm_getfiles.3
+++ lib/libkvm/kvm_getfiles.3
@@ -13,10 +13,6 @@
 .\" 2. Redistributions in binary form must reproduce the above copyright
 .\"    notice, this list of conditions and the following disclaimer in the
 .\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
 .\" 4. Neither the name of the University nor the names of its contributors
 .\"    may be used to endorse or promote products derived from this software
 .\"    without specific prior written permission.
@@ -34,7 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)kvm_getfiles.3	8.2 (Berkeley) 4/19/94
-.\" $FreeBSD: src/lib/libkvm/kvm_getfiles.3,v 1.15 2005/01/20 09:17:06 ru Exp $
+.\" $FreeBSD: src/lib/libkvm/kvm_getfiles.3,v 1.16 2007/01/08 17:35:36 imp Exp $
 .\"
 .Dd April 19, 1994
 .Dt KVM_GETFILES 3
Index: kvm.3
===================================================================
RCS file: /home/cvs/src/lib/libkvm/kvm.3,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L lib/libkvm/kvm.3 -L lib/libkvm/kvm.3 -u -r1.1.1.1 -r1.2
--- lib/libkvm/kvm.3
+++ lib/libkvm/kvm.3
@@ -13,10 +13,6 @@
 .\" 2. Redistributions in binary form must reproduce the above copyright
 .\"    notice, this list of conditions and the following disclaimer in the
 .\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
 .\" 4. Neither the name of the University nor the names of its contributors
 .\"    may be used to endorse or promote products derived from this software
 .\"    without specific prior written permission.
@@ -34,7 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)kvm.3	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libkvm/kvm.3,v 1.14 2004/07/02 23:52:16 ru Exp $
+.\" $FreeBSD: src/lib/libkvm/kvm.3,v 1.15 2007/01/08 17:35:36 imp Exp $
 .\"
 .Dd January 29, 2004
 .Dt KVM 3
Index: kvm_sparc.c
===================================================================
RCS file: /home/cvs/src/lib/libkvm/kvm_sparc.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L lib/libkvm/kvm_sparc.c -L lib/libkvm/kvm_sparc.c -u -r1.1.1.1 -r1.2
--- lib/libkvm/kvm_sparc.c
+++ lib/libkvm/kvm_sparc.c
@@ -14,10 +14,6 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
  * 4. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
@@ -36,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libkvm/kvm_sparc.c,v 1.6 2005/06/29 22:39:41 peter Exp $");
+__FBSDID("$FreeBSD: src/lib/libkvm/kvm_sparc.c,v 1.7 2007/01/08 17:35:36 imp Exp $");
 
 #if defined(LIBC_SCCS) && !defined(lint)
 #if 0
Index: kvm_getloadavg.3
===================================================================
RCS file: /home/cvs/src/lib/libkvm/kvm_getloadavg.3,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L lib/libkvm/kvm_getloadavg.3 -L lib/libkvm/kvm_getloadavg.3 -u -r1.1.1.1 -r1.2
--- lib/libkvm/kvm_getloadavg.3
+++ lib/libkvm/kvm_getloadavg.3
@@ -9,10 +9,6 @@
 .\" 2. Redistributions in binary form must reproduce the above copyright
 .\"    notice, this list of conditions and the following disclaimer in the
 .\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
 .\" 4. Neither the name of the University nor the names of its contributors
 .\"    may be used to endorse or promote products derived from this software
 .\"    without specific prior written permission.
@@ -30,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)kvm_getloadavg.3	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libkvm/kvm_getloadavg.3,v 1.10 2001/10/01 16:09:16 ru Exp $
+.\" $FreeBSD: src/lib/libkvm/kvm_getloadavg.3,v 1.11 2007/01/08 17:35:36 imp Exp $
 .\"
 .Dd June 4, 1993
 .Dt KVM_GETLOADAVG 3
--- /dev/null
+++ lib/libkvm/kvm_minidump_amd64.c
@@ -0,0 +1,256 @@
+/*-
+ * Copyright (c) 2006 Peter Wemm
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/libkvm/kvm_minidump_amd64.c,v 1.2 2006/06/05 08:51:14 delphij Exp $");
+
+/*
+ * AMD64 machine dependent routines for kvm and minidumps. 
+ */
+
+#include <sys/param.h>
+#include <sys/user.h>
+#include <sys/proc.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <sys/fnv_hash.h>
+#include <stdlib.h>
+#include <strings.h>
+#include <unistd.h>
+#include <nlist.h>
+#include <kvm.h>
+
+#include <vm/vm.h>
+#include <vm/vm_param.h>
+
+#include <machine/elf.h>
+#include <machine/cpufunc.h>
+#include <machine/minidump.h>
+
+#include <limits.h>
+
+#include "kvm_private.h"
+
+struct hpte {
+	struct hpte *next;
+	vm_paddr_t pa;
+	int64_t off;
+};
+
+#define HPT_SIZE 1024
+
+/* minidump must be the first item! */
+struct vmstate {
+	int minidump;		/* 1 = minidump mode */
+	struct minidumphdr hdr;
+	void *hpt_head[HPT_SIZE];
+	uint64_t *bitmap;
+	uint64_t *ptemap;
+};
+
+static void
+hpt_insert(kvm_t *kd, vm_paddr_t pa, int64_t off)
+{
+	struct hpte *hpte;
+	uint32_t fnv = FNV1_32_INIT;
+
+	fnv = fnv_32_buf(&pa, sizeof(pa), fnv);
+	fnv &= (HPT_SIZE - 1);
+	hpte = malloc(sizeof(*hpte));
+	hpte->pa = pa;
+	hpte->off = off;
+	hpte->next = kd->vmst->hpt_head[fnv];
+	kd->vmst->hpt_head[fnv] = hpte;
+}
+
+static int64_t
+hpt_find(kvm_t *kd, vm_paddr_t pa)
+{
+	struct hpte *hpte;
+	uint32_t fnv = FNV1_32_INIT;
+
+	fnv = fnv_32_buf(&pa, sizeof(pa), fnv);
+	fnv &= (HPT_SIZE - 1);
+	for (hpte = kd->vmst->hpt_head[fnv]; hpte != NULL; hpte = hpte->next) {
+		if (pa == hpte->pa)
+			return (hpte->off);
+	}
+	return (-1);
+}
+
+static int
+inithash(kvm_t *kd, uint64_t *base, int len, off_t off)
+{
+	uint64_t idx;
+	uint64_t bit, bits;
+	vm_paddr_t pa;
+
+	for (idx = 0; idx < len / sizeof(*base); idx++) {
+		bits = base[idx];
+		while (bits) {
+			bit = bsfq(bits);
+			bits &= ~(1ul << bit);
+			pa = (idx * sizeof(*base) * NBBY + bit) * PAGE_SIZE;
+			hpt_insert(kd, pa, off);
+			off += PAGE_SIZE;
+		}
+	}
+	return (off);
+}
+
+void
+_kvm_minidump_freevtop(kvm_t *kd)
+{
+	struct vmstate *vm = kd->vmst;
+
+	if (vm->bitmap)
+		free(vm->bitmap);
+	if (vm->ptemap)
+		free(vm->ptemap);
+	free(vm);
+	kd->vmst = NULL;
+}
+
+int
+_kvm_minidump_initvtop(kvm_t *kd)
+{
+	u_long pa;
+	struct vmstate *vmst;
+	off_t off;
+
+	vmst = _kvm_malloc(kd, sizeof(*vmst));
+	if (vmst == 0) {
+		_kvm_err(kd, kd->program, "cannot allocate vm");
+		return (-1);
+	}
+	kd->vmst = vmst;
+	bzero(vmst, sizeof(*vmst));
+	vmst->minidump = 1;
+	if (pread(kd->pmfd, &vmst->hdr, sizeof(vmst->hdr), 0) !=
+	    sizeof(vmst->hdr)) {
+		_kvm_err(kd, kd->program, "cannot read dump header");
+		return (-1);
+	}
+	if (strncmp(MINIDUMP_MAGIC, vmst->hdr.magic, sizeof(vmst->hdr.magic)) != 0) {
+		_kvm_err(kd, kd->program, "not a minidump for this platform");
+		return (-1);
+	}
+	if (vmst->hdr.version != MINIDUMP_VERSION) {
+		_kvm_err(kd, kd->program, "wrong minidump version. expected %d got %d",
+		    MINIDUMP_VERSION, vmst->hdr.version);
+		return (-1);
+	}
+
+	/* Skip header and msgbuf */
+	off = PAGE_SIZE + round_page(vmst->hdr.msgbufsize);
+
+	vmst->bitmap = _kvm_malloc(kd, vmst->hdr.bitmapsize);
+	if (vmst->bitmap == NULL) {
+		_kvm_err(kd, kd->program, "cannot allocate %d bytes for bitmap", vmst->hdr.bitmapsize);
+		return (-1);
+	}
+	if (pread(kd->pmfd, vmst->bitmap, vmst->hdr.bitmapsize, off) !=
+	    vmst->hdr.bitmapsize) {
+		_kvm_err(kd, kd->program, "cannot read %d bytes for page bitmap", vmst->hdr.bitmapsize);
+		return (-1);
+	}
+	off += round_page(vmst->hdr.bitmapsize);
+
+	vmst->ptemap = _kvm_malloc(kd, vmst->hdr.ptesize);
+	if (vmst->ptemap == NULL) {
+		_kvm_err(kd, kd->program, "cannot allocate %d bytes for ptemap", vmst->hdr.ptesize);
+		return (-1);
+	}
+	if (pread(kd->pmfd, vmst->ptemap, vmst->hdr.ptesize, off) !=
+	    vmst->hdr.ptesize) {
+		_kvm_err(kd, kd->program, "cannot read %d bytes for ptemap", vmst->hdr.ptesize);
+		return (-1);
+	}
+	off += vmst->hdr.ptesize;
+
+	/* build physical address hash table for sparse pages */
+	inithash(kd, vmst->bitmap, vmst->hdr.bitmapsize, off);
+
+	return (0);
+}
+
+static int
+_kvm_minidump_vatop(kvm_t *kd, u_long va, off_t *pa)
+{
+	struct vmstate *vm;
+	u_long offset;
+	pt_entry_t pte;
+	u_long pteindex;
+	int i;
+	u_long a;
+	off_t ofs;
+
+	vm = kd->vmst;
+	offset = va & (PAGE_SIZE - 1);
+
+	if (va >= vm->hdr.kernbase) {
+		pteindex = (va - vm->hdr.kernbase) >> PAGE_SHIFT;
+		pte = vm->ptemap[pteindex];
+		if (((u_long)pte & PG_V) == 0) {
+			_kvm_err(kd, kd->program, "_kvm_vatop: pte not valid");
+			goto invalid;
+		}
+		a = pte & PG_FRAME;
+		ofs = hpt_find(kd, a);
+		if (ofs == -1) {
+			_kvm_err(kd, kd->program, "_kvm_vatop: physical address 0x%lx not in minidump", a);
+			goto invalid;
+		}
+		*pa = ofs + offset;
+		return (PAGE_SIZE - offset);
+	} else if (va >= vm->hdr.dmapbase && va < vm->hdr.dmapend) {
+		a = (va - vm->hdr.dmapbase) & ~PAGE_MASK;
+		ofs = hpt_find(kd, a);
+		if (ofs == -1) {
+			_kvm_err(kd, kd->program, "_kvm_vatop: direct map address 0x%lx not in minidump", va);
+			goto invalid;
+		}
+		*pa = ofs + offset;
+		return (PAGE_SIZE - offset);
+	} else {
+		_kvm_err(kd, kd->program, "_kvm_vatop: virtual address 0x%lx not minidumped", va);
+		goto invalid;
+	}
+
+invalid:
+	_kvm_err(kd, 0, "invalid address (0x%lx)", va);
+	return (0);
+}
+
+int
+_kvm_minidump_kvatop(kvm_t *kd, u_long va, off_t *pa)
+{
+
+	if (ISALIVE(kd)) {
+		_kvm_err(kd, 0, "kvm_kvatop called in live kernel!");
+		return (0);
+	}
+	return (_kvm_minidump_vatop(kd, va, pa));
+}
--- lib/libkvm/kvm_arm.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/*	$NetBSD: kvm_powerpc.c,v 1.4 1998/02/03 06:50:07 mycroft Exp $	*/
-
-/*-
- * Copyright (C) 1996 Wolfgang Solfrank.
- * Copyright (C) 1996 TooLs GmbH.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by TooLs GmbH.
- * 4. The name of TooLs GmbH may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * ARM machine dependent routines for kvm.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libkvm/kvm_arm.c,v 1.2 2005/06/29 22:39:41 peter Exp $");
-
-#include <sys/param.h>
-
-#include <vm/vm.h>
-
-#include <db.h>
-#include <limits.h>
-#include <kvm.h>
-#include <stdlib.h>
-
-#include "kvm_private.h"
-
-void
-_kvm_freevtop(kd)
-	kvm_t *kd;
-{
-	if (kd->vmst != 0)
-		free(kd->vmst);
-}
-
-int
-_kvm_initvtop(kd)
-	kvm_t *kd;
-{
-	return 0;
-}
-
-int
-_kvm_kvatop(kd, va, pa)
-	kvm_t *kd;
-	u_long va;
-	off_t *pa;
-{
-	_kvm_err(kd, 0, "vatop not yet implemented!");
-	return 0;
-}
-
-off_t
-_kvm_pa2off(kd, pa)
-	kvm_t *kd;
-	u_long pa;
-{
-	_kvm_err(kd, 0, "pa2off not yet implemented!");
-	return 0;
-}
-
-/*
- * Machine-dependent initialization for ALL open kvm descriptors,
- * not just those for a kernel crash dump.  Some architectures
- * have to deal with these NOT being constants!  (i.e. m68k)
- */
-int
-_kvm_mdopen(kd)
-	kvm_t	*kd;
-{
-
-#ifdef FBSD_NOT_YET
-	kd->usrstack = USRSTACK;
-	kd->min_uva = VM_MIN_ADDRESS;
-	kd->max_uva = VM_MAXUSER_ADDRESS;
-#endif
-
-	return (0);
-}
--- lib/libkvm/kvm_powerpc.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/*	$NetBSD: kvm_powerpc.c,v 1.4 1998/02/03 06:50:07 mycroft Exp $	*/
-
-/*-
- * Copyright (C) 1996 Wolfgang Solfrank.
- * Copyright (C) 1996 TooLs GmbH.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by TooLs GmbH.
- * 4. The name of TooLs GmbH may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * PowerPC machine dependent routines for kvm.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libkvm/kvm_powerpc.c,v 1.3 2005/06/29 22:39:41 peter Exp $");
-
-#include <sys/param.h>
-
-#include <vm/vm.h>
-
-#include <db.h>
-#include <limits.h>
-#include <kvm.h>
-#include <stdlib.h>
-
-#include "kvm_private.h"
-
-void
-_kvm_freevtop(kd)
-	kvm_t *kd;
-{
-	if (kd->vmst != 0)
-		free(kd->vmst);
-}
-
-int
-_kvm_initvtop(kd)
-	kvm_t *kd;
-{
-	return 0;
-}
-
-int
-_kvm_kvatop(kd, va, pa)
-	kvm_t *kd;
-	u_long va;
-	off_t *pa;
-{
-	_kvm_err(kd, 0, "vatop not yet implemented!");
-	return 0;
-}
-
-off_t
-_kvm_pa2off(kd, pa)
-	kvm_t *kd;
-	u_long pa;
-{
-	_kvm_err(kd, 0, "pa2off not yet implemented!");
-	return 0;
-}
-
-/*
- * Machine-dependent initialization for ALL open kvm descriptors,
- * not just those for a kernel crash dump.  Some architectures
- * have to deal with these NOT being constants!  (i.e. m68k)
- */
-int
-_kvm_mdopen(kd)
-	kvm_t	*kd;
-{
-
-#ifdef FBSD_NOT_YET
-	kd->usrstack = USRSTACK;
-	kd->min_uva = VM_MIN_ADDRESS;
-	kd->max_uva = VM_MAXUSER_ADDRESS;
-#endif
-
-	return (0);
-}
Index: kvm.h
===================================================================
RCS file: /home/cvs/src/lib/libkvm/kvm.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L lib/libkvm/kvm.h -L lib/libkvm/kvm.h -u -r1.1.1.1 -r1.2
--- lib/libkvm/kvm.h
+++ lib/libkvm/kvm.h
@@ -10,10 +10,6 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
  * 4. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
@@ -31,7 +27,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)kvm.h	8.1 (Berkeley) 6/2/93
- * $FreeBSD: src/lib/libkvm/kvm.h,v 1.16 2003/10/13 04:44:55 bde Exp $
+ * $FreeBSD: src/lib/libkvm/kvm.h,v 1.17 2007/01/08 17:35:36 imp Exp $
  */
 
 #ifndef _KVM_H_
Index: kvm_read.3
===================================================================
RCS file: /home/cvs/src/lib/libkvm/kvm_read.3,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L lib/libkvm/kvm_read.3 -L lib/libkvm/kvm_read.3 -u -r1.1.1.1 -r1.2
--- lib/libkvm/kvm_read.3
+++ lib/libkvm/kvm_read.3
@@ -13,10 +13,6 @@
 .\" 2. Redistributions in binary form must reproduce the above copyright
 .\"    notice, this list of conditions and the following disclaimer in the
 .\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
 .\" 4. Neither the name of the University nor the names of its contributors
 .\"    may be used to endorse or promote products derived from this software
 .\"    without specific prior written permission.
@@ -34,7 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)kvm_read.3	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libkvm/kvm_read.3,v 1.10 2004/07/02 23:52:16 ru Exp $
+.\" $FreeBSD: src/lib/libkvm/kvm_read.3,v 1.11 2007/01/08 17:35:36 imp Exp $
 .\"
 .Dd June 4, 1993
 .Dt KVM_READ 3
Index: kvm_private.h
===================================================================
RCS file: /home/cvs/src/lib/libkvm/kvm_private.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L lib/libkvm/kvm_private.h -L lib/libkvm/kvm_private.h -u -r1.1.1.1 -r1.2
--- lib/libkvm/kvm_private.h
+++ lib/libkvm/kvm_private.h
@@ -14,10 +14,6 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
  * 4. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
@@ -35,7 +31,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)kvm_private.h	8.1 (Berkeley) 6/4/93
- * $FreeBSD: src/lib/libkvm/kvm_private.h,v 1.9 2005/06/29 22:39:41 peter Exp $
+ * $FreeBSD: src/lib/libkvm/kvm_private.h,v 1.12 2007/06/15 11:35:11 simokawa Exp $
  */
 
 struct __kvm {
@@ -65,6 +61,7 @@
 	 * only allocate it if necessary.
 	 */
 	struct vmstate *vmst;
+	int	rawdump;	/* raw dump format */
 };
 
 /*
@@ -81,3 +78,9 @@
 void	 _kvm_syserr (kvm_t *kd, const char *program, const char *fmt, ...)
 	    __printflike(3, 4);
 int	 _kvm_uvatop(kvm_t *, const struct proc *, u_long, u_long *);
+
+#if defined(__amd64__) || defined(__i386__)
+void	 _kvm_minidump_freevtop(kvm_t *);
+int	 _kvm_minidump_initvtop(kvm_t *);
+int	 _kvm_minidump_kvatop(kvm_t *, u_long, off_t *);
+#endif
--- /dev/null
+++ lib/libkvm/kvm_minidump_i386.c
@@ -0,0 +1,295 @@
+/*-
+ * Copyright (c) 2006 Peter Wemm
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/libkvm/kvm_minidump_i386.c,v 1.2 2006/06/05 08:51:14 delphij Exp $");
+
+/*
+ * AMD64 machine dependent routines for kvm and minidumps. 
+ */
+
+#include <sys/param.h>
+#include <sys/user.h>
+#include <sys/proc.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <sys/fnv_hash.h>
+#include <stdlib.h>
+#include <strings.h>
+#include <unistd.h>
+#include <nlist.h>
+#include <kvm.h>
+
+#include <vm/vm.h>
+#include <vm/vm_param.h>
+
+#include <machine/elf.h>
+#include <machine/cpufunc.h>
+#include <machine/minidump.h>
+
+#include <limits.h>
+
+#include "kvm_private.h"
+
+#define PG_FRAME_PAE	(~((uint64_t)PAGE_MASK))
+
+struct hpte {
+	struct hpte *next;
+	uint64_t pa;
+	int64_t off;
+};
+
+#define HPT_SIZE 1024
+
+/* minidump must be the first item! */
+struct vmstate {
+	int minidump;		/* 1 = minidump mode */
+	struct minidumphdr hdr;
+	void *hpt_head[HPT_SIZE];
+	uint32_t *bitmap;
+	void *ptemap;
+};
+
+static void
+hpt_insert(kvm_t *kd, uint64_t pa, int64_t off)
+{
+	struct hpte *hpte;
+	uint32_t fnv = FNV1_32_INIT;
+
+	fnv = fnv_32_buf(&pa, sizeof(pa), fnv);
+	fnv &= (HPT_SIZE - 1);
+	hpte = malloc(sizeof(*hpte));
+	hpte->pa = pa;
+	hpte->off = off;
+	hpte->next = kd->vmst->hpt_head[fnv];
+	kd->vmst->hpt_head[fnv] = hpte;
+}
+
+static int64_t
+hpt_find(kvm_t *kd, uint64_t pa)
+{
+	struct hpte *hpte;
+	uint32_t fnv = FNV1_32_INIT;
+
+	fnv = fnv_32_buf(&pa, sizeof(pa), fnv);
+	fnv &= (HPT_SIZE - 1);
+	for (hpte = kd->vmst->hpt_head[fnv]; hpte != NULL; hpte = hpte->next) {
+		if (pa == hpte->pa)
+			return (hpte->off);
+	}
+	return (-1);
+}
+
+static int
+inithash(kvm_t *kd, uint32_t *base, int len, off_t off)
+{
+	uint64_t idx;
+	uint32_t bit, bits;
+	uint64_t pa;
+
+	for (idx = 0; idx < len / sizeof(*base); idx++) {
+		bits = base[idx];
+		while (bits) {
+			bit = bsfl(bits);
+			bits &= ~(1ul << bit);
+			pa = (idx * sizeof(*base) * NBBY + bit) * PAGE_SIZE;
+			hpt_insert(kd, pa, off);
+			off += PAGE_SIZE;
+		}
+	}
+	return (off);
+}
+
+void
+_kvm_minidump_freevtop(kvm_t *kd)
+{
+	struct vmstate *vm = kd->vmst;
+
+	if (vm->bitmap)
+		free(vm->bitmap);
+	if (vm->ptemap)
+		free(vm->ptemap);
+	free(vm);
+	kd->vmst = NULL;
+}
+
+int
+_kvm_minidump_initvtop(kvm_t *kd)
+{
+	u_long pa;
+	struct vmstate *vmst;
+	off_t off;
+
+	vmst = _kvm_malloc(kd, sizeof(*vmst));
+	if (vmst == 0) {
+		_kvm_err(kd, kd->program, "cannot allocate vm");
+		return (-1);
+	}
+	kd->vmst = vmst;
+	bzero(vmst, sizeof(*vmst));
+	vmst->minidump = 1;
+	if (pread(kd->pmfd, &vmst->hdr, sizeof(vmst->hdr), 0) !=
+	    sizeof(vmst->hdr)) {
+		_kvm_err(kd, kd->program, "cannot read dump header");
+		return (-1);
+	}
+	if (strncmp(MINIDUMP_MAGIC, vmst->hdr.magic, sizeof(vmst->hdr.magic)) != 0) {
+		_kvm_err(kd, kd->program, "not a minidump for this platform");
+		return (-1);
+	}
+	if (vmst->hdr.version != MINIDUMP_VERSION) {
+		_kvm_err(kd, kd->program, "wrong minidump version. expected %d got %d",
+		    MINIDUMP_VERSION, vmst->hdr.version);
+		return (-1);
+	}
+
+	/* Skip header and msgbuf */
+	off = PAGE_SIZE + round_page(vmst->hdr.msgbufsize);
+
+	vmst->bitmap = _kvm_malloc(kd, vmst->hdr.bitmapsize);
+	if (vmst->bitmap == NULL) {
+		_kvm_err(kd, kd->program, "cannot allocate %d bytes for bitmap", vmst->hdr.bitmapsize);
+		return (-1);
+	}
+	if (pread(kd->pmfd, vmst->bitmap, vmst->hdr.bitmapsize, off) !=
+	    vmst->hdr.bitmapsize) {
+		_kvm_err(kd, kd->program, "cannot read %d bytes for page bitmap", vmst->hdr.bitmapsize);
+		return (-1);
+	}
+	off += round_page(vmst->hdr.bitmapsize);
+
+	vmst->ptemap = _kvm_malloc(kd, vmst->hdr.ptesize);
+	if (vmst->ptemap == NULL) {
+		_kvm_err(kd, kd->program, "cannot allocate %d bytes for ptemap", vmst->hdr.ptesize);
+		return (-1);
+	}
+	if (pread(kd->pmfd, vmst->ptemap, vmst->hdr.ptesize, off) !=
+	    vmst->hdr.ptesize) {
+		_kvm_err(kd, kd->program, "cannot read %d bytes for ptemap", vmst->hdr.ptesize);
+		return (-1);
+	}
+	off += vmst->hdr.ptesize;
+
+	/* build physical address hash table for sparse pages */
+	inithash(kd, vmst->bitmap, vmst->hdr.bitmapsize, off);
+
+	return (0);
+}
+
+static int
+_kvm_minidump_vatop_pae(kvm_t *kd, u_long va, off_t *pa)
+{
+	struct vmstate *vm;
+	uint64_t offset;
+	uint64_t pte;
+	u_long pteindex;
+	int i;
+	uint64_t a;
+	off_t ofs;
+	uint64_t *ptemap;
+
+	vm = kd->vmst;
+	ptemap = vm->ptemap;
+	offset = va & (PAGE_SIZE - 1);
+
+	if (va >= vm->hdr.kernbase) {
+		pteindex = (va - vm->hdr.kernbase) >> PAGE_SHIFT;
+		pte = ptemap[pteindex];
+		if ((pte & PG_V) == 0) {
+			_kvm_err(kd, kd->program, "_kvm_vatop: pte not valid");
+			goto invalid;
+		}
+		a = pte & PG_FRAME_PAE;
+		ofs = hpt_find(kd, a);
+		if (ofs == -1) {
+			_kvm_err(kd, kd->program, "_kvm_vatop: physical address 0x%llx not in minidump", a);
+			goto invalid;
+		}
+		*pa = ofs + offset;
+		return (PAGE_SIZE - offset);
+	} else {
+		_kvm_err(kd, kd->program, "_kvm_vatop: virtual address 0x%lx not minidumped", va);
+		goto invalid;
+	}
+
+invalid:
+	_kvm_err(kd, 0, "invalid address (0x%lx)", va);
+	return (0);
+}
+
+static int
+_kvm_minidump_vatop(kvm_t *kd, u_long va, off_t *pa)
+{
+	struct vmstate *vm;
+	u_long offset;
+	pt_entry_t pte;
+	u_long pteindex;
+	int i;
+	u_long a;
+	off_t ofs;
+	uint32_t *ptemap;
+
+	vm = kd->vmst;
+	ptemap = vm->ptemap;
+	offset = va & (PAGE_SIZE - 1);
+
+	if (va >= vm->hdr.kernbase) {
+		pteindex = (va - vm->hdr.kernbase) >> PAGE_SHIFT;
+		pte = ptemap[pteindex];
+		if ((pte & PG_V) == 0) {
+			_kvm_err(kd, kd->program, "_kvm_vatop: pte not valid");
+			goto invalid;
+		}
+		a = pte & PG_FRAME;
+		ofs = hpt_find(kd, a);
+		if (ofs == -1) {
+			_kvm_err(kd, kd->program, "_kvm_vatop: physical address 0x%lx not in minidump", a);
+			goto invalid;
+		}
+		*pa = ofs + offset;
+		return (PAGE_SIZE - offset);
+	} else {
+		_kvm_err(kd, kd->program, "_kvm_vatop: virtual address 0x%lx not minidumped", va);
+		goto invalid;
+	}
+
+invalid:
+	_kvm_err(kd, 0, "invalid address (0x%lx)", va);
+	return (0);
+}
+
+int
+_kvm_minidump_kvatop(kvm_t *kd, u_long va, off_t *pa)
+{
+
+	if (ISALIVE(kd)) {
+		_kvm_err(kd, 0, "kvm_kvatop called in live kernel!");
+		return (0);
+	}
+	if (kd->vmst->hdr.paemode)
+		return (_kvm_minidump_vatop_pae(kd, va, pa));
+	else	
+		return (_kvm_minidump_vatop(kd, va, pa));
+}
Index: kvm_getswapinfo.c
===================================================================
RCS file: /home/cvs/src/lib/libkvm/kvm_getswapinfo.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L lib/libkvm/kvm_getswapinfo.c -L lib/libkvm/kvm_getswapinfo.c -u -r1.1.1.1 -r1.2
--- lib/libkvm/kvm_getswapinfo.c
+++ lib/libkvm/kvm_getswapinfo.c
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libkvm/kvm_getswapinfo.c,v 1.26 2004/07/31 18:49:53 imp Exp $");
+__FBSDID("$FreeBSD: src/lib/libkvm/kvm_getswapinfo.c,v 1.27 2007/02/07 17:43:10 jhb Exp $");
 
 #include <sys/param.h>
 #include <sys/time.h>
@@ -33,6 +33,7 @@
 #include <sys/blist.h>
 #include <sys/sysctl.h>
 
+#include <vm/swap_pager.h>
 #include <vm/vm_param.h>
 
 #include <err.h>
@@ -49,18 +50,34 @@
 
 #include "kvm_private.h"
 
-#define NL_SWAPBLIST	0
-#define NL_SWDEVT	1
-#define NL_NSWDEV	2
-#define NL_DMMAX	3
+static struct nlist kvm_swap_nl[] = {
+	{ "_swtailq" },		/* list of swap devices and sizes */
+	{ "_dmmax" },		/* maximum size of a swap block */
+	{ NULL }
+};
+
+#define NL_SWTAILQ	0
+#define NL_DMMAX	1
 
 static int kvm_swap_nl_cached = 0;
 static int unswdev;  /* number of found swap dev's */
 static int dmmax;
 
+static int  kvm_getswapinfo_kvm(kvm_t *, struct kvm_swap *, int, int);
 static int  kvm_getswapinfo_sysctl(kvm_t *, struct kvm_swap *, int, int);
+static int  nlist_init(kvm_t *);
 static int  getsysctl(kvm_t *, char *, void *, size_t);
 
+#define KREAD(kd, addr, obj) \
+	(kvm_read(kd, addr, (char *)(obj), sizeof(*obj)) != sizeof(*obj))
+#define	KGET(idx, var)							\
+	KGET2(kvm_swap_nl[(idx)].n_value, var, kvm_swap_nl[(idx)].n_name)
+#define KGET2(addr, var, msg)						\
+	if (KREAD(kd, (u_long)(addr), (var))) {				\
+		_kvm_err(kd, kd->program, "cannot read %s", msg);	\
+		return (-1);						\
+	}
+	
 #define GETSWDEVNAME(dev, str, flags)					\
 	if (dev == NODEV) {						\
 		strlcpy(str, "[NFS swap]", sizeof(str));		\
@@ -91,8 +108,50 @@
 	if (ISALIVE(kd)) {
 		return kvm_getswapinfo_sysctl(kd, swap_ary, swap_max, flags);
 	} else {
-		return -1;
+		return kvm_getswapinfo_kvm(kd, swap_ary, swap_max, flags);
+	}
+}
+
+int
+kvm_getswapinfo_kvm(
+	kvm_t *kd,
+	struct kvm_swap *swap_ary,
+	int swap_max,
+	int flags
+) {
+	int i, ttl;
+	TAILQ_HEAD(, swdevt) swtailq;
+	struct swdevt *sp, swinfo;
+	struct kvm_swap tot;
+
+	if (!nlist_init(kd))
+		return (-1);
+
+	bzero(&tot, sizeof(tot));
+	KGET(NL_SWTAILQ, &swtailq);
+	sp = TAILQ_FIRST(&swtailq);
+	for (i = 0; sp != NULL; i++) {
+		KGET2(sp, &swinfo, "swinfo");
+		ttl = swinfo.sw_nblks - dmmax;
+		if (i < swap_max - 1) {
+			bzero(&swap_ary[i], sizeof(swap_ary[i]));
+			swap_ary[i].ksw_total = ttl;
+			swap_ary[i].ksw_used = swinfo.sw_used;
+			swap_ary[i].ksw_flags = swinfo.sw_flags;
+			GETSWDEVNAME(swinfo.sw_dev, swap_ary[i].ksw_devname,
+			     flags);
+		}
+		tot.ksw_total += ttl;
+		tot.ksw_used += swinfo.sw_used;
+		sp = TAILQ_NEXT(&swinfo, sw_list);
 	}
+
+	if (i >= swap_max)
+		i = swap_max - 1;
+	if (i >= 0)
+		swap_ary[i] = tot;
+
+        return(i);
 }
 
 #define	GETSYSCTL(kd, name, var)					\
@@ -168,6 +227,36 @@
 }
 
 static int
+nlist_init(kvm_t *kd)
+{
+	TAILQ_HEAD(, swdevt) swtailq;
+	struct swdevt *sp, swinfo;
+
+	if (kvm_swap_nl_cached)
+		return (1);
+
+	if (kvm_nlist(kd, kvm_swap_nl) < 0)
+		return (0);
+
+	/* Required entries */
+	if (kvm_swap_nl[NL_SWTAILQ].n_value == 0) {
+		_kvm_err(kd, kd->program, "unable to find swtailq");
+		return (0);
+	}
+		
+	if (kvm_swap_nl[NL_DMMAX].n_value == 0) {
+		_kvm_err(kd, kd->program, "unable to find dmmax");
+		return (0);
+	}
+
+	/* Get globals, type of swap */
+	KGET(NL_DMMAX, &dmmax);
+
+	kvm_swap_nl_cached = 1;
+	return (1);
+}
+
+static int
 getsysctl (
 	kvm_t *kd,
 	char *name,


More information about the Midnightbsd-cvs mailing list