xref: /illumos-gate/usr/src/lib/libfakekernel/common/sys/proc.h (revision 4c28a617e3922d92a58e813a5b955eb526b9c386)
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  * Copyright 2017 RackTop Systems.
26  */
27 
28 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
29 /*	  All Rights Reserved  	*/
30 
31 #ifndef _SYS_PROC_H
32 #define	_SYS_PROC_H
33 
34 #include <sys/time.h>
35 #include <sys/thread.h>
36 #include <sys/cred.h>
37 #include <sys/debug.h>
38 #include <sys/signal.h>
39 #include <sys/list.h>
40 #include <sys/avl.h>
41 #include <sys/refstr.h>
42 
43 #ifdef	__cplusplus
44 extern "C" {
45 #endif
46 
47 struct pool;
48 struct task;
49 struct zone;
50 
51 /*
52  * One structure allocated per active process.  It contains all
53  * data needed about the process while the process may be swapped
54  * out.  Other per-process data (user.h) is also inside the proc structure.
55  * Lightweight-process data (lwp.h) and the kernel stack may be swapped out.
56  */
57 typedef struct	proc {
58 
59 	struct	cred	*p_cred;	/* process credentials */
60 
61 	struct	pid 	*p_pidp;	/* process ID info */
62 	struct	pid 	*p_pgidp;	/* process group ID info */
63 
64 	/*
65 	 * Per process lwp and kernel thread stuff
66 	 */
67 
68 	struct zone	*p_zone;	/* zone in which process lives */
69 
70 	int do_not_use[10];
71 	int p_user[10];		/* (see sys/user.h) */
72 } proc_t;
73 
74 #define	PROC_T				/* headers relying on proc_t are OK */
75 
76 /* process ID info */
77 
78 struct pid {
79 	unsigned int pid_prinactive :1;
80 	unsigned int pid_pgorphaned :1;
81 	unsigned int pid_padding :6;	/* used to be pid_ref, now an int */
82 	unsigned int pid_prslot :24;
83 	pid_t pid_id;
84 	struct proc *pid_pglink;
85 	struct proc *pid_pgtail;
86 	struct pid *pid_link;
87 	uint_t pid_ref;
88 };
89 
90 #define	p_pgrp p_pgidp->pid_id
91 #define	p_pid  p_pidp->pid_id
92 #define	p_slot p_pidp->pid_prslot
93 #define	p_detached p_pgidp->pid_pgorphaned
94 
95 #define	PID_HOLD(pidp)	ASSERT(MUTEX_HELD(&pidlock)); \
96 			++(pidp)->pid_ref;
97 #define	PID_RELE(pidp)	ASSERT(MUTEX_HELD(&pidlock)); \
98 			(pidp)->pid_ref > 1 ? \
99 				--(pidp)->pid_ref : pid_rele(pidp);
100 
101 /*
102  * Structure containing persistent process lock.  The structure and
103  * macro allow "mutex_enter(&p->p_lock)" to continue working.
104  */
105 struct plock {
106 	kmutex_t pl_lock;
107 };
108 #define	p_lock	p_lockp->pl_lock
109 
110 extern proc_t p0;		/* process 0 */
111 extern struct plock p0lock;	/* p0's plock */
112 extern struct pid pid0;		/* p0's pid */
113 
114 extern int issig(int);
115 #define	ISSIG(thr, why)	issig(why)
116 
117 /* Reasons for calling issig() */
118 
119 #define	FORREAL		0	/* Usual side-effects */
120 #define	JUSTLOOKING	1	/* Don't stop the process */
121 
122 extern	void	tsd_create(uint_t *, void (*)(void *));
123 extern	void	tsd_destroy(uint_t *);
124 extern	void	*tsd_get(uint_t);
125 extern	int	tsd_set(uint_t, void *);
126 
127 /*
128  * This is normally in sunddi.h but
129  * I didn't want to drag that in here.
130  */
131 pid_t
132 ddi_get_pid(void);
133 
134 #ifdef	__cplusplus
135 }
136 #endif
137 
138 #endif	/* _SYS_PROC_H */
139