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 (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
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/debug.h>
37 #include <sys/signal.h>
38 #include <sys/list.h>
39 #include <sys/avl.h>
40 #include <sys/refstr.h>
41 
42 #ifdef	__cplusplus
43 extern "C" {
44 #endif
45 
46 struct pool;
47 struct task;
48 struct zone;
49 
50 /*
51  * One structure allocated per active process.  It contains all
52  * data needed about the process while the process may be swapped
53  * out.  Other per-process data (user.h) is also inside the proc structure.
54  * Lightweight-process data (lwp.h) and the kernel stack may be swapped out.
55  */
56 typedef struct	proc {
57 
58 	struct	cred	*p_cred;	/* process credentials */
59 
60 	struct	pid 	*p_pidp;	/* process ID info */
61 	struct	pid 	*p_pgidp;	/* process group ID info */
62 
63 	/*
64 	 * Per process lwp and kernel thread stuff
65 	 */
66 
67 	struct zone	*p_zone;	/* zone in which process lives */
68 
69 	int do_not_use[10];
70 	int p_user[10];		/* (see sys/user.h) */
71 } proc_t;
72 
73 #define	PROC_T				/* headers relying on proc_t are OK */
74 
75 /* process ID info */
76 
77 struct pid {
78 	unsigned int pid_prinactive :1;
79 	unsigned int pid_pgorphaned :1;
80 	unsigned int pid_padding :6;	/* used to be pid_ref, now an int */
81 	unsigned int pid_prslot :24;
82 	pid_t pid_id;
83 	struct proc *pid_pglink;
84 	struct proc *pid_pgtail;
85 	struct pid *pid_link;
86 	uint_t pid_ref;
87 };
88 
89 #define	p_pgrp p_pgidp->pid_id
90 #define	p_pid  p_pidp->pid_id
91 #define	p_slot p_pidp->pid_prslot
92 #define	p_detached p_pgidp->pid_pgorphaned
93 
94 #define	PID_HOLD(pidp)	ASSERT(MUTEX_HELD(&pidlock)); \
95 			++(pidp)->pid_ref;
96 #define	PID_RELE(pidp)	ASSERT(MUTEX_HELD(&pidlock)); \
97 			(pidp)->pid_ref > 1 ? \
98 				--(pidp)->pid_ref : pid_rele(pidp);
99 
100 /*
101  * Structure containing persistent process lock.  The structure and
102  * macro allow "mutex_enter(&p->p_lock)" to continue working.
103  */
104 struct plock {
105 	kmutex_t pl_lock;
106 };
107 #define	p_lock	p_lockp->pl_lock
108 
109 extern proc_t p0;		/* process 0 */
110 extern struct plock p0lock;	/* p0's plock */
111 extern struct pid pid0;		/* p0's pid */
112 
113 
114 /*
115  * This is normally in sunddi.h but
116  * I didn't want to drag that in here.
117  */
118 pid_t
119 ddi_get_pid(void);
120 
121 #ifdef	__cplusplus
122 }
123 #endif
124 
125 #endif	/* _SYS_PROC_H */
126