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