diff options
author | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1996-03-19 23:15:57 +0000 |
---|---|---|
committer | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1996-03-19 23:15:57 +0000 |
commit | e46701f3ba417eb809e480d2383217567bd8a0d3 (patch) | |
tree | 6418b00c595e11941ebeb3d312e0136cfb1621b8 /lib/libkvm/kvm_i386.c | |
parent | 169c29d1b708c51bbae3f546e0adfe0d433b5b7b (diff) |
From NetBSD: merge of 960317
Diffstat (limited to 'lib/libkvm/kvm_i386.c')
-rw-r--r-- | lib/libkvm/kvm_i386.c | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/lib/libkvm/kvm_i386.c b/lib/libkvm/kvm_i386.c index 3ded232157f..b79a6804bac 100644 --- a/lib/libkvm/kvm_i386.c +++ b/lib/libkvm/kvm_i386.c @@ -1,3 +1,5 @@ +/* $OpenBSD: kvm_i386.c,v 1.2 1996/03/19 23:15:23 niklas Exp $ */ + /*- * Copyright (c) 1989, 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -37,7 +39,7 @@ #if defined(LIBC_SCCS) && !defined(lint) /* from: static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93"; */ -static char *rcsid = "$Id: kvm_i386.c,v 1.1 1995/10/18 08:42:44 deraadt Exp $"; +static char *rcsid = "$OpenBSD: kvm_i386.c,v 1.2 1996/03/19 23:15:23 niklas Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -70,13 +72,9 @@ static char *rcsid = "$Id: kvm_i386.c,v 1.1 1995/10/18 08:42:44 deraadt Exp $"; #endif struct vmstate { - pd_entry_t **PTDpaddr; pd_entry_t *PTD; }; -#define KREAD(kd, addr, p)\ - (kvm_read(kd, addr, (char *)(p), sizeof(*(p))) != sizeof(*(p))) - void _kvm_freevtop(kd) kvm_t *kd; @@ -95,7 +93,7 @@ _kvm_initvtop(kd) { struct vmstate *vm; struct nlist nlist[2]; - pt_entry_t *tmpPTD; + u_long pa; vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm)); if (vm == 0) @@ -110,21 +108,35 @@ _kvm_initvtop(kd) return (-1); } - vm->PTDpaddr = 0; vm->PTD = 0; - if (KREAD(kd, (u_long)nlist[0].n_value - KERNBASE, &vm->PTDpaddr)) { - _kvm_err(kd, kd->program, "cannot read PTDpaddr"); - return (-1); + + if (lseek(kd->pmfd, (off_t)(nlist[0].n_value - KERNBASE), 0) == -1 && + errno != 0) { + _kvm_syserr(kd, kd->program, "kvm_lseek"); + goto invalid; + } + if (read(kd->pmfd, &pa, sizeof pa) != sizeof pa) { + _kvm_syserr(kd, kd->program, "kvm_read"); + goto invalid; } - tmpPTD = (pd_entry_t *)_kvm_malloc(kd, NBPG); - if ((kvm_read(kd, (u_long)vm->PTDpaddr, tmpPTD, NBPG)) != NBPG) { - free(tmpPTD); - _kvm_err(kd, kd->program, "cannot read PTD"); - return (-1); + vm->PTD = (pd_entry_t *)_kvm_malloc(kd, NBPG); + + if (lseek(kd->pmfd, (off_t)pa, 0) == -1 && errno != 0) { + _kvm_syserr(kd, kd->program, "kvm_lseek"); + goto invalid; + } + if (read(kd->pmfd, vm->PTD, NBPG) != NBPG) { + _kvm_syserr(kd, kd->program, "kvm_read"); + goto invalid; } - vm->PTD = tmpPTD; + return (0); + +invalid: + if (vm->PTD != 0) + free(vm->PTD); + return (-1); } /* @@ -165,7 +177,7 @@ _kvm_kvatop(kd, va, pa) /* XXX READ PHYSICAL XXX */ { if (lseek(kd->pmfd, (off_t)pte_pa, 0) == -1 && errno != 0) { - _kvm_syserr(kd, 0, "kvm_lseek"); + _kvm_syserr(kd, kd->program, "kvm_lseek"); goto invalid; } if (read(kd->pmfd, &pte, sizeof pte) != sizeof pte) { |