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