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