etc/services - sync with NetBSD-8
[minix.git] / lib / libutil / kinfo_getvmmap.c
blob8b817e8dd3d160a1f7872095ec7c1c38755be92c
1 #include <sys/cdefs.h>
2 #ifdef __FBSDID
3 __FBSDID("$FreeBSD: head/lib/libutil/kinfo_getvmmap.c 186512 2008-12-27 11:12:23Z rwatson $");
4 #endif
5 __RCSID("$NetBSD: kinfo_getvmmap.c,v 1.3 2015/09/26 20:28:55 christos Exp $");
7 #include <sys/param.h>
8 #include <sys/user.h>
9 #include <sys/sysctl.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <util.h>
13 #include <uvm/uvm_param.h>
15 struct kinfo_vmentry *
16 kinfo_getvmmap(pid_t pid, size_t *cntp)
18 int mib[5];
19 int error;
20 size_t len;
21 struct kinfo_vmentry *kiv;
23 *cntp = 0;
24 len = 0;
25 mib[0] = CTL_VM;
26 mib[1] = VM_PROC;
27 mib[2] = VM_PROC_MAP;
28 mib[3] = pid;
29 mib[4] = sizeof(*kiv);
31 error = sysctl(mib, (u_int)__arraycount(mib), NULL, &len, NULL, 0);
32 if (error)
33 return NULL;
35 len = len * 4 / 3;
37 kiv = malloc(len);
38 if (kiv == NULL)
39 return NULL;
41 error = sysctl(mib, (u_int)__arraycount(mib), kiv, &len, NULL, 0);
42 if (error) {
43 free(kiv);
44 return NULL;
47 *cntp = len / sizeof(*kiv);
48 return kiv; /* Caller must free() return value */