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