Handle reading from raw disk devices.
This commit is contained in:
parent
622b391c8f
commit
a7a2d171df
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kvm.c,v 1.90 2007/11/08 21:58:26 joerg Exp $ */
|
||||
/* $NetBSD: kvm.c,v 1.91 2008/01/15 13:57:41 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1989, 1992, 1993
|
||||
|
@ -38,7 +38,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)kvm.c 8.2 (Berkeley) 2/13/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: kvm.c,v 1.90 2007/11/08 21:58:26 joerg Exp $");
|
||||
__RCSID("$NetBSD: kvm.c,v 1.91 2008/01/15 13:57:41 ad Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
|
@ -183,6 +183,44 @@ Lseek(kvm_t *kd, int fd, off_t offset, int whence)
|
|||
return (off);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
_kvm_pread(kvm_t *kd, int fd, void *buf, size_t size, off_t off)
|
||||
{
|
||||
ptrdiff_t moff;
|
||||
void *newbuf;
|
||||
size_t dsize;
|
||||
ssize_t rv;
|
||||
off_t doff;
|
||||
|
||||
/* If aligned nothing to do. */
|
||||
if (((off % kd->fdalign) | (size % kd->fdalign)) == 0) {
|
||||
return pread(fd, buf, size, off);
|
||||
}
|
||||
|
||||
/*
|
||||
* Otherwise must buffer. We can't tolerate short reads in this
|
||||
* case (lazy bum).
|
||||
*/
|
||||
moff = (ptrdiff_t)off % kd->fdalign;
|
||||
doff = off - moff;
|
||||
dsize = moff + size + kd->fdalign - 1;
|
||||
dsize -= dsize % kd->fdalign;
|
||||
if (kd->iobufsz < dsize) {
|
||||
newbuf = realloc(kd->iobuf, dsize);
|
||||
if (newbuf == NULL) {
|
||||
_kvm_syserr(kd, 0, "cannot allocate I/O buffer");
|
||||
return (-1);
|
||||
}
|
||||
kd->iobuf = newbuf;
|
||||
kd->iobufsz = dsize;
|
||||
}
|
||||
rv = pread(fd, kd->iobuf, dsize, doff);
|
||||
if (rv < dsize)
|
||||
return -1;
|
||||
memcpy(buf, kd->iobuf + moff, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
/*
|
||||
* Wrapper around the pread(2) system call; calls _kvm_syserr() for us
|
||||
* in the event of emergency.
|
||||
|
@ -194,7 +232,7 @@ Pread(kvm_t *kd, int fd, void *buf, size_t nbytes, off_t offset)
|
|||
|
||||
errno = 0;
|
||||
|
||||
if ((rv = pread(fd, buf, nbytes, offset)) != nbytes &&
|
||||
if ((rv = _kvm_pread(kd, fd, buf, nbytes, offset)) != nbytes &&
|
||||
errno != 0)
|
||||
_kvm_syserr(kd, kd->program, "Pread");
|
||||
return (rv);
|
||||
|
@ -230,6 +268,9 @@ _kvm_open(kvm_t *kd, const char *uf, const char *mf, const char *sf, int flag,
|
|||
kd->cpu_dsize = 0;
|
||||
kd->cpu_data = NULL;
|
||||
kd->dump_off = 0;
|
||||
kd->fdalign = 1;
|
||||
kd->iobuf = NULL;
|
||||
kd->iobufsz = 0;
|
||||
|
||||
if (flag & KVM_NO_FILES) {
|
||||
kd->alive = KVM_ALIVE_SYSCTL;
|
||||
|
@ -291,18 +332,12 @@ _kvm_open(kvm_t *kd, const char *uf, const char *mf, const char *sf, int flag,
|
|||
_kvm_syserr(kd, kd->program, "%s", mf);
|
||||
goto failed;
|
||||
}
|
||||
if (S_ISCHR(st.st_mode)) {
|
||||
if (S_ISCHR(st.st_mode) && strcmp(mf, _PATH_MEM) == 0) {
|
||||
/*
|
||||
* If this is a character special device, then check that
|
||||
* it's /dev/mem. If so, open kmem too. (Maybe we should
|
||||
* If this is /dev/mem, open kmem too. (Maybe we should
|
||||
* make it work for either /dev/mem or /dev/kmem -- in either
|
||||
* case you're working with a live kernel.)
|
||||
*/
|
||||
if (strcmp(mf, _PATH_MEM) != 0) { /* XXX */
|
||||
_kvm_err(kd, kd->program,
|
||||
"%s: not physical memory device", mf);
|
||||
goto failed;
|
||||
}
|
||||
if ((kd->vmfd = open_cloexec(_PATH_KMEM, flag, 0)) < 0) {
|
||||
_kvm_syserr(kd, kd->program, "%s", _PATH_KMEM);
|
||||
goto failed;
|
||||
|
@ -338,6 +373,7 @@ _kvm_open(kvm_t *kd, const char *uf, const char *mf, const char *sf, int flag,
|
|||
kd->nlfd = -1;
|
||||
}
|
||||
} else {
|
||||
kd->fdalign = DEV_BSIZE; /* XXX */
|
||||
/*
|
||||
* This is a crash dump.
|
||||
* Initialize the virtual address translation machinery,
|
||||
|
@ -707,24 +743,26 @@ kvm_close(kvm_t *kd)
|
|||
_kvm_freevtop(kd);
|
||||
kd->cpu_dsize = 0;
|
||||
if (kd->cpu_data != NULL)
|
||||
free((void *)kd->cpu_data);
|
||||
free(kd->cpu_data);
|
||||
if (kd->kcore_hdr != NULL)
|
||||
free((void *)kd->kcore_hdr);
|
||||
free(kd->kcore_hdr);
|
||||
if (kd->procbase != 0)
|
||||
free((void *)kd->procbase);
|
||||
free(kd->procbase);
|
||||
if (kd->procbase2 != 0)
|
||||
free((void *)kd->procbase2);
|
||||
free(kd->procbase2);
|
||||
if (kd->lwpbase != 0)
|
||||
free((void *)kd->lwpbase);
|
||||
free(kd->lwpbase);
|
||||
if (kd->swapspc != 0)
|
||||
free((void *)kd->swapspc);
|
||||
free(kd->swapspc);
|
||||
if (kd->argspc != 0)
|
||||
free((void *)kd->argspc);
|
||||
free(kd->argspc);
|
||||
if (kd->argbuf != 0)
|
||||
free((void *)kd->argbuf);
|
||||
free(kd->argbuf);
|
||||
if (kd->argv != 0)
|
||||
free((void *)kd->argv);
|
||||
free((void *)kd);
|
||||
free(kd->argv);
|
||||
if (kd->iobuf != 0)
|
||||
free(kd->iobuf);
|
||||
free(kd);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
@ -804,7 +842,7 @@ kvm_read(kvm_t *kd, u_long kva, void *buf, size_t len)
|
|||
* device and let the active kernel do the address translation.
|
||||
*/
|
||||
errno = 0;
|
||||
cc = pread(kd->vmfd, buf, len, (off_t)kva);
|
||||
cc = _kvm_pread(kd, kd->vmfd, buf, len, (off_t)kva);
|
||||
if (cc < 0) {
|
||||
_kvm_syserr(kd, 0, "kvm_read");
|
||||
return (-1);
|
||||
|
@ -832,7 +870,7 @@ kvm_read(kvm_t *kd, u_long kva, void *buf, size_t len)
|
|||
cc = len;
|
||||
foff = _kvm_pa2off(kd, pa);
|
||||
errno = 0;
|
||||
cc = pread(kd->pmfd, cp, (size_t)cc, foff);
|
||||
cc = _kvm_pread(kd, kd->pmfd, cp, (size_t)cc, foff);
|
||||
if (cc < 0) {
|
||||
_kvm_syserr(kd, kd->program, "kvm_read");
|
||||
break;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kvm_alpha.c,v 1.22 2003/05/16 10:24:55 wiz Exp $ */
|
||||
/* $NetBSD: kvm_alpha.c,v 1.23 2008/01/15 13:57:41 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1995 Carnegie-Mellon University.
|
||||
|
@ -99,7 +99,7 @@ _kvm_kvatop(kd, va, pa)
|
|||
/* Find and read the L1 PTE. */
|
||||
pteoff = cpu_kh->lev1map_pa +
|
||||
l1pte_index(va) * sizeof(alpha_pt_entry_t);
|
||||
if (pread(kd->pmfd, &pte, sizeof(pte),
|
||||
if (_kvm_pread(kd, kd->pmfd, &pte, sizeof(pte),
|
||||
_kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
|
||||
_kvm_syserr(kd, 0, "could not read L1 PTE");
|
||||
goto lose;
|
||||
|
@ -112,7 +112,7 @@ _kvm_kvatop(kd, va, pa)
|
|||
}
|
||||
pteoff = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size +
|
||||
l2pte_index(va) * sizeof(alpha_pt_entry_t);
|
||||
if (pread(kd->pmfd, &pte, sizeof(pte),
|
||||
if (_kvm_pread(kd, kd->pmfd, &pte, sizeof(pte),
|
||||
_kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
|
||||
_kvm_syserr(kd, 0, "could not read L2 PTE");
|
||||
goto lose;
|
||||
|
@ -125,7 +125,7 @@ _kvm_kvatop(kd, va, pa)
|
|||
}
|
||||
pteoff = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size +
|
||||
l3pte_index(va) * sizeof(alpha_pt_entry_t);
|
||||
if (pread(kd->pmfd, &pte, sizeof(pte),
|
||||
if (_kvm_pread(kd, kd->pmfd, &pte, sizeof(pte),
|
||||
_kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
|
||||
_kvm_syserr(kd, 0, "could not read L3 PTE");
|
||||
goto lose;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kvm_arm.c,v 1.3 2008/01/01 14:10:37 chris Exp $ */
|
||||
/* $NetBSD: kvm_arm.c,v 1.4 2008/01/15 13:57:42 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (C) 1996 Wolfgang Solfrank.
|
||||
|
@ -39,7 +39,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: kvm_arm.c,v 1.3 2008/01/01 14:10:37 chris Exp $");
|
||||
__RCSID("$NetBSD: kvm_arm.c,v 1.4 2008/01/15 13:57:42 ad Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
|
@ -105,7 +105,7 @@ _kvm_kvatop(kvm_t * kd, u_long va, u_long * pa)
|
|||
*/
|
||||
pde_pa += ((va >> 20) * sizeof(pd_entry_t));
|
||||
|
||||
if (pread(kd->pmfd, (void *) &pde, sizeof(pd_entry_t),
|
||||
if (_kvm_pread(kd, kd->pmfd, (void *) &pde, sizeof(pd_entry_t),
|
||||
_kvm_pa2off(kd, pde_pa)) != sizeof(pd_entry_t)) {
|
||||
_kvm_syserr(kd, 0, "could not read L1 entry");
|
||||
return (0);
|
||||
|
@ -133,7 +133,7 @@ _kvm_kvatop(kvm_t * kd, u_long va, u_long * pa)
|
|||
/*
|
||||
* locate the pte and load it
|
||||
*/
|
||||
if (pread(kd->pmfd, (void *) &pte, sizeof(pt_entry_t),
|
||||
if (_kvm_pread(kd, kd->pmfd, (void *) &pte, sizeof(pt_entry_t),
|
||||
_kvm_pa2off(kd, pte_pa)) != sizeof(pt_entry_t)) {
|
||||
_kvm_syserr(kd, 0, "could not read L2 entry");
|
||||
return (0);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kvm_hppa.c,v 1.2 2003/08/07 16:44:37 agc Exp $ */
|
||||
/* $NetBSD: kvm_hppa.c,v 1.3 2008/01/15 13:57:42 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1989, 1992, 1993
|
||||
|
@ -38,7 +38,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: kvm_hppa.c,v 1.2 2003/08/07 16:44:37 agc Exp $");
|
||||
__RCSID("$NetBSD: kvm_hppa.c,v 1.3 2008/01/15 13:57:42 ad Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
|
@ -126,7 +126,7 @@ _kvm_kvatop(kd, va, pa)
|
|||
* Find and read the page directory entry.
|
||||
*/
|
||||
pde_pa = cpu_kh->ptdpaddr + (pdei(va) * sizeof(pd_entry_t));
|
||||
if (pread(kd->pmfd, (void *)&pde, sizeof(pde),
|
||||
if (_kvm_pread(kd, kd->pmfd, (void *)&pde, sizeof(pde),
|
||||
_kvm_pa2off(kd, pde_pa)) != sizeof(pde)) {
|
||||
_kvm_syserr(kd, 0, "could not read PDE");
|
||||
goto lose;
|
||||
|
@ -140,7 +140,7 @@ _kvm_kvatop(kd, va, pa)
|
|||
goto lose;
|
||||
}
|
||||
pte_pa = (pde & PG_FRAME) + (ptei(va) * sizeof(pt_entry_t));
|
||||
if (pread(kd->pmfd, (void *) &pte, sizeof(pte),
|
||||
if (_kvm_pread(kd, kd->pmfd, (void *) &pte, sizeof(pte),
|
||||
_kvm_pa2off(kd, pte_pa)) != sizeof(pte)) {
|
||||
_kvm_syserr(kd, 0, "could not read PTE");
|
||||
goto lose;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kvm_i386.c,v 1.24 2008/01/05 06:54:12 jld Exp $ */
|
||||
/* $NetBSD: kvm_i386.c,v 1.25 2008/01/15 13:57:42 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1989, 1992, 1993
|
||||
|
@ -38,7 +38,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: kvm_i386.c,v 1.24 2008/01/05 06:54:12 jld Exp $");
|
||||
__RCSID("$NetBSD: kvm_i386.c,v 1.25 2008/01/15 13:57:42 ad Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
|
@ -118,7 +118,7 @@ _kvm_kvatop(kd, va, pa)
|
|||
* Find and read the page directory entry.
|
||||
*/
|
||||
pde_pa = cpu_kh->pdppaddr + (pl2_pi(va) * sizeof(pd_entry_t));
|
||||
if (pread(kd->pmfd, (void *)&pde, sizeof(pde),
|
||||
if (_kvm_pread(kd, kd->pmfd, (void *)&pde, sizeof(pde),
|
||||
_kvm_pa2off(kd, pde_pa)) != sizeof(pde)) {
|
||||
_kvm_syserr(kd, 0, "could not read PDE");
|
||||
goto lose;
|
||||
|
@ -140,7 +140,7 @@ _kvm_kvatop(kd, va, pa)
|
|||
return (int)(NBPD_L2 - page_off);
|
||||
}
|
||||
pte_pa = (pde & PG_FRAME) + (pl1_pi(va) * sizeof(pt_entry_t));
|
||||
if (pread(kd->pmfd, (void *) &pte, sizeof(pte),
|
||||
if (_kvm_pread(kd, kd->pmfd, (void *) &pte, sizeof(pte),
|
||||
_kvm_pa2off(kd, pte_pa)) != sizeof(pte)) {
|
||||
_kvm_syserr(kd, 0, "could not read PTE");
|
||||
goto lose;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kvm_m68k_cmn.c,v 1.12 2003/08/07 16:44:37 agc Exp $ */
|
||||
/* $NetBSD: kvm_m68k_cmn.c,v 1.13 2008/01/15 13:57:42 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1989, 1992, 1993
|
||||
|
@ -74,7 +74,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: kvm_m68k_cmn.c,v 1.12 2003/08/07 16:44:37 agc Exp $");
|
||||
__RCSID("$NetBSD: kvm_m68k_cmn.c,v 1.13 2008/01/15 13:57:42 ad Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
|
@ -226,7 +226,7 @@ vatop_030(kd, stpa, va, pa)
|
|||
* Fortunately it is 1-to-1 mapped so we don't have to.
|
||||
*/
|
||||
if (stpa == m->sysseg_pa) {
|
||||
if (pread(kd->pmfd, &ste, sizeof(ste),
|
||||
if (_kvm_pread(kd, kd->pmfd, &ste, sizeof(ste),
|
||||
_kvm_cmn_pa2off(kd, addr)) != sizeof(ste))
|
||||
goto invalid;
|
||||
} else if (KREAD(kd, addr, &ste))
|
||||
|
@ -241,8 +241,8 @@ vatop_030(kd, stpa, va, pa)
|
|||
/*
|
||||
* Address from STE is a physical address so don't use kvm_read.
|
||||
*/
|
||||
if (pread(kd->pmfd, &pte, sizeof(pte), _kvm_cmn_pa2off(kd, addr)) !=
|
||||
sizeof(pte))
|
||||
if (_kvm_pread(kd, kd->pmfd, &pte, sizeof(pte),
|
||||
_kvm_cmn_pa2off(kd, addr)) != sizeof(pte))
|
||||
goto invalid;
|
||||
addr = pte & m->pg_frame;
|
||||
if ((pte & m->pg_v) == 0) {
|
||||
|
@ -292,7 +292,7 @@ vatop_040(kd, stpa, va, pa)
|
|||
* Fortunately it is 1-to-1 mapped so we don't have to.
|
||||
*/
|
||||
if (stpa == m->sysseg_pa) {
|
||||
if (pread(kd->pmfd, &ste, sizeof(ste),
|
||||
if (_kvm_pread(kd, kd->pmfd, &ste, sizeof(ste),
|
||||
_kvm_cmn_pa2off(kd, addr)) != sizeof(ste))
|
||||
goto invalid;
|
||||
} else if (KREAD(kd, addr, &ste))
|
||||
|
@ -310,8 +310,8 @@ vatop_040(kd, stpa, va, pa)
|
|||
* Address from level 1 STE is a physical address,
|
||||
* so don't use kvm_read.
|
||||
*/
|
||||
if (pread(kd->pmfd, &ste, sizeof(ste), _kvm_cmn_pa2off(kd, addr)) !=
|
||||
sizeof(ste))
|
||||
if (_kvm_pread(kd, kd->pmfd, &ste, sizeof(ste),
|
||||
_kvm_cmn_pa2off(kd, addr)) != sizeof(ste))
|
||||
goto invalid;
|
||||
if ((ste & m->sg_v) == 0) {
|
||||
_kvm_err(kd, 0, "invalid level 2 descriptor (%x)",
|
||||
|
@ -325,8 +325,8 @@ vatop_040(kd, stpa, va, pa)
|
|||
/*
|
||||
* Address from STE is a physical address so don't use kvm_read.
|
||||
*/
|
||||
if (pread(kd->pmfd, &pte, sizeof(pte), _kvm_cmn_pa2off(kd, addr)) !=
|
||||
sizeof(pte))
|
||||
if (_kvm_pread(kd, kd->pmfd, &pte, sizeof(pte),
|
||||
_kvm_cmn_pa2off(kd, addr)) != sizeof(pte))
|
||||
goto invalid;
|
||||
addr = pte & m->pg_frame;
|
||||
if ((pte & m->pg_v) == 0) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kvm_mips.c,v 1.17 2003/05/16 10:24:55 wiz Exp $ */
|
||||
/* $NetBSD: kvm_mips.c,v 1.18 2008/01/15 13:57:42 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1995 Carnegie-Mellon University.
|
||||
|
@ -34,7 +34,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: kvm_mips.c,v 1.17 2003/05/16 10:24:55 wiz Exp $");
|
||||
__RCSID("$NetBSD: kvm_mips.c,v 1.18 2008/01/15 13:57:42 ad Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
/*
|
||||
|
@ -146,8 +146,8 @@ _kvm_kvatop(kd, va, pa)
|
|||
*/
|
||||
pte_pa = cpu_kh->sysmappa +
|
||||
(((va - MIPS_KSEG2_START) >> PGSHIFT) * sizeof(u_int));
|
||||
if (pread(kd->pmfd, &pte, sizeof(pte), _kvm_pa2off(kd, pte_pa)) !=
|
||||
sizeof(pte)) {
|
||||
if (_kvm_pread(kd, kd->pmfd, &pte, sizeof(pte),
|
||||
_kvm_pa2off(kd, pte_pa)) != sizeof(pte)) {
|
||||
_kvm_syserr(kd, 0, "could not read PTE");
|
||||
goto lose;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kvm_powerpc.c,v 1.7 2005/02/17 02:31:27 briggs Exp $ */
|
||||
/* $NetBSD: kvm_powerpc.c,v 1.8 2008/01/15 13:57:42 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2005 Wasabi Systems, Inc.
|
||||
|
@ -245,7 +245,7 @@ _kvm_match_sr(kd, va, pa, off)
|
|||
pteg_vaddr = ( htaborg & 0xfe000000) | ((hash & 0x3ff) << 6)
|
||||
| ((htaborg & 0x01ff0000) | (mhash << 16));
|
||||
|
||||
if (pread(kd->pmfd, (void *) &pteg, sizeof(pteg),
|
||||
if (_kvm_pread(kd, kd->pmfd, (void *) &pteg, sizeof(pteg),
|
||||
_kvm_pa2off(kd, pteg_vaddr)) != sizeof(pteg)) {
|
||||
_kvm_syserr(kd, 0, "could not read primary PTEG");
|
||||
return 0;
|
||||
|
@ -263,7 +263,7 @@ _kvm_match_sr(kd, va, pa, off)
|
|||
pteg_vaddr = ( htaborg & 0xfe000000) | ((hash & 0x3ff) << 6)
|
||||
| ((htaborg & 0x01ff0000) | (mhash << 16));
|
||||
|
||||
if (pread(kd->pmfd, (void *) &pteg, sizeof(pteg),
|
||||
if (_kvm_pread(kd, kd->pmfd, (void *) &pteg, sizeof(pteg),
|
||||
_kvm_pa2off(kd, pteg_vaddr)) != sizeof(pteg)) {
|
||||
_kvm_syserr(kd, 0, "could not read secondary PTEG");
|
||||
return 0;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kvm_private.h,v 1.15 2006/02/16 20:48:42 christos Exp $ */
|
||||
/* $NetBSD: kvm_private.h,v 1.16 2008/01/15 13:57:42 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -86,6 +86,10 @@ struct __kvm {
|
|||
*/
|
||||
struct pglist *vm_page_buckets;
|
||||
int vm_page_hash_mask;
|
||||
/* Buffer for raw disk I/O. */
|
||||
size_t fdalign;
|
||||
uint8_t *iobuf;
|
||||
size_t iobufsz;
|
||||
};
|
||||
|
||||
/* Levels of aliveness */
|
||||
|
@ -114,6 +118,7 @@ void *_kvm_realloc __P((kvm_t *kd, void *, size_t));
|
|||
void _kvm_syserr
|
||||
__P((kvm_t *kd, const char *program, const char *fmt, ...))
|
||||
__attribute__((__format__(__printf__, 3, 4)));
|
||||
ssize_t _kvm_pread(kvm_t *, int, void *, size_t, off_t);
|
||||
|
||||
#define KVM_ALLOC(kd, member, size) \
|
||||
do { \
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kvm_proc.c,v 1.75 2007/12/22 01:22:03 yamt Exp $ */
|
||||
/* $NetBSD: kvm_proc.c,v 1.76 2008/01/15 13:57:42 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
||||
|
@ -74,7 +74,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)kvm_proc.c 8.3 (Berkeley) 9/23/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: kvm_proc.c,v 1.75 2007/12/22 01:22:03 yamt Exp $");
|
||||
__RCSID("$NetBSD: kvm_proc.c,v 1.76 2008/01/15 13:57:42 ad Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
|
@ -272,12 +272,12 @@ _kvm_ureadm(kd, p, va, cnt)
|
|||
if (KREAD(kd, addr, &pg))
|
||||
return (NULL);
|
||||
|
||||
if (pread(kd->pmfd, kd->swapspc, (size_t)kd->nbpg,
|
||||
if (_kvm_pread(kd, kd->pmfd, kd->swapspc, (size_t)kd->nbpg,
|
||||
(off_t)pg.phys_addr) != kd->nbpg)
|
||||
return (NULL);
|
||||
} else {
|
||||
if (kd->swfd < 0 ||
|
||||
pread(kd->swfd, kd->swapspc, (size_t)kd->nbpg,
|
||||
_kvm_pread(kd, kd->swfd, kd->swapspc, (size_t)kd->nbpg,
|
||||
(off_t)(anon.an_swslot * kd->nbpg)) != kd->nbpg)
|
||||
return (NULL);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kvm_sparc.c,v 1.28 2003/08/07 16:44:39 agc Exp $ */
|
||||
/* $NetBSD: kvm_sparc.c,v 1.29 2008/01/15 13:57:42 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -38,7 +38,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)kvm_sparc.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: kvm_sparc.c,v 1.28 2003/08/07 16:44:39 agc Exp $");
|
||||
__RCSID("$NetBSD: kvm_sparc.c,v 1.29 2008/01/15 13:57:42 ad Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
|
@ -270,7 +270,7 @@ _kvm_kvatop4m(kd, va, pa)
|
|||
if (foff == (off_t)-1)
|
||||
return (0);
|
||||
|
||||
if (pread(kd->pmfd, &pte, sizeof(pte), foff) != sizeof(pte)) {
|
||||
if (_kvm_pread(kd, kd->pmfd, &pte, sizeof(pte), foff) != sizeof(pte)) {
|
||||
_kvm_syserr(kd, kd->program, "cannot read pte for %lx", va);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kvm_sparc64.c,v 1.11 2007/11/05 00:46:23 martin Exp $ */
|
||||
/* $NetBSD: kvm_sparc64.c,v 1.12 2008/01/15 13:57:42 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -38,7 +38,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)kvm_sparc.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: kvm_sparc64.c,v 1.11 2007/11/05 00:46:23 martin Exp $");
|
||||
__RCSID("$NetBSD: kvm_sparc64.c,v 1.12 2008/01/15 13:57:42 ad Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
|
@ -161,7 +161,7 @@ _kvm_kvatop(kd, va, pa)
|
|||
* Parse kernel page table.
|
||||
*/
|
||||
pseg = (uint64_t *)(u_long)cpup->segmapoffset;
|
||||
if (pread(kd->pmfd, &pdir, sizeof(pdir),
|
||||
if (_kvm_pread(kd, kd->pmfd, &pdir, sizeof(pdir),
|
||||
_kvm_pa2off(kd, (u_long)&pseg[va_to_seg(va)]))
|
||||
!= sizeof(pdir)) {
|
||||
_kvm_syserr(kd, 0, "could not read L1 PTE");
|
||||
|
@ -173,7 +173,7 @@ _kvm_kvatop(kd, va, pa)
|
|||
goto lose;
|
||||
}
|
||||
|
||||
if (pread(kd->pmfd, &ptbl, sizeof(ptbl),
|
||||
if (_kvm_pread(kd, kd->pmfd, &ptbl, sizeof(ptbl),
|
||||
_kvm_pa2off(kd, (u_long)&pdir[va_to_dir(va)]))
|
||||
!= sizeof(ptbl)) {
|
||||
_kvm_syserr(kd, 0, "could not read L2 PTE");
|
||||
|
@ -185,7 +185,7 @@ _kvm_kvatop(kd, va, pa)
|
|||
goto lose;
|
||||
}
|
||||
|
||||
if (pread(kd->pmfd, &data, sizeof(data),
|
||||
if (_kvm_pread(kd, kd->pmfd, &data, sizeof(data),
|
||||
_kvm_pa2off(kd, (u_long)&ptbl[va_to_pte(va)]))
|
||||
!= sizeof(data)) {
|
||||
_kvm_syserr(kd, 0, "could not read TTE");
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kvm_x86_64.c,v 1.5 2005/08/04 19:26:02 fvdl Exp $ */
|
||||
/* $NetBSD: kvm_x86_64.c,v 1.6 2008/01/15 13:57:42 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1989, 1992, 1993
|
||||
|
@ -38,7 +38,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: kvm_x86_64.c,v 1.5 2005/08/04 19:26:02 fvdl Exp $");
|
||||
__RCSID("$NetBSD: kvm_x86_64.c,v 1.6 2008/01/15 13:57:42 ad Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
|
@ -118,7 +118,7 @@ _kvm_kvatop(kd, va, pa)
|
|||
* Level 4.
|
||||
*/
|
||||
pde_pa = cpu_kh->ptdpaddr + (pl4_pi(va) * sizeof(pd_entry_t));
|
||||
if (pread(kd->pmfd, (void *)&pde, sizeof(pde),
|
||||
if (_kvm_pread(kd, kd->pmfd, (void *)&pde, sizeof(pde),
|
||||
_kvm_pa2off(kd, pde_pa)) != sizeof(pde)) {
|
||||
_kvm_syserr(kd, 0, "could not read PT level 4 entry");
|
||||
goto lose;
|
||||
|
@ -132,7 +132,7 @@ _kvm_kvatop(kd, va, pa)
|
|||
* Level 3.
|
||||
*/
|
||||
pde_pa = (pde & PG_FRAME) + (pl3_pi(va) * sizeof(pd_entry_t));
|
||||
if (pread(kd->pmfd, (void *)&pde, sizeof(pde),
|
||||
if (_kvm_pread(kd, kd->pmfd, (void *)&pde, sizeof(pde),
|
||||
_kvm_pa2off(kd, pde_pa)) != sizeof(pde)) {
|
||||
_kvm_syserr(kd, 0, "could not read PT level 3 entry");
|
||||
goto lose;
|
||||
|
@ -146,7 +146,7 @@ _kvm_kvatop(kd, va, pa)
|
|||
* Level 2.
|
||||
*/
|
||||
pde_pa = (pde & PG_FRAME) + (pl2_pi(va) * sizeof(pd_entry_t));
|
||||
if (pread(kd->pmfd, (void *)&pde, sizeof(pde),
|
||||
if (_kvm_pread(kd, kd->pmfd, (void *)&pde, sizeof(pde),
|
||||
_kvm_pa2off(kd, pde_pa)) != sizeof(pde)) {
|
||||
_kvm_syserr(kd, 0, "could not read PT level 2 entry");
|
||||
goto lose;
|
||||
|
@ -161,7 +161,7 @@ _kvm_kvatop(kd, va, pa)
|
|||
* Level 1.
|
||||
*/
|
||||
pte_pa = (pde & PG_FRAME) + (pl1_pi(va) * sizeof(pt_entry_t));
|
||||
if (pread(kd->pmfd, (void *) &pte, sizeof(pte),
|
||||
if (_kvm_pread(kd, kd->pmfd, (void *) &pte, sizeof(pte),
|
||||
_kvm_pa2off(kd, pte_pa)) != sizeof(pte)) {
|
||||
_kvm_syserr(kd, 0, "could not read PTE");
|
||||
goto lose;
|
||||
|
|
Loading…
Reference in New Issue