1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 1982, 1986, 1989, 1991, 1993 5 * The Regents of the University of California. 6 * Copyright (c) 2007 Robert N. M. Watson 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34 #ifndef _SYS_USER_H_ 35 #define _SYS_USER_H_ 36 37 #include <machine/pcb.h> 38 #ifndef _KERNEL 39 /* stuff that *used* to be included by user.h, or is now needed */ 40 #include <sys/errno.h> 41 #include <sys/event.h> 42 #include <sys/time.h> 43 #include <sys/resource.h> 44 #include <sys/ucred.h> 45 #include <sys/uio.h> 46 #include <sys/queue.h> 47 #include <sys/_lock.h> 48 #include <sys/_mutex.h> 49 #include <sys/proc.h> 50 #include <vm/vm.h> /* XXX */ 51 #include <vm/vm_param.h> /* XXX */ 52 #include <vm/pmap.h> /* XXX */ 53 #include <vm/vm_map.h> /* XXX */ 54 #endif /* !_KERNEL */ 55 #ifndef _SYS_RESOURCEVAR_H_ 56 #include <sys/resourcevar.h> 57 #endif 58 #ifndef _SYS_SIGNALVAR_H_ 59 #include <sys/signalvar.h> 60 #endif 61 #ifndef _SYS_SOCKET_VAR_H_ 62 #include <sys/socket.h> 63 #endif 64 #include <sys/caprights.h> 65 66 /* 67 * KERN_PROC subtype ops return arrays of selected proc structure entries: 68 * 69 * This struct includes several arrays of spare space, with different arrays 70 * for different standard C-types. When adding new variables to this struct, 71 * the space for byte-aligned data should be taken from the ki_sparestring, 72 * pointers from ki_spareptrs, word-aligned data from ki_spareints, and 73 * doubleword-aligned data from ki_sparelongs. Make sure the space for new 74 * variables come from the array which matches the size and alignment of 75 * those variables on ALL hardware platforms, and then adjust the appropriate 76 * KI_NSPARE_* value(s) to match. 77 * 78 * Always verify that sizeof(struct kinfo_proc) == KINFO_PROC_SIZE on all 79 * platforms after you have added new variables. Note that if you change 80 * the value of KINFO_PROC_SIZE, then many userland programs will stop 81 * working until they are recompiled! 82 * 83 * Once you have added the new field, you will need to add code to initialize 84 * it in two places: function fill_kinfo_proc in sys/kern/kern_proc.c and 85 * function kvm_proclist in lib/libkvm/kvm_proc.c . 86 */ 87 #define KI_NSPARE_INT 2 88 #define KI_NSPARE_LONG 12 89 #define KI_NSPARE_PTR 4 90 91 #ifndef _KERNEL 92 #ifndef KINFO_PROC_SIZE 93 #error "Unknown architecture" 94 #endif 95 #endif /* !_KERNEL */ 96 97 #define WMESGLEN 8 /* size of returned wchan message */ 98 #define LOCKNAMELEN 8 /* size of returned lock name */ 99 #define TDNAMLEN 16 /* size of returned thread name */ 100 #define COMMLEN 19 /* size of returned ki_comm name */ 101 #define KI_EMULNAMELEN 16 /* size of returned ki_emul */ 102 #define KI_NGROUPS 16 /* number of groups in ki_groups */ 103 #define LOGNAMELEN 17 /* size of returned ki_login */ 104 #define LOGINCLASSLEN 17 /* size of returned ki_loginclass */ 105 106 #ifndef BURN_BRIDGES 107 #define OCOMMLEN TDNAMLEN 108 #define ki_ocomm ki_tdname 109 #endif 110 111 /* Flags for the process credential. */ 112 #define KI_CRF_CAPABILITY_MODE 0x00000001 113 /* 114 * Steal a bit from ki_cr_flags to indicate that the cred had more than 115 * KI_NGROUPS groups. 116 */ 117 #define KI_CRF_GRP_OVERFLOW 0x80000000 118 119 struct kinfo_proc { 120 int ki_structsize; /* size of this structure */ 121 int ki_layout; /* reserved: layout identifier */ 122 struct pargs *ki_args; /* address of command arguments */ 123 struct proc *ki_paddr; /* address of proc */ 124 struct user *ki_addr; /* kernel virtual addr of u-area */ 125 struct vnode *ki_tracep; /* pointer to trace file */ 126 struct vnode *ki_textvp; /* pointer to executable file */ 127 struct filedesc *ki_fd; /* pointer to open file info */ 128 struct vmspace *ki_vmspace; /* pointer to kernel vmspace struct */ 129 const void *ki_wchan; /* sleep address */ 130 pid_t ki_pid; /* Process identifier */ 131 pid_t ki_ppid; /* parent process id */ 132 pid_t ki_pgid; /* process group id */ 133 pid_t ki_tpgid; /* tty process group id */ 134 pid_t ki_sid; /* Process session ID */ 135 pid_t ki_tsid; /* Terminal session ID */ 136 short ki_jobc; /* job control counter */ 137 short ki_spare_short1; /* unused (just here for alignment) */ 138 uint32_t ki_tdev_freebsd11; /* controlling tty dev */ 139 sigset_t ki_siglist; /* Signals arrived but not delivered */ 140 sigset_t ki_sigmask; /* Current signal mask */ 141 sigset_t ki_sigignore; /* Signals being ignored */ 142 sigset_t ki_sigcatch; /* Signals being caught by user */ 143 uid_t ki_uid; /* effective user id */ 144 uid_t ki_ruid; /* Real user id */ 145 uid_t ki_svuid; /* Saved effective user id */ 146 gid_t ki_rgid; /* Real group id */ 147 gid_t ki_svgid; /* Saved effective group id */ 148 short ki_ngroups; /* number of groups */ 149 short ki_spare_short2; /* unused (just here for alignment) */ 150 gid_t ki_groups[KI_NGROUPS]; /* groups */ 151 vm_size_t ki_size; /* virtual size */ 152 segsz_t ki_rssize; /* current resident set size in pages */ 153 segsz_t ki_swrss; /* resident set size before last swap */ 154 segsz_t ki_tsize; /* text size (pages) XXX */ 155 segsz_t ki_dsize; /* data size (pages) XXX */ 156 segsz_t ki_ssize; /* stack size (pages) */ 157 u_short ki_xstat; /* Exit status for wait & stop signal */ 158 u_short ki_acflag; /* Accounting flags */ 159 fixpt_t ki_pctcpu; /* %cpu for process during ki_swtime */ 160 u_int ki_estcpu; /* Time averaged value of ki_cpticks */ 161 u_int ki_slptime; /* Time since last blocked */ 162 u_int ki_swtime; /* Time swapped in or out */ 163 u_int ki_cow; /* number of copy-on-write faults */ 164 u_int64_t ki_runtime; /* Real time in microsec */ 165 struct timeval ki_start; /* starting time */ 166 struct timeval ki_childtime; /* time used by process children */ 167 long ki_flag; /* P_* flags */ 168 long ki_kiflag; /* KI_* flags (below) */ 169 int ki_traceflag; /* Kernel trace points */ 170 char ki_stat; /* S* process status */ 171 signed char ki_nice; /* Process "nice" value */ 172 char ki_lock; /* Process lock (prevent swap) count */ 173 char ki_rqindex; /* Run queue index */ 174 u_char ki_oncpu_old; /* Which cpu we are on (legacy) */ 175 u_char ki_lastcpu_old; /* Last cpu we were on (legacy) */ 176 char ki_tdname[TDNAMLEN+1]; /* thread name */ 177 char ki_wmesg[WMESGLEN+1]; /* wchan message */ 178 char ki_login[LOGNAMELEN+1]; /* setlogin name */ 179 char ki_lockname[LOCKNAMELEN+1]; /* lock name */ 180 char ki_comm[COMMLEN+1]; /* command name */ 181 char ki_emul[KI_EMULNAMELEN+1]; /* emulation name */ 182 char ki_loginclass[LOGINCLASSLEN+1]; /* login class */ 183 char ki_moretdname[MAXCOMLEN-TDNAMLEN+1]; /* more thread name */ 184 /* 185 * When adding new variables, take space for char-strings from the 186 * front of ki_sparestrings, and ints from the end of ki_spareints. 187 * That way the spare room from both arrays will remain contiguous. 188 */ 189 char ki_sparestrings[38]; /* spare string space */ 190 int ki_spareints[KI_NSPARE_INT]; /* spare room for growth */ 191 pid_t ki_reaper; /* pid of reaper process */ 192 pid_t ki_reapsubtree; /* reaper subtree id */ 193 uint64_t ki_tdev; /* controlling tty dev */ 194 int ki_oncpu; /* Which cpu we are on */ 195 int ki_lastcpu; /* Last cpu we were on */ 196 int ki_tracer; /* Pid of tracing process */ 197 int ki_flag2; /* P2_* flags */ 198 int ki_fibnum; /* Default FIB number */ 199 u_int ki_cr_flags; /* Credential flags */ 200 int ki_jid; /* Process jail ID */ 201 int ki_numthreads; /* number of threads in total */ 202 lwpid_t ki_tid; /* thread id */ 203 struct priority ki_pri; /* process priority */ 204 struct rusage ki_rusage; /* process rusage statistics */ 205 /* XXX - most fields in ki_rusage_ch are not (yet) filled in */ 206 struct rusage ki_rusage_ch; /* rusage of children processes */ 207 struct pcb *ki_pcb; /* kernel virtual addr of pcb */ 208 void *ki_kstack; /* kernel virtual addr of stack */ 209 void *ki_udata; /* User convenience pointer */ 210 struct thread *ki_tdaddr; /* address of thread */ 211 /* 212 * When adding new variables, take space for pointers from the 213 * front of ki_spareptrs, and longs from the end of ki_sparelongs. 214 * That way the spare room from both arrays will remain contiguous. 215 */ 216 struct pwddesc *ki_pd; /* pointer to process paths info */ 217 void *ki_uerrmsg; /* address of the ext err msg place */ 218 void *ki_spareptrs[KI_NSPARE_PTR]; /* spare room for growth */ 219 long ki_sparelongs[KI_NSPARE_LONG]; /* spare room for growth */ 220 long ki_sflag; /* PS_* flags */ 221 long ki_tdflags; /* kthread flag */ 222 }; 223 void fill_kinfo_proc(struct proc *, struct kinfo_proc *); 224 /* XXX - the following two defines are temporary */ 225 #define ki_childstime ki_rusage_ch.ru_stime 226 #define ki_childutime ki_rusage_ch.ru_utime 227 228 /* 229 * Legacy PS_ flag. This moved to p_flag but is maintained for 230 * compatibility. 231 */ 232 #define PS_INMEM 0x00001 /* Loaded into memory, always true. */ 233 234 /* ki_sessflag values */ 235 #define KI_CTTY 0x00000001 /* controlling tty vnode active */ 236 #define KI_SLEADER 0x00000002 /* session leader */ 237 #define KI_LOCKBLOCK 0x00000004 /* proc blocked on lock ki_lockname */ 238 239 /* 240 * This used to be the per-process structure containing data that 241 * isn't needed in core when the process is swapped out, but now it 242 * remains only for the benefit of a.out core dumps. 243 */ 244 struct user { 245 struct pstats u_stats; /* *p_stats */ 246 struct kinfo_proc u_kproc; /* eproc */ 247 }; 248 249 /* 250 * The KERN_PROC_FILE sysctl allows a process to dump the file descriptor 251 * array of another process. 252 */ 253 #define KF_ATTR_VALID 0x0001 254 255 #define KF_TYPE_NONE 0 256 #define KF_TYPE_VNODE 1 257 #define KF_TYPE_SOCKET 2 258 #define KF_TYPE_PIPE 3 259 #define KF_TYPE_FIFO 4 260 #define KF_TYPE_KQUEUE 5 261 /* was KF_TYPE_CRYPTO 6 */ 262 #define KF_TYPE_MQUEUE 7 263 #define KF_TYPE_SHM 8 264 #define KF_TYPE_SEM 9 265 #define KF_TYPE_PTS 10 266 #define KF_TYPE_PROCDESC 11 267 #define KF_TYPE_DEV 12 268 #define KF_TYPE_EVENTFD 13 269 #define KF_TYPE_TIMERFD 14 270 #define KF_TYPE_INOTIFY 15 271 #define KF_TYPE_JAILDESC 16 272 #define KF_TYPE_UNKNOWN 255 273 274 #define KF_VTYPE_VNON 0 275 #define KF_VTYPE_VREG 1 276 #define KF_VTYPE_VDIR 2 277 #define KF_VTYPE_VBLK 3 278 #define KF_VTYPE_VCHR 4 279 #define KF_VTYPE_VLNK 5 280 #define KF_VTYPE_VSOCK 6 281 #define KF_VTYPE_VFIFO 7 282 #define KF_VTYPE_VBAD 8 283 #define KF_VTYPE_UNKNOWN 255 284 285 #define KF_FD_TYPE_CWD -1 /* Current working directory */ 286 #define KF_FD_TYPE_ROOT -2 /* Root directory */ 287 #define KF_FD_TYPE_JAIL -3 /* Jail directory */ 288 #define KF_FD_TYPE_TRACE -4 /* Ktrace vnode */ 289 #define KF_FD_TYPE_TEXT -5 /* Text vnode */ 290 #define KF_FD_TYPE_CTTY -6 /* Controlling terminal */ 291 292 #define KF_FLAG_READ 0x00000001 293 #define KF_FLAG_WRITE 0x00000002 294 #define KF_FLAG_APPEND 0x00000004 295 #define KF_FLAG_ASYNC 0x00000008 296 #define KF_FLAG_FSYNC 0x00000010 297 #define KF_FLAG_NONBLOCK 0x00000020 298 #define KF_FLAG_DIRECT 0x00000040 299 #define KF_FLAG_HASLOCK 0x00000080 300 #define KF_FLAG_SHLOCK 0x00000100 301 #define KF_FLAG_EXLOCK 0x00000200 302 #define KF_FLAG_NOFOLLOW 0x00000400 303 #define KF_FLAG_CREAT 0x00000800 304 #define KF_FLAG_TRUNC 0x00001000 305 #define KF_FLAG_EXCL 0x00002000 306 #define KF_FLAG_EXEC 0x00004000 307 308 /* 309 * Old format. Has variable hidden padding due to alignment. 310 * This is a compatibility hack for pre-build 7.1 packages. 311 */ 312 #if defined(__amd64__) 313 #define KINFO_OFILE_SIZE 1328 314 #endif 315 #if defined(__i386__) 316 #define KINFO_OFILE_SIZE 1324 317 #endif 318 319 struct kinfo_ofile { 320 int kf_structsize; /* Size of kinfo_file. */ 321 int kf_type; /* Descriptor type. */ 322 int kf_fd; /* Array index. */ 323 int kf_ref_count; /* Reference count. */ 324 int kf_flags; /* Flags. */ 325 /* XXX Hidden alignment padding here on amd64 */ 326 off_t kf_offset; /* Seek location. */ 327 int kf_vnode_type; /* Vnode type. */ 328 int kf_sock_domain; /* Socket domain. */ 329 int kf_sock_type; /* Socket type. */ 330 int kf_sock_protocol; /* Socket protocol. */ 331 char kf_path[PATH_MAX]; /* Path to file, if any. */ 332 struct sockaddr_storage kf_sa_local; /* Socket address. */ 333 struct sockaddr_storage kf_sa_peer; /* Peer address. */ 334 }; 335 336 #if defined(__amd64__) || defined(__i386__) 337 /* 338 * This size should never be changed. If you really need to, you must provide 339 * backward ABI compatibility by allocating a new sysctl MIB that will return 340 * the new structure. The current structure has to be returned by the current 341 * sysctl MIB. See how it is done for the kinfo_ofile structure. 342 */ 343 #define KINFO_FILE_SIZE 1392 344 #endif 345 346 struct kinfo_file { 347 int kf_structsize; /* Variable size of record. */ 348 int kf_type; /* Descriptor type. */ 349 int kf_fd; /* Array index. */ 350 int kf_ref_count; /* Reference count. */ 351 int kf_flags; /* Flags. */ 352 int kf_pad0; /* Round to 64 bit alignment. */ 353 int64_t kf_offset; /* Seek location. */ 354 union { 355 struct { 356 /* API compatibility with FreeBSD < 12. */ 357 int kf_vnode_type; 358 int kf_sock_domain; 359 int kf_sock_type; 360 int kf_sock_protocol; 361 struct sockaddr_storage kf_sa_local; 362 struct sockaddr_storage kf_sa_peer; 363 }; 364 union { 365 struct { 366 /* Sendq size */ 367 uint32_t kf_sock_sendq; 368 /* Socket domain. */ 369 int kf_sock_domain0; 370 /* Socket type. */ 371 int kf_sock_type0; 372 /* Socket protocol. */ 373 int kf_sock_protocol0; 374 /* Socket address. */ 375 struct sockaddr_storage kf_sa_local; 376 /* Peer address. */ 377 struct sockaddr_storage kf_sa_peer; 378 /* Address of so_pcb. */ 379 uint64_t kf_sock_pcb; 380 /* Obsolete! May be reused as a spare. */ 381 uint64_t kf_sock_inpcb; 382 /* Address of unp_conn. */ 383 uint64_t kf_sock_unpconn; 384 /* Send buffer state. */ 385 uint16_t kf_sock_snd_sb_state; 386 /* Receive buffer state. */ 387 uint16_t kf_sock_rcv_sb_state; 388 /* Recvq size. */ 389 uint32_t kf_sock_recvq; 390 } kf_sock; 391 struct { 392 /* Vnode type. */ 393 int kf_file_type; 394 /* Space for future use */ 395 int kf_spareint[3]; 396 uint64_t kf_spareint64[29]; 397 /* Number of references to file. */ 398 uint64_t kf_file_nlink; 399 /* Vnode filesystem id. */ 400 uint64_t kf_file_fsid; 401 /* File device. */ 402 uint64_t kf_file_rdev; 403 /* Global file id. */ 404 uint64_t kf_file_fileid; 405 /* File size. */ 406 uint64_t kf_file_size; 407 /* Vnode filesystem id, FreeBSD 11 compat. */ 408 uint32_t kf_file_fsid_freebsd11; 409 /* File device, FreeBSD 11 compat. */ 410 uint32_t kf_file_rdev_freebsd11; 411 /* File mode. */ 412 uint16_t kf_file_mode; 413 /* Round to 64 bit alignment. */ 414 uint16_t kf_file_pad0; 415 uint32_t kf_file_pad1; 416 } kf_file; 417 struct { 418 uint32_t kf_spareint[4]; 419 uint64_t kf_spareint64[32]; 420 uint32_t kf_sem_value; 421 uint16_t kf_sem_mode; 422 } kf_sem; 423 struct { 424 uint32_t kf_spareint[4]; 425 uint64_t kf_spareint64[32]; 426 uint64_t kf_pipe_addr; 427 uint64_t kf_pipe_peer; 428 uint32_t kf_pipe_buffer_cnt; 429 uint32_t kf_pipe_buffer_in; 430 uint32_t kf_pipe_buffer_out; 431 uint32_t kf_pipe_buffer_size; 432 } kf_pipe; 433 struct { 434 uint32_t kf_spareint[4]; 435 uint64_t kf_spareint64[32]; 436 uint32_t kf_pts_dev_freebsd11; 437 uint32_t kf_pts_pad0; 438 uint64_t kf_pts_dev; 439 /* Round to 64 bit alignment. */ 440 uint32_t kf_pts_pad1[4]; 441 } kf_pts; 442 struct { 443 uint32_t kf_spareint[4]; 444 uint64_t kf_spareint64[32]; 445 pid_t kf_pid; 446 } kf_proc; 447 struct { 448 uint64_t kf_eventfd_value; 449 uint32_t kf_eventfd_flags; 450 uint32_t kf_eventfd_spareint[3]; 451 uint64_t kf_eventfd_addr; 452 } kf_eventfd; 453 struct { 454 uint32_t kf_timerfd_clockid; 455 uint32_t kf_timerfd_flags; 456 uint64_t kf_timerfd_addr; 457 } kf_timerfd; 458 struct { 459 int32_t kf_jid; 460 } kf_jail; 461 struct { 462 uint64_t kf_kqueue_addr; 463 int32_t kf_kqueue_count; 464 int32_t kf_kqueue_state; 465 } kf_kqueue; 466 struct { 467 uint64_t kf_inotify_npending; 468 uint64_t kf_inotify_nbpending; 469 } kf_inotify; 470 } kf_un; 471 }; 472 uint16_t kf_status; /* Status flags. */ 473 uint16_t kf_pad1; /* Round to 32 bit alignment. */ 474 int _kf_ispare0; /* Space for more stuff. */ 475 cap_rights_t kf_cap_rights; /* Capability rights. */ 476 uint64_t _kf_cap_spare; /* Space for future cap_rights_t. */ 477 /* Truncated before copyout in sysctl */ 478 char kf_path[PATH_MAX]; /* Path to file, if any. */ 479 }; 480 481 struct kinfo_lockf { 482 int kl_structsize; /* Variable size of record. */ 483 int kl_rw; 484 int kl_type; 485 int kl_pid; 486 int kl_sysid; 487 int kl_pad0; 488 uint64_t kl_file_fsid; 489 uint64_t kl_file_rdev; 490 uint64_t kl_file_fileid; 491 off_t kl_start; 492 off_t kl_len; /* len == 0 till the EOF */ 493 char kl_path[PATH_MAX]; 494 }; 495 496 #define KLOCKF_RW_READ 0x01 497 #define KLOCKF_RW_WRITE 0x02 498 499 #define KLOCKF_TYPE_FLOCK 0x01 500 #define KLOCKF_TYPE_PID 0x02 501 #define KLOCKF_TYPE_REMOTE 0x03 502 503 /* 504 * The KERN_PROC_VMMAP sysctl allows a process to dump the VM layout of 505 * another process as a series of entries. 506 */ 507 #define KVME_TYPE_NONE 0 508 #define KVME_TYPE_DEFAULT 1 /* no longer returned */ 509 #define KVME_TYPE_VNODE 2 510 #define KVME_TYPE_SWAP 3 511 #define KVME_TYPE_DEVICE 4 512 #define KVME_TYPE_PHYS 5 513 #define KVME_TYPE_DEAD 6 514 #define KVME_TYPE_SG 7 515 #define KVME_TYPE_MGTDEVICE 8 516 #define KVME_TYPE_GUARD 9 517 #define KVME_TYPE_UNKNOWN 255 518 519 #define KVME_PROT_READ 0x00000001 520 #define KVME_PROT_WRITE 0x00000002 521 #define KVME_PROT_EXEC 0x00000004 522 #define KVME_MAX_PROT_READ 0x00010000 523 #define KVME_MAX_PROT_WRITE 0x00020000 524 #define KVME_MAX_PROT_EXEC 0x00040000 525 526 #define KVME_FLAG_COW 0x00000001 527 #define KVME_FLAG_NEEDS_COPY 0x00000002 528 #define KVME_FLAG_NOCOREDUMP 0x00000004 529 #define KVME_FLAG_SUPER 0x00000008 530 #define KVME_FLAG_GROWS_UP 0x00000010 531 #define KVME_FLAG_GROWS_DOWN 0x00000020 532 #define KVME_FLAG_USER_WIRED 0x00000040 533 #define KVME_FLAG_SYSVSHM 0x00000080 534 #define KVME_FLAG_POSIXSHM 0x00000100 535 536 #if defined(__amd64__) 537 #define KINFO_OVMENTRY_SIZE 1168 538 #endif 539 #if defined(__i386__) 540 #define KINFO_OVMENTRY_SIZE 1128 541 #endif 542 543 struct kinfo_ovmentry { 544 int kve_structsize; /* Size of kinfo_vmmapentry. */ 545 int kve_type; /* Type of map entry. */ 546 void *kve_start; /* Starting address. */ 547 void *kve_end; /* Finishing address. */ 548 int kve_flags; /* Flags on map entry. */ 549 int kve_resident; /* Number of resident pages. */ 550 int kve_private_resident; /* Number of private pages. */ 551 int kve_protection; /* Protection bitmask. */ 552 int kve_ref_count; /* VM obj ref count. */ 553 int kve_shadow_count; /* VM obj shadow count. */ 554 char kve_path[PATH_MAX]; /* Path to VM obj, if any. */ 555 void *_kve_pspare[8]; /* Space for more stuff. */ 556 off_t kve_offset; /* Mapping offset in object */ 557 uint64_t kve_fileid; /* inode number if vnode */ 558 uint32_t kve_fsid; /* dev_t of vnode location */ 559 int _kve_ispare[3]; /* Space for more stuff. */ 560 }; 561 562 #if defined(__amd64__) || defined(__i386__) 563 #define KINFO_VMENTRY_SIZE 1160 564 #endif 565 566 struct kinfo_vmentry { 567 int kve_structsize; /* Variable size of record. */ 568 int kve_type; /* Type of map entry. */ 569 uint64_t kve_start; /* Starting address. */ 570 uint64_t kve_end; /* Finishing address. */ 571 uint64_t kve_offset; /* Mapping offset in object */ 572 uint64_t kve_vn_fileid; /* inode number if vnode */ 573 uint32_t kve_vn_fsid_freebsd11; /* dev_t of vnode location */ 574 int kve_flags; /* Flags on map entry. */ 575 int kve_resident; /* Number of resident pages. */ 576 int kve_private_resident; /* Number of private pages. */ 577 int kve_protection; /* Protection bitmask. */ 578 int kve_ref_count; /* VM obj ref count. */ 579 int kve_shadow_count; /* VM obj shadow count. */ 580 int kve_vn_type; /* Vnode type. */ 581 uint64_t kve_vn_size; /* File size. */ 582 uint32_t kve_vn_rdev_freebsd11; /* Device id if device. */ 583 uint16_t kve_vn_mode; /* File mode. */ 584 uint16_t kve_status; /* Status flags. */ 585 union { 586 uint64_t _kve_vn_fsid; /* dev_t of vnode location */ 587 uint64_t _kve_obj; /* handle of anon obj */ 588 } kve_type_spec; 589 uint64_t kve_vn_rdev; /* Device id if device. */ 590 int _kve_ispare[8]; /* Space for more stuff. */ 591 /* Truncated before copyout in sysctl */ 592 char kve_path[PATH_MAX]; /* Path to VM obj, if any. */ 593 }; 594 #define kve_vn_fsid kve_type_spec._kve_vn_fsid 595 #define kve_obj kve_type_spec._kve_obj 596 597 #define KVMO_FLAG_SYSVSHM 0x0001 598 #define KVMO_FLAG_POSIXSHM 0x0002 599 600 /* 601 * The "vm.objects" sysctl provides a list of all VM objects in the system 602 * via an array of these entries. 603 */ 604 struct kinfo_vmobject { 605 int kvo_structsize; /* Variable size of record. */ 606 int kvo_type; /* Object type: KVME_TYPE_*. */ 607 uint64_t kvo_size; /* Object size in pages. */ 608 uint64_t kvo_vn_fileid; /* inode number if vnode. */ 609 uint32_t kvo_vn_fsid_freebsd11; /* dev_t of vnode location. */ 610 int kvo_ref_count; /* Reference count. */ 611 int kvo_shadow_count; /* Shadow count. */ 612 int kvo_memattr; /* Memory attribute. */ 613 uint64_t kvo_resident; /* Number of resident pages. */ 614 uint64_t kvo_active; /* Number of active pages. */ 615 uint64_t kvo_inactive; /* Number of inactive pages. */ 616 union { 617 uint64_t _kvo_vn_fsid; 618 uint64_t _kvo_backing_obj; /* Handle for the backing obj */ 619 } kvo_type_spec; /* Type-specific union */ 620 uint64_t kvo_me; /* Uniq handle for anon obj */ 621 uint64_t kvo_laundry; /* Number of laundry pages. */ 622 uint64_t kvo_wired; /* Number of wired pages. */ 623 uint64_t _kvo_qspare[4]; 624 uint32_t kvo_swapped; /* Number of swapped pages */ 625 uint32_t kvo_flags; 626 uint32_t _kvo_ispare[6]; 627 char kvo_path[PATH_MAX]; /* Pathname, if any. */ 628 }; 629 #define kvo_vn_fsid kvo_type_spec._kvo_vn_fsid 630 #define kvo_backing_obj kvo_type_spec._kvo_backing_obj 631 632 /* 633 * The KERN_PROC_KSTACK sysctl allows a process to dump the kernel stacks of 634 * another process as a series of entries. Each stack is represented by a 635 * series of symbol names and offsets as generated by stack_sbuf_print(9). 636 */ 637 #define KKST_MAXLEN 1024 638 639 #define KKST_STATE_STACKOK 0 /* Stack is valid. */ 640 #define KKST_STATE_SWAPPED 1 /* Stack swapped out, obsolete. */ 641 #define KKST_STATE_RUNNING 2 /* Stack ephemeral. */ 642 643 #if defined(__amd64__) || defined(__i386__) 644 #define KINFO_KSTACK_SIZE 1096 645 #endif 646 647 struct kinfo_kstack { 648 lwpid_t kkst_tid; /* ID of thread. */ 649 int kkst_state; /* Validity of stack. */ 650 char kkst_trace[KKST_MAXLEN]; /* String representing stack. */ 651 int _kkst_ispare[16]; /* Space for more stuff. */ 652 }; 653 654 struct kinfo_sigtramp { 655 void *ksigtramp_start; 656 void *ksigtramp_end; 657 void *ksigtramp_spare[4]; 658 }; 659 660 #define KMAP_FLAG_WIREFUTURE 0x01 /* all future mappings wil be wired */ 661 #define KMAP_FLAG_ASLR 0x02 /* ASLR is applied to mappings */ 662 #define KMAP_FLAG_ASLR_IGNSTART 0x04 /* ASLR may map into sbrk grow region */ 663 #define KMAP_FLAG_WXORX 0x08 /* W^X mapping policy is enforced */ 664 #define KMAP_FLAG_ASLR_STACK 0x10 /* the stack location is randomized */ 665 #define KMAP_FLAG_ASLR_SHARED_PAGE 0x20 /* the shared page location is randomized */ 666 667 struct kinfo_vm_layout { 668 uintptr_t kvm_min_user_addr; 669 uintptr_t kvm_max_user_addr; 670 uintptr_t kvm_text_addr; 671 size_t kvm_text_size; 672 uintptr_t kvm_data_addr; 673 size_t kvm_data_size; 674 uintptr_t kvm_stack_addr; 675 size_t kvm_stack_size; 676 int kvm_map_flags; 677 uintptr_t kvm_shp_addr; 678 size_t kvm_shp_size; 679 uintptr_t kvm_spare[12]; 680 }; 681 682 #define KNOTE_STATUS_ACTIVE 0x00000001 683 #define KNOTE_STATUS_QUEUED 0x00000002 684 #define KNOTE_STATUS_DISABLED 0x00000004 685 #define KNOTE_STATUS_DETACHED 0x00000008 686 #define KNOTE_STATUS_KQUEUE 0x00000010 687 688 #define KNOTE_EXTDATA_NONE 0 689 #define KNOTE_EXTDATA_VNODE 1 690 #define KNOTE_EXTDATA_PIPE 2 691 692 struct kinfo_knote { 693 int knt_kq_fd; 694 struct kevent knt_event; 695 int knt_status; 696 int knt_extdata; 697 uint64_t knt_spare0[4]; 698 union { 699 struct { 700 int knt_vnode_type; 701 uint64_t knt_vnode_fsid; 702 uint64_t knt_vnode_fileid; 703 char knt_vnode_fullpath[PATH_MAX]; 704 } knt_vnode; 705 struct { 706 ino_t knt_pipe_ino; 707 } knt_pipe; 708 }; 709 }; 710 711 #ifdef _KERNEL 712 /* Flags for kern_proc_out function. */ 713 #define KERN_PROC_NOTHREADS 0x1 714 #define KERN_PROC_MASK32 0x2 715 716 /* Flags for kern_proc_filedesc_out. */ 717 #define KERN_FILEDESC_PACK_KINFO 0x00000001U 718 719 /* Flags for kern_proc_vmmap_out. */ 720 #define KERN_VMMAP_PACK_KINFO 0x00000001U 721 struct sbuf; 722 723 /* 724 * The kern_proc out functions are helper functions to dump process 725 * miscellaneous kinfo structures to sbuf. The main consumers are KERN_PROC 726 * sysctls but they may also be used by other kernel subsystems. 727 * 728 * The functions manipulate the process locking state and expect the process 729 * to be locked on enter. On return the process is unlocked. 730 */ 731 732 int kern_proc_filedesc_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, 733 int flags); 734 int kern_proc_cwd_out(struct proc *p, struct sbuf *sb, ssize_t maxlen); 735 int kern_proc_out(struct proc *p, struct sbuf *sb, int flags); 736 int kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, 737 int flags); 738 int kern_proc_kqueues_out(struct proc *p, struct sbuf *s, size_t maxlen, 739 bool compat32); 740 741 int vntype_to_kinfo(int vtype); 742 void pack_kinfo(struct kinfo_file *kif); 743 #endif /* !_KERNEL */ 744 745 #endif 746