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 if (kv->kve_structsize == 0)
49 bp += kv->kve_structsize;
53 kiv = calloc(cnt, sizeof(*kiv));
63 kv = (struct kinfo_vmentry *)(uintptr_t)bp;
64 if (kv->kve_structsize == 0)
66 /* Copy/expand into pre-zeroed buffer */
67 memcpy(kp, kv, kv->kve_structsize);
68 /* Advance to next packed record */
69 bp += kv->kve_structsize;
70 /* Set field size to fixed length, advance */
71 kp->kve_structsize = sizeof(*kp);
76 return (kiv); /* Caller must free() return value */