Ruby: missing/procstat_vm.c Source File

Ruby 3.4.4p34 (2025-05-14 revision a38531fd3f617bf734ef7d6c595325f69985ea1d)

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, FILE *errout)
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(errout, "%*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(errout, "%#*jx ", ptrwidth, (uintmax_t)kve->kve_start);
34 fprintf(errout, "%#*jx ", ptrwidth, (uintmax_t)kve->kve_end);
35 fprintf(errout, "%s", kve->kve_protection & KVME_PROT_READ ? "r" : "-");
36 fprintf(errout, "%s", kve->kve_protection & KVME_PROT_WRITE ? "w" : "-");
37 fprintf(errout, "%s ", kve->kve_protection & KVME_PROT_EXEC ? "x" : "-");
38 fprintf(errout, "%4d ", kve->kve_resident);
39 fprintf(errout, "%4d ", kve->kve_private_resident);
40 fprintf(errout, "%3d ", kve->kve_ref_count);
41 fprintf(errout, "%3d ", kve->kve_shadow_count);
42 fprintf(errout, "%-1s", kve->kve_flags & KVME_FLAG_COW ? "C" : "-");
43 fprintf(errout, "%-1s", kve->kve_flags & KVME_FLAG_NEEDS_COPY ? "N" :
44 "-");
45 fprintf(errout, "%-1s", kve->kve_flags & KVME_FLAG_SUPER ? "S" : "-");
46 fprintf(errout, "%-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(errout, "%-2s ", str);
82 fprintf(errout, "%-s\n", kve->kve_path);
83 }
84 free(freep);
85}