3 #include <sys/sysctl.h>
10 struct kinfo_vmentry *
11 kinfo_getvmmap(pid_t pid, int *cntp)
18 struct kinfo_vmentry *kiv, *kp, *kv;
24 mib[2] = KERN_PROC_VMMAP;
27 error = sysctl(mib, nitems(mib), NULL, &len, NULL, 0);
34 error = sysctl(mib, nitems(mib), buf, &len, NULL, 0);
39 /* Pass 1: count items */
44 kv = (struct kinfo_vmentry *)(uintptr_t)bp;
45 if (kv->kve_structsize == 0)
47 bp += kv->kve_structsize;
51 kiv = calloc(cnt, sizeof(*kiv));
61 kv = (struct kinfo_vmentry *)(uintptr_t)bp;
62 if (kv->kve_structsize == 0)
64 /* Copy/expand into pre-zeroed buffer */
65 memcpy(kp, kv, kv->kve_structsize);
66 /* Advance to next packed record */
67 bp += kv->kve_structsize;
68 /* Set field size to fixed length, advance */
69 kp->kve_structsize = sizeof(*kp);
74 return (kiv); /* Caller must free() return value */