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