6 #include <sys/sysctl.h>
12 struct kinfo_vmentry *
13 kinfo_getvmmap(pid_t pid, int *cntp)
20 struct kinfo_vmentry *kiv, *kp, *kv;
26 mib[2] = KERN_PROC_VMMAP;
29 error = sysctl(mib, 4, NULL, &len, NULL, 0);
36 error = sysctl(mib, 4, buf, &len, NULL, 0);
41 /* Pass 1: count items */
46 kv = (struct kinfo_vmentry *)(uintptr_t)bp;
47 bp += kv->kve_structsize;
51 kiv = calloc(cnt, sizeof(*kiv));
61 kv = (struct kinfo_vmentry *)(uintptr_t)bp;
62 /* Copy/expand into pre-zeroed buffer */
63 memcpy(kp, kv, kv->kve_structsize);
64 /* Advance to next packed record */
65 bp += kv->kve_structsize;
66 /* Set field size to fixed length, advance */
67 kp->kve_structsize = sizeof(*kp);
72 return (kiv); /* Caller must free() return value */