Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libkvm Add kvm interface to the new sysctls:
details: https://anonhg.NetBSD.org/src/rev/6dfe77f2a430
branches: trunk
changeset: 486583:6dfe77f2a430
user: simonb <simonb%NetBSD.org@localhost>
date: Fri May 26 02:42:21 2000 +0000
description:
Add kvm interface to the new sysctls:
kvm_getproc2() -> sysctl(KERN_PROC2)
kvm_getargv2() -> sysctl(KERN_PROC_ARGS, KERN_PROC_ARGV)
kvm_getenvv2() -> sysctl(KERN_PROC_ARGS, KERN_PROC_ENV)
Add new KVM_NO_FILES flag to kvm_open*() - set up enough state to
use the above calls without having to open any kernel files.
XXX: kvm_getprocs.3 and kvm_open.3 to be updated soon.
diffstat:
lib/libkvm/kvm.c | 26 ++-
lib/libkvm/kvm_file.c | 6 +-
lib/libkvm/kvm_private.h | 14 +-
lib/libkvm/kvm_proc.c | 501 +++++++++++++++++++++++++++++++++++++++++-----
lib/libkvm/shlib_version | 4 +-
5 files changed, 479 insertions(+), 72 deletions(-)
diffs (truncated from 955 to 300 lines):
diff -r 6985f71ed241 -r 6dfe77f2a430 lib/libkvm/kvm.c
--- a/lib/libkvm/kvm.c Fri May 26 02:34:01 2000 +0000
+++ b/lib/libkvm/kvm.c Fri May 26 02:42:21 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kvm.c,v 1.64 1999/07/02 15:28:49 simonb Exp $ */
+/* $NetBSD: kvm.c,v 1.65 2000/05/26 02:42:21 simonb Exp $ */
/*-
* Copyright (c) 1989, 1992, 1993
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)kvm.c 8.2 (Berkeley) 2/13/94";
#else
-__RCSID("$NetBSD: kvm.c,v 1.64 1999/07/02 15:28:49 simonb Exp $");
+__RCSID("$NetBSD: kvm.c,v 1.65 2000/05/26 02:42:21 simonb Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -235,7 +235,9 @@
kd->vmfd = -1;
kd->swfd = -1;
kd->nlfd = -1;
+ kd->alive = KVM_ALIVE_DEAD;
kd->procbase = 0;
+ kd->procbase2 = 0;
kd->nbpg = getpagesize();
kd->swapspc = 0;
kd->argspc = 0;
@@ -248,6 +250,11 @@
kd->cpu_data = 0;
kd->dump_off = 0;
+ if (flag & KVM_NO_FILES) {
+ kd->alive = KVM_ALIVE_SYSCTL;
+ return(kd);
+ }
+
/*
* Call the MD open hook. This sets:
* usrstack, min_uva, max_uva
@@ -297,6 +304,7 @@
_kvm_syserr(kd, kd->program, "%s", _PATH_KMEM);
goto failed;
}
+ kd->alive = KVM_ALIVE_FILES;
if ((kd->swfd = open(sf, flag, 0)) < 0) {
_kvm_syserr(kd, kd->program, "%s", sf);
goto failed;
@@ -688,6 +696,8 @@
free((void *)kd->kcore_hdr);
if (kd->procbase != 0)
free((void *)kd->procbase);
+ if (kd->procbase2 != 0)
+ free((void *)kd->procbase2);
if (kd->swapspc != 0)
free((void *)kd->swapspc);
if (kd->argspc != 0)
@@ -860,7 +870,7 @@
int cc;
void *cp;
- if (ISALIVE(kd)) {
+ if (ISKMEM(kd)) {
/*
* We're using /dev/kmem. Just read straight from the
* device and let the active kernel do the address translation.
@@ -873,6 +883,10 @@
} else if (cc < len)
_kvm_err(kd, kd->program, "short read");
return (cc);
+ } else if (ISSYSCTL(kd)) {
+ _kvm_err(kd, kd->program, "kvm_open called with KVM_NO_FILES, "
+ "can't use kvm_read");
+ return (-1);
} else {
if ((kd->kcore_hdr == NULL) || (kd->cpu_data == NULL)) {
_kvm_err(kd, kd->program, "no valid dump header");
@@ -921,7 +935,7 @@
{
int cc;
- if (ISALIVE(kd)) {
+ if (ISKMEM(kd)) {
/*
* Just like kvm_read, only we write.
*/
@@ -933,6 +947,10 @@
} else if (cc < len)
_kvm_err(kd, kd->program, "short write");
return (cc);
+ } else if (ISSYSCTL(kd)) {
+ _kvm_err(kd, kd->program, "kvm_open called with KVM_NO_FILES, "
+ "can't use kvm_write");
+ return (-1);
} else {
_kvm_err(kd, kd->program,
"kvm_write not implemented for dead kernels");
diff -r 6985f71ed241 -r 6dfe77f2a430 lib/libkvm/kvm_file.c
--- a/lib/libkvm/kvm_file.c Fri May 26 02:34:01 2000 +0000
+++ b/lib/libkvm/kvm_file.c Fri May 26 02:42:21 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kvm_file.c,v 1.14 1999/08/19 05:42:56 cgd Exp $ */
+/* $NetBSD: kvm_file.c,v 1.15 2000/05/26 02:42:22 simonb Exp $ */
/*-
* Copyright (c) 1989, 1992, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)kvm_file.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: kvm_file.c,v 1.14 1999/08/19 05:42:56 cgd Exp $");
+__RCSID("$NetBSD: kvm_file.c,v 1.15 2000/05/26 02:42:22 simonb Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -141,7 +141,7 @@
struct file *fp, *fplim;
struct filelist fhead;
- if (ISALIVE(kd)) {
+ if (ISSYSCTL(kd)) {
size = 0;
mib[0] = CTL_KERN;
mib[1] = KERN_FILE;
diff -r 6985f71ed241 -r 6dfe77f2a430 lib/libkvm/kvm_private.h
--- a/lib/libkvm/kvm_private.h Fri May 26 02:34:01 2000 +0000
+++ b/lib/libkvm/kvm_private.h Fri May 26 02:42:21 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kvm_private.h,v 1.8 1997/08/12 16:27:01 gwr Exp $ */
+/* $NetBSD: kvm_private.h,v 1.9 2000/05/26 02:42:22 simonb Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -49,12 +49,13 @@
char *errp; /* XXX this can probably go away */
char errbuf[_POSIX2_LINE_MAX];
DB *db;
-#define ISALIVE(kd) ((kd)->vmfd >= 0)
int pmfd; /* physical memory file (or crashdump) */
int vmfd; /* virtual memory file (-1 if crashdump) */
int swfd; /* swap file (e.g., /dev/drum) */
int nlfd; /* namelist file (e.g., /vmunix) */
+ char alive; /* live kernel? */
struct kinfo_proc *procbase;
+ struct kinfo_proc2 *procbase2;
u_long usrstack; /* address of end of user stack */
u_long min_uva, max_uva; /* min/max user virtual address */
int nbpg; /* page size */
@@ -88,6 +89,15 @@
int vm_page_hash_mask;
};
+/* Levels of aliveness */
+#define KVM_ALIVE_DEAD 0 /* dead, working from core file */
+#define KVM_ALIVE_FILES 1 /* alive, working from open kmem/drum */
+#define KVM_ALIVE_SYSCTL 2 /* alive, sysctl-type calls only */
+
+#define ISALIVE(kd) ((kd)->alive != KVM_ALIVE_DEAD)
+#define ISKMEM(kd) ((kd)->alive == KVM_ALIVE_FILES)
+#define ISSYSCTL(kd) ((kd)->alive == KVM_ALIVE_SYSCTL || ISKMEM(kd))
+
/*
* Functions used internally by kvm, but across kvm modules.
*/
diff -r 6985f71ed241 -r 6dfe77f2a430 lib/libkvm/kvm_proc.c
--- a/lib/libkvm/kvm_proc.c Fri May 26 02:34:01 2000 +0000
+++ b/lib/libkvm/kvm_proc.c Fri May 26 02:42:21 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kvm_proc.c,v 1.33 2000/04/15 15:52:52 simonb Exp $ */
+/* $NetBSD: kvm_proc.c,v 1.34 2000/05/26 02:42:22 simonb Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
#if 0
static char sccsid[] = "@(#)kvm_proc.c 8.3 (Berkeley) 9/23/93";
#else
-__RCSID("$NetBSD: kvm_proc.c,v 1.33 2000/04/15 15:52:52 simonb Exp $");
+__RCSID("$NetBSD: kvm_proc.c,v 1.34 2000/05/26 02:42:22 simonb Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -116,29 +116,78 @@
#include "kvm_private.h"
+/*
+ * Common info from kinfo_proc and kinfo_proc2 used by helper routines.
+ */
+struct miniproc {
+ struct vmspace *p_vmspace;
+ char p_stat;
+ struct proc *p_paddr;
+ pid_t p_pid;
+};
+
+/*
+ * Convert from struct proc and kinfo_proc{,2} to miniproc.
+ */
+#define PTOMINI(kp, p) \
+ do { \
+ (p)->p_stat = (kp)->p_stat; \
+ (p)->p_pid = (kp)->p_pid; \
+ (p)->p_paddr = NULL; \
+ (p)->p_vmspace = (kp)->p_vmspace; \
+ } while (/*CONSTCOND*/0);
+
+#define KPTOMINI(kp, p) \
+ do { \
+ (p)->p_stat = (kp)->kp_proc.p_stat; \
+ (p)->p_pid = (kp)->kp_proc.p_pid; \
+ (p)->p_paddr = (kp)->kp_eproc.e_paddr; \
+ (p)->p_vmspace = (kp)->kp_proc.p_vmspace; \
+ } while (/*CONSTCOND*/0);
+
+#define KP2TOMINI(kp, p) \
+ do { \
+ (p)->p_stat = (kp)->p_stat; \
+ (p)->p_pid = (kp)->p_pid; \
+ (p)->p_paddr = (void *)(long)(kp)->p_paddr; \
+ (p)->p_vmspace = (void *)(long)(kp)->p_vmspace; \
+ } while (/*CONSTCOND*/0);
+
+
+#define PTRTOINT64(foo) ((u_int64_t)(uintptr_t)(foo))
+
#define KREAD(kd, addr, obj) \
- (kvm_read(kd, addr, (void *)(obj), sizeof(*obj)) != sizeof(*obj))
+ (kvm_read(kd, addr, (obj), sizeof(*obj)) != sizeof(*obj))
-char *_kvm_uread __P((kvm_t *, const struct proc *, u_long, u_long *));
+/* XXX: What uses these two functions? */
+char *_kvm_uread __P((kvm_t *, const struct proc *, u_long,
+ u_long *));
ssize_t kvm_uread __P((kvm_t *, const struct proc *, u_long, char *,
size_t));
-static char **kvm_argv __P((kvm_t *, const struct proc *, u_long, int,
+static char *_kvm_ureadm __P((kvm_t *, const struct miniproc *, u_long,
+ u_long *));
+static ssize_t kvm_ureadm __P((kvm_t *, const struct miniproc *, u_long,
+ char *, size_t));
+
+static char **kvm_argv __P((kvm_t *, const struct miniproc *, u_long, int,
int));
static int kvm_deadprocs __P((kvm_t *, int, int, u_long, u_long, u_long,
int));
-static char **kvm_doargv __P((kvm_t *, const struct kinfo_proc *, int,
+static char **kvm_doargv __P((kvm_t *, const struct miniproc *, int,
void (*)(struct ps_strings *, u_long *, int *)));
+static char **kvm_doargv2 __P((kvm_t *, pid_t, int, int));
static int kvm_proclist __P((kvm_t *, int, int, struct proc *,
struct kinfo_proc *, int));
-static int proc_verify __P((kvm_t *, u_long, const struct proc *));
+static int proc_verify __P((kvm_t *, u_long, const struct miniproc *));
static void ps_str_a __P((struct ps_strings *, u_long *, int *));
static void ps_str_e __P((struct ps_strings *, u_long *, int *));
-char *
-_kvm_uread(kd, p, va, cnt)
+
+static char *
+_kvm_ureadm(kd, p, va, cnt)
kvm_t *kd;
- const struct proc *p;
+ const struct miniproc *p;
u_long va;
u_long *cnt;
{
@@ -154,7 +203,7 @@
if (kd->swapspc == 0) {
kd->swapspc = (char *)_kvm_malloc(kd, (size_t)kd->nbpg);
if (kd->swapspc == 0)
- return (0);
+ return NULL;
}
/*
@@ -166,7 +215,7 @@
addr = head;
while (true) {
if (KREAD(kd, addr, &vme))
- return (0);
+ return NULL;
if (va >= vme.start && va < vme.end &&
vme.aref.ar_amap != NULL)
@@ -174,7 +223,7 @@
addr = (u_long)vme.next;
if (addr == head)
- return (0);
+ return NULL;
}
@@ -207,12 +256,12 @@
if (KREAD(kd, addr, &pg))
return NULL;
Home |
Main Index |
Thread Index |
Old Index