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]) & 0x7fffffff, 625 mntto); 626 /* (6) mount options */ 627 _sbuf_mntoptions_helper(sb, sp->f_flags); 628 /* 629 * (7) zero or more optional fields -- again, namespace related 630 * 631 * (8) End of variable length fields separator ("-") 632 * 633 * (9) fstype 634 * 635 * (10) mount from 636 * 637 * (11) "superblock" options -- like (6), but different 638 * semantics in Linux 639 */ 640 sbuf_printf(sb, " - %s %s %s\n", fstype, mntfrom, 641 (sp->f_flags & MNT_RDONLY) ? "ro" : "rw"); 642 } 643 644 error = 0; 645 out: 646 free(buf, M_TEMP); 647 free(flep, M_TEMP); 648 return (error); 649 } 650 651 /* 652 * Filler function for proc/partitions 653 */ 654 static int 655 linprocfs_dopartitions(PFS_FILL_ARGS) 656 { 657 struct g_class *cp; 658 struct g_geom *gp; 659 struct g_provider *pp; 660 int major, minor; 661 662 g_topology_lock(); 663 sbuf_printf(sb, "major minor #blocks name\n\n"); 664 665 LIST_FOREACH(cp, &g_classes, class) { 666 if (strcmp(cp->name, "DISK") == 0 || 667 strcmp(cp->name, "PART") == 0) 668 LIST_FOREACH(gp, &cp->geom, geom) { 669 LIST_FOREACH(pp, &gp->provider, provider) { 670 if (linux_driver_get_major_minor( 671 pp->name, &major, &minor) != 0) { 672 major = 0; 673 minor = 0; 674 } 675 sbuf_printf(sb, "%4d %7d %10lld %s\n", 676 major, minor, 677 B2K((long long)pp->mediasize), 678 pp->name); 679 } 680 } 681 } 682 g_topology_unlock(); 683 684 return (0); 685 } 686 687 /* 688 * Filler function for proc/stat 689 * 690 * Output depends on kernel version: 691 * 692 * v2.5.40 <= 693 * user nice system idle 694 * v2.5.41 695 * user nice system idle iowait 696 * v2.6.11 697 * user nice system idle iowait irq softirq steal 698 * v2.6.24 699 * user nice system idle iowait irq softirq steal guest 700 * v2.6.33 >= 701 * user nice system idle iowait irq softirq steal guest guest_nice 702 */ 703 static int 704 linprocfs_dostat(PFS_FILL_ARGS) 705 { 706 struct pcpu *pcpu; 707 long cp_time[CPUSTATES]; 708 long *cp; 709 struct timeval boottime; 710 int i; 711 char *zero_pad; 712 bool has_intr = true; 713 714 if (linux_kernver(td) >= LINUX_KERNVER(2,6,33)) { 715 zero_pad = " 0 0 0 0\n"; 716 } else if (linux_kernver(td) >= LINUX_KERNVER(2,6,24)) { 717 zero_pad = " 0 0 0\n"; 718 } else if (linux_kernver(td) >= LINUX_KERNVER(2,6,11)) { 719 zero_pad = " 0 0\n"; 720 } else if (linux_kernver(td) >= LINUX_KERNVER(2,5,41)) { 721 has_intr = false; 722 zero_pad = " 0\n"; 723 } else { 724 has_intr = false; 725 zero_pad = "\n"; 726 } 727 728 read_cpu_time(cp_time); 729 getboottime(&boottime); 730 /* Parameters common to all versions */ 731 sbuf_printf(sb, "cpu %lu %lu %lu %lu", 732 T2J(cp_time[CP_USER]), 733 T2J(cp_time[CP_NICE]), 734 T2J(cp_time[CP_SYS]), 735 T2J(cp_time[CP_IDLE])); 736 737 /* Print interrupt stats if available */ 738 if (has_intr) { 739 sbuf_printf(sb, " 0 %lu", T2J(cp_time[CP_INTR])); 740 } 741 742 /* Pad out remaining fields depending on version */ 743 sbuf_printf(sb, "%s", zero_pad); 744 745 CPU_FOREACH(i) { 746 pcpu = pcpu_find(i); 747 cp = pcpu->pc_cp_time; 748 sbuf_printf(sb, "cpu%d %lu %lu %lu %lu", i, 749 T2J(cp[CP_USER]), 750 T2J(cp[CP_NICE]), 751 T2J(cp[CP_SYS]), 752 T2J(cp[CP_IDLE])); 753 754 if (has_intr) { 755 sbuf_printf(sb, " 0 %lu", T2J(cp[CP_INTR])); 756 } 757 758 sbuf_printf(sb, "%s", zero_pad); 759 } 760 sbuf_printf(sb, 761 "disk 0 0 0 0\n" 762 "page %ju %ju\n" 763 "swap %ju %ju\n" 764 "intr %ju\n" 765 "ctxt %ju\n" 766 "btime %lld\n", 767 (uintmax_t)VM_CNT_FETCH(v_vnodepgsin), 768 (uintmax_t)VM_CNT_FETCH(v_vnodepgsout), 769 (uintmax_t)VM_CNT_FETCH(v_swappgsin), 770 (uintmax_t)VM_CNT_FETCH(v_swappgsout), 771 (uintmax_t)VM_CNT_FETCH(v_intr), 772 (uintmax_t)VM_CNT_FETCH(v_swtch), 773 (long long)boottime.tv_sec); 774 return (0); 775 } 776 777 static int 778 linprocfs_doswaps(PFS_FILL_ARGS) 779 { 780 struct xswdev xsw; 781 uintmax_t total, used; 782 int n; 783 char devname[SPECNAMELEN + 1]; 784 785 sbuf_printf(sb, "Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n"); 786 for (n = 0; ; n++) { 787 if (swap_dev_info(n, &xsw, devname, sizeof(devname)) != 0) 788 break; 789 total = (uintmax_t)xsw.xsw_nblks * PAGE_SIZE / 1024; 790 used = (uintmax_t)xsw.xsw_used * PAGE_SIZE / 1024; 791 792 /* 793 * The space and not tab after the device name is on 794 * purpose. Linux does so. 795 */ 796 sbuf_printf(sb, "/dev/%-34s unknown\t\t%jd\t%jd\t-1\n", 797 devname, total, used); 798 } 799 return (0); 800 } 801 802 /* 803 * Filler function for proc/uptime 804 */ 805 static int 806 linprocfs_douptime(PFS_FILL_ARGS) 807 { 808 long cp_time[CPUSTATES]; 809 struct timeval tv; 810 811 getmicrouptime(&tv); 812 read_cpu_time(cp_time); 813 sbuf_printf(sb, "%lld.%02ld %ld.%02lu\n", 814 (long long)tv.tv_sec, tv.tv_usec / 10000, 815 T2S(cp_time[CP_IDLE] / mp_ncpus), 816 T2CS(cp_time[CP_IDLE] / mp_ncpus) % 100); 817 return (0); 818 } 819 820 /* 821 * Get OS build date 822 */ 823 static void 824 linprocfs_osbuild(struct thread *td, struct sbuf *sb) 825 { 826 #if 0 827 char osbuild[256]; 828 char *cp1, *cp2; 829 830 strncpy(osbuild, version, 256); 831 osbuild[255] = '\0'; 832 cp1 = strstr(osbuild, "\n"); 833 cp2 = strstr(osbuild, ":"); 834 if (cp1 && cp2) { 835 *cp1 = *cp2 = '\0'; 836 cp1 = strstr(osbuild, "#"); 837 } else 838 cp1 = NULL; 839 if (cp1) 840 sbuf_printf(sb, "%s%s", cp1, cp2 + 1); 841 else 842 #endif 843 sbuf_cat(sb, "#4 Sun Dec 18 04:30:00 CET 1977"); 844 } 845 846 /* 847 * Get OS builder 848 */ 849 static void 850 linprocfs_osbuilder(struct thread *td, struct sbuf *sb) 851 { 852 #if 0 853 char builder[256]; 854 char *cp; 855 856 cp = strstr(version, "\n "); 857 if (cp) { 858 strncpy(builder, cp + 5, 256); 859 builder[255] = '\0'; 860 cp = strstr(builder, ":"); 861 if (cp) 862 *cp = '\0'; 863 } 864 if (cp) 865 sbuf_cat(sb, builder); 866 else 867 #endif 868 sbuf_cat(sb, "des@freebsd.org"); 869 } 870 871 /* 872 * Filler function for proc/version 873 */ 874 static int 875 linprocfs_doversion(PFS_FILL_ARGS) 876 { 877 char osname[LINUX_MAX_UTSNAME]; 878 char osrelease[LINUX_MAX_UTSNAME]; 879 880 linux_get_osname(td, osname); 881 linux_get_osrelease(td, osrelease); 882 sbuf_printf(sb, "%s version %s (", osname, osrelease); 883 linprocfs_osbuilder(td, sb); 884 sbuf_cat(sb, ") (gcc version " __VERSION__ ") "); 885 linprocfs_osbuild(td, sb); 886 sbuf_cat(sb, "\n"); 887 888 return (0); 889 } 890 891 /* 892 * Filler function for proc/loadavg 893 */ 894 static int 895 linprocfs_doloadavg(PFS_FILL_ARGS) 896 { 897 898 sbuf_printf(sb, 899 "%d.%02d %d.%02d %d.%02d %d/%d %d\n", 900 (int)(averunnable.ldavg[0] / averunnable.fscale), 901 (int)(averunnable.ldavg[0] * 100 / averunnable.fscale % 100), 902 (int)(averunnable.ldavg[1] / averunnable.fscale), 903 (int)(averunnable.ldavg[1] * 100 / averunnable.fscale % 100), 904 (int)(averunnable.ldavg[2] / averunnable.fscale), 905 (int)(averunnable.ldavg[2] * 100 / averunnable.fscale % 100), 906 1, /* number of running tasks */ 907 nprocs, /* number of tasks */ 908 lastpid /* the last pid */ 909 ); 910 return (0); 911 } 912 913 static int 914 linprocfs_get_tty_nr(struct proc *p) 915 { 916 struct session *sp; 917 const char *ttyname; 918 int error, major, minor, nr; 919 920 PROC_LOCK_ASSERT(p, MA_OWNED); 921 sx_assert(&proctree_lock, SX_LOCKED); 922 923 if ((p->p_flag & P_CONTROLT) == 0) 924 return (-1); 925 926 sp = p->p_pgrp->pg_session; 927 if (sp == NULL) 928 return (-1); 929 930 ttyname = devtoname(sp->s_ttyp->t_dev); 931 error = linux_driver_get_major_minor(ttyname, &major, &minor); 932 if (error != 0) 933 return (-1); 934 935 nr = makedev(major, minor); 936 return (nr); 937 } 938 939 /* 940 * Filler function for proc/pid/stat 941 */ 942 static int 943 linprocfs_doprocstat(PFS_FILL_ARGS) 944 { 945 struct kinfo_proc kp; 946 struct timeval boottime; 947 char state; 948 static int ratelimit = 0; 949 int tty_nr; 950 vm_offset_t startcode, startdata; 951 952 getboottime(&boottime); 953 sx_slock(&proctree_lock); 954 PROC_LOCK(p); 955 fill_kinfo_proc(p, &kp); 956 tty_nr = linprocfs_get_tty_nr(p); 957 sx_sunlock(&proctree_lock); 958 if (p->p_vmspace) { 959 startcode = (vm_offset_t)p->p_vmspace->vm_taddr; 960 startdata = (vm_offset_t)p->p_vmspace->vm_daddr; 961 } else { 962 startcode = 0; 963 startdata = 0; 964 } 965 sbuf_printf(sb, "%d", p->p_pid); 966 #define PS_ADD(name, fmt, arg) sbuf_printf(sb, " " fmt, arg) 967 PS_ADD("comm", "(%s)", p->p_comm); 968 if (kp.ki_stat > sizeof(linux_state)) { 969 state = 'R'; 970 971 if (ratelimit == 0) { 972 printf("linprocfs: don't know how to handle unknown FreeBSD state %d/%zd, mapping to R\n", 973 kp.ki_stat, sizeof(linux_state)); 974 ++ratelimit; 975 } 976 } else 977 state = linux_state[kp.ki_stat - 1]; 978 PS_ADD("state", "%c", state); 979 PS_ADD("ppid", "%d", p->p_pptr ? p->p_pptr->p_pid : 0); 980 PS_ADD("pgrp", "%d", p->p_pgid); 981 PS_ADD("session", "%d", p->p_session->s_sid); 982 PROC_UNLOCK(p); 983 PS_ADD("tty", "%d", tty_nr); 984 PS_ADD("tpgid", "%d", kp.ki_tpgid); 985 PS_ADD("flags", "%u", 0); /* XXX */ 986 PS_ADD("minflt", "%lu", kp.ki_rusage.ru_minflt); 987 PS_ADD("cminflt", "%lu", kp.ki_rusage_ch.ru_minflt); 988 PS_ADD("majflt", "%lu", kp.ki_rusage.ru_majflt); 989 PS_ADD("cmajflt", "%lu", kp.ki_rusage_ch.ru_majflt); 990 PS_ADD("utime", "%ld", TV2J(&kp.ki_rusage.ru_utime)); 991 PS_ADD("stime", "%ld", TV2J(&kp.ki_rusage.ru_stime)); 992 PS_ADD("cutime", "%ld", TV2J(&kp.ki_rusage_ch.ru_utime)); 993 PS_ADD("cstime", "%ld", TV2J(&kp.ki_rusage_ch.ru_stime)); 994 PS_ADD("priority", "%d", kp.ki_pri.pri_user); 995 PS_ADD("nice", "%d", kp.ki_nice); /* 19 (nicest) to -19 */ 996 PS_ADD("0", "%d", 0); /* removed field */ 997 PS_ADD("itrealvalue", "%d", 0); /* XXX */ 998 PS_ADD("starttime", "%lu", TV2J(&kp.ki_start) - TV2J(&boottime)); 999 PS_ADD("vsize", "%ju", (uintmax_t)kp.ki_size); 1000 PS_ADD("rss", "%ju", (uintmax_t)kp.ki_rssize); 1001 PS_ADD("rlim", "%lu", kp.ki_rusage.ru_maxrss); 1002 PS_ADD("startcode", "%ju", (uintmax_t)startcode); 1003 PS_ADD("endcode", "%ju", (uintmax_t)startdata); 1004 PS_ADD("startstack", "%u", 0); /* XXX */ 1005 PS_ADD("kstkesp", "%u", 0); /* XXX */ 1006 PS_ADD("kstkeip", "%u", 0); /* XXX */ 1007 PS_ADD("signal", "%u", 0); /* XXX */ 1008 PS_ADD("blocked", "%u", 0); /* XXX */ 1009 PS_ADD("sigignore", "%u", 0); /* XXX */ 1010 PS_ADD("sigcatch", "%u", 0); /* XXX */ 1011 PS_ADD("wchan", "%u", 0); /* XXX */ 1012 PS_ADD("nswap", "%lu", kp.ki_rusage.ru_nswap); 1013 PS_ADD("cnswap", "%lu", kp.ki_rusage_ch.ru_nswap); 1014 PS_ADD("exitsignal", "%d", 0); /* XXX */ 1015 PS_ADD("processor", "%u", kp.ki_lastcpu); 1016 PS_ADD("rt_priority", "%u", 0); /* XXX */ /* >= 2.5.19 */ 1017 PS_ADD("policy", "%u", kp.ki_pri.pri_class); /* >= 2.5.19 */ 1018 #undef PS_ADD 1019 sbuf_putc(sb, '\n'); 1020 1021 return (0); 1022 } 1023 1024 /* 1025 * Filler function for proc/pid/statm 1026 */ 1027 static int 1028 linprocfs_doprocstatm(PFS_FILL_ARGS) 1029 { 1030 struct kinfo_proc kp; 1031 segsz_t lsize; 1032 1033 sx_slock(&proctree_lock); 1034 PROC_LOCK(p); 1035 fill_kinfo_proc(p, &kp); 1036 PROC_UNLOCK(p); 1037 sx_sunlock(&proctree_lock); 1038 1039 /* 1040 * See comments in linprocfs_doprocstatus() regarding the 1041 * computation of lsize. 1042 */ 1043 /* size resident share trs drs lrs dt */ 1044 sbuf_printf(sb, "%ju ", B2P((uintmax_t)kp.ki_size)); 1045 sbuf_printf(sb, "%ju ", (uintmax_t)kp.ki_rssize); 1046 sbuf_printf(sb, "%ju ", (uintmax_t)0); /* XXX */ 1047 sbuf_printf(sb, "%ju ", (uintmax_t)kp.ki_tsize); 1048 sbuf_printf(sb, "%ju ", (uintmax_t)(kp.ki_dsize + kp.ki_ssize)); 1049 lsize = B2P(kp.ki_size) - kp.ki_dsize - 1050 kp.ki_ssize - kp.ki_tsize - 1; 1051 sbuf_printf(sb, "%ju ", (uintmax_t)lsize); 1052 sbuf_printf(sb, "%ju\n", (uintmax_t)0); /* XXX */ 1053 1054 return (0); 1055 } 1056 1057 /* 1058 * Filler function for proc/pid/status 1059 */ 1060 static int 1061 linprocfs_doprocstatus(PFS_FILL_ARGS) 1062 { 1063 struct kinfo_proc kp; 1064 char *state; 1065 segsz_t lsize; 1066 struct thread *td2; 1067 struct sigacts *ps; 1068 l_sigset_t siglist, sigignore, sigcatch; 1069 int i; 1070 1071 sx_slock(&proctree_lock); 1072 PROC_LOCK(p); 1073 td2 = FIRST_THREAD_IN_PROC(p); 1074 1075 if (P_SHOULDSTOP(p)) { 1076 state = "T (stopped)"; 1077 } else { 1078 switch(p->p_state) { 1079 case PRS_NEW: 1080 state = "I (idle)"; 1081 break; 1082 case PRS_NORMAL: 1083 if (p->p_flag & P_WEXIT) { 1084 state = "X (exiting)"; 1085 break; 1086 } 1087 switch(TD_GET_STATE(td2)) { 1088 case TDS_INHIBITED: 1089 state = "S (sleeping)"; 1090 break; 1091 case TDS_RUNQ: 1092 case TDS_RUNNING: 1093 state = "R (running)"; 1094 break; 1095 default: 1096 state = "? (unknown)"; 1097 break; 1098 } 1099 break; 1100 case PRS_ZOMBIE: 1101 state = "Z (zombie)"; 1102 break; 1103 default: 1104 state = "? (unknown)"; 1105 break; 1106 } 1107 } 1108 1109 fill_kinfo_proc(p, &kp); 1110 sx_sunlock(&proctree_lock); 1111 1112 sbuf_printf(sb, "Name:\t%s\n", p->p_comm); /* XXX escape */ 1113 sbuf_printf(sb, "State:\t%s\n", state); 1114 1115 /* 1116 * Credentials 1117 */ 1118 sbuf_printf(sb, "Tgid:\t%d\n", p->p_pid); 1119 sbuf_printf(sb, "Pid:\t%d\n", p->p_pid); 1120 sbuf_printf(sb, "PPid:\t%d\n", kp.ki_ppid ); 1121 sbuf_printf(sb, "TracerPid:\t%d\n", kp.ki_tracer ); 1122 sbuf_printf(sb, "Uid:\t%d\t%d\t%d\t%d\n", p->p_ucred->cr_ruid, 1123 p->p_ucred->cr_uid, 1124 p->p_ucred->cr_svuid, 1125 /* FreeBSD doesn't have fsuid */ 1126 p->p_ucred->cr_uid); 1127 sbuf_printf(sb, "Gid:\t%d\t%d\t%d\t%d\n", p->p_ucred->cr_rgid, 1128 p->p_ucred->cr_gid, 1129 p->p_ucred->cr_svgid, 1130 /* FreeBSD doesn't have fsgid */ 1131 p->p_ucred->cr_gid); 1132 sbuf_cat(sb, "Groups:\t"); 1133 for (i = 0; i < p->p_ucred->cr_ngroups; i++) 1134 sbuf_printf(sb, "%d ", p->p_ucred->cr_groups[i]); 1135 PROC_UNLOCK(p); 1136 sbuf_putc(sb, '\n'); 1137 1138 /* 1139 * Memory 1140 * 1141 * While our approximation of VmLib may not be accurate (I 1142 * don't know of a simple way to verify it, and I'm not sure 1143 * it has much meaning anyway), I believe it's good enough. 1144 * 1145 * The same code that could (I think) accurately compute VmLib 1146 * could also compute VmLck, but I don't really care enough to 1147 * implement it. Submissions are welcome. 1148 */ 1149 sbuf_printf(sb, "VmSize:\t%8ju kB\n", B2K((uintmax_t)kp.ki_size)); 1150 sbuf_printf(sb, "VmLck:\t%8u kB\n", P2K(0)); /* XXX */ 1151 sbuf_printf(sb, "VmRSS:\t%8ju kB\n", P2K((uintmax_t)kp.ki_rssize)); 1152 sbuf_printf(sb, "VmData:\t%8ju kB\n", P2K((uintmax_t)kp.ki_dsize)); 1153 sbuf_printf(sb, "VmStk:\t%8ju kB\n", P2K((uintmax_t)kp.ki_ssize)); 1154 sbuf_printf(sb, "VmExe:\t%8ju kB\n", P2K((uintmax_t)kp.ki_tsize)); 1155 lsize = B2P(kp.ki_size) - kp.ki_dsize - 1156 kp.ki_ssize - kp.ki_tsize - 1; 1157 sbuf_printf(sb, "VmLib:\t%8ju kB\n", P2K((uintmax_t)lsize)); 1158 1159 /* 1160 * Signal masks 1161 */ 1162 PROC_LOCK(p); 1163 bsd_to_linux_sigset(&p->p_siglist, &siglist); 1164 ps = p->p_sigacts; 1165 mtx_lock(&ps->ps_mtx); 1166 bsd_to_linux_sigset(&ps->ps_sigignore, &sigignore); 1167 bsd_to_linux_sigset(&ps->ps_sigcatch, &sigcatch); 1168 mtx_unlock(&ps->ps_mtx); 1169 PROC_UNLOCK(p); 1170 1171 sbuf_printf(sb, "SigPnd:\t%016jx\n", siglist.__mask); 1172 /* 1173 * XXX. SigBlk - target thread's signal mask, td_sigmask. 1174 * To implement SigBlk pseudofs should support proc/tid dir entries. 1175 */ 1176 sbuf_printf(sb, "SigBlk:\t%016x\n", 0); 1177 sbuf_printf(sb, "SigIgn:\t%016jx\n", sigignore.__mask); 1178 sbuf_printf(sb, "SigCgt:\t%016jx\n", sigcatch.__mask); 1179 1180 /* 1181 * Linux also prints the capability masks, but we don't have 1182 * capabilities yet, and when we do get them they're likely to 1183 * be meaningless to Linux programs, so we lie. XXX 1184 */ 1185 sbuf_printf(sb, "CapInh:\t%016x\n", 0); 1186 sbuf_printf(sb, "CapPrm:\t%016x\n", 0); 1187 sbuf_printf(sb, "CapEff:\t%016x\n", 0); 1188 1189 return (0); 1190 } 1191 1192 /* 1193 * Filler function for proc/pid/cwd 1194 */ 1195 static int 1196 linprocfs_doproccwd(PFS_FILL_ARGS) 1197 { 1198 struct pwd *pwd; 1199 char *fullpath = "unknown"; 1200 char *freepath = NULL; 1201 1202 pwd = pwd_hold_proc(p); 1203 vn_fullpath(pwd->pwd_cdir, &fullpath, &freepath); 1204 sbuf_printf(sb, "%s", fullpath); 1205 if (freepath) 1206 free(freepath, M_TEMP); 1207 pwd_drop(pwd); 1208 return (0); 1209 } 1210 1211 /* 1212 * Filler function for proc/pid/root 1213 */ 1214 static int 1215 linprocfs_doprocroot(PFS_FILL_ARGS) 1216 { 1217 struct pwd *pwd; 1218 struct vnode *vp; 1219 char *fullpath = "unknown"; 1220 char *freepath = NULL; 1221 1222 pwd = pwd_hold_proc(p); 1223 vp = jailed(p->p_ucred) ? pwd->pwd_jdir : pwd->pwd_rdir; 1224 vn_fullpath(vp, &fullpath, &freepath); 1225 sbuf_printf(sb, "%s", fullpath); 1226 if (freepath) 1227 free(freepath, M_TEMP); 1228 pwd_drop(pwd); 1229 return (0); 1230 } 1231 1232 /* 1233 * Filler function for proc/pid/cmdline 1234 */ 1235 static int 1236 linprocfs_doproccmdline(PFS_FILL_ARGS) 1237 { 1238 int ret; 1239 1240 PROC_LOCK(p); 1241 if ((ret = p_cansee(td, p)) != 0) { 1242 PROC_UNLOCK(p); 1243 return (ret); 1244 } 1245 1246 /* 1247 * Mimic linux behavior and pass only processes with usermode 1248 * address space as valid. Return zero silently otherwize. 1249 */ 1250 if (p->p_vmspace == &vmspace0) { 1251 PROC_UNLOCK(p); 1252 return (0); 1253 } 1254 if (p->p_args != NULL) { 1255 sbuf_bcpy(sb, p->p_args->ar_args, p->p_args->ar_length); 1256 PROC_UNLOCK(p); 1257 return (0); 1258 } 1259 1260 if ((p->p_flag & P_SYSTEM) != 0) { 1261 PROC_UNLOCK(p); 1262 return (0); 1263 } 1264 1265 PROC_UNLOCK(p); 1266 1267 ret = proc_getargv(td, p, sb); 1268 return (ret); 1269 } 1270 1271 /* 1272 * Filler function for proc/pid/environ 1273 */ 1274 static int 1275 linprocfs_doprocenviron(PFS_FILL_ARGS) 1276 { 1277 1278 /* 1279 * Mimic linux behavior and pass only processes with usermode 1280 * address space as valid. Return zero silently otherwize. 1281 */ 1282 if (p->p_vmspace == &vmspace0) 1283 return (0); 1284 1285 return (proc_getenvv(td, p, sb)); 1286 } 1287 1288 static char l32_map_str[] = "%08lx-%08lx %s%s%s%s %08lx %02x:%02x %lu%s%s\n"; 1289 static char l64_map_str[] = "%016lx-%016lx %s%s%s%s %08lx %02x:%02x %lu%s%s\n"; 1290 static char vdso_str[] = " [vdso]"; 1291 static char stack_str[] = " [stack]"; 1292 1293 /* 1294 * Filler function for proc/pid/maps 1295 */ 1296 static int 1297 linprocfs_doprocmaps(PFS_FILL_ARGS) 1298 { 1299 struct vmspace *vm; 1300 vm_map_t map; 1301 vm_map_entry_t entry, tmp_entry; 1302 vm_object_t obj, tobj, lobj; 1303 vm_offset_t e_start, e_end; 1304 vm_ooffset_t off; 1305 vm_prot_t e_prot; 1306 unsigned int last_timestamp; 1307 char *name = "", *freename = NULL; 1308 const char *l_map_str; 1309 ino_t ino; 1310 int error; 1311 struct vnode *vp; 1312 struct vattr vat; 1313 bool private; 1314 1315 if (uio->uio_rw != UIO_READ) 1316 return (EOPNOTSUPP); 1317 1318 error = proc_vmspace_ref(td, p, PRVM_BLOCK_EXEC | PRVM_CHECK_DEBUG, 1319 &vm); 1320 if (error != 0) 1321 return (error); 1322 1323 if (SV_CURPROC_FLAG(SV_LP64)) 1324 l_map_str = l64_map_str; 1325 else 1326 l_map_str = l32_map_str; 1327 map = &vm->vm_map; 1328 vm_map_lock_read(map); 1329 VM_MAP_ENTRY_FOREACH(entry, map) { 1330 name = ""; 1331 freename = NULL; 1332 /* 1333 * Skip printing of the guard page of the stack region, as 1334 * it confuses glibc pthread_getattr_np() method, where both 1335 * the base address and size of the stack of the initial thread 1336 * are calculated. 1337 */ 1338 if ((entry->eflags & (MAP_ENTRY_IS_SUB_MAP | MAP_ENTRY_GUARD)) != 0) 1339 continue; 1340 e_prot = entry->protection; 1341 e_start = entry->start; 1342 e_end = entry->end; 1343 obj = entry->object.vm_object; 1344 off = entry->offset; 1345 for (lobj = tobj = obj; tobj != NULL; 1346 lobj = tobj, tobj = tobj->backing_object) { 1347 VM_OBJECT_RLOCK(tobj); 1348 off += lobj->backing_object_offset; 1349 if (lobj != obj) 1350 VM_OBJECT_RUNLOCK(lobj); 1351 } 1352 private = (entry->eflags & MAP_ENTRY_COW) != 0 || obj == NULL || 1353 (obj->flags & OBJ_ANON) != 0; 1354 last_timestamp = map->timestamp; 1355 vm_map_unlock_read(map); 1356 ino = 0; 1357 if (lobj) { 1358 vp = vm_object_vnode(lobj); 1359 if (vp != NULL) 1360 vref(vp); 1361 if (lobj != obj) 1362 VM_OBJECT_RUNLOCK(lobj); 1363 VM_OBJECT_RUNLOCK(obj); 1364 if (vp != NULL) { 1365 vn_fullpath(vp, &name, &freename); 1366 vn_lock(vp, LK_SHARED | LK_RETRY); 1367 VOP_GETATTR(vp, &vat, td->td_ucred); 1368 ino = vat.va_fileid; 1369 vput(vp); 1370 } else if (SV_PROC_ABI(p) == SV_ABI_LINUX) { 1371 /* 1372 * sv_shared_page_base pointed out to the 1373 * FreeBSD sharedpage, PAGE_SIZE is a size 1374 * of it. The vDSO page is above. 1375 */ 1376 if (e_start == p->p_sysent->sv_shared_page_base + 1377 PAGE_SIZE) 1378 name = vdso_str; 1379 if (e_end == p->p_sysent->sv_usrstack) 1380 name = stack_str; 1381 } 1382 } 1383 1384 /* 1385 * format: 1386 * start, end, access, offset, major, minor, inode, name. 1387 */ 1388 error = sbuf_printf(sb, l_map_str, 1389 (u_long)e_start, (u_long)e_end, 1390 (e_prot & VM_PROT_READ)?"r":"-", 1391 (e_prot & VM_PROT_WRITE)?"w":"-", 1392 (e_prot & VM_PROT_EXECUTE)?"x":"-", 1393 private ? "p" : "s", 1394 (u_long)off, 1395 0, 1396 0, 1397 (u_long)ino, 1398 *name ? " " : " ", 1399 name 1400 ); 1401 if (freename) 1402 free(freename, M_TEMP); 1403 vm_map_lock_read(map); 1404 if (error == -1) { 1405 error = 0; 1406 break; 1407 } 1408 if (last_timestamp != map->timestamp) { 1409 /* 1410 * Look again for the entry because the map was 1411 * modified while it was unlocked. Specifically, 1412 * the entry may have been clipped, merged, or deleted. 1413 */ 1414 vm_map_lookup_entry(map, e_end - 1, &tmp_entry); 1415 entry = tmp_entry; 1416 } 1417 } 1418 vm_map_unlock_read(map); 1419 proc_vmspace_unref(td, p, PRVM_CHECK_DEBUG | PRVM_BLOCK_EXEC, vm); 1420 1421 return (error); 1422 } 1423 1424 /* 1425 * Filler function for proc/pid/mem 1426 */ 1427 static int 1428 linprocfs_doprocmem(PFS_FILL_ARGS) 1429 { 1430 ssize_t resid; 1431 int error; 1432 1433 resid = uio->uio_resid; 1434 error = procfs_doprocmem(PFS_FILL_ARGNAMES); 1435 1436 if (uio->uio_rw == UIO_READ && resid != uio->uio_resid) 1437 return (0); 1438 1439 if (error == EFAULT) 1440 error = EIO; 1441 1442 return (error); 1443 } 1444 1445 /* 1446 * Filler function for proc/net/dev 1447 */ 1448 static int 1449 linprocfs_donetdev_cb(if_t ifp, void *arg) 1450 { 1451 char ifname[LINUX_IFNAMSIZ]; 1452 struct sbuf *sb = arg; 1453 1454 if (ifname_bsd_to_linux_ifp(ifp, ifname, sizeof(ifname)) <= 0) 1455 return (ENODEV); 1456 1457 sbuf_printf(sb, "%6.6s: ", ifname); 1458 sbuf_printf(sb, "%7ju %7ju %4ju %4ju %4lu %5lu %10lu %9ju ", 1459 (uintmax_t)if_getcounter(ifp, IFCOUNTER_IBYTES), 1460 (uintmax_t)if_getcounter(ifp, IFCOUNTER_IPACKETS), 1461 (uintmax_t)if_getcounter(ifp, IFCOUNTER_IERRORS), 1462 (uintmax_t)if_getcounter(ifp, IFCOUNTER_IQDROPS), 1463 /* rx_missed_errors */ 1464 0UL, /* rx_fifo_errors */ 1465 0UL, /* rx_length_errors + 1466 * rx_over_errors + 1467 * rx_crc_errors + 1468 * rx_frame_errors */ 1469 0UL, /* rx_compressed */ 1470 (uintmax_t)if_getcounter(ifp, IFCOUNTER_IMCASTS)); 1471 /* XXX-BZ rx only? */ 1472 sbuf_printf(sb, "%8ju %7ju %4ju %4ju %4lu %5ju %7lu %10lu\n", 1473 (uintmax_t)if_getcounter(ifp, IFCOUNTER_OBYTES), 1474 (uintmax_t)if_getcounter(ifp, IFCOUNTER_OPACKETS), 1475 (uintmax_t)if_getcounter(ifp, IFCOUNTER_OERRORS), 1476 (uintmax_t)if_getcounter(ifp, IFCOUNTER_OQDROPS), 1477 0UL, /* tx_fifo_errors */ 1478 (uintmax_t)if_getcounter(ifp, IFCOUNTER_COLLISIONS), 1479 0UL, /* tx_carrier_errors + 1480 * tx_aborted_errors + 1481 * tx_window_errors + 1482 * tx_heartbeat_errors*/ 1483 0UL); /* tx_compressed */ 1484 return (0); 1485 } 1486 1487 static int 1488 linprocfs_donetdev(PFS_FILL_ARGS) 1489 { 1490 struct epoch_tracker et; 1491 1492 sbuf_printf(sb, "%6s|%58s|%s\n" 1493 "%6s|%58s|%58s\n", 1494 "Inter-", " Receive", " Transmit", 1495 " face", 1496 "bytes packets errs drop fifo frame compressed multicast", 1497 "bytes packets errs drop fifo colls carrier compressed"); 1498 1499 CURVNET_SET(TD_TO_VNET(curthread)); 1500 NET_EPOCH_ENTER(et); 1501 if_foreach(linprocfs_donetdev_cb, sb); 1502 NET_EPOCH_EXIT(et); 1503 CURVNET_RESTORE(); 1504 1505 return (0); 1506 } 1507 1508 struct walkarg { 1509 struct sbuf *sb; 1510 }; 1511 1512 static int 1513 linux_route_print(struct rtentry *rt, void *vw) 1514 { 1515 #ifdef INET 1516 struct walkarg *w = vw; 1517 struct route_nhop_data rnd; 1518 struct in_addr dst, mask; 1519 struct nhop_object *nh; 1520 char ifname[16]; 1521 uint32_t scopeid = 0; 1522 uint32_t gw = 0; 1523 uint32_t linux_flags = 0; 1524 1525 rt_get_inet_prefix_pmask(rt, &dst, &mask, &scopeid); 1526 1527 rt_get_rnd(rt, &rnd); 1528 1529 /* select only first route in case of multipath */ 1530 nh = nhop_select_func(rnd.rnd_nhop, 0); 1531 1532 if (ifname_bsd_to_linux_ifp(nh->nh_ifp, ifname, sizeof(ifname)) <= 0) 1533 return (ENODEV); 1534 1535 gw = (nh->nh_flags & NHF_GATEWAY) 1536 ? nh->gw4_sa.sin_addr.s_addr : 0; 1537 1538 linux_flags = RTF_UP | 1539 (nhop_get_rtflags(nh) & (RTF_GATEWAY | RTF_HOST)); 1540 1541 sbuf_printf(w->sb, 1542 "%s\t" 1543 "%08X\t%08X\t%04X\t" 1544 "%d\t%u\t%d\t" 1545 "%08X\t%d\t%u\t%u", 1546 ifname, 1547 dst.s_addr, gw, linux_flags, 1548 0, 0, rnd.rnd_weight, 1549 mask.s_addr, nh->nh_mtu, 0, 0); 1550 1551 sbuf_printf(w->sb, "\n\n"); 1552 #endif 1553 return (0); 1554 } 1555 1556 /* 1557 * Filler function for proc/net/route 1558 */ 1559 static int 1560 linprocfs_donetroute(PFS_FILL_ARGS) 1561 { 1562 struct epoch_tracker et; 1563 struct walkarg w = { 1564 .sb = sb 1565 }; 1566 uint32_t fibnum = curthread->td_proc->p_fibnum; 1567 1568 sbuf_printf(w.sb, "%-127s\n", "Iface\tDestination\tGateway " 1569 "\tFlags\tRefCnt\tUse\tMetric\tMask\t\tMTU" 1570 "\tWindow\tIRTT"); 1571 1572 CURVNET_SET(TD_TO_VNET(curthread)); 1573 NET_EPOCH_ENTER(et); 1574 rib_walk(fibnum, AF_INET, false, linux_route_print, &w); 1575 NET_EPOCH_EXIT(et); 1576 CURVNET_RESTORE(); 1577 1578 return (0); 1579 } 1580 1581 /* 1582 * Filler function for proc/sys/kernel/osrelease 1583 */ 1584 static int 1585 linprocfs_doosrelease(PFS_FILL_ARGS) 1586 { 1587 char osrelease[LINUX_MAX_UTSNAME]; 1588 1589 linux_get_osrelease(td, osrelease); 1590 sbuf_printf(sb, "%s\n", osrelease); 1591 1592 return (0); 1593 } 1594 1595 /* 1596 * Filler function for proc/sys/kernel/ostype 1597 */ 1598 static int 1599 linprocfs_doostype(PFS_FILL_ARGS) 1600 { 1601 char osname[LINUX_MAX_UTSNAME]; 1602 1603 linux_get_osname(td, osname); 1604 sbuf_printf(sb, "%s\n", osname); 1605 1606 return (0); 1607 } 1608 1609 /* 1610 * Filler function for proc/sys/kernel/version 1611 */ 1612 static int 1613 linprocfs_doosbuild(PFS_FILL_ARGS) 1614 { 1615 1616 linprocfs_osbuild(td, sb); 1617 sbuf_cat(sb, "\n"); 1618 return (0); 1619 } 1620 1621 /* 1622 * Filler function for proc/sys/kernel/msgmax 1623 */ 1624 static int 1625 linprocfs_domsgmax(PFS_FILL_ARGS) 1626 { 1627 1628 sbuf_printf(sb, "%d\n", msginfo.msgmax); 1629 return (0); 1630 } 1631 1632 /* 1633 * Filler function for proc/sys/kernel/msgmni 1634 */ 1635 static int 1636 linprocfs_domsgmni(PFS_FILL_ARGS) 1637 { 1638 1639 sbuf_printf(sb, "%d\n", msginfo.msgmni); 1640 return (0); 1641 } 1642 1643 /* 1644 * Filler function for proc/sys/kernel/msgmnb 1645 */ 1646 static int 1647 linprocfs_domsgmnb(PFS_FILL_ARGS) 1648 { 1649 1650 sbuf_printf(sb, "%d\n", msginfo.msgmnb); 1651 return (0); 1652 } 1653 1654 /* 1655 * Filler function for proc/sys/kernel/ngroups_max 1656 * 1657 * Note that in Linux it defaults to 65536, not 1023. 1658 */ 1659 static int 1660 linprocfs_dongroups_max(PFS_FILL_ARGS) 1661 { 1662 1663 sbuf_printf(sb, "%d\n", ngroups_max); 1664 return (0); 1665 } 1666 1667 /* 1668 * Filler function for proc/sys/kernel/pid_max 1669 */ 1670 static int 1671 linprocfs_dopid_max(PFS_FILL_ARGS) 1672 { 1673 1674 sbuf_printf(sb, "%i\n", PID_MAX); 1675 return (0); 1676 } 1677 1678 /* 1679 * Filler function for proc/sys/kernel/sem 1680 */ 1681 static int 1682 linprocfs_dosem(PFS_FILL_ARGS) 1683 { 1684 1685 sbuf_printf(sb, "%d %d %d %d\n", seminfo.semmsl, seminfo.semmns, 1686 seminfo.semopm, seminfo.semmni); 1687 return (0); 1688 } 1689 1690 /* 1691 * Filler function for proc/sys/kernel/shmall 1692 */ 1693 static int 1694 linprocfs_doshmall(PFS_FILL_ARGS) 1695 { 1696 1697 sbuf_printf(sb, "%lu\n", shminfo.shmall); 1698 return (0); 1699 } 1700 1701 /* 1702 * Filler function for proc/sys/kernel/shmmax 1703 */ 1704 static int 1705 linprocfs_doshmmax(PFS_FILL_ARGS) 1706 { 1707 1708 sbuf_printf(sb, "%lu\n", shminfo.shmmax); 1709 return (0); 1710 } 1711 1712 /* 1713 * Filler function for proc/sys/kernel/shmmni 1714 */ 1715 static int 1716 linprocfs_doshmmni(PFS_FILL_ARGS) 1717 { 1718 1719 sbuf_printf(sb, "%lu\n", shminfo.shmmni); 1720 return (0); 1721 } 1722 1723 /* 1724 * Filler function for proc/sys/kernel/tainted 1725 */ 1726 static int 1727 linprocfs_dotainted(PFS_FILL_ARGS) 1728 { 1729 1730 sbuf_printf(sb, "0\n"); 1731 return (0); 1732 } 1733 1734 /* 1735 * Filler function for proc/sys/kernel/threads-max 1736 */ 1737 static int 1738 linprocfs_dothreads_max(PFS_FILL_ARGS) 1739 { 1740 int res, error; 1741 size_t size = sizeof(res); 1742 1743 error = kernel_sysctlbyname(curthread, "kern.maxproc", 1744 &res, &size, NULL, 0, 0, 0); 1745 if (error != 0) 1746 return (error); 1747 sbuf_printf(sb, "%d\n", res); 1748 return (0); 1749 } 1750 1751 /* 1752 * Filler function for proc/sys/vm/min_free_kbytes 1753 * 1754 * This mirrors the approach in illumos to return zero for reads. Effectively, 1755 * it says, no memory is kept in reserve for "atomic allocations". This class 1756 * of allocation can be used at times when a thread cannot be suspended. 1757 */ 1758 static int 1759 linprocfs_dominfree(PFS_FILL_ARGS) 1760 { 1761 1762 sbuf_printf(sb, "%d\n", 0); 1763 return (0); 1764 } 1765 1766 /* 1767 * Filler function for proc/scsi/device_info 1768 */ 1769 static int 1770 linprocfs_doscsidevinfo(PFS_FILL_ARGS) 1771 { 1772 1773 return (0); 1774 } 1775 1776 /* 1777 * Filler function for proc/scsi/scsi 1778 */ 1779 static int 1780 linprocfs_doscsiscsi(PFS_FILL_ARGS) 1781 { 1782 1783 return (0); 1784 } 1785 1786 /* 1787 * Filler function for proc/devices 1788 */ 1789 static int 1790 linprocfs_dodevices(PFS_FILL_ARGS) 1791 { 1792 char *char_devices; 1793 sbuf_printf(sb, "Character devices:\n"); 1794 1795 char_devices = linux_get_char_devices(); 1796 sbuf_printf(sb, "%s", char_devices); 1797 linux_free_get_char_devices(char_devices); 1798 1799 sbuf_printf(sb, "\nBlock devices:\n"); 1800 1801 return (0); 1802 } 1803 1804 /* 1805 * Filler function for proc/cmdline 1806 */ 1807 static int 1808 linprocfs_docmdline(PFS_FILL_ARGS) 1809 { 1810 1811 sbuf_printf(sb, "BOOT_IMAGE=%s", kernelname); 1812 sbuf_printf(sb, " ro root=302\n"); 1813 return (0); 1814 } 1815 1816 /* 1817 * Filler function for proc/filesystems 1818 */ 1819 static int 1820 linprocfs_dofilesystems(PFS_FILL_ARGS) 1821 { 1822 struct vfsconf *vfsp; 1823 1824 vfsconf_slock(); 1825 TAILQ_FOREACH(vfsp, &vfsconf, vfc_list) { 1826 if (vfsp->vfc_flags & VFCF_SYNTHETIC) 1827 sbuf_printf(sb, "nodev"); 1828 sbuf_printf(sb, "\t%s\n", vfsp->vfc_name); 1829 } 1830 vfsconf_sunlock(); 1831 return(0); 1832 } 1833 1834 /* 1835 * Filler function for proc/modules 1836 */ 1837 static int 1838 linprocfs_domodules(PFS_FILL_ARGS) 1839 { 1840 #if 0 1841 struct linker_file *lf; 1842 1843 TAILQ_FOREACH(lf, &linker_files, link) { 1844 sbuf_printf(sb, "%-20s%8lu%4d\n", lf->filename, 1845 (unsigned long)lf->size, lf->refs); 1846 } 1847 #endif 1848 return (0); 1849 } 1850 1851 /* 1852 * Filler function for proc/pid/fd 1853 */ 1854 static int 1855 linprocfs_dofdescfs(PFS_FILL_ARGS) 1856 { 1857 1858 if (p == curproc) 1859 sbuf_printf(sb, "/dev/fd"); 1860 else 1861 sbuf_printf(sb, "unknown"); 1862 return (0); 1863 } 1864 1865 /* 1866 * Filler function for proc/pid/limits 1867 */ 1868 static const struct linux_rlimit_ident { 1869 const char *desc; 1870 const char *unit; 1871 unsigned int rlim_id; 1872 } linux_rlimits_ident[] = { 1873 { "Max cpu time", "seconds", RLIMIT_CPU }, 1874 { "Max file size", "bytes", RLIMIT_FSIZE }, 1875 { "Max data size", "bytes", RLIMIT_DATA }, 1876 { "Max stack size", "bytes", RLIMIT_STACK }, 1877 { "Max core file size", "bytes", RLIMIT_CORE }, 1878 { "Max resident set", "bytes", RLIMIT_RSS }, 1879 { "Max processes", "processes", RLIMIT_NPROC }, 1880 { "Max open files", "files", RLIMIT_NOFILE }, 1881 { "Max locked memory", "bytes", RLIMIT_MEMLOCK }, 1882 { "Max address space", "bytes", RLIMIT_AS }, 1883 { "Max file locks", "locks", LINUX_RLIMIT_LOCKS }, 1884 { "Max pending signals", "signals", LINUX_RLIMIT_SIGPENDING }, 1885 { "Max msgqueue size", "bytes", LINUX_RLIMIT_MSGQUEUE }, 1886 { "Max nice priority", "", LINUX_RLIMIT_NICE }, 1887 { "Max realtime priority", "", LINUX_RLIMIT_RTPRIO }, 1888 { "Max realtime timeout", "us", LINUX_RLIMIT_RTTIME }, 1889 { 0, 0, 0 } 1890 }; 1891 1892 static int 1893 linprocfs_doproclimits(PFS_FILL_ARGS) 1894 { 1895 const struct linux_rlimit_ident *li; 1896 struct plimit *limp; 1897 struct rlimit rl; 1898 ssize_t size; 1899 int res, error; 1900 1901 error = 0; 1902 1903 PROC_LOCK(p); 1904 limp = lim_hold(p->p_limit); 1905 PROC_UNLOCK(p); 1906 size = sizeof(res); 1907 sbuf_printf(sb, "%-26s%-21s%-21s%-21s\n", "Limit", "Soft Limit", 1908 "Hard Limit", "Units"); 1909 for (li = linux_rlimits_ident; li->desc != NULL; ++li) { 1910 switch (li->rlim_id) 1911 { 1912 case LINUX_RLIMIT_LOCKS: 1913 /* FALLTHROUGH */ 1914 case LINUX_RLIMIT_RTTIME: 1915 rl.rlim_cur = RLIM_INFINITY; 1916 break; 1917 case LINUX_RLIMIT_SIGPENDING: 1918 error = kernel_sysctlbyname(td, 1919 "kern.sigqueue.max_pending_per_proc", 1920 &res, &size, 0, 0, 0, 0); 1921 if (error != 0) 1922 continue; 1923 rl.rlim_cur = res; 1924 rl.rlim_max = res; 1925 break; 1926 case LINUX_RLIMIT_MSGQUEUE: 1927 error = kernel_sysctlbyname(td, 1928 "kern.ipc.msgmnb", &res, &size, 0, 0, 0, 0); 1929 if (error != 0) 1930 continue; 1931 rl.rlim_cur = res; 1932 rl.rlim_max = res; 1933 break; 1934 case LINUX_RLIMIT_NICE: 1935 /* FALLTHROUGH */ 1936 case LINUX_RLIMIT_RTPRIO: 1937 rl.rlim_cur = 0; 1938 rl.rlim_max = 0; 1939 break; 1940 default: 1941 rl = limp->pl_rlimit[li->rlim_id]; 1942 break; 1943 } 1944 if (rl.rlim_cur == RLIM_INFINITY) 1945 sbuf_printf(sb, "%-26s%-21s%-21s%-10s\n", 1946 li->desc, "unlimited", "unlimited", li->unit); 1947 else 1948 sbuf_printf(sb, "%-26s%-21llu%-21llu%-10s\n", 1949 li->desc, (unsigned long long)rl.rlim_cur, 1950 (unsigned long long)rl.rlim_max, li->unit); 1951 } 1952 1953 lim_free(limp); 1954 return (0); 1955 } 1956 1957 /* 1958 * The point of the following two functions is to work around 1959 * an assertion in Chromium; see kern/240991 for details. 1960 */ 1961 static int 1962 linprocfs_dotaskattr(PFS_ATTR_ARGS) 1963 { 1964 1965 vap->va_nlink = 3; 1966 return (0); 1967 } 1968 1969 /* 1970 * Filler function for proc/<pid>/task/.dummy 1971 */ 1972 static int 1973 linprocfs_dotaskdummy(PFS_FILL_ARGS) 1974 { 1975 1976 return (0); 1977 } 1978 1979 /* 1980 * Filler function for proc/sys/kernel/random/uuid 1981 */ 1982 static int 1983 linprocfs_douuid(PFS_FILL_ARGS) 1984 { 1985 struct uuid uuid; 1986 1987 kern_uuidgen(&uuid, 1); 1988 sbuf_printf_uuid(sb, &uuid); 1989 sbuf_printf(sb, "\n"); 1990 return(0); 1991 } 1992 1993 /* 1994 * Filler function for proc/sys/kernel/random/boot_id 1995 */ 1996 static int 1997 linprocfs_doboot_id(PFS_FILL_ARGS) 1998 { 1999 static bool firstboot = 1; 2000 static struct uuid uuid; 2001 2002 if (firstboot) { 2003 kern_uuidgen(&uuid, 1); 2004 firstboot = 0; 2005 } 2006 sbuf_printf_uuid(sb, &uuid); 2007 sbuf_printf(sb, "\n"); 2008 return(0); 2009 } 2010 2011 /* 2012 * Filler function for proc/pid/auxv 2013 */ 2014 static int 2015 linprocfs_doauxv(PFS_FILL_ARGS) 2016 { 2017 struct sbuf *asb; 2018 off_t buflen, resid; 2019 int error; 2020 2021 /* 2022 * Mimic linux behavior and pass only processes with usermode 2023 * address space as valid. Return zero silently otherwise. 2024 */ 2025 if (p->p_vmspace == &vmspace0) 2026 return (0); 2027 2028 if (uio->uio_resid == 0) 2029 return (0); 2030 if (uio->uio_offset < 0 || uio->uio_resid < 0) 2031 return (EINVAL); 2032 2033 asb = sbuf_new_auto(); 2034 if (asb == NULL) 2035 return (ENOMEM); 2036 error = proc_getauxv(td, p, asb); 2037 if (error != 0) 2038 goto out; 2039 error = sbuf_finish(asb); 2040 if (error != 0) 2041 goto out; 2042 2043 resid = sbuf_len(asb) - uio->uio_offset; 2044 if (resid > uio->uio_resid) 2045 buflen = uio->uio_resid; 2046 else 2047 buflen = resid; 2048 if (buflen > IOSIZE_MAX) { 2049 error = EINVAL; 2050 goto out; 2051 } 2052 if (buflen > maxphys) 2053 buflen = maxphys; 2054 if (resid > 0) 2055 error = uiomove(sbuf_data(asb) + uio->uio_offset, buflen, uio); 2056 out: 2057 sbuf_delete(asb); 2058 return (error); 2059 } 2060 2061 /* 2062 * Filler function for proc/self/oom_score_adj 2063 */ 2064 static int 2065 linprocfs_do_oom_score_adj(PFS_FILL_ARGS) 2066 { 2067 struct linux_pemuldata *pem; 2068 long oom; 2069 2070 pem = pem_find(p); 2071 if (pem == NULL || uio == NULL) 2072 return (EOPNOTSUPP); 2073 if (uio->uio_rw == UIO_READ) { 2074 sbuf_printf(sb, "%d\n", pem->oom_score_adj); 2075 } else { 2076 sbuf_trim(sb); 2077 sbuf_finish(sb); 2078 oom = strtol(sbuf_data(sb), NULL, 10); 2079 if (oom < LINUX_OOM_SCORE_ADJ_MIN || 2080 oom > LINUX_OOM_SCORE_ADJ_MAX) 2081 return (EINVAL); 2082 pem->oom_score_adj = oom; 2083 } 2084 return (0); 2085 } 2086 2087 /* 2088 * Filler function for proc/sys/vm/max_map_count 2089 * 2090 * Maximum number of active map areas, on Linux this limits the number 2091 * of vmaps per mm struct. We don't limit mappings, return a suitable 2092 * large value. 2093 */ 2094 static int 2095 linprocfs_domax_map_cnt(PFS_FILL_ARGS) 2096 { 2097 2098 sbuf_printf(sb, "%d\n", INT32_MAX); 2099 return (0); 2100 } 2101 2102 /* 2103 * Filler function for proc/sysvipc/msg 2104 */ 2105 static int 2106 linprocfs_dosysvipc_msg(PFS_FILL_ARGS) 2107 { 2108 struct msqid_kernel *msqids; 2109 size_t id, size; 2110 int error; 2111 2112 sbuf_printf(sb, 2113 "%10s %10s %4s %10s %10s %5s %5s %5s %5s %5s %5s %10s %10s %10s\n", 2114 "key", "msqid", "perms", "cbytes", "qnum", "lspid", "lrpid", 2115 "uid", "gid", "cuid", "cgid", "stime", "rtime", "ctime"); 2116 2117 error = kern_get_msqids(curthread, &msqids, &size); 2118 if (error != 0) 2119 return (error); 2120 2121 for (id = 0; id < size; id++) { 2122 if (msqids[id].u.msg_qbytes == 0) 2123 continue; 2124 sbuf_printf(sb, 2125 "%10d %10zu %4o %10lu %10lu %5u %5u %5u %5u %5u %5u %jd %jd %jd\n", 2126 (int)msqids[id].u.msg_perm.key, 2127 IXSEQ_TO_IPCID(id, msqids[id].u.msg_perm), 2128 msqids[id].u.msg_perm.mode, 2129 msqids[id].u.msg_cbytes, 2130 msqids[id].u.msg_qnum, 2131 msqids[id].u.msg_lspid, 2132 msqids[id].u.msg_lrpid, 2133 msqids[id].u.msg_perm.uid, 2134 msqids[id].u.msg_perm.gid, 2135 msqids[id].u.msg_perm.cuid, 2136 msqids[id].u.msg_perm.cgid, 2137 (intmax_t)msqids[id].u.msg_stime, 2138 (intmax_t)msqids[id].u.msg_rtime, 2139 (intmax_t)msqids[id].u.msg_ctime); 2140 } 2141 2142 free(msqids, M_TEMP); 2143 return (0); 2144 } 2145 2146 /* 2147 * Filler function for proc/sysvipc/sem 2148 */ 2149 static int 2150 linprocfs_dosysvipc_sem(PFS_FILL_ARGS) 2151 { 2152 struct semid_kernel *semids; 2153 size_t id, size; 2154 int error; 2155 2156 sbuf_printf(sb, "%10s %10s %4s %10s %5s %5s %5s %5s %10s %10s\n", 2157 "key", "semid", "perms", "nsems", "uid", "gid", "cuid", "cgid", 2158 "otime", "ctime"); 2159 2160 error = kern_get_sema(curthread, &semids, &size); 2161 if (error != 0) 2162 return (error); 2163 2164 for (id = 0; id < size; id++) { 2165 if ((semids[id].u.sem_perm.mode & SEM_ALLOC) == 0) 2166 continue; 2167 sbuf_printf(sb, 2168 "%10d %10zu %4o %10u %5u %5u %5u %5u %jd %jd\n", 2169 (int)semids[id].u.sem_perm.key, 2170 IXSEQ_TO_IPCID(id, semids[id].u.sem_perm), 2171 semids[id].u.sem_perm.mode, 2172 semids[id].u.sem_nsems, 2173 semids[id].u.sem_perm.uid, 2174 semids[id].u.sem_perm.gid, 2175 semids[id].u.sem_perm.cuid, 2176 semids[id].u.sem_perm.cgid, 2177 (intmax_t)semids[id].u.sem_otime, 2178 (intmax_t)semids[id].u.sem_ctime); 2179 } 2180 2181 free(semids, M_TEMP); 2182 return (0); 2183 } 2184 2185 /* 2186 * Filler function for proc/sysvipc/shm 2187 */ 2188 static int 2189 linprocfs_dosysvipc_shm(PFS_FILL_ARGS) 2190 { 2191 struct shmid_kernel *shmids; 2192 size_t id, size; 2193 int error; 2194 2195 sbuf_printf(sb, 2196 "%10s %10s %s %21s %5s %5s %5s %5s %5s %5s %5s %10s %10s %10s %21s %21s\n", 2197 "key", "shmid", "perms", "size", "cpid", "lpid", "nattch", "uid", 2198 "gid", "cuid", "cgid", "atime", "dtime", "ctime", "rss", "swap"); 2199 2200 error = kern_get_shmsegs(curthread, &shmids, &size); 2201 if (error != 0) 2202 return (error); 2203 2204 for (id = 0; id < size; id++) { 2205 if ((shmids[id].u.shm_perm.mode & SHMSEG_ALLOCATED) == 0) 2206 continue; 2207 sbuf_printf(sb, 2208 "%10d %10zu %4o %21zu %5u %5u %5u %5u %5u %5u %5u %jd %jd %jd %21d %21d\n", 2209 (int)shmids[id].u.shm_perm.key, 2210 IXSEQ_TO_IPCID(id, shmids[id].u.shm_perm), 2211 shmids[id].u.shm_perm.mode, 2212 shmids[id].u.shm_segsz, 2213 shmids[id].u.shm_cpid, 2214 shmids[id].u.shm_lpid, 2215 shmids[id].u.shm_nattch, 2216 shmids[id].u.shm_perm.uid, 2217 shmids[id].u.shm_perm.gid, 2218 shmids[id].u.shm_perm.cuid, 2219 shmids[id].u.shm_perm.cgid, 2220 (intmax_t)shmids[id].u.shm_atime, 2221 (intmax_t)shmids[id].u.shm_dtime, 2222 (intmax_t)shmids[id].u.shm_ctime, 2223 0, 0); /* XXX rss & swp are not supported */ 2224 } 2225 2226 free(shmids, M_TEMP); 2227 return (0); 2228 } 2229 2230 /* 2231 * Filler function for proc/sys/fs/file-max 2232 */ 2233 static int 2234 linprocfs_dofile_max(PFS_FILL_ARGS) 2235 { 2236 int res, error; 2237 size_t size = sizeof(res); 2238 2239 error = kernel_sysctlbyname(curthread, "kern.maxfiles", 2240 &res, &size, NULL, 0, 0, 0); 2241 if (error != 0) 2242 return (error); 2243 sbuf_printf(sb, "%d\n", res); 2244 return (0); 2245 } 2246 2247 /* 2248 * Filler function for proc/sys/fs/file-nr 2249 */ 2250 static int 2251 linprocfs_dofile_nr(PFS_FILL_ARGS) 2252 { 2253 int openfiles, maxfiles, error; 2254 size_t size; 2255 2256 size = sizeof(openfiles); 2257 error = kernel_sysctlbyname(curthread, "kern.openfiles", 2258 &openfiles, &size, NULL, 0, 0, 0); 2259 if (error != 0) 2260 return (error); 2261 size = sizeof(maxfiles); 2262 error = kernel_sysctlbyname(curthread, "kern.maxfiles", 2263 &maxfiles, &size, NULL, 0, 0, 0); 2264 if (error != 0) 2265 return (error); 2266 /* 2267 * From Linux's proc_sys_fs(5): 2268 * the "free file handles" value is always zero. 2269 */ 2270 sbuf_printf(sb, "%d\t0\t%d\n", openfiles, maxfiles); 2271 return (0); 2272 } 2273 2274 /* 2275 * Filler function for proc/sys/fs/nr_open 2276 */ 2277 static int 2278 linprocfs_donr_open(PFS_FILL_ARGS) 2279 { 2280 int res, error; 2281 size_t size = sizeof(res); 2282 2283 error = kernel_sysctlbyname(curthread, "kern.maxfilesperproc", 2284 &res, &size, NULL, 0, 0, 0); 2285 if (error != 0) 2286 return (error); 2287 sbuf_printf(sb, "%d\n", res); 2288 return (0); 2289 } 2290 2291 /* 2292 * Filler function for proc/sys/fs/overflowuid 2293 */ 2294 static int 2295 linprocfs_dooverflowuid(PFS_FILL_ARGS) 2296 { 2297 sbuf_printf(sb, "%u\n", UID_NOBODY); 2298 return (0); 2299 } 2300 2301 /* 2302 * Filler function for proc/sys/fs/overflowgid 2303 */ 2304 static int 2305 linprocfs_dooverflowgid(PFS_FILL_ARGS) 2306 { 2307 sbuf_printf(sb, "%u\n", GID_NOGROUP); 2308 return (0); 2309 } 2310 2311 /* 2312 * Filler function for proc/sys/fs/suid_dumpable 2313 */ 2314 static int 2315 linprocfs_dosuid_dumpable(PFS_FILL_ARGS) 2316 { 2317 int res, error; 2318 size_t size = sizeof(res); 2319 2320 error = kernel_sysctlbyname(curthread, "kern.sugid_coredump", 2321 &res, &size, NULL, 0, 0, 0); 2322 if (error != 0) 2323 return (error); 2324 sbuf_printf(sb, "%d\n", res ? 1 : 0); 2325 return (0); 2326 } 2327 2328 /* 2329 * Filler function for proc/sys/fs/protected_hardlinks 2330 */ 2331 static int 2332 linprocfs_doprotected_hardlinks(PFS_FILL_ARGS) 2333 { 2334 int res, error; 2335 size_t size = sizeof(res); 2336 2337 error = kernel_sysctlbyname(curthread, 2338 "security.bsd.hardlink_check_uid", 2339 &res, &size, NULL, 0, 0, 0); 2340 if (error != 0) 2341 return (error); 2342 sbuf_printf(sb, "%d\n", res ? 1 : 0); 2343 return (0); 2344 } 2345 2346 static int 2347 linprocfs_doinotify(const char *sysctl, PFS_FILL_ARGS) 2348 { 2349 size_t size; 2350 int error, val; 2351 2352 if (uio->uio_rw == UIO_READ) { 2353 size = sizeof(val); 2354 error = kernel_sysctlbyname(curthread, 2355 __DECONST(void *, sysctl), &val, &size, NULL, 0, 0, 0); 2356 if (error == 0) 2357 sbuf_printf(sb, "%d\n", val); 2358 } else { 2359 char *endp, *newval; 2360 long vall; 2361 2362 sbuf_trim(sb); 2363 sbuf_finish(sb); 2364 newval = sbuf_data(sb); 2365 vall = strtol(newval, &endp, 10); 2366 if (vall < 0 || vall > INT_MAX || endp == newval || 2367 *endp != '\0') 2368 return (EINVAL); 2369 val = (int)vall; 2370 error = kernel_sysctlbyname(curthread, 2371 __DECONST(void *, sysctl), NULL, NULL, 2372 &val, sizeof(val), 0, 0); 2373 } 2374 return (error); 2375 } 2376 2377 /* 2378 * Filler function for proc/sys/fs/inotify/max_queued_events 2379 */ 2380 static int 2381 linprocfs_doinotify_max_queued_events(PFS_FILL_ARGS) 2382 { 2383 return (linprocfs_doinotify("vfs.inotify.max_queued_events", 2384 PFS_FILL_ARGNAMES)); 2385 } 2386 2387 /* 2388 * Filler function for proc/sys/fs/inotify/max_user_instances 2389 */ 2390 static int 2391 linprocfs_doinotify_max_user_instances(PFS_FILL_ARGS) 2392 { 2393 return (linprocfs_doinotify("vfs.inotify.max_user_instances", 2394 PFS_FILL_ARGNAMES)); 2395 } 2396 2397 /* 2398 * Filler function for proc/sys/fs/inotify/max_user_watches 2399 */ 2400 static int 2401 linprocfs_doinotify_max_user_watches(PFS_FILL_ARGS) 2402 { 2403 return (linprocfs_doinotify("vfs.inotify.max_user_watches", 2404 PFS_FILL_ARGNAMES)); 2405 } 2406 2407 /* 2408 * Filler function for proc/sys/fs/mqueue/msg_default 2409 */ 2410 static int 2411 linprocfs_domqueue_msg_default(PFS_FILL_ARGS) 2412 { 2413 int res, error; 2414 size_t size = sizeof(res); 2415 2416 error = kernel_sysctlbyname(curthread, "kern.mqueue.default_maxmsg", 2417 &res, &size, NULL, 0, 0, 0); 2418 if (error != 0) 2419 return (error); 2420 2421 sbuf_printf(sb, "%d\n", res); 2422 return (0); 2423 } 2424 2425 /* 2426 * Filler function for proc/sys/fs/mqueue/msgsize_default 2427 */ 2428 static int 2429 linprocfs_domqueue_msgsize_default(PFS_FILL_ARGS) 2430 { 2431 int res, error; 2432 size_t size = sizeof(res); 2433 2434 error = kernel_sysctlbyname(curthread, "kern.mqueue.default_msgsize", 2435 &res, &size, NULL, 0, 0, 0); 2436 if (error != 0) 2437 return (error); 2438 2439 sbuf_printf(sb, "%d\n", res); 2440 return (0); 2441 2442 } 2443 2444 /* 2445 * Filler function for proc/sys/fs/mqueue/msg_max 2446 */ 2447 static int 2448 linprocfs_domqueue_msg_max(PFS_FILL_ARGS) 2449 { 2450 int res, error; 2451 size_t size = sizeof(res); 2452 2453 error = kernel_sysctlbyname(curthread, "kern.mqueue.maxmsg", 2454 &res, &size, NULL, 0, 0, 0); 2455 if (error != 0) 2456 return (error); 2457 2458 sbuf_printf(sb, "%d\n", res); 2459 return (0); 2460 } 2461 2462 /* 2463 * Filler function for proc/sys/fs/mqueue/msgsize_max 2464 */ 2465 static int 2466 linprocfs_domqueue_msgsize_max(PFS_FILL_ARGS) 2467 { 2468 int res, error; 2469 size_t size = sizeof(res); 2470 2471 error = kernel_sysctlbyname(curthread, "kern.mqueue.maxmsgsize", 2472 &res, &size, NULL, 0, 0, 0); 2473 if (error != 0) 2474 return (error); 2475 2476 sbuf_printf(sb, "%d\n", res); 2477 return (0); 2478 } 2479 2480 /* 2481 * Filler function for proc/sys/fs/mqueue/queues_max 2482 */ 2483 static int 2484 linprocfs_domqueue_queues_max(PFS_FILL_ARGS) 2485 { 2486 int res, error; 2487 size_t size = sizeof(res); 2488 2489 error = kernel_sysctlbyname(curthread, "kern.mqueue.maxmq", 2490 &res, &size, NULL, 0, 0, 0); 2491 if (error != 0) 2492 return (error); 2493 2494 sbuf_printf(sb, "%d\n", res); 2495 return (0); 2496 } 2497 2498 /* 2499 * Constructor 2500 */ 2501 static int 2502 linprocfs_init(PFS_INIT_ARGS) 2503 { 2504 struct pfs_node *dir, *fs, *root, *sys; 2505 2506 root = pi->pi_root; 2507 2508 /* /proc/... */ 2509 pfs_create_file(root, NULL, "cmdline", &linprocfs_docmdline, NULL, NULL, 2510 NULL, PFS_RD); 2511 pfs_create_file(root, NULL, "cpuinfo", &linprocfs_docpuinfo, NULL, NULL, 2512 NULL, PFS_RD); 2513 pfs_create_file(root, NULL, "devices", &linprocfs_dodevices, NULL, NULL, 2514 NULL, PFS_RD); 2515 pfs_create_file(root, NULL, "filesystems", &linprocfs_dofilesystems, 2516 NULL, NULL, NULL, PFS_RD); 2517 pfs_create_file(root, NULL, "loadavg", &linprocfs_doloadavg, NULL, NULL, 2518 NULL, PFS_RD); 2519 pfs_create_file(root, NULL, "meminfo", &linprocfs_domeminfo, NULL, NULL, 2520 NULL, PFS_RD); 2521 pfs_create_file(root, NULL, "modules", &linprocfs_domodules, NULL, NULL, 2522 NULL, PFS_RD); 2523 pfs_create_file(root, NULL, "mounts", &linprocfs_domtab, NULL, NULL, 2524 NULL, PFS_RD); 2525 pfs_create_file(root, NULL, "mtab", &linprocfs_domtab, NULL, NULL, NULL, 2526 PFS_RD); 2527 pfs_create_file(root, NULL, "partitions", &linprocfs_dopartitions, NULL, 2528 NULL, NULL, PFS_RD); 2529 pfs_create_link(root, NULL, "self", &procfs_docurproc, NULL, NULL, NULL, 2530 0); 2531 pfs_create_file(root, NULL, "stat", &linprocfs_dostat, NULL, NULL, NULL, 2532 PFS_RD); 2533 pfs_create_file(root, NULL, "swaps", &linprocfs_doswaps, NULL, NULL, 2534 NULL, PFS_RD); 2535 pfs_create_file(root, NULL, "uptime", &linprocfs_douptime, NULL, NULL, 2536 NULL, PFS_RD); 2537 pfs_create_file(root, NULL, "version", &linprocfs_doversion, NULL, NULL, 2538 NULL, PFS_RD); 2539 2540 /* /proc/bus/... */ 2541 pfs_create_dir(root, &dir, "bus", NULL, NULL, NULL, 0); 2542 pfs_create_dir(dir, &dir, "pci", NULL, NULL, NULL, 0); 2543 pfs_create_dir(dir, &dir, "devices", NULL, NULL, NULL, 0); 2544 2545 /* /proc/net/... */ 2546 pfs_create_dir(root, &dir, "net", NULL, NULL, NULL, 0); 2547 pfs_create_file(dir, NULL, "dev", &linprocfs_donetdev, NULL, NULL, NULL, 2548 PFS_RD); 2549 pfs_create_file(dir, NULL, "route", &linprocfs_donetroute, NULL, NULL, 2550 NULL, PFS_RD); 2551 2552 /* /proc/<pid>/... */ 2553 pfs_create_dir(root, &dir, "pid", NULL, NULL, NULL, PFS_PROCDEP); 2554 pfs_create_file(dir, NULL, "cmdline", &linprocfs_doproccmdline, NULL, 2555 NULL, NULL, PFS_RD); 2556 pfs_create_link(dir, NULL, "cwd", &linprocfs_doproccwd, NULL, NULL, 2557 NULL, 0); 2558 pfs_create_file(dir, NULL, "environ", &linprocfs_doprocenviron, NULL, 2559 &procfs_candebug, NULL, PFS_RD); 2560 pfs_create_link(dir, NULL, "exe", &procfs_doprocfile, NULL, 2561 &procfs_notsystem, NULL, 0); 2562 pfs_create_file(dir, NULL, "maps", &linprocfs_doprocmaps, NULL, NULL, 2563 NULL, PFS_RD | PFS_AUTODRAIN); 2564 pfs_create_file(dir, NULL, "mem", &linprocfs_doprocmem, procfs_attr_rw, 2565 &procfs_candebug, NULL, PFS_RDWR | PFS_RAW); 2566 pfs_create_file(dir, NULL, "mountinfo", &linprocfs_doprocmountinfo, 2567 NULL, NULL, NULL, PFS_RD); 2568 pfs_create_file(dir, NULL, "mounts", &linprocfs_domtab, NULL, NULL, 2569 NULL, PFS_RD); 2570 pfs_create_link(dir, NULL, "root", &linprocfs_doprocroot, NULL, NULL, 2571 NULL, 0); 2572 pfs_create_file(dir, NULL, "stat", &linprocfs_doprocstat, NULL, NULL, 2573 NULL, PFS_RD); 2574 pfs_create_file(dir, NULL, "statm", &linprocfs_doprocstatm, NULL, NULL, 2575 NULL, PFS_RD); 2576 pfs_create_file(dir, NULL, "status", &linprocfs_doprocstatus, NULL, 2577 NULL, NULL, PFS_RD); 2578 pfs_create_link(dir, NULL, "fd", &linprocfs_dofdescfs, NULL, NULL, NULL, 2579 0); 2580 pfs_create_file(dir, NULL, "auxv", &linprocfs_doauxv, NULL, 2581 &procfs_candebug, NULL, PFS_RD | PFS_RAWRD); 2582 pfs_create_file(dir, NULL, "limits", &linprocfs_doproclimits, NULL, 2583 NULL, NULL, PFS_RD); 2584 pfs_create_file(dir, NULL, "oom_score_adj", &linprocfs_do_oom_score_adj, 2585 procfs_attr_rw, &procfs_candebug, NULL, PFS_RDWR); 2586 2587 /* /proc/<pid>/task/... */ 2588 pfs_create_dir(dir, &dir, "task", linprocfs_dotaskattr, NULL, NULL, 0); 2589 pfs_create_file(dir, NULL, ".dummy", &linprocfs_dotaskdummy, NULL, NULL, 2590 NULL, PFS_RD); 2591 2592 /* /proc/scsi/... */ 2593 pfs_create_dir(root, &dir, "scsi", NULL, NULL, NULL, 0); 2594 pfs_create_file(dir, NULL, "device_info", &linprocfs_doscsidevinfo, 2595 NULL, NULL, NULL, PFS_RD); 2596 pfs_create_file(dir, NULL, "scsi", &linprocfs_doscsiscsi, NULL, NULL, 2597 NULL, PFS_RD); 2598 2599 /* /proc/sys/... */ 2600 pfs_create_dir(root, &sys, "sys", NULL, NULL, NULL, 0); 2601 2602 /* /proc/sys/kernel/... */ 2603 pfs_create_dir(sys, &dir, "kernel", NULL, NULL, NULL, 0); 2604 pfs_create_file(dir, NULL, "osrelease", &linprocfs_doosrelease, NULL, 2605 NULL, NULL, PFS_RD); 2606 pfs_create_file(dir, NULL, "ostype", &linprocfs_doostype, NULL, NULL, 2607 NULL, PFS_RD); 2608 pfs_create_file(dir, NULL, "version", &linprocfs_doosbuild, NULL, NULL, 2609 NULL, PFS_RD); 2610 pfs_create_file(dir, NULL, "msgmax", &linprocfs_domsgmax, NULL, NULL, 2611 NULL, PFS_RD); 2612 pfs_create_file(dir, NULL, "msgmni", &linprocfs_domsgmni, NULL, NULL, 2613 NULL, PFS_RD); 2614 pfs_create_file(dir, NULL, "msgmnb", &linprocfs_domsgmnb, NULL, NULL, 2615 NULL, PFS_RD); 2616 pfs_create_file(dir, NULL, "ngroups_max", &linprocfs_dongroups_max, 2617 NULL, NULL, NULL, PFS_RD); 2618 pfs_create_file(dir, NULL, "pid_max", &linprocfs_dopid_max, NULL, NULL, 2619 NULL, PFS_RD); 2620 pfs_create_file(dir, NULL, "sem", &linprocfs_dosem, NULL, NULL, NULL, 2621 PFS_RD); 2622 pfs_create_file(dir, NULL, "shmall", &linprocfs_doshmall, NULL, NULL, 2623 NULL, PFS_RD); 2624 pfs_create_file(dir, NULL, "shmmax", &linprocfs_doshmmax, NULL, NULL, 2625 NULL, PFS_RD); 2626 pfs_create_file(dir, NULL, "shmmni", &linprocfs_doshmmni, NULL, NULL, 2627 NULL, PFS_RD); 2628 pfs_create_file(dir, NULL, "tainted", &linprocfs_dotainted, NULL, NULL, 2629 NULL, PFS_RD); 2630 pfs_create_file(dir, NULL, "threads-max", &linprocfs_dothreads_max, 2631 NULL, NULL, NULL, PFS_RD); 2632 2633 /* /proc/sys/kernel/random/... */ 2634 pfs_create_dir(dir, &dir, "random", NULL, NULL, NULL, 0); 2635 pfs_create_file(dir, NULL, "uuid", &linprocfs_douuid, NULL, NULL, NULL, 2636 PFS_RD); 2637 pfs_create_file(dir, NULL, "boot_id", &linprocfs_doboot_id, NULL, NULL, 2638 NULL, PFS_RD); 2639 2640 /* /proc/sys/vm/.... */ 2641 pfs_create_dir(sys, &dir, "vm", NULL, NULL, NULL, 0); 2642 pfs_create_file(dir, NULL, "min_free_kbytes", &linprocfs_dominfree, 2643 NULL, NULL, NULL, PFS_RD); 2644 pfs_create_file(dir, NULL, "max_map_count", &linprocfs_domax_map_cnt, 2645 NULL, NULL, NULL, PFS_RD); 2646 2647 /* /proc/sysvipc/... */ 2648 pfs_create_dir(root, &dir, "sysvipc", NULL, NULL, NULL, 0); 2649 pfs_create_file(dir, NULL, "msg", &linprocfs_dosysvipc_msg, NULL, NULL, 2650 NULL, PFS_RD); 2651 pfs_create_file(dir, NULL, "sem", &linprocfs_dosysvipc_sem, NULL, NULL, 2652 NULL, PFS_RD); 2653 pfs_create_file(dir, NULL, "shm", &linprocfs_dosysvipc_shm, NULL, NULL, 2654 NULL, PFS_RD); 2655 2656 /* /proc/sys/fs/... */ 2657 pfs_create_dir(sys, &fs, "fs", NULL, NULL, NULL, 0); 2658 2659 pfs_create_file(fs, NULL, "file-nr", &linprocfs_dofile_nr, 2660 NULL, NULL, NULL, PFS_RD); 2661 pfs_create_file(fs, NULL, "file-max", &linprocfs_dofile_max, 2662 NULL, NULL, NULL, PFS_RD); 2663 pfs_create_file(fs, NULL, "nr_open", &linprocfs_donr_open, 2664 NULL, NULL, NULL, PFS_RD); 2665 pfs_create_file(fs, NULL, "overflowgid", &linprocfs_dooverflowgid, 2666 NULL, NULL, NULL, PFS_RD); 2667 pfs_create_file(fs, NULL, "overflowuid", &linprocfs_dooverflowuid, 2668 NULL, NULL, NULL, PFS_RD); 2669 pfs_create_file(fs, NULL, "protected_hardlinks", 2670 &linprocfs_doprotected_hardlinks, NULL, NULL, NULL, PFS_RD); 2671 pfs_create_file(fs, NULL, "suid_dumpable", &linprocfs_dosuid_dumpable, 2672 NULL, NULL, NULL, PFS_RD); 2673 2674 pfs_create_dir(fs, &dir, "inotify", NULL, NULL, NULL, 0); 2675 pfs_create_file(dir, NULL, "max_queued_events", 2676 &linprocfs_doinotify_max_queued_events, NULL, NULL, NULL, PFS_RDWR); 2677 pfs_create_file(dir, NULL, "max_user_instances", 2678 &linprocfs_doinotify_max_user_instances, NULL, NULL, NULL, PFS_RDWR); 2679 pfs_create_file(dir, NULL, "max_user_watches", 2680 &linprocfs_doinotify_max_user_watches, NULL, NULL, NULL, PFS_RDWR); 2681 2682 /* /proc/sys/fs/mqueue/... */ 2683 pfs_create_dir(fs, &dir, "mqueue", NULL, NULL, NULL, 0); 2684 pfs_create_file(dir, NULL, "msg_default", 2685 &linprocfs_domqueue_msg_default, NULL, NULL, NULL, PFS_RD); 2686 pfs_create_file(dir, NULL, "msgsize_default", 2687 &linprocfs_domqueue_msgsize_default, NULL, NULL, NULL, PFS_RD); 2688 pfs_create_file(dir, NULL, "msg_max", &linprocfs_domqueue_msg_max, NULL, 2689 NULL, NULL, PFS_RD); 2690 pfs_create_file(dir, NULL, "msgsize_max", 2691 &linprocfs_domqueue_msgsize_max, NULL, NULL, NULL, PFS_RD); 2692 pfs_create_file(dir, NULL, "queues_max", &linprocfs_domqueue_queues_max, 2693 NULL, NULL, NULL, PFS_RD); 2694 2695 return (0); 2696 } 2697 2698 /* 2699 * Destructor 2700 */ 2701 static int 2702 linprocfs_uninit(PFS_INIT_ARGS) 2703 { 2704 2705 /* nothing to do, pseudofs will GC */ 2706 return (0); 2707 } 2708 2709 PSEUDOFS(linprocfs, 1, VFCF_JAIL); 2710 #if defined(__aarch64__) || defined(__amd64__) 2711 MODULE_DEPEND(linprocfs, linux_common, 1, 1, 1); 2712 #else 2713 MODULE_DEPEND(linprocfs, linux, 1, 1, 1); 2714 #endif 2715 MODULE_DEPEND(linprocfs, procfs, 1, 1, 1); 2716 MODULE_DEPEND(linprocfs, sysvmsg, 1, 1, 1); 2717 MODULE_DEPEND(linprocfs, sysvsem, 1, 1, 1); 2718 MODULE_DEPEND(linprocfs, sysvshm, 1, 1, 1); 2719