Deleted Added
full compact
26c26
< * $FreeBSD: head/usr.bin/procstat/procstat_vm.c 176107 2008-02-08 11:03:05Z dwmalone $
---
> * $FreeBSD: head/usr.bin/procstat/procstat_vm.c 185548 2008-12-02 06:50:26Z peter $
36a37
> #include <libutil.h>
44,45c45,46
< int error, name[4], ptrwidth;
< unsigned int i;
---
> int ptrwidth;
> int i, cnt;
47d47
< size_t len;
55,86c55,57
< name[0] = CTL_KERN;
< name[1] = KERN_PROC;
< name[2] = KERN_PROC_VMMAP;
< name[3] = pid;
<
< len = 0;
< error = sysctl(name, 4, NULL, &len, NULL, 0);
< if (error < 0 && errno != ESRCH && errno != EPERM) {
< warn("sysctl: kern.proc.vmmap: %d", pid);
< return;
< }
< if (error < 0)
< return;
<
< /*
< * Especially if running procstat -sv, we may need room for more
< * mappings when printing than were present when we queried, so pad
< * out the allocation a bit.
< */
< len += sizeof(*kve) * 3;
< freep = kve = malloc(len);
< if (kve == NULL)
< err(-1, "malloc");
< if (sysctl(name, 4, kve, &len, NULL, 0) < 0) {
< warn("sysctl: kern.proc.vmmap: %d", pid);
< free(freep);
< return;
< }
<
< for (i = 0; i < (len / sizeof(*kve)); i++, kve++) {
< if (kve->kve_structsize != sizeof(*kve))
< errx(-1, "kinfo_vmentry structure mismatch");
---
> freep = kinfo_getvmmap(pid, &cnt);
> for (i = 0; i < cnt; i++) {
> kve = &freep[i];