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 2021 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 * Solaris Audit 296 */ 297 struct p_audit_data *p_audit_data; /* per process audit structure */ 298 299 pctxop_t *p_pctx; 300 301 #if defined(__x86) 302 /* 303 * LDT support. 304 */ 305 kmutex_t p_ldtlock; /* protects the following fields */ 306 user_desc_t *p_ldt; /* Pointer to private LDT */ 307 uint64_t p_unused1; /* no longer used */ 308 uint64_t p_unused2; /* no longer used */ 309 ushort_t p_ldtlimit; /* highest selector used */ 310 #endif 311 size_t p_swrss; /* resident set size before last swap */ 312 struct aio *p_aio; /* pointer to async I/O struct */ 313 struct itimer **p_itimer; /* interval timers */ 314 uint_t p_itimer_sz; /* max allocated interval timers */ 315 timeout_id_t p_alarmid; /* alarm's timeout id */ 316 caddr_t p_usrstack; /* top of the process stack */ 317 uint_t p_stkprot; /* stack memory protection */ 318 uint_t p_datprot; /* data memory protection */ 319 model_t p_model; /* data model determined at exec time */ 320 struct lwpchan_data *p_lcp; /* lwpchan cache */ 321 kmutex_t p_lcp_lock; /* protects assignments to p_lcp */ 322 utrap_handler_t *p_utraps; /* pointer to user trap handlers */ 323 struct corectl_path *p_corefile; /* pattern for core file */ 324 struct task *p_task; /* our containing task */ 325 struct proc *p_taskprev; /* ptr to previous process in task */ 326 struct proc *p_tasknext; /* ptr to next process in task */ 327 kmutex_t p_sc_lock; /* protects p_pagep */ 328 struct sc_page_ctl *p_pagep; /* list of process's shared pages */ 329 struct rctl_set *p_rctls; /* resource controls for this process */ 330 rlim64_t p_stk_ctl; /* currently enforced stack size */ 331 rlim64_t p_fsz_ctl; /* currently enforced file size */ 332 rlim64_t p_vmem_ctl; /* currently enforced addr-space size */ 333 rlim64_t p_fno_ctl; /* currently enforced file-desc limit */ 334 pid_t p_ancpid; /* ancestor pid, used by exacct */ 335 struct itimerval p_realitimer; /* real interval timer */ 336 timeout_id_t p_itimerid; /* real interval timer's timeout id */ 337 struct corectl_content *p_content; /* content of core file */ 338 339 avl_tree_t p_ct_held; /* held contracts */ 340 struct ct_equeue **p_ct_equeue; /* process-type event queues */ 341 342 struct cont_process *p_ct_process; /* process contract */ 343 list_node_t p_ct_member; /* process contract membership */ 344 sigqueue_t *p_killsqp; /* sigqueue pointer for SIGKILL */ 345 346 int p_dtrace_probes; /* are there probes for this proc? */ 347 uint64_t p_dtrace_count; /* number of DTrace tracepoints */ 348 /* (protected by P_PR_LOCK) */ 349 void *p_dtrace_helpers; /* DTrace helpers, if any */ 350 struct pool *p_pool; /* pointer to containing pool */ 351 kcondvar_t p_poolcv; /* synchronization with pools */ 352 uint_t p_poolcnt; /* # threads inside pool barrier */ 353 uint_t p_poolflag; /* pool-related flags (see below) */ 354 uint_t p_upanicflag; /* upanic-related flags (see below) */ 355 void *p_upanic; /* optional upanic data */ 356 uintptr_t p_portcnt; /* event ports counter */ 357 struct zone *p_zone; /* zone in which process lives */ 358 struct vnode *p_execdir; /* directory that p_exec came from */ 359 struct brand *p_brand; /* process's brand */ 360 void *p_brand_data; /* per-process brand state */ 361 psecflags_t p_secflags; /* per-process security flags */ 362 363 /* additional lock to protect p_sessp (but not its contents) */ 364 kmutex_t p_splock; 365 rctl_qty_t p_locked_mem; /* locked memory charged to proc */ 366 /* protected by p_lock */ 367 rctl_qty_t p_crypto_mem; /* /dev/crypto memory charged to proc */ 368 /* protected by p_lock */ 369 clock_t p_ttime; /* buffered task time */ 370 371 /* 372 * The user structure 373 */ 374 struct user p_user; /* (see sys/user.h) */ 375 } proc_t; 376 377 #define PROC_T /* headers relying on proc_t are OK */ 378 379 #ifdef _KERNEL 380 381 /* active process chain */ 382 383 extern proc_t *practive; 384 385 /* Well known processes */ 386 387 extern proc_t *proc_sched; /* memory scheduler */ 388 extern proc_t *proc_init; /* init */ 389 extern proc_t *proc_pageout; /* pageout daemon */ 390 extern proc_t *proc_fsflush; /* filesystem sync-er */ 391 392 #endif /* _KERNEL */ 393 394 /* 395 * Stuff to keep track of the number of processes each uid has. 396 * It is tracked on a per-zone basis; that is, if users in different 397 * zones have the same uid, they are tracked separately. 398 * 399 * A structure is allocated when a new <uid,zoneid> pair shows up 400 * There is a hash to find each structure. 401 */ 402 struct upcount { 403 struct upcount *up_next; 404 uid_t up_uid; 405 zoneid_t up_zoneid; 406 uint_t up_count; 407 }; 408 409 /* process ID info */ 410 411 struct pid { 412 unsigned int pid_prinactive :1; 413 unsigned int pid_pgorphaned :1; 414 unsigned int pid_padding :6; /* used to be pid_ref, now an int */ 415 unsigned int pid_prslot :24; 416 pid_t pid_id; 417 struct proc *pid_pglink; 418 struct proc *pid_pgtail; 419 struct pid *pid_link; 420 uint_t pid_ref; 421 }; 422 423 #define p_pgrp p_pgidp->pid_id 424 #define p_pid p_pidp->pid_id 425 #define p_slot p_pidp->pid_prslot 426 #define p_detached p_pgidp->pid_pgorphaned 427 428 #define PID_HOLD(pidp) ASSERT(MUTEX_HELD(&pidlock)); \ 429 ++(pidp)->pid_ref; 430 #define PID_RELE(pidp) ASSERT(MUTEX_HELD(&pidlock)); \ 431 (pidp)->pid_ref > 1 ? \ 432 --(pidp)->pid_ref : pid_rele(pidp); 433 434 /* 435 * Structure containing persistent process lock. The structure and 436 * macro allow "mutex_enter(&p->p_lock)" to continue working. 437 */ 438 struct plock { 439 kmutex_t pl_lock; 440 }; 441 #define p_lock p_lockp->pl_lock 442 443 #ifdef _KERNEL 444 extern proc_t p0; /* process 0 */ 445 extern struct plock p0lock; /* p0's plock */ 446 extern struct pid pid0; /* p0's pid */ 447 448 /* pid_allocate() flags */ 449 #define PID_ALLOC_PROC 0x0001 /* assign a /proc slot as well */ 450 451 #endif /* _KERNEL */ 452 453 /* stat codes */ 454 455 #define SSLEEP 1 /* awaiting an event */ 456 #define SRUN 2 /* runnable */ 457 #define SZOMB 3 /* process terminated but not waited for */ 458 #define SSTOP 4 /* process stopped by debugger */ 459 #define SIDL 5 /* intermediate state in process creation */ 460 #define SONPROC 6 /* process is being run on a processor */ 461 #define SWAIT 7 /* process is waiting to become runnable */ 462 463 /* p_pidflag codes */ 464 #define CLDPEND 0x0001 /* have yet to post a SIGCHLD to the parent */ 465 #define CLDCONT 0x0002 /* child has notified parent of CLD_CONTINUED */ 466 #define CLDNOSIGCHLD 0x0004 /* do not post SIGCHLD when child terminates */ 467 #define CLDWAITPID 0x0008 /* only waitid(P_PID, pid) can reap the child */ 468 469 /* p_proc_flag codes -- these flags are mostly private to /proc */ 470 #define P_PR_TRACE 0x0001 /* signal, fault or syscall tracing via /proc */ 471 #define P_PR_PTRACE 0x0002 /* ptrace() compatibility mode */ 472 #define P_PR_FORK 0x0004 /* child inherits tracing flags */ 473 #define P_PR_LOCK 0x0008 /* process locked by /proc */ 474 #define P_PR_ASYNC 0x0010 /* asynchronous stopping via /proc */ 475 #define P_PR_EXEC 0x0020 /* process is in exec() */ 476 #define P_PR_BPTADJ 0x0040 /* adjust pc on breakpoint trap */ 477 #define P_PR_RUNLCL 0x0080 /* set process running on last /proc close */ 478 #define P_PR_KILLCL 0x0100 /* kill process on last /proc close */ 479 480 /* 481 * p_flag codes 482 * 483 * note that two of these flags, SMSACCT and SSYS, are exported to /proc's 484 * psinfo_t.p_flag field. Historically, all were, but since they are 485 * implementation dependant, we only export the ones people have come to 486 * rely upon. Hence, the bit positions of SSYS and SMSACCT should not be 487 * altered. 488 */ 489 #define SSYS 0x00000001 /* system (resident) process */ 490 #define SEXITING 0x00000002 /* process is exiting */ 491 #define SITBUSY 0x00000004 /* setitimer(ITIMER_REAL) in progress */ 492 #define SFORKING 0x00000008 /* tells called functions that we're forking */ 493 #define SWATCHOK 0x00000010 /* proc in acceptable state for watchpoints */ 494 #define SKILLED 0x00000100 /* SIGKILL has been posted to the process */ 495 #define SSCONT 0x00000200 /* SIGCONT has been posted to the process */ 496 #define SZONETOP 0x00000400 /* process has no valid PPID in its zone */ 497 #define SEXTKILLED 0x00000800 /* SKILLED is from another contract */ 498 #define SUGID 0x00002000 /* process was result of set[ug]id exec */ 499 #define SEXECED 0x00004000 /* this process has execed */ 500 #define SJCTL 0x00010000 /* SIGCHLD sent when children stop/continue */ 501 #define SNOWAIT 0x00020000 /* children never become zombies */ 502 #define SVFORK 0x00040000 /* child of vfork that has not yet exec'd */ 503 #define SVFWAIT 0x00080000 /* parent of vfork waiting for child to exec */ 504 #define SEXITLWPS 0x00100000 /* have lwps exit within the process */ 505 #define SHOLDFORK 0x00200000 /* hold lwps where they're cloneable */ 506 #define SHOLDFORK1 0x00800000 /* hold lwps in place (not cloning) */ 507 #define SCOREDUMP 0x01000000 /* process is dumping core */ 508 #define SMSACCT 0x02000000 /* process is keeping micro-state accounting */ 509 #define SLWPWRAP 0x04000000 /* process has wrapped its lwp ids */ 510 #define SAUTOLPG 0x08000000 /* kernel controls page sizes */ 511 #define SNOCD 0x10000000 /* new creds from VSxID, do not coredump */ 512 #define SHOLDWATCH 0x20000000 /* hold lwps for watchpoint operation */ 513 #define SMSFORK 0x40000000 /* child inherits micro-state accounting */ 514 #define SDOCORE 0x80000000 /* process will attempt to dump core */ 515 516 /* 517 * p_poolflag codes 518 * 519 * These flags are used to synchronize with the pool subsystem to allow 520 * re-binding of processes to new pools. 521 */ 522 #define PBWAIT 0x0001 /* process should wait outside fork/exec/exit */ 523 #define PEXITED 0x0002 /* process exited and about to become zombie */ 524 525 /* 526 * p_upanicflag codes 527 */ 528 #define P_UPF_PANICKED 0x0001 529 #define P_UPF_HAVEMSG 0x0002 530 #define P_UPF_TRUNCMSG 0x0004 531 #define P_UPF_INVALMSG 0x0008 532 533 /* Macro to convert proc pointer to a user block pointer */ 534 #define PTOU(p) (&(p)->p_user) 535 536 #define tracing(p, sig) (sigismember(&(p)->p_sigmask, sig)) 537 538 /* Macro to reduce unnecessary calls to issig() */ 539 540 #define ISSIG(t, why) ISSIG_FAST(t, ttolwp(t), ttoproc(t), why) 541 542 /* 543 * Fast version of ISSIG. 544 * 1. uses register pointers to lwp and proc instead of reloading them. 545 * 2. uses bit-wise OR of tests, since the usual case is that none of them 546 * are true, this saves orcc's and branches. 547 * 3. load the signal flags instead of using sigisempty() macro which does 548 * a branch to convert to boolean. 549 */ 550 #define ISSIG_FAST(t, lwp, p, why) \ 551 (ISSIG_PENDING(t, lwp, p) && issig(why)) 552 553 #define ISSIG_PENDING(t, lwp, p) \ 554 ((lwp)->lwp_cursig | \ 555 sigcheck((p), (t)) | \ 556 (p)->p_stopsig | \ 557 (t)->t_dtrace_stop | \ 558 (t)->t_dtrace_sig | \ 559 ((t)->t_proc_flag & (TP_PRSTOP|TP_HOLDLWP|TP_CHKPT|TP_PAUSE)) | \ 560 ((p)->p_flag & (SEXITLWPS|SKILLED|SHOLDFORK1|SHOLDWATCH))) 561 562 #define ISSTOP(sig) (u.u_signal[sig-1] == SIG_DFL && \ 563 sigismember(&stopdefault, sig)) 564 565 #define ISHOLD(p) ((p)->p_flag & SHOLDFORK) 566 567 #define MUSTRETURN(p, t) (ISHOLD(p) | (t)->t_activefd.a_stale) 568 569 /* 570 * Determine if there are any watchpoints active in the process. 571 */ 572 #define pr_watch_active(p) (avl_numnodes(&(p)->p_warea) != 0) 573 574 /* Reasons for calling issig() */ 575 576 #define FORREAL 0 /* Usual side-effects */ 577 #define JUSTLOOKING 1 /* Don't stop the process */ 578 579 /* 'what' values for stop(PR_SUSPENDED, what) */ 580 #define SUSPEND_NORMAL 0 581 #define SUSPEND_PAUSE 1 582 583 /* pseudo-flag to lwp_create() */ 584 #define NOCLASS (-1) 585 586 /* unused scheduling class ID */ 587 #define CLASS_UNUSED (-2) 588 589 /* LWP stats updated via lwp_stats_update() */ 590 typedef enum { 591 LWP_STAT_INBLK, 592 LWP_STAT_OUBLK, 593 LWP_STAT_MSGRCV, 594 LWP_STAT_MSGSND 595 } lwp_stat_id_t; 596 597 typedef struct prkillinfo { 598 int32_t prk_error; /* errno */ 599 int32_t prk_pad; /* pad */ 600 siginfo_t prk_info; /* siginfo of killing signal */ 601 } prkillinfo_t; 602 603 #ifdef _KERNEL 604 605 /* user profiling functions */ 606 607 extern void profil_tick(uintptr_t); 608 609 /* process management functions */ 610 611 extern int newproc(void (*)(), caddr_t, id_t, int, struct contract **, pid_t); 612 extern void vfwait(pid_t); 613 extern void proc_detach(proc_t *); 614 extern void freeproc(proc_t *); 615 extern void setrun(kthread_t *); 616 extern void setrun_locked(kthread_t *); 617 extern void exit(int, int); 618 extern int proc_exit(int, int); 619 extern void proc_is_exiting(proc_t *); 620 extern void relvm(void); 621 extern void add_ns(proc_t *, proc_t *); 622 extern void delete_ns(proc_t *, proc_t *); 623 extern void upcount_inc(uid_t, zoneid_t); 624 extern void upcount_dec(uid_t, zoneid_t); 625 extern int upcount_get(uid_t, zoneid_t); 626 #if defined(__x86) 627 extern selector_t setup_thrptr(proc_t *, uintptr_t); 628 extern void deferred_singlestep_trap(caddr_t); 629 #endif 630 631 extern void sigcld(proc_t *, sigqueue_t *); 632 extern void sigcld_delete(k_siginfo_t *); 633 extern void sigcld_repost(void); 634 extern int fsig(k_sigset_t *, kthread_t *); 635 extern void psig(void); 636 extern void stop(int, int); 637 extern int stop_on_fault(uint_t, k_siginfo_t *); 638 extern int issig(int); 639 extern int jobstopped(proc_t *); 640 extern void psignal(proc_t *, int); 641 extern void tsignal(kthread_t *, int); 642 extern void sigtoproc(proc_t *, kthread_t *, int); 643 extern void trapsig(k_siginfo_t *, int); 644 extern void realsigprof(int, int, int); 645 extern int eat_signal(kthread_t *, int); 646 extern int signal_is_blocked(kthread_t *, int); 647 extern int sigcheck(proc_t *, kthread_t *); 648 extern void sigdefault(proc_t *); 649 650 extern void pid_setmin(void); 651 extern pid_t pid_allocate(proc_t *, pid_t, int); 652 extern int pid_rele(struct pid *); 653 extern void pid_exit(proc_t *, struct task *); 654 extern void proc_entry_free(struct pid *); 655 extern proc_t *prfind(pid_t); 656 extern proc_t *prfind_zone(pid_t, zoneid_t); 657 extern proc_t *pgfind(pid_t); 658 extern proc_t *pgfind_zone(pid_t, zoneid_t); 659 extern proc_t *sprlock(pid_t); 660 extern proc_t *sprlock_zone(pid_t, zoneid_t); 661 extern int sprtrylock_proc(proc_t *); 662 extern void sprwaitlock_proc(proc_t *); 663 extern void sprlock_proc(proc_t *); 664 extern void sprunlock(proc_t *); 665 extern void pid_init(void); 666 extern proc_t *pid_entry(int); 667 extern int pid_slot(proc_t *); 668 extern void signal(pid_t, int); 669 extern void prsignal(struct pid *, int); 670 extern int uread(proc_t *, void *, size_t, uintptr_t); 671 extern int uwrite(proc_t *, void *, size_t, uintptr_t); 672 673 extern void pgsignal(struct pid *, int); 674 extern void pgjoin(proc_t *, struct pid *); 675 extern void pgcreate(proc_t *); 676 extern void pgexit(proc_t *); 677 extern void pgdetach(proc_t *); 678 extern int pgmembers(pid_t); 679 680 extern void init_mstate(kthread_t *, int); 681 extern int new_mstate(kthread_t *, int); 682 extern void restore_mstate(kthread_t *); 683 extern void term_mstate(kthread_t *); 684 extern void estimate_msacct(kthread_t *, hrtime_t); 685 extern void disable_msacct(proc_t *); 686 extern hrtime_t mstate_aggr_state(proc_t *, int); 687 extern hrtime_t mstate_thread_onproc_time(kthread_t *); 688 extern void mstate_systhread_times(kthread_t *, hrtime_t *, hrtime_t *); 689 extern void syscall_mstate(int, int); 690 691 extern uint_t cpu_update_pct(kthread_t *, hrtime_t); 692 693 extern void set_proc_pre_sys(proc_t *p); 694 extern void set_proc_post_sys(proc_t *p); 695 extern void set_proc_sys(proc_t *p); 696 extern void set_proc_ast(proc_t *p); 697 extern void set_all_proc_sys(void); 698 extern void set_all_zone_usr_proc_sys(zoneid_t); 699 700 /* thread function prototypes */ 701 702 extern kthread_t *thread_create( 703 caddr_t stk, 704 size_t stksize, 705 void (*proc)(), 706 void *arg, 707 size_t len, 708 proc_t *pp, 709 int state, 710 pri_t pri); 711 extern void thread_exit(void) __NORETURN; 712 extern void thread_free(kthread_t *); 713 extern void thread_rele(kthread_t *); 714 extern void thread_join(kt_did_t); 715 extern int reaper(void); 716 717 #define CTXOP_TPL_REV 1 718 719 struct ctxop_template { 720 uint32_t ct_rev; 721 uint32_t ct_pad; 722 void (*ct_save)(void *); 723 void (*ct_restore)(void *); 724 void (*ct_fork)(void *, void *); 725 void (*ct_lwp_create)(void *, void *); 726 void (*ct_exit)(void *); 727 void (*ct_free)(void *, int); 728 }; 729 730 extern struct ctxop *ctxop_allocate(const struct ctxop_template *, void *); 731 extern void ctxop_free(struct ctxop *); 732 extern void ctxop_attach(kthread_t *, struct ctxop *); 733 extern void ctxop_detach(kthread_t *, struct ctxop *); 734 extern void ctxop_install(kthread_t *, const struct ctxop_template *, void *); 735 extern int ctxop_remove(kthread_t *, const struct ctxop_template *, void *); 736 737 extern void savectx(kthread_t *); 738 extern void restorectx(kthread_t *); 739 extern void forkctx(kthread_t *, kthread_t *); 740 extern void lwp_createctx(kthread_t *, kthread_t *); 741 extern void exitctx(kthread_t *); 742 extern void freectx(kthread_t *, int); 743 extern void installpctx(proc_t *, void *, void (*)(), void (*)(), 744 void (*)(), void (*)(), void (*)()); 745 extern int removepctx(proc_t *, void *, void (*)(), void (*)(), 746 void (*)(), void (*)(), void (*)()); 747 extern void savepctx(proc_t *); 748 extern void restorepctx(proc_t *); 749 extern void forkpctx(proc_t *, proc_t *); 750 extern void exitpctx(proc_t *); 751 extern void freepctx(proc_t *, int); 752 extern kthread_t *thread_unpin(void); 753 extern void thread_init(void); 754 extern void thread_load(kthread_t *, void (*)(), caddr_t, size_t); 755 756 extern void tsd_create(uint_t *, void (*)(void *)); 757 extern void tsd_destroy(uint_t *); 758 extern void *tsd_getcreate(uint_t *, void (*)(void *), void *(*)(void)); 759 extern void *tsd_get(uint_t); 760 extern int tsd_set(uint_t, void *); 761 extern void tsd_exit(void); 762 extern void *tsd_agent_get(kthread_t *, uint_t); 763 extern int tsd_agent_set(kthread_t *, uint_t, void *); 764 765 /* lwp function prototypes */ 766 767 extern kthread_t *lwp_kernel_create(proc_t *, void (*)(), void *, int, pri_t); 768 extern klwp_t *lwp_create( 769 void (*proc)(), 770 caddr_t arg, 771 size_t len, 772 proc_t *p, 773 int state, 774 int pri, 775 const k_sigset_t *smask, 776 int cid, 777 id_t lwpid); 778 extern kthread_t *idtot(proc_t *, id_t); 779 extern void lwp_hash_in(proc_t *, lwpent_t *, tidhash_t *, uint_t, int); 780 extern void lwp_hash_out(proc_t *, id_t); 781 extern lwpdir_t *lwp_hash_lookup(proc_t *, id_t); 782 extern lwpdir_t *lwp_hash_lookup_and_lock(proc_t *, id_t, kmutex_t **); 783 extern void lwp_create_done(kthread_t *); 784 extern void lwp_exit(void); 785 extern void lwp_pcb_exit(void); 786 extern void lwp_cleanup(void); 787 extern int lwp_suspend(kthread_t *); 788 extern void lwp_continue(kthread_t *); 789 extern void holdlwp(void); 790 extern void stoplwp(void); 791 extern int holdlwps(int); 792 extern int holdwatch(void); 793 extern void pokelwps(proc_t *); 794 extern void continuelwps(proc_t *); 795 extern int exitlwps(int); 796 extern void lwp_ctmpl_copy(klwp_t *, klwp_t *); 797 extern void lwp_ctmpl_clear(klwp_t *); 798 extern klwp_t *forklwp(klwp_t *, proc_t *, id_t); 799 extern void lwp_load(klwp_t *, gregset_t, uintptr_t); 800 extern void lwp_setrval(klwp_t *, int, int); 801 extern void lwp_forkregs(klwp_t *, klwp_t *); 802 extern void lwp_freeregs(klwp_t *, int); 803 extern caddr_t lwp_stk_init(klwp_t *, caddr_t); 804 extern void lwp_stk_cache_init(void); 805 extern void lwp_stk_fini(klwp_t *); 806 extern void lwp_fp_init(klwp_t *); 807 extern void lwp_installctx(klwp_t *); 808 extern void lwp_rtt(void); 809 extern void lwp_rtt_initial(void); 810 extern int lwp_setprivate(klwp_t *, int, uintptr_t); 811 extern void lwp_stat_update(lwp_stat_id_t, long); 812 extern void lwp_attach_brand_hdlrs(klwp_t *); 813 extern void lwp_detach_brand_hdlrs(klwp_t *); 814 815 #if defined(__sparcv9) 816 extern void lwp_mmodel_newlwp(void); 817 extern void lwp_mmodel_shared_as(caddr_t, size_t); 818 #define LWP_MMODEL_NEWLWP() lwp_mmodel_newlwp() 819 #define LWP_MMODEL_SHARED_AS(addr, sz) lwp_mmodel_shared_as((addr), (sz)) 820 #else 821 #define LWP_MMODEL_NEWLWP() 822 #define LWP_MMODEL_SHARED_AS(addr, sz) 823 #endif 824 825 /* 826 * Signal queue function prototypes. Must be here due to header ordering 827 * dependencies. 828 */ 829 extern void sigqfree(proc_t *); 830 extern void siginfofree(sigqueue_t *); 831 extern void sigdeq(proc_t *, kthread_t *, int, sigqueue_t **); 832 extern void sigdelq(proc_t *, kthread_t *, int); 833 extern void sigaddq(proc_t *, kthread_t *, k_siginfo_t *, int); 834 extern void sigaddqa(proc_t *, kthread_t *, sigqueue_t *); 835 extern void sigqsend(int, proc_t *, kthread_t *, sigqueue_t *); 836 extern void sigdupq(proc_t *, proc_t *); 837 extern int sigwillqueue(int, int); 838 extern sigqhdr_t *sigqhdralloc(size_t, uint_t); 839 extern sigqueue_t *sigqalloc(sigqhdr_t *); 840 extern void sigqhdrfree(sigqhdr_t *); 841 extern sigqueue_t *sigappend(k_sigset_t *, sigqueue_t *, 842 k_sigset_t *, sigqueue_t *); 843 extern sigqueue_t *sigprepend(k_sigset_t *, sigqueue_t *, 844 k_sigset_t *, sigqueue_t *); 845 extern void winfo(proc_t *, k_siginfo_t *, int); 846 extern int wstat(int, int); 847 extern int sendsig(int, k_siginfo_t *, void (*)()); 848 #if defined(_SYSCALL32_IMPL) 849 extern int sendsig32(int, k_siginfo_t *, void (*)()); 850 #endif 851 852 #endif /* _KERNEL */ 853 854 #ifdef __cplusplus 855 } 856 #endif 857 858 #endif /* _SYS_PROC_H */ 859