1 /*- 2 * SPDX-License-Identifier: BSD-4-Clause 3 * 4 * Copyright (c) 2000 Dag-Erling Smørgrav 5 * Copyright (c) 1999 Pierre Beyssac 6 * Copyright (c) 1993 Jan-Simon Pendry 7 * Copyright (c) 1993 8 * The Regents of the University of California. All rights reserved. 9 * 10 * This code is derived from software contributed to Berkeley by 11 * Jan-Simon Pendry. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 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. 28 * 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 39 * SUCH DAMAGE. 40 */ 41 42 #include "opt_inet.h" 43 44 #include <sys/param.h> 45 #include <sys/systm.h> 46 #include <sys/blist.h> 47 #include <sys/conf.h> 48 #include <sys/exec.h> 49 #include <sys/fcntl.h> 50 #include <sys/filedesc.h> 51 #include <sys/jail.h> 52 #include <sys/kernel.h> 53 #include <sys/limits.h> 54 #include <sys/linker.h> 55 #include <sys/lock.h> 56 #include <sys/malloc.h> 57 #include <sys/msg.h> 58 #include <sys/mutex.h> 59 #include <sys/namei.h> 60 #include <sys/proc.h> 61 #include <sys/ptrace.h> 62 #include <sys/queue.h> 63 #include <sys/resourcevar.h> 64 #include <sys/resource.h> 65 #include <sys/sbuf.h> 66 #include <sys/sem.h> 67 #include <sys/shm.h> 68 #include <sys/smp.h> 69 #include <sys/socket.h> 70 #include <sys/syscallsubr.h> 71 #include <sys/sysctl.h> 72 #include <sys/sysent.h> 73 #include <sys/time.h> 74 #include <sys/tty.h> 75 #include <sys/user.h> 76 #include <sys/uuid.h> 77 #include <sys/vmmeter.h> 78 #include <sys/vnode.h> 79 #include <sys/bus.h> 80 #include <sys/uio.h> 81 82 #include <net/if.h> 83 #include <net/if_var.h> 84 #include <net/if_types.h> 85 86 #include <net/route.h> 87 #include <net/route/nhop.h> 88 #include <net/route/route_ctl.h> 89 90 #include <vm/vm.h> 91 #include <vm/vm_extern.h> 92 #include <vm/pmap.h> 93 #include <vm/vm_map.h> 94 #include <vm/vm_param.h> 95 #include <vm/vm_object.h> 96 #include <vm/swap_pager.h> 97 98 #include <machine/clock.h> 99 100 #include <geom/geom.h> 101 #include <geom/geom_int.h> 102 103 #if defined(__i386__) || defined(__amd64__) 104 #include <machine/cputypes.h> 105 #include <machine/md_var.h> 106 #endif /* __i386__ || __amd64__ */ 107 108 #include <compat/linux/linux.h> 109 #include <compat/linux/linux_common.h> 110 #include <compat/linux/linux_emul.h> 111 #include <compat/linux/linux_mib.h> 112 #include <compat/linux/linux_misc.h> 113 #include <compat/linux/linux_util.h> 114 #include <fs/pseudofs/pseudofs.h> 115 #include <fs/procfs/procfs.h> 116 117 /* 118 * Various conversion macros 119 */ 120 #define T2J(x) ((long)(((x) * 100ULL) / (stathz ? stathz : hz))) /* ticks to jiffies */ 121 #define T2CS(x) ((unsigned long)(((x) * 100ULL) / (stathz ? stathz : hz))) /* ticks to centiseconds */ 122 #define T2S(x) ((x) / (stathz ? stathz : hz)) /* ticks to seconds */ 123 #define B2K(x) ((x) >> 10) /* bytes to kbytes */ 124 #define B2P(x) ((x) >> PAGE_SHIFT) /* bytes to pages */ 125 #define P2B(x) ((x) << PAGE_SHIFT) /* pages to bytes */ 126 #define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* pages to kbytes */ 127 #define TV2J(x) ((x)->tv_sec * 100UL + (x)->tv_usec / 10000) 128 129 /** 130 * @brief Mapping of ki_stat in struct kinfo_proc to the linux state 131 * 132 * The linux procfs state field displays one of the characters RSDZTW to 133 * denote running, sleeping in an interruptible wait, waiting in an 134 * uninterruptible disk sleep, a zombie process, process is being traced 135 * or stopped, or process is paging respectively. 136 * 137 * Our struct kinfo_proc contains the variable ki_stat which contains a 138 * value out of SIDL, SRUN, SSLEEP, SSTOP, SZOMB, SWAIT and SLOCK. 139 * 140 * This character array is used with ki_stati-1 as an index and tries to 141 * map our states to suitable linux states. 142 */ 143 static char linux_state[] = "RRSTZDD"; 144 145 /* 146 * Filler function for proc/meminfo 147 */ 148 static int 149 linprocfs_domeminfo(PFS_FILL_ARGS) 150 { 151 unsigned long memtotal; /* total memory in bytes */ 152 unsigned long memfree; /* free memory in bytes */ 153 unsigned long cached; /* page cache */ 154 unsigned long buffers; /* buffer cache */ 155 unsigned long long swaptotal; /* total swap space in bytes */ 156 unsigned long long swapused; /* used swap space in bytes */ 157 unsigned long long swapfree; /* free swap space in bytes */ 158 size_t sz; 159 int error, i, j; 160 161 memtotal = physmem * PAGE_SIZE; 162 memfree = (unsigned long)vm_free_count() * PAGE_SIZE; 163 swap_pager_status(&i, &j); 164 swaptotal = (unsigned long long)i * PAGE_SIZE; 165 swapused = (unsigned long long)j * PAGE_SIZE; 166 swapfree = swaptotal - swapused; 167 168 /* 169 * This value may exclude wired pages, but we have no good way of 170 * accounting for that. 171 */ 172 cached = 173 (vm_active_count() + vm_inactive_count() + vm_laundry_count()) * 174 PAGE_SIZE; 175 176 sz = sizeof(buffers); 177 error = kernel_sysctlbyname(curthread, "vfs.bufspace", &buffers, &sz, 178 NULL, 0, 0, 0); 179 if (error != 0) 180 buffers = 0; 181 182 sbuf_printf(sb, 183 "MemTotal: %9lu kB\n" 184 "MemFree: %9lu kB\n" 185 "Buffers: %9lu kB\n" 186 "Cached: %9lu kB\n" 187 "SwapTotal:%9llu kB\n" 188 "SwapFree: %9llu kB\n", 189 B2K(memtotal), B2K(memfree), B2K(buffers), 190 B2K(cached), B2K(swaptotal), B2K(swapfree)); 191 192 return (0); 193 } 194 195 #if defined(__i386__) || defined(__amd64__) 196 /* 197 * Filler function for proc/cpuinfo (i386 & amd64 version) 198 */ 199 static int 200 linprocfs_docpuinfo(PFS_FILL_ARGS) 201 { 202 uint64_t freq; 203 u_int cache_size[4]; 204 u_int regs[4] = { 0 }; 205 int fqmhz, fqkhz; 206 int i, j; 207 208 /* 209 * We default the flags to include all non-conflicting flags, 210 * and the Intel versions of conflicting flags. 211 */ 212 static char *cpu_feature_names[] = { 213 /* 0 */ "fpu", "vme", "de", "pse", 214 /* 4 */ "tsc", "msr", "pae", "mce", 215 /* 8 */ "cx8", "apic", "", "sep", 216 /* 12 */ "mtrr", "pge", "mca", "cmov", 217 /* 16 */ "pat", "pse36", "pn", "clflush", 218 /* 20 */ "", "dts", "acpi", "mmx", 219 /* 24 */ "fxsr", "sse", "sse2", "ss", 220 /* 28 */ "ht", "tm", "ia64", "pbe" 221 }; 222 223 static char *amd_feature_names[] = { 224 /* 0 */ "", "", "", "", 225 /* 4 */ "", "", "", "", 226 /* 8 */ "", "", "", "syscall", 227 /* 12 */ "", "", "", "", 228 /* 16 */ "", "", "", "mp", 229 /* 20 */ "nx", "", "mmxext", "", 230 /* 24 */ "", "fxsr_opt", "pdpe1gb", "rdtscp", 231 /* 28 */ "", "lm", "3dnowext", "3dnow" 232 }; 233 234 static char *cpu_feature2_names[] = { 235 /* 0 */ "pni", "pclmulqdq", "dtes64", "monitor", 236 /* 4 */ "ds_cpl", "vmx", "smx", "est", 237 /* 8 */ "tm2", "ssse3", "cid", "sdbg", 238 /* 12 */ "fma", "cx16", "xtpr", "pdcm", 239 /* 16 */ "", "pcid", "dca", "sse4_1", 240 /* 20 */ "sse4_2", "x2apic", "movbe", "popcnt", 241 /* 24 */ "tsc_deadline_timer", "aes", "xsave", "", 242 /* 28 */ "avx", "f16c", "rdrand", "hypervisor" 243 }; 244 245 static char *amd_feature2_names[] = { 246 /* 0 */ "lahf_lm", "cmp_legacy", "svm", "extapic", 247 /* 4 */ "cr8_legacy", "abm", "sse4a", "misalignsse", 248 /* 8 */ "3dnowprefetch", "osvw", "ibs", "xop", 249 /* 12 */ "skinit", "wdt", "", "lwp", 250 /* 16 */ "fma4", "tce", "", "nodeid_msr", 251 /* 20 */ "", "tbm", "topoext", "perfctr_core", 252 /* 24 */ "perfctr_nb", "", "bpext", "ptsc", 253 /* 28 */ "perfctr_llc", "mwaitx", "", "" 254 }; 255 256 static char *cpu_stdext_feature_names[] = { 257 /* 0 */ "fsgsbase", "tsc_adjust", "sgx", "bmi1", 258 /* 4 */ "hle", "avx2", "", "smep", 259 /* 8 */ "bmi2", "erms", "invpcid", "rtm", 260 /* 12 */ "cqm", "", "mpx", "rdt_a", 261 /* 16 */ "avx512f", "avx512dq", "rdseed", "adx", 262 /* 20 */ "smap", "avx512ifma", "", "clflushopt", 263 /* 24 */ "clwb", "intel_pt", "avx512pf", "avx512er", 264 /* 28 */ "avx512cd", "sha_ni", "avx512bw", "avx512vl" 265 }; 266 267 static char *cpu_stdext_feature2_names[] = { 268 /* 0 */ "prefetchwt1", "avx512vbmi", "umip", "pku", 269 /* 4 */ "ospke", "waitpkg", "avx512_vbmi2", "", 270 /* 8 */ "gfni", "vaes", "vpclmulqdq", "avx512_vnni", 271 /* 12 */ "avx512_bitalg", "", "avx512_vpopcntdq", "", 272 /* 16 */ "", "", "", "", 273 /* 20 */ "", "", "rdpid", "", 274 /* 24 */ "", "cldemote", "", "movdiri", 275 /* 28 */ "movdir64b", "enqcmd", "sgx_lc", "" 276 }; 277 278 static char *cpu_stdext_feature3_names[] = { 279 /* 0 */ "", "", "avx512_4vnniw", "avx512_4fmaps", 280 /* 4 */ "fsrm", "", "", "", 281 /* 8 */ "avx512_vp2intersect", "", "md_clear", "", 282 /* 12 */ "", "", "", "", 283 /* 16 */ "", "", "pconfig", "", 284 /* 20 */ "", "", "", "", 285 /* 24 */ "", "", "ibrs", "stibp", 286 /* 28 */ "flush_l1d", "arch_capabilities", "core_capabilities", "ssbd" 287 }; 288 289 static char *cpu_stdext_feature_l1_names[] = { 290 /* 0 */ "xsaveopt", "xsavec", "xgetbv1", "xsaves", 291 /* 4 */ "xfd" 292 }; 293 294 static char *power_flags[] = { 295 "ts", "fid", "vid", 296 "ttp", "tm", "stc", 297 "100mhzsteps", "hwpstate", "", 298 "cpb", "eff_freq_ro", "proc_feedback", 299 "acc_power", 300 }; 301 302 #ifdef __i386__ 303 switch (cpu_vendor_id) { 304 case CPU_VENDOR_AMD: 305 if (cpu_class < CPUCLASS_686) 306 cpu_feature_names[16] = "fcmov"; 307 break; 308 case CPU_VENDOR_CYRIX: 309 cpu_feature_names[24] = "cxmmx"; 310 break; 311 } 312 #endif 313 if (cpu_exthigh >= 0x80000006) 314 do_cpuid(0x80000006, cache_size); 315 else 316 memset(cache_size, 0, sizeof(cache_size)); 317 for (i = 0; i < mp_ncpus; ++i) { 318 fqmhz = 0; 319 fqkhz = 0; 320 freq = atomic_load_acq_64(&tsc_freq); 321 if (freq != 0) { 322 fqmhz = (freq + 4999) / 1000000; 323 fqkhz = ((freq + 4999) / 10000) % 100; 324 } 325 sbuf_printf(sb, 326 "processor\t: %d\n" 327 "vendor_id\t: %.20s\n" 328 "cpu family\t: %u\n" 329 "model\t\t: %u\n" 330 "model name\t: %s\n" 331 "stepping\t: %u\n" 332 "cpu MHz\t\t: %d.%02d\n" 333 "cache size\t: %d KB\n" 334 "physical id\t: %d\n" 335 "siblings\t: %d\n" 336 "core id\t\t: %d\n" 337 "cpu cores\t: %d\n" 338 "apicid\t\t: %d\n" 339 "initial apicid\t: %d\n" 340 "fpu\t\t: %s\n" 341 "fpu_exception\t: %s\n" 342 "cpuid level\t: %d\n" 343 "wp\t\t: %s\n", 344 i, cpu_vendor, CPUID_TO_FAMILY(cpu_id), 345 CPUID_TO_MODEL(cpu_id), cpu_model, cpu_id & CPUID_STEPPING, 346 fqmhz, fqkhz, 347 (cache_size[2] >> 16), 0, mp_ncpus, i, mp_ncpus, 348 i, i, /*cpu_id & CPUID_LOCAL_APIC_ID ??*/ 349 (cpu_feature & CPUID_FPU) ? "yes" : "no", "yes", 350 CPUID_TO_FAMILY(cpu_id), "yes"); 351 sbuf_cat(sb, "flags\t\t:"); 352 for (j = 0; j < nitems(cpu_feature_names); j++) 353 if (cpu_feature & (1 << j) && 354 cpu_feature_names[j][0] != '\0') 355 sbuf_printf(sb, " %s", cpu_feature_names[j]); 356 for (j = 0; j < nitems(amd_feature_names); j++) 357 if (amd_feature & (1 << j) && 358 amd_feature_names[j][0] != '\0') 359 sbuf_printf(sb, " %s", amd_feature_names[j]); 360 for (j = 0; j < nitems(cpu_feature2_names); j++) 361 if (cpu_feature2 & (1 << j) && 362 cpu_feature2_names[j][0] != '\0') 363 sbuf_printf(sb, " %s", cpu_feature2_names[j]); 364 for (j = 0; j < nitems(amd_feature2_names); j++) 365 if (amd_feature2 & (1 << j) && 366 amd_feature2_names[j][0] != '\0') 367 sbuf_printf(sb, " %s", amd_feature2_names[j]); 368 for (j = 0; j < nitems(cpu_stdext_feature_names); j++) 369 if (cpu_stdext_feature & (1 << j) && 370 cpu_stdext_feature_names[j][0] != '\0') 371 sbuf_printf(sb, " %s", 372 cpu_stdext_feature_names[j]); 373 if (tsc_is_invariant) 374 sbuf_cat(sb, " constant_tsc"); 375 for (j = 0; j < nitems(cpu_stdext_feature2_names); j++) 376 if (cpu_stdext_feature2 & (1 << j) && 377 cpu_stdext_feature2_names[j][0] != '\0') 378 sbuf_printf(sb, " %s", 379 cpu_stdext_feature2_names[j]); 380 for (j = 0; j < nitems(cpu_stdext_feature3_names); j++) 381 if (cpu_stdext_feature3 & (1 << j) && 382 cpu_stdext_feature3_names[j][0] != '\0') 383 sbuf_printf(sb, " %s", 384 cpu_stdext_feature3_names[j]); 385 if ((cpu_feature2 & CPUID2_XSAVE) != 0) { 386 cpuid_count(0xd, 0x1, regs); 387 for (j = 0; j < nitems(cpu_stdext_feature_l1_names); j++) 388 if (regs[0] & (1 << j) && 389 cpu_stdext_feature_l1_names[j][0] != '\0') 390 sbuf_printf(sb, " %s", 391 cpu_stdext_feature_l1_names[j]); 392 } 393 sbuf_cat(sb, "\n"); 394 sbuf_printf(sb, 395 "bugs\t\t: %s\n" 396 "bogomips\t: %d.%02d\n" 397 "clflush size\t: %d\n" 398 "cache_alignment\t: %d\n" 399 "address sizes\t: %d bits physical, %d bits virtual\n", 400 #if defined(I586_CPU) && !defined(NO_F00F_HACK) 401 (has_f00f_bug) ? "Intel F00F" : "", 402 #else 403 "", 404 #endif 405 fqmhz * 2, fqkhz, 406 cpu_clflush_line_size, cpu_clflush_line_size, 407 cpu_maxphyaddr, 408 (cpu_maxphyaddr > 32) ? 48 : 0); 409 sbuf_cat(sb, "power management: "); 410 for (j = 0; j < nitems(power_flags); j++) 411 if (amd_pminfo & (1 << j)) 412 sbuf_printf(sb, " %s", power_flags[j]); 413 sbuf_cat(sb, "\n\n"); 414 415 /* XXX per-cpu vendor / class / model / id? */ 416 } 417 sbuf_cat(sb, "\n"); 418 419 return (0); 420 } 421 #else 422 /* ARM64TODO: implement non-stubbed linprocfs_docpuinfo */ 423 static int 424 linprocfs_docpuinfo(PFS_FILL_ARGS) 425 { 426 int i; 427 428 for (i = 0; i < mp_ncpus; ++i) { 429 sbuf_printf(sb, 430 "processor\t: %d\n" 431 "BogoMIPS\t: %d.%02d\n", 432 i, 0, 0); 433 sbuf_cat(sb, "Features\t: "); 434 sbuf_cat(sb, "\n"); 435 sbuf_printf(sb, 436 "CPU implementer\t: \n" 437 "CPU architecture: \n" 438 "CPU variant\t: 0x%x\n" 439 "CPU part\t: 0x%x\n" 440 "CPU revision\t: %d\n", 441 0, 0, 0); 442 sbuf_cat(sb, "\n"); 443 } 444 445 return (0); 446 } 447 #endif /* __i386__ || __amd64__ */ 448 449 static int 450 _mtab_helper(const struct pfs_node *pn, const struct statfs *sp, 451 const char **mntfrom, const char **mntto, const char **fstype) 452 { 453 /* determine device name */ 454 *mntfrom = sp->f_mntfromname; 455 456 /* determine mount point */ 457 *mntto = sp->f_mntonname; 458 459 /* determine fs type */ 460 *fstype = sp->f_fstypename; 461 if (strcmp(*fstype, pn->pn_info->pi_name) == 0) 462 *mntfrom = *fstype = "proc"; 463 else if (strcmp(*fstype, "procfs") == 0) 464 return (ECANCELED); 465 466 if (strcmp(*fstype, "autofs") == 0) { 467 /* 468 * FreeBSD uses eg "map -hosts", whereas Linux 469 * expects just "-hosts". 470 */ 471 if (strncmp(*mntfrom, "map ", 4) == 0) 472 *mntfrom += 4; 473 } 474 475 if (strcmp(*fstype, "linsysfs") == 0) { 476 *mntfrom = *fstype = "sysfs"; 477 } else { 478 /* For Linux msdosfs is called vfat */ 479 if (strcmp(*fstype, "msdosfs") == 0) 480 *fstype = "vfat"; 481 } 482 return (0); 483 } 484 485 static void 486 _sbuf_mntoptions_helper(struct sbuf *sb, uint64_t f_flags) 487 { 488 sbuf_cat(sb, (f_flags & MNT_RDONLY) ? "ro" : "rw"); 489 #define ADD_OPTION(opt, name) \ 490 if (f_flags & (opt)) sbuf_cat(sb, "," name); 491 ADD_OPTION(MNT_SYNCHRONOUS, "sync"); 492 ADD_OPTION(MNT_NOEXEC, "noexec"); 493 ADD_OPTION(MNT_NOSUID, "nosuid"); 494 ADD_OPTION(MNT_UNION, "union"); 495 ADD_OPTION(MNT_ASYNC, "async"); 496 ADD_OPTION(MNT_SUIDDIR, "suiddir"); 497 ADD_OPTION(MNT_NOSYMFOLLOW, "nosymfollow"); 498 ADD_OPTION(MNT_NOATIME, "noatime"); 499 #undef ADD_OPTION 500 } 501 502 /* 503 * Filler function for proc/mtab and proc/<pid>/mounts. 504 * 505 * /proc/mtab doesn't exist in Linux' procfs, but is included here so 506 * users can symlink /compat/linux/etc/mtab to /proc/mtab 507 */ 508 static int 509 linprocfs_domtab(PFS_FILL_ARGS) 510 { 511 const char *mntto, *mntfrom, *fstype; 512 char *dlep, *flep; 513 struct vnode *vp; 514 struct pwd *pwd; 515 size_t lep_len; 516 int error; 517 struct statfs *buf, *sp; 518 size_t count; 519 520 /* 521 * Resolve emulation tree prefix 522 */ 523 flep = NULL; 524 pwd = pwd_hold(td); 525 vp = pwd->pwd_adir; 526 error = vn_fullpath_global(vp, &dlep, &flep); 527 pwd_drop(pwd); 528 if (error != 0) 529 return (error); 530 lep_len = strlen(dlep); 531 532 buf = NULL; 533 error = kern_getfsstat(td, &buf, SIZE_T_MAX, &count, 534 UIO_SYSSPACE, MNT_WAIT); 535 if (error != 0) { 536 goto out; 537 } 538 539 for (sp = buf; count > 0; sp++, count--) { 540 error = _mtab_helper(pn, sp, &mntfrom, &mntto, &fstype); 541 if (error != 0) { 542 MPASS(error == ECANCELED); 543 continue; 544 } 545 546 /* determine mount point */ 547 if (strncmp(mntto, dlep, lep_len) == 0 && mntto[lep_len] == '/') 548 mntto += lep_len; 549 550 sbuf_printf(sb, "%s %s %s ", mntfrom, mntto, fstype); 551 _sbuf_mntoptions_helper(sb, sp->f_flags); 552 /* a real Linux mtab will also show NFS options */ 553 sbuf_printf(sb, " 0 0\n"); 554 } 555 556 error = 0; 557 out: 558 free(buf, M_TEMP); 559 free(flep, M_TEMP); 560 return (error); 561 } 562 563 static int 564 linprocfs_doprocmountinfo(PFS_FILL_ARGS) 565 { 566 const char *mntfrom, *mntto, *fstype; 567 char *dlep, *flep; 568 struct statfs *buf, *sp; 569 size_t count, lep_len; 570 struct vnode *vp; 571 struct pwd *pwd; 572 int error; 573 574 /* 575 * Resolve emulation tree prefix 576 */ 577 flep = NULL; 578 pwd = pwd_hold(td); 579 vp = pwd->pwd_adir; 580 error = vn_fullpath_global(vp, &dlep, &flep); 581 pwd_drop(pwd); 582 if (error != 0) 583 return (error); 584 lep_len = strlen(dlep); 585 586 buf = NULL; 587 error = kern_getfsstat(td, &buf, SIZE_T_MAX, &count, 588 UIO_SYSSPACE, MNT_WAIT); 589 if (error != 0) 590 goto out; 591 592 for (sp = buf; count > 0; sp++, count--) { 593 error = _mtab_helper(pn, sp, &mntfrom, &mntto, &fstype); 594 if (error != 0) { 595 MPASS(error == ECANCELED); 596 continue; 597 } 598 599 if (strncmp(mntto, dlep, lep_len) == 0 && mntto[lep_len] == '/') 600 mntto += lep_len; 601 #if 0 602 /* 603 * If the prefix is a chroot, and this mountpoint is not under 604 * the prefix, we should skip it. Leave it for now for 605 * consistency with procmtab above. 606 */ 607 else 608 continue; 609 #endif 610 611 /* 612 * (1) mount id 613 * 614 * (2) parent mount id -- we don't have this cheaply, so 615 * provide a dummy value 616 * 617 * (3) major:minor -- ditto 618 * 619 * (4) root filesystem mount -- probably a namespaces thing 620 * 621 * (5) mountto path 622 */ 623 sbuf_printf(sb, "%u 0 0:0 / %s ", 624 sp->f_fsid.val[0] ^ sp->f_fsid.val[1], mntto); 625 /* (6) mount options */ 626 _sbuf_mntoptions_helper(sb, sp->f_flags); 627 /* 628 * (7) zero or more optional fields -- again, namespace related 629 * 630 * (8) End of variable length fields separator ("-") 631 * 632 * (9) fstype 633 * 634 * (10) mount from 635 * 636 * (11) "superblock" options -- like (6), but different 637 * semantics in Linux 638 */ 639 sbuf_printf(sb, " - %s %s %s\n", fstype, mntfrom, 640 (sp->f_flags & MNT_RDONLY) ? "ro" : "rw"); 641 } 642 643 error = 0; 644 out: 645 free(buf, M_TEMP); 646 free(flep, M_TEMP); 647 return (error); 648 } 649 650 /* 651 * Filler function for proc/partitions 652 */ 653 static int 654 linprocfs_dopartitions(PFS_FILL_ARGS) 655 { 656 struct g_class *cp; 657 struct g_geom *gp; 658 struct g_provider *pp; 659 int major, minor; 660 661 g_topology_lock(); 662 sbuf_printf(sb, "major minor #blocks name\n\n"); 663 664 LIST_FOREACH(cp, &g_classes, class) { 665 if (strcmp(cp->name, "DISK") == 0 || 666 strcmp(cp->name, "PART") == 0) 667 LIST_FOREACH(gp, &cp->geom, geom) { 668 LIST_FOREACH(pp, &gp->provider, provider) { 669 if (linux_driver_get_major_minor( 670 pp->name, &major, &minor) != 0) { 671 major = 0; 672 minor = 0; 673 } 674 sbuf_printf(sb, "%4d %7d %10lld %s\n", 675 major, minor, 676 B2K((long long)pp->mediasize), 677 pp->name); 678 } 679 } 680 } 681 g_topology_unlock(); 682 683 return (0); 684 } 685 686 /* 687 * Filler function for proc/stat 688 * 689 * Output depends on kernel version: 690 * 691 * v2.5.40 <= 692 * user nice system idle 693 * v2.5.41 694 * user nice system idle iowait 695 * v2.6.11 696 * user nice system idle iowait irq softirq steal 697 * v2.6.24 698 * user nice system idle iowait irq softirq steal guest 699 * v2.6.33 >= 700 * user nice system idle iowait irq softirq steal guest guest_nice 701 */ 702 static int 703 linprocfs_dostat(PFS_FILL_ARGS) 704 { 705 struct pcpu *pcpu; 706 long cp_time[CPUSTATES]; 707 long *cp; 708 struct timeval boottime; 709 int i; 710 char *zero_pad; 711 bool has_intr = true; 712 713 if (linux_kernver(td) >= LINUX_KERNVER(2,6,33)) { 714 zero_pad = " 0 0 0 0\n"; 715 } else if (linux_kernver(td) >= LINUX_KERNVER(2,6,24)) { 716 zero_pad = " 0 0 0\n"; 717 } else if (linux_kernver(td) >= LINUX_KERNVER(2,6,11)) { 718 zero_pad = " 0 0\n"; 719 } else if (linux_kernver(td) >= LINUX_KERNVER(2,5,41)) { 720 has_intr = false; 721 zero_pad = " 0\n"; 722 } else { 723 has_intr = false; 724 zero_pad = "\n"; 725 } 726 727 read_cpu_time(cp_time); 728 getboottime(&boottime); 729 /* Parameters common to all versions */ 730 sbuf_printf(sb, "cpu %lu %lu %lu %lu", 731 T2J(cp_time[CP_USER]), 732 T2J(cp_time[CP_NICE]), 733 T2J(cp_time[CP_SYS]), 734 T2J(cp_time[CP_IDLE])); 735 736 /* Print interrupt stats if available */ 737 if (has_intr) { 738 sbuf_printf(sb, " 0 %lu", T2J(cp_time[CP_INTR])); 739 } 740 741 /* Pad out remaining fields depending on version */ 742 sbuf_printf(sb, "%s", zero_pad); 743 744 CPU_FOREACH(i) { 745 pcpu = pcpu_find(i); 746 cp = pcpu->pc_cp_time; 747 sbuf_printf(sb, "cpu%d %lu %lu %lu %lu", i, 748 T2J(cp[CP_USER]), 749 T2J(cp[CP_NICE]), 750 T2J(cp[CP_SYS]), 751 T2J(cp[CP_IDLE])); 752 753 if (has_intr) { 754 sbuf_printf(sb, " 0 %lu", T2J(cp[CP_INTR])); 755 } 756 757 sbuf_printf(sb, "%s", zero_pad); 758 } 759 sbuf_printf(sb, 760 "disk 0 0 0 0\n" 761 "page %ju %ju\n" 762 "swap %ju %ju\n" 763 "intr %ju\n" 764 "ctxt %ju\n" 765 "btime %lld\n", 766 (uintmax_t)VM_CNT_FETCH(v_vnodepgsin), 767 (uintmax_t)VM_CNT_FETCH(v_vnodepgsout), 768 (uintmax_t)VM_CNT_FETCH(v_swappgsin), 769 (uintmax_t)VM_CNT_FETCH(v_swappgsout), 770 (uintmax_t)VM_CNT_FETCH(v_intr), 771 (uintmax_t)VM_CNT_FETCH(v_swtch), 772 (long long)boottime.tv_sec); 773 return (0); 774 } 775 776 static int 777 linprocfs_doswaps(PFS_FILL_ARGS) 778 { 779 struct xswdev xsw; 780 uintmax_t total, used; 781 int n; 782 char devname[SPECNAMELEN + 1]; 783 784 sbuf_printf(sb, "Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n"); 785 for (n = 0; ; n++) { 786 if (swap_dev_info(n, &xsw, devname, sizeof(devname)) != 0) 787 break; 788 total = (uintmax_t)xsw.xsw_nblks * PAGE_SIZE / 1024; 789 used = (uintmax_t)xsw.xsw_used * PAGE_SIZE / 1024; 790 791 /* 792 * The space and not tab after the device name is on 793 * purpose. Linux does so. 794 */ 795 sbuf_printf(sb, "/dev/%-34s unknown\t\t%jd\t%jd\t-1\n", 796 devname, total, used); 797 } 798 return (0); 799 } 800 801 /* 802 * Filler function for proc/uptime 803 */ 804 static int 805 linprocfs_douptime(PFS_FILL_ARGS) 806 { 807 long cp_time[CPUSTATES]; 808 struct timeval tv; 809 810 getmicrouptime(&tv); 811 read_cpu_time(cp_time); 812 sbuf_printf(sb, "%lld.%02ld %ld.%02lu\n", 813 (long long)tv.tv_sec, tv.tv_usec / 10000, 814 T2S(cp_time[CP_IDLE] / mp_ncpus), 815 T2CS(cp_time[CP_IDLE] / mp_ncpus) % 100); 816 return (0); 817 } 818 819 /* 820 * Get OS build date 821 */ 822 static void 823 linprocfs_osbuild(struct thread *td, struct sbuf *sb) 824 { 825 #if 0 826 char osbuild[256]; 827 char *cp1, *cp2; 828 829 strncpy(osbuild, version, 256); 830 osbuild[255] = '\0'; 831 cp1 = strstr(osbuild, "\n"); 832 cp2 = strstr(osbuild, ":"); 833 if (cp1 && cp2) { 834 *cp1 = *cp2 = '\0'; 835 cp1 = strstr(osbuild, "#"); 836 } else 837 cp1 = NULL; 838 if (cp1) 839 sbuf_printf(sb, "%s%s", cp1, cp2 + 1); 840 else 841 #endif 842 sbuf_cat(sb, "#4 Sun Dec 18 04:30:00 CET 1977"); 843 } 844 845 /* 846 * Get OS builder 847 */ 848 static void 849 linprocfs_osbuilder(struct thread *td, struct sbuf *sb) 850 { 851 #if 0 852 char builder[256]; 853 char *cp; 854 855 cp = strstr(version, "\n "); 856 if (cp) { 857 strncpy(builder, cp + 5, 256); 858 builder[255] = '\0'; 859 cp = strstr(builder, ":"); 860 if (cp) 861 *cp = '\0'; 862 } 863 if (cp) 864 sbuf_cat(sb, builder); 865 else 866 #endif 867 sbuf_cat(sb, "des@freebsd.org"); 868 } 869 870 /* 871 * Filler function for proc/version 872 */ 873 static int 874 linprocfs_doversion(PFS_FILL_ARGS) 875 { 876 char osname[LINUX_MAX_UTSNAME]; 877 char osrelease[LINUX_MAX_UTSNAME]; 878 879 linux_get_osname(td, osname); 880 linux_get_osrelease(td, osrelease); 881 sbuf_printf(sb, "%s version %s (", osname, osrelease); 882 linprocfs_osbuilder(td, sb); 883 sbuf_cat(sb, ") (gcc version " __VERSION__ ") "); 884 linprocfs_osbuild(td, sb); 885 sbuf_cat(sb, "\n"); 886 887 return (0); 888 } 889 890 /* 891 * Filler function for proc/loadavg 892 */ 893 static int 894 linprocfs_doloadavg(PFS_FILL_ARGS) 895 { 896 897 sbuf_printf(sb, 898 "%d.%02d %d.%02d %d.%02d %d/%d %d\n", 899 (int)(averunnable.ldavg[0] / averunnable.fscale), 900 (int)(averunnable.ldavg[0] * 100 / averunnable.fscale % 100), 901 (int)(averunnable.ldavg[1] / averunnable.fscale), 902 (int)(averunnable.ldavg[1] * 100 / averunnable.fscale % 100), 903 (int)(averunnable.ldavg[2] / averunnable.fscale), 904 (int)(averunnable.ldavg[2] * 100 / averunnable.fscale % 100), 905 1, /* number of running tasks */ 906 nprocs, /* number of tasks */ 907 lastpid /* the last pid */ 908 ); 909 return (0); 910 } 911 912 static int 913 linprocfs_get_tty_nr(struct proc *p) 914 { 915 struct session *sp; 916 const char *ttyname; 917 int error, major, minor, nr; 918 919 PROC_LOCK_ASSERT(p, MA_OWNED); 920 sx_assert(&proctree_lock, SX_LOCKED); 921 922 if ((p->p_flag & P_CONTROLT) == 0) 923 return (-1); 924 925 sp = p->p_pgrp->pg_session; 926 if (sp == NULL) 927 return (-1); 928 929 ttyname = devtoname(sp->s_ttyp->t_dev); 930 error = linux_driver_get_major_minor(ttyname, &major, &minor); 931 if (error != 0) 932 return (-1); 933 934 nr = makedev(major, minor); 935 return (nr); 936 } 937 938 /* 939 * Filler function for proc/pid/stat 940 */ 941 static int 942 linprocfs_doprocstat(PFS_FILL_ARGS) 943 { 944 struct kinfo_proc kp; 945 struct timeval boottime; 946 char state; 947 static int ratelimit = 0; 948 int tty_nr; 949 vm_offset_t startcode, startdata; 950 951 getboottime(&boottime); 952 sx_slock(&proctree_lock); 953 PROC_LOCK(p); 954 fill_kinfo_proc(p, &kp); 955 tty_nr = linprocfs_get_tty_nr(p); 956 sx_sunlock(&proctree_lock); 957 if (p->p_vmspace) { 958 startcode = (vm_offset_t)p->p_vmspace->vm_taddr; 959 startdata = (vm_offset_t)p->p_vmspace->vm_daddr; 960 } else { 961 startcode = 0; 962 startdata = 0; 963 } 964 sbuf_printf(sb, "%d", p->p_pid); 965 #define PS_ADD(name, fmt, arg) sbuf_printf(sb, " " fmt, arg) 966 PS_ADD("comm", "(%s)", p->p_comm); 967 if (kp.ki_stat > sizeof(linux_state)) { 968 state = 'R'; 969 970 if (ratelimit == 0) { 971 printf("linprocfs: don't know how to handle unknown FreeBSD state %d/%zd, mapping to R\n", 972 kp.ki_stat, sizeof(linux_state)); 973 ++ratelimit; 974 } 975 } else 976 state = linux_state[kp.ki_stat - 1]; 977 PS_ADD("state", "%c", state); 978 PS_ADD("ppid", "%d", p->p_pptr ? p->p_pptr->p_pid : 0); 979 PS_ADD("pgrp", "%d", p->p_pgid); 980 PS_ADD("session", "%d", p->p_session->s_sid); 981 PROC_UNLOCK(p); 982 PS_ADD("tty", "%d", tty_nr); 983 PS_ADD("tpgid", "%d", kp.ki_tpgid); 984 PS_ADD("flags", "%u", 0); /* XXX */ 985 PS_ADD("minflt", "%lu", kp.ki_rusage.ru_minflt); 986 PS_ADD("cminflt", "%lu", kp.ki_rusage_ch.ru_minflt); 987 PS_ADD("majflt", "%lu", kp.ki_rusage.ru_majflt); 988 PS_ADD("cmajflt", "%lu", kp.ki_rusage_ch.ru_majflt); 989 PS_ADD("utime", "%ld", TV2J(&kp.ki_rusage.ru_utime)); 990 PS_ADD("stime", "%ld", TV2J(&kp.ki_rusage.ru_stime)); 991 PS_ADD("cutime", "%ld", TV2J(&kp.ki_rusage_ch.ru_utime)); 992 PS_ADD("cstime", "%ld", TV2J(&kp.ki_rusage_ch.ru_stime)); 993 PS_ADD("priority", "%d", kp.ki_pri.pri_user); 994 PS_ADD("nice", "%d", kp.ki_nice); /* 19 (nicest) to -19 */ 995 PS_ADD("0", "%d", 0); /* removed field */ 996 PS_ADD("itrealvalue", "%d", 0); /* XXX */ 997 PS_ADD("starttime", "%lu", TV2J(&kp.ki_start) - TV2J(&boottime)); 998 PS_ADD("vsize", "%ju", (uintmax_t)kp.ki_size); 999 PS_ADD("rss", "%ju", (uintmax_t)kp.ki_rssize); 1000 PS_ADD("rlim", "%lu", kp.ki_rusage.ru_maxrss); 1001 PS_ADD("startcode", "%ju", (uintmax_t)startcode); 1002 PS_ADD("endcode", "%ju", (uintmax_t)startdata); 1003 PS_ADD("startstack", "%u", 0); /* XXX */ 1004 PS_ADD("kstkesp", "%u", 0); /* XXX */ 1005 PS_ADD("kstkeip", "%u", 0); /* XXX */ 1006 PS_ADD("signal", "%u", 0); /* XXX */ 1007 PS_ADD("blocked", "%u", 0); /* XXX */ 1008 PS_ADD("sigignore", "%u", 0); /* XXX */ 1009 PS_ADD("sigcatch", "%u", 0); /* XXX */ 1010 PS_ADD("wchan", "%u", 0); /* XXX */ 1011 PS_ADD("nswap", "%lu", kp.ki_rusage.ru_nswap); 1012 PS_ADD("cnswap", "%lu", kp.ki_rusage_ch.ru_nswap); 1013 PS_ADD("exitsignal", "%d", 0); /* XXX */ 1014 PS_ADD("processor", "%u", kp.ki_lastcpu); 1015 PS_ADD("rt_priority", "%u", 0); /* XXX */ /* >= 2.5.19 */ 1016 PS_ADD("policy", "%u", kp.ki_pri.pri_class); /* >= 2.5.19 */ 1017 #undef PS_ADD 1018 sbuf_putc(sb, '\n'); 1019 1020 return (0); 1021 } 1022 1023 /* 1024 * Filler function for proc/pid/statm 1025 */ 1026 static int 1027 linprocfs_doprocstatm(PFS_FILL_ARGS) 1028 { 1029 struct kinfo_proc kp; 1030 segsz_t lsize; 1031 1032 sx_slock(&proctree_lock); 1033 PROC_LOCK(p); 1034 fill_kinfo_proc(p, &kp); 1035 PROC_UNLOCK(p); 1036 sx_sunlock(&proctree_lock); 1037 1038 /* 1039 * See comments in linprocfs_doprocstatus() regarding the 1040 * computation of lsize. 1041 */ 1042 /* size resident share trs drs lrs dt */ 1043 sbuf_printf(sb, "%ju ", B2P((uintmax_t)kp.ki_size)); 1044 sbuf_printf(sb, "%ju ", (uintmax_t)kp.ki_rssize); 1045 sbuf_printf(sb, "%ju ", (uintmax_t)0); /* XXX */ 1046 sbuf_printf(sb, "%ju ", (uintmax_t)kp.ki_tsize); 1047 sbuf_printf(sb, "%ju ", (uintmax_t)(kp.ki_dsize + kp.ki_ssize)); 1048 lsize = B2P(kp.ki_size) - kp.ki_dsize - 1049 kp.ki_ssize - kp.ki_tsize - 1; 1050 sbuf_printf(sb, "%ju ", (uintmax_t)lsize); 1051 sbuf_printf(sb, "%ju\n", (uintmax_t)0); /* XXX */ 1052 1053 return (0); 1054 } 1055 1056 /* 1057 * Filler function for proc/pid/status 1058 */ 1059 static int 1060 linprocfs_doprocstatus(PFS_FILL_ARGS) 1061 { 1062 struct kinfo_proc kp; 1063 char *state; 1064 segsz_t lsize; 1065 struct thread *td2; 1066 struct sigacts *ps; 1067 l_sigset_t siglist, sigignore, sigcatch; 1068 int i; 1069 1070 sx_slock(&proctree_lock); 1071 PROC_LOCK(p); 1072 td2 = FIRST_THREAD_IN_PROC(p); 1073 1074 if (P_SHOULDSTOP(p)) { 1075 state = "T (stopped)"; 1076 } else { 1077 switch(p->p_state) { 1078 case PRS_NEW: 1079 state = "I (idle)"; 1080 break; 1081 case PRS_NORMAL: 1082 if (p->p_flag & P_WEXIT) { 1083 state = "X (exiting)"; 1084 break; 1085 } 1086 switch(TD_GET_STATE(td2)) { 1087 case TDS_INHIBITED: 1088 state = "S (sleeping)"; 1089 break; 1090 case TDS_RUNQ: 1091 case TDS_RUNNING: 1092 state = "R (running)"; 1093 break; 1094 default: 1095 state = "? (unknown)"; 1096 break; 1097 } 1098 break; 1099 case PRS_ZOMBIE: 1100 state = "Z (zombie)"; 1101 break; 1102 default: 1103 state = "? (unknown)"; 1104 break; 1105 } 1106 } 1107 1108 fill_kinfo_proc(p, &kp); 1109 sx_sunlock(&proctree_lock); 1110 1111 sbuf_printf(sb, "Name:\t%s\n", p->p_comm); /* XXX escape */ 1112 sbuf_printf(sb, "State:\t%s\n", state); 1113 1114 /* 1115 * Credentials 1116 */ 1117 sbuf_printf(sb, "Tgid:\t%d\n", p->p_pid); 1118 sbuf_printf(sb, "Pid:\t%d\n", p->p_pid); 1119 sbuf_printf(sb, "PPid:\t%d\n", kp.ki_ppid ); 1120 sbuf_printf(sb, "TracerPid:\t%d\n", kp.ki_tracer ); 1121 sbuf_printf(sb, "Uid:\t%d\t%d\t%d\t%d\n", p->p_ucred->cr_ruid, 1122 p->p_ucred->cr_uid, 1123 p->p_ucred->cr_svuid, 1124 /* FreeBSD doesn't have fsuid */ 1125 p->p_ucred->cr_uid); 1126 sbuf_printf(sb, "Gid:\t%d\t%d\t%d\t%d\n", p->p_ucred->cr_rgid, 1127 p->p_ucred->cr_gid, 1128 p->p_ucred->cr_svgid, 1129 /* FreeBSD doesn't have fsgid */ 1130 p->p_ucred->cr_gid); 1131 sbuf_cat(sb, "Groups:\t"); 1132 for (i = 0; i < p->p_ucred->cr_ngroups; i++) 1133 sbuf_printf(sb, "%d ", p->p_ucred->cr_groups[i]); 1134 PROC_UNLOCK(p); 1135 sbuf_putc(sb, '\n'); 1136 1137 /* 1138 * Memory 1139 * 1140 * While our approximation of VmLib may not be accurate (I 1141 * don't know of a simple way to verify it, and I'm not sure 1142 * it has much meaning anyway), I believe it's good enough. 1143 * 1144 * The same code that could (I think) accurately compute VmLib 1145 * could also compute VmLck, but I don't really care enough to 1146 * implement it. Submissions are welcome. 1147 */ 1148 sbuf_printf(sb, "VmSize:\t%8ju kB\n", B2K((uintmax_t)kp.ki_size)); 1149 sbuf_printf(sb, "VmLck:\t%8u kB\n", P2K(0)); /* XXX */ 1150 sbuf_printf(sb, "VmRSS:\t%8ju kB\n", P2K((uintmax_t)kp.ki_rssize)); 1151 sbuf_printf(sb, "VmData:\t%8ju kB\n", P2K((uintmax_t)kp.ki_dsize)); 1152 sbuf_printf(sb, "VmStk:\t%8ju kB\n", P2K((uintmax_t)kp.ki_ssize)); 1153 sbuf_printf(sb, "VmExe:\t%8ju kB\n", P2K((uintmax_t)kp.ki_tsize)); 1154 lsize = B2P(kp.ki_size) - kp.ki_dsize - 1155 kp.ki_ssize - kp.ki_tsize - 1; 1156 sbuf_printf(sb, "VmLib:\t%8ju kB\n", P2K((uintmax_t)lsize)); 1157 1158 /* 1159 * Signal masks 1160 */ 1161 PROC_LOCK(p); 1162 bsd_to_linux_sigset(&p->p_siglist, &siglist); 1163 ps = p->p_sigacts; 1164 mtx_lock(&ps->ps_mtx); 1165 bsd_to_linux_sigset(&ps->ps_sigignore, &sigignore); 1166 bsd_to_linux_sigset(&ps->ps_sigcatch, &sigcatch); 1167 mtx_unlock(&ps->ps_mtx); 1168 PROC_UNLOCK(p); 1169 1170 sbuf_printf(sb, "SigPnd:\t%016jx\n", siglist.__mask); 1171 /* 1172 * XXX. SigBlk - target thread's signal mask, td_sigmask. 1173 * To implement SigBlk pseudofs should support proc/tid dir entries. 1174 */ 1175 sbuf_printf(sb, "SigBlk:\t%016x\n", 0); 1176 sbuf_printf(sb, "SigIgn:\t%016jx\n", sigignore.__mask); 1177 sbuf_printf(sb, "SigCgt:\t%016jx\n", sigcatch.__mask); 1178 1179 /* 1180 * Linux also prints the capability masks, but we don't have 1181 * capabilities yet, and when we do get them they're likely to 1182 * be meaningless to Linux programs, so we lie. XXX 1183 */ 1184 sbuf_printf(sb, "CapInh:\t%016x\n", 0); 1185 sbuf_printf(sb, "CapPrm:\t%016x\n", 0); 1186 sbuf_printf(sb, "CapEff:\t%016x\n", 0); 1187 1188 return (0); 1189 } 1190 1191 /* 1192 * Filler function for proc/pid/cwd 1193 */ 1194 static int 1195 linprocfs_doproccwd(PFS_FILL_ARGS) 1196 { 1197 struct pwd *pwd; 1198 char *fullpath = "unknown"; 1199 char *freepath = NULL; 1200 1201 pwd = pwd_hold_proc(p); 1202 vn_fullpath(pwd->pwd_cdir, &fullpath, &freepath); 1203 sbuf_printf(sb, "%s", fullpath); 1204 if (freepath) 1205 free(freepath, M_TEMP); 1206 pwd_drop(pwd); 1207 return (0); 1208 } 1209 1210 /* 1211 * Filler function for proc/pid/root 1212 */ 1213 static int 1214 linprocfs_doprocroot(PFS_FILL_ARGS) 1215 { 1216 struct pwd *pwd; 1217 struct vnode *vp; 1218 char *fullpath = "unknown"; 1219 char *freepath = NULL; 1220 1221 pwd = pwd_hold_proc(p); 1222 vp = jailed(p->p_ucred) ? pwd->pwd_jdir : pwd->pwd_rdir; 1223 vn_fullpath(vp, &fullpath, &freepath); 1224 sbuf_printf(sb, "%s", fullpath); 1225 if (freepath) 1226 free(freepath, M_TEMP); 1227 pwd_drop(pwd); 1228 return (0); 1229 } 1230 1231 /* 1232 * Filler function for proc/pid/cmdline 1233 */ 1234 static int 1235 linprocfs_doproccmdline(PFS_FILL_ARGS) 1236 { 1237 int ret; 1238 1239 PROC_LOCK(p); 1240 if ((ret = p_cansee(td, p)) != 0) { 1241 PROC_UNLOCK(p); 1242 return (ret); 1243 } 1244 1245 /* 1246 * Mimic linux behavior and pass only processes with usermode 1247 * address space as valid. Return zero silently otherwize. 1248 */ 1249 if (p->p_vmspace == &vmspace0) { 1250 PROC_UNLOCK(p); 1251 return (0); 1252 } 1253 if (p->p_args != NULL) { 1254 sbuf_bcpy(sb, p->p_args->ar_args, p->p_args->ar_length); 1255 PROC_UNLOCK(p); 1256 return (0); 1257 } 1258 1259 if ((p->p_flag & P_SYSTEM) != 0) { 1260 PROC_UNLOCK(p); 1261 return (0); 1262 } 1263 1264 PROC_UNLOCK(p); 1265 1266 ret = proc_getargv(td, p, sb); 1267 return (ret); 1268 } 1269 1270 /* 1271 * Filler function for proc/pid/environ 1272 */ 1273 static int 1274 linprocfs_doprocenviron(PFS_FILL_ARGS) 1275 { 1276 1277 /* 1278 * Mimic linux behavior and pass only processes with usermode 1279 * address space as valid. Return zero silently otherwize. 1280 */ 1281 if (p->p_vmspace == &vmspace0) 1282 return (0); 1283 1284 return (proc_getenvv(td, p, sb)); 1285 } 1286 1287 static char l32_map_str[] = "%08lx-%08lx %s%s%s%s %08lx %02x:%02x %lu%s%s\n"; 1288 static char l64_map_str[] = "%016lx-%016lx %s%s%s%s %08lx %02x:%02x %lu%s%s\n"; 1289 static char vdso_str[] = " [vdso]"; 1290 static char stack_str[] = " [stack]"; 1291 1292 /* 1293 * Filler function for proc/pid/maps 1294 */ 1295 static int 1296 linprocfs_doprocmaps(PFS_FILL_ARGS) 1297 { 1298 struct vmspace *vm; 1299 vm_map_t map; 1300 vm_map_entry_t entry, tmp_entry; 1301 vm_object_t obj, tobj, lobj; 1302 vm_offset_t e_start, e_end; 1303 vm_ooffset_t off; 1304 vm_prot_t e_prot; 1305 unsigned int last_timestamp; 1306 char *name = "", *freename = NULL; 1307 const char *l_map_str; 1308 ino_t ino; 1309 int error; 1310 struct vnode *vp; 1311 struct vattr vat; 1312 bool private; 1313 1314 PROC_LOCK(p); 1315 error = p_candebug(td, p); 1316 PROC_UNLOCK(p); 1317 if (error) 1318 return (error); 1319 1320 if (uio->uio_rw != UIO_READ) 1321 return (EOPNOTSUPP); 1322 1323 error = 0; 1324 vm = vmspace_acquire_ref(p); 1325 if (vm == NULL) 1326 return (ESRCH); 1327 1328 if (SV_CURPROC_FLAG(SV_LP64)) 1329 l_map_str = l64_map_str; 1330 else 1331 l_map_str = l32_map_str; 1332 map = &vm->vm_map; 1333 vm_map_lock_read(map); 1334 VM_MAP_ENTRY_FOREACH(entry, map) { 1335 name = ""; 1336 freename = NULL; 1337 /* 1338 * Skip printing of the guard page of the stack region, as 1339 * it confuses glibc pthread_getattr_np() method, where both 1340 * the base address and size of the stack of the initial thread 1341 * are calculated. 1342 */ 1343 if ((entry->eflags & (MAP_ENTRY_IS_SUB_MAP | MAP_ENTRY_GUARD)) != 0) 1344 continue; 1345 e_prot = entry->protection; 1346 e_start = entry->start; 1347 e_end = entry->end; 1348 obj = entry->object.vm_object; 1349 off = entry->offset; 1350 for (lobj = tobj = obj; tobj != NULL; 1351 lobj = tobj, tobj = tobj->backing_object) { 1352 VM_OBJECT_RLOCK(tobj); 1353 off += lobj->backing_object_offset; 1354 if (lobj != obj) 1355 VM_OBJECT_RUNLOCK(lobj); 1356 } 1357 private = (entry->eflags & MAP_ENTRY_COW) != 0 || obj == NULL || 1358 (obj->flags & OBJ_ANON) != 0; 1359 last_timestamp = map->timestamp; 1360 vm_map_unlock_read(map); 1361 ino = 0; 1362 if (lobj) { 1363 vp = vm_object_vnode(lobj); 1364 if (vp != NULL) 1365 vref(vp); 1366 if (lobj != obj) 1367 VM_OBJECT_RUNLOCK(lobj); 1368 VM_OBJECT_RUNLOCK(obj); 1369 if (vp != NULL) { 1370 vn_fullpath(vp, &name, &freename); 1371 vn_lock(vp, LK_SHARED | LK_RETRY); 1372 VOP_GETATTR(vp, &vat, td->td_ucred); 1373 ino = vat.va_fileid; 1374 vput(vp); 1375 } else if (SV_PROC_ABI(p) == SV_ABI_LINUX) { 1376 /* 1377 * sv_shared_page_base pointed out to the 1378 * FreeBSD sharedpage, PAGE_SIZE is a size 1379 * of it. The vDSO page is above. 1380 */ 1381 if (e_start == p->p_sysent->sv_shared_page_base + 1382 PAGE_SIZE) 1383 name = vdso_str; 1384 if (e_end == p->p_sysent->sv_usrstack) 1385 name = stack_str; 1386 } 1387 } 1388 1389 /* 1390 * format: 1391 * start, end, access, offset, major, minor, inode, name. 1392 */ 1393 error = sbuf_printf(sb, l_map_str, 1394 (u_long)e_start, (u_long)e_end, 1395 (e_prot & VM_PROT_READ)?"r":"-", 1396 (e_prot & VM_PROT_WRITE)?"w":"-", 1397 (e_prot & VM_PROT_EXECUTE)?"x":"-", 1398 private ? "p" : "s", 1399 (u_long)off, 1400 0, 1401 0, 1402 (u_long)ino, 1403 *name ? " " : " ", 1404 name 1405 ); 1406 if (freename) 1407 free(freename, M_TEMP); 1408 vm_map_lock_read(map); 1409 if (error == -1) { 1410 error = 0; 1411 break; 1412 } 1413 if (last_timestamp != map->timestamp) { 1414 /* 1415 * Look again for the entry because the map was 1416 * modified while it was unlocked. Specifically, 1417 * the entry may have been clipped, merged, or deleted. 1418 */ 1419 vm_map_lookup_entry(map, e_end - 1, &tmp_entry); 1420 entry = tmp_entry; 1421 } 1422 } 1423 vm_map_unlock_read(map); 1424 vmspace_free(vm); 1425 1426 return (error); 1427 } 1428 1429 /* 1430 * Filler function for proc/pid/mem 1431 */ 1432 static int 1433 linprocfs_doprocmem(PFS_FILL_ARGS) 1434 { 1435 ssize_t resid; 1436 int error; 1437 1438 resid = uio->uio_resid; 1439 error = procfs_doprocmem(PFS_FILL_ARGNAMES); 1440 1441 if (uio->uio_rw == UIO_READ && resid != uio->uio_resid) 1442 return (0); 1443 1444 if (error == EFAULT) 1445 error = EIO; 1446 1447 return (error); 1448 } 1449 1450 /* 1451 * Filler function for proc/net/dev 1452 */ 1453 static int 1454 linprocfs_donetdev_cb(if_t ifp, void *arg) 1455 { 1456 char ifname[LINUX_IFNAMSIZ]; 1457 struct sbuf *sb = arg; 1458 1459 if (ifname_bsd_to_linux_ifp(ifp, ifname, sizeof(ifname)) <= 0) 1460 return (ENODEV); 1461 1462 sbuf_printf(sb, "%6.6s: ", ifname); 1463 sbuf_printf(sb, "%7ju %7ju %4ju %4ju %4lu %5lu %10lu %9ju ", 1464 (uintmax_t)if_getcounter(ifp, IFCOUNTER_IBYTES), 1465 (uintmax_t)if_getcounter(ifp, IFCOUNTER_IPACKETS), 1466 (uintmax_t)if_getcounter(ifp, IFCOUNTER_IERRORS), 1467 (uintmax_t)if_getcounter(ifp, IFCOUNTER_IQDROPS), 1468 /* rx_missed_errors */ 1469 0UL, /* rx_fifo_errors */ 1470 0UL, /* rx_length_errors + 1471 * rx_over_errors + 1472 * rx_crc_errors + 1473 * rx_frame_errors */ 1474 0UL, /* rx_compressed */ 1475 (uintmax_t)if_getcounter(ifp, IFCOUNTER_IMCASTS)); 1476 /* XXX-BZ rx only? */ 1477 sbuf_printf(sb, "%8ju %7ju %4ju %4ju %4lu %5ju %7lu %10lu\n", 1478 (uintmax_t)if_getcounter(ifp, IFCOUNTER_OBYTES), 1479 (uintmax_t)if_getcounter(ifp, IFCOUNTER_OPACKETS), 1480 (uintmax_t)if_getcounter(ifp, IFCOUNTER_OERRORS), 1481 (uintmax_t)if_getcounter(ifp, IFCOUNTER_OQDROPS), 1482 0UL, /* tx_fifo_errors */ 1483 (uintmax_t)if_getcounter(ifp, IFCOUNTER_COLLISIONS), 1484 0UL, /* tx_carrier_errors + 1485 * tx_aborted_errors + 1486 * tx_window_errors + 1487 * tx_heartbeat_errors*/ 1488 0UL); /* tx_compressed */ 1489 return (0); 1490 } 1491 1492 static int 1493 linprocfs_donetdev(PFS_FILL_ARGS) 1494 { 1495 struct epoch_tracker et; 1496 1497 sbuf_printf(sb, "%6s|%58s|%s\n" 1498 "%6s|%58s|%58s\n", 1499 "Inter-", " Receive", " Transmit", 1500 " face", 1501 "bytes packets errs drop fifo frame compressed multicast", 1502 "bytes packets errs drop fifo colls carrier compressed"); 1503 1504 CURVNET_SET(TD_TO_VNET(curthread)); 1505 NET_EPOCH_ENTER(et); 1506 if_foreach(linprocfs_donetdev_cb, sb); 1507 NET_EPOCH_EXIT(et); 1508 CURVNET_RESTORE(); 1509 1510 return (0); 1511 } 1512 1513 struct walkarg { 1514 struct sbuf *sb; 1515 }; 1516 1517 static int 1518 linux_route_print(struct rtentry *rt, void *vw) 1519 { 1520 #ifdef INET 1521 struct walkarg *w = vw; 1522 struct route_nhop_data rnd; 1523 struct in_addr dst, mask; 1524 struct nhop_object *nh; 1525 char ifname[16]; 1526 uint32_t scopeid = 0; 1527 uint32_t gw = 0; 1528 uint32_t linux_flags = 0; 1529 1530 rt_get_inet_prefix_pmask(rt, &dst, &mask, &scopeid); 1531 1532 rt_get_rnd(rt, &rnd); 1533 1534 /* select only first route in case of multipath */ 1535 nh = nhop_select_func(rnd.rnd_nhop, 0); 1536 1537 if (ifname_bsd_to_linux_ifp(nh->nh_ifp, ifname, sizeof(ifname)) <= 0) 1538 return (ENODEV); 1539 1540 gw = (nh->nh_flags & NHF_GATEWAY) 1541 ? nh->gw4_sa.sin_addr.s_addr : 0; 1542 1543 linux_flags = RTF_UP | 1544 (nhop_get_rtflags(nh) & (RTF_GATEWAY | RTF_HOST)); 1545 1546 sbuf_printf(w->sb, 1547 "%s\t" 1548 "%08X\t%08X\t%04X\t" 1549 "%d\t%u\t%d\t" 1550 "%08X\t%d\t%u\t%u", 1551 ifname, 1552 dst.s_addr, gw, linux_flags, 1553 0, 0, rnd.rnd_weight, 1554 mask.s_addr, nh->nh_mtu, 0, 0); 1555 1556 sbuf_printf(w->sb, "\n\n"); 1557 #endif 1558 return (0); 1559 } 1560 1561 /* 1562 * Filler function for proc/net/route 1563 */ 1564 static int 1565 linprocfs_donetroute(PFS_FILL_ARGS) 1566 { 1567 struct epoch_tracker et; 1568 struct walkarg w = { 1569 .sb = sb 1570 }; 1571 uint32_t fibnum = curthread->td_proc->p_fibnum; 1572 1573 sbuf_printf(w.sb, "%-127s\n", "Iface\tDestination\tGateway " 1574 "\tFlags\tRefCnt\tUse\tMetric\tMask\t\tMTU" 1575 "\tWindow\tIRTT"); 1576 1577 CURVNET_SET(TD_TO_VNET(curthread)); 1578 NET_EPOCH_ENTER(et); 1579 rib_walk(fibnum, AF_INET, false, linux_route_print, &w); 1580 NET_EPOCH_EXIT(et); 1581 CURVNET_RESTORE(); 1582 1583 return (0); 1584 } 1585 1586 /* 1587 * Filler function for proc/sys/kernel/osrelease 1588 */ 1589 static int 1590 linprocfs_doosrelease(PFS_FILL_ARGS) 1591 { 1592 char osrelease[LINUX_MAX_UTSNAME]; 1593 1594 linux_get_osrelease(td, osrelease); 1595 sbuf_printf(sb, "%s\n", osrelease); 1596 1597 return (0); 1598 } 1599 1600 /* 1601 * Filler function for proc/sys/kernel/ostype 1602 */ 1603 static int 1604 linprocfs_doostype(PFS_FILL_ARGS) 1605 { 1606 char osname[LINUX_MAX_UTSNAME]; 1607 1608 linux_get_osname(td, osname); 1609 sbuf_printf(sb, "%s\n", osname); 1610 1611 return (0); 1612 } 1613 1614 /* 1615 * Filler function for proc/sys/kernel/version 1616 */ 1617 static int 1618 linprocfs_doosbuild(PFS_FILL_ARGS) 1619 { 1620 1621 linprocfs_osbuild(td, sb); 1622 sbuf_cat(sb, "\n"); 1623 return (0); 1624 } 1625 1626 /* 1627 * Filler function for proc/sys/kernel/msgmax 1628 */ 1629 static int 1630 linprocfs_domsgmax(PFS_FILL_ARGS) 1631 { 1632 1633 sbuf_printf(sb, "%d\n", msginfo.msgmax); 1634 return (0); 1635 } 1636 1637 /* 1638 * Filler function for proc/sys/kernel/msgmni 1639 */ 1640 static int 1641 linprocfs_domsgmni(PFS_FILL_ARGS) 1642 { 1643 1644 sbuf_printf(sb, "%d\n", msginfo.msgmni); 1645 return (0); 1646 } 1647 1648 /* 1649 * Filler function for proc/sys/kernel/msgmnb 1650 */ 1651 static int 1652 linprocfs_domsgmnb(PFS_FILL_ARGS) 1653 { 1654 1655 sbuf_printf(sb, "%d\n", msginfo.msgmnb); 1656 return (0); 1657 } 1658 1659 /* 1660 * Filler function for proc/sys/kernel/ngroups_max 1661 * 1662 * Note that in Linux it defaults to 65536, not 1023. 1663 */ 1664 static int 1665 linprocfs_dongroups_max(PFS_FILL_ARGS) 1666 { 1667 1668 sbuf_printf(sb, "%d\n", ngroups_max); 1669 return (0); 1670 } 1671 1672 /* 1673 * Filler function for proc/sys/kernel/pid_max 1674 */ 1675 static int 1676 linprocfs_dopid_max(PFS_FILL_ARGS) 1677 { 1678 1679 sbuf_printf(sb, "%i\n", PID_MAX); 1680 return (0); 1681 } 1682 1683 /* 1684 * Filler function for proc/sys/kernel/sem 1685 */ 1686 static int 1687 linprocfs_dosem(PFS_FILL_ARGS) 1688 { 1689 1690 sbuf_printf(sb, "%d %d %d %d\n", seminfo.semmsl, seminfo.semmns, 1691 seminfo.semopm, seminfo.semmni); 1692 return (0); 1693 } 1694 1695 /* 1696 * Filler function for proc/sys/kernel/shmall 1697 */ 1698 static int 1699 linprocfs_doshmall(PFS_FILL_ARGS) 1700 { 1701 1702 sbuf_printf(sb, "%lu\n", shminfo.shmall); 1703 return (0); 1704 } 1705 1706 /* 1707 * Filler function for proc/sys/kernel/shmmax 1708 */ 1709 static int 1710 linprocfs_doshmmax(PFS_FILL_ARGS) 1711 { 1712 1713 sbuf_printf(sb, "%lu\n", shminfo.shmmax); 1714 return (0); 1715 } 1716 1717 /* 1718 * Filler function for proc/sys/kernel/shmmni 1719 */ 1720 static int 1721 linprocfs_doshmmni(PFS_FILL_ARGS) 1722 { 1723 1724 sbuf_printf(sb, "%lu\n", shminfo.shmmni); 1725 return (0); 1726 } 1727 1728 /* 1729 * Filler function for proc/sys/kernel/tainted 1730 */ 1731 static int 1732 linprocfs_dotainted(PFS_FILL_ARGS) 1733 { 1734 1735 sbuf_printf(sb, "0\n"); 1736 return (0); 1737 } 1738 1739 /* 1740 * Filler function for proc/sys/vm/min_free_kbytes 1741 * 1742 * This mirrors the approach in illumos to return zero for reads. Effectively, 1743 * it says, no memory is kept in reserve for "atomic allocations". This class 1744 * of allocation can be used at times when a thread cannot be suspended. 1745 */ 1746 static int 1747 linprocfs_dominfree(PFS_FILL_ARGS) 1748 { 1749 1750 sbuf_printf(sb, "%d\n", 0); 1751 return (0); 1752 } 1753 1754 /* 1755 * Filler function for proc/scsi/device_info 1756 */ 1757 static int 1758 linprocfs_doscsidevinfo(PFS_FILL_ARGS) 1759 { 1760 1761 return (0); 1762 } 1763 1764 /* 1765 * Filler function for proc/scsi/scsi 1766 */ 1767 static int 1768 linprocfs_doscsiscsi(PFS_FILL_ARGS) 1769 { 1770 1771 return (0); 1772 } 1773 1774 /* 1775 * Filler function for proc/devices 1776 */ 1777 static int 1778 linprocfs_dodevices(PFS_FILL_ARGS) 1779 { 1780 char *char_devices; 1781 sbuf_printf(sb, "Character devices:\n"); 1782 1783 char_devices = linux_get_char_devices(); 1784 sbuf_printf(sb, "%s", char_devices); 1785 linux_free_get_char_devices(char_devices); 1786 1787 sbuf_printf(sb, "\nBlock devices:\n"); 1788 1789 return (0); 1790 } 1791 1792 /* 1793 * Filler function for proc/cmdline 1794 */ 1795 static int 1796 linprocfs_docmdline(PFS_FILL_ARGS) 1797 { 1798 1799 sbuf_printf(sb, "BOOT_IMAGE=%s", kernelname); 1800 sbuf_printf(sb, " ro root=302\n"); 1801 return (0); 1802 } 1803 1804 /* 1805 * Filler function for proc/filesystems 1806 */ 1807 static int 1808 linprocfs_dofilesystems(PFS_FILL_ARGS) 1809 { 1810 struct vfsconf *vfsp; 1811 1812 vfsconf_slock(); 1813 TAILQ_FOREACH(vfsp, &vfsconf, vfc_list) { 1814 if (vfsp->vfc_flags & VFCF_SYNTHETIC) 1815 sbuf_printf(sb, "nodev"); 1816 sbuf_printf(sb, "\t%s\n", vfsp->vfc_name); 1817 } 1818 vfsconf_sunlock(); 1819 return(0); 1820 } 1821 1822 /* 1823 * Filler function for proc/modules 1824 */ 1825 static int 1826 linprocfs_domodules(PFS_FILL_ARGS) 1827 { 1828 #if 0 1829 struct linker_file *lf; 1830 1831 TAILQ_FOREACH(lf, &linker_files, link) { 1832 sbuf_printf(sb, "%-20s%8lu%4d\n", lf->filename, 1833 (unsigned long)lf->size, lf->refs); 1834 } 1835 #endif 1836 return (0); 1837 } 1838 1839 /* 1840 * Filler function for proc/pid/fd 1841 */ 1842 static int 1843 linprocfs_dofdescfs(PFS_FILL_ARGS) 1844 { 1845 1846 if (p == curproc) 1847 sbuf_printf(sb, "/dev/fd"); 1848 else 1849 sbuf_printf(sb, "unknown"); 1850 return (0); 1851 } 1852 1853 /* 1854 * Filler function for proc/pid/limits 1855 */ 1856 static const struct linux_rlimit_ident { 1857 const char *desc; 1858 const char *unit; 1859 unsigned int rlim_id; 1860 } linux_rlimits_ident[] = { 1861 { "Max cpu time", "seconds", RLIMIT_CPU }, 1862 { "Max file size", "bytes", RLIMIT_FSIZE }, 1863 { "Max data size", "bytes", RLIMIT_DATA }, 1864 { "Max stack size", "bytes", RLIMIT_STACK }, 1865 { "Max core file size", "bytes", RLIMIT_CORE }, 1866 { "Max resident set", "bytes", RLIMIT_RSS }, 1867 { "Max processes", "processes", RLIMIT_NPROC }, 1868 { "Max open files", "files", RLIMIT_NOFILE }, 1869 { "Max locked memory", "bytes", RLIMIT_MEMLOCK }, 1870 { "Max address space", "bytes", RLIMIT_AS }, 1871 { "Max file locks", "locks", LINUX_RLIMIT_LOCKS }, 1872 { "Max pending signals", "signals", LINUX_RLIMIT_SIGPENDING }, 1873 { "Max msgqueue size", "bytes", LINUX_RLIMIT_MSGQUEUE }, 1874 { "Max nice priority", "", LINUX_RLIMIT_NICE }, 1875 { "Max realtime priority", "", LINUX_RLIMIT_RTPRIO }, 1876 { "Max realtime timeout", "us", LINUX_RLIMIT_RTTIME }, 1877 { 0, 0, 0 } 1878 }; 1879 1880 static int 1881 linprocfs_doproclimits(PFS_FILL_ARGS) 1882 { 1883 const struct linux_rlimit_ident *li; 1884 struct plimit *limp; 1885 struct rlimit rl; 1886 ssize_t size; 1887 int res, error; 1888 1889 error = 0; 1890 1891 PROC_LOCK(p); 1892 limp = lim_hold(p->p_limit); 1893 PROC_UNLOCK(p); 1894 size = sizeof(res); 1895 sbuf_printf(sb, "%-26s%-21s%-21s%-21s\n", "Limit", "Soft Limit", 1896 "Hard Limit", "Units"); 1897 for (li = linux_rlimits_ident; li->desc != NULL; ++li) { 1898 switch (li->rlim_id) 1899 { 1900 case LINUX_RLIMIT_LOCKS: 1901 /* FALLTHROUGH */ 1902 case LINUX_RLIMIT_RTTIME: 1903 rl.rlim_cur = RLIM_INFINITY; 1904 break; 1905 case LINUX_RLIMIT_SIGPENDING: 1906 error = kernel_sysctlbyname(td, 1907 "kern.sigqueue.max_pending_per_proc", 1908 &res, &size, 0, 0, 0, 0); 1909 if (error != 0) 1910 continue; 1911 rl.rlim_cur = res; 1912 rl.rlim_max = res; 1913 break; 1914 case LINUX_RLIMIT_MSGQUEUE: 1915 error = kernel_sysctlbyname(td, 1916 "kern.ipc.msgmnb", &res, &size, 0, 0, 0, 0); 1917 if (error != 0) 1918 continue; 1919 rl.rlim_cur = res; 1920 rl.rlim_max = res; 1921 break; 1922 case LINUX_RLIMIT_NICE: 1923 /* FALLTHROUGH */ 1924 case LINUX_RLIMIT_RTPRIO: 1925 rl.rlim_cur = 0; 1926 rl.rlim_max = 0; 1927 break; 1928 default: 1929 rl = limp->pl_rlimit[li->rlim_id]; 1930 break; 1931 } 1932 if (rl.rlim_cur == RLIM_INFINITY) 1933 sbuf_printf(sb, "%-26s%-21s%-21s%-10s\n", 1934 li->desc, "unlimited", "unlimited", li->unit); 1935 else 1936 sbuf_printf(sb, "%-26s%-21llu%-21llu%-10s\n", 1937 li->desc, (unsigned long long)rl.rlim_cur, 1938 (unsigned long long)rl.rlim_max, li->unit); 1939 } 1940 1941 lim_free(limp); 1942 return (0); 1943 } 1944 1945 /* 1946 * The point of the following two functions is to work around 1947 * an assertion in Chromium; see kern/240991 for details. 1948 */ 1949 static int 1950 linprocfs_dotaskattr(PFS_ATTR_ARGS) 1951 { 1952 1953 vap->va_nlink = 3; 1954 return (0); 1955 } 1956 1957 /* 1958 * Filler function for proc/<pid>/task/.dummy 1959 */ 1960 static int 1961 linprocfs_dotaskdummy(PFS_FILL_ARGS) 1962 { 1963 1964 return (0); 1965 } 1966 1967 /* 1968 * Filler function for proc/sys/kernel/random/uuid 1969 */ 1970 static int 1971 linprocfs_douuid(PFS_FILL_ARGS) 1972 { 1973 struct uuid uuid; 1974 1975 kern_uuidgen(&uuid, 1); 1976 sbuf_printf_uuid(sb, &uuid); 1977 sbuf_printf(sb, "\n"); 1978 return(0); 1979 } 1980 1981 /* 1982 * Filler function for proc/sys/kernel/random/boot_id 1983 */ 1984 static int 1985 linprocfs_doboot_id(PFS_FILL_ARGS) 1986 { 1987 static bool firstboot = 1; 1988 static struct uuid uuid; 1989 1990 if (firstboot) { 1991 kern_uuidgen(&uuid, 1); 1992 firstboot = 0; 1993 } 1994 sbuf_printf_uuid(sb, &uuid); 1995 sbuf_printf(sb, "\n"); 1996 return(0); 1997 } 1998 1999 /* 2000 * Filler function for proc/pid/auxv 2001 */ 2002 static int 2003 linprocfs_doauxv(PFS_FILL_ARGS) 2004 { 2005 struct sbuf *asb; 2006 off_t buflen, resid; 2007 int error; 2008 2009 /* 2010 * Mimic linux behavior and pass only processes with usermode 2011 * address space as valid. Return zero silently otherwise. 2012 */ 2013 if (p->p_vmspace == &vmspace0) 2014 return (0); 2015 2016 if (uio->uio_resid == 0) 2017 return (0); 2018 if (uio->uio_offset < 0 || uio->uio_resid < 0) 2019 return (EINVAL); 2020 2021 asb = sbuf_new_auto(); 2022 if (asb == NULL) 2023 return (ENOMEM); 2024 error = proc_getauxv(td, p, asb); 2025 if (error != 0) 2026 goto out; 2027 error = sbuf_finish(asb); 2028 if (error != 0) 2029 goto out; 2030 2031 resid = sbuf_len(asb) - uio->uio_offset; 2032 if (resid > uio->uio_resid) 2033 buflen = uio->uio_resid; 2034 else 2035 buflen = resid; 2036 if (buflen > IOSIZE_MAX) { 2037 error = EINVAL; 2038 goto out; 2039 } 2040 if (buflen > maxphys) 2041 buflen = maxphys; 2042 if (resid > 0) 2043 error = uiomove(sbuf_data(asb) + uio->uio_offset, buflen, uio); 2044 out: 2045 sbuf_delete(asb); 2046 return (error); 2047 } 2048 2049 /* 2050 * Filler function for proc/self/oom_score_adj 2051 */ 2052 static int 2053 linprocfs_do_oom_score_adj(PFS_FILL_ARGS) 2054 { 2055 struct linux_pemuldata *pem; 2056 long oom; 2057 2058 pem = pem_find(p); 2059 if (pem == NULL || uio == NULL) 2060 return (EOPNOTSUPP); 2061 if (uio->uio_rw == UIO_READ) { 2062 sbuf_printf(sb, "%d\n", pem->oom_score_adj); 2063 } else { 2064 sbuf_trim(sb); 2065 sbuf_finish(sb); 2066 oom = strtol(sbuf_data(sb), NULL, 10); 2067 if (oom < LINUX_OOM_SCORE_ADJ_MIN || 2068 oom > LINUX_OOM_SCORE_ADJ_MAX) 2069 return (EINVAL); 2070 pem->oom_score_adj = oom; 2071 } 2072 return (0); 2073 } 2074 2075 /* 2076 * Filler function for proc/sys/vm/max_map_count 2077 * 2078 * Maximum number of active map areas, on Linux this limits the number 2079 * of vmaps per mm struct. We don't limit mappings, return a suitable 2080 * large value. 2081 */ 2082 static int 2083 linprocfs_domax_map_cnt(PFS_FILL_ARGS) 2084 { 2085 2086 sbuf_printf(sb, "%d\n", INT32_MAX); 2087 return (0); 2088 } 2089 2090 /* 2091 * Filler function for proc/sysvipc/msg 2092 */ 2093 static int 2094 linprocfs_dosysvipc_msg(PFS_FILL_ARGS) 2095 { 2096 struct msqid_kernel *msqids; 2097 size_t id, size; 2098 int error; 2099 2100 sbuf_printf(sb, 2101 "%10s %10s %4s %10s %10s %5s %5s %5s %5s %5s %5s %10s %10s %10s\n", 2102 "key", "msqid", "perms", "cbytes", "qnum", "lspid", "lrpid", 2103 "uid", "gid", "cuid", "cgid", "stime", "rtime", "ctime"); 2104 2105 error = kern_get_msqids(curthread, &msqids, &size); 2106 if (error != 0) 2107 return (error); 2108 2109 for (id = 0; id < size; id++) { 2110 if (msqids[id].u.msg_qbytes == 0) 2111 continue; 2112 sbuf_printf(sb, 2113 "%10d %10zu %4o %10lu %10lu %5u %5u %5u %5u %5u %5u %jd %jd %jd\n", 2114 (int)msqids[id].u.msg_perm.key, 2115 IXSEQ_TO_IPCID(id, msqids[id].u.msg_perm), 2116 msqids[id].u.msg_perm.mode, 2117 msqids[id].u.msg_cbytes, 2118 msqids[id].u.msg_qnum, 2119 msqids[id].u.msg_lspid, 2120 msqids[id].u.msg_lrpid, 2121 msqids[id].u.msg_perm.uid, 2122 msqids[id].u.msg_perm.gid, 2123 msqids[id].u.msg_perm.cuid, 2124 msqids[id].u.msg_perm.cgid, 2125 (intmax_t)msqids[id].u.msg_stime, 2126 (intmax_t)msqids[id].u.msg_rtime, 2127 (intmax_t)msqids[id].u.msg_ctime); 2128 } 2129 2130 free(msqids, M_TEMP); 2131 return (0); 2132 } 2133 2134 /* 2135 * Filler function for proc/sysvipc/sem 2136 */ 2137 static int 2138 linprocfs_dosysvipc_sem(PFS_FILL_ARGS) 2139 { 2140 struct semid_kernel *semids; 2141 size_t id, size; 2142 int error; 2143 2144 sbuf_printf(sb, "%10s %10s %4s %10s %5s %5s %5s %5s %10s %10s\n", 2145 "key", "semid", "perms", "nsems", "uid", "gid", "cuid", "cgid", 2146 "otime", "ctime"); 2147 2148 error = kern_get_sema(curthread, &semids, &size); 2149 if (error != 0) 2150 return (error); 2151 2152 for (id = 0; id < size; id++) { 2153 if ((semids[id].u.sem_perm.mode & SEM_ALLOC) == 0) 2154 continue; 2155 sbuf_printf(sb, 2156 "%10d %10zu %4o %10u %5u %5u %5u %5u %jd %jd\n", 2157 (int)semids[id].u.sem_perm.key, 2158 IXSEQ_TO_IPCID(id, semids[id].u.sem_perm), 2159 semids[id].u.sem_perm.mode, 2160 semids[id].u.sem_nsems, 2161 semids[id].u.sem_perm.uid, 2162 semids[id].u.sem_perm.gid, 2163 semids[id].u.sem_perm.cuid, 2164 semids[id].u.sem_perm.cgid, 2165 (intmax_t)semids[id].u.sem_otime, 2166 (intmax_t)semids[id].u.sem_ctime); 2167 } 2168 2169 free(semids, M_TEMP); 2170 return (0); 2171 } 2172 2173 /* 2174 * Filler function for proc/sysvipc/shm 2175 */ 2176 static int 2177 linprocfs_dosysvipc_shm(PFS_FILL_ARGS) 2178 { 2179 struct shmid_kernel *shmids; 2180 size_t id, size; 2181 int error; 2182 2183 sbuf_printf(sb, 2184 "%10s %10s %s %21s %5s %5s %5s %5s %5s %5s %5s %10s %10s %10s %21s %21s\n", 2185 "key", "shmid", "perms", "size", "cpid", "lpid", "nattch", "uid", 2186 "gid", "cuid", "cgid", "atime", "dtime", "ctime", "rss", "swap"); 2187 2188 error = kern_get_shmsegs(curthread, &shmids, &size); 2189 if (error != 0) 2190 return (error); 2191 2192 for (id = 0; id < size; id++) { 2193 if ((shmids[id].u.shm_perm.mode & SHMSEG_ALLOCATED) == 0) 2194 continue; 2195 sbuf_printf(sb, 2196 "%10d %10zu %4o %21zu %5u %5u %5u %5u %5u %5u %5u %jd %jd %jd %21d %21d\n", 2197 (int)shmids[id].u.shm_perm.key, 2198 IXSEQ_TO_IPCID(id, shmids[id].u.shm_perm), 2199 shmids[id].u.shm_perm.mode, 2200 shmids[id].u.shm_segsz, 2201 shmids[id].u.shm_cpid, 2202 shmids[id].u.shm_lpid, 2203 shmids[id].u.shm_nattch, 2204 shmids[id].u.shm_perm.uid, 2205 shmids[id].u.shm_perm.gid, 2206 shmids[id].u.shm_perm.cuid, 2207 shmids[id].u.shm_perm.cgid, 2208 (intmax_t)shmids[id].u.shm_atime, 2209 (intmax_t)shmids[id].u.shm_dtime, 2210 (intmax_t)shmids[id].u.shm_ctime, 2211 0, 0); /* XXX rss & swp are not supported */ 2212 } 2213 2214 free(shmids, M_TEMP); 2215 return (0); 2216 } 2217 2218 static int 2219 linprocfs_doinotify(const char *sysctl, PFS_FILL_ARGS) 2220 { 2221 size_t size; 2222 int error, val; 2223 2224 if (uio->uio_rw == UIO_READ) { 2225 size = sizeof(val); 2226 error = kernel_sysctlbyname(curthread, 2227 __DECONST(void *, sysctl), &val, &size, NULL, 0, 0, 0); 2228 if (error == 0) 2229 sbuf_printf(sb, "%d\n", val); 2230 } else { 2231 char *endp, *newval; 2232 long vall; 2233 2234 sbuf_trim(sb); 2235 sbuf_finish(sb); 2236 newval = sbuf_data(sb); 2237 vall = strtol(newval, &endp, 10); 2238 if (vall < 0 || vall > INT_MAX || endp == newval || 2239 *endp != '\0') 2240 return (EINVAL); 2241 val = (int)vall; 2242 error = kernel_sysctlbyname(curthread, 2243 __DECONST(void *, sysctl), NULL, NULL, 2244 &val, sizeof(val), 0, 0); 2245 } 2246 return (error); 2247 } 2248 2249 /* 2250 * Filler function for proc/sys/fs/inotify/max_queued_events 2251 */ 2252 static int 2253 linprocfs_doinotify_max_queued_events(PFS_FILL_ARGS) 2254 { 2255 return (linprocfs_doinotify("vfs.inotify.max_queued_events", 2256 PFS_FILL_ARGNAMES)); 2257 } 2258 2259 /* 2260 * Filler function for proc/sys/fs/inotify/max_user_instances 2261 */ 2262 static int 2263 linprocfs_doinotify_max_user_instances(PFS_FILL_ARGS) 2264 { 2265 return (linprocfs_doinotify("vfs.inotify.max_user_instances", 2266 PFS_FILL_ARGNAMES)); 2267 } 2268 2269 /* 2270 * Filler function for proc/sys/fs/inotify/max_user_watches 2271 */ 2272 static int 2273 linprocfs_doinotify_max_user_watches(PFS_FILL_ARGS) 2274 { 2275 return (linprocfs_doinotify("vfs.inotify.max_user_watches", 2276 PFS_FILL_ARGNAMES)); 2277 } 2278 2279 /* 2280 * Filler function for proc/sys/fs/mqueue/msg_default 2281 */ 2282 static int 2283 linprocfs_domqueue_msg_default(PFS_FILL_ARGS) 2284 { 2285 int res, error; 2286 size_t size = sizeof(res); 2287 2288 error = kernel_sysctlbyname(curthread, "kern.mqueue.default_maxmsg", 2289 &res, &size, NULL, 0, 0, 0); 2290 if (error != 0) 2291 return (error); 2292 2293 sbuf_printf(sb, "%d\n", res); 2294 return (0); 2295 } 2296 2297 /* 2298 * Filler function for proc/sys/fs/mqueue/msgsize_default 2299 */ 2300 static int 2301 linprocfs_domqueue_msgsize_default(PFS_FILL_ARGS) 2302 { 2303 int res, error; 2304 size_t size = sizeof(res); 2305 2306 error = kernel_sysctlbyname(curthread, "kern.mqueue.default_msgsize", 2307 &res, &size, NULL, 0, 0, 0); 2308 if (error != 0) 2309 return (error); 2310 2311 sbuf_printf(sb, "%d\n", res); 2312 return (0); 2313 2314 } 2315 2316 /* 2317 * Filler function for proc/sys/fs/mqueue/msg_max 2318 */ 2319 static int 2320 linprocfs_domqueue_msg_max(PFS_FILL_ARGS) 2321 { 2322 int res, error; 2323 size_t size = sizeof(res); 2324 2325 error = kernel_sysctlbyname(curthread, "kern.mqueue.maxmsg", 2326 &res, &size, NULL, 0, 0, 0); 2327 if (error != 0) 2328 return (error); 2329 2330 sbuf_printf(sb, "%d\n", res); 2331 return (0); 2332 } 2333 2334 /* 2335 * Filler function for proc/sys/fs/mqueue/msgsize_max 2336 */ 2337 static int 2338 linprocfs_domqueue_msgsize_max(PFS_FILL_ARGS) 2339 { 2340 int res, error; 2341 size_t size = sizeof(res); 2342 2343 error = kernel_sysctlbyname(curthread, "kern.mqueue.maxmsgsize", 2344 &res, &size, NULL, 0, 0, 0); 2345 if (error != 0) 2346 return (error); 2347 2348 sbuf_printf(sb, "%d\n", res); 2349 return (0); 2350 } 2351 2352 /* 2353 * Filler function for proc/sys/fs/mqueue/queues_max 2354 */ 2355 static int 2356 linprocfs_domqueue_queues_max(PFS_FILL_ARGS) 2357 { 2358 int res, error; 2359 size_t size = sizeof(res); 2360 2361 error = kernel_sysctlbyname(curthread, "kern.mqueue.maxmq", 2362 &res, &size, NULL, 0, 0, 0); 2363 if (error != 0) 2364 return (error); 2365 2366 sbuf_printf(sb, "%d\n", res); 2367 return (0); 2368 } 2369 2370 /* 2371 * Constructor 2372 */ 2373 static int 2374 linprocfs_init(PFS_INIT_ARGS) 2375 { 2376 struct pfs_node *dir, *fs, *root, *sys; 2377 2378 root = pi->pi_root; 2379 2380 /* /proc/... */ 2381 pfs_create_file(root, NULL, "cmdline", &linprocfs_docmdline, NULL, NULL, 2382 NULL, PFS_RD); 2383 pfs_create_file(root, NULL, "cpuinfo", &linprocfs_docpuinfo, NULL, NULL, 2384 NULL, PFS_RD); 2385 pfs_create_file(root, NULL, "devices", &linprocfs_dodevices, NULL, NULL, 2386 NULL, PFS_RD); 2387 pfs_create_file(root, NULL, "filesystems", &linprocfs_dofilesystems, 2388 NULL, NULL, NULL, PFS_RD); 2389 pfs_create_file(root, NULL, "loadavg", &linprocfs_doloadavg, NULL, NULL, 2390 NULL, PFS_RD); 2391 pfs_create_file(root, NULL, "meminfo", &linprocfs_domeminfo, NULL, NULL, 2392 NULL, PFS_RD); 2393 pfs_create_file(root, NULL, "modules", &linprocfs_domodules, NULL, NULL, 2394 NULL, PFS_RD); 2395 pfs_create_file(root, NULL, "mounts", &linprocfs_domtab, NULL, NULL, 2396 NULL, PFS_RD); 2397 pfs_create_file(root, NULL, "mtab", &linprocfs_domtab, NULL, NULL, NULL, 2398 PFS_RD); 2399 pfs_create_file(root, NULL, "partitions", &linprocfs_dopartitions, NULL, 2400 NULL, NULL, PFS_RD); 2401 pfs_create_link(root, NULL, "self", &procfs_docurproc, NULL, NULL, NULL, 2402 0); 2403 pfs_create_file(root, NULL, "stat", &linprocfs_dostat, NULL, NULL, NULL, 2404 PFS_RD); 2405 pfs_create_file(root, NULL, "swaps", &linprocfs_doswaps, NULL, NULL, 2406 NULL, PFS_RD); 2407 pfs_create_file(root, NULL, "uptime", &linprocfs_douptime, NULL, NULL, 2408 NULL, PFS_RD); 2409 pfs_create_file(root, NULL, "version", &linprocfs_doversion, NULL, NULL, 2410 NULL, PFS_RD); 2411 2412 /* /proc/bus/... */ 2413 pfs_create_dir(root, &dir, "bus", NULL, NULL, NULL, 0); 2414 pfs_create_dir(dir, &dir, "pci", NULL, NULL, NULL, 0); 2415 pfs_create_dir(dir, &dir, "devices", NULL, NULL, NULL, 0); 2416 2417 /* /proc/net/... */ 2418 pfs_create_dir(root, &dir, "net", NULL, NULL, NULL, 0); 2419 pfs_create_file(dir, NULL, "dev", &linprocfs_donetdev, NULL, NULL, NULL, 2420 PFS_RD); 2421 pfs_create_file(dir, NULL, "route", &linprocfs_donetroute, NULL, NULL, 2422 NULL, PFS_RD); 2423 2424 /* /proc/<pid>/... */ 2425 pfs_create_dir(root, &dir, "pid", NULL, NULL, NULL, PFS_PROCDEP); 2426 pfs_create_file(dir, NULL, "cmdline", &linprocfs_doproccmdline, NULL, 2427 NULL, NULL, PFS_RD); 2428 pfs_create_link(dir, NULL, "cwd", &linprocfs_doproccwd, NULL, NULL, 2429 NULL, 0); 2430 pfs_create_file(dir, NULL, "environ", &linprocfs_doprocenviron, NULL, 2431 &procfs_candebug, NULL, PFS_RD); 2432 pfs_create_link(dir, NULL, "exe", &procfs_doprocfile, NULL, 2433 &procfs_notsystem, NULL, 0); 2434 pfs_create_file(dir, NULL, "maps", &linprocfs_doprocmaps, NULL, NULL, 2435 NULL, PFS_RD | PFS_AUTODRAIN); 2436 pfs_create_file(dir, NULL, "mem", &linprocfs_doprocmem, procfs_attr_rw, 2437 &procfs_candebug, NULL, PFS_RDWR | PFS_RAW); 2438 pfs_create_file(dir, NULL, "mountinfo", &linprocfs_doprocmountinfo, 2439 NULL, NULL, NULL, PFS_RD); 2440 pfs_create_file(dir, NULL, "mounts", &linprocfs_domtab, NULL, NULL, 2441 NULL, PFS_RD); 2442 pfs_create_link(dir, NULL, "root", &linprocfs_doprocroot, NULL, NULL, 2443 NULL, 0); 2444 pfs_create_file(dir, NULL, "stat", &linprocfs_doprocstat, NULL, NULL, 2445 NULL, PFS_RD); 2446 pfs_create_file(dir, NULL, "statm", &linprocfs_doprocstatm, NULL, NULL, 2447 NULL, PFS_RD); 2448 pfs_create_file(dir, NULL, "status", &linprocfs_doprocstatus, NULL, 2449 NULL, NULL, PFS_RD); 2450 pfs_create_link(dir, NULL, "fd", &linprocfs_dofdescfs, NULL, NULL, NULL, 2451 0); 2452 pfs_create_file(dir, NULL, "auxv", &linprocfs_doauxv, NULL, 2453 &procfs_candebug, NULL, PFS_RD | PFS_RAWRD); 2454 pfs_create_file(dir, NULL, "limits", &linprocfs_doproclimits, NULL, 2455 NULL, NULL, PFS_RD); 2456 pfs_create_file(dir, NULL, "oom_score_adj", &linprocfs_do_oom_score_adj, 2457 procfs_attr_rw, &procfs_candebug, NULL, PFS_RDWR); 2458 2459 /* /proc/<pid>/task/... */ 2460 pfs_create_dir(dir, &dir, "task", linprocfs_dotaskattr, NULL, NULL, 0); 2461 pfs_create_file(dir, NULL, ".dummy", &linprocfs_dotaskdummy, NULL, NULL, 2462 NULL, PFS_RD); 2463 2464 /* /proc/scsi/... */ 2465 pfs_create_dir(root, &dir, "scsi", NULL, NULL, NULL, 0); 2466 pfs_create_file(dir, NULL, "device_info", &linprocfs_doscsidevinfo, 2467 NULL, NULL, NULL, PFS_RD); 2468 pfs_create_file(dir, NULL, "scsi", &linprocfs_doscsiscsi, NULL, NULL, 2469 NULL, PFS_RD); 2470 2471 /* /proc/sys/... */ 2472 pfs_create_dir(root, &sys, "sys", NULL, NULL, NULL, 0); 2473 2474 /* /proc/sys/kernel/... */ 2475 pfs_create_dir(sys, &dir, "kernel", NULL, NULL, NULL, 0); 2476 pfs_create_file(dir, NULL, "osrelease", &linprocfs_doosrelease, NULL, 2477 NULL, NULL, PFS_RD); 2478 pfs_create_file(dir, NULL, "ostype", &linprocfs_doostype, NULL, NULL, 2479 NULL, PFS_RD); 2480 pfs_create_file(dir, NULL, "version", &linprocfs_doosbuild, NULL, NULL, 2481 NULL, PFS_RD); 2482 pfs_create_file(dir, NULL, "msgmax", &linprocfs_domsgmax, NULL, NULL, 2483 NULL, PFS_RD); 2484 pfs_create_file(dir, NULL, "msgmni", &linprocfs_domsgmni, NULL, NULL, 2485 NULL, PFS_RD); 2486 pfs_create_file(dir, NULL, "msgmnb", &linprocfs_domsgmnb, NULL, NULL, 2487 NULL, PFS_RD); 2488 pfs_create_file(dir, NULL, "ngroups_max", &linprocfs_dongroups_max, 2489 NULL, NULL, NULL, PFS_RD); 2490 pfs_create_file(dir, NULL, "pid_max", &linprocfs_dopid_max, NULL, NULL, 2491 NULL, PFS_RD); 2492 pfs_create_file(dir, NULL, "sem", &linprocfs_dosem, NULL, NULL, NULL, 2493 PFS_RD); 2494 pfs_create_file(dir, NULL, "shmall", &linprocfs_doshmall, NULL, NULL, 2495 NULL, PFS_RD); 2496 pfs_create_file(dir, NULL, "shmmax", &linprocfs_doshmmax, NULL, NULL, 2497 NULL, PFS_RD); 2498 pfs_create_file(dir, NULL, "shmmni", &linprocfs_doshmmni, NULL, NULL, 2499 NULL, PFS_RD); 2500 pfs_create_file(dir, NULL, "tainted", &linprocfs_dotainted, NULL, NULL, 2501 NULL, PFS_RD); 2502 2503 /* /proc/sys/kernel/random/... */ 2504 pfs_create_dir(dir, &dir, "random", NULL, NULL, NULL, 0); 2505 pfs_create_file(dir, NULL, "uuid", &linprocfs_douuid, NULL, NULL, NULL, 2506 PFS_RD); 2507 pfs_create_file(dir, NULL, "boot_id", &linprocfs_doboot_id, NULL, NULL, 2508 NULL, PFS_RD); 2509 2510 /* /proc/sys/vm/.... */ 2511 pfs_create_dir(sys, &dir, "vm", NULL, NULL, NULL, 0); 2512 pfs_create_file(dir, NULL, "min_free_kbytes", &linprocfs_dominfree, 2513 NULL, NULL, NULL, PFS_RD); 2514 pfs_create_file(dir, NULL, "max_map_count", &linprocfs_domax_map_cnt, 2515 NULL, NULL, NULL, PFS_RD); 2516 2517 /* /proc/sysvipc/... */ 2518 pfs_create_dir(root, &dir, "sysvipc", NULL, NULL, NULL, 0); 2519 pfs_create_file(dir, NULL, "msg", &linprocfs_dosysvipc_msg, NULL, NULL, 2520 NULL, PFS_RD); 2521 pfs_create_file(dir, NULL, "sem", &linprocfs_dosysvipc_sem, NULL, NULL, 2522 NULL, PFS_RD); 2523 pfs_create_file(dir, NULL, "shm", &linprocfs_dosysvipc_shm, NULL, NULL, 2524 NULL, PFS_RD); 2525 2526 /* /proc/sys/fs/... */ 2527 pfs_create_dir(sys, &fs, "fs", NULL, NULL, NULL, 0); 2528 2529 pfs_create_dir(fs, &dir, "inotify", NULL, NULL, NULL, 0); 2530 pfs_create_file(dir, NULL, "max_queued_events", 2531 &linprocfs_doinotify_max_queued_events, NULL, NULL, NULL, PFS_RDWR); 2532 pfs_create_file(dir, NULL, "max_user_instances", 2533 &linprocfs_doinotify_max_user_instances, NULL, NULL, NULL, PFS_RDWR); 2534 pfs_create_file(dir, NULL, "max_user_watches", 2535 &linprocfs_doinotify_max_user_watches, NULL, NULL, NULL, PFS_RDWR); 2536 2537 /* /proc/sys/fs/mqueue/... */ 2538 pfs_create_dir(fs, &dir, "mqueue", NULL, NULL, NULL, 0); 2539 pfs_create_file(dir, NULL, "msg_default", 2540 &linprocfs_domqueue_msg_default, NULL, NULL, NULL, PFS_RD); 2541 pfs_create_file(dir, NULL, "msgsize_default", 2542 &linprocfs_domqueue_msgsize_default, NULL, NULL, NULL, PFS_RD); 2543 pfs_create_file(dir, NULL, "msg_max", &linprocfs_domqueue_msg_max, NULL, 2544 NULL, NULL, PFS_RD); 2545 pfs_create_file(dir, NULL, "msgsize_max", 2546 &linprocfs_domqueue_msgsize_max, NULL, NULL, NULL, PFS_RD); 2547 pfs_create_file(dir, NULL, "queues_max", &linprocfs_domqueue_queues_max, 2548 NULL, NULL, NULL, PFS_RD); 2549 2550 return (0); 2551 } 2552 2553 /* 2554 * Destructor 2555 */ 2556 static int 2557 linprocfs_uninit(PFS_INIT_ARGS) 2558 { 2559 2560 /* nothing to do, pseudofs will GC */ 2561 return (0); 2562 } 2563 2564 PSEUDOFS(linprocfs, 1, VFCF_JAIL); 2565 #if defined(__aarch64__) || defined(__amd64__) 2566 MODULE_DEPEND(linprocfs, linux_common, 1, 1, 1); 2567 #else 2568 MODULE_DEPEND(linprocfs, linux, 1, 1, 1); 2569 #endif 2570 MODULE_DEPEND(linprocfs, procfs, 1, 1, 1); 2571 MODULE_DEPEND(linprocfs, sysvmsg, 1, 1, 1); 2572 MODULE_DEPEND(linprocfs, sysvsem, 1, 1, 1); 2573 MODULE_DEPEND(linprocfs, sysvshm, 1, 1, 1); 2574