Author: uqs
Date: Sun Jan 23 11:08:28 2011
New Revision: 217744
URL: http://svn.freebsd.org/changeset/base/217744

Log:
  libkvm code janitoring
  
  - make WARNS=6 clean for archs w/o strict alignment requirments
  - add const, ANSIfy, remove unused vars, cast types for comparison
  - thanks to differing definitions of VM_MIN_ADDRESS across our archs, we
    need to trick the compiler to not complain about signedness. We could
    either fix VM_MIN_ADDRESS to always be a simple integer or make the
    check conditional on $ARCH.
  
  Closes PRs:   kern/42386, kern/83364
  Reviewed by:  bde

Modified:
  head/lib/libkvm/kvm.c
  head/lib/libkvm/kvm.h
  head/lib/libkvm/kvm_amd64.c
  head/lib/libkvm/kvm_arm.c
  head/lib/libkvm/kvm_cptime.c
  head/lib/libkvm/kvm_file.c
  head/lib/libkvm/kvm_getloadavg.c
  head/lib/libkvm/kvm_getswapinfo.c
  head/lib/libkvm/kvm_i386.c
  head/lib/libkvm/kvm_ia64.c
  head/lib/libkvm/kvm_minidump_amd64.c
  head/lib/libkvm/kvm_minidump_arm.c
  head/lib/libkvm/kvm_minidump_i386.c
  head/lib/libkvm/kvm_minidump_mips.c
  head/lib/libkvm/kvm_mips.c
  head/lib/libkvm/kvm_pcpu.c
  head/lib/libkvm/kvm_powerpc.c
  head/lib/libkvm/kvm_proc.c
  head/lib/libkvm/kvm_sparc64.c
  head/lib/libkvm/kvm_vnet.c

Modified: head/lib/libkvm/kvm.c
==============================================================================
--- head/lib/libkvm/kvm.c       Sun Jan 23 09:50:39 2011        (r217743)
+++ head/lib/libkvm/kvm.c       Sun Jan 23 11:08:28 2011        (r217744)
@@ -77,8 +77,7 @@ static char sccsid[] = "@(#)kvm.c     8.2 (B
 int __fdnlist(int, struct nlist *);
 
 char *
-kvm_geterr(kd)
-       kvm_t *kd;
+kvm_geterr(kvm_t *kd)
 {
        return (kd->errbuf);
 }
@@ -103,7 +102,7 @@ _kvm_err(kvm_t *kd, const char *program,
                (void)fputc('\n', stderr);
        } else
                (void)vsnprintf(kd->errbuf,
-                   sizeof(kd->errbuf), (char *)fmt, ap);
+                   sizeof(kd->errbuf), fmt, ap);
 
        va_end(ap);
 }
@@ -122,7 +121,7 @@ _kvm_syserr(kvm_t *kd, const char *progr
        } 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));
@@ -131,25 +130,18 @@ _kvm_syserr(kvm_t *kd, const char *progr
 }
 
 void *
-_kvm_malloc(kd, n)
-       kvm_t *kd;
-       size_t n;
+_kvm_malloc(kvm_t *kd, size_t n)
 {
        void *p;
 
        if ((p = calloc(n, sizeof(char))) == NULL)
-               _kvm_err(kd, kd->program, "can't allocate %u bytes: %s",
+               _kvm_err(kd, kd->program, "can't allocate %zu bytes: %s",
                         n, strerror(errno));
        return (p);
 }
 
 static kvm_t *
-_kvm_open(kd, uf, mf, flag, errout)
-       kvm_t *kd;
-       const char *uf;
-       const char *mf;
-       int flag;
-       char *errout;
+_kvm_open(kvm_t *kd, const char *uf, const char *mf, int flag, char *errout)
 {
        struct stat st;
 
@@ -242,12 +234,8 @@ failed:
 }
 
 kvm_t *
-kvm_openfiles(uf, mf, sf, flag, errout)
-       const char *uf;
-       const char *mf;
-       const char *sf __unused;
-       int flag;
-       char *errout;
+kvm_openfiles(const char *uf, const char *mf, const char *sf __unused, int 
flag,
+    char *errout)
 {
        kvm_t *kd;
 
@@ -260,12 +248,8 @@ kvm_openfiles(uf, mf, sf, flag, errout)
 }
 
 kvm_t *
-kvm_open(uf, mf, sf, flag, errstr)
-       const char *uf;
-       const char *mf;
-       const char *sf __unused;
-       int flag;
-       const char *errstr;
+kvm_open(const char *uf, const char *mf, const char *sf __unused, int flag,
+    const char *errstr)
 {
        kvm_t *kd;
 
@@ -280,8 +264,7 @@ kvm_open(uf, mf, sf, flag, errstr)
 }
 
 int
-kvm_close(kd)
-       kvm_t *kd;
+kvm_close(kvm_t *kd)
 {
        int error = 0;
 
@@ -316,8 +299,9 @@ kvm_fdnlist_prefix(kvm_t *kd, struct nli
 {
        struct nlist *n, *np, *p;
        char *cp, *ce;
+       const char *ccp;
        size_t len;
-       int unresolved;
+       int slen, unresolved;
 
        /*
         * Calculate the space we need to malloc for nlist and names.
@@ -355,13 +339,13 @@ kvm_fdnlist_prefix(kvm_t *kd, struct nli
                        continue;
                bcopy(p, np, sizeof(struct nlist));
                /* Save the new\0orig. name so we can later match it again. */
-               len = snprintf(cp, ce - cp, "%s%s%c%s", prefix,
+               slen = snprintf(cp, ce - cp, "%s%s%c%s", prefix,
                    (prefix[0] != '\0' && p->n_name[0] == '_') ?
                        (p->n_name + 1) : p->n_name, '\0', p->n_name);
-               if (len >= ce - cp)
+               if (slen < 0 || slen >= ce - cp)
                        continue;
                np->n_name = cp;
-               cp += len + 1;
+               cp += slen + 1;
                np++;
                unresolved++;
        }
@@ -385,8 +369,8 @@ kvm_fdnlist_prefix(kvm_t *kd, struct nli
                        if (p->n_type != N_UNDF)
                                continue;
                        /* Skip expanded name and compare to orig. one. */
-                       cp = np->n_name + strlen(np->n_name) + 1;
-                       if (strcmp(cp, p->n_name))
+                       ccp = np->n_name + strlen(np->n_name) + 1;
+                       if (strcmp(ccp, p->n_name) != 0)
                                continue;
                        /* Update nlist with new, translated results. */
                        p->n_type = np->n_type;
@@ -416,7 +400,8 @@ _kvm_nlist(kvm_t *kd, struct nlist *nl, 
        int nvalid;
        struct kld_sym_lookup lookup;
        int error;
-       char *prefix = "", symname[1024]; /* XXX-BZ symbol name length limit? */
+       const char *prefix = "";
+       char symname[1024]; /* XXX-BZ symbol name length limit? */
        int tried_vnet, tried_dpcpu;
 
        /*
@@ -458,9 +443,8 @@ again:
                error = snprintf(symname, sizeof(symname), "%s%s", prefix,
                    (prefix[0] != '\0' && p->n_name[0] == '_') ?
                        (p->n_name + 1) : p->n_name);
-               if (error >= sizeof(symname))
+               if (error < 0 || error >= (int)sizeof(symname))
                        continue;
-
                lookup.symname = symname;
                if (lookup.symname[0] == '_')
                        lookup.symname++;
@@ -470,11 +454,11 @@ again:
                        p->n_other = 0;
                        p->n_desc = 0;
                        if (_kvm_vnet_initialized(kd, initialize) &&
-                           !strcmp(prefix, VNET_SYMPREFIX))
+                           !strcmp(prefix, VNET_SYMPREFIX) == 0)
                                p->n_value =
                                    _kvm_vnet_validaddr(kd, lookup.symvalue);
                        else if (_kvm_dpcpu_initialized(kd, initialize) &&
-                           !strcmp(prefix, DPCPU_SYMPREFIX))
+                           !strcmp(prefix, DPCPU_SYMPREFIX) == 0)
                                p->n_value =
                                    _kvm_dpcpu_validaddr(kd, lookup.symvalue);
                        else
@@ -511,9 +495,7 @@ again:
 }
 
 int
-kvm_nlist(kd, nl)
-       kvm_t *kd;
-       struct nlist *nl;
+kvm_nlist(kvm_t *kd, struct nlist *nl)
 {
 
        /*
@@ -524,13 +506,11 @@ kvm_nlist(kd, nl)
 }
 
 ssize_t
-kvm_read(kd, kva, buf, len)
-       kvm_t *kd;
-       u_long kva;
-       void *buf;
-       size_t len;
+kvm_read(kvm_t *kd, u_long kva, void *buf, size_t len)
 {
        int cc;
+       ssize_t cr;
+       off_t pa;
        char *cp;
 
        if (ISALIVE(kd)) {
@@ -540,59 +520,52 @@ kvm_read(kd, kva, buf, len)
                 */
                errno = 0;
                if (lseek(kd->vmfd, (off_t)kva, 0) == -1 && errno != 0) {
-                       _kvm_err(kd, 0, "invalid address (%x)", kva);
+                       _kvm_err(kd, 0, "invalid address (%lx)", kva);
                        return (-1);
                }
-               cc = read(kd->vmfd, buf, len);
-               if (cc < 0) {
+               cr = read(kd->vmfd, buf, len);
+               if (cr < 0) {
                        _kvm_syserr(kd, 0, "kvm_read");
                        return (-1);
-               } else if (cc < len)
+               } else if (cr < (ssize_t)len)
                        _kvm_err(kd, kd->program, "short read");
-               return (cc);
-       } else {
-               cp = buf;
-               while (len > 0) {
-                       off_t pa;
-
-                       cc = _kvm_kvatop(kd, kva, &pa);
-                       if (cc == 0)
-                               return (-1);
-                       if (cc > len)
-                               cc = len;
-                       errno = 0;
-                       if (lseek(kd->pmfd, pa, 0) == -1 && errno != 0) {
-                               _kvm_syserr(kd, 0, _PATH_MEM);
-                               break;
-                       }
-                       cc = read(kd->pmfd, cp, cc);
-                       if (cc < 0) {
-                               _kvm_syserr(kd, kd->program, "kvm_read");
-                               break;
-                       }
-                       /*
-                        * If kvm_kvatop returns a bogus value or our core
-                        * file is truncated, we might wind up seeking beyond
-                        * the end of the core file in which case the read will
-                        * return 0 (EOF).
-                        */
-                       if (cc == 0)
-                               break;
-                       cp += cc;
-                       kva += cc;
-                       len -= cc;
+               return (cr);
+       }
+
+       cp = buf;
+       while (len > 0) {
+               cc = _kvm_kvatop(kd, kva, &pa);
+               if (cc == 0)
+                       return (-1);
+               if (cc > (ssize_t)len)
+                       cc = len;
+               errno = 0;
+               if (lseek(kd->pmfd, pa, 0) == -1 && errno != 0) {
+                       _kvm_syserr(kd, 0, _PATH_MEM);
+                       break;
+               }
+               cr = read(kd->pmfd, cp, cc);
+               if (cr < 0) {
+                       _kvm_syserr(kd, kd->program, "kvm_read");
+                       break;
                }
-               return (cp - (char *)buf);
+               /*
+                * If kvm_kvatop returns a bogus value or our core file is
+                * truncated, we might wind up seeking beyond the end of the
+                * core file in which case the read will return 0 (EOF).
+                */
+               if (cr == 0)
+                       break;
+               cp += cr;
+               kva += cr;
+               len -= cr;
        }
-       /* NOTREACHED */
+
+       return (cp - (char *)buf);
 }
 
 ssize_t
-kvm_write(kd, kva, buf, len)
-       kvm_t *kd;
-       u_long kva;
-       const void *buf;
-       size_t len;
+kvm_write(kvm_t *kd, u_long kva, const void *buf, size_t len)
 {
        int cc;
 
@@ -602,14 +575,14 @@ kvm_write(kd, kva, buf, len)
                 */
                errno = 0;
                if (lseek(kd->vmfd, (off_t)kva, 0) == -1 && errno != 0) {
-                       _kvm_err(kd, 0, "invalid address (%x)", kva);
+                       _kvm_err(kd, 0, "invalid address (%lx)", kva);
                        return (-1);
                }
                cc = write(kd->vmfd, buf, len);
                if (cc < 0) {
                        _kvm_syserr(kd, 0, "kvm_write");
                        return (-1);
-               } else if (cc < len)
+               } else if ((size_t)cc < len)
                        _kvm_err(kd, kd->program, "short write");
                return (cc);
        } else {

Modified: head/lib/libkvm/kvm.h
==============================================================================
--- head/lib/libkvm/kvm.h       Sun Jan 23 09:50:39 2011        (r217743)
+++ head/lib/libkvm/kvm.h       Sun Jan 23 11:08:28 2011        (r217744)
@@ -88,7 +88,7 @@ kvm_t  *kvm_openfiles
            (const char *, const char *, const char *, int, char *);
 ssize_t          kvm_read(kvm_t *, unsigned long, void *, size_t);
 ssize_t          kvm_uread
-           (kvm_t *, struct kinfo_proc *, unsigned long, char *, size_t);
+           (kvm_t *, const struct kinfo_proc *, unsigned long, char *, size_t);
 ssize_t          kvm_write(kvm_t *, unsigned long, const void *, size_t);
 __END_DECLS
 

Modified: head/lib/libkvm/kvm_amd64.c
==============================================================================
--- head/lib/libkvm/kvm_amd64.c Sun Jan 23 09:50:39 2011        (r217743)
+++ head/lib/libkvm/kvm_amd64.c Sun Jan 23 11:08:28 2011        (r217744)
@@ -147,7 +147,7 @@ _kvm_freevtop(kvm_t *kd)
 int
 _kvm_initvtop(kvm_t *kd)
 {
-       struct nlist nlist[2];
+       struct nlist nl[2];
        u_long pa;
        u_long kernbase;
        pml4_entry_t    *PML4;
@@ -176,23 +176,23 @@ _kvm_initvtop(kvm_t *kd)
                        return (-1);
        }
 
-       nlist[0].n_name = "kernbase";
-       nlist[1].n_name = 0;
+       nl[0].n_name = "kernbase";
+       nl[1].n_name = 0;
 
-       if (kvm_nlist(kd, nlist) != 0) {
+       if (kvm_nlist(kd, nl) != 0) {
                _kvm_err(kd, kd->program, "bad namelist - no kernbase");
                return (-1);
        }
-       kernbase = nlist[0].n_value;
+       kernbase = nl[0].n_value;
 
-       nlist[0].n_name = "KPML4phys";
-       nlist[1].n_name = 0;
+       nl[0].n_name = "KPML4phys";
+       nl[1].n_name = 0;
 
-       if (kvm_nlist(kd, nlist) != 0) {
+       if (kvm_nlist(kd, nl) != 0) {
                _kvm_err(kd, kd->program, "bad namelist - no KPML4phys");
                return (-1);
        }
-       if (kvm_read(kd, (nlist[0].n_value - kernbase), &pa, sizeof(pa)) !=
+       if (kvm_read(kd, (nl[0].n_value - kernbase), &pa, sizeof(pa)) !=
            sizeof(pa)) {
                _kvm_err(kd, kd->program, "cannot read KPML4phys");
                return (-1);
@@ -222,7 +222,6 @@ _kvm_vatop(kvm_t *kd, u_long va, off_t *
        u_long pdpeindex;
        u_long pdeindex;
        u_long pteindex;
-       int i;
        u_long a;
        off_t ofs;
        size_t s;

Modified: head/lib/libkvm/kvm_arm.c
==============================================================================
--- head/lib/libkvm/kvm_arm.c   Sun Jan 23 09:50:39 2011        (r217743)
+++ head/lib/libkvm/kvm_arm.c   Sun Jan 23 11:08:28 2011        (r217744)
@@ -124,7 +124,7 @@ int
 _kvm_initvtop(kvm_t *kd)
 {
        struct vmstate *vm;
-       struct nlist nlist[2];
+       struct nlist nl[2];
        u_long kernbase, physaddr, pa;
        pd_entry_t *l1pt;
        Elf32_Ehdr *ehdr;
@@ -154,25 +154,25 @@ _kvm_initvtop(kvm_t *kd)
        hdrsz = ehdr->e_phoff + ehdr->e_phentsize * ehdr->e_phnum;
        if (_kvm_maphdrs(kd, hdrsz) == -1)
                return (-1);
-       nlist[0].n_name = "kernbase";
-       nlist[1].n_name = NULL;
-       if (kvm_nlist(kd, nlist) != 0)
+       nl[0].n_name = "kernbase";
+       nl[1].n_name = NULL;
+       if (kvm_nlist(kd, nl) != 0)
                kernbase = KERNBASE;
        else
-               kernbase = nlist[0].n_value;
+               kernbase = nl[0].n_value;
 
-       nlist[0].n_name = "physaddr";
-       if (kvm_nlist(kd, nlist) != 0) {
+       nl[0].n_name = "physaddr";
+       if (kvm_nlist(kd, nl) != 0) {
                _kvm_err(kd, kd->program, "couldn't get phys addr");
                return (-1);
        }
-       physaddr = nlist[0].n_value;
-       nlist[0].n_name = "kernel_l1pa";
-       if (kvm_nlist(kd, nlist) != 0) {
+       physaddr = nl[0].n_value;
+       nl[0].n_name = "kernel_l1pa";
+       if (kvm_nlist(kd, nl) != 0) {
                _kvm_err(kd, kd->program, "bad namelist");
                return (-1);
        }
-       if (kvm_read(kd, (nlist[0].n_value - kernbase + physaddr), &pa,
+       if (kvm_read(kd, (nl[0].n_value - kernbase + physaddr), &pa,
            sizeof(pa)) != sizeof(pa)) {
                _kvm_err(kd, kd->program, "cannot read kernel_l1pa");
                return (-1);
@@ -205,7 +205,6 @@ _kvm_initvtop(kvm_t *kd)
 int
 _kvm_kvatop(kvm_t *kd, u_long va, off_t *pa)
 {
-       u_long offset = va & (PAGE_SIZE - 1);
        struct vmstate *vm = kd->vmst;
        pd_entry_t pd;
        pt_entry_t pte;
@@ -244,7 +243,7 @@ _kvm_kvatop(kvm_t *kd, u_long va, off_t 
        *pa = (pte & L2_S_FRAME) | (va & L2_S_OFFSET);
        return (_kvm_pa2off(kd, *pa, pa, PAGE_SIZE));
 invalid:
-       _kvm_err(kd, 0, "Invalid address (%x)", va);
+       _kvm_err(kd, 0, "Invalid address (%lx)", va);
        return 0;
 }
 
@@ -253,16 +252,15 @@ invalid:
  * not just those for a kernel crash dump.  Some architectures
  * have to deal with these NOT being constants!  (i.e. m68k)
  */
+#ifdef FBSD_NOT_YET
 int
-_kvm_mdopen(kd)
-       kvm_t   *kd;
+_kvm_mdopen(kvm_t *kd)
 {
 
-#ifdef FBSD_NOT_YET
        kd->usrstack = USRSTACK;
        kd->min_uva = VM_MIN_ADDRESS;
        kd->max_uva = VM_MAXUSER_ADDRESS;
-#endif
 
        return (0);
 }
+#endif

Modified: head/lib/libkvm/kvm_cptime.c
==============================================================================
--- head/lib/libkvm/kvm_cptime.c        Sun Jan 23 09:50:39 2011        
(r217743)
+++ head/lib/libkvm/kvm_cptime.c        Sun Jan 23 11:08:28 2011        
(r217744)
@@ -44,8 +44,8 @@ __FBSDID("$FreeBSD$");
 #include "kvm_private.h"
 
 static struct nlist kvm_cp_time_nl[] = {
-       { "_cp_time" },                 /* (deprecated) */
-       { NULL },
+       { .n_name = "_cp_time" },               /* (deprecated) */
+       { .n_name = NULL },
 };
 
 #define        NL_CP_TIME              0
@@ -59,6 +59,7 @@ _kvm_cp_time_init(kvm_t *kd)
        if (kvm_nlist(kd, kvm_cp_time_nl) < 0)
                return (-1);
        kvm_cp_time_cached = 1;
+       return (0);
 }
 
 static int

Modified: head/lib/libkvm/kvm_file.c
==============================================================================
--- head/lib/libkvm/kvm_file.c  Sun Jan 23 09:50:39 2011        (r217743)
+++ head/lib/libkvm/kvm_file.c  Sun Jan 23 11:08:28 2011        (r217744)
@@ -69,16 +69,14 @@ static char sccsid[] = "@(#)kvm_file.c      8
        (kvm_read(kd, addr, obj, sizeof(*obj)) != sizeof(*obj))
 
 #define KREADN(kd, addr, obj, cnt) \
-       (kvm_read(kd, addr, obj, (cnt)) != (cnt))
+       (kvm_read(kd, addr, obj, (cnt)) != (ssize_t)(cnt))
 
 /*
  * Get file structures.
  */
 static int
-kvm_deadfiles(kd, op, arg, allproc_o, nprocs)
-       kvm_t *kd;
-       int op, arg, nprocs;
-       long allproc_o;
+kvm_deadfiles(kvm_t *kd, int op __unused, int arg __unused, long allproc_o,
+    int nprocs __unused)
 {
        struct proc proc;
        struct filedesc filed;
@@ -88,7 +86,7 @@ kvm_deadfiles(kd, op, arg, allproc_o, np
        struct proc *p;
        char *where = kd->argspc;
 
-       if (buflen < sizeof (struct file *) + sizeof (struct file))
+       if (buflen < (int)(sizeof(struct file *) + sizeof(struct file)))
                return (0);
        if (KREAD(kd, allproc_o, &p)) {
                _kvm_err(kd, kd->program, "cannot read allproc");
@@ -96,7 +94,7 @@ kvm_deadfiles(kd, op, arg, allproc_o, np
        }
        for (; p != NULL; p = LIST_NEXT(&proc, p_list)) {
                if (KREAD(kd, (u_long)p, &proc)) {
-                       _kvm_err(kd, kd->program, "can't read proc at %x", p);
+                       _kvm_err(kd, kd->program, "can't read proc at %p", p);
                        goto fail;
                }
                if (proc.p_state == PRS_NEW)
@@ -104,7 +102,7 @@ kvm_deadfiles(kd, op, arg, allproc_o, np
                if (proc.p_fd == NULL)
                        continue;
                if (KREAD(kd, (u_long)p->p_fd, &filed)) {
-                       _kvm_err(kd, kd->program, "can't read filedesc at %x",
+                       _kvm_err(kd, kd->program, "can't read filedesc at %p",
                            p->p_fd);
                        goto fail;
                }
@@ -118,7 +116,7 @@ kvm_deadfiles(kd, op, arg, allproc_o, np
                }
                if (KREADN(kd, (u_long)filed.fd_ofiles, ofiles,
                    ocnt * sizeof(struct file *))) {
-                       _kvm_err(kd, kd->program, "can't read ofiles at %x",
+                       _kvm_err(kd, kd->program, "can't read ofiles at %p",
                            filed.fd_ofiles);
                        return (0);
                }
@@ -135,7 +133,7 @@ kvm_deadfiles(kd, op, arg, allproc_o, np
                                where += sizeof (fp);
                                once = 1;
                        }
-                       if (buflen < sizeof (struct file))
+                       if (buflen < (int)sizeof(struct file))
                                goto fail;
                        if (KREAD(kd, (long)fp, ((struct file *)where))) {
                                _kvm_err(kd, kd->program, "can't read kfp");
@@ -156,10 +154,7 @@ fail:
 }
 
 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)
 {
        int mib[2], st, n, nfiles, nprocs;
        size_t size;
@@ -177,7 +172,7 @@ kvm_getfiles(kd, op, arg, cnt)
                }
                if (kd->argspc == 0)
                        kd->argspc = (char *)_kvm_malloc(kd, size);
-               else if (kd->arglen < size)
+               else if (kd->arglen < (int)size)
                        kd->argspc = (char *)_kvm_realloc(kd, kd->argspc, size);
                if (kd->argspc == 0)
                        return (0);
@@ -214,7 +209,7 @@ kvm_getfiles(kd, op, arg, cnt)
                size = sizeof(void *) + (nfiles + 10) * sizeof(struct file);
                if (kd->argspc == 0)
                        kd->argspc = (char *)_kvm_malloc(kd, size);
-               else if (kd->arglen < size)
+               else if (kd->arglen < (int)size)
                        kd->argspc = (char *)_kvm_realloc(kd, kd->argspc, size);
                if (kd->argspc == 0)
                        return (0);

Modified: head/lib/libkvm/kvm_getloadavg.c
==============================================================================
--- head/lib/libkvm/kvm_getloadavg.c    Sun Jan 23 09:50:39 2011        
(r217743)
+++ head/lib/libkvm/kvm_getloadavg.c    Sun Jan 23 11:08:28 2011        
(r217744)
@@ -48,11 +48,11 @@ static char sccsid[] = "@(#)kvm_getloada
 #include "kvm_private.h"
 
 static struct nlist nl[] = {
-       { "_averunnable" },
+       { .n_name = "_averunnable" },
 #define        X_AVERUNNABLE   0
-       { "_fscale" },
+       { .n_name = "_fscale" },
 #define        X_FSCALE        1
-       { "" },
+       { .n_name = "" },
 };
 
 /*
@@ -62,10 +62,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;
@@ -95,7 +92,7 @@ kvm_getloadavg(kd, loadavg, nelem)
        if (!KREAD(kd, nl[X_FSCALE].n_value, &fscale))
                loadinfo.fscale = fscale;
 
-       nelem = MIN(nelem, sizeof(loadinfo.ldavg) / sizeof(fixpt_t));
+       nelem = MIN(nelem, (int)(sizeof(loadinfo.ldavg) / sizeof(fixpt_t)));
        for (i = 0; i < nelem; i++)
                loadavg[i] = (double) loadinfo.ldavg[i] / loadinfo.fscale;
        return (nelem);

Modified: head/lib/libkvm/kvm_getswapinfo.c
==============================================================================
--- head/lib/libkvm/kvm_getswapinfo.c   Sun Jan 23 09:50:39 2011        
(r217743)
+++ head/lib/libkvm/kvm_getswapinfo.c   Sun Jan 23 11:08:28 2011        
(r217744)
@@ -51,9 +51,9 @@ __FBSDID("$FreeBSD$");
 #include "kvm_private.h"
 
 static struct nlist kvm_swap_nl[] = {
-       { "_swtailq" },         /* list of swap devices and sizes */
-       { "_dmmax" },           /* maximum size of a swap block */
-       { NULL }
+       { .n_name = "_swtailq" },       /* list of swap devices and sizes */
+       { .n_name = "_dmmax" },         /* maximum size of a swap block */
+       { .n_name = NULL }
 };
 
 #define NL_SWTAILQ     0
@@ -66,7 +66,7 @@ static int dmmax;
 static int  kvm_getswapinfo_kvm(kvm_t *, struct kvm_swap *, int, int);
 static int  kvm_getswapinfo_sysctl(kvm_t *, struct kvm_swap *, int, int);
 static int  nlist_init(kvm_t *);
-static int  getsysctl(kvm_t *, char *, void *, size_t);
+static int  getsysctl(kvm_t *, const char *, void *, size_t);
 
 #define KREAD(kd, addr, obj) \
        (kvm_read(kd, addr, (char *)(obj), sizeof(*obj)) != sizeof(*obj))
@@ -90,12 +90,8 @@ static int  getsysctl(kvm_t *, char *, v
        }
 
 int
-kvm_getswapinfo(
-       kvm_t *kd, 
-       struct kvm_swap *swap_ary,
-       int swap_max, 
-       int flags
-) {
+kvm_getswapinfo(kvm_t *kd, struct kvm_swap *swap_ary, int swap_max, int flags)
+{
 
        /*
         * clear cache
@@ -113,12 +109,9 @@ kvm_getswapinfo(
 }
 
 int
-kvm_getswapinfo_kvm(
-       kvm_t *kd,
-       struct kvm_swap *swap_ary,
-       int swap_max,
-       int flags
-) {
+kvm_getswapinfo_kvm(kvm_t *kd, struct kvm_swap *swap_ary, int swap_max,
+    int flags)
+{
        int i, ttl;
        TAILQ_HEAD(, swdevt) swtailq;
        struct swdevt *sp, swinfo;
@@ -161,12 +154,9 @@ kvm_getswapinfo_kvm(
 #define        SWI_MAXMIB      3
 
 int
-kvm_getswapinfo_sysctl(
-       kvm_t *kd, 
-       struct kvm_swap *swap_ary,
-       int swap_max, 
-       int flags
-) {
+kvm_getswapinfo_sysctl(kvm_t *kd, struct kvm_swap *swap_ary, int swap_max,
+    int flags)
+{
        int ti, ttl;
        size_t mibi, len;
        int soid[SWI_MAXMIB];
@@ -229,8 +219,6 @@ kvm_getswapinfo_sysctl(
 static int
 nlist_init(kvm_t *kd)
 {
-       TAILQ_HEAD(, swdevt) swtailq;
-       struct swdevt *sp, swinfo;
 
        if (kvm_swap_nl_cached)
                return (1);
@@ -257,12 +245,8 @@ nlist_init(kvm_t *kd)
 }
 
 static int
-getsysctl (
-       kvm_t *kd,
-       char *name,
-       void *ptr,
-       size_t len
-) {
+getsysctl(kvm_t *kd, const char *name, void *ptr, size_t len)
+{
        size_t nlen = len;
        if (sysctlbyname(name, ptr, &nlen, NULL, 0) == -1) {
                _kvm_err(kd, kd->program, "cannot read sysctl %s:%s", name,

Modified: head/lib/libkvm/kvm_i386.c
==============================================================================
--- head/lib/libkvm/kvm_i386.c  Sun Jan 23 09:50:39 2011        (r217743)
+++ head/lib/libkvm/kvm_i386.c  Sun Jan 23 11:08:28 2011        (r217744)
@@ -153,7 +153,7 @@ _kvm_freevtop(kvm_t *kd)
 int
 _kvm_initvtop(kvm_t *kd)
 {
-       struct nlist nlist[2];
+       struct nlist nl[2];
        u_long pa;
        u_long kernbase;
        char            *PTD;
@@ -183,21 +183,21 @@ _kvm_initvtop(kvm_t *kd)
                        return (-1);
        }
 
-       nlist[0].n_name = "kernbase";
-       nlist[1].n_name = 0;
+       nl[0].n_name = "kernbase";
+       nl[1].n_name = 0;
 
-       if (kvm_nlist(kd, nlist) != 0)
+       if (kvm_nlist(kd, nl) != 0)
                kernbase = KERNBASE;    /* for old kernels */
        else
-               kernbase = nlist[0].n_value;
+               kernbase = nl[0].n_value;
 
-       nlist[0].n_name = "IdlePDPT";
-       nlist[1].n_name = 0;
+       nl[0].n_name = "IdlePDPT";
+       nl[1].n_name = 0;
 
-       if (kvm_nlist(kd, nlist) == 0) {
+       if (kvm_nlist(kd, nl) == 0) {
                uint64_t pa64;
 
-               if (kvm_read(kd, (nlist[0].n_value - kernbase), &pa,
+               if (kvm_read(kd, (nl[0].n_value - kernbase), &pa,
                    sizeof(pa)) != sizeof(pa)) {
                        _kvm_err(kd, kd->program, "cannot read IdlePDPT");
                        return (-1);
@@ -220,14 +220,14 @@ _kvm_initvtop(kvm_t *kd)
                kd->vmst->PTD = PTD;
                kd->vmst->pae = 1;
        } else {
-               nlist[0].n_name = "IdlePTD";
-               nlist[1].n_name = 0;
+               nl[0].n_name = "IdlePTD";
+               nl[1].n_name = 0;
 
-               if (kvm_nlist(kd, nlist) != 0) {
+               if (kvm_nlist(kd, nl) != 0) {
                        _kvm_err(kd, kd->program, "bad namelist");
                        return (-1);
                }
-               if (kvm_read(kd, (nlist[0].n_value - kernbase), &pa,
+               if (kvm_read(kd, (nl[0].n_value - kernbase), &pa,
                    sizeof(pa)) != sizeof(pa)) {
                        _kvm_err(kd, kd->program, "cannot read IdlePTD");
                        return (-1);

Modified: head/lib/libkvm/kvm_ia64.c
==============================================================================
--- head/lib/libkvm/kvm_ia64.c  Sun Jan 23 09:50:39 2011        (r217743)
+++ head/lib/libkvm/kvm_ia64.c  Sun Jan 23 11:08:28 2011        (r217744)
@@ -32,6 +32,7 @@
 #include <sys/elf64.h>
 #include <sys/mman.h>
 
+#include <machine/atomic.h>
 #include <machine/pte.h>
 
 #include <kvm.h>
@@ -123,7 +124,7 @@ _kvm_freevtop(kvm_t *kd)
 int
 _kvm_initvtop(kvm_t *kd)
 {
-       struct nlist nlist[2];
+       struct nlist nl[2];
        uint64_t va;
        Elf64_Ehdr *ehdr;
        size_t hdrsz;
@@ -150,15 +151,15 @@ _kvm_initvtop(kvm_t *kd)
         * addresses/values.
         */
 
-       nlist[0].n_name = "ia64_kptdir";
-       nlist[1].n_name = 0;
+       nl[0].n_name = "ia64_kptdir";
+       nl[1].n_name = 0;
 
-       if (kvm_nlist(kd, nlist) != 0) {
+       if (kvm_nlist(kd, nl) != 0) {
                _kvm_err(kd, kd->program, "bad namelist");
                return (-1);
        }
 
-       if (kvm_read(kd, (nlist[0].n_value), &va, sizeof(va)) != sizeof(va)) {
+       if (kvm_read(kd, (nl[0].n_value), &va, sizeof(va)) != sizeof(va)) {
                _kvm_err(kd, kd->program, "cannot read kptdir");
                return (-1);
        }

Modified: head/lib/libkvm/kvm_minidump_amd64.c
==============================================================================
--- head/lib/libkvm/kvm_minidump_amd64.c        Sun Jan 23 09:50:39 2011        
(r217743)
+++ head/lib/libkvm/kvm_minidump_amd64.c        Sun Jan 23 11:08:28 2011        
(r217744)
@@ -136,7 +136,6 @@ _kvm_minidump_freevtop(kvm_t *kd)
 int
 _kvm_minidump_initvtop(kvm_t *kd)
 {
-       u_long pa;
        struct vmstate *vmst;
        off_t off;
 
@@ -207,7 +206,6 @@ _kvm_minidump_vatop_v1(kvm_t *kd, u_long
        u_long offset;
        pt_entry_t pte;
        u_long pteindex;
-       int i;
        u_long a;
        off_t ofs;
 
@@ -258,7 +256,6 @@ _kvm_minidump_vatop(kvm_t *kd, u_long va
        pd_entry_t pte;
        u_long pteindex;
        u_long pdeindex;
-       int i;
        u_long a;
        off_t ofs;
 

Modified: head/lib/libkvm/kvm_minidump_arm.c
==============================================================================
--- head/lib/libkvm/kvm_minidump_arm.c  Sun Jan 23 09:50:39 2011        
(r217743)
+++ head/lib/libkvm/kvm_minidump_arm.c  Sun Jan 23 11:08:28 2011        
(r217744)
@@ -138,7 +138,6 @@ _kvm_minidump_freevtop(kvm_t *kd)
 int
 _kvm_minidump_initvtop(kvm_t *kd)
 {
-       u_long pa;
        struct vmstate *vmst;
        off_t off;
 
@@ -179,7 +178,7 @@ _kvm_minidump_initvtop(kvm_t *kd)
        }
 
        if (pread(kd->pmfd, vmst->bitmap, vmst->hdr.bitmapsize, off) !=
-           vmst->hdr.bitmapsize) {
+           (ssize_t)vmst->hdr.bitmapsize) {
                _kvm_err(kd, kd->program, "cannot read %d bytes for page 
bitmap",
                    vmst->hdr.bitmapsize);
                return (-1);
@@ -194,7 +193,7 @@ _kvm_minidump_initvtop(kvm_t *kd)
        }
 
        if (pread(kd->pmfd, vmst->ptemap, vmst->hdr.ptesize, off) !=
-           vmst->hdr.ptesize) {
+           (ssize_t)vmst->hdr.ptesize) {
                _kvm_err(kd, kd->program, "cannot read %d bytes for ptemap",
                    vmst->hdr.ptesize);
                return (-1);
@@ -216,7 +215,6 @@ _kvm_minidump_kvatop(kvm_t *kd, u_long v
        u_long offset, pteindex, a;
        off_t ofs;
        uint32_t *ptemap;
-       int i;
 
        if (ISALIVE(kd)) {
                _kvm_err(kd, 0, "kvm_kvatop called in live kernel!");

Modified: head/lib/libkvm/kvm_minidump_i386.c
==============================================================================
--- head/lib/libkvm/kvm_minidump_i386.c Sun Jan 23 09:50:39 2011        
(r217743)
+++ head/lib/libkvm/kvm_minidump_i386.c Sun Jan 23 11:08:28 2011        
(r217744)
@@ -138,7 +138,6 @@ _kvm_minidump_freevtop(kvm_t *kd)
 int
 _kvm_minidump_initvtop(kvm_t *kd)
 {
-       u_long pa;
        struct vmstate *vmst;
        off_t off;
 
@@ -173,7 +172,7 @@ _kvm_minidump_initvtop(kvm_t *kd)
                return (-1);
        }
        if (pread(kd->pmfd, vmst->bitmap, vmst->hdr.bitmapsize, off) !=
-           vmst->hdr.bitmapsize) {
+           (ssize_t)vmst->hdr.bitmapsize) {
                _kvm_err(kd, kd->program, "cannot read %d bytes for page 
bitmap", vmst->hdr.bitmapsize);
                return (-1);
        }
@@ -185,7 +184,7 @@ _kvm_minidump_initvtop(kvm_t *kd)
                return (-1);
        }
        if (pread(kd->pmfd, vmst->ptemap, vmst->hdr.ptesize, off) !=
-           vmst->hdr.ptesize) {
+           (ssize_t)vmst->hdr.ptesize) {
                _kvm_err(kd, kd->program, "cannot read %d bytes for ptemap", 
vmst->hdr.ptesize);
                return (-1);
        }
@@ -204,7 +203,6 @@ _kvm_minidump_vatop_pae(kvm_t *kd, u_lon
        uint64_t offset;
        uint64_t pte;
        u_long pteindex;
-       int i;
        uint64_t a;
        off_t ofs;
        uint64_t *ptemap;
@@ -245,7 +243,6 @@ _kvm_minidump_vatop(kvm_t *kd, u_long va
        u_long offset;
        pt_entry_t pte;
        u_long pteindex;
-       int i;
        u_long a;
        off_t ofs;
        uint32_t *ptemap;

Modified: head/lib/libkvm/kvm_minidump_mips.c
==============================================================================
--- head/lib/libkvm/kvm_minidump_mips.c Sun Jan 23 09:50:39 2011        
(r217743)
+++ head/lib/libkvm/kvm_minidump_mips.c Sun Jan 23 11:08:28 2011        
(r217744)
@@ -140,7 +140,6 @@ _kvm_minidump_freevtop(kvm_t *kd)
 int
 _kvm_minidump_initvtop(kvm_t *kd)
 {
-       u_long pa;
        struct vmstate *vmst;
        off_t off;
 
@@ -182,7 +181,7 @@ _kvm_minidump_initvtop(kvm_t *kd)
        }
 
        if (pread(kd->pmfd, vmst->bitmap, vmst->hdr.bitmapsize, off) !=
-           vmst->hdr.bitmapsize) {
+           (ssize_t)vmst->hdr.bitmapsize) {
                _kvm_err(kd, kd->program, "cannot read %d bytes for page 
bitmap",
                    vmst->hdr.bitmapsize);
                return (-1);
@@ -197,7 +196,7 @@ _kvm_minidump_initvtop(kvm_t *kd)
        }
 
        if (pread(kd->pmfd, vmst->ptemap, vmst->hdr.ptesize, off) !=
-           vmst->hdr.ptesize) {
+           (ssize_t)vmst->hdr.ptesize) {
                _kvm_err(kd, kd->program, "cannot read %d bytes for ptemap",
                    vmst->hdr.ptesize);
                return (-1);
@@ -219,7 +218,6 @@ _kvm_minidump_kvatop(kvm_t *kd, u_long v
        u_long offset, pteindex, a;
        off_t ofs;
        pt_entry_t *ptemap;
-       int i;
 
        if (ISALIVE(kd)) {
                _kvm_err(kd, 0, "kvm_kvatop called in live kernel!");
@@ -238,9 +236,9 @@ _kvm_minidump_kvatop(kvm_t *kd, u_long v
                a = (MIPS_XKPHYS_TO_PHYS(va));
        else
 #endif
-       if (va >= MIPS_KSEG0_START && va < MIPS_KSEG0_END)
+       if (va >= (u_long)MIPS_KSEG0_START && va < (u_long)MIPS_KSEG0_END)
                a = (MIPS_KSEG0_TO_PHYS(va));
-       else if (va >= MIPS_KSEG1_START && va < MIPS_KSEG1_END)
+       else if (va >= (u_long)MIPS_KSEG1_START && va < (u_long)MIPS_KSEG1_END)
                a = (MIPS_KSEG1_TO_PHYS(va));
        else if (va >= vm->hdr.kernbase) {
                pteindex = (va - vm->hdr.kernbase) >> PAGE_SHIFT;

Modified: head/lib/libkvm/kvm_mips.c
==============================================================================
--- head/lib/libkvm/kvm_mips.c  Sun Jan 23 09:50:39 2011        (r217743)
+++ head/lib/libkvm/kvm_mips.c  Sun Jan 23 11:08:28 2011        (r217744)
@@ -94,12 +94,9 @@ _kvm_initvtop(kvm_t *kd)
 }
 
 int
-_kvm_kvatop(kvm_t *kd, u_long va , off_t *pa)
+_kvm_kvatop(kvm_t *kd, u_long va, off_t *pa)
 {
 
-       u_long offset = va & (PAGE_SIZE - 1);
-       struct vmstate *vm = kd->vmst;
-
        if (kd->vmst->minidump)
                return _kvm_minidump_kvatop(kd, va, pa);
 
@@ -113,9 +110,11 @@ _kvm_kvatop(kvm_t *kd, u_long va , off_t
  * not just those for a kernel crash dump.  Some architectures
  * have to deal with these NOT being constants!  (i.e. m68k)
  */
+#ifdef FBSD_NOT_YET
 int
 _kvm_mdopen(kvm_t *kd __unused)
 {
 
        return (0);
 }
+#endif

Modified: head/lib/libkvm/kvm_pcpu.c
==============================================================================
--- head/lib/libkvm/kvm_pcpu.c  Sun Jan 23 09:50:39 2011        (r217743)
+++ head/lib/libkvm/kvm_pcpu.c  Sun Jan 23 11:08:28 2011        (r217744)
@@ -48,9 +48,9 @@ __FBSDID("$FreeBSD$");
 #include "kvm_private.h"
 
 static struct nlist kvm_pcpu_nl[] = {
-       { "_cpuid_to_pcpu" },
-       { "_mp_maxcpus" },

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to