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