xref: /titanic_44/usr/src/lib/libfakekernel/common/sys/proc.h (revision b819cea2f73f98c5662230cc9affc8cc84f77fcf)
1*b819cea2SGordon Ross /*
2*b819cea2SGordon Ross  * CDDL HEADER START
3*b819cea2SGordon Ross  *
4*b819cea2SGordon Ross  * The contents of this file are subject to the terms of the
5*b819cea2SGordon Ross  * Common Development and Distribution License (the "License").
6*b819cea2SGordon Ross  * You may not use this file except in compliance with the License.
7*b819cea2SGordon Ross  *
8*b819cea2SGordon Ross  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*b819cea2SGordon Ross  * or http://www.opensolaris.org/os/licensing.
10*b819cea2SGordon Ross  * See the License for the specific language governing permissions
11*b819cea2SGordon Ross  * and limitations under the License.
12*b819cea2SGordon Ross  *
13*b819cea2SGordon Ross  * When distributing Covered Code, include this CDDL HEADER in each
14*b819cea2SGordon Ross  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*b819cea2SGordon Ross  * If applicable, add the following below this CDDL HEADER, with the
16*b819cea2SGordon Ross  * fields enclosed by brackets "[]" replaced with your own identifying
17*b819cea2SGordon Ross  * information: Portions Copyright [yyyy] [name of copyright owner]
18*b819cea2SGordon Ross  *
19*b819cea2SGordon Ross  * CDDL HEADER END
20*b819cea2SGordon Ross  */
21*b819cea2SGordon Ross 
22*b819cea2SGordon Ross /*
23*b819cea2SGordon Ross  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
24*b819cea2SGordon Ross  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
25*b819cea2SGordon Ross  */
26*b819cea2SGordon Ross 
27*b819cea2SGordon Ross /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*b819cea2SGordon Ross /*	  All Rights Reserved  	*/
29*b819cea2SGordon Ross 
30*b819cea2SGordon Ross #ifndef _SYS_PROC_H
31*b819cea2SGordon Ross #define	_SYS_PROC_H
32*b819cea2SGordon Ross 
33*b819cea2SGordon Ross #include <sys/time.h>
34*b819cea2SGordon Ross #include <sys/thread.h>
35*b819cea2SGordon Ross #include <sys/cred.h>
36*b819cea2SGordon Ross #include <sys/debug.h>
37*b819cea2SGordon Ross #include <sys/signal.h>
38*b819cea2SGordon Ross #include <sys/list.h>
39*b819cea2SGordon Ross #include <sys/avl.h>
40*b819cea2SGordon Ross #include <sys/refstr.h>
41*b819cea2SGordon Ross 
42*b819cea2SGordon Ross #ifdef	__cplusplus
43*b819cea2SGordon Ross extern "C" {
44*b819cea2SGordon Ross #endif
45*b819cea2SGordon Ross 
46*b819cea2SGordon Ross struct pool;
47*b819cea2SGordon Ross struct task;
48*b819cea2SGordon Ross struct zone;
49*b819cea2SGordon Ross 
50*b819cea2SGordon Ross /*
51*b819cea2SGordon Ross  * One structure allocated per active process.  It contains all
52*b819cea2SGordon Ross  * data needed about the process while the process may be swapped
53*b819cea2SGordon Ross  * out.  Other per-process data (user.h) is also inside the proc structure.
54*b819cea2SGordon Ross  * Lightweight-process data (lwp.h) and the kernel stack may be swapped out.
55*b819cea2SGordon Ross  */
56*b819cea2SGordon Ross typedef struct	proc {
57*b819cea2SGordon Ross 
58*b819cea2SGordon Ross 	struct	cred	*p_cred;	/* process credentials */
59*b819cea2SGordon Ross 
60*b819cea2SGordon Ross 	struct	pid 	*p_pidp;	/* process ID info */
61*b819cea2SGordon Ross 	struct	pid 	*p_pgidp;	/* process group ID info */
62*b819cea2SGordon Ross 
63*b819cea2SGordon Ross 	/*
64*b819cea2SGordon Ross 	 * Per process lwp and kernel thread stuff
65*b819cea2SGordon Ross 	 */
66*b819cea2SGordon Ross 
67*b819cea2SGordon Ross 	struct zone	*p_zone;	/* zone in which process lives */
68*b819cea2SGordon Ross 
69*b819cea2SGordon Ross 	int do_not_use[10];
70*b819cea2SGordon Ross 	int p_user[10];		/* (see sys/user.h) */
71*b819cea2SGordon Ross } proc_t;
72*b819cea2SGordon Ross 
73*b819cea2SGordon Ross #define	PROC_T				/* headers relying on proc_t are OK */
74*b819cea2SGordon Ross 
75*b819cea2SGordon Ross /* process ID info */
76*b819cea2SGordon Ross 
77*b819cea2SGordon Ross struct pid {
78*b819cea2SGordon Ross 	unsigned int pid_prinactive :1;
79*b819cea2SGordon Ross 	unsigned int pid_pgorphaned :1;
80*b819cea2SGordon Ross 	unsigned int pid_padding :6;	/* used to be pid_ref, now an int */
81*b819cea2SGordon Ross 	unsigned int pid_prslot :24;
82*b819cea2SGordon Ross 	pid_t pid_id;
83*b819cea2SGordon Ross 	struct proc *pid_pglink;
84*b819cea2SGordon Ross 	struct proc *pid_pgtail;
85*b819cea2SGordon Ross 	struct pid *pid_link;
86*b819cea2SGordon Ross 	uint_t pid_ref;
87*b819cea2SGordon Ross };
88*b819cea2SGordon Ross 
89*b819cea2SGordon Ross #define	p_pgrp p_pgidp->pid_id
90*b819cea2SGordon Ross #define	p_pid  p_pidp->pid_id
91*b819cea2SGordon Ross #define	p_slot p_pidp->pid_prslot
92*b819cea2SGordon Ross #define	p_detached p_pgidp->pid_pgorphaned
93*b819cea2SGordon Ross 
94*b819cea2SGordon Ross #define	PID_HOLD(pidp)	ASSERT(MUTEX_HELD(&pidlock)); \
95*b819cea2SGordon Ross 			++(pidp)->pid_ref;
96*b819cea2SGordon Ross #define	PID_RELE(pidp)	ASSERT(MUTEX_HELD(&pidlock)); \
97*b819cea2SGordon Ross 			(pidp)->pid_ref > 1 ? \
98*b819cea2SGordon Ross 				--(pidp)->pid_ref : pid_rele(pidp);
99*b819cea2SGordon Ross 
100*b819cea2SGordon Ross /*
101*b819cea2SGordon Ross  * Structure containing persistent process lock.  The structure and
102*b819cea2SGordon Ross  * macro allow "mutex_enter(&p->p_lock)" to continue working.
103*b819cea2SGordon Ross  */
104*b819cea2SGordon Ross struct plock {
105*b819cea2SGordon Ross 	kmutex_t pl_lock;
106*b819cea2SGordon Ross };
107*b819cea2SGordon Ross #define	p_lock	p_lockp->pl_lock
108*b819cea2SGordon Ross 
109*b819cea2SGordon Ross extern proc_t p0;		/* process 0 */
110*b819cea2SGordon Ross extern struct plock p0lock;	/* p0's plock */
111*b819cea2SGordon Ross extern struct pid pid0;		/* p0's pid */
112*b819cea2SGordon Ross 
113*b819cea2SGordon Ross 
114*b819cea2SGordon Ross /*
115*b819cea2SGordon Ross  * This is normally in sunddi.h but
116*b819cea2SGordon Ross  * I didn't want to drag that in here.
117*b819cea2SGordon Ross  */
118*b819cea2SGordon Ross pid_t
119*b819cea2SGordon Ross ddi_get_pid(void);
120*b819cea2SGordon Ross 
121*b819cea2SGordon Ross #ifdef	__cplusplus
122*b819cea2SGordon Ross }
123*b819cea2SGordon Ross #endif
124*b819cea2SGordon Ross 
125*b819cea2SGordon Ross #endif	/* _SYS_PROC_H */
126