From: deraadt Date: Sun, 5 May 1996 14:56:34 +0000 (+0000) Subject: sync with 0430 X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=15f0ebb07559326692b6c475dd1bc53c9862ac8e;p=openbsd sync with 0430 --- diff --git a/lib/libkvm/Makefile b/lib/libkvm/Makefile index 2b6a84603aa..62995ba3614 100644 --- a/lib/libkvm/Makefile +++ b/lib/libkvm/Makefile @@ -1,5 +1,6 @@ +# $OpenBSD: Makefile,v 1.2 1996/05/05 14:56:34 deraadt Exp $ +# $NetBSD: Makefile,v 1.11 1996/03/18 22:33:07 thorpej Exp $ # from: @(#)Makefile 8.1 (Berkeley) 6/4/93 -# $Id: Makefile,v 1.1.1.1 1995/10/18 08:42:43 deraadt Exp $ LIB= kvm CFLAGS+=-DLIBC_SCCS @@ -15,11 +16,13 @@ SRCS= kvm_${MACHINE_ARCH}.c SRCS+= kvm.c kvm_file.c kvm_getloadavg.c kvm_proc.c -MAN= kvm.3 kvm_geterr.3 kvm_getfiles.3 kvm_getloadavg.3 kvm_getprocs.3 \ - kvm_nlist.3 kvm_open.3 kvm_read.3 +MAN= kvm.3 kvm_dump.3 kvm_geterr.3 kvm_getfiles.3 kvm_getloadavg.3 \ + kvm_getprocs.3 kvm_nlist.3 kvm_open.3 kvm_read.3 MLINKS+=kvm_getprocs.3 kvm_getargv.3 kvm_getprocs.3 kvm_getenvv.3 MLINKS+=kvm_open.3 kvm_openfiles.3 kvm_open.3 kvm_close.3 MLINKS+=kvm_read.3 kvm_write.3 +MLINKS+=kvm_dump.3 kvm_dump_mkheader.3 kvm_dump.3 kvm_dump_wrtheader.3 +MLINKS+=kvm_dump.3 kvm_dump_inval.3 .include diff --git a/lib/libkvm/kvm.3 b/lib/libkvm/kvm.3 index 0343d46907f..6a4ecd98a36 100644 --- a/lib/libkvm/kvm.3 +++ b/lib/libkvm/kvm.3 @@ -1,3 +1,6 @@ +.\" $OpenBSD: kvm.3,v 1.2 1996/05/05 14:56:38 deraadt Exp $ +.\" $NetBSD: kvm.3,v 1.2 1996/03/18 22:33:11 thorpej Exp $ +.\" .\" Copyright (c) 1992, 1993 .\" The Regents of the University of California. All rights reserved. .\" diff --git a/lib/libkvm/kvm.c b/lib/libkvm/kvm.c index 0126e54a178..0ff1e73c39c 100644 --- a/lib/libkvm/kvm.c +++ b/lib/libkvm/kvm.c @@ -1,4 +1,5 @@ -/* $OpenBSD: kvm.c,v 1.2 1996/03/19 23:15:22 niklas Exp $ */ +/* $OpenBSD: kvm.c,v 1.3 1996/05/05 14:56:42 deraadt Exp $ */ +/* $NetBSD: kvm.c,v 1.42 1996/03/18 22:33:13 thorpej Exp $ */ /*- * Copyright (c) 1989, 1992, 1993 @@ -38,7 +39,11 @@ */ #if defined(LIBC_SCCS) && !defined(lint) +#if 0 static char sccsid[] = "@(#)kvm.c 8.2 (Berkeley) 2/13/94"; +#else +static char *rcsid = "$OpenBSD: kvm.c,v 1.3 1996/05/05 14:56:42 deraadt Exp $"; +#endif #endif /* LIBC_SCCS and not lint */ #include @@ -62,7 +67,6 @@ static char sccsid[] = "@(#)kvm.c 8.2 (Berkeley) 2/13/94"; #include #include #include -#include #include #include #include @@ -70,6 +74,7 @@ static char sccsid[] = "@(#)kvm.c 8.2 (Berkeley) 2/13/94"; #include #include #include +#include #include "kvm_private.h" @@ -426,8 +431,8 @@ _kvm_pa2off(kd, pa) } int -kvm_dump_mkheader(kd_live, kd_dump, dump_off) -kvm_t *kd_live, *kd_dump; +kvm_dump_mkheader(kd, dump_off) +kvm_t *kd; off_t dump_off; { kcore_hdr_t kch; @@ -436,74 +441,70 @@ off_t dump_off; int hdr_size; hdr_size = 0; - if (kd_dump->kcore_hdr != NULL) { - _kvm_err(kd_dump, kd_dump->program, "already has a dump header"); + if (kd->kcore_hdr != NULL) { + _kvm_err(kd, kd->program, "already has a dump header"); return (-1); } - if (!ISALIVE(kd_live) || ISALIVE(kd_dump)) { - _kvm_err(kd_live, kd_live->program, "wrong arguments"); + if (ISALIVE(kd)) { + _kvm_err(kd, kd->program, "don't use on live kernel"); return (-1); } /* * Check for new format crash dump */ - if (Lseek(kd_dump, kd_dump->pmfd, dump_off, SEEK_SET) == -1) + if (Lseek(kd, kd->pmfd, dump_off, SEEK_SET) == -1) return (-1); - if (Read(kd_dump, kd_dump->pmfd, &kseg, sizeof(kseg)) != sizeof(kseg)) + if (Read(kd, kd->pmfd, &kseg, sizeof(kseg)) != sizeof(kseg)) return (-1); if ((CORE_GETMAGIC(kseg) == KCORE_MAGIC) && ((CORE_GETMID(kseg) == MID_MACHINE))) { hdr_size += ALIGN(sizeof(kcore_seg_t)); - if (Lseek(kd_dump, kd_dump->pmfd, dump_off+hdr_size, SEEK_SET) - == -1) + if (Lseek(kd, kd->pmfd, dump_off+hdr_size, SEEK_SET) == -1) return (-1); - if (Read(kd_dump, kd_dump->pmfd, &ckhdr, sizeof(ckhdr)) - != sizeof(ckhdr)) + if (Read(kd, kd->pmfd, &ckhdr, sizeof(ckhdr)) != sizeof(ckhdr)) return (-1); hdr_size += kseg.c_size; - if (Lseek(kd_dump, kd_dump->pmfd, dump_off+hdr_size, SEEK_SET) - == -1) + if (Lseek(kd, kd->pmfd, dump_off+hdr_size, SEEK_SET) == -1) return (-1); - kd_dump->cpu_hdr = (cpu_kcore_hdr_t *) - _kvm_malloc(kd_dump, sizeof(cpu_kcore_hdr_t)); - *kd_dump->cpu_hdr = ckhdr; + kd->cpu_hdr = (cpu_kcore_hdr_t *) + _kvm_malloc(kd, sizeof(cpu_kcore_hdr_t)); + *kd->cpu_hdr = ckhdr; } /* * Create a kcore_hdr. */ - kd_dump->kcore_hdr = (kcore_hdr_t *) - _kvm_malloc(kd_dump, sizeof(kcore_hdr_t)); - if (kd_dump->kcore_hdr == NULL) { - if (kd_dump->cpu_hdr != NULL) { - free((void *)kd_dump->cpu_hdr); - kd_dump->cpu_hdr = NULL; + kd->kcore_hdr = (kcore_hdr_t *) _kvm_malloc(kd, sizeof(kcore_hdr_t)); + if (kd->kcore_hdr == NULL) { + if (kd->cpu_hdr != NULL) { + free((void *)kd->cpu_hdr); + kd->cpu_hdr = NULL; } return (-1); } - kd_dump->kcore_hdr->c_hdrsize = ALIGN(sizeof(kcore_hdr_t)); - kd_dump->kcore_hdr->c_seghdrsize = ALIGN(sizeof(kcore_seg_t)); - kd_dump->kcore_hdr->c_nseg = 2; - CORE_SETMAGIC(*(kd_dump->kcore_hdr), KCORE_MAGIC, MID_MACHINE,0); + kd->kcore_hdr->c_hdrsize = ALIGN(sizeof(kcore_hdr_t)); + kd->kcore_hdr->c_seghdrsize = ALIGN(sizeof(kcore_seg_t)); + kd->kcore_hdr->c_nseg = 2; + CORE_SETMAGIC(*(kd->kcore_hdr), KCORE_MAGIC, MID_MACHINE,0); /* * If there is no cpu_hdr at this point, we probably have an * old format crash dump.....bail out */ - if (kd_dump->cpu_hdr == NULL) { - free((void *)kd_dump->kcore_hdr); - kd_dump->kcore_hdr = NULL; - _kvm_err(kd_dump, kd_dump->program, "invalid dump"); + if (kd->cpu_hdr == NULL) { + free((void *)kd->kcore_hdr); + kd->kcore_hdr = NULL; + _kvm_err(kd, kd->program, "invalid dump"); } - kd_dump->dump_off = dump_off + hdr_size; + kd->dump_off = dump_off + hdr_size; /* * Now that we have a valid header, enable translations. */ - _kvm_initvtop(kd_dump); + _kvm_initvtop(kd); return(hdr_size); } diff --git a/lib/libkvm/kvm_alpha.c b/lib/libkvm/kvm_alpha.c index 8845aff05d6..d07681a7f8d 100644 --- a/lib/libkvm/kvm_alpha.c +++ b/lib/libkvm/kvm_alpha.c @@ -1,3 +1,4 @@ +/* $OpenBSD: kvm_alpha.c,v 1.2 1996/05/05 14:56:50 deraadt Exp $ */ /* $NetBSD: kvm_alpha.c,v 1.2 1995/09/29 03:57:48 cgd Exp $ */ /* diff --git a/lib/libkvm/kvm_arm32.c b/lib/libkvm/kvm_arm32.c new file mode 100644 index 00000000000..37a7c19a174 --- /dev/null +++ b/lib/libkvm/kvm_arm32.c @@ -0,0 +1,206 @@ +/* $OpenBSD: kvm_arm32.c,v 1.1 1996/05/05 14:56:52 deraadt Exp $ */ +/* $NetBSD: kvm_arm32.c,v 1.2 1996/03/18 22:33:16 thorpej Exp $ */ + +/* + * Copyright (c) 1989, 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software developed by the Computer Systems + * Engineering group at Lawrence Berkeley Laboratory under DARPA contract + * BG 91-66 and contributed to Berkeley. + * + * 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 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. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93"; +#else +static char *rcsid = "$OpenBSD: kvm_arm32.c,v 1.1 1996/05/05 14:56:52 deraadt Exp $"; +#endif +#endif /* LIBC_SCCS and not lint */ + +/* + * arm32 machine dependent routines for kvm. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include "kvm_private.h" + +#include + +#ifndef btop +#define btop(x) (((unsigned)(x)) >> PGSHIFT) /* XXX */ +#define ptob(x) ((caddr_t)((x) << PGSHIFT)) /* XXX */ +#endif + +struct vmstate { + pd_entry_t **IdlePTD; + 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; +{ + _kvm_err(kd, 0, "unsupported"); + return; + if (kd->vmst->PTD != 0) + free(kd->vmst->PTD); + + if (kd->vmst != 0) + free(kd->vmst); +} + +int +_kvm_initvtop(kd) + kvm_t *kd; +{ + struct vmstate *vm; + struct nlist nlist[2]; + + _kvm_err(kd, 0, "unsupported"); + return (0); + vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm)); + if (vm == 0) + return (-1); + kd->vmst = vm; + + nlist[0].n_name = "_IdlePTD"; + nlist[1].n_name = 0; + + if (kvm_nlist(kd, nlist) != 0) { + _kvm_err(kd, kd->program, "bad namelist"); + return (-1); + } + vm->IdlePTD = 0; + vm->PTD = 0; + if (KREAD(kd, (u_long)nlist[0].n_value, &vm->IdlePTD)) { + _kvm_err(kd, kd->program, "cannot read IdlePTD"); + return (-1); + } + vm->PTD = (pd_entry_t *)_kvm_malloc(kd, NBPG); + if ((kvm_read(kd, (u_long)vm->IdlePTD, &vm->PTD, NBPG)) != NBPG) { + _kvm_err(kd, kd->program, "cannot read PTD"); + return (-1); + } + return (0); +} + +/* + * Translate a kernel virtual address to a physical address. + */ +int +_kvm_kvatop(kd, va, pa) + kvm_t *kd; + u_long va; + u_long *pa; +{ + struct vmstate *vm; + u_long offset; + + _kvm_err(kd, 0, "unsupported"); + return (0); + if (ISALIVE(kd)) { + _kvm_err(kd, 0, "vatop called in live kernel!"); + return(0); + } + vm = kd->vmst; + offset = va & PGOFSET; + +invalid: + _kvm_err(kd, 0, "invalid address (%x)", va); + return (0); +} + +/* + * Translate a user virtual address to a physical address. + */ +int +_kvm_uvatop(kd, p, va, pa) + kvm_t *kd; + const struct proc *p; + u_long va; + u_long *pa; +{ + struct vmspace vms; + pd_entry_t pde, *pdeloc; + pt_entry_t pte, *pteloc; + u_long kva, offset; + + _kvm_err(kd, 0, "unsupported"); + return (0); + + if (va >= KERNBASE) + goto invalid; + + /* XXX - should be passed a `kinfo_proc *' here */ + if (kvm_read(kd, (u_long)p->p_vmspace, (char *)&vms, sizeof(vms)) != + sizeof(vms)) + goto invalid; + + pdeloc = vms.vm_pmap.pm_pdir + (va >> PDSHIFT); + if (kvm_read(kd, (u_long)pdeloc, (char *)&pde, sizeof(pde)) != + sizeof(pde)) + goto invalid; + if (pde == 0) + goto invalid; + + pteloc = (pt_entry_t *)(pde & PG_FRAME) + btop(va & PT_MASK); + if (lseek(kd->pmfd, (off_t)(u_long)pteloc, 0) != (off_t)(u_long)pteloc) + goto invalid; + if (read(kd->pmfd, (char *)&pte, sizeof(pte)) != sizeof(pte)) + goto invalid; + if (pte == 0) + goto invalid; + + offset = va & PGOFSET; + *pa = (pte & PG_FRAME) + offset; + return (NBPG - offset); + +invalid: + _kvm_err(kd, 0, "invalid address (%x)", va); + return (0); +} diff --git a/lib/libkvm/kvm_dump.3 b/lib/libkvm/kvm_dump.3 new file mode 100644 index 00000000000..9012146b08a --- /dev/null +++ b/lib/libkvm/kvm_dump.3 @@ -0,0 +1,104 @@ +.\" $OpenBSD: kvm_dump.3,v 1.1 1996/05/05 14:56:55 deraadt Exp $ +.\" $NetBSD: kvm_dump.3,v 1.1 1996/03/18 21:11:12 leo Exp $ +.\" +.\" Copyright (c) 1996 Leo Weppelman +.\" 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 Leo Weppelman. +.\" 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. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. +.\" +.\" +.Dd March 17, 1996 +.Dt KVM_DUMP 3 +.Os +.Sh NAME +.Nm kvm_dump_mkheader , +.Nm kvm_dump_wrtheader , +.Nm kvm_dump_inval +.Nd crash-dump support functions +.Sh SYNOPSIS +.Fd #include +.br +.Ft int +.Fn kvm_dump_mkheader "kvm_t *kd" "off_t dump_off" +.Ft int +.Fn kvm_dump_wrtheader "kvm_t *kd" "FILE *fp" "int dumpsize" +.Ft int +.Fn kvm_dump_inval "kvm_t *kd" +.Sh DESCRIPTION +First note that the functions described here were designed to be used by +.Xr savecore 8 . +.Pp +The function +.Fn kvm_dump_mkheader +checks if the physical memory file associated with +.Fa kd +contains a valid crash-dump header as generated by a dumping kernel. When a +valid header is found, +.Fn kvm_dump_mkheader +initializes the internal kvm data structures as if a crash-dump generated by +the +.Xr savecore 8 +program was opened. This has the intentional side effect of enabling the +address translation machinery. +.Pp +A call to +.Fn kvm_dump_mkheader +will most likely be followed by a call to +.Fn kvm_dump_wrtheader . +This function takes care of generating the generic header, the CORE_CPU +section and the section header of the CORE_DATA section. The data is written +to the file pointed at by +.Fa fp . +The +.Fa dumpsize +argument is only used to properly the set the segment size of the CORE_DATA +section. Note that this function assumes that +.Fa fp +is positioned at file location 0. This function will not seek and therefore +allows +.Fa fp +to be a file pointer obtained by +.Fn zopen . +.Pp +The +.Fn kvm_dump_inval +function clears the magic number in the physical memory file associated with +.Fa kd . +The address translations must be enabled for this to work (thus assuming +that +.Fn kvm_dum_mkheader +was called earlier in the sequence). +.Sh RETURN VALUES +All functions return 0 on success, -1 on failure. In the case of failure, +.Xr kvm_geterr 3 +can be used to retrieve the cause of the error. +.Sh HISTORY +These functions first appeared in NetBSD 1.1A. +.Sh BUGS +There probably are... +.Sh SEE ALSO +.Xr kvm 3 diff --git a/lib/libkvm/kvm_file.c b/lib/libkvm/kvm_file.c index bd6737430f8..edc8a47c42b 100644 --- a/lib/libkvm/kvm_file.c +++ b/lib/libkvm/kvm_file.c @@ -1,3 +1,6 @@ +/* $OpenBSD: kvm_file.c,v 1.2 1996/05/05 14:56:58 deraadt Exp $ */ +/* $NetBSD: kvm_file.c,v 1.5 1996/03/18 22:33:18 thorpej Exp $ */ + /*- * Copyright (c) 1989, 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -32,7 +35,11 @@ */ #if defined(LIBC_SCCS) && !defined(lint) +#if 0 static char sccsid[] = "@(#)kvm_file.c 8.1 (Berkeley) 6/4/93"; +#else +static char *rcsid = "$OpenBSD: kvm_file.c,v 1.2 1996/05/05 14:56:58 deraadt Exp $"; +#endif #endif /* LIBC_SCCS and not lint */ /* diff --git a/lib/libkvm/kvm_geterr.3 b/lib/libkvm/kvm_geterr.3 index b8eefa7aa74..1d1899dc02f 100644 --- a/lib/libkvm/kvm_geterr.3 +++ b/lib/libkvm/kvm_geterr.3 @@ -1,3 +1,6 @@ +.\" $OpenBSD: kvm_geterr.3,v 1.2 1996/05/05 14:57:02 deraadt Exp $ +.\" $NetBSD: kvm_geterr.3,v 1.2 1996/03/18 22:33:20 thorpej Exp $ +.\" .\" Copyright (c) 1992, 1993 .\" The Regents of the University of California. All rights reserved. .\" diff --git a/lib/libkvm/kvm_getfiles.3 b/lib/libkvm/kvm_getfiles.3 index 3c3ba6b2848..92edc93d4c6 100644 --- a/lib/libkvm/kvm_getfiles.3 +++ b/lib/libkvm/kvm_getfiles.3 @@ -1,3 +1,6 @@ +.\" $OpenBSD: kvm_getfiles.3,v 1.2 1996/05/05 14:57:06 deraadt Exp $ +.\" $NetBSD: kvm_getfiles.3,v 1.3 1996/03/18 22:33:23 thorpej Exp $ +.\" .\" Copyright (c) 1992, 1993 .\" The Regents of the University of California. All rights reserved. .\" diff --git a/lib/libkvm/kvm_getloadavg.3 b/lib/libkvm/kvm_getloadavg.3 index 80dc3b1d4c2..f44b8bb2abf 100644 --- a/lib/libkvm/kvm_getloadavg.3 +++ b/lib/libkvm/kvm_getloadavg.3 @@ -1,3 +1,6 @@ +.\" $OpenBSD: kvm_getloadavg.3,v 1.2 1996/05/05 14:57:09 deraadt Exp $ +.\" $NetBSD: kvm_getloadavg.3,v 1.2 1996/03/18 22:33:26 thorpej Exp $ +.\" .\" Copyright (c) 1992, 1993 .\" The Regents of the University of California. All rights reserved. .\" diff --git a/lib/libkvm/kvm_getloadavg.c b/lib/libkvm/kvm_getloadavg.c index e13ee1d46e8..8474038f1d0 100644 --- a/lib/libkvm/kvm_getloadavg.c +++ b/lib/libkvm/kvm_getloadavg.c @@ -1,3 +1,6 @@ +/* $OpenBSD: kvm_getloadavg.c,v 1.2 1996/05/05 14:57:12 deraadt Exp $ */ +/* $NetBSD: kvm_getloadavg.c,v 1.2 1996/03/18 22:33:31 thorpej Exp $ */ + /*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. @@ -32,7 +35,11 @@ */ #if defined(LIBC_SCCS) && !defined(lint) +#if 0 static char sccsid[] = "@(#)kvm_getloadavg.c 8.1 (Berkeley) 6/4/93"; +#else +static char *rcsid = "$OpenBSD: kvm_getloadavg.c,v 1.2 1996/05/05 14:57:12 deraadt Exp $"; +#endif #endif /* LIBC_SCCS and not lint */ #include diff --git a/lib/libkvm/kvm_getprocs.3 b/lib/libkvm/kvm_getprocs.3 index a5eacb9a34a..16d4efa5bd6 100644 --- a/lib/libkvm/kvm_getprocs.3 +++ b/lib/libkvm/kvm_getprocs.3 @@ -1,3 +1,6 @@ +.\" $OpenBSD: kvm_getprocs.3,v 1.2 1996/05/05 14:57:17 deraadt Exp $ +.\" $NetBSD: kvm_getprocs.3,v 1.2 1996/03/18 22:33:35 thorpej Exp $ +.\" .\" Copyright (c) 1992, 1993 .\" The Regents of the University of California. All rights reserved. .\" diff --git a/lib/libkvm/kvm_i386.c b/lib/libkvm/kvm_i386.c index b79a6804bac..7d1c30e3901 100644 --- a/lib/libkvm/kvm_i386.c +++ b/lib/libkvm/kvm_i386.c @@ -1,4 +1,5 @@ -/* $OpenBSD: kvm_i386.c,v 1.2 1996/03/19 23:15:23 niklas Exp $ */ +/* $OpenBSD: kvm_i386.c,v 1.3 1996/05/05 14:57:20 deraadt Exp $ */ +/* $NetBSD: kvm_i386.c,v 1.9 1996/03/18 22:33:38 thorpej Exp $ */ /*- * Copyright (c) 1989, 1992, 1993 @@ -38,8 +39,11 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -/* from: static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93"; */ -static char *rcsid = "$OpenBSD: kvm_i386.c,v 1.2 1996/03/19 23:15:23 niklas Exp $"; +#if 0 +static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93"; +#else +static char *rcsid = "$OpenBSD: kvm_i386.c,v 1.3 1996/05/05 14:57:20 deraadt Exp $"; +#endif #endif /* LIBC_SCCS and not lint */ /* diff --git a/lib/libkvm/kvm_m68k.c b/lib/libkvm/kvm_m68k.c index dbea9864055..d6e33fe11c3 100644 --- a/lib/libkvm/kvm_m68k.c +++ b/lib/libkvm/kvm_m68k.c @@ -1,4 +1,5 @@ -/* $OpenBSD: kvm_m68k.c,v 1.2 1996/03/19 23:15:24 niklas Exp $ */ +/* $OpenBSD: kvm_m68k.c,v 1.3 1996/05/05 14:57:23 deraadt Exp $ */ +/* $NetBSD: kvm_m68k.c,v 1.7 1996/03/18 22:33:41 thorpej Exp $ */ /*- * Copyright (c) 1989, 1992, 1993 @@ -38,8 +39,11 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -/* from: static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93"; */ -static char *rcsid = "$OpenBSD: kvm_m68k.c,v 1.2 1996/03/19 23:15:24 niklas Exp $"; +#if 0 +static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93"; +#else +static char *rcsid = "$OpenBSD: kvm_m68k.c,v 1.3 1996/05/05 14:57:23 deraadt Exp $"; +#endif #endif /* LIBC_SCCS and not lint */ /* diff --git a/lib/libkvm/kvm_mips.c b/lib/libkvm/kvm_mips.c index db768bf5a60..12dd72b4952 100644 --- a/lib/libkvm/kvm_mips.c +++ b/lib/libkvm/kvm_mips.c @@ -1,3 +1,6 @@ +/* $OpenBSD: kvm_mips.c,v 1.2 1996/05/05 14:57:26 deraadt Exp $ */ +/* $NetBSD: kvm_mips.c,v 1.3 1996/03/18 22:33:44 thorpej Exp $ */ + /*- * Copyright (c) 1989, 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -36,8 +39,13 @@ */ #if defined(LIBC_SCCS) && !defined(lint) +#if 0 static char sccsid[] = "@(#)kvm_mips.c 8.1 (Berkeley) 6/4/93"; +#else +static char *rcsid = "$OpenBSD: kvm_mips.c,v 1.2 1996/05/05 14:57:26 deraadt Exp $"; +#endif #endif /* LIBC_SCCS and not lint */ + /* * MIPS machine dependent routines for kvm. Hopefully, the forthcoming * vm code will one day obsolete this module. diff --git a/lib/libkvm/kvm_nlist.3 b/lib/libkvm/kvm_nlist.3 index f3b2fdc6fdf..8ef654e5b08 100644 --- a/lib/libkvm/kvm_nlist.3 +++ b/lib/libkvm/kvm_nlist.3 @@ -1,3 +1,6 @@ +.\" $OpenBSD: kvm_nlist.3,v 1.2 1996/05/05 14:57:30 deraadt Exp $ +.\" $NetBSD: kvm_nlist.3,v 1.3 1996/03/18 22:33:48 thorpej Exp $ +.\" .\" Copyright (c) 1992, 1993 .\" The Regents of the University of California. All rights reserved. .\" diff --git a/lib/libkvm/kvm_ns32k.c b/lib/libkvm/kvm_ns32k.c index 83f02e07b22..5f363b48677 100644 --- a/lib/libkvm/kvm_ns32k.c +++ b/lib/libkvm/kvm_ns32k.c @@ -1,3 +1,6 @@ +/* $OpenBSD: kvm_ns32k.c,v 1.2 1996/05/05 14:57:32 deraadt Exp $ */ +/* $NetBSD: kvm_ns32k.c,v 1.4 1996/03/18 22:33:50 thorpej Exp $ */ + /*- * Copyright (c) 1989, 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -36,19 +39,23 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -/* from: static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93"; */ -static char *rcsid = "$Id: kvm_ns32k.c,v 1.1.1.1 1995/10/18 08:42:44 deraadt Exp $"; +#if 0 +static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93"; +#else +static char *rcsid = "$OpenBSD: kvm_ns32k.c,v 1.2 1996/05/05 14:57:32 deraadt Exp $"; +#endif #endif /* LIBC_SCCS and not lint */ /* - * pc532 machine dependent routines for kvm. Hopefully, the forthcoming - * vm code will one day obsolete this module. (copy from kvm_i386.c) + * ns32k machine dependent routines for kvm. Hopefully, the forthcoming + * vm code will one day obsolete this module. */ #include #include #include #include +#include #include #include #include @@ -61,8 +68,7 @@ static char *rcsid = "$Id: kvm_ns32k.c,v 1.1.1.1 1995/10/18 08:42:44 deraadt Exp #include "kvm_private.h" -#include -#define PDSHIFT 22 +#include #ifndef btop #define btop(x) (((unsigned)(x)) >> PGSHIFT) /* XXX */ @@ -70,8 +76,8 @@ static char *rcsid = "$Id: kvm_ns32k.c,v 1.1.1.1 1995/10/18 08:42:44 deraadt Exp #endif struct vmstate { - struct pde **IdlePTD; - struct pde *PTD; + pd_entry_t **PTDpaddr; + pd_entry_t *PTD; }; #define KREAD(kd, addr, p)\ @@ -81,11 +87,12 @@ void _kvm_freevtop(kd) kvm_t *kd; { - if (kd->vmst->PTD != 0) - free(kd->vmst->PTD); + if (kd->vmst != 0) { + if (kd->vmst->PTD != 0) + free(kd->vmst->PTD); - if (kd->vmst != 0) free(kd->vmst); + } } int @@ -94,30 +101,35 @@ _kvm_initvtop(kd) { struct vmstate *vm; struct nlist nlist[2]; + pt_entry_t *tmpPTD; vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm)); if (vm == 0) return (-1); kd->vmst = vm; - nlist[0].n_name = "_IdlePTD"; + nlist[0].n_name = "_PTDpaddr"; nlist[1].n_name = 0; if (kvm_nlist(kd, nlist) != 0) { _kvm_err(kd, kd->program, "bad namelist"); return (-1); } - vm->IdlePTD = 0; + + vm->PTDpaddr = 0; vm->PTD = 0; - if (KREAD(kd, (u_long)nlist[0].n_value, &vm->IdlePTD)) { - _kvm_err(kd, kd->program, "cannot read IdlePTD"); + if (KREAD(kd, (u_long)nlist[0].n_value - KERNBASE, &vm->PTDpaddr)) { + _kvm_err(kd, kd->program, "cannot read PTDpaddr"); return (-1); } - vm->PTD = (struct pde *)_kvm_malloc(kd, NBPG); - if ((kvm_read(kd, (u_long)vm->IdlePTD, &vm->PTD, NBPG)) != NBPG) { + + 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 = tmpPTD; return (0); } @@ -132,14 +144,45 @@ _kvm_kvatop(kd, va, pa) { struct vmstate *vm; u_long offset; + u_long pte_pa; + pt_entry_t pte; if (ISALIVE(kd)) { _kvm_err(kd, 0, "vatop called in live kernel!"); return(0); } + vm = kd->vmst; offset = va & PGOFSET; + /* + * If we are initializing (kernel page table descriptor pointer + * not yet set) * then return pa == va to avoid infinite recursion. + */ + if (vm->PTD == 0) { + *pa = va; + return (NBPG - offset); + } + if ((vm->PTD[pdei(va)] & PG_V) == 0) + goto invalid; + + pte_pa = (vm->PTD[pdei(va)] & PG_FRAME) + + (ptei(va) * sizeof(pt_entry_t)); + /* XXX READ PHYSICAL XXX */ + { + if (lseek(kd->pmfd, (off_t)pte_pa, 0) == -1 && errno != 0) { + _kvm_syserr(kd, 0, "kvm_lseek"); + goto invalid; + } + if (read(kd->pmfd, &pte, sizeof pte) != sizeof pte) { + _kvm_syserr(kd, kd->program, "kvm_read"); + goto invalid; + } + } + + *pa = (pte & PG_FRAME) + offset; + return (NBPG - offset); + invalid: _kvm_err(kd, 0, "invalid address (%x)", va); return (0); diff --git a/lib/libkvm/kvm_open.3 b/lib/libkvm/kvm_open.3 index dd6895b417d..96e063c622a 100644 --- a/lib/libkvm/kvm_open.3 +++ b/lib/libkvm/kvm_open.3 @@ -1,3 +1,6 @@ +.\" $OpenBSD: kvm_open.3,v 1.2 1996/05/05 14:57:35 deraadt Exp $ +.\" $NetBSD: kvm_open.3,v 1.2 1996/03/18 22:33:52 thorpej Exp $ +.\" .\" Copyright (c) 1992, 1993 .\" The Regents of the University of California. All rights reserved. .\" diff --git a/lib/libkvm/kvm_private.h b/lib/libkvm/kvm_private.h index d1b2583f559..cdea44877e5 100644 --- a/lib/libkvm/kvm_private.h +++ b/lib/libkvm/kvm_private.h @@ -1,4 +1,5 @@ -/* $OpenBSD: kvm_private.h,v 1.2 1996/03/19 23:15:25 niklas Exp $ */ +/* $OpenBSD: kvm_private.h,v 1.3 1996/05/05 14:57:38 deraadt Exp $ */ +/* $NetBSD: kvm_private.h,v 1.6 1996/03/18 22:33:54 thorpej Exp $ */ /*- * Copyright (c) 1992, 1993 diff --git a/lib/libkvm/kvm_proc.c b/lib/libkvm/kvm_proc.c index 2e92a482980..1aede825e90 100644 --- a/lib/libkvm/kvm_proc.c +++ b/lib/libkvm/kvm_proc.c @@ -1,3 +1,6 @@ +/* $OpenBSD: kvm_proc.c,v 1.2 1996/05/05 14:57:42 deraadt Exp $ */ +/* $NetBSD: kvm_proc.c,v 1.16 1996/03/18 22:33:57 thorpej Exp $ */ + /*- * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved. * Copyright (c) 1989, 1992, 1993 @@ -37,7 +40,11 @@ */ #if defined(LIBC_SCCS) && !defined(lint) +#if 0 static char sccsid[] = "@(#)kvm_proc.c 8.3 (Berkeley) 9/23/93"; +#else +static char *rcsid = "$OpenBSD: kvm_proc.c,v 1.2 1996/05/05 14:57:42 deraadt Exp $"; +#endif #endif /* LIBC_SCCS and not lint */ /* diff --git a/lib/libkvm/kvm_read.3 b/lib/libkvm/kvm_read.3 index b5609599f6a..e87f4854f1c 100644 --- a/lib/libkvm/kvm_read.3 +++ b/lib/libkvm/kvm_read.3 @@ -1,3 +1,6 @@ +.\" $OpenBSD: kvm_read.3,v 1.2 1996/05/05 14:57:47 deraadt Exp $ +.\" $NetBSD: kvm_read.3,v 1.2 1996/03/18 22:34:01 thorpej Exp $ +.\" .\" Copyright (c) 1992, 1993 .\" The Regents of the University of California. All rights reserved. .\" diff --git a/lib/libkvm/kvm_sparc.c b/lib/libkvm/kvm_sparc.c index c89759e04f4..d316b37d7ca 100644 --- a/lib/libkvm/kvm_sparc.c +++ b/lib/libkvm/kvm_sparc.c @@ -1,3 +1,6 @@ +/* $OpenBSD: kvm_sparc.c,v 1.2 1996/05/05 14:57:50 deraadt Exp $ */ +/* $NetBSD: kvm_sparc.c,v 1.9 1996/04/01 19:23:03 cgd Exp $ */ + /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -36,7 +39,11 @@ */ #if defined(LIBC_SCCS) && !defined(lint) +#if 0 static char sccsid[] = "@(#)kvm_sparc.c 8.1 (Berkeley) 6/4/93"; +#else +static char *rcsid = "$OpenBSD: kvm_sparc.c,v 1.2 1996/05/05 14:57:50 deraadt Exp $"; +#endif #endif /* LIBC_SCCS and not lint */ /* @@ -66,7 +73,7 @@ static char sccsid[] = "@(#)kvm_sparc.c 8.1 (Berkeley) 6/4/93"; #define MA_SIZE 32 /* XXX */ struct vmstate { struct { - int x_seginval; + int x_seginval; /* [sun4/sun4c] only */ int x_npmemarr; struct memarr x_pmemarr[MA_SIZE]; struct segmap x_segmap_store[NKREG*NSEGRG]; @@ -75,7 +82,7 @@ struct vmstate { #define npmemarr x.x_npmemarr #define pmemarr x.x_pmemarr #define segmap_store x.x_segmap_store - int *pte; + int *pte; /* [sun4/sun4c] only */ }; #define NPMEG(vm) ((vm)->seginval+1) @@ -83,26 +90,62 @@ static int cputyp = -1; static int pgshift, nptesg; -#define VA_VPG(va) (cputyp==CPU_SUN4C ? VA_SUN4C_VPG(va) : VA_SUN4_VPG(va)) +#define VA_VPG(va) ((cputyp == CPU_SUN4C || cputyp == CPU_SUN4M) \ + ? VA_SUN4C_VPG(va) \ + : VA_SUN4_VPG(va)) + +static int _kvm_mustinit __P((kvm_t *)); + +#if 0 +static int +getcputyp() +{ + int mib[2]; + size_t size; + + mib[0] = CTL_HW; + mib[1] = HW_CLASS; + size = sizeof cputyp; + if (sysctl(mib, 2, &cputyp, &size, NULL, 0) == -1) + return (-1); +} +#endif -static void +static int _kvm_mustinit(kd) kvm_t *kd; { +static struct nlist nlist[2] = { +# define X_CPUTYP 0 + { "_cputyp" }, + { NULL }, + }; + off_t foff; + if (cputyp != -1) - return; + return 0; + for (pgshift = 12; (1 << pgshift) != kd->nbpg; pgshift++) ; nptesg = NBPSG / kd->nbpg; -#if 1 - if (cputyp == -1) { - if (kd->nbpg == 8192) - cputyp = CPU_SUN4; - else - cputyp = CPU_SUN4C; + if (kvm_nlist(kd, nlist) != 0) { + _kvm_err(kd, kd->program, "cannot find `cputyp' symbol"); + return (-1); } -#endif + /* Assume kernel mappings are all within first memory bank. */ + foff = nlist[X_CPUTYP].n_value - KERNBASE; + if (lseek(kd->pmfd, foff, 0) == -1 || + read(kd->pmfd, &cputyp, sizeof(cputyp)) < 0) { + _kvm_err(kd, kd->program, "cannot read `cputyp"); + return (-1); + } + if (cputyp != CPU_SUN4 && + cputyp != CPU_SUN4C && + cputyp != CPU_SUN4M) + return (-1); + + return (0); } void @@ -117,6 +160,26 @@ _kvm_freevtop(kd) } } +/* + * Translate a kernel virtual address to a physical address using the + * mapping information in kd->vm. Returns the result in pa, and returns + * the number of bytes that are contiguously available from this + * physical address. This routine is used only for crashdumps. + */ +int +_kvm_kvatop(kd, va, pa) + kvm_t *kd; + u_long va; + u_long *pa; +{ + if (_kvm_mustinit(kd) != 0) + return (-1); + + return ((cputyp == CPU_SUN4M) + ? _kvm_kvatop4m(kd, va, pa) + : _kvm_kvatop44c(kd, va, pa)); +} + /* * Prepare for translation of kernel virtual addresses into offsets * into crash dump files. We use the MMU specific goop written at the @@ -127,13 +190,30 @@ int _kvm_initvtop(kd) kvm_t *kd; { - register int i; - register int off; + if (_kvm_mustinit(kd) != 0) + return (-1); + + return ((cputyp == CPU_SUN4M) + ? _kvm_initvtop4m(kd) + : _kvm_initvtop44c(kd)); +} + +#define VA_OFF(va) (va & (kd->nbpg - 1)) + + +/* + * We use the MMU specific goop written at the end of crash dump + * by pmap_dumpmmu(). + * (note: sun4 3-level MMU not yet supported) + */ +int +_kvm_initvtop44c(kd) + kvm_t *kd; +{ register struct vmstate *vm; + register int i; + off_t foff; struct stat st; - struct nlist nlist[5]; - - _kvm_mustinit(kd); if ((vm = kd->vmst) == 0) { kd->vmst = vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm)); @@ -147,9 +227,9 @@ _kvm_initvtop(kd) * Read segment table. */ - off = st.st_size - roundup(sizeof(vm->x), kd->nbpg); + foff = st.st_size - roundup(sizeof(vm->x), kd->nbpg); errno = 0; - if (lseek(kd->pmfd, (off_t)off, 0) == -1 && errno != 0 || + if (lseek(kd->pmfd, (off_t)foff, 0) == -1 && errno != 0 || read(kd->pmfd, (char *)&vm->x, sizeof(vm->x)) < 0) { _kvm_err(kd, kd->program, "cannot read segment map"); return (-1); @@ -165,11 +245,11 @@ _kvm_initvtop(kd) /* * Read PMEGs. */ - off = st.st_size - roundup(sizeof(vm->x), kd->nbpg) - + foff = st.st_size - roundup(sizeof(vm->x), kd->nbpg) - roundup(NPMEG(vm) * nptesg * sizeof(int), kd->nbpg); errno = 0; - if (lseek(kd->pmfd, (off_t)off, 0) == -1 && errno != 0 || + if (lseek(kd->pmfd, foff, 0) == -1 && errno != 0 || read(kd->pmfd, (char *)vm->pte, NPMEG(vm) * nptesg * sizeof(int)) < 0) { _kvm_err(kd, kd->program, "cannot read PMEG table"); return (-1); @@ -178,16 +258,8 @@ _kvm_initvtop(kd) return (0); } -#define VA_OFF(va) (va & (kd->nbpg - 1)) - -/* - * Translate a kernel virtual address to a physical address using the - * mapping information in kd->vm. Returns the result in pa, and returns - * the number of bytes that are contiguously available from this - * physical address. This routine is used only for crashdumps. - */ int -_kvm_kvatop(kd, va, pa) +_kvm_kvatop44c(kd, va, pa) kvm_t *kd; u_long va; u_long *pa; @@ -198,8 +270,6 @@ _kvm_kvatop(kd, va, pa) struct segmap *sp; struct memarr *mp; - _kvm_mustinit(kd); - if (va < KERNBASE) goto err; @@ -233,17 +303,115 @@ err: return (0); } -#if 0 -static int -getcputyp() +/* + * Prepare for translation of kernel virtual addresses into offsets + * into crash dump files. Since the sun4m pagetables are all in memory, + * we use nlist to bootstrap the translation tables. This assumes that + * the kernel mappings all reside in the first physical memory bank. + */ +int +_kvm_initvtop4m(kd) + kvm_t *kd; { - int mib[2]; - size_t size; + register int i; + register off_t foff; + register struct vmstate *vm; + struct stat st; +static struct nlist nlist[4] = { +# define X_KSEGSTORE 0 + { "_kernel_segmap_store" }, +# define X_PMEMARR 1 + { "_pmemarr" }, +# define X_NPMEMARR 2 + { "_npmemarr" }, + { NULL }, + }; - mib[0] = CTL_HW; - mib[1] = HW_CLASS; - size = sizeof cputyp; - if (sysctl(mib, 2, &cputyp, &size, NULL, 0) == -1) + if ((vm = kd->vmst) == 0) { + kd->vmst = vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm)); + if (vm == 0) + return (-1); + } + + if (kvm_nlist(kd, nlist) != 0) { + _kvm_err(kd, kd->program, "cannot read symbols"); return (-1); + } + + /* Assume kernel mappings are all within first memory bank. */ + foff = nlist[X_KSEGSTORE].n_value - KERNBASE; + if (lseek(kd->pmfd, foff, 0) == -1 || + read(kd->pmfd, vm->segmap_store, sizeof(vm->segmap_store)) < 0) { + _kvm_err(kd, kd->program, "cannot read segment map"); + return (-1); + } + + foff = nlist[X_PMEMARR].n_value - KERNBASE; + if (lseek(kd->pmfd, foff, 0) == -1 || + read(kd->pmfd, vm->pmemarr, sizeof(vm->pmemarr)) < 0) { + _kvm_err(kd, kd->program, "cannot read pmemarr"); + return (-1); + } + + foff = nlist[X_NPMEMARR].n_value - KERNBASE; + if (lseek(kd->pmfd, foff, 0) == -1 || + read(kd->pmfd, &vm->npmemarr, sizeof(vm->npmemarr)) < 0) { + _kvm_err(kd, kd->program, "cannot read npmemarr"); + return (-1); + } + + return (0); +} + +int +_kvm_kvatop4m(kd, va, pa) + kvm_t *kd; + u_long va; + u_long *pa; +{ + register struct vmstate *vm = kd->vmst; + register int vr, vs, nmem, off; + int pte; + off_t foff; + struct regmap *rp; + struct segmap *sp; + struct memarr *mp; + + if (va < KERNBASE) + goto err; + + vr = VA_VREG(va); + vs = VA_VSEG(va); + + sp = &vm->segmap_store[(vr-NUREG)*NSEGRG + vs]; + if (sp->sg_npte == 0) + goto err; + + /* Assume kernel mappings are all within first memory bank. */ + foff = (long)&sp->sg_pte[VA_VPG(va)] - KERNBASE; + if (lseek(kd->pmfd, foff, 0) == -1 || + read(kd->pmfd, (void *)&pte, sizeof(pte)) < 0) { + _kvm_err(kd, kd->program, "cannot read pte"); + goto err; + } + + if ((pte & SRMMU_TETYPE) == SRMMU_TEPTE) { + register long p, dumpoff = 0; + + off = VA_OFF(va); + p = (pte & SRMMU_PPNMASK) << SRMMU_PPNPASHIFT; + /* Translate (sparse) pfnum to (packed) dump offset */ + for (mp = vm->pmemarr, nmem = vm->npmemarr; --nmem >= 0; mp++) { + if (mp->addr <= p && p < mp->addr + mp->len) + break; + dumpoff += mp->len; + } + if (nmem < 0) + goto err; + *pa = (dumpoff + p - mp->addr) | off; + return (kd->nbpg - off); + } +err: + _kvm_err(kd, 0, "invalid address (%x)", va); + return (0); } -#endif diff --git a/lib/libkvm/kvm_sun3.c b/lib/libkvm/kvm_sun3.c index f4cbac772da..69b22c23c98 100644 --- a/lib/libkvm/kvm_sun3.c +++ b/lib/libkvm/kvm_sun3.c @@ -1,3 +1,6 @@ +/* $OpenBSD: kvm_sun3.c,v 1.2 1996/05/05 14:57:53 deraadt Exp $ */ +/* $NetBSD: kvm_sun3.c,v 1.3 1996/03/18 22:34:04 thorpej Exp $ */ + /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. diff --git a/lib/libkvm/kvm_vax.c b/lib/libkvm/kvm_vax.c index b4a2b9532f6..9b35a94fbb1 100644 --- a/lib/libkvm/kvm_vax.c +++ b/lib/libkvm/kvm_vax.c @@ -1,4 +1,6 @@ -/* $NetBSD: kvm_vax.c,v 1.2 1995/04/25 15:41:11 ragge Exp $ */ +/* $OpenBSD: kvm_vax.c,v 1.2 1996/05/05 14:57:57 deraadt Exp $ */ +/* $NetBSD: kvm_vax.c,v 1.3 1996/03/18 22:34:06 thorpej Exp $ */ + /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. diff --git a/lib/libkvm/shlib_version b/lib/libkvm/shlib_version index d9961ea9fef..3066b9771e7 100644 --- a/lib/libkvm/shlib_version +++ b/lib/libkvm/shlib_version @@ -1,2 +1,2 @@ -major=4 +major=5 minor=0