summaryrefslogtreecommitdiffstats
path: root/lib/libkvm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libkvm')
-rw-r--r--lib/libkvm/kvm.c139
-rw-r--r--lib/libkvm/kvm_alpha.c84
-rw-r--r--lib/libkvm/kvm_amd64.c23
-rw-r--r--lib/libkvm/kvm_arm.c27
-rw-r--r--lib/libkvm/kvm_file.c25
-rw-r--r--lib/libkvm/kvm_getloadavg.c12
-rw-r--r--lib/libkvm/kvm_hppa.c23
-rw-r--r--lib/libkvm/kvm_i386.c64
-rw-r--r--lib/libkvm/kvm_m68k.c79
-rw-r--r--lib/libkvm/kvm_m88k.c37
-rw-r--r--lib/libkvm/kvm_powerpc.c26
-rw-r--r--lib/libkvm/kvm_proc.c262
-rw-r--r--lib/libkvm/kvm_sparc.c61
-rw-r--r--lib/libkvm/kvm_sparc64.c38
-rw-r--r--lib/libkvm/kvm_vax.c36
15 files changed, 375 insertions, 561 deletions
diff --git a/lib/libkvm/kvm.c b/lib/libkvm/kvm.c
index 7b98ecbaf53..42b6cf24939 100644
--- a/lib/libkvm/kvm.c
+++ b/lib/libkvm/kvm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm.c,v 1.37 2004/02/23 23:19:09 deraadt Exp $ */
+/* $OpenBSD: kvm.c,v 1.38 2004/06/15 03:52:58 deraadt Exp $ */
/* $NetBSD: kvm.c,v 1.43 1996/05/05 04:31:59 gwr Exp $ */
/*-
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)kvm.c 8.2 (Berkeley) 2/13/94";
#else
-static char *rcsid = "$OpenBSD: kvm.c,v 1.37 2004/02/23 23:19:09 deraadt Exp $";
+static char *rcsid = "$OpenBSD: kvm.c,v 1.38 2004/06/15 03:52:58 deraadt Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -96,7 +96,7 @@ _kvm_pread(kvm_t *kd, int fd, void *buf, size_t nbytes, off_t offset)
if (rval == -1 || errno != 0) {
_kvm_syserr(kd, kd->program, "pread");
}
- return(rval);
+ return (rval);
}
/*
@@ -112,7 +112,7 @@ _kvm_pwrite(kvm_t *kd, int fd, void *buf, size_t nbytes, off_t offset)
if (rval == -1 || errno != 0) {
_kvm_syserr(kd, kd->program, "pwrite");
}
- return(rval);
+ return (rval);
}
/*
@@ -142,7 +142,7 @@ void
_kvm_syserr(kvm_t *kd, const char *program, const char *fmt, ...)
{
va_list ap;
- register int n;
+ int n;
va_start(ap, fmt);
if (program != NULL) {
@@ -150,7 +150,7 @@ _kvm_syserr(kvm_t *kd, const char *program, const char *fmt, ...)
(void)vfprintf(stderr, fmt, ap);
(void)fprintf(stderr, ": %s\n", strerror(errno));
} else {
- register char *cp = kd->errbuf;
+ char *cp = kd->errbuf;
(void)vsnprintf(cp, sizeof(kd->errbuf), (char *)fmt, ap);
n = strlen(cp);
@@ -161,9 +161,7 @@ _kvm_syserr(kvm_t *kd, const char *program, const char *fmt, ...)
}
void *
-_kvm_malloc(kd, n)
- register kvm_t *kd;
- register size_t n;
+_kvm_malloc(kvm_t *kd, size_t n)
{
void *p;
@@ -173,13 +171,8 @@ _kvm_malloc(kd, n)
}
static kvm_t *
-_kvm_open(kd, uf, mf, sf, flag, errout)
- register kvm_t *kd;
- const char *uf;
- const char *mf;
- const char *sf;
- int flag;
- char *errout;
+_kvm_open(kvm_t *kd, const char *uf, const char *mf, const char *sf,
+ int flag, char *errout)
{
struct stat st;
@@ -196,7 +189,7 @@ _kvm_open(kd, uf, mf, sf, flag, errout)
kd->argspc = 0;
kd->argbuf = 0;
kd->argv = 0;
- kd->vmst = 0;
+ kd->vmst = NULL;
kd->vm_page_buckets = 0;
kd->kcore_hdr = 0;
kd->cpu_dsize = 0;
@@ -206,7 +199,7 @@ _kvm_open(kd, uf, mf, sf, flag, errout)
if (flag & KVM_NO_FILES) {
kd->alive = 1;
return (kd);
- }
+ }
if (uf && strlen(uf) >= MAXPATHLEN) {
_kvm_err(kd, kd->program, "exec file name too long");
@@ -283,7 +276,7 @@ _kvm_open(kd, uf, mf, sf, flag, errout)
/*
* If there is no valid core header, fail silently here.
- * The address translations however will fail without
+ * The address translations however will fail without
* header. Things can be made to run by calling
* kvm_dump_mkheader() before doing any translation.
*/
@@ -313,13 +306,12 @@ failed:
* (opaque) cpu_data; (size is cpu_hdr.c_size)
* kcore_seg_t mem_hdr;
* (memory) mem_data; (size is mem_hdr.c_size)
- *
+ *
* Note: khdr is padded to khdr.c_hdrsize;
* cpu_hdr and mem_hdr are padded to khdr.c_seghdrsize
*/
static int
-_kvm_get_header(kd)
- kvm_t *kd;
+_kvm_get_header(kvm_t *kd)
{
kcore_hdr_t kcore_hdr;
kcore_seg_t cpu_hdr;
@@ -367,7 +359,7 @@ _kvm_get_header(kd)
if (sz != sizeof(cpu_hdr)) {
goto fail;
}
-
+
if ((CORE_GETMAGIC(cpu_hdr) != KCORESEG_MAGIC) ||
(CORE_GETFLAG(cpu_hdr) != CORE_CPU))
goto fail;
@@ -427,9 +419,7 @@ fail:
* (memory) mem_data; (size is mem_hdr.c_size)
*/
int
-kvm_dump_mkheader(kd, dump_off)
-kvm_t *kd;
-off_t dump_off;
+kvm_dump_mkheader(kvm_t *kd, off_t dump_off)
{
kcore_seg_t cpu_hdr;
int hdr_size, sz;
@@ -516,10 +506,7 @@ fail:
}
static int
-clear_gap(kd, fp, size)
-kvm_t *kd;
-FILE *fp;
-int size;
+clear_gap(kvm_t *kd, FILE *fp, int size)
{
if (size <= 0) /* XXX - < 0 should never happen */
return (0);
@@ -537,10 +524,7 @@ int size;
* because 'fp' might be a file pointer obtained by zopen().
*/
int
-kvm_dump_wrtheader(kd, fp, dumpsize)
-kvm_t *kd;
-FILE *fp;
-int dumpsize;
+kvm_dump_wrtheader(kvm_t *kd, FILE *fp, int dumpsize)
{
kcore_seg_t seghdr;
long offset;
@@ -605,14 +589,10 @@ int dumpsize;
}
kvm_t *
-kvm_openfiles(uf, mf, sf, flag, errout)
- const char *uf;
- const char *mf;
- const char *sf;
- int flag;
- char *errout;
+kvm_openfiles(const char *uf, const char *mf, const char *sf,
+ int flag, char *errout)
{
- register kvm_t *kd;
+ kvm_t *kd;
if ((kd = malloc(sizeof(*kd))) == NULL) {
(void)strlcpy(errout, strerror(errno), _POSIX2_LINE_MAX);
@@ -623,14 +603,10 @@ kvm_openfiles(uf, mf, sf, flag, errout)
}
kvm_t *
-kvm_open(uf, mf, sf, flag, program)
- const char *uf;
- const char *mf;
- const char *sf;
- int flag;
- const char *program;
+kvm_open(const char *uf, const char *mf, const char *sf, int flag,
+ const char *program)
{
- register kvm_t *kd;
+ kvm_t *kd;
if ((kd = malloc(sizeof(*kd))) == NULL && program != NULL) {
(void)fprintf(stderr, "%s: %s\n", program, strerror(errno));
@@ -641,10 +617,9 @@ kvm_open(uf, mf, sf, flag, program)
}
int
-kvm_close(kd)
- kvm_t *kd;
+kvm_close(kvm_t *kd)
{
- register int error = 0;
+ int error = 0;
if (kd->pmfd >= 0)
error |= close(kd->pmfd);
@@ -681,21 +656,18 @@ kvm_close(kd)
/*
* Set up state necessary to do queries on the kernel namelist
- * data base. If the data base is out-of-data/incompatible with
+ * data base. If the data base is out-of-data/incompatible with
* given executable, set up things so we revert to standard nlist call.
* Only called for live kernels. Return 0 on success, -1 on failure.
*/
static int
-kvm_dbopen(kd, uf)
- kvm_t *kd;
- const char *uf;
+kvm_dbopen(kvm_t *kd, const char *uf)
{
- DBT rec;
- int dbversionlen;
- struct nlist nitem;
- char dbversion[_POSIX2_LINE_MAX];
- char kversion[_POSIX2_LINE_MAX];
+ char dbversion[_POSIX2_LINE_MAX], kversion[_POSIX2_LINE_MAX];
char dbname[MAXPATHLEN];
+ struct nlist nitem;
+ int dbversionlen;
+ DBT rec;
uf = basename((char *)uf);
@@ -745,7 +717,7 @@ kvm_dbopen(kd, uf)
if (rec.data == 0 || rec.size != sizeof(struct nlist))
goto close;
bcopy((char *)rec.data, (char *)&nitem, sizeof(nitem));
- if (kvm_read(kd, (u_long)nitem.n_value, kversion, dbversionlen) !=
+ if (kvm_read(kd, (u_long)nitem.n_value, kversion, dbversionlen) !=
dbversionlen)
goto close;
/*
@@ -762,15 +734,13 @@ close:
}
int
-kvm_nlist(kd, nl)
- kvm_t *kd;
- struct nlist *nl;
+kvm_nlist(kvm_t *kd, struct nlist *nl)
{
- register struct nlist *p;
- register int nvalid, rv;
+ struct nlist *p;
+ int nvalid, rv;
/*
- * If we can't use the data base, revert to the
+ * If we can't use the data base, revert to the
* slow library call.
*/
if (kd->db == 0) {
@@ -786,7 +756,7 @@ kvm_nlist(kd, nl)
*/
nvalid = 0;
for (p = nl; p->n_name && p->n_name[0]; ++p) {
- register int len;
+ int len;
DBT rec;
if ((len = strlen(p->n_name)) > 4096) {
@@ -811,11 +781,9 @@ kvm_nlist(kd, nl)
* Avoid alignment issues.
*/
bcopy((char *)&((struct nlist *)rec.data)->n_type,
- (char *)&p->n_type,
- sizeof(p->n_type));
+ (char *)&p->n_type, sizeof(p->n_type));
bcopy((char *)&((struct nlist *)rec.data)->n_value,
- (char *)&p->n_value,
- sizeof(p->n_value));
+ (char *)&p->n_value, sizeof(p->n_value));
}
/*
* Return the number of entries that weren't found.
@@ -823,8 +791,8 @@ kvm_nlist(kd, nl)
return ((p - nl) - nvalid);
}
-int kvm_dump_inval(kd)
-kvm_t *kd;
+int
+kvm_dump_inval(kvm_t *kd)
{
struct nlist nlist[2];
u_long pa, x;
@@ -853,14 +821,10 @@ kvm_t *kd;
}
ssize_t
-kvm_read(kd, kva, buf, len)
- kvm_t *kd;
- register u_long kva;
- register void *buf;
- register size_t len;
+kvm_read(kvm_t *kd, u_long kva, void *buf, size_t len)
{
- register int cc;
- register void *cp;
+ int cc;
+ void *cp;
if (ISALIVE(kd)) {
/*
@@ -882,7 +846,7 @@ kvm_read(kd, kva, buf, len)
cp = buf;
while (len > 0) {
u_long pa;
-
+
/* In case of error, _kvm_kvatop sets the err string */
cc = _kvm_kvatop(kd, kva, &pa);
if (cc == 0)
@@ -913,13 +877,9 @@ kvm_read(kd, kva, buf, len)
}
ssize_t
-kvm_write(kd, kva, buf, len)
- kvm_t *kd;
- register u_long kva;
- register const void *buf;
- register size_t len;
+kvm_write(kvm_t *kd, u_long kva, const void *buf, size_t len)
{
- register int cc;
+ int cc;
if (ISALIVE(kd)) {
/*
@@ -941,8 +901,7 @@ kvm_write(kd, kva, buf, len)
}
static int
-kvm_setfd(kd)
- kvm_t *kd;
+kvm_setfd(kvm_t *kd)
{
if (kd->pmfd >= 0 && fcntl(kd->pmfd, F_SETFD, FD_CLOEXEC) < 0)
return (-1);
diff --git a/lib/libkvm/kvm_alpha.c b/lib/libkvm/kvm_alpha.c
index b2d8cd975a4..2bef0731951 100644
--- a/lib/libkvm/kvm_alpha.c
+++ b/lib/libkvm/kvm_alpha.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_alpha.c,v 1.10 2001/12/05 02:23:11 art Exp $ */
+/* $OpenBSD: kvm_alpha.c,v 1.11 2004/06/15 03:52:59 deraadt Exp $ */
/* $NetBSD: kvm_alpha.c,v 1.5 1996/10/01 21:12:05 cgd Exp $ */
/*
@@ -6,17 +6,17 @@
* 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
+ *
+ * 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@CS.CMU.EDU
@@ -28,7 +28,7 @@
* rights to redistribute these changes.
*/
-#define __KVM_ALPHA_PRIVATE /* see <machine/pte.h> */
+#define __KVM_ALPHA_PRIVATE /* see <machine/pte.h> */
#include <sys/param.h>
#include <sys/user.h>
@@ -54,46 +54,43 @@ struct vmstate {
};
void
-_kvm_freevtop(kd)
- kvm_t *kd;
+_kvm_freevtop(kvm_t *kd)
{
/* Not actually used for anything right now, but safe. */
- if (kd->vmst != 0)
+ if (kd->vmst != NULL) {
free(kd->vmst);
+ kd->vmst = NULL;
+ }
}
int
-_kvm_initvtop(kd)
- kvm_t *kd;
+_kvm_initvtop(kvm_t *kd)
{
- cpu_kcore_hdr_t *cpu_kh;
- struct vmstate *vm;
+ cpu_kcore_hdr_t *cpu_kh;
+ struct vmstate *vm;
- vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm));
- if (vm == NULL)
- return (-1);
+ vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm));
+ if (vm == NULL)
+ return (-1);
- cpu_kh = kd->cpu_data;
+ cpu_kh = kd->cpu_data;
- /* Compute page_shift. */
- for (vm->page_shift = 0; (1L << vm->page_shift) < cpu_kh->page_size;
- vm->page_shift++)
- /* nothing */ ;
- if ((1L << vm->page_shift) != cpu_kh->page_size) {
- free(vm);
- return (-1);
- }
+ /* Compute page_shift. */
+ for (vm->page_shift = 0; (1L << vm->page_shift) < cpu_kh->page_size;
+ vm->page_shift++)
+ /* nothing */ ;
+ if ((1L << vm->page_shift) != cpu_kh->page_size) {
+ free(vm);
+ return (-1);
+ }
- kd->vmst = vm;
+ kd->vmst = vm;
return (0);
}
int
-_kvm_kvatop(kd, va, pa)
- kvm_t *kd;
- u_long va;
- u_long *pa;
+_kvm_kvatop(kvm_t *kd, u_long va, u_long *pa)
{
cpu_kcore_hdr_t *cpu_kh;
struct vmstate *vm;
@@ -101,17 +98,17 @@ _kvm_kvatop(kd, va, pa)
alpha_pt_entry_t pte;
off_t pteoff;
- if (ISALIVE(kd)) {
- _kvm_err(kd, 0, "vatop called in live kernel!");
- return(0);
- }
+ if (ISALIVE(kd)) {
+ _kvm_err(kd, 0, "vatop called in live kernel!");
+ return (0);
+ }
cpu_kh = kd->cpu_data;
vm = kd->vmst;
page_off = va & (cpu_kh->page_size - 1);
#ifndef PAGE_SHIFT
-#define PAGE_SHIFT vm->page_shift
+#define PAGE_SHIFT vm->page_shift
#endif
if (va >= ALPHA_K0SEG_BASE && va <= ALPHA_K0SEG_END) {
@@ -129,7 +126,8 @@ _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 (_kvm_pread(kd, kd->pmfd, (char *)&pte, sizeof(pte), (off_t)_kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
+ if (_kvm_pread(kd, kd->pmfd, (char *)&pte, sizeof(pte),
+ (off_t)_kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
_kvm_syserr(kd, 0, "could not read L1 PTE");
goto lose;
}
@@ -141,7 +139,8 @@ _kvm_kvatop(kd, va, pa)
}
pteoff = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size +
l2pte_index(va) * sizeof(alpha_pt_entry_t);
- if (_kvm_pread(kd, kd->pmfd, (char *)&pte, sizeof(pte), (off_t)_kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
+ if (_kvm_pread(kd, kd->pmfd, (char *)&pte, sizeof(pte),
+ (off_t)_kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
_kvm_syserr(kd, 0, "could not read L2 PTE");
goto lose;
}
@@ -153,7 +152,8 @@ _kvm_kvatop(kd, va, pa)
}
pteoff = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size +
l3pte_index(va) * sizeof(alpha_pt_entry_t);
- if (_kvm_pread(kd, kd->pmfd, (char *)&pte, sizeof(pte), (off_t)_kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
+ if (_kvm_pread(kd, kd->pmfd, (char *)&pte, sizeof(pte),
+ (off_t)_kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
_kvm_syserr(kd, 0, "could not read L3 PTE");
goto lose;
}
@@ -182,10 +182,8 @@ lose:
/*
* Translate a physical address to a file-offset in the crash-dump.
*/
-off_t
-_kvm_pa2off(kd, pa)
- kvm_t *kd;
- u_long pa;
+off_t
+_kvm_pa2off(kvm_t *kd, u_long pa)
{
cpu_kcore_hdr_t *cpu_kh;
phys_ram_seg_t *ramsegs;
diff --git a/lib/libkvm/kvm_amd64.c b/lib/libkvm/kvm_amd64.c
index 3e74dba45fc..f7446c9e62d 100644
--- a/lib/libkvm/kvm_amd64.c
+++ b/lib/libkvm/kvm_amd64.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_amd64.c,v 1.2 2004/05/05 16:45:55 marc Exp $ */
+/* $OpenBSD: kvm_amd64.c,v 1.3 2004/06/15 03:52:59 deraadt Exp $ */
/* $NetBSD: kvm_x86_64.c,v 1.3 2002/06/05 22:01:55 fvdl Exp $ */
/*-
@@ -67,19 +67,19 @@
#include <machine/vmparam.h>
void
-_kvm_freevtop(kd)
- kvm_t *kd;
+_kvm_freevtop(kvm_t *kd)
{
/* Not actually used for anything right now, but safe. */
- if (kd->vmst != 0)
+ if (kd->vmst != NULL) {
free(kd->vmst);
+ kd->vmst = NULL;
+ }
}
/*ARGSUSED*/
int
-_kvm_initvtop(kd)
- kvm_t *kd;
+_kvm_initvtop(kvm_t *kd)
{
return (0);
@@ -89,16 +89,13 @@ _kvm_initvtop(kd)
* Translate a kernel virtual address to a physical address.
*/
int
-_kvm_kvatop(kd, va, pa)
- kvm_t *kd;
- u_long va;
- u_long *pa;
+_kvm_kvatop(kvm_t *kd, u_long va, u_long *pa)
{
cpu_kcore_hdr_t *cpu_kh;
+ paddr_t pde_pa, pte_pa;
u_long page_off;
pd_entry_t pde;
pt_entry_t pte;
- paddr_t pde_pa, pte_pa;
if (ISALIVE(kd)) {
_kvm_err(kd, 0, "vatop called in live kernel!");
@@ -183,9 +180,7 @@ _kvm_kvatop(kd, va, pa)
* Translate a physical address to a file-offset in the crash dump.
*/
off_t
-_kvm_pa2off(kd, pa)
- kvm_t *kd;
- u_long pa;
+_kvm_pa2off(kvm_t *kd, u_long pa)
{
cpu_kcore_hdr_t *cpu_kh;
phys_ram_seg_t *ramsegs;
diff --git a/lib/libkvm/kvm_arm.c b/lib/libkvm/kvm_arm.c
index f04eb59ef06..1dcb10ee1c8 100644
--- a/lib/libkvm/kvm_arm.c
+++ b/lib/libkvm/kvm_arm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_arm.c,v 1.1 2004/02/09 04:06:13 drahn Exp $ */
+/* $OpenBSD: kvm_arm.c,v 1.2 2004/06/15 03:52:59 deraadt Exp $ */
/*-
* Copyright (C) 1996 Wolfgang Solfrank.
@@ -44,35 +44,30 @@
#include "kvm_private.h"
void
-_kvm_freevtop(kd)
- kvm_t *kd;
+_kvm_freevtop(kvm_t *kd)
{
- if (kd->vmst != 0)
+ if (kd->vmst != NULL) {
free(kd->vmst);
+ kd->vmst = NULL;
+ }
}
int
-_kvm_initvtop(kd)
- kvm_t *kd;
+_kvm_initvtop(kvm_t *kd)
{
- return 0;
+ return (0);
}
int
-_kvm_kvatop(kd, va, pa)
- kvm_t *kd;
- u_long va;
- u_long *pa;
+_kvm_kvatop(kvm_t *kd, u_long va, u_long *pa)
{
_kvm_err(kd, 0, "vatop not yet implemented!");
- return 0;
+ return (0);
}
off_t
-_kvm_pa2off(kd, pa)
- kvm_t *kd;
- u_long pa;
+_kvm_pa2off(kvm_t *kd, u_long pa)
{
_kvm_err(kd, 0, "pa2off not yet implemented!");
- return 0;
+ return (0);
}
diff --git a/lib/libkvm/kvm_file.c b/lib/libkvm/kvm_file.c
index 7203a930e58..913194d5533 100644
--- a/lib/libkvm/kvm_file.c
+++ b/lib/libkvm/kvm_file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_file.c,v 1.10 2004/04/28 03:16:31 millert Exp $ */
+/* $OpenBSD: kvm_file.c,v 1.11 2004/06/15 03:52:59 deraadt Exp $ */
/* $NetBSD: kvm_file.c,v 1.5 1996/03/18 22:33:18 thorpej Exp $ */
/*-
@@ -34,12 +34,12 @@
#if 0
static char sccsid[] = "@(#)kvm_file.c 8.1 (Berkeley) 6/4/93";
#else
-static char *rcsid = "$OpenBSD: kvm_file.c,v 1.10 2004/04/28 03:16:31 millert Exp $";
+static char *rcsid = "$OpenBSD: kvm_file.c,v 1.11 2004/06/15 03:52:59 deraadt Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
/*
- * File list interface for kvm. pstat, fstat and netstat are
+ * File list interface for kvm. pstat, fstat and netstat are
* users of this code, so we've factored it out into a separate module.
* Thus, we keep this grunge out of the other kvm applications (i.e.,
* most other applications are interested only in open/close/read/nlist).
@@ -76,16 +76,12 @@ static int kvm_deadfiles(kvm_t *kd, int op, int arg, long filehead_o,
* Get file structures.
*/
static int
-kvm_deadfiles(kd, op, arg, filehead_o, nfiles)
- kvm_t *kd;
- int op, arg, nfiles;
- long filehead_o;
+kvm_deadfiles(kvm_t *kd, int op, int arg, long filehead_o, int nfiles)
{
int buflen = kd->arglen, needed = buflen, error, n = 0;
+ char *where = kd->argspc, *start = where;
struct file *fp, file;
struct filelist filehead;
- register char *where = kd->argspc;
- char *start = where;
/*
* first copyout filehead
@@ -122,15 +118,12 @@ kvm_deadfiles(kd, op, arg, filehead_o, nfiles)
}
char *
-kvm_getfiles(kd, op, arg, cnt)
- kvm_t *kd;
- int op, arg;
- int *cnt;
+kvm_getfiles(kvm_t *kd, int op, int arg, int *cnt)
{
- size_t size;
- int mib[2], st, nfiles;
- struct file *fp, *fplim;
struct filelist filehead;
+ struct file *fp, *fplim;
+ int mib[2], st, nfiles;
+ size_t size;
if (ISALIVE(kd)) {
size = 0;
diff --git a/lib/libkvm/kvm_getloadavg.c b/lib/libkvm/kvm_getloadavg.c
index e88c7c36ca8..371b3eb8e6b 100644
--- a/lib/libkvm/kvm_getloadavg.c
+++ b/lib/libkvm/kvm_getloadavg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_getloadavg.c,v 1.5 2003/07/18 23:05:13 david Exp $ */
+/* $OpenBSD: kvm_getloadavg.c,v 1.6 2004/06/15 03:52:59 deraadt Exp $ */
/* $NetBSD: kvm_getloadavg.c,v 1.2 1996/03/18 22:33:31 thorpej Exp $ */
/*-
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)kvm_getloadavg.c 8.1 (Berkeley) 6/4/93";
#else
-static char *rcsid = "$OpenBSD: kvm_getloadavg.c,v 1.5 2003/07/18 23:05:13 david Exp $";
+static char *rcsid = "$OpenBSD: kvm_getloadavg.c,v 1.6 2004/06/15 03:52:59 deraadt Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -68,10 +68,7 @@ static struct nlist nl[] = {
* Return number of samples retrieved, or -1 on error.
*/
int
-kvm_getloadavg(kd, loadavg, nelem)
- kvm_t *kd;
- double loadavg[];
- int nelem;
+kvm_getloadavg(kvm_t *kd, double loadavg[], int nelem)
{
struct loadavg loadinfo;
struct nlist *p;
@@ -81,7 +78,8 @@ kvm_getloadavg(kd, loadavg, nelem)
return (getloadavg(loadavg, nelem));
if (kvm_nlist(kd, nl) != 0) {
- for (p = nl; p->n_type != 0; ++p);
+ for (p = nl; p->n_type != 0; ++p)
+ ;
_kvm_err(kd, kd->program,
"%s: no such symbol", p->n_name);
return (-1);
diff --git a/lib/libkvm/kvm_hppa.c b/lib/libkvm/kvm_hppa.c
index f1a3497ff07..a4a45d9869b 100644
--- a/lib/libkvm/kvm_hppa.c
+++ b/lib/libkvm/kvm_hppa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_hppa.c,v 1.2 2003/06/02 16:16:23 miod Exp $ */
+/* $OpenBSD: kvm_hppa.c,v 1.3 2004/06/15 03:52:59 deraadt Exp $ */
/*
* Copyright (c) 2002, Miodrag Vallat.
@@ -35,31 +35,28 @@
#include "kvm_private.h"
void
-_kvm_freevtop(kd)
- kvm_t *kd;
+_kvm_freevtop(kvm_t *kd)
{
- if (kd->vmst != 0)
+ if (kd->vmst != NULL) {
free(kd->vmst);
+ kd->vmst = NULL;
+ }
}
int
-_kvm_initvtop(kd)
- kvm_t *kd;
+_kvm_initvtop(kvm_t *kd)
{
return (0);
}
int
-_kvm_kvatop(kd, va, pa)
- kvm_t *kd;
- u_long va;
- u_long *pa;
+_kvm_kvatop(kvm_t *kd, u_long va, u_long *pa)
{
int offset;
if (ISALIVE(kd)) {
_kvm_err(kd, 0, "vatop called in live kernel!");
- return 0;
+ return (0);
}
/* TODO */
@@ -70,9 +67,7 @@ _kvm_kvatop(kd, va, pa)
* Translate a physical address to a file offset in the crash dump.
*/
off_t
-_kvm_pa2off(kd, pa)
- kvm_t *kd;
- u_long pa;
+_kvm_pa2off(kvm_t *kd, u_long pa)
{
/* TODO */
return (0);
diff --git a/lib/libkvm/kvm_i386.c b/lib/libkvm/kvm_i386.c
index d7447bb2794..758f1265f29 100644
--- a/lib/libkvm/kvm_i386.c
+++ b/lib/libkvm/kvm_i386.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_i386.c,v 1.11 2003/06/02 20:18:40 millert Exp $ */
+/* $OpenBSD: kvm_i386.c,v 1.12 2004/06/15 03:52:59 deraadt Exp $ */
/* $NetBSD: kvm_i386.c,v 1.9 1996/03/18 22:33:38 thorpej Exp $ */
/*-
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93";
#else
-static char *rcsid = "$OpenBSD: kvm_i386.c,v 1.11 2003/06/02 20:18:40 millert Exp $";
+static char *rcsid = "$OpenBSD: kvm_i386.c,v 1.12 2004/06/15 03:52:59 deraadt Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -72,23 +72,22 @@ struct vmstate {
};
void
-_kvm_freevtop(kd)
- kvm_t *kd;
+_kvm_freevtop(kvm_t *kd)
{
- if (kd->vmst != 0) {
- if (kd->vmst->PTD != 0)
+ if (kd->vmst != NULL) {
+ if (kd->vmst->PTD != NULL)
free(kd->vmst->PTD);
free(kd->vmst);
+ kd->vmst = NULL;
}
}
int
-_kvm_initvtop(kd)
- kvm_t *kd;
+_kvm_initvtop(kvm_t *kd)
{
- struct vmstate *vm;
struct nlist nlist[2];
+ struct vmstate *vm;
u_long pa;
vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm));
@@ -106,15 +105,15 @@ _kvm_initvtop(kd)
vm->PTD = 0;
- if (_kvm_pread(kd, kd->pmfd, &pa, sizeof pa, (off_t)_kvm_pa2off(kd, nlist[0].n_value - KERNBASE)) != sizeof pa) {
+ if (_kvm_pread(kd, kd->pmfd, &pa, sizeof pa,
+ (off_t)_kvm_pa2off(kd, nlist[0].n_value - KERNBASE)) != sizeof pa)
goto invalid;
- }
vm->PTD = (pd_entry_t *)_kvm_malloc(kd, NBPG);
- if (_kvm_pread(kd, kd->pmfd, vm->PTD, NBPG, (off_t)_kvm_pa2off(kd, pa)) != NBPG) {
+ if (_kvm_pread(kd, kd->pmfd, vm->PTD, NBPG,
+ (off_t)_kvm_pa2off(kd, pa)) != NBPG)
goto invalid;
- }
return (0);
@@ -128,43 +127,38 @@ invalid:
* Translate a kernel virtual address to a physical address.
*/
int
-_kvm_kvatop(kd, va, pa)
- kvm_t *kd;
- u_long va;
- u_long *pa;
+_kvm_kvatop(kvm_t *kd, u_long va, u_long *pa)
{
+ u_long offset, pte_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);
+ return (0);
}
vm = kd->vmst;
offset = va & PGOFSET;
- /*
- * If we are initializing (kernel page table descriptor pointer
+ /*
+ * 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 == 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 (_kvm_pread(kd, kd->pmfd, &pte, sizeof pte, (off_t)_kvm_pa2off(kd, pte_pa)) != sizeof pte) {
- goto invalid;
- }
- }
+ if (_kvm_pread(kd, kd->pmfd, &pte, sizeof pte,
+ (off_t)_kvm_pa2off(kd, pte_pa)) != sizeof pte)
+ goto invalid;
*pa = (pte & PG_FRAME) + offset;
return (NBPG - offset);
@@ -178,9 +172,7 @@ invalid:
* Translate a physical address to a file-offset in the crash-dump.
*/
off_t
-_kvm_pa2off(kd, pa)
- kvm_t *kd;
- u_long pa;
+_kvm_pa2off(kvm_t *kd, u_long pa)
{
- return((off_t)(kd->dump_off + pa));
+ return ((off_t)(kd->dump_off + pa));
}
diff --git a/lib/libkvm/kvm_m68k.c b/lib/libkvm/kvm_m68k.c
index aa03bed04d8..e1629479c65 100644
--- a/lib/libkvm/kvm_m68k.c
+++ b/lib/libkvm/kvm_m68k.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_m68k.c,v 1.12 2003/06/02 20:18:40 millert Exp $ */
+/* $OpenBSD: kvm_m68k.c,v 1.13 2004/06/15 03:52:59 deraadt Exp $ */
/* $NetBSD: kvm_m68k.c,v 1.9 1996/05/07 06:09:11 leo Exp $ */
/*-
@@ -38,12 +38,12 @@
#if 0
static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93";
#else
-static char *rcsid = "$OpenBSD: kvm_m68k.c,v 1.12 2003/06/02 20:18:40 millert Exp $";
+static char *rcsid = "$OpenBSD: kvm_m68k.c,v 1.13 2004/06/15 03:52:59 deraadt Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
/*
- * m68k machine dependent routines for kvm. Hopefully, the forthcoming
+ * m68k machine dependent routines for kvm. Hopefully, the forthcoming
* vm code will one day obsolete this module.
*/
@@ -82,35 +82,29 @@ static char *rcsid = "$OpenBSD: kvm_m68k.c,v 1.12 2003/06/02 20:18:40 millert Ex
(kvm_read(kd, addr, (char *)(p), sizeof(*(p))) != sizeof(*(p)))
void
-_kvm_freevtop(kd)
- kvm_t *kd;
+_kvm_freevtop(kvm_t *kd)
{
- if (kd->vmst != 0)
+ if (kd->vmst != NULL) {
free(kd->vmst);
-}
+ kd->vmst = NULL;
+ }
int
-_kvm_initvtop(kd)
- kvm_t *kd;
+_kvm_initvtop(kvm_t *kd)
{
return (0);
}
static int
-_kvm_vatop(kd, sta, va, pa)
- kvm_t *kd;
- st_entry_t *sta;
- u_long va;
- u_long *pa;
+_kvm_vatop(kvm_t *kd, st_entry_t *sta, u_long va, u_long *pa)
{
- register cpu_kcore_hdr_t *cpu_kh;
- register u_long addr;
- int p, ste, pte;
- int offset;
+ cpu_kcore_hdr_t *cpu_kh;
+ int p, ste, pte, offset;
+ u_long addr;
if (ISALIVE(kd)) {
_kvm_err(kd, 0, "vatop called in live kernel!");
- return((off_t)0);
+ return (0);
}
offset = va & PGOFSET;
cpu_kh = kd->cpu_data;
@@ -128,17 +122,18 @@ _kvm_vatop(kd, sta, va, pa)
addr = (u_long)&sta[va >> SG4_SHIFT1];
/*
* Can't use KREAD to read kernel segment table entries.
- * Fortunately it is 1-to-1 mapped so we don't have to.
+ * Fortunately it is 1-to-1 mapped so we don't have to.
*/
if (sta == cpu_kh->sysseg_pa) {
- if (_kvm_pread(kd, kd->pmfd, (char *)&ste, sizeof(ste), (off_t)_kvm_pa2off(kd, addr)) < 0)
+ if (_kvm_pread(kd, kd->pmfd, (char *)&ste, sizeof(ste),
+ (off_t)_kvm_pa2off(kd, addr)) < 0)
goto invalid;
} else if (KREAD(kd, addr, &ste))
goto invalid;
if ((ste & SG_V) == 0) {
_kvm_err(kd, 0, "invalid level 1 descriptor (%x)",
- ste);
- return((off_t)0);
+ ste);
+ return (0);
}
sta2 = (st_entry_t *)(ste & SG4_ADDR1);
addr = (u_long)&sta2[(va & SG4_MASK2) >> SG4_SHIFT2];
@@ -146,12 +141,13 @@ _kvm_vatop(kd, sta, va, pa)
* Address from level 1 STE is a physical address,
* so don't use kvm_read.
*/
- if (_kvm_pread(kd, kd->pmfd, (char *)&ste, sizeof(ste), (off_t)_kvm_pa2off(kd, addr)) < 0)
+ if (_kvm_pread(kd, kd->pmfd, (char *)&ste, sizeof(ste),
+ (off_t)_kvm_pa2off(kd, addr)) < 0)
goto invalid;
if ((ste & SG_V) == 0) {
_kvm_err(kd, 0, "invalid level 2 descriptor (%x)",
- ste);
- return((off_t)0);
+ ste);
+ return (0);
}
sta2 = (st_entry_t *)(ste & SG4_ADDR2);
addr = (u_long)&sta2[(va & SG4_MASK3) >> SG4_SHIFT3];
@@ -159,16 +155,17 @@ _kvm_vatop(kd, sta, va, pa)
addr = (u_long)&sta[va >> SEGSHIFT];
/*
* Can't use KREAD to read kernel segment table entries.
- * Fortunately it is 1-to-1 mapped so we don't have to.
+ * Fortunately it is 1-to-1 mapped so we don't have to.
*/
if (sta == cpu_kh->sysseg_pa) {
- if (_kvm_pread(kd, kd->pmfd, (char *)&ste, sizeof(ste), (off_t)_kvm_pa2off(kd, addr)) < 0)
+ if (_kvm_pread(kd, kd->pmfd, (char *)&ste,
+ sizeof(ste), (off_t)_kvm_pa2off(kd, addr)) < 0)
goto invalid;
} else if (KREAD(kd, addr, &ste))
goto invalid;
if ((ste & SG_V) == 0) {
_kvm_err(kd, 0, "invalid segment (%x)", ste);
- return((off_t)0);
+ return (0);
}
p = btop(va & SG_PMASK);
addr = (ste & SG_FRAME) + (p * sizeof(pt_entry_t));
@@ -176,7 +173,8 @@ _kvm_vatop(kd, sta, va, pa)
/*
* Address from STE is a physical address so don't use kvm_read.
*/
- if (_kvm_pread(kd, kd->pmfd, (char *)&pte, sizeof(pte), (off_t)_kvm_pa2off(kd, addr)) < 0)
+ if (_kvm_pread(kd, kd->pmfd, (char *)&pte, sizeof(pte),
+ (off_t)_kvm_pa2off(kd, addr)) < 0)
goto invalid;
addr = pte & PG_FRAME;
if (pte == PG_NV) {
@@ -184,20 +182,17 @@ _kvm_vatop(kd, sta, va, pa)
return (0);
}
*pa = addr + offset;
-
+
return (NBPG - offset);
invalid:
_kvm_err(kd, 0, "invalid address (%lx)", va);
return (0);
}
-
+n
int
-_kvm_kvatop(kd, va, pa)
- kvm_t *kd;
- u_long va;
- u_long *pa;
+_kvm_kvatop(kvm_t *kd, u_long va, u_long *pa)
{
- register cpu_kcore_hdr_t *cpu_kh;
+ cpu_kcore_hdr_t *cpu_kh;
cpu_kh = kd->cpu_data;
return (_kvm_vatop(kd, (u_long)cpu_kh->sysseg_pa, va, pa));
@@ -207,13 +202,11 @@ _kvm_kvatop(kd, va, pa)
* Translate a physical address to a file-offset in the crash-dump.
*/
off_t
-_kvm_pa2off(kd, pa)
- kvm_t *kd;
- u_long pa;
+_kvm_pa2off(kvm_t *kd, u_long pa)
{
- off_t off;
+ cpu_kcore_hdr_t *cpu_kh;
phys_ram_seg_t *rsp;
- register cpu_kcore_hdr_t *cpu_kh;
+ off_t off;
cpu_kh = kd->cpu_data;
off = 0;
@@ -224,5 +217,5 @@ _kvm_pa2off(kd, pa)
}
off += rsp->size;
}
- return(kd->dump_off + off + pa);
+ return (kd->dump_off + off + pa);
}
diff --git a/lib/libkvm/kvm_m88k.c b/lib/libkvm/kvm_m88k.c
index c5736be61fa..2f53544859e 100644
--- a/lib/libkvm/kvm_m88k.c
+++ b/lib/libkvm/kvm_m88k.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_m88k.c,v 1.1 2004/04/21 18:35:25 miod Exp $ */
+/* $OpenBSD: kvm_m88k.c,v 1.2 2004/06/15 03:52:59 deraadt Exp $ */
/* $NetBSD: kvm_alpha.c,v 1.2 1995/09/29 03:57:48 cgd Exp $ */
/*
@@ -6,17 +6,17 @@
* 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
+ *
+ * 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@CS.CMU.EDU
@@ -44,36 +44,33 @@
#include "kvm_private.h"
void
-_kvm_freevtop(kd)
- kvm_t *kd;
+_kvm_freevtop(kvm_t *kd)
{
-
+ if (kd->vmst != NULL) {
+ free(kd->vmst);
+ kd->vmst = NULL;
+ }
}
int
-_kvm_initvtop(kd)
- kvm_t *kd;
+_kvm_initvtop(kvm_t *kd)
{
return (0);
}
int
-_kvm_kvatop(kd, va, pa)
- kvm_t *kd;
- u_long va;
- u_long *pa;
+_kvm_kvatop(kvm_t *kd, u_long va, u_long *pa)
{
/* don't forget k0seg translations! */
-
+ _kvm_err(kd, 0, "vatop not yet implemented!");
return (0);
}
+
off_t
-_kvm_pa2off(kd, pa)
- kvm_t *kd;
- u_long pa;
+_kvm_pa2off(kvm_t *kd, u_long pa)
{
_kvm_err(kd, 0, "pa2off not yet implemented!");
- return 0;
+ return (0);
}
diff --git a/lib/libkvm/kvm_powerpc.c b/lib/libkvm/kvm_powerpc.c
index 453cd3c3935..7927fe9a5c8 100644
--- a/lib/libkvm/kvm_powerpc.c
+++ b/lib/libkvm/kvm_powerpc.c
@@ -44,35 +44,31 @@
#include "kvm_private.h"
void
-_kvm_freevtop(kd)
- kvm_t *kd;
+_kvm_freevtop(kvm_t *kd)
{
- if (kd->vmst != 0)
+ if (kd->vmst != NULL) {
free(kd->vmst);
+ kd->vmst = NULL;
+ }
}
int
-_kvm_initvtop(kd)
- kvm_t *kd;
+_kvm_initvtop(kvm_t *kd)
{
- return 0;
+
+ return (0);
}
int
-_kvm_kvatop(kd, va, pa)
- kvm_t *kd;
- u_long va;
- u_long *pa;
+_kvm_kvatop(kvm_t *kd, u_long va, u_long *pa)
{
_kvm_err(kd, 0, "vatop not yet implemented!");
- return 0;
+ return (0);
}
off_t
-_kvm_pa2off(kd, pa)
- kvm_t *kd;
- u_long pa;
+_kvm_pa2off(kvm_t *kd, u_long pa)
{
_kvm_err(kd, 0, "pa2off not yet implemented!");
- return 0;
+ return (0);
}
diff --git a/lib/libkvm/kvm_proc.c b/lib/libkvm/kvm_proc.c
index d47e071f964..df36310abef 100644
--- a/lib/libkvm/kvm_proc.c
+++ b/lib/libkvm/kvm_proc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_proc.c,v 1.23 2004/06/14 03:46:46 millert Exp $ */
+/* $OpenBSD: kvm_proc.c,v 1.24 2004/06/15 03:52:59 deraadt Exp $ */
/* $NetBSD: kvm_proc.c,v 1.30 1999/03/24 05:50:50 mrg Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
#if 0
static char sccsid[] = "@(#)kvm_proc.c 8.3 (Berkeley) 9/23/93";
#else
-static char *rcsid = "$OpenBSD: kvm_proc.c,v 1.23 2004/06/14 03:46:46 millert Exp $";
+static char *rcsid = "$OpenBSD: kvm_proc.c,v 1.24 2004/06/15 03:52:59 deraadt Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -170,19 +170,13 @@ static void ps_str_a(struct ps_strings *, u_long *, int *);
static void ps_str_e(struct ps_strings *, u_long *, int *);
static char *
-_kvm_ureadm(kd, p, va, cnt)
- kvm_t *kd;
- const struct miniproc *p;
- u_long va;
- u_long *cnt;
+_kvm_ureadm(kvm_t *kd, const struct miniproc *p, u_long va, u_long *cnt)
{
- u_long addr, head;
- u_long offset;
+ u_long addr, head, offset, slot;
+ struct vm_anon *anonp, anon;
struct vm_map_entry vme;
struct vm_amap amap;
- struct vm_anon *anonp, anon;
struct vm_page pg;
- u_long slot;
if (kd->swapspc == 0) {
kd->swapspc = (char *)_kvm_malloc(kd, kd->nbpg);
@@ -201,7 +195,7 @@ _kvm_ureadm(kd, p, va, cnt)
if (KREAD(kd, addr, &vme))
return (0);
- if (va >= vme.start && va < vme.end &&
+ if (va >= vme.start && va < vme.end &&
vme.aref.ar_amap != NULL)
break;
@@ -214,38 +208,39 @@ _kvm_ureadm(kd, p, va, cnt)
* we found the map entry, now to find the object...
*/
if (vme.aref.ar_amap == NULL)
- return NULL;
+ return (NULL);
addr = (u_long)vme.aref.ar_amap;
if (KREAD(kd, addr, &amap))
- return NULL;
+ return (NULL);
offset = va - vme.start;
slot = offset / kd->nbpg + vme.aref.ar_pageoff;
/* sanity-check slot number */
if (slot > amap.am_nslot)
- return NULL;
+ return (NULL);
addr = (u_long)amap.am_anon + (offset / kd->nbpg) * sizeof(anonp);
if (KREAD(kd, addr, &anonp))
- return NULL;
+ return (NULL);
addr = (u_long)anonp;
if (KREAD(kd, addr, &anon))
- return NULL;
+ return (NULL);
addr = (u_long)anon.u.an_page;
if (addr) {
if (KREAD(kd, addr, &pg))
- return NULL;
+ return (NULL);
- if (_kvm_pread(kd, kd->pmfd, (void *)kd->swapspc, (size_t)kd->nbpg, (off_t)pg.phys_addr) != kd->nbpg) {
- return NULL;
- }
+ if (_kvm_pread(kd, kd->pmfd, (void *)kd->swapspc,
+ (size_t)kd->nbpg, (off_t)pg.phys_addr) != kd->nbpg)
+ return (NULL);
} else {
- if (_kvm_pread(kd, kd->swfd, (void *)kd->swapspc, (size_t)kd->nbpg, (off_t)(anon.an_swslot * kd->nbpg)) != kd->nbpg) {
- return NULL;
- }
+ if (_kvm_pread(kd, kd->swfd, (void *)kd->swapspc,
+ (size_t)kd->nbpg,
+ (off_t)(anon.an_swslot * kd->nbpg)) != kd->nbpg)
+ return (NULL);
}
/* Found the page. */
@@ -255,11 +250,7 @@ _kvm_ureadm(kd, p, va, cnt)
}
char *
-_kvm_uread(kd, p, va, cnt)
- kvm_t *kd;
- const struct proc *p;
- u_long va;
- u_long *cnt;
+_kvm_uread(kvm_t *kd, const struct proc *p, u_long va, u_long *cnt)
{
struct miniproc mp;
@@ -272,19 +263,15 @@ _kvm_uread(kd, p, va, cnt)
* at most maxcnt procs.
*/
static int
-kvm_proclist(kd, what, arg, p, bp, maxcnt)
- kvm_t *kd;
- int what, arg;
- struct proc *p;
- struct kinfo_proc *bp;
- int maxcnt;
+kvm_proclist(kvm_t *kd, int what, int arg, struct proc *p,
+ struct kinfo_proc *bp, int maxcnt)
{
- int cnt = 0;
+ struct session sess;
struct eproc eproc;
+ struct proc proc;
struct pgrp pgrp;
- struct session sess;
struct tty tty;
- struct proc proc;
+ int cnt = 0;
for (; cnt < maxcnt && p != NULL; p = proc.p_list.le_next) {
if (KREAD(kd, (u_long)p, &proc)) {
@@ -293,10 +280,9 @@ kvm_proclist(kd, what, arg, p, bp, maxcnt)
}
if (KREAD(kd, (u_long)proc.p_cred, &eproc.e_pcred) == 0)
KREAD(kd, (u_long)eproc.e_pcred.pc_ucred,
- &eproc.e_ucred);
+ &eproc.e_ucred);
- switch(what) {
-
+ switch (what) {
case KERN_PROC_PID:
if (proc.p_pid != (pid_t)arg)
continue;
@@ -332,21 +318,21 @@ kvm_proclist(kd, what, arg, p, bp, maxcnt)
eproc.e_paddr = p;
if (KREAD(kd, (u_long)proc.p_pgrp, &pgrp)) {
_kvm_err(kd, kd->program, "can't read pgrp at %x",
- proc.p_pgrp);
+ proc.p_pgrp);
return (-1);
}
eproc.e_sess = pgrp.pg_session;
eproc.e_pgid = pgrp.pg_id;
eproc.e_jobc = pgrp.pg_jobc;
if (KREAD(kd, (u_long)pgrp.pg_session, &sess)) {
- _kvm_err(kd, kd->program, "can't read session at %x",
- pgrp.pg_session);
+ _kvm_err(kd, kd->program, "can't read session at %x",
+ pgrp.pg_session);
return (-1);
}
if ((proc.p_flag & P_CONTROLT) && sess.s_ttyp != NULL) {
if (KREAD(kd, (u_long)sess.s_ttyp, &tty)) {
_kvm_err(kd, kd->program,
- "can't read tty at %x", sess.s_ttyp);
+ "can't read tty at %x", sess.s_ttyp);
return (-1);
}
eproc.e_tdev = tty.t_dev;
@@ -354,8 +340,8 @@ kvm_proclist(kd, what, arg, p, bp, maxcnt)
if (tty.t_pgrp != NULL) {
if (KREAD(kd, (u_long)tty.t_pgrp, &pgrp)) {
_kvm_err(kd, kd->program,
- "can't read tpgrp at &x",
- tty.t_pgrp);
+ "can't read tpgrp at &x",
+ tty.t_pgrp);
return (-1);
}
eproc.e_tpgid = pgrp.pg_id;
@@ -367,7 +353,7 @@ kvm_proclist(kd, what, arg, p, bp, maxcnt)
if (sess.s_leader == p)
eproc.e_flag |= EPROC_SLEADER;
if (proc.p_wmesg)
- (void)kvm_read(kd, (u_long)proc.p_wmesg,
+ (void)kvm_read(kd, (u_long)proc.p_wmesg,
eproc.e_wmesg, WMESGLEN);
(void)kvm_read(kd, (u_long)proc.p_vmspace,
@@ -377,15 +363,14 @@ kvm_proclist(kd, what, arg, p, bp, maxcnt)
eproc.e_xccount = eproc.e_xswrss = 0;
switch (what) {
-
case KERN_PROC_PGRP:
if (eproc.e_pgid != (pid_t)arg)
continue;
break;
case KERN_PROC_TTY:
- if ((proc.p_flag & P_CONTROLT) == 0 ||
- eproc.e_tdev != (dev_t)arg)
+ if ((proc.p_flag & P_CONTROLT) == 0 ||
+ eproc.e_tdev != (dev_t)arg)
continue;
break;
}
@@ -402,16 +387,12 @@ kvm_proclist(kd, what, arg, p, bp, maxcnt)
* Return number of procs read. maxcnt is the max we will read.
*/
static int
-kvm_deadprocs(kd, what, arg, a_allproc, a_zombproc, maxcnt)
- kvm_t *kd;
- int what, arg;
- u_long a_allproc;
- u_long a_zombproc;
- int maxcnt;
+kvm_deadprocs(kvm_t *kd, int what, int arg, u_long a_allproc,
+ u_long a_zombproc, int maxcnt)
{
struct kinfo_proc *bp = kd->procbase;
- int acnt, zcnt;
struct proc *p;
+ int acnt, zcnt;
if (KREAD(kd, a_allproc, &p)) {
_kvm_err(kd, kd->program, "cannot read allproc");
@@ -433,18 +414,14 @@ kvm_deadprocs(kd, what, arg, a_allproc, a_zombproc, maxcnt)
}
struct kinfo_proc2 *
-kvm_getproc2(kd, op, arg, esize, cnt)
- kvm_t *kd;
- int op, arg;
- size_t esize;
- int *cnt;
+kvm_getproc2(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
{
- size_t size;
int mib[6], st, nprocs;
struct user user;
+ size_t size;
if (esize < 0)
- return NULL;
+ return (NULL);
if (kd->procbase2 != NULL) {
free(kd->procbase2);
@@ -466,28 +443,28 @@ kvm_getproc2(kd, op, arg, esize, cnt)
st = sysctl(mib, 6, NULL, &size, NULL, 0);
if (st == -1) {
_kvm_syserr(kd, kd->program, "kvm_getproc2");
- return NULL;
+ return (NULL);
}
mib[5] = size / esize;
kd->procbase2 = (struct kinfo_proc2 *)_kvm_malloc(kd, size);
if (kd->procbase2 == 0)
- return NULL;
+ return (NULL);
st = sysctl(mib, 6, kd->procbase2, &size, NULL, 0);
if (st == -1) {
_kvm_syserr(kd, kd->program, "kvm_getproc2");
- return NULL;
+ return (NULL);
}
nprocs = size / esize;
} else {
- char *kp2c;
- struct kinfo_proc *kp;
struct kinfo_proc2 kp2, *kp2p;
+ struct kinfo_proc *kp;
+ char *kp2c;
int i;
kp = kvm_getprocs(kd, op, arg, &nprocs);
if (kp == NULL)
- return NULL;
+ return (NULL);
kd->procbase2 = _kvm_malloc(kd, nprocs * esize);
kp2c = (char *)kd->procbase2;
@@ -530,7 +507,8 @@ kvm_getproc2(kd, op, arg, esize, cnt)
kp2p->p_rgid = kp->kp_eproc.e_pcred.p_rgid;
memcpy(kp2p->p_groups, kp->kp_eproc.e_ucred.cr_groups,
- MIN(sizeof(kp2p->p_groups), sizeof(kp->kp_eproc.e_ucred.cr_groups)));
+ MIN(sizeof(kp2p->p_groups),
+ sizeof(kp->kp_eproc.e_ucred.cr_groups)));
kp2p->p_ngroups = kp->kp_eproc.e_ucred.cr_ngroups;
kp2p->p_jobc = kp->kp_eproc.e_jobc;
@@ -572,10 +550,12 @@ kvm_getproc2(kd, op, arg, esize, cnt)
strncpy(kp2p->p_comm, kp->kp_proc.p_comm,
MIN(sizeof(kp2p->p_comm), sizeof(kp->kp_proc.p_comm)));
- strncpy(kp2p->p_wmesg, kp->kp_eproc.e_wmesg, sizeof(kp2p->p_wmesg));
+ strncpy(kp2p->p_wmesg, kp->kp_eproc.e_wmesg,
+ sizeof(kp2p->p_wmesg));
kp2p->p_wchan = PTRTOINT64(kp->kp_proc.p_wchan);
- strncpy(kp2p->p_login, kp->kp_eproc.e_login, sizeof(kp2p->p_login));
+ strncpy(kp2p->p_login, kp->kp_eproc.e_login,
+ sizeof(kp2p->p_login));
kp2p->p_vm_rssize = kp->kp_eproc.e_xrssize;
kp2p->p_vm_tsize = kp->kp_eproc.e_vm.vm_tsize;
@@ -613,9 +593,11 @@ kvm_getproc2(kd, op, arg, esize, cnt)
kp2p->p_uru_nvcsw = user.u_stats.p_ru.ru_nvcsw;
kp2p->p_uru_nivcsw = user.u_stats.p_ru.ru_nivcsw;
- kp2p->p_uctime_sec = user.u_stats.p_cru.ru_utime.tv_sec +
+ kp2p->p_uctime_sec =
+ user.u_stats.p_cru.ru_utime.tv_sec +
user.u_stats.p_cru.ru_stime.tv_sec;
- kp2p->p_uctime_usec = user.u_stats.p_cru.ru_utime.tv_usec +
+ kp2p->p_uctime_usec =
+ user.u_stats.p_cru.ru_utime.tv_usec +
user.u_stats.p_cru.ru_stime.tv_usec;
}
@@ -630,17 +612,14 @@ kvm_getproc2(kd, op, arg, esize, cnt)
}
struct kinfo_proc *
-kvm_getprocs(kd, op, arg, cnt)
- kvm_t *kd;
- int op, arg;
- int *cnt;
+kvm_getprocs(kvm_t *kd, int op, int arg, int *cnt)
{
- size_t size;
int mib[4], st, nprocs;
+ size_t size;
if (kd->procbase != 0) {
free((void *)kd->procbase);
- /*
+ /*
* Clear this pointer in case this call fails. Otherwise,
* kvm_close() will free it again.
*/
@@ -667,8 +646,8 @@ kvm_getprocs(kd, op, arg, cnt)
}
if (size % sizeof(struct kinfo_proc) != 0) {
_kvm_err(kd, kd->program,
- "proc size mismatch (%d total, %d chunks)",
- size, sizeof(struct kinfo_proc));
+ "proc size mismatch (%d total, %d chunks)",
+ size, sizeof(struct kinfo_proc));
return (0);
}
nprocs = size / sizeof(struct kinfo_proc);
@@ -685,7 +664,7 @@ kvm_getprocs(kd, op, arg, cnt)
for (p = nl; p->n_type != 0; ++p)
;
_kvm_err(kd, kd->program,
- "%s: no such symbol", p->n_name);
+ "%s: no such symbol", p->n_name);
return (0);
}
if (KREAD(kd, nl[0].n_value, &nprocs)) {
@@ -698,7 +677,7 @@ kvm_getprocs(kd, op, arg, cnt)
return (0);
nprocs = kvm_deadprocs(kd, op, arg, nl[1].n_value,
- nl[2].n_value, nprocs);
+ nl[2].n_value, nprocs);
#ifdef notdef
size = nprocs * sizeof(struct kinfo_proc);
(void)realloc(kd->procbase, size);
@@ -709,8 +688,7 @@ kvm_getprocs(kd, op, arg, cnt)
}
void
-_kvm_freeprocs(kd)
- kvm_t *kd;
+_kvm_freeprocs(kvm_t *kd)
{
if (kd->procbase) {
free(kd->procbase);
@@ -719,10 +697,7 @@ _kvm_freeprocs(kd)
}
void *
-_kvm_realloc(kd, p, n)
- kvm_t *kd;
- void *p;
- size_t n;
+_kvm_realloc(kvm_t *kd, void *p, size_t n)
{
void *np = (void *)realloc(p, n);
@@ -733,22 +708,17 @@ _kvm_realloc(kd, p, n)
/*
* Read in an argument vector from the user address space of process p.
- * addr if the user-space base address of narg null-terminated contiguous
+ * addr if the user-space base address of narg null-terminated contiguous
* strings. This is used to read in both the command arguments and
* environment strings. Read at most maxcnt characters of strings.
*/
static char **
-kvm_argv(kd, p, addr, narg, maxcnt)
- kvm_t *kd;
- const struct miniproc *p;
- u_long addr;
- int narg;
- int maxcnt;
+kvm_argv(kvm_t *kd, const struct miniproc *p, u_long addr, int narg,
+ int maxcnt)
{
- char *np, *cp, *ep, *ap;
+ char *np, *cp, *ep, *ap, **argv;
u_long oaddr = -1;
int len, cc;
- char **argv;
/*
* Check that there aren't an unreasonable number of agruments,
@@ -762,14 +732,14 @@ kvm_argv(kd, p, addr, narg, maxcnt)
* Try to avoid reallocs.
*/
kd->argc = MAX(narg + 1, 32);
- kd->argv = (char **)_kvm_malloc(kd, kd->argc *
- sizeof(*kd->argv));
+ kd->argv = (char **)_kvm_malloc(kd, kd->argc *
+ sizeof(*kd->argv));
if (kd->argv == 0)
return (0);
} else if (narg + 1 > kd->argc) {
kd->argc = MAX(2 * kd->argc, narg + 1);
- kd->argv = (char **)_kvm_realloc(kd, kd->argv, kd->argc *
- sizeof(*kd->argv));
+ kd->argv = (char **)_kvm_realloc(kd, kd->argv, kd->argc *
+ sizeof(*kd->argv));
if (kd->argv == 0)
return (0);
}
@@ -790,6 +760,7 @@ kvm_argv(kd, p, addr, narg, maxcnt)
ap = np = kd->argspc;
argv = kd->argv;
len = 0;
+
/*
* Loop over pages, filling in the argument vector.
*/
@@ -816,7 +787,7 @@ kvm_argv(kd, p, addr, narg, maxcnt)
kd->arglen *= 2;
kd->argspc = (char *)_kvm_realloc(kd, kd->argspc,
- kd->arglen);
+ kd->arglen);
if (kd->argspc == 0)
return (0);
/*
@@ -855,20 +826,14 @@ kvm_argv(kd, p, addr, narg, maxcnt)
}
static void
-ps_str_a(p, addr, n)
- struct ps_strings *p;
- u_long *addr;
- int *n;
+ps_str_a(struct ps_strings *p, u_long *addr, int *n)
{
*addr = (u_long)p->ps_argvstr;
*n = p->ps_nargvstr;
}
static void
-ps_str_e(p, addr, n)
- struct ps_strings *p;
- u_long *addr;
- int *n;
+ps_str_e(struct ps_strings *p, u_long *addr, int *n)
{
*addr = (u_long)p->ps_envstr;
*n = p->ps_nenvstr;
@@ -880,9 +845,7 @@ ps_str_e(p, addr, n)
* being wrong are very low.
*/
static int
-proc_verify(kd, p)
- kvm_t *kd;
- const struct miniproc *p;
+proc_verify(kvm_t *kd, const struct miniproc *p)
{
struct proc kernproc;
@@ -890,25 +853,22 @@ proc_verify(kd, p)
* Just read in the whole proc. It's not that big relative
* to the cost of the read system call.
*/
- if (kvm_read(kd, (u_long)p->p_paddr, &kernproc, sizeof(kernproc)) !=
+ if (kvm_read(kd, (u_long)p->p_paddr, &kernproc, sizeof(kernproc)) !=
sizeof(kernproc))
return (0);
return (p->p_pid == kernproc.p_pid &&
- (kernproc.p_stat != SZOMB || p->p_stat == SZOMB));
+ (kernproc.p_stat != SZOMB || p->p_stat == SZOMB));
}
static char **
-kvm_doargv(kd, p, nchr, info)
- kvm_t *kd;
- const struct miniproc *p;
- int nchr;
- void (*info)(struct ps_strings *, u_long *, int *);
+kvm_doargv(kvm_t *kd, const struct miniproc *p, int nchr,
+ void (*info)(struct ps_strings *, u_long *, int *))
{
- char **ap;
+ static struct ps_strings *ps;
+ struct ps_strings arginfo;
u_long addr;
+ char **ap;
int cnt;
- struct ps_strings arginfo;
- static struct ps_strings *ps;
if (ps == NULL) {
struct _ps_strings _ps;
@@ -925,9 +885,9 @@ kvm_doargv(kd, p, nchr, info)
/*
* Pointers are stored at the top of the user stack.
*/
- if (p->p_stat == SZOMB ||
+ if (p->p_stat == SZOMB ||
kvm_ureadm(kd, p, (u_long)ps, (char *)&arginfo,
- sizeof(arginfo)) != sizeof(arginfo))
+ sizeof(arginfo)) != sizeof(arginfo))
return (0);
(*info)(&arginfo, &addr, &cnt);
@@ -945,9 +905,8 @@ kvm_doargv(kd, p, nchr, info)
static char **
kvm_arg_sysctl(kvm_t *kd, pid_t pid, int nchr, int env)
{
- int mib[4];
size_t len, orglen;
- int ret;
+ int mib[4], ret;
char *buf;
orglen = kd->nbpg;
@@ -991,10 +950,7 @@ again:
* Get the command args. This code is now machine independent.
*/
char **
-kvm_getargv(kd, kp, nchr)
- kvm_t *kd;
- const struct kinfo_proc *kp;
- int nchr;
+kvm_getargv(kvm_t *kd, const struct kinfo_proc *kp, int nchr)
{
struct miniproc p;
@@ -1005,10 +961,7 @@ kvm_getargv(kd, kp, nchr)
}
char **
-kvm_getenvv(kd, kp, nchr)
- kvm_t *kd;
- const struct kinfo_proc *kp;
- int nchr;
+kvm_getenvv(kvm_t *kd, const struct kinfo_proc *kp, int nchr)
{
struct miniproc p;
@@ -1019,10 +972,7 @@ kvm_getenvv(kd, kp, nchr)
}
char **
-kvm_getargv2(kd, kp, nchr)
- kvm_t *kd;
- const struct kinfo_proc2 *kp;
- int nchr;
+kvm_getargv2(kvm_t *kd, const struct kinfo_proc2 *kp, int nchr)
{
struct miniproc p;
@@ -1033,10 +983,7 @@ kvm_getargv2(kd, kp, nchr)
}
char **
-kvm_getenvv2(kd, kp, nchr)
- kvm_t *kd;
- const struct kinfo_proc2 *kp;
- int nchr;
+kvm_getenvv2(kvm_t *kd, const struct kinfo_proc2 *kp, int nchr)
{
struct miniproc p;
@@ -1050,20 +997,15 @@ kvm_getenvv2(kd, kp, nchr)
* Read from user space. The user context is given by p.
*/
static ssize_t
-kvm_ureadm(kd, p, uva, buf, len)
- kvm_t *kd;
- const struct miniproc *p;
- u_long uva;
- char *buf;
- size_t len;
+kvm_ureadm(kvm_t *kd, const struct miniproc *p, u_long uva, char *buf,
+ size_t len)
{
- char *cp;
+ char *cp = buf;
- cp = buf;
while (len > 0) {
+ u_long cnt;
size_t cc;
char *dp;
- u_long cnt;
dp = _kvm_ureadm(kd, p, uva, &cnt);
if (dp == 0) {
@@ -1080,12 +1022,8 @@ kvm_ureadm(kd, p, uva, buf, len)
}
ssize_t
-kvm_uread(kd, p, uva, buf, len)
- kvm_t *kd;
- const struct proc *p;
- u_long uva;
- char *buf;
- size_t len;
+kvm_uread(kvm_t *kd, const struct proc *p, u_long uva, char *buf,
+ size_t len)
{
struct miniproc mp;
diff --git a/lib/libkvm/kvm_sparc.c b/lib/libkvm/kvm_sparc.c
index 081d8c3e723..22e0795b7ef 100644
--- a/lib/libkvm/kvm_sparc.c
+++ b/lib/libkvm/kvm_sparc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_sparc.c,v 1.9 2003/06/02 20:18:41 millert Exp $ */
+/* $OpenBSD: kvm_sparc.c,v 1.10 2004/06/15 03:52:59 deraadt Exp $ */
/* $NetBSD: kvm_sparc.c,v 1.9 1996/04/01 19:23:03 cgd Exp $ */
/*-
@@ -38,12 +38,12 @@
#if 0
static char sccsid[] = "@(#)kvm_sparc.c 8.1 (Berkeley) 6/4/93";
#else
-static char *rcsid = "$OpenBSD: kvm_sparc.c,v 1.9 2003/06/02 20:18:41 millert Exp $";
+static char *rcsid = "$OpenBSD: kvm_sparc.c,v 1.10 2004/06/15 03:52:59 deraadt Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
/*
- * Sparc machine dependent routines for kvm. Hopefully, the forthcoming
+ * Sparc machine dependent routines for kvm. Hopefully, the forthcoming
* vm code will one day obsolete this module.
*/
@@ -81,12 +81,11 @@ static int nptesg; /* [sun4/sun4c] only */
void
-_kvm_freevtop(kd)
- kvm_t *kd;
+_kvm_freevtop(kvm_t *kd)
{
- if (kd->vmst != 0) {
+ if (kd->vmst != NULL) {
_kvm_err(kd, kd->program, "_kvm_freevtop: internal error");
- kd->vmst = 0;
+ kd->vmst = NULL;
}
}
@@ -96,8 +95,7 @@ _kvm_freevtop(kd)
* front of the crash dump by pmap_dumpmmu().
*/
int
-_kvm_initvtop(kd)
- kvm_t *kd;
+_kvm_initvtop(kvm_t *kd)
{
cpu_kcore_hdr_t *cpup = kd->cpu_data;
@@ -122,38 +120,30 @@ _kvm_initvtop(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
+ * 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;
+_kvm_kvatop(kvm_t *kd, u_long va, u_long *pa)
{
if (cputyp == -1)
if (_kvm_initvtop(kd) != 0)
- return (-1);
+ return (-1);
- return ((cputyp == CPU_SUN4M)
- ? _kvm_kvatop4m(kd, va, pa)
- : _kvm_kvatop44c(kd, va, pa));
+ return ((cputyp == CPU_SUN4M) ? _kvm_kvatop4m(kd, va, pa) :
+ _kvm_kvatop44c(kd, va, pa));
}
/*
* (note: sun4 3-level MMU not yet supported)
*/
int
-_kvm_kvatop44c(kd, va, pa)
- kvm_t *kd;
- u_long va;
- u_long *pa;
+_kvm_kvatop44c(kvm_t *kd, u_long va, u_long *pa)
{
- register int vr, vs, pte;
cpu_kcore_hdr_t *cpup = kd->cpu_data;
+ int vr, vs, pte, *ptes;
struct regmap *rp;
struct segmap *sp;
- int *ptes;
if (va < KERNBASE)
goto err;
@@ -177,7 +167,7 @@ _kvm_kvatop44c(kd, va, pa)
goto err;
pte = ptes[sp->sg_pmeg * nptesg + VA_VPG(va)];
if ((pte & PG_V) != 0) {
- register long p, off = VA_OFF(va);
+ long p, off = VA_OFF(va);
p = (pte & PG_PFNUM) << pgshift;
*pa = p + off;
@@ -189,17 +179,13 @@ err:
}
int
-_kvm_kvatop4m(kd, va, pa)
- kvm_t *kd;
- u_long va;
- u_long *pa;
+_kvm_kvatop4m(kvm_t *kd, u_long va, u_long *pa)
{
cpu_kcore_hdr_t *cpup = kd->cpu_data;
- register int vr, vs;
- int pte;
- off_t foff;
struct regmap *rp;
struct segmap *sp;
+ int vr, vs, pte;
+ off_t foff;
if (va < KERNBASE)
goto err;
@@ -210,7 +196,6 @@ _kvm_kvatop4m(kd, va, pa)
* [alignment]
* phys_ram_seg_t[cpup->nmemseg];
*/
-
vr = VA_VREG(va);
vs = VA_VSEG(va);
@@ -229,7 +214,7 @@ _kvm_kvatop4m(kd, va, pa)
}
if ((pte & SRMMU_TETYPE) == SRMMU_TEPTE) {
- register long p, off = VA_OFF(va);
+ long p, off = VA_OFF(va);
p = (pte & SRMMU_PPNMASK) << SRMMU_PPNPASHIFT;
*pa = p + off;
@@ -240,13 +225,11 @@ err:
return (0);
}
-/*
+/*
* Translate a physical address to a file-offset in the crash-dump.
- */
+ */
off_t
-_kvm_pa2off(kd, pa)
- kvm_t *kd;
- u_long pa;
+_kvm_pa2off(kvm_t *kd, u_long pa)
{
cpu_kcore_hdr_t *cpup = kd->cpu_data;
phys_ram_seg_t *mp;
diff --git a/lib/libkvm/kvm_sparc64.c b/lib/libkvm/kvm_sparc64.c
index ce4fc3b5731..59fa0a9ffc9 100644
--- a/lib/libkvm/kvm_sparc64.c
+++ b/lib/libkvm/kvm_sparc64.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_sparc64.c,v 1.4 2003/06/02 20:18:41 millert Exp $ */
+/* $OpenBSD: kvm_sparc64.c,v 1.5 2004/06/15 03:52:59 deraadt Exp $ */
/* $NetBSD: kvm_sparc64.c,v 1.7 2001/08/05 03:33:15 matt Exp $ */
/*-
@@ -66,12 +66,11 @@
int _kvm_kvatop(kvm_t *, u_long, u_long *);
void
-_kvm_freevtop(kd)
- kvm_t *kd;
+_kvm_freevtop(kvm_t *kd)
{
- if (kd->vmst != 0) {
+ if (kd->vmst != NULL) {
_kvm_err(kd, kd->program, "_kvm_freevtop: internal error");
- kd->vmst = 0;
+ kd->vmst = NULL;
}
}
@@ -83,8 +82,7 @@ _kvm_freevtop(kd)
* We should read in and cache the ksegs here to speed up operations...
*/
int
-_kvm_initvtop(kd)
- kvm_t *kd;
+_kvm_initvtop(kvm_t *kd)
{
kd->nbpg = 0x2000;
@@ -98,10 +96,7 @@ _kvm_initvtop(kd)
* physical address. This routine is used only for crashdumps.
*/
int
-_kvm_kvatop(kd, va, pa)
- kvm_t *kd;
- u_long va;
- u_long *pa;
+_kvm_kvatop(kvm_t *kd, u_long va, u_long *pa)
{
cpu_kcore_hdr_t *cpup = kd->cpu_data;
u_long kernbase = cpup->kernbase;
@@ -134,8 +129,7 @@ _kvm_kvatop(kd, va, pa)
*/
pseg = (uint64_t *)(u_long)cpup->segmapoffset;
if (pread(kd->pmfd, &pdir, sizeof(pdir),
- _kvm_pa2off(kd, (u_long)&pseg[va_to_seg(va)]))
- != sizeof(pdir)) {
+ _kvm_pa2off(kd, (u_long)&pseg[va_to_seg(va)])) != sizeof(pdir)) {
_kvm_syserr(kd, 0, "could not read L1 PTE");
goto lose;
}
@@ -146,8 +140,7 @@ _kvm_kvatop(kd, va, pa)
}
if (pread(kd->pmfd, &ptbl, sizeof(ptbl),
- _kvm_pa2off(kd, (u_long)&pdir[va_to_dir(va)]))
- != sizeof(ptbl)) {
+ _kvm_pa2off(kd, (u_long)&pdir[va_to_dir(va)])) != sizeof(ptbl)) {
_kvm_syserr(kd, 0, "could not read L2 PTE");
goto lose;
}
@@ -158,8 +151,7 @@ _kvm_kvatop(kd, va, pa)
}
if (pread(kd->pmfd, &data, sizeof(data),
- _kvm_pa2off(kd, (u_long)&ptbl[va_to_pte(va)]))
- != sizeof(data)) {
+ _kvm_pa2off(kd, (u_long)&ptbl[va_to_pte(va)])) != sizeof(data)) {
_kvm_syserr(kd, 0, "could not read TTE");
goto lose;
}
@@ -168,8 +160,8 @@ _kvm_kvatop(kd, va, pa)
_kvm_err(kd, 0, "invalid L2 TTE");
goto lose;
}
-
- /*
+
+ /*
* Calculate page offsets and things.
*
* XXXX -- We could support multiple page sizes.
@@ -179,9 +171,8 @@ _kvm_kvatop(kd, va, pa)
*pa = data + va;
/*
- * Parse and trnslate our TTE.
+ * Parse and translate our TTE.
*/
-
return (kd->nbpg - va);
lose:
@@ -195,9 +186,7 @@ lose:
* Translate a physical address to a file-offset in the crash-dump.
*/
off_t
-_kvm_pa2off(kd, pa)
- kvm_t *kd;
- u_long pa;
+_kvm_pa2off(kvm_t *kd, u_long pa)
{
cpu_kcore_hdr_t *cpup = kd->cpu_data;
phys_ram_seg_t *mp;
@@ -226,4 +215,3 @@ _kvm_pa2off(kd, pa)
return (kd->dump_off + off + pa - mp->start);
}
-
diff --git a/lib/libkvm/kvm_vax.c b/lib/libkvm/kvm_vax.c
index 4d7cd340ade..3ec966aa7d8 100644
--- a/lib/libkvm/kvm_vax.c
+++ b/lib/libkvm/kvm_vax.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_vax.c,v 1.8 2003/06/02 20:18:41 millert Exp $ */
+/* $OpenBSD: kvm_vax.c,v 1.9 2004/06/15 03:52:59 deraadt Exp $ */
/* $NetBSD: kvm_vax.c,v 1.3 1996/03/18 22:34:06 thorpej Exp $ */
/*-
@@ -63,22 +63,21 @@ struct vmstate {
};
void
-_kvm_freevtop(kd)
- kvm_t *kd;
+_kvm_freevtop(kvm_t *kd)
{
- if (kd->vmst != 0)
+ if (kd->vmst != NULL) {
free(kd->vmst);
+ kd->vmst = NULL;
+ }
}
int
-_kvm_initvtop(kd)
- kvm_t *kd;
+_kvm_initvtop(kvm_t *kd)
{
- register int i;
- register int off;
- register struct vmstate *vm;
- struct stat st;
struct nlist nlist[2];
+ struct vmstate *vm;
+ struct stat st;
+ int i, off;
vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm));
if (vm == 0)
@@ -106,16 +105,13 @@ _kvm_initvtop(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
+ * 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;
+_kvm_kvatop(kvm_t *kd, u_long va, u_long *pa)
{
- register u_long end;
+ u_long end;
if (va < KERNBASE) {
_kvm_err(kd, 0, "invalid address (%lx<%lx)", va, KERNBASE);
@@ -132,14 +128,12 @@ _kvm_kvatop(kd, va, pa)
return (end - va);
}
-/*
+/*
* Translate a physical address to an offset in the crash dump
* XXX crashdumps not working yet anyway
*/
off_t
-_kvm_pa2off(kd, pa)
- kvm_t *kd;
- u_long pa;
+_kvm_pa2off(kvm_t *kd, u_long pa)
{
- return(kd->dump_off+pa);
+ return (kd->dump_off+pa);
}