diff options
-rw-r--r-- | lib/libkvm/kvm.c | 75 | ||||
-rw-r--r-- | lib/libkvm/kvm_file.c | 50 | ||||
-rw-r--r-- | lib/libkvm/kvm_getloadavg.c | 5 | ||||
-rw-r--r-- | lib/libkvm/kvm_private.h | 11 | ||||
-rw-r--r-- | lib/libkvm/kvm_proc.c | 20 |
5 files changed, 81 insertions, 80 deletions
diff --git a/lib/libkvm/kvm.c b/lib/libkvm/kvm.c index ebf55567702..393dd5971db 100644 --- a/lib/libkvm/kvm.c +++ b/lib/libkvm/kvm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm.c,v 1.44 2006/03/31 03:09:17 deraadt Exp $ */ +/* $OpenBSD: kvm.c,v 1.45 2006/03/31 03:59:40 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.44 2006/03/31 03:09:17 deraadt Exp $"; +static char *rcsid = "$OpenBSD: kvm.c,v 1.45 2006/03/31 03:59:40 deraadt Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -74,7 +74,7 @@ extern int __fdnlist(int, struct nlist *); static int kvm_dbopen(kvm_t *, const char *); static int _kvm_get_header(kvm_t *); static kvm_t *_kvm_open(kvm_t *, const char *, const char *, const char *, - int, char *); + int, char *); static int clear_gap(kvm_t *, FILE *, int); static int kvm_setfd(kvm_t *); @@ -105,7 +105,7 @@ _kvm_pread(kvm_t *kd, int fd, void *buf, size_t nbytes, off_t offset) * Wrapper around pwrite. */ ssize_t -_kvm_pwrite(kvm_t *kd, int fd, void *buf, size_t nbytes, off_t offset) +_kvm_pwrite(kvm_t *kd, int fd, const void *buf, size_t nbytes, off_t offset) { ssize_t rval; @@ -135,7 +135,7 @@ _kvm_err(kvm_t *kd, const char *program, const char *fmt, ...) (void)fputc('\n', stderr); } else (void)vsnprintf(kd->errbuf, - sizeof(kd->errbuf), (char *)fmt, ap); + sizeof(kd->errbuf), fmt, ap); va_end(ap); } @@ -144,7 +144,7 @@ void _kvm_syserr(kvm_t *kd, const char *program, const char *fmt, ...) { va_list ap; - int n; + size_t n; va_start(ap, fmt); if (program != NULL) { @@ -154,7 +154,7 @@ _kvm_syserr(kvm_t *kd, const char *program, const char *fmt, ...) } else { char *cp = kd->errbuf; - (void)vsnprintf(cp, sizeof(kd->errbuf), (char *)fmt, ap); + (void)vsnprintf(cp, sizeof(kd->errbuf), fmt, ap); n = strlen(cp); (void)snprintf(&cp[n], sizeof(kd->errbuf) - n, ": %s", strerror(errno)); @@ -371,12 +371,13 @@ _kvm_get_header(kvm_t *kd) * Read the CPU segment DATA. */ kd->cpu_dsize = cpu_hdr.c_size; - kd->cpu_data = _kvm_malloc(kd, cpu_hdr.c_size); + kd->cpu_data = _kvm_malloc(kd, (size_t)cpu_hdr.c_size); if (kd->cpu_data == NULL) goto fail; - sz = _kvm_pread(kd, kd->pmfd, kd->cpu_data, cpu_hdr.c_size, (off_t)offset); - if (sz != cpu_hdr.c_size) { + sz = _kvm_pread(kd, kd->pmfd, kd->cpu_data, (size_t)cpu_hdr.c_size, + (off_t)offset); + if (sz != (size_t)cpu_hdr.c_size) { goto fail; } @@ -424,7 +425,8 @@ int kvm_dump_mkheader(kvm_t *kd, off_t dump_off) { kcore_seg_t cpu_hdr; - int hdr_size, sz; + int hdr_size; + ssize_t sz; if (kd->kcore_hdr != NULL) { _kvm_err(kd, kd->program, "already has a dump header"); @@ -457,9 +459,9 @@ kvm_dump_mkheader(kvm_t *kd, off_t dump_off) if (kd->cpu_data == NULL) goto fail; - sz = _kvm_pread(kd, kd->pmfd, kd->cpu_data, cpu_hdr.c_size, + sz = _kvm_pread(kd, kd->pmfd, kd->cpu_data, (size_t)cpu_hdr.c_size, (off_t)dump_off+hdr_size); - if (sz != cpu_hdr.c_size) { + if (sz != (ssize_t)cpu_hdr.c_size) { _kvm_err(kd, 0, "invalid size in cpu_hdr"); goto fail; } @@ -541,7 +543,7 @@ kvm_dump_wrtheader(kvm_t *kd, FILE *fp, int dumpsize) * Write the generic header */ offset = 0; - if (fwrite((void*)kd->kcore_hdr, sizeof(kcore_hdr_t), 1, fp) <= 0) { + if (fwrite(kd->kcore_hdr, sizeof(kcore_hdr_t), 1, fp) < 1) { _kvm_syserr(kd, kd->program, "kvm_dump_wrtheader"); return (-1); } @@ -554,8 +556,8 @@ kvm_dump_wrtheader(kvm_t *kd, FILE *fp, int dumpsize) * Write the cpu header */ CORE_SETMAGIC(seghdr, KCORESEG_MAGIC, 0, CORE_CPU); - seghdr.c_size = ALIGN(kd->cpu_dsize); - if (fwrite((void*)&seghdr, sizeof(seghdr), 1, fp) <= 0) { + seghdr.c_size = (u_long)ALIGN(kd->cpu_dsize); + if (fwrite(&seghdr, sizeof(seghdr), 1, fp) < 1) { _kvm_syserr(kd, kd->program, "kvm_dump_wrtheader"); return (-1); } @@ -564,7 +566,7 @@ kvm_dump_wrtheader(kvm_t *kd, FILE *fp, int dumpsize) if (clear_gap(kd, fp, gap) == -1) return (-1); - if (fwrite((void*)kd->cpu_data, kd->cpu_dsize, 1, fp) <= 0) { + if (fwrite(kd->cpu_data, kd->cpu_dsize, 1, fp) < 1) { _kvm_syserr(kd, kd->program, "kvm_dump_wrtheader"); return (-1); } @@ -578,7 +580,7 @@ kvm_dump_wrtheader(kvm_t *kd, FILE *fp, int dumpsize) */ CORE_SETMAGIC(seghdr, KCORESEG_MAGIC, 0, CORE_DATA); seghdr.c_size = dumpsize; - if (fwrite((void*)&seghdr, sizeof(seghdr), 1, fp) <= 0) { + if (fwrite(&seghdr, sizeof(seghdr), 1, fp) < 1) { _kvm_syserr(kd, kd->program, "kvm_dump_wrtheader"); return (-1); } @@ -670,10 +672,10 @@ kvm_dbopen(kvm_t *kd, const char *uf) char dbversion[_POSIX2_LINE_MAX], kversion[_POSIX2_LINE_MAX]; char dbname[MAXPATHLEN]; struct nlist nitem; - int dbversionlen; + size_t dbversionlen; DBT rec; - uf = basename((char *)uf); + uf = basename(uf); (void)snprintf(dbname, sizeof(dbname), "%skvm_%s.db", _PATH_VARDB, uf); kd->db = dbopen(dbname, O_RDONLY, 0, DB_HASH, NULL); @@ -709,6 +711,7 @@ kvm_dbopen(kvm_t *kd, const char *uf) bcopy(rec.data, dbversion, rec.size); dbversionlen = rec.size; + /* * Read version string from kernel memory. * Since we are dealing with a live kernel, we can call kvm_read() @@ -720,7 +723,7 @@ kvm_dbopen(kvm_t *kd, const char *uf) goto close; if (rec.data == 0 || rec.size != sizeof(struct nlist)) goto close; - bcopy((char *)rec.data, (char *)&nitem, sizeof(nitem)); + bcopy(rec.data, &nitem, sizeof(nitem)); if (kvm_read(kd, (u_long)nitem.n_value, kversion, dbversionlen) != dbversionlen) goto close; @@ -760,7 +763,7 @@ kvm_nlist(kvm_t *kd, struct nlist *nl) */ nvalid = 0; for (p = nl; p->n_name && p->n_name[0]; ++p) { - int len; + size_t len; DBT rec; if ((len = strlen(p->n_name)) > 4096) { @@ -784,10 +787,10 @@ kvm_nlist(kvm_t *kd, struct nlist *nl) /* * Avoid alignment issues. */ - bcopy((char *)&((struct nlist *)rec.data)->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)); + bcopy(&((struct nlist *)rec.data)->n_type, + &p->n_type, sizeof(p->n_type)); + bcopy(&((struct nlist *)rec.data)->n_value, + &p->n_value, sizeof(p->n_value)); } /* * Return the number of entries that weren't found. @@ -798,7 +801,7 @@ kvm_nlist(kvm_t *kd, struct nlist *nl) int kvm_dump_inval(kvm_t *kd) { - struct nlist nlist[2]; + struct nlist nl[2]; u_long x; paddr_t pa; @@ -806,20 +809,20 @@ kvm_dump_inval(kvm_t *kd) _kvm_err(kd, kd->program, "clearing dump on live kernel"); return (-1); } - nlist[0].n_name = "_dumpmag"; - nlist[1].n_name = NULL; + nl[0].n_name = "_dumpmag"; + nl[1].n_name = NULL; - if (kvm_nlist(kd, nlist) == -1) { + if (kvm_nlist(kd, nl) == -1) { _kvm_err(kd, 0, "bad namelist"); return (-1); } - if (nlist[0].n_value == 0) { - _kvm_err(kd, nlist[0].n_name, "not in name list"); + if (nl[0].n_value == 0) { + _kvm_err(kd, nl[0].n_name, "not in name list"); return (-1); } - if (_kvm_kvatop(kd, (u_long)nlist[0].n_value, &pa) == 0) + if (_kvm_kvatop(kd, (u_long)nl[0].n_value, &pa) == 0) return (-1); x = 0; @@ -834,7 +837,7 @@ kvm_dump_inval(kvm_t *kd) ssize_t kvm_read(kvm_t *kd, u_long kva, void *buf, size_t len) { - int cc; + ssize_t cc; void *cp; if (ISALIVE(kd)) { @@ -864,7 +867,7 @@ kvm_read(kvm_t *kd, u_long kva, void *buf, size_t len) return (-1); if (cc > len) cc = len; - cc = _kvm_pread(kd, kd->pmfd, cp, cc, + cc = _kvm_pread(kd, kd->pmfd, cp, (size_t)cc, (off_t)_kvm_pa2off(kd, pa)); if (cc == -1) { _kvm_syserr(kd, 0, _PATH_MEM); @@ -896,7 +899,7 @@ kvm_write(kvm_t *kd, u_long kva, const void *buf, size_t len) /* * Just like kvm_read, only we write. */ - cc = _kvm_pwrite(kd, kd->vmfd, (void*)buf, (size_t)len, (off_t)kva); + cc = _kvm_pwrite(kd, kd->vmfd, buf, len, (off_t)kva); if (cc == -1) { _kvm_err(kd, 0, "invalid address (%lx)", kva); return (-1); diff --git a/lib/libkvm/kvm_file.c b/lib/libkvm/kvm_file.c index aeada10d1d3..c9457473304 100644 --- a/lib/libkvm/kvm_file.c +++ b/lib/libkvm/kvm_file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm_file.c,v 1.13 2005/10/12 07:24:28 otto Exp $ */ +/* $OpenBSD: kvm_file.c,v 1.14 2006/03/31 03:59:40 deraadt Exp $ */ /* $NetBSD: kvm_file.c,v 1.5 1996/03/18 22:33:18 thorpej Exp $ */ /*- @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)kvm_file.c 8.1 (Berkeley) 6/4/93"; #else -static char *rcsid = "$OpenBSD: kvm_file.c,v 1.13 2005/10/12 07:24:28 otto Exp $"; +static char *rcsid = "$OpenBSD: kvm_file.c,v 1.14 2006/03/31 03:59:40 deraadt Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -76,29 +76,29 @@ static int kvm_deadfiles(kvm_t *kd, int op, int arg, long filehead_o, * Get file structures. */ static int -kvm_deadfiles(kvm_t *kd, int op, int arg, long filehead_o, int nfiles) +kvm_deadfiles(kvm_t *kd, int op, int arg, long filehead_o, int kvm_nfiles) { int buflen = kd->arglen, n = 0; char *where = kd->argspc; struct file *fp; - struct filelist filehead; + struct filelist kvm_filehead; /* * first copyout filehead */ - if (buflen > sizeof (filehead)) { - if (KREAD(kd, filehead_o, &filehead)) { + if (buflen > sizeof (kvm_filehead)) { + if (KREAD(kd, filehead_o, &kvm_filehead)) { _kvm_err(kd, kd->program, "can't read filehead"); return (0); } - buflen -= sizeof (filehead); - where += sizeof (filehead); - *(struct filelist *)kd->argspc = filehead; + buflen -= sizeof(kvm_filehead); + where += sizeof(kvm_filehead); + *(struct filelist *)kd->argspc = kvm_filehead; } /* * followed by an array of file structures */ - LIST_FOREACH(fp, &filehead, f_list) { + LIST_FOREACH(fp, &kvm_filehead, f_list) { if (buflen > sizeof (struct file)) { if (KREAD(kd, (long)fp, ((struct file *)where))) { _kvm_err(kd, kd->program, "can't read kfp"); @@ -110,19 +110,19 @@ kvm_deadfiles(kvm_t *kd, int op, int arg, long filehead_o, int nfiles) n++; } } - if (n != nfiles) { + if (n != kvm_nfiles) { _kvm_err(kd, kd->program, "inconsistent nfiles"); return (0); } - return (nfiles); + return (kvm_nfiles); } char * kvm_getfiles(kvm_t *kd, int op, int arg, int *cnt) { - struct filelist filehead; + struct filelist kvm_filehead; struct file *fp, *fplim; - int mib[2], st, nfiles; + int mib[2], st, kvm_nfiles; size_t size; if (ISALIVE(kd)) { @@ -142,16 +142,16 @@ kvm_getfiles(kvm_t *kd, int op, int arg, int *cnt) return (0); kd->arglen = size; st = sysctl(mib, 2, kd->argspc, &size, NULL, 0); - if (st == -1 || size < sizeof(filehead)) { + if (st == -1 || size < sizeof(kvm_filehead)) { _kvm_syserr(kd, kd->program, "kvm_getfiles"); return (0); } - filehead = *(struct filelist *)kd->argspc; - fp = (struct file *)(kd->argspc + sizeof (filehead)); + kvm_filehead = *(struct filelist *)kd->argspc; + fp = (struct file *)(kd->argspc + sizeof(kvm_filehead)); fplim = (struct file *)(kd->argspc + size); - for (nfiles = 0; LIST_FIRST(&filehead) && (fp < fplim); - nfiles++, fp++) - LIST_FIRST(&filehead) = LIST_NEXT(fp, f_list); + for (kvm_nfiles = 0; LIST_FIRST(&kvm_filehead) && (fp < fplim); + kvm_nfiles++, fp++) + LIST_FIRST(&kvm_filehead) = LIST_NEXT(fp, f_list); } else { struct nlist nl[3], *p; @@ -166,11 +166,11 @@ kvm_getfiles(kvm_t *kd, int op, int arg, int *cnt) "%s: no such symbol", p->n_name); return (0); } - if (KREAD(kd, nl[0].n_value, &nfiles)) { + if (KREAD(kd, nl[0].n_value, &kvm_nfiles)) { _kvm_err(kd, kd->program, "can't read nfiles"); return (0); } - size = sizeof(filehead) + (nfiles + 10) * sizeof(struct file); + size = sizeof(kvm_filehead) + (kvm_nfiles + 10) * sizeof(struct file); if (kd->argspc == 0) kd->argspc = (char *)_kvm_malloc(kd, size); else if (kd->arglen < size) @@ -178,10 +178,10 @@ kvm_getfiles(kvm_t *kd, int op, int arg, int *cnt) if (kd->argspc == 0) return (0); kd->arglen = size; - nfiles = kvm_deadfiles(kd, op, arg, nl[1].n_value, nfiles); - if (nfiles == 0) + kvm_nfiles = kvm_deadfiles(kd, op, arg, nl[1].n_value, kvm_nfiles); + if (kvm_nfiles == 0) return (0); } - *cnt = nfiles; + *cnt = kvm_nfiles; return (kd->argspc); } diff --git a/lib/libkvm/kvm_getloadavg.c b/lib/libkvm/kvm_getloadavg.c index 371b3eb8e6b..38dc4c838f9 100644 --- a/lib/libkvm/kvm_getloadavg.c +++ b/lib/libkvm/kvm_getloadavg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm_getloadavg.c,v 1.6 2004/06/15 03:52:59 deraadt Exp $ */ +/* $OpenBSD: kvm_getloadavg.c,v 1.7 2006/03/31 03:59:40 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.6 2004/06/15 03:52:59 deraadt Exp $"; +static char *rcsid = "$OpenBSD: kvm_getloadavg.c,v 1.7 2006/03/31 03:59:40 deraadt Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -87,6 +87,7 @@ kvm_getloadavg(kvm_t *kd, double loadavg[], int nelem) #define KREAD(kd, addr, obj) \ (kvm_read(kd, addr, (char *)(obj), sizeof(*obj)) != sizeof(*obj)) + if (KREAD(kd, nl[X_AVERUNNABLE].n_value, &loadinfo)) { _kvm_err(kd, kd->program, "can't read averunnable"); return (-1); diff --git a/lib/libkvm/kvm_private.h b/lib/libkvm/kvm_private.h index 26ae1f46596..fa0d714f9cd 100644 --- a/lib/libkvm/kvm_private.h +++ b/lib/libkvm/kvm_private.h @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm_private.h,v 1.10 2006/03/20 15:11:48 mickey Exp $ */ +/* $OpenBSD: kvm_private.h,v 1.11 2006/03/31 03:59:40 deraadt Exp $ */ /* $NetBSD: kvm_private.h,v 1.7 1996/05/05 04:32:15 gwr Exp $ */ /*- @@ -97,9 +97,6 @@ int _kvm_kvatop(kvm_t *, u_long, paddr_t *); void *_kvm_malloc(kvm_t *kd, size_t); off_t _kvm_pa2off(kvm_t *, paddr_t); void *_kvm_realloc(kvm_t *kd, void *, size_t); -void _kvm_syserr -(kvm_t *kd, const char *program, const char *fmt, ...); -ssize_t _kvm_pread -(kvm_t *, int, void *, size_t, off_t); -ssize_t _kvm_pwrite -(kvm_t *, int, void *, size_t, off_t); +void _kvm_syserr(kvm_t *kd, const char *program, const char *fmt, ...); +ssize_t _kvm_pread(kvm_t *, int, void *, size_t, off_t); +ssize_t _kvm_pwrite(kvm_t *, int, const void *, size_t, off_t); diff --git a/lib/libkvm/kvm_proc.c b/lib/libkvm/kvm_proc.c index d4d43e19c25..48b269698e3 100644 --- a/lib/libkvm/kvm_proc.c +++ b/lib/libkvm/kvm_proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm_proc.c,v 1.27 2005/10/12 07:24:28 otto Exp $ */ +/* $OpenBSD: kvm_proc.c,v 1.28 2006/03/31 03:59:40 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.27 2005/10/12 07:24:28 otto Exp $"; +static char *rcsid = "$OpenBSD: kvm_proc.c,v 1.28 2006/03/31 03:59:40 deraadt Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -179,7 +179,7 @@ _kvm_ureadm(kvm_t *kd, const struct miniproc *p, u_long va, u_long *cnt) struct vm_page pg; if (kd->swapspc == 0) { - kd->swapspc = (char *)_kvm_malloc(kd, kd->nbpg); + kd->swapspc = _kvm_malloc(kd, kd->nbpg); if (kd->swapspc == 0) return (0); } @@ -420,7 +420,7 @@ kvm_getproc2(kvm_t *kd, int op, int arg, size_t esize, int *cnt) struct user user; size_t size; - if (esize < 0) + if ((ssize_t)esize < 0) return (NULL); if (kd->procbase2 != NULL) { @@ -447,7 +447,7 @@ kvm_getproc2(kvm_t *kd, int op, int arg, size_t esize, int *cnt) } mib[5] = size / esize; - kd->procbase2 = (struct kinfo_proc2 *)_kvm_malloc(kd, size); + kd->procbase2 = _kvm_malloc(kd, size); if (kd->procbase2 == 0) return (NULL); st = sysctl(mib, 6, kd->procbase2, &size, NULL, 0); @@ -636,7 +636,7 @@ kvm_getprocs(kvm_t *kd, int op, int arg, int *cnt) _kvm_syserr(kd, kd->program, "kvm_getprocs"); return (0); } - kd->procbase = (struct kinfo_proc *)_kvm_malloc(kd, size); + kd->procbase = _kvm_malloc(kd, size); if (kd->procbase == 0) return (0); st = sysctl(mib, 4, kd->procbase, &size, NULL, 0); @@ -672,7 +672,7 @@ kvm_getprocs(kvm_t *kd, int op, int arg, int *cnt) return (0); } size = nprocs * sizeof(struct kinfo_proc); - kd->procbase = (struct kinfo_proc *)_kvm_malloc(kd, size); + kd->procbase = _kvm_malloc(kd, size); if (kd->procbase == 0) return (0); @@ -732,7 +732,7 @@ kvm_argv(kvm_t *kd, const struct miniproc *p, u_long addr, int narg, * Try to avoid reallocs. */ kd->argc = MAX(narg + 1, 32); - kd->argv = (char **)_kvm_malloc(kd, kd->argc * + kd->argv = _kvm_malloc(kd, kd->argc * sizeof(*kd->argv)); if (kd->argv == 0) return (0); @@ -744,13 +744,13 @@ kvm_argv(kvm_t *kd, const struct miniproc *p, u_long addr, int narg, return (0); } if (kd->argspc == 0) { - kd->argspc = (char *)_kvm_malloc(kd, kd->nbpg); + kd->argspc = _kvm_malloc(kd, kd->nbpg); if (kd->argspc == 0) return (0); kd->arglen = kd->nbpg; } if (kd->argbuf == 0) { - kd->argbuf = (char *)_kvm_malloc(kd, kd->nbpg); + kd->argbuf = _kvm_malloc(kd, kd->nbpg); if (kd->argbuf == 0) return (0); } |