xref: /illumos-gate/usr/src/uts/common/sys/proc.h (revision 9ff75ade)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5100b72f4Sandrei  * Common Development and Distribution License (the "License").
6100b72f4Sandrei  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2197eda132Sraf 
227c478bd9Sstevel@tonic-gate /*
23*9ff75adeSSurya Prakki  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef _SYS_PROC_H
307c478bd9Sstevel@tonic-gate #define	_SYS_PROC_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/time.h>
337c478bd9Sstevel@tonic-gate #include <sys/thread.h>
347c478bd9Sstevel@tonic-gate #include <sys/cred.h>
357c478bd9Sstevel@tonic-gate #include <sys/user.h>
367c478bd9Sstevel@tonic-gate #include <sys/watchpoint.h>
377c478bd9Sstevel@tonic-gate #include <sys/timer.h>
387c478bd9Sstevel@tonic-gate #if defined(__x86)
397c478bd9Sstevel@tonic-gate #include <sys/tss.h>
407c478bd9Sstevel@tonic-gate #include <sys/segments.h>
417c478bd9Sstevel@tonic-gate #endif
427c478bd9Sstevel@tonic-gate #include <sys/utrap.h>
437c478bd9Sstevel@tonic-gate #include <sys/model.h>
447c478bd9Sstevel@tonic-gate #include <sys/refstr.h>
457c478bd9Sstevel@tonic-gate #include <sys/avl.h>
467c478bd9Sstevel@tonic-gate #include <sys/rctl.h>
477c478bd9Sstevel@tonic-gate #include <sys/list.h>
487c478bd9Sstevel@tonic-gate #include <sys/avl.h>
497c478bd9Sstevel@tonic-gate #include <sys/door_impl.h>
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
527c478bd9Sstevel@tonic-gate extern "C" {
537c478bd9Sstevel@tonic-gate #endif
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * Profile arguments.
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate struct prof {
597c478bd9Sstevel@tonic-gate 	void		*pr_base;	/* buffer base */
607c478bd9Sstevel@tonic-gate 	uintptr_t	pr_off;		/* pc offset */
617c478bd9Sstevel@tonic-gate 	size_t		pr_size;	/* buffer size */
627c478bd9Sstevel@tonic-gate 	uint32_t	pr_scale;	/* pc scaling */
637c478bd9Sstevel@tonic-gate 	long		pr_samples;	/* sample count */
647c478bd9Sstevel@tonic-gate };
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate  * An lwp directory entry.
687c478bd9Sstevel@tonic-gate  * If le_thread != NULL, this is an active lwp.
697c478bd9Sstevel@tonic-gate  * If le_thread == NULL, this is an unreaped zombie lwp.
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate typedef struct lwpent {
727c478bd9Sstevel@tonic-gate 	kthread_t	*le_thread;	/* the active lwp, NULL if zombie */
737c478bd9Sstevel@tonic-gate 	id_t		le_lwpid;	/* its lwpid (t->t_tid) */
747c478bd9Sstevel@tonic-gate 	uint16_t	le_waiters;	/* total number of lwp_wait()ers */
757c478bd9Sstevel@tonic-gate 	uint16_t	le_dwaiters;	/* number that are daemons */
767c478bd9Sstevel@tonic-gate 	clock_t		le_start;	/* start time of this lwp */
777c478bd9Sstevel@tonic-gate 	struct vnode	*le_trace;	/* pointer to /proc lwp vnode */
787c478bd9Sstevel@tonic-gate } lwpent_t;
797c478bd9Sstevel@tonic-gate 
800baeff3dSrab typedef struct pctxop {
810baeff3dSrab 	void	(*save_op)(void *);	/* function to invoke to save ctx */
820baeff3dSrab 	void	(*restore_op)(void *);	/* function to invoke to restore ctx */
830baeff3dSrab 	void	(*fork_op)(void *, void *); /* invoke to fork context */
840baeff3dSrab 	void	(*exit_op)(void *);	/* invoked during process exit */
850baeff3dSrab 	void	(*free_op)(void *, int); /* function which frees the context */
860baeff3dSrab 	void	*arg;			/* argument to above functions */
870baeff3dSrab 	struct pctxop *next;		/* next pcontext ops */
880baeff3dSrab } pctxop_t;
890baeff3dSrab 
907c478bd9Sstevel@tonic-gate /*
917c478bd9Sstevel@tonic-gate  * Elements of the lwp directory, p->p_lwpdir[].
927c478bd9Sstevel@tonic-gate  *
937c478bd9Sstevel@tonic-gate  * We allocate lwp directory entries separately from lwp directory
947c478bd9Sstevel@tonic-gate  * elements because the lwp directory must be allocated as an array.
957c478bd9Sstevel@tonic-gate  * The number of lwps can grow quite large and we want to keep the
967c478bd9Sstevel@tonic-gate  * size of the kmem_alloc()d directory as small as possible.
977c478bd9Sstevel@tonic-gate  *
987c478bd9Sstevel@tonic-gate  * If ld_entry == NULL, the entry is free and is on the free list,
997c478bd9Sstevel@tonic-gate  * p->p_lwpfree, linked through ld_next.  If ld_entry != NULL, the
1007c478bd9Sstevel@tonic-gate  * entry is used and ld_next is the thread-id hash link pointer.
1017c478bd9Sstevel@tonic-gate  */
1027c478bd9Sstevel@tonic-gate typedef struct lwpdir {
1037c478bd9Sstevel@tonic-gate 	struct lwpdir	*ld_next;	/* hash chain or free list */
1047c478bd9Sstevel@tonic-gate 	struct lwpent	*ld_entry;	/* lwp directory entry */
1057c478bd9Sstevel@tonic-gate } lwpdir_t;
1067c478bd9Sstevel@tonic-gate 
1076eb30ec3SRoger A. Faulkner /*
1086eb30ec3SRoger A. Faulkner  * Element of the p_tidhash thread-id (lwpid) hash table.
1096eb30ec3SRoger A. Faulkner  */
1106eb30ec3SRoger A. Faulkner typedef struct tidhash {
1116eb30ec3SRoger A. Faulkner 	kmutex_t	th_lock;
1126eb30ec3SRoger A. Faulkner 	lwpdir_t	*th_list;
1136eb30ec3SRoger A. Faulkner } tidhash_t;
1146eb30ec3SRoger A. Faulkner 
1156eb30ec3SRoger A. Faulkner /*
1166eb30ec3SRoger A. Faulkner  * Retired tidhash hash tables.
1176eb30ec3SRoger A. Faulkner  */
1186eb30ec3SRoger A. Faulkner typedef struct ret_tidhash {
1196eb30ec3SRoger A. Faulkner 	struct ret_tidhash	*rth_next;
1206eb30ec3SRoger A. Faulkner 	tidhash_t		*rth_tidhash;
1216eb30ec3SRoger A. Faulkner 	uint_t			rth_tidhash_sz;
1226eb30ec3SRoger A. Faulkner } ret_tidhash_t;
1236eb30ec3SRoger A. Faulkner 
1247c478bd9Sstevel@tonic-gate struct pool;
1257c478bd9Sstevel@tonic-gate struct task;
1267c478bd9Sstevel@tonic-gate struct zone;
1279acbbeafSnn struct brand;
1287c478bd9Sstevel@tonic-gate struct corectl_path;
1297c478bd9Sstevel@tonic-gate struct corectl_content;
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate /*
1327c478bd9Sstevel@tonic-gate  * One structure allocated per active process.  It contains all
1337c478bd9Sstevel@tonic-gate  * data needed about the process while the process may be swapped
1347c478bd9Sstevel@tonic-gate  * out.  Other per-process data (user.h) is also inside the proc structure.
1357c478bd9Sstevel@tonic-gate  * Lightweight-process data (lwp.h) and the kernel stack may be swapped out.
1367c478bd9Sstevel@tonic-gate  */
1377c478bd9Sstevel@tonic-gate typedef struct	proc {
1387c478bd9Sstevel@tonic-gate 	/*
1397c478bd9Sstevel@tonic-gate 	 * Fields requiring no explicit locking
1407c478bd9Sstevel@tonic-gate 	 */
1417c478bd9Sstevel@tonic-gate 	struct	vnode *p_exec;		/* pointer to a.out vnode */
1427c478bd9Sstevel@tonic-gate 	struct	as *p_as;		/* process address space pointer */
1437c478bd9Sstevel@tonic-gate 	struct	plock *p_lockp;		/* ptr to proc struct's mutex lock */
1447c478bd9Sstevel@tonic-gate 	kmutex_t p_crlock;		/* lock for p_cred */
1457c478bd9Sstevel@tonic-gate 	struct	cred	*p_cred;	/* process credentials */
1467c478bd9Sstevel@tonic-gate 	/*
1477c478bd9Sstevel@tonic-gate 	 * Fields protected by pidlock
1487c478bd9Sstevel@tonic-gate 	 */
1497c478bd9Sstevel@tonic-gate 	int	p_swapcnt;		/* number of swapped out lwps */
1507c478bd9Sstevel@tonic-gate 	char	p_stat;			/* status of process */
1517c478bd9Sstevel@tonic-gate 	char	p_wcode;		/* current wait code */
1527c478bd9Sstevel@tonic-gate 	ushort_t p_pidflag;		/* flags protected only by pidlock */
1537c478bd9Sstevel@tonic-gate 	int 	p_wdata;		/* current wait return value */
1547c478bd9Sstevel@tonic-gate 	pid_t	p_ppid;			/* process id of parent */
1557c478bd9Sstevel@tonic-gate 	struct	proc	*p_link;	/* forward link */
1567c478bd9Sstevel@tonic-gate 	struct	proc	*p_parent;	/* ptr to parent process */
1577c478bd9Sstevel@tonic-gate 	struct	proc	*p_child;	/* ptr to first child process */
1587c478bd9Sstevel@tonic-gate 	struct	proc	*p_sibling;	/* ptr to next sibling proc on chain */
1597c478bd9Sstevel@tonic-gate 	struct	proc	*p_psibling;	/* ptr to prev sibling proc on chain */
1607c478bd9Sstevel@tonic-gate 	struct	proc	*p_sibling_ns;	/* prt to siblings with new state */
1617c478bd9Sstevel@tonic-gate 	struct	proc	*p_child_ns;	/* prt to children with new state */
1627c478bd9Sstevel@tonic-gate 	struct	proc 	*p_next;	/* active chain link next */
1637c478bd9Sstevel@tonic-gate 	struct	proc 	*p_prev;	/* active chain link prev */
1647c478bd9Sstevel@tonic-gate 	struct	proc 	*p_nextofkin;	/* gets accounting info at exit */
1657c478bd9Sstevel@tonic-gate 	struct	proc 	*p_orphan;
1667c478bd9Sstevel@tonic-gate 	struct	proc 	*p_nextorph;
1677c478bd9Sstevel@tonic-gate 	struct	proc	*p_pglink;	/* process group hash chain link next */
1687c478bd9Sstevel@tonic-gate 	struct	proc	*p_ppglink;	/* process group hash chain link prev */
1697c478bd9Sstevel@tonic-gate 	struct	sess	*p_sessp;	/* session information */
1707c478bd9Sstevel@tonic-gate 	struct	pid 	*p_pidp;	/* process ID info */
1717c478bd9Sstevel@tonic-gate 	struct	pid 	*p_pgidp;	/* process group ID info */
1727c478bd9Sstevel@tonic-gate 	/*
1737c478bd9Sstevel@tonic-gate 	 * Fields protected by p_lock
1747c478bd9Sstevel@tonic-gate 	 */
1757c478bd9Sstevel@tonic-gate 	kcondvar_t p_cv;		/* proc struct's condition variable */
1767c478bd9Sstevel@tonic-gate 	kcondvar_t p_flag_cv;
1777c478bd9Sstevel@tonic-gate 	kcondvar_t p_lwpexit;		/* waiting for some lwp to exit */
1787c478bd9Sstevel@tonic-gate 	kcondvar_t p_holdlwps;		/* process is waiting for its lwps */
1797c478bd9Sstevel@tonic-gate 					/* to to be held.  */
1807c478bd9Sstevel@tonic-gate 	uint_t	p_proc_flag;		/* /proc-related flags */
1817c478bd9Sstevel@tonic-gate 	uint_t	p_flag;			/* protected while set. */
1827c478bd9Sstevel@tonic-gate 					/* flags defined below */
1837c478bd9Sstevel@tonic-gate 	clock_t	p_utime;		/* user time, this process */
1847c478bd9Sstevel@tonic-gate 	clock_t	p_stime;		/* system time, this process */
1857c478bd9Sstevel@tonic-gate 	clock_t	p_cutime;		/* sum of children's user time */
1867c478bd9Sstevel@tonic-gate 	clock_t	p_cstime;		/* sum of children's system time */
1877c478bd9Sstevel@tonic-gate 	avl_tree_t *p_segacct;		/* System V shared segment list */
1887c478bd9Sstevel@tonic-gate 	avl_tree_t *p_semacct;		/* System V semaphore undo list */
1897c478bd9Sstevel@tonic-gate 	caddr_t	p_bssbase;		/* base addr of last bss below heap */
1907c478bd9Sstevel@tonic-gate 	caddr_t	p_brkbase;		/* base addr of heap */
1917c478bd9Sstevel@tonic-gate 	size_t	p_brksize;		/* heap size in bytes */
1927c478bd9Sstevel@tonic-gate 	uint_t	p_brkpageszc;		/* preferred heap max page size code */
1937c478bd9Sstevel@tonic-gate 	/*
1947c478bd9Sstevel@tonic-gate 	 * Per process signal stuff.
1957c478bd9Sstevel@tonic-gate 	 */
1967c478bd9Sstevel@tonic-gate 	k_sigset_t p_sig;		/* signals pending to this process */
1977c478bd9Sstevel@tonic-gate 	k_sigset_t p_extsig;		/* signals sent from another contract */
1987c478bd9Sstevel@tonic-gate 	k_sigset_t p_ignore;		/* ignore when generated */
1997c478bd9Sstevel@tonic-gate 	k_sigset_t p_siginfo;		/* gets signal info with signal */
2007c478bd9Sstevel@tonic-gate 	struct sigqueue *p_sigqueue;	/* queued siginfo structures */
2017c478bd9Sstevel@tonic-gate 	struct sigqhdr *p_sigqhdr;	/* hdr to sigqueue structure pool */
2027c478bd9Sstevel@tonic-gate 	struct sigqhdr *p_signhdr;	/* hdr to signotify structure pool */
2037c478bd9Sstevel@tonic-gate 	uchar_t	p_stopsig;		/* jobcontrol stop signal */
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 	/*
2067c478bd9Sstevel@tonic-gate 	 * Special per-process flag when set will fix misaligned memory
2077c478bd9Sstevel@tonic-gate 	 * references.
2087c478bd9Sstevel@tonic-gate 	 */
2097c478bd9Sstevel@tonic-gate 	char    p_fixalignment;
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 	/*
2127c478bd9Sstevel@tonic-gate 	 * Per process lwp and kernel thread stuff
2137c478bd9Sstevel@tonic-gate 	 */
2147c478bd9Sstevel@tonic-gate 	id_t	p_lwpid;		/* most recently allocated lwpid */
2157c478bd9Sstevel@tonic-gate 	int 	p_lwpcnt;		/* number of lwps in this process */
2167c478bd9Sstevel@tonic-gate 	int	p_lwprcnt;		/* number of not stopped lwps */
2177c478bd9Sstevel@tonic-gate 	int	p_lwpdaemon;		/* number of TP_DAEMON lwps */
2187c478bd9Sstevel@tonic-gate 	int	p_lwpwait;		/* number of lwps in lwp_wait() */
2197c478bd9Sstevel@tonic-gate 	int	p_lwpdwait;		/* number of daemons in lwp_wait() */
2207c478bd9Sstevel@tonic-gate 	int	p_zombcnt;		/* number of zombie lwps */
2217c478bd9Sstevel@tonic-gate 	kthread_t *p_tlist;		/* circular list of threads */
2227c478bd9Sstevel@tonic-gate 	lwpdir_t *p_lwpdir;		/* thread (lwp) directory */
2237c478bd9Sstevel@tonic-gate 	lwpdir_t *p_lwpfree;		/* p_lwpdir free list */
2246eb30ec3SRoger A. Faulkner 	tidhash_t *p_tidhash;		/* tid (lwpid) lookup hash table */
2257c478bd9Sstevel@tonic-gate 	uint_t	p_lwpdir_sz;		/* number of p_lwpdir[] entries */
2267c478bd9Sstevel@tonic-gate 	uint_t	p_tidhash_sz;		/* number of p_tidhash[] entries */
2276eb30ec3SRoger A. Faulkner 	ret_tidhash_t *p_ret_tidhash;	/* retired tidhash hash tables */
2287c478bd9Sstevel@tonic-gate 	uint64_t p_lgrpset;		/* unprotected hint of set of lgrps */
2297c478bd9Sstevel@tonic-gate 					/* on which process has threads */
2302cb27123Saguzovsk 	volatile lgrp_id_t  p_t1_lgrpid; /* main's thread lgroup id */
2312cb27123Saguzovsk 	volatile lgrp_id_t  p_tr_lgrpid; /* text replica's lgroup id */
2322cb27123Saguzovsk #if defined(_LP64)
2332cb27123Saguzovsk 	uintptr_t  p_lgrpres2;		/* reserved for lgrp migration */
2342cb27123Saguzovsk #endif
2357c478bd9Sstevel@tonic-gate 	/*
2367c478bd9Sstevel@tonic-gate 	 * /proc (process filesystem) debugger interface stuff.
2377c478bd9Sstevel@tonic-gate 	 */
2387c478bd9Sstevel@tonic-gate 	k_sigset_t p_sigmask;		/* mask of traced signals (/proc) */
2397c478bd9Sstevel@tonic-gate 	k_fltset_t p_fltmask;		/* mask of traced faults (/proc) */
2407c478bd9Sstevel@tonic-gate 	struct vnode *p_trace;		/* pointer to primary /proc vnode */
2417c478bd9Sstevel@tonic-gate 	struct vnode *p_plist;		/* list of /proc vnodes for process */
2427c478bd9Sstevel@tonic-gate 	kthread_t *p_agenttp;		/* thread ptr for /proc agent lwp */
2437c478bd9Sstevel@tonic-gate 	avl_tree_t p_warea;		/* list of watched areas */
2447c478bd9Sstevel@tonic-gate 	avl_tree_t p_wpage;		/* remembered watched pages (vfork) */
2457c478bd9Sstevel@tonic-gate 	watched_page_t *p_wprot;	/* pages that need to have prot set */
2467c478bd9Sstevel@tonic-gate 	int	p_mapcnt;		/* number of active pr_mappage()s */
2477c478bd9Sstevel@tonic-gate 	kmutex_t p_maplock;		/* lock for pr_mappage() */
2487c478bd9Sstevel@tonic-gate 	struct	proc  *p_rlink;		/* linked list for server */
2497c478bd9Sstevel@tonic-gate 	kcondvar_t p_srwchan_cv;
2507c478bd9Sstevel@tonic-gate 	size_t	p_stksize;		/* process stack size in bytes */
2517c478bd9Sstevel@tonic-gate 	uint_t	p_stkpageszc;		/* preferred stack max page size code */
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate 	/*
2547c478bd9Sstevel@tonic-gate 	 * Microstate accounting, resource usage, and real-time profiling
2557c478bd9Sstevel@tonic-gate 	 */
2567c478bd9Sstevel@tonic-gate 	hrtime_t p_mstart;		/* hi-res process start time */
2577c478bd9Sstevel@tonic-gate 	hrtime_t p_mterm;		/* hi-res process termination time */
2587c478bd9Sstevel@tonic-gate 	hrtime_t p_mlreal;		/* elapsed time sum over defunct lwps */
2597c478bd9Sstevel@tonic-gate 	hrtime_t p_acct[NMSTATES];	/* microstate sum over defunct lwps */
2607c478bd9Sstevel@tonic-gate 	hrtime_t p_cacct[NMSTATES];	/* microstate sum over child procs */
2617c478bd9Sstevel@tonic-gate 	struct lrusage p_ru;		/* lrusage sum over defunct lwps */
2627c478bd9Sstevel@tonic-gate 	struct lrusage p_cru;		/* lrusage sum over child procs */
2637c478bd9Sstevel@tonic-gate 	struct itimerval p_rprof_timer; /* ITIMER_REALPROF interval timer */
2647c478bd9Sstevel@tonic-gate 	uintptr_t p_rprof_cyclic;	/* ITIMER_REALPROF cyclic */
2657c478bd9Sstevel@tonic-gate 	uint_t	p_defunct;		/* number of defunct lwps */
2667c478bd9Sstevel@tonic-gate 	/*
2677c478bd9Sstevel@tonic-gate 	 * profiling. A lock is used in the event of multiple lwp's
2687c478bd9Sstevel@tonic-gate 	 * using the same profiling base/size.
2697c478bd9Sstevel@tonic-gate 	 */
2707c478bd9Sstevel@tonic-gate 	kmutex_t p_pflock;		/* protects user profile arguments */
2717c478bd9Sstevel@tonic-gate 	struct prof p_prof;		/* profile arguments */
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate 	/*
2747c478bd9Sstevel@tonic-gate 	 * Doors.
2757c478bd9Sstevel@tonic-gate 	 */
2767c478bd9Sstevel@tonic-gate 	door_pool_t		p_server_threads; /* common thread pool */
2777c478bd9Sstevel@tonic-gate 	struct door_node	*p_door_list;	/* active doors */
2787c478bd9Sstevel@tonic-gate 	struct door_node	*p_unref_list;
2797c478bd9Sstevel@tonic-gate 	kcondvar_t		p_unref_cv;
2807c478bd9Sstevel@tonic-gate 	char			p_unref_thread;	/* unref thread created */
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 	/*
2837c478bd9Sstevel@tonic-gate 	 * Kernel probes
2847c478bd9Sstevel@tonic-gate 	 */
2857c478bd9Sstevel@tonic-gate 	uchar_t			p_tnf_flags;
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate 	/*
288d3e55dcdSgww 	 * Solaris Audit
2897c478bd9Sstevel@tonic-gate 	 */
2907c478bd9Sstevel@tonic-gate 	struct p_audit_data	*p_audit_data; /* per process audit structure */
2910baeff3dSrab 
2920baeff3dSrab 	pctxop_t	*p_pctx;
2930baeff3dSrab 
2947c478bd9Sstevel@tonic-gate #if defined(__x86)
2957c478bd9Sstevel@tonic-gate 	/*
2967c478bd9Sstevel@tonic-gate 	 * LDT support.
2977c478bd9Sstevel@tonic-gate 	 */
2987c478bd9Sstevel@tonic-gate 	kmutex_t	p_ldtlock;	/* protects the following fields */
2997c478bd9Sstevel@tonic-gate 	user_desc_t	*p_ldt;		/* Pointer to private LDT */
3007c478bd9Sstevel@tonic-gate 	system_desc_t	p_ldt_desc;	/* segment descriptor for private LDT */
3017c478bd9Sstevel@tonic-gate 	ushort_t	p_ldtlimit;	/* highest selector used */
3027c478bd9Sstevel@tonic-gate #endif
3037c478bd9Sstevel@tonic-gate 	size_t p_swrss;			/* resident set size before last swap */
3047c478bd9Sstevel@tonic-gate 	struct aio	*p_aio;		/* pointer to async I/O struct */
3057c478bd9Sstevel@tonic-gate 	struct itimer	**p_itimer;	/* interval timers */
3067c478bd9Sstevel@tonic-gate 	timeout_id_t	p_alarmid;	/* alarm's timeout id */
3077c478bd9Sstevel@tonic-gate 	caddr_t		p_usrstack;	/* top of the process stack */
3087c478bd9Sstevel@tonic-gate 	uint_t		p_stkprot;	/* stack memory protection */
3097c478bd9Sstevel@tonic-gate 	uint_t		p_datprot;	/* data memory protection */
3107c478bd9Sstevel@tonic-gate 	model_t		p_model;	/* data model determined at exec time */
3117c478bd9Sstevel@tonic-gate 	struct lwpchan_data *p_lcp;	/* lwpchan cache */
3127c478bd9Sstevel@tonic-gate 	kmutex_t	p_lcp_lock;	/* protects assignments to p_lcp */
3137c478bd9Sstevel@tonic-gate 	utrap_handler_t	*p_utraps;	/* pointer to user trap handlers */
3147c478bd9Sstevel@tonic-gate 	struct corectl_path	*p_corefile;	/* pattern for core file */
3157c478bd9Sstevel@tonic-gate 	struct task	*p_task;	/* our containing task */
3167c478bd9Sstevel@tonic-gate 	struct proc	*p_taskprev;	/* ptr to previous process in task */
3177c478bd9Sstevel@tonic-gate 	struct proc	*p_tasknext;	/* ptr to next process in task */
3187c478bd9Sstevel@tonic-gate 	kmutex_t	p_sc_lock;	/* protects p_pagep */
3197c478bd9Sstevel@tonic-gate 	struct sc_page_ctl *p_pagep;	/* list of process's shared pages */
3207c478bd9Sstevel@tonic-gate 	struct rctl_set	*p_rctls;	/* resource controls for this process */
3217c478bd9Sstevel@tonic-gate 	rlim64_t	p_stk_ctl;	/* currently enforced stack size */
3227c478bd9Sstevel@tonic-gate 	rlim64_t	p_fsz_ctl;	/* currently enforced file size */
3237c478bd9Sstevel@tonic-gate 	rlim64_t	p_vmem_ctl;	/* currently enforced addr-space size */
3247c478bd9Sstevel@tonic-gate 	rlim64_t	p_fno_ctl;	/* currently enforced file-desc limit */
3257c478bd9Sstevel@tonic-gate 	pid_t		p_ancpid;	/* ancestor pid, used by exacct */
3267c478bd9Sstevel@tonic-gate 	struct itimerval p_realitimer;	/* real interval timer */
3277c478bd9Sstevel@tonic-gate 	timeout_id_t	p_itimerid;	/* real interval timer's timeout id */
3287c478bd9Sstevel@tonic-gate 	struct corectl_content *p_content;	/* content of core file */
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate 	avl_tree_t	p_ct_held;	/* held contracts */
3317c478bd9Sstevel@tonic-gate 	struct ct_equeue **p_ct_equeue;	/* process-type event queues */
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate 	struct cont_process *p_ct_process; /* process contract */
3347c478bd9Sstevel@tonic-gate 	list_node_t	p_ct_member;	/* process contract membership */
3357c478bd9Sstevel@tonic-gate 	sigqueue_t	*p_killsqp;	/* sigqueue pointer for SIGKILL */
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate 	int		p_dtrace_probes; /* are there probes for this proc? */
3387c478bd9Sstevel@tonic-gate 	uint64_t	p_dtrace_count;	/* number of DTrace tracepoints */
3397c478bd9Sstevel@tonic-gate 					/* (protected by P_PR_LOCK) */
3407c478bd9Sstevel@tonic-gate 	void		*p_dtrace_helpers; /* DTrace helpers, if any */
3417c478bd9Sstevel@tonic-gate 	struct pool	*p_pool;	/* pointer to containing pool */
3427c478bd9Sstevel@tonic-gate 	kcondvar_t	p_poolcv;	/* synchronization with pools */
3437c478bd9Sstevel@tonic-gate 	uint_t		p_poolcnt;	/* # threads inside pool barrier */
3447c478bd9Sstevel@tonic-gate 	uint_t		p_poolflag;	/* pool-related flags (see below) */
3457c478bd9Sstevel@tonic-gate 	uintptr_t	p_portcnt;	/* event ports counter */
3467c478bd9Sstevel@tonic-gate 	struct zone	*p_zone;	/* zone in which process lives */
3477c478bd9Sstevel@tonic-gate 	struct vnode	*p_execdir;	/* directory that p_exec came from */
3489acbbeafSnn 	struct brand	*p_brand;	/* process's brand  */
3499acbbeafSnn 	void		*p_brand_data;	/* per-process brand state */
3509acbbeafSnn 
3519acbbeafSnn 	/* additional lock to protect p_sessp (but not its contents) */
3529acbbeafSnn 	kmutex_t p_splock;
353c6939658Ssl 	rctl_qty_t	p_locked_mem;	/* locked memory charged to proc */
354c6939658Ssl 					/* protected by p_lock */
355c1a9a9c3Skrishna 	rctl_qty_t	p_crypto_mem;	/* /dev/crypto memory charged to proc */
356c1a9a9c3Skrishna 					/* protected by p_lock */
3572850d85bSmv 	clock_t	p_ttime;		/* buffered task time */
358bdf0047cSRoger A. Faulkner 
359bdf0047cSRoger A. Faulkner 	/*
360bdf0047cSRoger A. Faulkner 	 * The user structure
361bdf0047cSRoger A. Faulkner 	 */
362bdf0047cSRoger A. Faulkner 	struct user p_user;		/* (see sys/user.h) */
3637c478bd9Sstevel@tonic-gate } proc_t;
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate #define	PROC_T				/* headers relying on proc_t are OK */
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate #ifdef _KERNEL
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate /* active process chain */
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate extern proc_t *practive;
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate /* Well known processes */
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate extern proc_t *proc_sched;		/* memory scheduler */
3767c478bd9Sstevel@tonic-gate extern proc_t *proc_init;		/* init */
3777c478bd9Sstevel@tonic-gate extern proc_t *proc_pageout;		/* pageout daemon */
3787c478bd9Sstevel@tonic-gate extern proc_t *proc_fsflush;		/* filesystem sync-er */
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate /*
3837c478bd9Sstevel@tonic-gate  * Stuff to keep track of the number of processes each uid has.
3847c478bd9Sstevel@tonic-gate  * It is tracked on a per-zone basis; that is, if users in different
3857c478bd9Sstevel@tonic-gate  * zones have the same uid, they are tracked separately.
3867c478bd9Sstevel@tonic-gate  *
3877c478bd9Sstevel@tonic-gate  * A structure is allocated when a new <uid,zoneid> pair shows up
3887c478bd9Sstevel@tonic-gate  * There is a hash to find each structure.
3897c478bd9Sstevel@tonic-gate  */
3907c478bd9Sstevel@tonic-gate struct	upcount	{
3917c478bd9Sstevel@tonic-gate 	struct	upcount	*up_next;
3927c478bd9Sstevel@tonic-gate 	uid_t		up_uid;
3937c478bd9Sstevel@tonic-gate 	zoneid_t	up_zoneid;
3947c478bd9Sstevel@tonic-gate 	uint_t		up_count;
3957c478bd9Sstevel@tonic-gate };
3967c478bd9Sstevel@tonic-gate 
3977c478bd9Sstevel@tonic-gate /* process ID info */
3987c478bd9Sstevel@tonic-gate 
3997c478bd9Sstevel@tonic-gate struct pid {
4007c478bd9Sstevel@tonic-gate 	unsigned int pid_prinactive :1;
4017c478bd9Sstevel@tonic-gate 	unsigned int pid_pgorphaned :1;
4027c478bd9Sstevel@tonic-gate 	unsigned int pid_padding :6;	/* used to be pid_ref, now an int */
4037c478bd9Sstevel@tonic-gate 	unsigned int pid_prslot :24;
4047c478bd9Sstevel@tonic-gate 	pid_t pid_id;
4057c478bd9Sstevel@tonic-gate 	struct proc *pid_pglink;
406e44bd21cSsusans 	struct proc *pid_pgtail;
4077c478bd9Sstevel@tonic-gate 	struct pid *pid_link;
4087c478bd9Sstevel@tonic-gate 	uint_t pid_ref;
4097c478bd9Sstevel@tonic-gate };
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate #define	p_pgrp p_pgidp->pid_id
4127c478bd9Sstevel@tonic-gate #define	p_pid  p_pidp->pid_id
4137c478bd9Sstevel@tonic-gate #define	p_slot p_pidp->pid_prslot
4147c478bd9Sstevel@tonic-gate #define	p_detached p_pgidp->pid_pgorphaned
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate #define	PID_HOLD(pidp)	ASSERT(MUTEX_HELD(&pidlock)); \
4177c478bd9Sstevel@tonic-gate 			++(pidp)->pid_ref;
4187c478bd9Sstevel@tonic-gate #define	PID_RELE(pidp)	ASSERT(MUTEX_HELD(&pidlock)); \
4197c478bd9Sstevel@tonic-gate 			(pidp)->pid_ref > 1 ? \
4207c478bd9Sstevel@tonic-gate 				--(pidp)->pid_ref : pid_rele(pidp);
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate /*
4237c478bd9Sstevel@tonic-gate  * Structure containing persistent process lock.  The structure and
4247c478bd9Sstevel@tonic-gate  * macro allow "mutex_enter(&p->p_lock)" to continue working.
4257c478bd9Sstevel@tonic-gate  */
4267c478bd9Sstevel@tonic-gate struct plock {
4277c478bd9Sstevel@tonic-gate 	kmutex_t pl_lock;
4287c478bd9Sstevel@tonic-gate };
4297c478bd9Sstevel@tonic-gate #define	p_lock	p_lockp->pl_lock
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate #ifdef _KERNEL
4327c478bd9Sstevel@tonic-gate extern proc_t p0;		/* process 0 */
4337c478bd9Sstevel@tonic-gate extern struct plock p0lock;	/* p0's plock */
4347c478bd9Sstevel@tonic-gate extern struct pid pid0;		/* p0's pid */
4359acbbeafSnn 
4369acbbeafSnn /* pid_allocate() flags */
4379acbbeafSnn #define	PID_ALLOC_PROC	0x0001	/* assign a /proc slot as well */
4389acbbeafSnn 
4397c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate /* stat codes */
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate #define	SSLEEP	1		/* awaiting an event */
444c97ad5cdSakolb #define	SRUN	2		/* runnable */
4457c478bd9Sstevel@tonic-gate #define	SZOMB	3		/* process terminated but not waited for */
4467c478bd9Sstevel@tonic-gate #define	SSTOP	4		/* process stopped by debugger */
4477c478bd9Sstevel@tonic-gate #define	SIDL	5		/* intermediate state in process creation */
4487c478bd9Sstevel@tonic-gate #define	SONPROC	6		/* process is being run on a processor */
449c97ad5cdSakolb #define	SWAIT	7		/* process is waiting to become runnable */
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate /* p_pidflag codes */
452657b1f3dSraf #define	CLDPEND		0x0001	/* have yet to post a SIGCHLD to the parent */
453657b1f3dSraf #define	CLDCONT		0x0002	/* child has notified parent of CLD_CONTINUED */
454657b1f3dSraf #define	CLDNOSIGCHLD	0x0004	/* do not post SIGCHLD when child terminates */
455657b1f3dSraf #define	CLDWAITPID	0x0008	/* only waitid(P_PID, pid) can reap the child */
4567c478bd9Sstevel@tonic-gate 
4577c478bd9Sstevel@tonic-gate /* p_proc_flag codes -- these flags are mostly private to /proc */
4587c478bd9Sstevel@tonic-gate #define	P_PR_TRACE	0x0001	/* signal, fault or syscall tracing via /proc */
4597c478bd9Sstevel@tonic-gate #define	P_PR_PTRACE	0x0002	/* ptrace() compatibility mode */
4607c478bd9Sstevel@tonic-gate #define	P_PR_FORK	0x0004	/* child inherits tracing flags */
4617c478bd9Sstevel@tonic-gate #define	P_PR_LOCK	0x0008	/* process locked by /proc */
4627c478bd9Sstevel@tonic-gate #define	P_PR_ASYNC	0x0010	/* asynchronous stopping via /proc */
4637c478bd9Sstevel@tonic-gate #define	P_PR_EXEC	0x0020	/* process is in exec() */
4647c478bd9Sstevel@tonic-gate #define	P_PR_BPTADJ	0x0040	/* adjust pc on breakpoint trap */
4657c478bd9Sstevel@tonic-gate #define	P_PR_RUNLCL	0x0080	/* set process running on last /proc close */
4667c478bd9Sstevel@tonic-gate #define	P_PR_KILLCL	0x0100	/* kill process on last /proc close */
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate /*
4697c478bd9Sstevel@tonic-gate  * p_flag codes
4707c478bd9Sstevel@tonic-gate  *
4717c478bd9Sstevel@tonic-gate  * note that two of these flags, SMSACCT and SSYS, are exported to /proc's
4727c478bd9Sstevel@tonic-gate  * psinfo_t.p_flag field.  Historically, all were, but since they are
4737c478bd9Sstevel@tonic-gate  * implementation dependant, we only export the ones people have come to
4747c478bd9Sstevel@tonic-gate  * rely upon.  Hence, the bit positions of SSYS and SMSACCT should not be
4757c478bd9Sstevel@tonic-gate  * altered.
4767c478bd9Sstevel@tonic-gate  */
4777c478bd9Sstevel@tonic-gate #define	SSYS	   0x00000001	/* system (resident) process */
47897eda132Sraf #define	SEXITING   0x00000002	/* process is exiting */
4797c478bd9Sstevel@tonic-gate #define	SITBUSY	   0x00000004	/* setitimer(ITIMER_REAL) in progress */
480ab9a77c7Sahl #define	SFORKING   0x00000008	/* tells called functions that we're forking */
4817c478bd9Sstevel@tonic-gate #define	SWATCHOK   0x00000010	/* proc in acceptable state for watchpoints */
4827c478bd9Sstevel@tonic-gate #define	SKILLED    0x00000100	/* SIGKILL has been posted to the process */
4837c478bd9Sstevel@tonic-gate #define	SSCONT	   0x00000200	/* SIGCONT has been posted to the process */
4847c478bd9Sstevel@tonic-gate #define	SZONETOP   0x00000400	/* process has no valid PPID in its zone */
4857c478bd9Sstevel@tonic-gate #define	SEXTKILLED 0x00000800	/* SKILLED is from another contract */
4867c478bd9Sstevel@tonic-gate #define	SUGID	   0x00002000	/* process was result of set[ug]id exec */
4877c478bd9Sstevel@tonic-gate #define	SEXECED	   0x00004000	/* this process has execed */
488657b1f3dSraf #define	SJCTL	   0x00010000	/* SIGCHLD sent when children stop/continue */
4897c478bd9Sstevel@tonic-gate #define	SNOWAIT    0x00020000	/* children never become zombies */
4907c478bd9Sstevel@tonic-gate #define	SVFORK	   0x00040000	/* child of vfork that has not yet exec'd */
4917c478bd9Sstevel@tonic-gate #define	SVFWAIT	   0x00080000	/* parent of vfork waiting for child to exec */
4927c478bd9Sstevel@tonic-gate #define	SEXITLWPS  0x00100000	/* have lwps exit within the process */
4937c478bd9Sstevel@tonic-gate #define	SHOLDFORK  0x00200000	/* hold lwps where they're cloneable */
4947c478bd9Sstevel@tonic-gate #define	SHOLDFORK1 0x00800000	/* hold lwps in place (not cloning) */
4957c478bd9Sstevel@tonic-gate #define	SCOREDUMP  0x01000000	/* process is dumping core */
4967c478bd9Sstevel@tonic-gate #define	SMSACCT    0x02000000	/* process is keeping micro-state accounting */
4977c478bd9Sstevel@tonic-gate #define	SLWPWRAP   0x04000000	/* process has wrapped its lwp ids */
4987c478bd9Sstevel@tonic-gate #define	SAUTOLPG   0x08000000	/* kernel controls page sizes */
4997c478bd9Sstevel@tonic-gate #define	SNOCD	   0x10000000	/* new creds from VSxID, do not coredump */
5007c478bd9Sstevel@tonic-gate #define	SHOLDWATCH 0x20000000	/* hold lwps for watchpoint operation */
5017c478bd9Sstevel@tonic-gate #define	SMSFORK	   0x40000000	/* child inherits micro-state accounting */
5027c478bd9Sstevel@tonic-gate #define	SDOCORE	   0x80000000	/* process will attempt to dump core */
5037c478bd9Sstevel@tonic-gate 
5047c478bd9Sstevel@tonic-gate /*
5057c478bd9Sstevel@tonic-gate  * p_poolflag codes
5067c478bd9Sstevel@tonic-gate  *
5077c478bd9Sstevel@tonic-gate  * These flags are used to synchronize with the pool subsystem to allow
5087c478bd9Sstevel@tonic-gate  * re-binding of processes to new pools.
5097c478bd9Sstevel@tonic-gate  */
510c6939658Ssl #define	PBWAIT		0x0001  /* process should wait outside fork/exec/exit */
511c6939658Ssl #define	PEXITED		0x0002  /* process exited and about to become zombie */
5127c478bd9Sstevel@tonic-gate 
5137c478bd9Sstevel@tonic-gate /* Macro to convert proc pointer to a user block pointer */
5147c478bd9Sstevel@tonic-gate #define	PTOU(p)		(&(p)->p_user)
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate #define	tracing(p, sig)	(sigismember(&(p)->p_sigmask, sig))
5177c478bd9Sstevel@tonic-gate 
5187c478bd9Sstevel@tonic-gate /* Macro to reduce unnecessary calls to issig() */
5197c478bd9Sstevel@tonic-gate 
5207c478bd9Sstevel@tonic-gate #define	ISSIG(t, why)	ISSIG_FAST(t, ttolwp(t), ttoproc(t), why)
5217c478bd9Sstevel@tonic-gate 
5227c478bd9Sstevel@tonic-gate /*
5237c478bd9Sstevel@tonic-gate  * Fast version of ISSIG.
5247c478bd9Sstevel@tonic-gate  *	1. uses register pointers to lwp and proc instead of reloading them.
5257c478bd9Sstevel@tonic-gate  *	2. uses bit-wise OR of tests, since the usual case is that none of them
5267c478bd9Sstevel@tonic-gate  *	   are true, this saves orcc's and branches.
5277c478bd9Sstevel@tonic-gate  *	3. load the signal flags instead of using sigisempty() macro which does
5287c478bd9Sstevel@tonic-gate  *	   a branch to convert to boolean.
5297c478bd9Sstevel@tonic-gate  */
5307c478bd9Sstevel@tonic-gate #define	ISSIG_FAST(t, lwp, p, why)		\
5317c478bd9Sstevel@tonic-gate 	(ISSIG_PENDING(t, lwp, p) && issig(why))
5327c478bd9Sstevel@tonic-gate 
5337c478bd9Sstevel@tonic-gate #define	ISSIG_PENDING(t, lwp, p)		\
5347c478bd9Sstevel@tonic-gate 	((lwp)->lwp_cursig |			\
5357c478bd9Sstevel@tonic-gate 	    sigcheck((p), (t)) |		\
5367c478bd9Sstevel@tonic-gate 	    (p)->p_stopsig |			\
5377c478bd9Sstevel@tonic-gate 	    (t)->t_dtrace_stop |		\
5387c478bd9Sstevel@tonic-gate 	    (t)->t_dtrace_sig |			\
5397c478bd9Sstevel@tonic-gate 	    ((t)->t_proc_flag & (TP_PRSTOP|TP_HOLDLWP|TP_CHKPT|TP_PAUSE)) | \
5407c478bd9Sstevel@tonic-gate 	    ((p)->p_flag & (SEXITLWPS|SKILLED|SHOLDFORK1|SHOLDWATCH)))
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate #define	ISSTOP(sig)	 (u.u_signal[sig-1] == SIG_DFL && \
5437c478bd9Sstevel@tonic-gate 				sigismember(&stopdefault, sig))
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate #define	ISHOLD(p)	((p)->p_flag & SHOLDFORK)
5467c478bd9Sstevel@tonic-gate 
5477c478bd9Sstevel@tonic-gate #define	MUSTRETURN(p, t)	(ISHOLD(p) | (t)->t_activefd.a_stale)
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate /*
5507c478bd9Sstevel@tonic-gate  * Determine if there are any watchpoints active in the process.
5517c478bd9Sstevel@tonic-gate  */
5527c478bd9Sstevel@tonic-gate #define	pr_watch_active(p)	(avl_numnodes(&(p)->p_warea) != 0)
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate /* Reasons for calling issig() */
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate #define	FORREAL		0	/* Usual side-effects */
5577c478bd9Sstevel@tonic-gate #define	JUSTLOOKING	1	/* Don't stop the process */
5587c478bd9Sstevel@tonic-gate 
5597c478bd9Sstevel@tonic-gate /* 'what' values for stop(PR_SUSPENDED, what) */
5607c478bd9Sstevel@tonic-gate #define	SUSPEND_NORMAL	0
5617c478bd9Sstevel@tonic-gate #define	SUSPEND_PAUSE	1
5627c478bd9Sstevel@tonic-gate 
5637c478bd9Sstevel@tonic-gate /* pseudo-flag to lwp_create() */
5647c478bd9Sstevel@tonic-gate #define	NOCLASS	(-1)
5657c478bd9Sstevel@tonic-gate 
56635a5a358SJonathan Adams /* unused scheduling class ID */
56735a5a358SJonathan Adams #define	CLASS_UNUSED	(-2)
56835a5a358SJonathan Adams 
5697c478bd9Sstevel@tonic-gate /* LWP stats updated via lwp_stats_update() */
5707c478bd9Sstevel@tonic-gate typedef enum {
5717c478bd9Sstevel@tonic-gate 	LWP_STAT_INBLK,
5727c478bd9Sstevel@tonic-gate 	LWP_STAT_OUBLK,
5737c478bd9Sstevel@tonic-gate 	LWP_STAT_MSGRCV,
5747c478bd9Sstevel@tonic-gate 	LWP_STAT_MSGSND
5757c478bd9Sstevel@tonic-gate } lwp_stat_id_t;
5767c478bd9Sstevel@tonic-gate 
5777c478bd9Sstevel@tonic-gate #ifdef _KERNEL
5787c478bd9Sstevel@tonic-gate 
5797c478bd9Sstevel@tonic-gate /* user profiling functions */
5807c478bd9Sstevel@tonic-gate 
5817c478bd9Sstevel@tonic-gate extern void profil_tick(uintptr_t);
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate /* process management functions */
5847c478bd9Sstevel@tonic-gate 
58535a5a358SJonathan Adams extern int newproc(void (*)(), caddr_t, id_t, int, struct contract **, pid_t);
5867c478bd9Sstevel@tonic-gate extern void vfwait(pid_t);
5877c478bd9Sstevel@tonic-gate extern void proc_detach(proc_t *);
5887c478bd9Sstevel@tonic-gate extern void freeproc(proc_t *);
5897c478bd9Sstevel@tonic-gate extern void setrun(kthread_t *);
5907c478bd9Sstevel@tonic-gate extern void setrun_locked(kthread_t *);
5917c478bd9Sstevel@tonic-gate extern void exit(int, int);
5927c478bd9Sstevel@tonic-gate extern int proc_exit(int, int);
59397eda132Sraf extern void proc_is_exiting(proc_t *);
5947c478bd9Sstevel@tonic-gate extern void relvm(void);
5957c478bd9Sstevel@tonic-gate extern void add_ns(proc_t *, proc_t *);
5967c478bd9Sstevel@tonic-gate extern void delete_ns(proc_t *, proc_t *);
5977c478bd9Sstevel@tonic-gate extern void upcount_inc(uid_t, zoneid_t);
5987c478bd9Sstevel@tonic-gate extern void upcount_dec(uid_t, zoneid_t);
5997c478bd9Sstevel@tonic-gate extern int upcount_get(uid_t, zoneid_t);
6007c478bd9Sstevel@tonic-gate #if defined(__x86)
6017c478bd9Sstevel@tonic-gate extern selector_t setup_thrptr(proc_t *, uintptr_t);
602d8aa0f5aSsudheer extern void deferred_singlestep_trap(caddr_t);
6037c478bd9Sstevel@tonic-gate #endif
6047c478bd9Sstevel@tonic-gate 
6057c478bd9Sstevel@tonic-gate extern void sigcld(proc_t *, sigqueue_t *);
6067c478bd9Sstevel@tonic-gate extern void sigcld_delete(k_siginfo_t *);
6077c478bd9Sstevel@tonic-gate extern void sigcld_repost(void);
6087c478bd9Sstevel@tonic-gate extern int fsig(k_sigset_t *, kthread_t *);
6097c478bd9Sstevel@tonic-gate extern void psig(void);
6107c478bd9Sstevel@tonic-gate extern void stop(int, int);
6117c478bd9Sstevel@tonic-gate extern int stop_on_fault(uint_t, k_siginfo_t *);
6127c478bd9Sstevel@tonic-gate extern int issig(int);
6137c478bd9Sstevel@tonic-gate extern int jobstopped(proc_t *);
6147c478bd9Sstevel@tonic-gate extern void psignal(proc_t *, int);
6157c478bd9Sstevel@tonic-gate extern void tsignal(kthread_t *, int);
6167c478bd9Sstevel@tonic-gate extern void sigtoproc(proc_t *, kthread_t *, int);
6177c478bd9Sstevel@tonic-gate extern void trapsig(k_siginfo_t *, int);
618e0cf54a5SRoger A. Faulkner extern void realsigprof(int, int, int);
6197c478bd9Sstevel@tonic-gate extern int eat_signal(kthread_t *, int);
6207c478bd9Sstevel@tonic-gate extern int signal_is_blocked(kthread_t *, int);
6217c478bd9Sstevel@tonic-gate extern int sigcheck(proc_t *, kthread_t *);
6227c478bd9Sstevel@tonic-gate extern void sigdefault(proc_t *);
6237c478bd9Sstevel@tonic-gate 
6247c478bd9Sstevel@tonic-gate extern void pid_setmin(void);
62535a5a358SJonathan Adams extern pid_t pid_allocate(proc_t *, pid_t, int);
6267c478bd9Sstevel@tonic-gate extern int pid_rele(struct pid *);
6277c478bd9Sstevel@tonic-gate extern void pid_exit(proc_t *);
6287c478bd9Sstevel@tonic-gate extern void proc_entry_free(struct pid *);
6297c478bd9Sstevel@tonic-gate extern proc_t *prfind(pid_t);
6307c478bd9Sstevel@tonic-gate extern proc_t *prfind_zone(pid_t, zoneid_t);
6317c478bd9Sstevel@tonic-gate extern proc_t *pgfind(pid_t);
6327c478bd9Sstevel@tonic-gate extern proc_t *pgfind_zone(pid_t, zoneid_t);
6337c478bd9Sstevel@tonic-gate extern proc_t *sprlock(pid_t);
6347c478bd9Sstevel@tonic-gate extern proc_t *sprlock_zone(pid_t, zoneid_t);
6350209230bSgjelinek extern int sprtrylock_proc(proc_t *);
6360209230bSgjelinek extern void sprwaitlock_proc(proc_t *);
6377c478bd9Sstevel@tonic-gate extern void sprlock_proc(proc_t *);
6387c478bd9Sstevel@tonic-gate extern void sprunlock(proc_t *);
6397c478bd9Sstevel@tonic-gate extern void pid_init(void);
6407c478bd9Sstevel@tonic-gate extern proc_t *pid_entry(int);
6417c478bd9Sstevel@tonic-gate extern int pid_slot(proc_t *);
6427c478bd9Sstevel@tonic-gate extern void signal(pid_t, int);
6437c478bd9Sstevel@tonic-gate extern void prsignal(struct pid *, int);
6447c478bd9Sstevel@tonic-gate extern int uread(proc_t *, void *, size_t, uintptr_t);
6457c478bd9Sstevel@tonic-gate extern int uwrite(proc_t *, void *, size_t, uintptr_t);
6467c478bd9Sstevel@tonic-gate 
6477c478bd9Sstevel@tonic-gate extern void pgsignal(struct pid *, int);
6487c478bd9Sstevel@tonic-gate extern void pgjoin(proc_t *, struct pid *);
6497c478bd9Sstevel@tonic-gate extern void pgcreate(proc_t *);
6507c478bd9Sstevel@tonic-gate extern void pgexit(proc_t *);
6517c478bd9Sstevel@tonic-gate extern void pgdetach(proc_t *);
6527c478bd9Sstevel@tonic-gate extern int pgmembers(pid_t);
6537c478bd9Sstevel@tonic-gate 
6547c478bd9Sstevel@tonic-gate extern	void	init_mstate(kthread_t *, int);
6557c478bd9Sstevel@tonic-gate extern	int	new_mstate(kthread_t *, int);
6567c478bd9Sstevel@tonic-gate extern	void	restore_mstate(kthread_t *);
6577c478bd9Sstevel@tonic-gate extern	void	term_mstate(kthread_t *);
6587c478bd9Sstevel@tonic-gate extern	void	estimate_msacct(kthread_t *, hrtime_t);
6597c478bd9Sstevel@tonic-gate extern	void	disable_msacct(proc_t *);
6607c478bd9Sstevel@tonic-gate extern	hrtime_t mstate_aggr_state(proc_t *, int);
661c97ad5cdSakolb extern	hrtime_t mstate_thread_onproc_time(kthread_t *);
66235a5a358SJonathan Adams extern	void	mstate_systhread_times(kthread_t *, hrtime_t *, hrtime_t *);
6637c478bd9Sstevel@tonic-gate extern	void	syscall_mstate(int, int);
6647c478bd9Sstevel@tonic-gate 
6657c478bd9Sstevel@tonic-gate extern	uint_t	cpu_update_pct(kthread_t *, hrtime_t);
6667c478bd9Sstevel@tonic-gate 
6677c478bd9Sstevel@tonic-gate extern void	set_proc_pre_sys(proc_t *p);
6687c478bd9Sstevel@tonic-gate extern void	set_proc_post_sys(proc_t *p);
6697c478bd9Sstevel@tonic-gate extern void	set_proc_sys(proc_t *p);
6707c478bd9Sstevel@tonic-gate extern void	set_proc_ast(proc_t *p);
6717c478bd9Sstevel@tonic-gate extern void	set_all_proc_sys(void);
672005d3febSMarek Pospisil extern void	set_all_zone_usr_proc_sys(zoneid_t);
6737c478bd9Sstevel@tonic-gate 
6747c478bd9Sstevel@tonic-gate /* thread function prototypes */
6757c478bd9Sstevel@tonic-gate 
6767c478bd9Sstevel@tonic-gate extern	kthread_t	*thread_create(
6777c478bd9Sstevel@tonic-gate 	caddr_t		stk,
6787c478bd9Sstevel@tonic-gate 	size_t		stksize,
6797c478bd9Sstevel@tonic-gate 	void		(*proc)(),
6807c478bd9Sstevel@tonic-gate 	void		*arg,
6817c478bd9Sstevel@tonic-gate 	size_t		len,
6827c478bd9Sstevel@tonic-gate 	proc_t 		*pp,
6837c478bd9Sstevel@tonic-gate 	int		state,
6847c478bd9Sstevel@tonic-gate 	pri_t		pri);
6857c478bd9Sstevel@tonic-gate extern	void	thread_exit(void) __NORETURN;
6867c478bd9Sstevel@tonic-gate extern	void	thread_free(kthread_t *);
6877c478bd9Sstevel@tonic-gate extern	void	thread_rele(kthread_t *);
6887c478bd9Sstevel@tonic-gate extern	void	thread_join(kt_did_t);
6897c478bd9Sstevel@tonic-gate extern	int	reaper(void);
6907c478bd9Sstevel@tonic-gate extern	void	installctx(kthread_t *, void *, void (*)(), void (*)(),
6917c478bd9Sstevel@tonic-gate     void (*)(), void (*)(), void (*)(), void (*)());
6927c478bd9Sstevel@tonic-gate extern	int	removectx(kthread_t *, void *, void (*)(), void (*)(),
6937c478bd9Sstevel@tonic-gate     void (*)(), void (*)(), void (*)(), void (*)());
6947c478bd9Sstevel@tonic-gate extern	void	savectx(kthread_t *);
6957c478bd9Sstevel@tonic-gate extern	void	restorectx(kthread_t *);
6967c478bd9Sstevel@tonic-gate extern	void	forkctx(kthread_t *, kthread_t *);
6977c478bd9Sstevel@tonic-gate extern	void	lwp_createctx(kthread_t *, kthread_t *);
6987c478bd9Sstevel@tonic-gate extern	void	exitctx(kthread_t *);
6997c478bd9Sstevel@tonic-gate extern	void	freectx(kthread_t *, int);
7000baeff3dSrab extern	void	installpctx(proc_t *, void *, void (*)(), void (*)(),
7010baeff3dSrab     void (*)(), void (*)(), void (*)());
7020baeff3dSrab extern	int	removepctx(proc_t *, void *, void (*)(), void (*)(),
7030baeff3dSrab     void (*)(), void (*)(), void (*)());
7040baeff3dSrab extern	void	savepctx(proc_t *);
7050baeff3dSrab extern	void	restorepctx(proc_t *);
7060baeff3dSrab extern	void	forkpctx(proc_t *, proc_t *);
7070baeff3dSrab extern	void	exitpctx(proc_t *);
7080baeff3dSrab extern	void	freepctx(proc_t *, int);
7097c478bd9Sstevel@tonic-gate extern	kthread_t *thread_unpin(void);
7107c478bd9Sstevel@tonic-gate extern	void	thread_init(void);
7117c478bd9Sstevel@tonic-gate extern	void	thread_load(kthread_t *, void (*)(), caddr_t, size_t);
7127c478bd9Sstevel@tonic-gate 
7137c478bd9Sstevel@tonic-gate extern	void	tsd_create(uint_t *, void (*)(void *));
7147c478bd9Sstevel@tonic-gate extern	void	tsd_destroy(uint_t *);
7157c478bd9Sstevel@tonic-gate extern	void	*tsd_getcreate(uint_t *, void (*)(void *), void *(*)(void));
7167c478bd9Sstevel@tonic-gate extern	void	*tsd_get(uint_t);
7177c478bd9Sstevel@tonic-gate extern	int	tsd_set(uint_t, void *);
7187c478bd9Sstevel@tonic-gate extern	void	tsd_exit(void);
7197c478bd9Sstevel@tonic-gate extern	void	*tsd_agent_get(kthread_t *, uint_t);
7207c478bd9Sstevel@tonic-gate extern	int	tsd_agent_set(kthread_t *, uint_t, void *);
7217c478bd9Sstevel@tonic-gate 
7227c478bd9Sstevel@tonic-gate /* lwp function prototypes */
7237c478bd9Sstevel@tonic-gate 
72435a5a358SJonathan Adams extern kthread_t *lwp_kernel_create(proc_t *, void (*)(), void *, int, pri_t);
7257c478bd9Sstevel@tonic-gate extern	klwp_t 		*lwp_create(
7267c478bd9Sstevel@tonic-gate 	void		(*proc)(),
7277c478bd9Sstevel@tonic-gate 	caddr_t		arg,
7287c478bd9Sstevel@tonic-gate 	size_t		len,
7297c478bd9Sstevel@tonic-gate 	proc_t		*p,
7307c478bd9Sstevel@tonic-gate 	int		state,
7317c478bd9Sstevel@tonic-gate 	int		pri,
7327c478bd9Sstevel@tonic-gate 	const k_sigset_t *smask,
7337c478bd9Sstevel@tonic-gate 	int		cid,
7347c478bd9Sstevel@tonic-gate 	id_t		lwpid);
7357c478bd9Sstevel@tonic-gate extern	kthread_t *idtot(proc_t *, id_t);
7366eb30ec3SRoger A. Faulkner extern	void	lwp_hash_in(proc_t *, lwpent_t *, tidhash_t *, uint_t, int);
7377c478bd9Sstevel@tonic-gate extern	void	lwp_hash_out(proc_t *, id_t);
7387c478bd9Sstevel@tonic-gate extern	lwpdir_t *lwp_hash_lookup(proc_t *, id_t);
7396eb30ec3SRoger A. Faulkner extern	lwpdir_t *lwp_hash_lookup_and_lock(proc_t *, id_t, kmutex_t **);
7407c478bd9Sstevel@tonic-gate extern	void	lwp_create_done(kthread_t *);
7417c478bd9Sstevel@tonic-gate extern	void	lwp_exit(void);
7427c478bd9Sstevel@tonic-gate extern	void	lwp_pcb_exit(void);
7437c478bd9Sstevel@tonic-gate extern	void	lwp_cleanup(void);
7447c478bd9Sstevel@tonic-gate extern	int	lwp_suspend(kthread_t *);
7457c478bd9Sstevel@tonic-gate extern	void	lwp_continue(kthread_t *);
7467c478bd9Sstevel@tonic-gate extern	void	holdlwp(void);
7477c478bd9Sstevel@tonic-gate extern	void	stoplwp(void);
7487c478bd9Sstevel@tonic-gate extern	int	holdlwps(int);
7497c478bd9Sstevel@tonic-gate extern	int	holdwatch(void);
7507c478bd9Sstevel@tonic-gate extern	void	pokelwps(proc_t *);
7517c478bd9Sstevel@tonic-gate extern	void	continuelwps(proc_t *);
7527c478bd9Sstevel@tonic-gate extern	int	exitlwps(int);
7537c478bd9Sstevel@tonic-gate extern	void	lwp_ctmpl_copy(klwp_t *, klwp_t *);
7547c478bd9Sstevel@tonic-gate extern	void	lwp_ctmpl_clear(klwp_t *);
7557c478bd9Sstevel@tonic-gate extern	klwp_t	*forklwp(klwp_t *, proc_t *, id_t);
7567c478bd9Sstevel@tonic-gate extern	void	lwp_load(klwp_t *, gregset_t, uintptr_t);
7577c478bd9Sstevel@tonic-gate extern	void	lwp_setrval(klwp_t *, int, int);
7587c478bd9Sstevel@tonic-gate extern	void	lwp_forkregs(klwp_t *, klwp_t *);
7597c478bd9Sstevel@tonic-gate extern	void	lwp_freeregs(klwp_t *, int);
7607c478bd9Sstevel@tonic-gate extern	caddr_t	lwp_stk_init(klwp_t *, caddr_t);
761a8599265Selowe extern	void	lwp_stk_cache_init(void);
7627c478bd9Sstevel@tonic-gate extern	void	lwp_stk_fini(klwp_t *);
7637c478bd9Sstevel@tonic-gate extern	void	lwp_installctx(klwp_t *);
7647c478bd9Sstevel@tonic-gate extern	void	lwp_rtt(void);
7657c478bd9Sstevel@tonic-gate extern	void	lwp_rtt_initial(void);
7667c478bd9Sstevel@tonic-gate extern	int	lwp_setprivate(klwp_t *, int, uintptr_t);
7677c478bd9Sstevel@tonic-gate extern	void	lwp_stat_update(lwp_stat_id_t, long);
7689acbbeafSnn extern	void	lwp_attach_brand_hdlrs(klwp_t *);
769fd9e7635Sedp extern	void	lwp_detach_brand_hdlrs(klwp_t *);
7707c478bd9Sstevel@tonic-gate 
7712c5124a1SPrashanth Sreenivasa #if defined(__sparcv9)
7722c5124a1SPrashanth Sreenivasa extern	void	lwp_mmodel_newlwp(void);
7732c5124a1SPrashanth Sreenivasa extern	void	lwp_mmodel_shared_as(caddr_t, size_t);
7742c5124a1SPrashanth Sreenivasa #define	LWP_MMODEL_NEWLWP()		lwp_mmodel_newlwp()
7752c5124a1SPrashanth Sreenivasa #define	LWP_MMODEL_SHARED_AS(addr, sz)	lwp_mmodel_shared_as((addr), (sz))
7762c5124a1SPrashanth Sreenivasa #else
7772c5124a1SPrashanth Sreenivasa #define	LWP_MMODEL_NEWLWP()
7782c5124a1SPrashanth Sreenivasa #define	LWP_MMODEL_SHARED_AS(addr, sz)
7792c5124a1SPrashanth Sreenivasa #endif
7802c5124a1SPrashanth Sreenivasa 
7817c478bd9Sstevel@tonic-gate /*
7827c478bd9Sstevel@tonic-gate  * Signal queue function prototypes. Must be here due to header ordering
7837c478bd9Sstevel@tonic-gate  * dependencies.
7847c478bd9Sstevel@tonic-gate  */
7857c478bd9Sstevel@tonic-gate extern void sigqfree(proc_t *);
7867c478bd9Sstevel@tonic-gate extern void siginfofree(sigqueue_t *);
7877c478bd9Sstevel@tonic-gate extern void sigdeq(proc_t *, kthread_t *, int, sigqueue_t **);
7887c478bd9Sstevel@tonic-gate extern void sigdelq(proc_t *, kthread_t *, int);
7897c478bd9Sstevel@tonic-gate extern void sigaddq(proc_t *, kthread_t *, k_siginfo_t *, int);
7907c478bd9Sstevel@tonic-gate extern void sigaddqa(proc_t *, kthread_t *, sigqueue_t *);
7917c478bd9Sstevel@tonic-gate extern void sigqsend(int, proc_t *, kthread_t *, sigqueue_t *);
7927c478bd9Sstevel@tonic-gate extern void sigdupq(proc_t *, proc_t *);
7937c478bd9Sstevel@tonic-gate extern int sigwillqueue(int, int);
7947c478bd9Sstevel@tonic-gate extern sigqhdr_t *sigqhdralloc(size_t, uint_t);
7957c478bd9Sstevel@tonic-gate extern sigqueue_t *sigqalloc(sigqhdr_t *);
7967c478bd9Sstevel@tonic-gate extern void sigqhdrfree(sigqhdr_t *);
7977c478bd9Sstevel@tonic-gate extern sigqueue_t *sigappend(k_sigset_t *, sigqueue_t *,
7987c478bd9Sstevel@tonic-gate 	k_sigset_t *, sigqueue_t *);
7997c478bd9Sstevel@tonic-gate extern sigqueue_t *sigprepend(k_sigset_t *, sigqueue_t *,
8007c478bd9Sstevel@tonic-gate 	k_sigset_t *, sigqueue_t *);
8017c478bd9Sstevel@tonic-gate extern void winfo(proc_t *, k_siginfo_t *, int);
8027c478bd9Sstevel@tonic-gate extern int wstat(int, int);
8037c478bd9Sstevel@tonic-gate extern int sendsig(int, k_siginfo_t *, void (*)());
8047c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32_IMPL)
8057c478bd9Sstevel@tonic-gate extern int sendsig32(int, k_siginfo_t *, void (*)());
8067c478bd9Sstevel@tonic-gate #endif
8077c478bd9Sstevel@tonic-gate 
8087c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
8097c478bd9Sstevel@tonic-gate 
8107c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
8117c478bd9Sstevel@tonic-gate }
8127c478bd9Sstevel@tonic-gate #endif
8137c478bd9Sstevel@tonic-gate 
8147c478bd9Sstevel@tonic-gate #endif	/* _SYS_PROC_H */
815