Ruby: missing/procstat_vm.c Source File

Ruby 3.2.5p208 (2024-07-26 revision 31d0f1a2e7dbfb60731d1f05b868e1d578cda493)

procstat_vm.c
1#include <sys/user.h>
2#include <sys/sysctl.h>
3#include <sys/param.h>
4#include <libprocstat.h>
5# ifndef KVME_TYPE_MGTDEVICE
6# define KVME_TYPE_MGTDEVICE 8
7# endif
8void
9procstat_vm(struct procstat *procstat, struct kinfo_proc *kipp)
10{
11 struct kinfo_vmentry *freep, *kve;
12 int ptrwidth;
13 unsigned int i, cnt;
14 const char *str;
15#ifdef __x86_64__
16 ptrwidth = 14;
17#else
18 ptrwidth = 2*sizeof(void *) + 2;
19#endif
20 fprintf(stderr, "%*s %*s %3s %4s %4s %3s %3s %4s %-2s %-s\n",
21 ptrwidth, "START", ptrwidth, "END", "PRT", "RES",
22 "P""RES", "REF", "SHD", "FL", "TP", "PATH");
23
24#ifdef HAVE_PROCSTAT_GETVMMAP
25 freep = procstat_getvmmap(procstat, kipp, &cnt);
26#else
27 freep = kinfo_getvmmap(kipp->ki_pid, &cnt);
28#endif
29 if (freep == NULL)
30 return;
31 for (i = 0; i < cnt; i++) {
32 kve = &freep[i];
33 fprintf(stderr, "%#*jx ", ptrwidth, (uintmax_t)kve->kve_start);
34 fprintf(stderr, "%#*jx ", ptrwidth, (uintmax_t)kve->kve_end);
35 fprintf(stderr, "%s", kve->kve_protection & KVME_PROT_READ ? "r" : "-");
36 fprintf(stderr, "%s", kve->kve_protection & KVME_PROT_WRITE ? "w" : "-");
37 fprintf(stderr, "%s ", kve->kve_protection & KVME_PROT_EXEC ? "x" : "-");
38 fprintf(stderr, "%4d ", kve->kve_resident);
39 fprintf(stderr, "%4d ", kve->kve_private_resident);
40 fprintf(stderr, "%3d ", kve->kve_ref_count);
41 fprintf(stderr, "%3d ", kve->kve_shadow_count);
42 fprintf(stderr, "%-1s", kve->kve_flags & KVME_FLAG_COW ? "C" : "-");
43 fprintf(stderr, "%-1s", kve->kve_flags & KVME_FLAG_NEEDS_COPY ? "N" :
44 "-");
45 fprintf(stderr, "%-1s", kve->kve_flags & KVME_FLAG_SUPER ? "S" : "-");
46 fprintf(stderr, "%-1s ", kve->kve_flags & KVME_FLAG_GROWS_UP ? "U" :
47 kve->kve_flags & KVME_FLAG_GROWS_DOWN ? "D" : "-");
48 switch (kve->kve_type) {
49 case KVME_TYPE_NONE:
50 str = "--";
51 break;
52 case KVME_TYPE_DEFAULT:
53 str = "df";
54 break;
55 case KVME_TYPE_VNODE:
56 str = "vn";
57 break;
58 case KVME_TYPE_SWAP:
59 str = "sw";
60 break;
61 case KVME_TYPE_DEVICE:
62 str = "dv";
63 break;
64 case KVME_TYPE_PHYS:
65 str = "ph";
66 break;
67 case KVME_TYPE_DEAD:
68 str = "dd";
69 break;
70 case KVME_TYPE_SG:
71 str = "sg";
72 break;
73 case KVME_TYPE_MGTDEVICE:
74 str = "md";
75 break;
76 case KVME_TYPE_UNKNOWN:
77 default:
78 str = "??";
79 break;
80 }
81 fprintf(stderr, "%-2s ", str);
82 fprintf(stderr, "%-s\n", kve->kve_path);
83 }
84 free(freep);
85}