1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved. 24 * Copyright 2021 Joyent, Inc. 25 * Copyright 2020 Oxide Computer Company 26 */ 27 28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 29 /* All Rights Reserved */ 30 31 #ifndef _SYS_PROC_H 32 #define _SYS_PROC_H 33 34 #include <sys/time.h> 35 #include <sys/thread.h> 36 #include <sys/cred.h> 37 #include <sys/user.h> 38 #include <sys/watchpoint.h> 39 #include <sys/timer.h> 40 #if defined(__x86) 41 #include <sys/tss.h> 42 #include <sys/segments.h> 43 #endif 44 #include <sys/utrap.h> 45 #include <sys/model.h> 46 #include <sys/refstr.h> 47 #include <sys/avl.h> 48 #include <sys/rctl.h> 49 #include <sys/list.h> 50 #include <sys/avl.h> 51 #include <sys/door_impl.h> 52 #include <sys/signalfd.h> 53 #include <sys/secflags.h> 54 55 #ifdef __cplusplus 56 extern "C" { 57 #endif 58 59 /* 60 * Profile arguments. 61 */ 62 struct prof { 63 void *pr_base; /* buffer base */ 64 uintptr_t pr_off; /* pc offset */ 65 size_t pr_size; /* buffer size */ 66 uint32_t pr_scale; /* pc scaling */ 67 long pr_samples; /* sample count */ 68 }; 69 70 /* 71 * An lwp directory entry. 72 * If le_thread != NULL, this is an active lwp. 73 * If le_thread == NULL, this is an unreaped zombie lwp. 74 */ 75 typedef struct lwpent { 76 kthread_t *le_thread; /* the active lwp, NULL if zombie */ 77 id_t le_lwpid; /* its lwpid (t->t_tid) */ 78 uint16_t le_waiters; /* total number of lwp_wait()ers */ 79 uint16_t le_dwaiters; /* number that are daemons */ 80 clock_t le_start; /* start time of this lwp */ 81 struct vnode *le_trace; /* pointer to /proc lwp vnode */ 82 } lwpent_t; 83 84 typedef struct pctxop { 85 void (*save_op)(void *); /* function to invoke to save ctx */ 86 void (*restore_op)(void *); /* function to invoke to restore ctx */ 87 void (*fork_op)(void *, void *); /* invoke to fork context */ 88 void (*exit_op)(void *); /* invoked during process exit */ 89 void (*free_op)(void *, int); /* function which frees the context */ 90 void *arg; /* argument to above functions */ 91 struct pctxop *next; /* next pcontext ops */ 92 } pctxop_t; 93 94 /* 95 * Elements of the lwp directory, p->p_lwpdir[]. 96 * 97 * We allocate lwp directory entries separately from lwp directory 98 * elements because the lwp directory must be allocated as an array. 99 * The number of lwps can grow quite large and we want to keep the 100 * size of the kmem_alloc()d directory as small as possible. 101 * 102 * If ld_entry == NULL, the entry is free and is on the free list, 103 * p->p_lwpfree, linked through ld_next. If ld_entry != NULL, the 104 * entry is used and ld_next is the thread-id hash link pointer. 105 */ 106 typedef struct lwpdir { 107 struct lwpdir *ld_next; /* hash chain or free list */ 108 struct lwpent *ld_entry; /* lwp directory entry */ 109 } lwpdir_t; 110 111 /* 112 * Element of the p_tidhash thread-id (lwpid) hash table. 113 */ 114 typedef struct tidhash { 115 kmutex_t th_lock; 116 lwpdir_t *th_list; 117 } tidhash_t; 118 119 /* 120 * Retired tidhash hash tables. 121 */ 122 typedef struct ret_tidhash { 123 struct ret_tidhash *rth_next; 124 tidhash_t *rth_tidhash; 125 uint_t rth_tidhash_sz; 126 } ret_tidhash_t; 127 128 struct pool; 129 struct task; 130 struct zone; 131 struct brand; 132 struct corectl_path; 133 struct corectl_content; 134 135 /* 136 * One structure allocated per active process. It contains all 137 * data needed about the process while the process may be swapped 138 * out. Other per-process data (user.h) is also inside the proc structure. 139 * Lightweight-process data (lwp.h) and the kernel stack may be swapped out. 140 */ 141 typedef struct proc { 142 /* 143 * Fields requiring no explicit locking 144 */ 145 struct vnode *p_exec; /* pointer to a.out vnode */ 146 struct as *p_as; /* process address space pointer */ 147 struct plock *p_lockp; /* ptr to proc struct's mutex lock */ 148 kmutex_t p_crlock; /* lock for p_cred */ 149 struct cred *p_cred; /* process credentials */ 150 /* 151 * Fields protected by pidlock 152 */ 153 int p_swapcnt; /* number of swapped out lwps */ 154 char p_stat; /* status of process */ 155 char p_wcode; /* current wait code */ 156 ushort_t p_pidflag; /* flags protected only by pidlock */ 157 int p_wdata; /* current wait return value */ 158 pid_t p_ppid; /* process id of parent */ 159 struct proc *p_link; /* forward link */ 160 struct proc *p_parent; /* ptr to parent process */ 161 struct proc *p_child; /* ptr to first child process */ 162 struct proc *p_sibling; /* ptr to next sibling proc on chain */ 163 struct proc *p_psibling; /* ptr to prev sibling proc on chain */ 164 struct proc *p_sibling_ns; /* prt to siblings with new state */ 165 struct proc *p_child_ns; /* prt to children with new state */ 166 struct proc *p_next; /* active chain link next */ 167 struct proc *p_prev; /* active chain link prev */ 168 struct proc *p_nextofkin; /* gets accounting info at exit */ 169 struct proc *p_orphan; 170 struct proc *p_nextorph; 171 struct proc *p_pglink; /* process group hash chain link next */ 172 struct proc *p_ppglink; /* process group hash chain link prev */ 173 struct sess *p_sessp; /* session information */ 174 struct pid *p_pidp; /* process ID info */ 175 struct pid *p_pgidp; /* process group ID info */ 176 /* 177 * Fields protected by p_lock 178 */ 179 kcondvar_t p_cv; /* proc struct's condition variable */ 180 kcondvar_t p_flag_cv; 181 kcondvar_t p_lwpexit; /* waiting for some lwp to exit */ 182 kcondvar_t p_holdlwps; /* process is waiting for its lwps */ 183 /* to to be held. */ 184 uint_t p_proc_flag; /* /proc-related flags */ 185 uint_t p_flag; /* protected while set. */ 186 /* flags defined below */ 187 clock_t p_utime; /* user time, this process */ 188 clock_t p_stime; /* system time, this process */ 189 clock_t p_cutime; /* sum of children's user time */ 190 clock_t p_cstime; /* sum of children's system time */ 191 avl_tree_t *p_segacct; /* System V shared segment list */ 192 avl_tree_t *p_semacct; /* System V semaphore undo list */ 193 caddr_t p_bssbase; /* base addr of last bss below heap */ 194 caddr_t p_brkbase; /* base addr of heap */ 195 size_t p_brksize; /* heap size in bytes */ 196 uint_t p_brkpageszc; /* preferred heap max page size code */ 197 /* 198 * Per process signal stuff. 199 */ 200 k_sigset_t p_sig; /* signals pending to this process */ 201 k_sigset_t p_extsig; /* signals sent from another contract */ 202 k_sigset_t p_ignore; /* ignore when generated */ 203 k_sigset_t p_siginfo; /* gets signal info with signal */ 204 void *p_sigfd; /* signalfd support state */ 205 struct sigqueue *p_sigqueue; /* queued siginfo structures */ 206 struct sigqhdr *p_sigqhdr; /* hdr to sigqueue structure pool */ 207 struct sigqhdr *p_signhdr; /* hdr to signotify structure pool */ 208 uchar_t p_stopsig; /* jobcontrol stop signal */ 209 210 /* 211 * Special per-process flag when set will fix misaligned memory 212 * references. 213 */ 214 char p_fixalignment; 215 216 /* 217 * Per process lwp and kernel thread stuff 218 */ 219 id_t p_lwpid; /* most recently allocated lwpid */ 220 int p_lwpcnt; /* number of lwps in this process */ 221 int p_lwprcnt; /* number of not stopped lwps */ 222 int p_lwpdaemon; /* number of TP_DAEMON lwps */ 223 int p_lwpwait; /* number of lwps in lwp_wait() */ 224 int p_lwpdwait; /* number of daemons in lwp_wait() */ 225 int p_zombcnt; /* number of zombie lwps */ 226 kthread_t *p_tlist; /* circular list of threads */ 227 lwpdir_t *p_lwpdir; /* thread (lwp) directory */ 228 lwpdir_t *p_lwpfree; /* p_lwpdir free list */ 229 tidhash_t *p_tidhash; /* tid (lwpid) lookup hash table */ 230 uint_t p_lwpdir_sz; /* number of p_lwpdir[] entries */ 231 uint_t p_tidhash_sz; /* number of p_tidhash[] entries */ 232 ret_tidhash_t *p_ret_tidhash; /* retired tidhash hash tables */ 233 uint64_t p_lgrpset; /* unprotected hint of set of lgrps */ 234 /* on which process has threads */ 235 volatile lgrp_id_t p_t1_lgrpid; /* main's thread lgroup id */ 236 volatile lgrp_id_t p_tr_lgrpid; /* text replica's lgroup id */ 237 #if defined(_LP64) 238 uintptr_t p_lgrpres2; /* reserved for lgrp migration */ 239 #endif 240 /* 241 * /proc (process filesystem) debugger interface stuff. 242 */ 243 k_sigset_t p_sigmask; /* mask of traced signals (/proc) */ 244 k_fltset_t p_fltmask; /* mask of traced faults (/proc) */ 245 struct vnode *p_trace; /* pointer to primary /proc vnode */ 246 struct vnode *p_plist; /* list of /proc vnodes for process */ 247 kthread_t *p_agenttp; /* thread ptr for /proc agent lwp */ 248 avl_tree_t p_warea; /* list of watched areas */ 249 avl_tree_t p_wpage; /* remembered watched pages (vfork) */ 250 watched_page_t *p_wprot; /* pages that need to have prot set */ 251 int p_mapcnt; /* number of active pr_mappage()s */ 252 kmutex_t p_maplock; /* lock for pr_mappage() */ 253 struct proc *p_rlink; /* linked list for server */ 254 kcondvar_t p_srwchan_cv; 255 256 /* 257 * Stack sizing and guard information. 258 * Generally protected by as_rangelock() 259 */ 260 size_t p_stksize; /* process stack size in bytes */ 261 uint_t p_stkpageszc; /* preferred stack max page size code */ 262 uintptr_t p_stkg_start; /* start of stack guard */ 263 uintptr_t p_stkg_end; /* end of stack guard */ 264 265 /* 266 * Microstate accounting, resource usage, and real-time profiling 267 */ 268 hrtime_t p_mstart; /* hi-res process start time */ 269 hrtime_t p_mterm; /* hi-res process termination time */ 270 hrtime_t p_mlreal; /* elapsed time sum over defunct lwps */ 271 hrtime_t p_acct[NMSTATES]; /* microstate sum over defunct lwps */ 272 hrtime_t p_cacct[NMSTATES]; /* microstate sum over child procs */ 273 struct lrusage p_ru; /* lrusage sum over defunct lwps */ 274 struct lrusage p_cru; /* lrusage sum over child procs */ 275 struct itimerval p_rprof_timer; /* ITIMER_REALPROF interval timer */ 276 uintptr_t p_rprof_cyclic; /* ITIMER_REALPROF cyclic */ 277 uint_t p_defunct; /* number of defunct lwps */ 278 /* 279 * profiling. A lock is used in the event of multiple lwp's 280 * using the same profiling base/size. 281 */ 282 kmutex_t p_pflock; /* protects user profile arguments */ 283 struct prof p_prof; /* profile arguments */ 284 285 /* 286 * Doors. 287 */ 288 door_pool_t p_server_threads; /* common thread pool */ 289 struct door_node *p_door_list; /* active doors */ 290 struct door_node *p_unref_list; 291 kcondvar_t p_unref_cv; 292 char p_unref_thread; /* unref thread created */ 293 294 /* 295 * Kernel probes 296 */ 297 uchar_t p_tnf_flags; 298 299 /* 300 * Solaris Audit 301 */ 302 struct p_audit_data *p_audit_data; /* per process audit structure */ 303 304 pctxop_t *p_pctx; 305 306 #if defined(__x86) 307 /* 308 * LDT support. 309 */ 310 kmutex_t p_ldtlock; /* protects the following fields */ 311 user_desc_t *p_ldt; /* Pointer to private LDT */ 312 uint64_t p_unused1; /* no longer used */ 313 uint64_t p_unused2; /* no longer used */ 314 ushort_t p_ldtlimit; /* highest selector used */ 315 #endif 316 size_t p_swrss; /* resident set size before last swap */ 317 struct aio *p_aio; /* pointer to async I/O struct */ 318 struct itimer **p_itimer; /* interval timers */ 319 uint_t p_itimer_sz; /* max allocated interval timers */ 320 timeout_id_t p_alarmid; /* alarm's timeout id */ 321 caddr_t p_usrstack; /* top of the process stack */ 322 uint_t p_stkprot; /* stack memory protection */ 323 uint_t p_datprot; /* data memory protection */ 324 model_t p_model; /* data model determined at exec time */ 325 struct lwpchan_data *p_lcp; /* lwpchan cache */ 326 kmutex_t p_lcp_lock; /* protects assignments to p_lcp */ 327 utrap_handler_t *p_utraps; /* pointer to user trap handlers */ 328 struct corectl_path *p_corefile; /* pattern for core file */ 329 struct task *p_task; /* our containing task */ 330 struct proc *p_taskprev; /* ptr to previous process in task */ 331 struct proc *p_tasknext; /* ptr to next process in task */ 332 kmutex_t p_sc_lock; /* protects p_pagep */ 333 struct sc_page_ctl *p_pagep; /* list of process's shared pages */ 334 struct rctl_set *p_rctls; /* resource controls for this process */ 335 rlim64_t p_stk_ctl; /* currently enforced stack size */ 336 rlim64_t p_fsz_ctl; /* currently enforced file size */ 337 rlim64_t p_vmem_ctl; /* currently enforced addr-space size */ 338 rlim64_t p_fno_ctl; /* currently enforced file-desc limit */ 339 pid_t p_ancpid; /* ancestor pid, used by exacct */ 340 struct itimerval p_realitimer; /* real interval timer */ 341 timeout_id_t p_itimerid; /* real interval timer's timeout id */ 342 struct corectl_content *p_content; /* content of core file */ 343 344 avl_tree_t p_ct_held; /* held contracts */ 345 struct ct_equeue **p_ct_equeue; /* process-type event queues */ 346 347 struct cont_process *p_ct_process; /* process contract */ 348 list_node_t p_ct_member; /* process contract membership */ 349 sigqueue_t *p_killsqp; /* sigqueue pointer for SIGKILL */ 350 351 int p_dtrace_probes; /* are there probes for this proc? */ 352 uint64_t p_dtrace_count; /* number of DTrace tracepoints */ 353 /* (protected by P_PR_LOCK) */ 354 void *p_dtrace_helpers; /* DTrace helpers, if any */ 355 struct pool *p_pool; /* pointer to containing pool */ 356 kcondvar_t p_poolcv; /* synchronization with pools */ 357 uint_t p_poolcnt; /* # threads inside pool barrier */ 358 uint_t p_poolflag; /* pool-related flags (see below) */ 359 uint_t p_upanicflag; /* upanic-related flags (see below) */ 360 void *p_upanic; /* optional upanic data */ 361 uintptr_t p_portcnt; /* event ports counter */ 362 struct zone *p_zone; /* zone in which process lives */ 363 struct vnode *p_execdir; /* directory that p_exec came from */ 364 struct brand *p_brand; /* process's brand */ 365 void *p_brand_data; /* per-process brand state */ 366 psecflags_t p_secflags; /* per-process security flags */ 367 368 /* additional lock to protect p_sessp (but not its contents) */ 369 kmutex_t p_splock; 370 rctl_qty_t p_locked_mem; /* locked memory charged to proc */ 371 /* protected by p_lock */ 372 rctl_qty_t p_crypto_mem; /* /dev/crypto memory charged to proc */ 373 /* protected by p_lock */ 374 clock_t p_ttime; /* buffered task time */ 375 376 /* 377 * The user structure 378 */ 379 struct user p_user; /* (see sys/user.h) */ 380 } proc_t; 381 382 #define PROC_T /* headers relying on proc_t are OK */ 383 384 #ifdef _KERNEL 385 386 /* active process chain */ 387 388 extern proc_t *practive; 389 390 /* Well known processes */ 391 392 extern proc_t *proc_sched; /* memory scheduler */ 393 extern proc_t *proc_init; /* init */ 394 extern proc_t *proc_pageout; /* pageout daemon */ 395 extern proc_t *proc_fsflush; /* filesystem sync-er */ 396 397 #endif /* _KERNEL */ 398 399 /* 400 * Stuff to keep track of the number of processes each uid has. 401 * It is tracked on a per-zone basis; that is, if users in different 402 * zones have the same uid, they are tracked separately. 403 * 404 * A structure is allocated when a new <uid,zoneid> pair shows up 405 * There is a hash to find each structure. 406 */ 407 struct upcount { 408 struct upcount *up_next; 409 uid_t up_uid; 410 zoneid_t up_zoneid; 411 uint_t up_count; 412 }; 413 414 /* process ID info */ 415 416 struct pid { 417 unsigned int pid_prinactive :1; 418 unsigned int pid_pgorphaned :1; 419 unsigned int pid_padding :6; /* used to be pid_ref, now an int */ 420 unsigned int pid_prslot :24; 421 pid_t pid_id; 422 struct proc *pid_pglink; 423 struct proc *pid_pgtail; 424 struct pid *pid_link; 425 uint_t pid_ref; 426 }; 427 428 #define p_pgrp p_pgidp->pid_id 429 #define p_pid p_pidp->pid_id 430 #define p_slot p_pidp->pid_prslot 431 #define p_detached p_pgidp->pid_pgorphaned 432 433 #define PID_HOLD(pidp) ASSERT(MUTEX_HELD(&pidlock)); \ 434 ++(pidp)->pid_ref; 435 #define PID_RELE(pidp) ASSERT(MUTEX_HELD(&pidlock)); \ 436 (pidp)->pid_ref > 1 ? \ 437 --(pidp)->pid_ref : pid_rele(pidp); 438 439 /* 440 * Structure containing persistent process lock. The structure and 441 * macro allow "mutex_enter(&p->p_lock)" to continue working. 442 */ 443 struct plock { 444 kmutex_t pl_lock; 445 }; 446 #define p_lock p_lockp->pl_lock 447 448 #ifdef _KERNEL 449 extern proc_t p0; /* process 0 */ 450 extern struct plock p0lock; /* p0's plock */ 451 extern struct pid pid0; /* p0's pid */ 452 453 /* pid_allocate() flags */ 454 #define PID_ALLOC_PROC 0x0001 /* assign a /proc slot as well */ 455 456 #endif /* _KERNEL */ 457 458 /* stat codes */ 459 460 #define SSLEEP 1 /* awaiting an event */ 461 #define SRUN 2 /* runnable */ 462 #define SZOMB 3 /* process terminated but not waited for */ 463 #define SSTOP 4 /* process stopped by debugger */ 464 #define SIDL 5 /* intermediate state in process creation */ 465 #define SONPROC 6 /* process is being run on a processor */ 466 #define SWAIT 7 /* process is waiting to become runnable */ 467 468 /* p_pidflag codes */ 469 #define CLDPEND 0x0001 /* have yet to post a SIGCHLD to the parent */ 470 #define CLDCONT 0x0002 /* child has notified parent of CLD_CONTINUED */ 471 #define CLDNOSIGCHLD 0x0004 /* do not post SIGCHLD when child terminates */ 472 #define CLDWAITPID 0x0008 /* only waitid(P_PID, pid) can reap the child */ 473 474 /* p_proc_flag codes -- these flags are mostly private to /proc */ 475 #define P_PR_TRACE 0x0001 /* signal, fault or syscall tracing via /proc */ 476 #define P_PR_PTRACE 0x0002 /* ptrace() compatibility mode */ 477 #define P_PR_FORK 0x0004 /* child inherits tracing flags */ 478 #define P_PR_LOCK 0x0008 /* process locked by /proc */ 479 #define P_PR_ASYNC 0x0010 /* asynchronous stopping via /proc */ 480 #define P_PR_EXEC 0x0020 /* process is in exec() */ 481 #define P_PR_BPTADJ 0x0040 /* adjust pc on breakpoint trap */ 482 #define P_PR_RUNLCL 0x0080 /* set process running on last /proc close */ 483 #define P_PR_KILLCL 0x0100 /* kill process on last /proc close */ 484 485 /* 486 * p_flag codes 487 * 488 * note that two of these flags, SMSACCT and SSYS, are exported to /proc's 489 * psinfo_t.p_flag field. Historically, all were, but since they are 490 * implementation dependant, we only export the ones people have come to 491 * rely upon. Hence, the bit positions of SSYS and SMSACCT should not be 492 * altered. 493 */ 494 #define SSYS 0x00000001 /* system (resident) process */ 495 #define SEXITING 0x00000002 /* process is exiting */ 496 #define SITBUSY 0x00000004 /* setitimer(ITIMER_REAL) in progress */ 497 #define SFORKING 0x00000008 /* tells called functions that we're forking */ 498 #define SWATCHOK 0x00000010 /* proc in acceptable state for watchpoints */ 499 #define SKILLED 0x00000100 /* SIGKILL has been posted to the process */ 500 #define SSCONT 0x00000200 /* SIGCONT has been posted to the process */ 501 #define SZONETOP 0x00000400 /* process has no valid PPID in its zone */ 502 #define SEXTKILLED 0x00000800 /* SKILLED is from another contract */ 503 #define SUGID 0x00002000 /* process was result of set[ug]id exec */ 504 #define SEXECED 0x00004000 /* this process has execed */ 505 #define SJCTL 0x00010000 /* SIGCHLD sent when children stop/continue */ 506 #define SNOWAIT 0x00020000 /* children never become zombies */ 507 #define SVFORK 0x00040000 /* child of vfork that has not yet exec'd */ 508 #define SVFWAIT 0x00080000 /* parent of vfork waiting for child to exec */ 509 #define SEXITLWPS 0x00100000 /* have lwps exit within the process */ 510 #define SHOLDFORK 0x00200000 /* hold lwps where they're cloneable */ 511 #define SHOLDFORK1 0x00800000 /* hold lwps in place (not cloning) */ 512 #define SCOREDUMP 0x01000000 /* process is dumping core */ 513 #define SMSACCT 0x02000000 /* process is keeping micro-state accounting */ 514 #define SLWPWRAP 0x04000000 /* process has wrapped its lwp ids */ 515 #define SAUTOLPG 0x08000000 /* kernel controls page sizes */ 516 #define SNOCD 0x10000000 /* new creds from VSxID, do not coredump */ 517 #define SHOLDWATCH 0x20000000 /* hold lwps for watchpoint operation */ 518 #define SMSFORK 0x40000000 /* child inherits micro-state accounting */ 519 #define SDOCORE 0x80000000 /* process will attempt to dump core */ 520 521 /* 522 * p_poolflag codes 523 * 524 * These flags are used to synchronize with the pool subsystem to allow 525 * re-binding of processes to new pools. 526 */ 527 #define PBWAIT 0x0001 /* process should wait outside fork/exec/exit */ 528 #define PEXITED 0x0002 /* process exited and about to become zombie */ 529 530 /* 531 * p_upanicflag codes 532 */ 533 #define P_UPF_PANICKED 0x0001 534 #define P_UPF_HAVEMSG 0x0002 535 #define P_UPF_TRUNCMSG 0x0004 536 #define P_UPF_INVALMSG 0x0008 537 538 /* Macro to convert proc pointer to a user block pointer */ 539 #define PTOU(p) (&(p)->p_user) 540 541 #define tracing(p, sig) (sigismember(&(p)->p_sigmask, sig)) 542 543 /* Macro to reduce unnecessary calls to issig() */ 544 545 #define ISSIG(t, why) ISSIG_FAST(t, ttolwp(t), ttoproc(t), why) 546 547 /* 548 * Fast version of ISSIG. 549 * 1. uses register pointers to lwp and proc instead of reloading them. 550 * 2. uses bit-wise OR of tests, since the usual case is that none of them 551 * are true, this saves orcc's and branches. 552 * 3. load the signal flags instead of using sigisempty() macro which does 553 * a branch to convert to boolean. 554 */ 555 #define ISSIG_FAST(t, lwp, p, why) \ 556 (ISSIG_PENDING(t, lwp, p) && issig(why)) 557 558 #define ISSIG_PENDING(t, lwp, p) \ 559 ((lwp)->lwp_cursig | \ 560 sigcheck((p), (t)) | \ 561 (p)->p_stopsig | \ 562 (t)->t_dtrace_stop | \ 563 (t)->t_dtrace_sig | \ 564 ((t)->t_proc_flag & (TP_PRSTOP|TP_HOLDLWP|TP_CHKPT|TP_PAUSE)) | \ 565 ((p)->p_flag & (SEXITLWPS|SKILLED|SHOLDFORK1|SHOLDWATCH))) 566 567 #define ISSTOP(sig) (u.u_signal[sig-1] == SIG_DFL && \ 568 sigismember(&stopdefault, sig)) 569 570 #define ISHOLD(p) ((p)->p_flag & SHOLDFORK) 571 572 #define MUSTRETURN(p, t) (ISHOLD(p) | (t)->t_activefd.a_stale) 573 574 /* 575 * Determine if there are any watchpoints active in the process. 576 */ 577 #define pr_watch_active(p) (avl_numnodes(&(p)->p_warea) != 0) 578 579 /* Reasons for calling issig() */ 580 581 #define FORREAL 0 /* Usual side-effects */ 582 #define JUSTLOOKING 1 /* Don't stop the process */ 583 584 /* 'what' values for stop(PR_SUSPENDED, what) */ 585 #define SUSPEND_NORMAL 0 586 #define SUSPEND_PAUSE 1 587 588 /* pseudo-flag to lwp_create() */ 589 #define NOCLASS (-1) 590 591 /* unused scheduling class ID */ 592 #define CLASS_UNUSED (-2) 593 594 /* LWP stats updated via lwp_stats_update() */ 595 typedef enum { 596 LWP_STAT_INBLK, 597 LWP_STAT_OUBLK, 598 LWP_STAT_MSGRCV, 599 LWP_STAT_MSGSND 600 } lwp_stat_id_t; 601 602 typedef struct prkillinfo { 603 int32_t prk_error; /* errno */ 604 int32_t prk_pad; /* pad */ 605 siginfo_t prk_info; /* siginfo of killing signal */ 606 } prkillinfo_t; 607 608 #ifdef _KERNEL 609 610 /* user profiling functions */ 611 612 extern void profil_tick(uintptr_t); 613 614 /* process management functions */ 615 616 extern int newproc(void (*)(), caddr_t, id_t, int, struct contract **, pid_t); 617 extern void vfwait(pid_t); 618 extern void proc_detach(proc_t *); 619 extern void freeproc(proc_t *); 620 extern void setrun(kthread_t *); 621 extern void setrun_locked(kthread_t *); 622 extern void exit(int, int); 623 extern int proc_exit(int, int); 624 extern void proc_is_exiting(proc_t *); 625 extern void relvm(void); 626 extern void add_ns(proc_t *, proc_t *); 627 extern void delete_ns(proc_t *, proc_t *); 628 extern void upcount_inc(uid_t, zoneid_t); 629 extern void upcount_dec(uid_t, zoneid_t); 630 extern int upcount_get(uid_t, zoneid_t); 631 #if defined(__x86) 632 extern selector_t setup_thrptr(proc_t *, uintptr_t); 633 extern void deferred_singlestep_trap(caddr_t); 634 #endif 635 636 extern void sigcld(proc_t *, sigqueue_t *); 637 extern void sigcld_delete(k_siginfo_t *); 638 extern void sigcld_repost(void); 639 extern int fsig(k_sigset_t *, kthread_t *); 640 extern void psig(void); 641 extern void stop(int, int); 642 extern int stop_on_fault(uint_t, k_siginfo_t *); 643 extern int issig(int); 644 extern int jobstopped(proc_t *); 645 extern void psignal(proc_t *, int); 646 extern void tsignal(kthread_t *, int); 647 extern void sigtoproc(proc_t *, kthread_t *, int); 648 extern void trapsig(k_siginfo_t *, int); 649 extern void realsigprof(int, int, int); 650 extern int eat_signal(kthread_t *, int); 651 extern int signal_is_blocked(kthread_t *, int); 652 extern int sigcheck(proc_t *, kthread_t *); 653 extern void sigdefault(proc_t *); 654 655 extern void pid_setmin(void); 656 extern pid_t pid_allocate(proc_t *, pid_t, int); 657 extern int pid_rele(struct pid *); 658 extern void pid_exit(proc_t *, struct task *); 659 extern void proc_entry_free(struct pid *); 660 extern proc_t *prfind(pid_t); 661 extern proc_t *prfind_zone(pid_t, zoneid_t); 662 extern proc_t *pgfind(pid_t); 663 extern proc_t *pgfind_zone(pid_t, zoneid_t); 664 extern proc_t *sprlock(pid_t); 665 extern proc_t *sprlock_zone(pid_t, zoneid_t); 666 extern int sprtrylock_proc(proc_t *); 667 extern void sprwaitlock_proc(proc_t *); 668 extern void sprlock_proc(proc_t *); 669 extern void sprunlock(proc_t *); 670 extern void pid_init(void); 671 extern proc_t *pid_entry(int); 672 extern int pid_slot(proc_t *); 673 extern void signal(pid_t, int); 674 extern void prsignal(struct pid *, int); 675 extern int uread(proc_t *, void *, size_t, uintptr_t); 676 extern int uwrite(proc_t *, void *, size_t, uintptr_t); 677 678 extern void pgsignal(struct pid *, int); 679 extern void pgjoin(proc_t *, struct pid *); 680 extern void pgcreate(proc_t *); 681 extern void pgexit(proc_t *); 682 extern void pgdetach(proc_t *); 683 extern int pgmembers(pid_t); 684 685 extern void init_mstate(kthread_t *, int); 686 extern int new_mstate(kthread_t *, int); 687 extern void restore_mstate(kthread_t *); 688 extern void term_mstate(kthread_t *); 689 extern void estimate_msacct(kthread_t *, hrtime_t); 690 extern void disable_msacct(proc_t *); 691 extern hrtime_t mstate_aggr_state(proc_t *, int); 692 extern hrtime_t mstate_thread_onproc_time(kthread_t *); 693 extern void mstate_systhread_times(kthread_t *, hrtime_t *, hrtime_t *); 694 extern void syscall_mstate(int, int); 695 696 extern uint_t cpu_update_pct(kthread_t *, hrtime_t); 697 698 extern void set_proc_pre_sys(proc_t *p); 699 extern void set_proc_post_sys(proc_t *p); 700 extern void set_proc_sys(proc_t *p); 701 extern void set_proc_ast(proc_t *p); 702 extern void set_all_proc_sys(void); 703 extern void set_all_zone_usr_proc_sys(zoneid_t); 704 705 /* thread function prototypes */ 706 707 extern kthread_t *thread_create( 708 caddr_t stk, 709 size_t stksize, 710 void (*proc)(), 711 void *arg, 712 size_t len, 713 proc_t *pp, 714 int state, 715 pri_t pri); 716 extern void thread_exit(void) __NORETURN; 717 extern void thread_free(kthread_t *); 718 extern void thread_rele(kthread_t *); 719 extern void thread_join(kt_did_t); 720 extern int reaper(void); 721 extern struct ctxop *installctx_preallocate(void); 722 extern void installctx(kthread_t *, void *, void (*)(), void (*)(), 723 void (*)(), void (*)(), void (*)(), void (*)(), struct ctxop *); 724 extern int removectx(kthread_t *, void *, void (*)(), void (*)(), 725 void (*)(), void (*)(), void (*)(), void (*)()); 726 extern void savectx(kthread_t *); 727 extern void restorectx(kthread_t *); 728 extern void forkctx(kthread_t *, kthread_t *); 729 extern void lwp_createctx(kthread_t *, kthread_t *); 730 extern void exitctx(kthread_t *); 731 extern void freectx(kthread_t *, int); 732 extern void installpctx(proc_t *, void *, void (*)(), void (*)(), 733 void (*)(), void (*)(), void (*)()); 734 extern int removepctx(proc_t *, void *, void (*)(), void (*)(), 735 void (*)(), void (*)(), void (*)()); 736 extern void savepctx(proc_t *); 737 extern void restorepctx(proc_t *); 738 extern void forkpctx(proc_t *, proc_t *); 739 extern void exitpctx(proc_t *); 740 extern void freepctx(proc_t *, int); 741 extern kthread_t *thread_unpin(void); 742 extern void thread_init(void); 743 extern void thread_load(kthread_t *, void (*)(), caddr_t, size_t); 744 745 extern void tsd_create(uint_t *, void (*)(void *)); 746 extern void tsd_destroy(uint_t *); 747 extern void *tsd_getcreate(uint_t *, void (*)(void *), void *(*)(void)); 748 extern void *tsd_get(uint_t); 749 extern int tsd_set(uint_t, void *); 750 extern void tsd_exit(void); 751 extern void *tsd_agent_get(kthread_t *, uint_t); 752 extern int tsd_agent_set(kthread_t *, uint_t, void *); 753 754 /* lwp function prototypes */ 755 756 extern kthread_t *lwp_kernel_create(proc_t *, void (*)(), void *, int, pri_t); 757 extern klwp_t *lwp_create( 758 void (*proc)(), 759 caddr_t arg, 760 size_t len, 761 proc_t *p, 762 int state, 763 int pri, 764 const k_sigset_t *smask, 765 int cid, 766 id_t lwpid); 767 extern kthread_t *idtot(proc_t *, id_t); 768 extern void lwp_hash_in(proc_t *, lwpent_t *, tidhash_t *, uint_t, int); 769 extern void lwp_hash_out(proc_t *, id_t); 770 extern lwpdir_t *lwp_hash_lookup(proc_t *, id_t); 771 extern lwpdir_t *lwp_hash_lookup_and_lock(proc_t *, id_t, kmutex_t **); 772 extern void lwp_create_done(kthread_t *); 773 extern void lwp_exit(void); 774 extern void lwp_pcb_exit(void); 775 extern void lwp_cleanup(void); 776 extern int lwp_suspend(kthread_t *); 777 extern void lwp_continue(kthread_t *); 778 extern void holdlwp(void); 779 extern void stoplwp(void); 780 extern int holdlwps(int); 781 extern int holdwatch(void); 782 extern void pokelwps(proc_t *); 783 extern void continuelwps(proc_t *); 784 extern int exitlwps(int); 785 extern void lwp_ctmpl_copy(klwp_t *, klwp_t *); 786 extern void lwp_ctmpl_clear(klwp_t *); 787 extern klwp_t *forklwp(klwp_t *, proc_t *, id_t); 788 extern void lwp_load(klwp_t *, gregset_t, uintptr_t); 789 extern void lwp_setrval(klwp_t *, int, int); 790 extern void lwp_forkregs(klwp_t *, klwp_t *); 791 extern void lwp_freeregs(klwp_t *, int); 792 extern caddr_t lwp_stk_init(klwp_t *, caddr_t); 793 extern void lwp_stk_cache_init(void); 794 extern void lwp_stk_fini(klwp_t *); 795 extern void lwp_fp_init(klwp_t *); 796 extern void lwp_installctx(klwp_t *); 797 extern void lwp_rtt(void); 798 extern void lwp_rtt_initial(void); 799 extern int lwp_setprivate(klwp_t *, int, uintptr_t); 800 extern void lwp_stat_update(lwp_stat_id_t, long); 801 extern void lwp_attach_brand_hdlrs(klwp_t *); 802 extern void lwp_detach_brand_hdlrs(klwp_t *); 803 804 #if defined(__sparcv9) 805 extern void lwp_mmodel_newlwp(void); 806 extern void lwp_mmodel_shared_as(caddr_t, size_t); 807 #define LWP_MMODEL_NEWLWP() lwp_mmodel_newlwp() 808 #define LWP_MMODEL_SHARED_AS(addr, sz) lwp_mmodel_shared_as((addr), (sz)) 809 #else 810 #define LWP_MMODEL_NEWLWP() 811 #define LWP_MMODEL_SHARED_AS(addr, sz) 812 #endif 813 814 /* 815 * Signal queue function prototypes. Must be here due to header ordering 816 * dependencies. 817 */ 818 extern void sigqfree(proc_t *); 819 extern void siginfofree(sigqueue_t *); 820 extern void sigdeq(proc_t *, kthread_t *, int, sigqueue_t **); 821 extern void sigdelq(proc_t *, kthread_t *, int); 822 extern void sigaddq(proc_t *, kthread_t *, k_siginfo_t *, int); 823 extern void sigaddqa(proc_t *, kthread_t *, sigqueue_t *); 824 extern void sigqsend(int, proc_t *, kthread_t *, sigqueue_t *); 825 extern void sigdupq(proc_t *, proc_t *); 826 extern int sigwillqueue(int, int); 827 extern sigqhdr_t *sigqhdralloc(size_t, uint_t); 828 extern sigqueue_t *sigqalloc(sigqhdr_t *); 829 extern void sigqhdrfree(sigqhdr_t *); 830 extern sigqueue_t *sigappend(k_sigset_t *, sigqueue_t *, 831 k_sigset_t *, sigqueue_t *); 832 extern sigqueue_t *sigprepend(k_sigset_t *, sigqueue_t *, 833 k_sigset_t *, sigqueue_t *); 834 extern void winfo(proc_t *, k_siginfo_t *, int); 835 extern int wstat(int, int); 836 extern int sendsig(int, k_siginfo_t *, void (*)()); 837 #if defined(_SYSCALL32_IMPL) 838 extern int sendsig32(int, k_siginfo_t *, void (*)()); 839 #endif 840 841 #endif /* _KERNEL */ 842 843 #ifdef __cplusplus 844 } 845 #endif 846 847 #endif /* _SYS_PROC_H */ 848