2 * SPDX-License-Identifier: BSD-4-Clause
4 * Copyright (c) 2000 Dag-Erling Coïdan Smørgrav
5 * Copyright (c) 1999 Pierre Beyssac
6 * Copyright (c) 1993 Jan-Simon Pendry
8 * The Regents of the University of California. All rights reserved.
10 * This code is derived from software contributed to Berkeley by
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgement:
23 * This product includes software developed by the University of
24 * California, Berkeley and its contributors.
25 * 4. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 * @(#)procfs_status.c 8.4 (Berkeley) 6/15/94
44 #include <sys/cdefs.h>
45 __FBSDID("$FreeBSD$");
47 #include <sys/param.h>
48 #include <sys/queue.h>
49 #include <sys/blist.h>
52 #include <sys/fcntl.h>
53 #include <sys/filedesc.h>
55 #include <sys/kernel.h>
56 #include <sys/limits.h>
57 #include <sys/linker.h>
59 #include <sys/malloc.h>
61 #include <sys/mutex.h>
62 #include <sys/namei.h>
64 #include <sys/ptrace.h>
65 #include <sys/resourcevar.h>
66 #include <sys/resource.h>
70 #include <sys/socket.h>
71 #include <sys/syscallsubr.h>
72 #include <sys/sysctl.h>
73 #include <sys/sysent.h>
74 #include <sys/systm.h>
79 #include <sys/vmmeter.h>
80 #include <sys/vnode.h>
84 #include <net/if_var.h>
85 #include <net/if_types.h>
88 #include <vm/vm_extern.h>
90 #include <vm/vm_map.h>
91 #include <vm/vm_param.h>
92 #include <vm/vm_object.h>
93 #include <vm/swap_pager.h>
95 #include <machine/clock.h>
97 #include <geom/geom.h>
98 #include <geom/geom_int.h>
100 #if defined(__i386__) || defined(__amd64__)
101 #include <machine/cputypes.h>
102 #include <machine/md_var.h>
103 #endif /* __i386__ || __amd64__ */
105 #include <compat/linux/linux.h>
106 #include <compat/linux/linux_mib.h>
107 #include <compat/linux/linux_misc.h>
108 #include <compat/linux/linux_util.h>
109 #include <fs/pseudofs/pseudofs.h>
110 #include <fs/procfs/procfs.h>
113 * Various conversion macros
115 #define T2J(x) ((long)(((x) * 100ULL) / (stathz ? stathz : hz))) /* ticks to jiffies */
116 #define T2CS(x) ((unsigned long)(((x) * 100ULL) / (stathz ? stathz : hz))) /* ticks to centiseconds */
117 #define T2S(x) ((x) / (stathz ? stathz : hz)) /* ticks to seconds */
118 #define B2K(x) ((x) >> 10) /* bytes to kbytes */
119 #define B2P(x) ((x) >> PAGE_SHIFT) /* bytes to pages */
120 #define P2B(x) ((x) << PAGE_SHIFT) /* pages to bytes */
121 #define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* pages to kbytes */
122 #define TV2J(x) ((x)->tv_sec * 100UL + (x)->tv_usec / 10000)
125 * @brief Mapping of ki_stat in struct kinfo_proc to the linux state
127 * The linux procfs state field displays one of the characters RSDZTW to
128 * denote running, sleeping in an interruptible wait, waiting in an
129 * uninterruptible disk sleep, a zombie process, process is being traced
130 * or stopped, or process is paging respectively.
132 * Our struct kinfo_proc contains the variable ki_stat which contains a
133 * value out of SIDL, SRUN, SSLEEP, SSTOP, SZOMB, SWAIT and SLOCK.
135 * This character array is used with ki_stati-1 as an index and tries to
136 * map our states to suitable linux states.
138 static char linux_state[] = "RRSTZDD";
141 * Filler function for proc/meminfo
144 linprocfs_domeminfo(PFS_FILL_ARGS)
146 unsigned long memtotal; /* total memory in bytes */
147 unsigned long memused; /* used memory in bytes */
148 unsigned long memfree; /* free memory in bytes */
149 unsigned long buffers, cached; /* buffer / cache memory ??? */
150 unsigned long long swaptotal; /* total swap space in bytes */
151 unsigned long long swapused; /* used swap space in bytes */
152 unsigned long long swapfree; /* free swap space in bytes */
155 memtotal = physmem * PAGE_SIZE;
157 * The correct thing here would be:
159 memfree = vm_free_count() * PAGE_SIZE;
160 memused = memtotal - memfree;
162 * but it might mislead linux binaries into thinking there
163 * is very little memory left, so we cheat and tell them that
164 * all memory that isn't wired down is free.
166 memused = vm_wire_count() * PAGE_SIZE;
167 memfree = memtotal - memused;
168 swap_pager_status(&i, &j);
169 swaptotal = (unsigned long long)i * PAGE_SIZE;
170 swapused = (unsigned long long)j * PAGE_SIZE;
171 swapfree = swaptotal - swapused;
173 * We'd love to be able to write:
177 * but bufspace is internal to vfs_bio.c and we don't feel
178 * like unstaticizing it just for linprocfs's sake.
181 cached = vm_inactive_count() * PAGE_SIZE;
184 "MemTotal: %9lu kB\n"
188 "SwapTotal:%9llu kB\n"
189 "SwapFree: %9llu kB\n",
190 B2K(memtotal), B2K(memfree), B2K(buffers),
191 B2K(cached), B2K(swaptotal), B2K(swapfree));
196 #if defined(__i386__) || defined(__amd64__)
198 * Filler function for proc/cpuinfo (i386 & amd64 version)
201 linprocfs_docpuinfo(PFS_FILL_ARGS)
212 * We default the flags to include all non-conflicting flags,
213 * and the Intel versions of conflicting flags.
215 static char *cpu_feature_names[] = {
216 /* 0 */ "fpu", "vme", "de", "pse",
217 /* 4 */ "tsc", "msr", "pae", "mce",
218 /* 8 */ "cx8", "apic", "", "sep",
219 /* 12 */ "mtrr", "pge", "mca", "cmov",
220 /* 16 */ "pat", "pse36", "pn", "clflush",
221 /* 20 */ "", "dts", "acpi", "mmx",
222 /* 24 */ "fxsr", "sse", "sse2", "ss",
223 /* 28 */ "ht", "tm", "ia64", "pbe"
226 static char *amd_feature_names[] = {
227 /* 0 */ "", "", "", "",
228 /* 4 */ "", "", "", "",
229 /* 8 */ "", "", "", "syscall",
230 /* 12 */ "", "", "", "",
231 /* 16 */ "", "", "", "mp",
232 /* 20 */ "nx", "", "mmxext", "",
233 /* 24 */ "", "fxsr_opt", "pdpe1gb", "rdtscp",
234 /* 28 */ "", "lm", "3dnowext", "3dnow"
237 static char *cpu_feature2_names[] = {
238 /* 0 */ "pni", "pclmulqdq", "dtes3", "monitor",
239 /* 4 */ "ds_cpl", "vmx", "smx", "est",
240 /* 8 */ "tm2", "ssse3", "cid", "sdbg",
241 /* 12 */ "fma", "cx16", "xptr", "pdcm",
242 /* 16 */ "", "pcid", "dca", "sse4_1",
243 /* 20 */ "sse4_2", "x2apic", "movbe", "popcnt",
244 /* 24 */ "tsc_deadline_timer", "aes", "xsave", "",
245 /* 28 */ "avx", "f16c", "rdrand", "hypervisor"
248 static char *amd_feature2_names[] = {
249 /* 0 */ "lahf_lm", "cmp_legacy", "svm", "extapic",
250 /* 4 */ "cr8_legacy", "abm", "sse4a", "misalignsse",
251 /* 8 */ "3dnowprefetch", "osvw", "ibs", "xop",
252 /* 12 */ "skinit", "wdt", "", "lwp",
253 /* 16 */ "fma4", "tce", "", "nodeid_msr",
254 /* 20 */ "", "tbm", "topoext", "perfctr_core",
255 /* 24 */ "perfctr_nb", "", "bpext", "ptsc",
256 /* 28 */ "perfctr_llc", "mwaitx", "", ""
259 static char *cpu_stdext_feature_names[] = {
260 /* 0 */ "fsgsbase", "tsc_adjust", "", "bmi1",
261 /* 4 */ "hle", "avx2", "", "smep",
262 /* 8 */ "bmi2", "erms", "invpcid", "rtm",
263 /* 12 */ "cqm", "", "mpx", "rdt_a",
264 /* 16 */ "avx512f", "avx512dq", "rdseed", "adx",
265 /* 20 */ "smap", "avx512ifma", "", "clflushopt",
266 /* 24 */ "clwb", "intel_pt", "avx512pf", "avx512er",
267 /* 28 */ "avx512cd", "sha_ni", "avx512bw", "avx512vl"
270 static char *power_flags[] = {
273 "100mhzsteps", "hwpstate", "",
274 "cpb", "eff_freq_ro", "proc_feedback",
278 hw_model[0] = CTL_HW;
279 hw_model[1] = HW_MODEL;
281 size = sizeof(model);
282 if (kernel_sysctl(td, hw_model, 2, &model, &size, 0, 0, 0, 0) != 0)
283 strcpy(model, "unknown");
285 switch (cpu_vendor_id) {
287 if (cpu_class < CPUCLASS_686)
288 cpu_feature_names[16] = "fcmov";
290 case CPU_VENDOR_CYRIX:
291 cpu_feature_names[24] = "cxmmx";
295 if (cpu_exthigh >= 0x80000006)
296 do_cpuid(0x80000006, cache_size);
298 memset(cache_size, 0, sizeof(cache_size));
299 for (i = 0; i < mp_ncpus; ++i) {
302 freq = atomic_load_acq_64(&tsc_freq);
304 fqmhz = (freq + 4999) / 1000000;
305 fqkhz = ((freq + 4999) / 10000) % 100;
309 "vendor_id\t: %.20s\n"
314 "cpu MHz\t\t: %d.%02d\n"
315 "cache size\t: %d KB\n"
316 "physical id\t: %d\n"
321 "initial apicid\t: %d\n"
323 "fpu_exception\t: %s\n"
324 "cpuid level\t: %d\n"
326 i, cpu_vendor, CPUID_TO_FAMILY(cpu_id),
327 CPUID_TO_MODEL(cpu_id), model, cpu_id & CPUID_STEPPING,
329 (cache_size[2] >> 16), 0, mp_ncpus, i, mp_ncpus,
330 i, i, /*cpu_id & CPUID_LOCAL_APIC_ID ??*/
331 (cpu_feature & CPUID_FPU) ? "yes" : "no", "yes",
332 CPUID_TO_FAMILY(cpu_id), "yes");
333 sbuf_cat(sb, "flags\t\t:");
334 for (j = 0; j < nitems(cpu_feature_names); j++)
335 if (cpu_feature & (1 << j) &&
336 cpu_feature_names[j][0] != '\0')
337 sbuf_printf(sb, " %s", cpu_feature_names[j]);
338 for (j = 0; j < nitems(amd_feature_names); j++)
339 if (amd_feature & (1 << j) &&
340 amd_feature_names[j][0] != '\0')
341 sbuf_printf(sb, " %s", amd_feature_names[j]);
342 for (j = 0; j < nitems(cpu_feature2_names); j++)
343 if (cpu_feature2 & (1 << j) &&
344 cpu_feature2_names[j][0] != '\0')
345 sbuf_printf(sb, " %s", cpu_feature2_names[j]);
346 for (j = 0; j < nitems(amd_feature2_names); j++)
347 if (amd_feature2 & (1 << j) &&
348 amd_feature2_names[j][0] != '\0')
349 sbuf_printf(sb, " %s", amd_feature2_names[j]);
350 for (j = 0; j < nitems(cpu_stdext_feature_names); j++)
351 if (cpu_stdext_feature & (1 << j) &&
352 cpu_stdext_feature_names[j][0] != '\0')
353 sbuf_printf(sb, " %s",
354 cpu_stdext_feature_names[j]);
358 "bogomips\t: %d.%02d\n"
359 "clflush size\t: %d\n"
360 "cache_alignment\t: %d\n"
361 "address sizes\t: %d bits physical, %d bits virtual\n",
362 #if defined(I586_CPU) && !defined(NO_F00F_HACK)
363 (has_f00f_bug) ? "Intel F00F" : "",
368 cpu_clflush_line_size, cpu_clflush_line_size,
370 (cpu_maxphyaddr > 32) ? 48 : 0);
371 sbuf_cat(sb, "power management: ");
372 for (j = 0; j < nitems(power_flags); j++)
373 if (amd_pminfo & (1 << j))
374 sbuf_printf(sb, " %s", power_flags[j]);
375 sbuf_cat(sb, "\n\n");
377 /* XXX per-cpu vendor / class / model / id? */
384 /* ARM64TODO: implement non-stubbed linprocfs_docpuinfo */
386 linprocfs_docpuinfo(PFS_FILL_ARGS)
390 for (i = 0; i < mp_ncpus; ++i) {
393 "BogoMIPS\t: %d.%02d\n",
395 sbuf_cat(sb, "Features\t: ");
398 "CPU implementer\t: \n"
399 "CPU architecture: \n"
400 "CPU variant\t: 0x%x\n"
402 "CPU revision\t: %d\n",
409 #endif /* __i386__ || __amd64__ */
412 * Filler function for proc/mtab
414 * This file doesn't exist in Linux' procfs, but is included here so
415 * users can symlink /compat/linux/etc/mtab to /proc/mtab
418 linprocfs_domtab(PFS_FILL_ARGS)
422 char *dlep, *flep, *mntto, *mntfrom, *fstype;
425 struct statfs *buf, *sp;
428 /* resolve symlinks etc. in the emulation tree prefix */
429 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, linux_emul_path, td);
432 lep = linux_emul_path;
434 if (vn_fullpath(td, nd.ni_vp, &dlep, &flep) == 0)
438 lep_len = strlen(lep);
441 error = kern_getfsstat(td, &buf, SIZE_T_MAX, &count,
442 UIO_SYSSPACE, MNT_WAIT);
449 for (sp = buf; count > 0; sp++, count--) {
450 /* determine device name */
451 mntfrom = sp->f_mntfromname;
453 /* determine mount point */
454 mntto = sp->f_mntonname;
455 if (strncmp(mntto, lep, lep_len) == 0 && mntto[lep_len] == '/')
458 /* determine fs type */
459 fstype = sp->f_fstypename;
460 if (strcmp(fstype, pn->pn_info->pi_name) == 0)
461 mntfrom = fstype = "proc";
462 else if (strcmp(fstype, "procfs") == 0)
465 if (strcmp(fstype, "linsysfs") == 0) {
466 sbuf_printf(sb, "/sys %s sysfs %s", mntto,
467 sp->f_flags & MNT_RDONLY ? "ro" : "rw");
469 /* For Linux msdosfs is called vfat */
470 if (strcmp(fstype, "msdosfs") == 0)
472 sbuf_printf(sb, "%s %s %s %s", mntfrom, mntto, fstype,
473 sp->f_flags & MNT_RDONLY ? "ro" : "rw");
475 #define ADD_OPTION(opt, name) \
476 if (sp->f_flags & (opt)) sbuf_printf(sb, "," name);
477 ADD_OPTION(MNT_SYNCHRONOUS, "sync");
478 ADD_OPTION(MNT_NOEXEC, "noexec");
479 ADD_OPTION(MNT_NOSUID, "nosuid");
480 ADD_OPTION(MNT_UNION, "union");
481 ADD_OPTION(MNT_ASYNC, "async");
482 ADD_OPTION(MNT_SUIDDIR, "suiddir");
483 ADD_OPTION(MNT_NOSYMFOLLOW, "nosymfollow");
484 ADD_OPTION(MNT_NOATIME, "noatime");
486 /* a real Linux mtab will also show NFS options */
487 sbuf_printf(sb, " 0 0\n");
496 * Filler function for proc/partitions
499 linprocfs_dopartitions(PFS_FILL_ARGS)
503 struct g_provider *pp;
507 sbuf_printf(sb, "major minor #blocks name rio rmerge rsect "
508 "ruse wio wmerge wsect wuse running use aveq\n");
510 LIST_FOREACH(cp, &g_classes, class) {
511 if (strcmp(cp->name, "DISK") == 0 ||
512 strcmp(cp->name, "PART") == 0)
513 LIST_FOREACH(gp, &cp->geom, geom) {
514 LIST_FOREACH(pp, &gp->provider, provider) {
515 if (linux_driver_get_major_minor(
516 pp->name, &major, &minor) != 0) {
520 sbuf_printf(sb, "%d %d %lld %s "
522 "%d %d %d %d %d %d\n",
524 (long long)pp->mediasize, pp->name,
536 * Filler function for proc/stat
538 * Output depends on kernel version:
541 * user nice system idle
543 * user nice system idle iowait
545 * user nice system idle iowait irq softirq steal
547 * user nice system idle iowait irq softirq steal guest
549 * user nice system idle iowait irq softirq steal guest guest_nice
552 linprocfs_dostat(PFS_FILL_ARGS)
555 long cp_time[CPUSTATES];
557 struct timeval boottime;
560 bool has_intr = true;
562 if (linux_kernver(td) >= LINUX_KERNVER(2,6,33)) {
563 zero_pad = " 0 0 0 0\n";
564 } else if (linux_kernver(td) >= LINUX_KERNVER(2,6,24)) {
565 zero_pad = " 0 0 0\n";
566 } else if (linux_kernver(td) >= LINUX_KERNVER(2,6,11)) {
568 } else if (linux_kernver(td) >= LINUX_KERNVER(2,5,41)) {
576 read_cpu_time(cp_time);
577 getboottime(&boottime);
578 /* Parameters common to all versions */
579 sbuf_printf(sb, "cpu %lu %lu %lu %lu",
580 T2J(cp_time[CP_USER]),
581 T2J(cp_time[CP_NICE]),
582 T2J(cp_time[CP_SYS]),
583 T2J(cp_time[CP_IDLE]));
585 /* Print interrupt stats if available */
587 sbuf_printf(sb, " 0 %lu", T2J(cp_time[CP_INTR]));
590 /* Pad out remaining fields depending on version */
591 sbuf_printf(sb, "%s", zero_pad);
595 cp = pcpu->pc_cp_time;
596 sbuf_printf(sb, "cpu%d %lu %lu %lu %lu", i,
603 sbuf_printf(sb, " 0 %lu", T2J(cp[CP_INTR]));
606 sbuf_printf(sb, "%s", zero_pad);
615 (uintmax_t)VM_CNT_FETCH(v_vnodepgsin),
616 (uintmax_t)VM_CNT_FETCH(v_vnodepgsout),
617 (uintmax_t)VM_CNT_FETCH(v_swappgsin),
618 (uintmax_t)VM_CNT_FETCH(v_swappgsout),
619 (uintmax_t)VM_CNT_FETCH(v_intr),
620 (uintmax_t)VM_CNT_FETCH(v_swtch),
621 (long long)boottime.tv_sec);
626 linprocfs_doswaps(PFS_FILL_ARGS)
629 uintmax_t total, used;
631 char devname[SPECNAMELEN + 1];
633 sbuf_printf(sb, "Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
635 if (swap_dev_info(n, &xsw, devname, sizeof(devname)) != 0)
637 total = (uintmax_t)xsw.xsw_nblks * PAGE_SIZE / 1024;
638 used = (uintmax_t)xsw.xsw_used * PAGE_SIZE / 1024;
641 * The space and not tab after the device name is on
642 * purpose. Linux does so.
644 sbuf_printf(sb, "/dev/%-34s unknown\t\t%jd\t%jd\t-1\n",
645 devname, total, used);
651 * Filler function for proc/uptime
654 linprocfs_douptime(PFS_FILL_ARGS)
656 long cp_time[CPUSTATES];
660 read_cpu_time(cp_time);
661 sbuf_printf(sb, "%lld.%02ld %ld.%02lu\n",
662 (long long)tv.tv_sec, tv.tv_usec / 10000,
663 T2S(cp_time[CP_IDLE] / mp_ncpus),
664 T2CS(cp_time[CP_IDLE] / mp_ncpus) % 100);
672 linprocfs_osbuild(struct thread *td, struct sbuf *sb)
678 strncpy(osbuild, version, 256);
680 cp1 = strstr(osbuild, "\n");
681 cp2 = strstr(osbuild, ":");
684 cp1 = strstr(osbuild, "#");
688 sbuf_printf(sb, "%s%s", cp1, cp2 + 1);
691 sbuf_cat(sb, "#4 Sun Dec 18 04:30:00 CET 1977");
698 linprocfs_osbuilder(struct thread *td, struct sbuf *sb)
704 cp = strstr(version, "\n ");
706 strncpy(builder, cp + 5, 256);
708 cp = strstr(builder, ":");
713 sbuf_cat(sb, builder);
716 sbuf_cat(sb, "des@freebsd.org");
720 * Filler function for proc/version
723 linprocfs_doversion(PFS_FILL_ARGS)
725 char osname[LINUX_MAX_UTSNAME];
726 char osrelease[LINUX_MAX_UTSNAME];
728 linux_get_osname(td, osname);
729 linux_get_osrelease(td, osrelease);
730 sbuf_printf(sb, "%s version %s (", osname, osrelease);
731 linprocfs_osbuilder(td, sb);
732 sbuf_cat(sb, ") (gcc version " __VERSION__ ") ");
733 linprocfs_osbuild(td, sb);
740 * Filler function for proc/loadavg
743 linprocfs_doloadavg(PFS_FILL_ARGS)
747 "%d.%02d %d.%02d %d.%02d %d/%d %d\n",
748 (int)(averunnable.ldavg[0] / averunnable.fscale),
749 (int)(averunnable.ldavg[0] * 100 / averunnable.fscale % 100),
750 (int)(averunnable.ldavg[1] / averunnable.fscale),
751 (int)(averunnable.ldavg[1] * 100 / averunnable.fscale % 100),
752 (int)(averunnable.ldavg[2] / averunnable.fscale),
753 (int)(averunnable.ldavg[2] * 100 / averunnable.fscale % 100),
754 1, /* number of running tasks */
755 nprocs, /* number of tasks */
756 lastpid /* the last pid */
762 * Filler function for proc/pid/stat
765 linprocfs_doprocstat(PFS_FILL_ARGS)
767 struct kinfo_proc kp;
768 struct timeval boottime;
770 static int ratelimit = 0;
771 vm_offset_t startcode, startdata;
773 getboottime(&boottime);
774 sx_slock(&proctree_lock);
776 fill_kinfo_proc(p, &kp);
777 sx_sunlock(&proctree_lock);
779 startcode = (vm_offset_t)p->p_vmspace->vm_taddr;
780 startdata = (vm_offset_t)p->p_vmspace->vm_daddr;
785 sbuf_printf(sb, "%d", p->p_pid);
786 #define PS_ADD(name, fmt, arg) sbuf_printf(sb, " " fmt, arg)
787 PS_ADD("comm", "(%s)", p->p_comm);
788 if (kp.ki_stat > sizeof(linux_state)) {
791 if (ratelimit == 0) {
792 printf("linprocfs: don't know how to handle unknown FreeBSD state %d/%zd, mapping to R\n",
793 kp.ki_stat, sizeof(linux_state));
797 state = linux_state[kp.ki_stat - 1];
798 PS_ADD("state", "%c", state);
799 PS_ADD("ppid", "%d", p->p_pptr ? p->p_pptr->p_pid : 0);
800 PS_ADD("pgrp", "%d", p->p_pgid);
801 PS_ADD("session", "%d", p->p_session->s_sid);
803 PS_ADD("tty", "%ju", (uintmax_t)kp.ki_tdev);
804 PS_ADD("tpgid", "%d", kp.ki_tpgid);
805 PS_ADD("flags", "%u", 0); /* XXX */
806 PS_ADD("minflt", "%lu", kp.ki_rusage.ru_minflt);
807 PS_ADD("cminflt", "%lu", kp.ki_rusage_ch.ru_minflt);
808 PS_ADD("majflt", "%lu", kp.ki_rusage.ru_majflt);
809 PS_ADD("cmajflt", "%lu", kp.ki_rusage_ch.ru_majflt);
810 PS_ADD("utime", "%ld", TV2J(&kp.ki_rusage.ru_utime));
811 PS_ADD("stime", "%ld", TV2J(&kp.ki_rusage.ru_stime));
812 PS_ADD("cutime", "%ld", TV2J(&kp.ki_rusage_ch.ru_utime));
813 PS_ADD("cstime", "%ld", TV2J(&kp.ki_rusage_ch.ru_stime));
814 PS_ADD("priority", "%d", kp.ki_pri.pri_user);
815 PS_ADD("nice", "%d", kp.ki_nice); /* 19 (nicest) to -19 */
816 PS_ADD("0", "%d", 0); /* removed field */
817 PS_ADD("itrealvalue", "%d", 0); /* XXX */
818 PS_ADD("starttime", "%lu", TV2J(&kp.ki_start) - TV2J(&boottime));
819 PS_ADD("vsize", "%ju", P2K((uintmax_t)kp.ki_size));
820 PS_ADD("rss", "%ju", (uintmax_t)kp.ki_rssize);
821 PS_ADD("rlim", "%lu", kp.ki_rusage.ru_maxrss);
822 PS_ADD("startcode", "%ju", (uintmax_t)startcode);
823 PS_ADD("endcode", "%ju", (uintmax_t)startdata);
824 PS_ADD("startstack", "%u", 0); /* XXX */
825 PS_ADD("kstkesp", "%u", 0); /* XXX */
826 PS_ADD("kstkeip", "%u", 0); /* XXX */
827 PS_ADD("signal", "%u", 0); /* XXX */
828 PS_ADD("blocked", "%u", 0); /* XXX */
829 PS_ADD("sigignore", "%u", 0); /* XXX */
830 PS_ADD("sigcatch", "%u", 0); /* XXX */
831 PS_ADD("wchan", "%u", 0); /* XXX */
832 PS_ADD("nswap", "%lu", kp.ki_rusage.ru_nswap);
833 PS_ADD("cnswap", "%lu", kp.ki_rusage_ch.ru_nswap);
834 PS_ADD("exitsignal", "%d", 0); /* XXX */
835 PS_ADD("processor", "%u", kp.ki_lastcpu);
836 PS_ADD("rt_priority", "%u", 0); /* XXX */ /* >= 2.5.19 */
837 PS_ADD("policy", "%u", kp.ki_pri.pri_class); /* >= 2.5.19 */
845 * Filler function for proc/pid/statm
848 linprocfs_doprocstatm(PFS_FILL_ARGS)
850 struct kinfo_proc kp;
853 sx_slock(&proctree_lock);
855 fill_kinfo_proc(p, &kp);
857 sx_sunlock(&proctree_lock);
860 * See comments in linprocfs_doprocstatus() regarding the
861 * computation of lsize.
863 /* size resident share trs drs lrs dt */
864 sbuf_printf(sb, "%ju ", B2P((uintmax_t)kp.ki_size));
865 sbuf_printf(sb, "%ju ", (uintmax_t)kp.ki_rssize);
866 sbuf_printf(sb, "%ju ", (uintmax_t)0); /* XXX */
867 sbuf_printf(sb, "%ju ", (uintmax_t)kp.ki_tsize);
868 sbuf_printf(sb, "%ju ", (uintmax_t)(kp.ki_dsize + kp.ki_ssize));
869 lsize = B2P(kp.ki_size) - kp.ki_dsize -
870 kp.ki_ssize - kp.ki_tsize - 1;
871 sbuf_printf(sb, "%ju ", (uintmax_t)lsize);
872 sbuf_printf(sb, "%ju\n", (uintmax_t)0); /* XXX */
878 * Filler function for proc/pid/status
881 linprocfs_doprocstatus(PFS_FILL_ARGS)
883 struct kinfo_proc kp;
888 l_sigset_t siglist, sigignore, sigcatch;
891 sx_slock(&proctree_lock);
893 td2 = FIRST_THREAD_IN_PROC(p); /* XXXKSE pretend only one thread */
895 if (P_SHOULDSTOP(p)) {
896 state = "T (stopped)";
903 if (p->p_flag & P_WEXIT) {
904 state = "X (exiting)";
907 switch(td2->td_state) {
909 state = "S (sleeping)";
913 state = "R (running)";
916 state = "? (unknown)";
921 state = "Z (zombie)";
924 state = "? (unknown)";
929 fill_kinfo_proc(p, &kp);
930 sx_sunlock(&proctree_lock);
932 sbuf_printf(sb, "Name:\t%s\n", p->p_comm); /* XXX escape */
933 sbuf_printf(sb, "State:\t%s\n", state);
938 sbuf_printf(sb, "Pid:\t%d\n", p->p_pid);
939 sbuf_printf(sb, "PPid:\t%d\n", kp.ki_ppid );
940 sbuf_printf(sb, "TracerPid:\t%d\n", kp.ki_tracer );
941 sbuf_printf(sb, "Uid:\t%d %d %d %d\n", p->p_ucred->cr_ruid,
943 p->p_ucred->cr_svuid,
944 /* FreeBSD doesn't have fsuid */
946 sbuf_printf(sb, "Gid:\t%d %d %d %d\n", p->p_ucred->cr_rgid,
948 p->p_ucred->cr_svgid,
949 /* FreeBSD doesn't have fsgid */
951 sbuf_cat(sb, "Groups:\t");
952 for (i = 0; i < p->p_ucred->cr_ngroups; i++)
953 sbuf_printf(sb, "%d ", p->p_ucred->cr_groups[i]);
960 * While our approximation of VmLib may not be accurate (I
961 * don't know of a simple way to verify it, and I'm not sure
962 * it has much meaning anyway), I believe it's good enough.
964 * The same code that could (I think) accurately compute VmLib
965 * could also compute VmLck, but I don't really care enough to
966 * implement it. Submissions are welcome.
968 sbuf_printf(sb, "VmSize:\t%8ju kB\n", B2K((uintmax_t)kp.ki_size));
969 sbuf_printf(sb, "VmLck:\t%8u kB\n", P2K(0)); /* XXX */
970 sbuf_printf(sb, "VmRSS:\t%8ju kB\n", P2K((uintmax_t)kp.ki_rssize));
971 sbuf_printf(sb, "VmData:\t%8ju kB\n", P2K((uintmax_t)kp.ki_dsize));
972 sbuf_printf(sb, "VmStk:\t%8ju kB\n", P2K((uintmax_t)kp.ki_ssize));
973 sbuf_printf(sb, "VmExe:\t%8ju kB\n", P2K((uintmax_t)kp.ki_tsize));
974 lsize = B2P(kp.ki_size) - kp.ki_dsize -
975 kp.ki_ssize - kp.ki_tsize - 1;
976 sbuf_printf(sb, "VmLib:\t%8ju kB\n", P2K((uintmax_t)lsize));
982 bsd_to_linux_sigset(&p->p_siglist, &siglist);
984 mtx_lock(&ps->ps_mtx);
985 bsd_to_linux_sigset(&ps->ps_sigignore, &sigignore);
986 bsd_to_linux_sigset(&ps->ps_sigcatch, &sigcatch);
987 mtx_unlock(&ps->ps_mtx);
990 sbuf_printf(sb, "SigPnd:\t%016jx\n", siglist.__mask);
992 * XXX. SigBlk - target thread's signal mask, td_sigmask.
993 * To implement SigBlk pseudofs should support proc/tid dir entries.
995 sbuf_printf(sb, "SigBlk:\t%016x\n", 0);
996 sbuf_printf(sb, "SigIgn:\t%016jx\n", sigignore.__mask);
997 sbuf_printf(sb, "SigCgt:\t%016jx\n", sigcatch.__mask);
1000 * Linux also prints the capability masks, but we don't have
1001 * capabilities yet, and when we do get them they're likely to
1002 * be meaningless to Linux programs, so we lie. XXX
1004 sbuf_printf(sb, "CapInh:\t%016x\n", 0);
1005 sbuf_printf(sb, "CapPrm:\t%016x\n", 0);
1006 sbuf_printf(sb, "CapEff:\t%016x\n", 0);
1013 * Filler function for proc/pid/cwd
1016 linprocfs_doproccwd(PFS_FILL_ARGS)
1018 struct filedesc *fdp;
1020 char *fullpath = "unknown";
1021 char *freepath = NULL;
1024 FILEDESC_SLOCK(fdp);
1028 FILEDESC_SUNLOCK(fdp);
1029 vn_fullpath(td, vp, &fullpath, &freepath);
1032 sbuf_printf(sb, "%s", fullpath);
1034 free(freepath, M_TEMP);
1039 * Filler function for proc/pid/root
1042 linprocfs_doprocroot(PFS_FILL_ARGS)
1044 struct filedesc *fdp;
1046 char *fullpath = "unknown";
1047 char *freepath = NULL;
1050 FILEDESC_SLOCK(fdp);
1051 vp = jailed(p->p_ucred) ? fdp->fd_jdir : fdp->fd_rdir;
1054 FILEDESC_SUNLOCK(fdp);
1055 vn_fullpath(td, vp, &fullpath, &freepath);
1058 sbuf_printf(sb, "%s", fullpath);
1060 free(freepath, M_TEMP);
1065 * Filler function for proc/pid/cmdline
1068 linprocfs_doproccmdline(PFS_FILL_ARGS)
1073 if ((ret = p_cansee(td, p)) != 0) {
1079 * Mimic linux behavior and pass only processes with usermode
1080 * address space as valid. Return zero silently otherwize.
1082 if (p->p_vmspace == &vmspace0) {
1086 if (p->p_args != NULL) {
1087 sbuf_bcpy(sb, p->p_args->ar_args, p->p_args->ar_length);
1092 if ((p->p_flag & P_SYSTEM) != 0) {
1099 ret = proc_getargv(td, p, sb);
1104 * Filler function for proc/pid/environ
1107 linprocfs_doprocenviron(PFS_FILL_ARGS)
1111 * Mimic linux behavior and pass only processes with usermode
1112 * address space as valid. Return zero silently otherwize.
1114 if (p->p_vmspace == &vmspace0)
1117 return (proc_getenvv(td, p, sb));
1120 static char l32_map_str[] = "%08lx-%08lx %s%s%s%s %08lx %02x:%02x %lu%s%s\n";
1121 static char l64_map_str[] = "%016lx-%016lx %s%s%s%s %08lx %02x:%02x %lu%s%s\n";
1122 static char vdso_str[] = " [vdso]";
1123 static char stack_str[] = " [stack]";
1126 * Filler function for proc/pid/maps
1129 linprocfs_doprocmaps(PFS_FILL_ARGS)
1133 vm_map_entry_t entry, tmp_entry;
1134 vm_object_t obj, tobj, lobj;
1135 vm_offset_t e_start, e_end;
1136 vm_ooffset_t off = 0;
1138 unsigned int last_timestamp;
1139 char *name = "", *freename = NULL;
1140 const char *l_map_str;
1142 int ref_count, shadow_count, flags;
1148 error = p_candebug(td, p);
1153 if (uio->uio_rw != UIO_READ)
1154 return (EOPNOTSUPP);
1157 vm = vmspace_acquire_ref(p);
1161 if (SV_CURPROC_FLAG(SV_LP64))
1162 l_map_str = l64_map_str;
1164 l_map_str = l32_map_str;
1166 vm_map_lock_read(map);
1167 for (entry = map->header.next; entry != &map->header;
1168 entry = entry->next) {
1171 if (entry->eflags & MAP_ENTRY_IS_SUB_MAP)
1173 e_prot = entry->protection;
1174 e_start = entry->start;
1176 obj = entry->object.vm_object;
1177 for (lobj = tobj = obj; tobj; tobj = tobj->backing_object) {
1178 VM_OBJECT_RLOCK(tobj);
1180 VM_OBJECT_RUNLOCK(lobj);
1183 last_timestamp = map->timestamp;
1184 vm_map_unlock_read(map);
1187 off = IDX_TO_OFF(lobj->size);
1188 vp = vm_object_vnode(lobj);
1192 VM_OBJECT_RUNLOCK(lobj);
1194 ref_count = obj->ref_count;
1195 shadow_count = obj->shadow_count;
1196 VM_OBJECT_RUNLOCK(obj);
1198 vn_fullpath(td, vp, &name, &freename);
1199 vn_lock(vp, LK_SHARED | LK_RETRY);
1200 VOP_GETATTR(vp, &vat, td->td_ucred);
1201 ino = vat.va_fileid;
1203 } else if (SV_PROC_ABI(p) == SV_ABI_LINUX) {
1204 if (e_start == p->p_sysent->sv_shared_page_base)
1206 if (e_end == p->p_sysent->sv_usrstack)
1217 * start, end, access, offset, major, minor, inode, name.
1219 error = sbuf_printf(sb, l_map_str,
1220 (u_long)e_start, (u_long)e_end,
1221 (e_prot & VM_PROT_READ)?"r":"-",
1222 (e_prot & VM_PROT_WRITE)?"w":"-",
1223 (e_prot & VM_PROT_EXECUTE)?"x":"-",
1233 free(freename, M_TEMP);
1234 vm_map_lock_read(map);
1239 if (last_timestamp != map->timestamp) {
1241 * Look again for the entry because the map was
1242 * modified while it was unlocked. Specifically,
1243 * the entry may have been clipped, merged, or deleted.
1245 vm_map_lookup_entry(map, e_end - 1, &tmp_entry);
1249 vm_map_unlock_read(map);
1256 * Criteria for interface name translation
1258 #define IFP_IS_ETH(ifp) (ifp->if_type == IFT_ETHER)
1261 linux_ifname(struct ifnet *ifp, char *buffer, size_t buflen)
1263 struct ifnet *ifscan;
1266 IFNET_RLOCK_ASSERT();
1268 /* Short-circuit non ethernet interfaces */
1269 if (!IFP_IS_ETH(ifp))
1270 return (strlcpy(buffer, ifp->if_xname, buflen));
1272 /* Determine the (relative) unit number for ethernet interfaces */
1274 CK_STAILQ_FOREACH(ifscan, &V_ifnet, if_link) {
1276 return (snprintf(buffer, buflen, "eth%d", ethno));
1277 if (IFP_IS_ETH(ifscan))
1285 * Filler function for proc/net/dev
1288 linprocfs_donetdev(PFS_FILL_ARGS)
1290 char ifname[16]; /* XXX LINUX_IFNAMSIZ */
1293 sbuf_printf(sb, "%6s|%58s|%s\n"
1295 "Inter-", " Receive", " Transmit",
1297 "bytes packets errs drop fifo frame compressed multicast",
1298 "bytes packets errs drop fifo colls carrier compressed");
1300 CURVNET_SET(TD_TO_VNET(curthread));
1302 CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link) {
1303 linux_ifname(ifp, ifname, sizeof ifname);
1304 sbuf_printf(sb, "%6.6s: ", ifname);
1305 sbuf_printf(sb, "%7ju %7ju %4ju %4ju %4lu %5lu %10lu %9ju ",
1306 (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_IBYTES),
1307 (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_IPACKETS),
1308 (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_IERRORS),
1309 (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_IQDROPS),
1310 /* rx_missed_errors */
1311 0UL, /* rx_fifo_errors */
1312 0UL, /* rx_length_errors +
1315 * rx_frame_errors */
1316 0UL, /* rx_compressed */
1317 (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_IMCASTS));
1318 /* XXX-BZ rx only? */
1319 sbuf_printf(sb, "%8ju %7ju %4ju %4ju %4lu %5ju %7lu %10lu\n",
1320 (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_OBYTES),
1321 (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_OPACKETS),
1322 (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_OERRORS),
1323 (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_OQDROPS),
1324 0UL, /* tx_fifo_errors */
1325 (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_COLLISIONS),
1326 0UL, /* tx_carrier_errors +
1327 * tx_aborted_errors +
1328 * tx_window_errors +
1329 * tx_heartbeat_errors*/
1330 0UL); /* tx_compressed */
1339 * Filler function for proc/sys/kernel/osrelease
1342 linprocfs_doosrelease(PFS_FILL_ARGS)
1344 char osrelease[LINUX_MAX_UTSNAME];
1346 linux_get_osrelease(td, osrelease);
1347 sbuf_printf(sb, "%s\n", osrelease);
1353 * Filler function for proc/sys/kernel/ostype
1356 linprocfs_doostype(PFS_FILL_ARGS)
1358 char osname[LINUX_MAX_UTSNAME];
1360 linux_get_osname(td, osname);
1361 sbuf_printf(sb, "%s\n", osname);
1367 * Filler function for proc/sys/kernel/version
1370 linprocfs_doosbuild(PFS_FILL_ARGS)
1373 linprocfs_osbuild(td, sb);
1379 * Filler function for proc/sys/kernel/msgmni
1382 linprocfs_domsgmni(PFS_FILL_ARGS)
1385 sbuf_printf(sb, "%d\n", msginfo.msgmni);
1390 * Filler function for proc/sys/kernel/pid_max
1393 linprocfs_dopid_max(PFS_FILL_ARGS)
1396 sbuf_printf(sb, "%i\n", PID_MAX);
1401 * Filler function for proc/sys/kernel/sem
1404 linprocfs_dosem(PFS_FILL_ARGS)
1407 sbuf_printf(sb, "%d %d %d %d\n", seminfo.semmsl, seminfo.semmns,
1408 seminfo.semopm, seminfo.semmni);
1413 * Filler function for proc/sys/vm/min_free_kbytes
1415 * This mirrors the approach in illumos to return zero for reads. Effectively,
1416 * it says, no memory is kept in reserve for "atomic allocations". This class
1417 * of allocation can be used at times when a thread cannot be suspended.
1420 linprocfs_dominfree(PFS_FILL_ARGS)
1423 sbuf_printf(sb, "%d\n", 0);
1428 * Filler function for proc/scsi/device_info
1431 linprocfs_doscsidevinfo(PFS_FILL_ARGS)
1438 * Filler function for proc/scsi/scsi
1441 linprocfs_doscsiscsi(PFS_FILL_ARGS)
1448 * Filler function for proc/devices
1451 linprocfs_dodevices(PFS_FILL_ARGS)
1454 sbuf_printf(sb, "Character devices:\n");
1456 char_devices = linux_get_char_devices();
1457 sbuf_printf(sb, "%s", char_devices);
1458 linux_free_get_char_devices(char_devices);
1460 sbuf_printf(sb, "\nBlock devices:\n");
1466 * Filler function for proc/cmdline
1469 linprocfs_docmdline(PFS_FILL_ARGS)
1472 sbuf_printf(sb, "BOOT_IMAGE=%s", kernelname);
1473 sbuf_printf(sb, " ro root=302\n");
1478 * Filler function for proc/filesystems
1481 linprocfs_dofilesystems(PFS_FILL_ARGS)
1483 struct vfsconf *vfsp;
1486 TAILQ_FOREACH(vfsp, &vfsconf, vfc_list) {
1487 if (vfsp->vfc_flags & VFCF_SYNTHETIC)
1488 sbuf_printf(sb, "nodev");
1489 sbuf_printf(sb, "\t%s\n", vfsp->vfc_name);
1497 * Filler function for proc/modules
1500 linprocfs_domodules(PFS_FILL_ARGS)
1502 struct linker_file *lf;
1504 TAILQ_FOREACH(lf, &linker_files, link) {
1505 sbuf_printf(sb, "%-20s%8lu%4d\n", lf->filename,
1506 (unsigned long)lf->size, lf->refs);
1513 * Filler function for proc/pid/fd
1516 linprocfs_dofdescfs(PFS_FILL_ARGS)
1520 sbuf_printf(sb, "/dev/fd");
1522 sbuf_printf(sb, "unknown");
1527 * Filler function for proc/pid/limits
1529 static const struct linux_rlimit_ident {
1532 unsigned int rlim_id;
1533 } linux_rlimits_ident[] = {
1534 { "Max cpu time", "seconds", RLIMIT_CPU },
1535 { "Max file size", "bytes", RLIMIT_FSIZE },
1536 { "Max data size", "bytes", RLIMIT_DATA },
1537 { "Max stack size", "bytes", RLIMIT_STACK },
1538 { "Max core file size", "bytes", RLIMIT_CORE },
1539 { "Max resident set", "bytes", RLIMIT_RSS },
1540 { "Max processes", "processes", RLIMIT_NPROC },
1541 { "Max open files", "files", RLIMIT_NOFILE },
1542 { "Max locked memory", "bytes", RLIMIT_MEMLOCK },
1543 { "Max address space", "bytes", RLIMIT_AS },
1544 { "Max file locks", "locks", LINUX_RLIMIT_LOCKS },
1545 { "Max pending signals", "signals", LINUX_RLIMIT_SIGPENDING },
1546 { "Max msgqueue size", "bytes", LINUX_RLIMIT_MSGQUEUE },
1547 { "Max nice priority", "", LINUX_RLIMIT_NICE },
1548 { "Max realtime priority", "", LINUX_RLIMIT_RTPRIO },
1549 { "Max realtime timeout", "us", LINUX_RLIMIT_RTTIME },
1554 linprocfs_doproclimits(PFS_FILL_ARGS)
1556 const struct linux_rlimit_ident *li;
1557 struct plimit *limp;
1565 limp = lim_hold(p->p_limit);
1568 sbuf_printf(sb, "%-26s%-21s%-21s%-21s\n", "Limit", "Soft Limit",
1569 "Hard Limit", "Units");
1570 for (li = linux_rlimits_ident; li->desc != NULL; ++li) {
1571 switch (li->rlim_id)
1573 case LINUX_RLIMIT_LOCKS:
1575 case LINUX_RLIMIT_RTTIME:
1576 rl.rlim_cur = RLIM_INFINITY;
1578 case LINUX_RLIMIT_SIGPENDING:
1579 error = kernel_sysctlbyname(td,
1580 "kern.sigqueue.max_pending_per_proc",
1581 &res, &size, 0, 0, 0, 0);
1587 case LINUX_RLIMIT_MSGQUEUE:
1588 error = kernel_sysctlbyname(td,
1589 "kern.ipc.msgmnb", &res, &size, 0, 0, 0, 0);
1595 case LINUX_RLIMIT_NICE:
1597 case LINUX_RLIMIT_RTPRIO:
1602 rl = limp->pl_rlimit[li->rlim_id];
1605 if (rl.rlim_cur == RLIM_INFINITY)
1606 sbuf_printf(sb, "%-26s%-21s%-21s%-10s\n",
1607 li->desc, "unlimited", "unlimited", li->unit);
1609 sbuf_printf(sb, "%-26s%-21llu%-21llu%-10s\n",
1610 li->desc, (unsigned long long)rl.rlim_cur,
1611 (unsigned long long)rl.rlim_max, li->unit);
1619 * Filler function for proc/sys/kernel/random/uuid
1622 linprocfs_douuid(PFS_FILL_ARGS)
1626 kern_uuidgen(&uuid, 1);
1627 sbuf_printf_uuid(sb, &uuid);
1628 sbuf_printf(sb, "\n");
1633 * Filler function for proc/pid/auxv
1636 linprocfs_doauxv(PFS_FILL_ARGS)
1639 off_t buflen, resid;
1643 * Mimic linux behavior and pass only processes with usermode
1644 * address space as valid. Return zero silently otherwise.
1646 if (p->p_vmspace == &vmspace0)
1649 if (uio->uio_resid == 0)
1651 if (uio->uio_offset < 0 || uio->uio_resid < 0)
1654 asb = sbuf_new_auto();
1657 error = proc_getauxv(td, p, asb);
1659 error = sbuf_finish(asb);
1661 resid = sbuf_len(asb) - uio->uio_offset;
1662 if (resid > uio->uio_resid)
1663 buflen = uio->uio_resid;
1666 if (buflen > IOSIZE_MAX)
1668 if (buflen > MAXPHYS)
1674 error = uiomove(sbuf_data(asb) + uio->uio_offset, buflen, uio);
1683 linprocfs_init(PFS_INIT_ARGS)
1685 struct pfs_node *root;
1686 struct pfs_node *dir;
1687 struct pfs_node *sys;
1692 pfs_create_file(root, "cmdline", &linprocfs_docmdline,
1693 NULL, NULL, NULL, PFS_RD);
1694 pfs_create_file(root, "cpuinfo", &linprocfs_docpuinfo,
1695 NULL, NULL, NULL, PFS_RD);
1696 pfs_create_file(root, "devices", &linprocfs_dodevices,
1697 NULL, NULL, NULL, PFS_RD);
1698 pfs_create_file(root, "filesystems", &linprocfs_dofilesystems,
1699 NULL, NULL, NULL, PFS_RD);
1700 pfs_create_file(root, "loadavg", &linprocfs_doloadavg,
1701 NULL, NULL, NULL, PFS_RD);
1702 pfs_create_file(root, "meminfo", &linprocfs_domeminfo,
1703 NULL, NULL, NULL, PFS_RD);
1705 pfs_create_file(root, "modules", &linprocfs_domodules,
1706 NULL, NULL, NULL, PFS_RD);
1708 pfs_create_file(root, "mounts", &linprocfs_domtab,
1709 NULL, NULL, NULL, PFS_RD);
1710 pfs_create_file(root, "mtab", &linprocfs_domtab,
1711 NULL, NULL, NULL, PFS_RD);
1712 pfs_create_file(root, "partitions", &linprocfs_dopartitions,
1713 NULL, NULL, NULL, PFS_RD);
1714 pfs_create_link(root, "self", &procfs_docurproc,
1715 NULL, NULL, NULL, 0);
1716 pfs_create_file(root, "stat", &linprocfs_dostat,
1717 NULL, NULL, NULL, PFS_RD);
1718 pfs_create_file(root, "swaps", &linprocfs_doswaps,
1719 NULL, NULL, NULL, PFS_RD);
1720 pfs_create_file(root, "uptime", &linprocfs_douptime,
1721 NULL, NULL, NULL, PFS_RD);
1722 pfs_create_file(root, "version", &linprocfs_doversion,
1723 NULL, NULL, NULL, PFS_RD);
1726 dir = pfs_create_dir(root, "net", NULL, NULL, NULL, 0);
1727 pfs_create_file(dir, "dev", &linprocfs_donetdev,
1728 NULL, NULL, NULL, PFS_RD);
1730 /* /proc/<pid>/... */
1731 dir = pfs_create_dir(root, "pid", NULL, NULL, NULL, PFS_PROCDEP);
1732 pfs_create_file(dir, "cmdline", &linprocfs_doproccmdline,
1733 NULL, NULL, NULL, PFS_RD);
1734 pfs_create_link(dir, "cwd", &linprocfs_doproccwd,
1735 NULL, NULL, NULL, 0);
1736 pfs_create_file(dir, "environ", &linprocfs_doprocenviron,
1737 NULL, &procfs_candebug, NULL, PFS_RD);
1738 pfs_create_link(dir, "exe", &procfs_doprocfile,
1739 NULL, &procfs_notsystem, NULL, 0);
1740 pfs_create_file(dir, "maps", &linprocfs_doprocmaps,
1741 NULL, NULL, NULL, PFS_RD);
1742 pfs_create_file(dir, "mem", &procfs_doprocmem,
1743 procfs_attr_rw, &procfs_candebug, NULL, PFS_RDWR | PFS_RAW);
1744 pfs_create_file(dir, "mounts", &linprocfs_domtab,
1745 NULL, NULL, NULL, PFS_RD);
1746 pfs_create_link(dir, "root", &linprocfs_doprocroot,
1747 NULL, NULL, NULL, 0);
1748 pfs_create_file(dir, "stat", &linprocfs_doprocstat,
1749 NULL, NULL, NULL, PFS_RD);
1750 pfs_create_file(dir, "statm", &linprocfs_doprocstatm,
1751 NULL, NULL, NULL, PFS_RD);
1752 pfs_create_file(dir, "status", &linprocfs_doprocstatus,
1753 NULL, NULL, NULL, PFS_RD);
1754 pfs_create_link(dir, "fd", &linprocfs_dofdescfs,
1755 NULL, NULL, NULL, 0);
1756 pfs_create_file(dir, "auxv", &linprocfs_doauxv,
1757 NULL, &procfs_candebug, NULL, PFS_RD|PFS_RAWRD);
1758 pfs_create_file(dir, "limits", &linprocfs_doproclimits,
1759 NULL, NULL, NULL, PFS_RD);
1761 /* /proc/scsi/... */
1762 dir = pfs_create_dir(root, "scsi", NULL, NULL, NULL, 0);
1763 pfs_create_file(dir, "device_info", &linprocfs_doscsidevinfo,
1764 NULL, NULL, NULL, PFS_RD);
1765 pfs_create_file(dir, "scsi", &linprocfs_doscsiscsi,
1766 NULL, NULL, NULL, PFS_RD);
1769 sys = pfs_create_dir(root, "sys", NULL, NULL, NULL, 0);
1770 /* /proc/sys/kernel/... */
1771 dir = pfs_create_dir(sys, "kernel", NULL, NULL, NULL, 0);
1772 pfs_create_file(dir, "osrelease", &linprocfs_doosrelease,
1773 NULL, NULL, NULL, PFS_RD);
1774 pfs_create_file(dir, "ostype", &linprocfs_doostype,
1775 NULL, NULL, NULL, PFS_RD);
1776 pfs_create_file(dir, "version", &linprocfs_doosbuild,
1777 NULL, NULL, NULL, PFS_RD);
1778 pfs_create_file(dir, "msgmni", &linprocfs_domsgmni,
1779 NULL, NULL, NULL, PFS_RD);
1780 pfs_create_file(dir, "pid_max", &linprocfs_dopid_max,
1781 NULL, NULL, NULL, PFS_RD);
1782 pfs_create_file(dir, "sem", &linprocfs_dosem,
1783 NULL, NULL, NULL, PFS_RD);
1785 /* /proc/sys/kernel/random/... */
1786 dir = pfs_create_dir(dir, "random", NULL, NULL, NULL, 0);
1787 pfs_create_file(dir, "uuid", &linprocfs_douuid,
1788 NULL, NULL, NULL, PFS_RD);
1790 /* /proc/sys/vm/.... */
1791 dir = pfs_create_dir(sys, "vm", NULL, NULL, NULL, 0);
1792 pfs_create_file(dir, "min_free_kbytes", &linprocfs_dominfree,
1793 NULL, NULL, NULL, PFS_RD);
1802 linprocfs_uninit(PFS_INIT_ARGS)
1805 /* nothing to do, pseudofs will GC */
1809 PSEUDOFS(linprocfs, 1, VFCF_JAIL);
1810 #if defined(__aarch64__) || defined(__amd64__)
1811 MODULE_DEPEND(linprocfs, linux_common, 1, 1, 1);
1813 MODULE_DEPEND(linprocfs, linux, 1, 1, 1);
1815 MODULE_DEPEND(linprocfs, procfs, 1, 1, 1);
1816 MODULE_DEPEND(linprocfs, sysvmsg, 1, 1, 1);
1817 MODULE_DEPEND(linprocfs, sysvsem, 1, 1, 1);