1 /*
2  * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
6  * This file contains Original Code and/or Modifications of Original Code
7  * as defined in and that are subject to the Apple Public Source License
8  * Version 2.0 (the 'License'). You may not use this file except in
9  * compliance with the License. The rights granted to you under the License
10  * may not be used to create, or enable the creation or redistribution of,
11  * unlawful or unlicensed copies of an Apple operating system, or to
12  * circumvent, violate, or enable the circumvention or violation of, any
13  * terms of an Apple operating system software license agreement.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
18  * The Original Code and all software distributed under the License are
19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23  * Please see the License for the specific language governing rights and
24  * limitations under the License.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 /* Copyright (c) 1995, 1997 Apple Computer, Inc. All Rights Reserved */
29 /*-
30  * Copyright (c) 1986, 1989, 1991, 1993
31  *	The Regents of the University of California.  All rights reserved.
32  * (c) UNIX System Laboratories, Inc.
33  * All or some portions of this file are derived from material licensed
34  * to the University of California by American Telephone and Telegraph
35  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
36  * the permission of UNIX System Laboratories, Inc.
37  *
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions
40  * are met:
41  * 1. Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  * 2. Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in the
45  *    documentation and/or other materials provided with the distribution.
46  * 3. All advertising materials mentioning features or use of this software
47  *    must display the following acknowledgement:
48  *	This product includes software developed by the University of
49  *	California, Berkeley and its contributors.
50  * 4. Neither the name of the University nor the names of its contributors
51  *    may be used to endorse or promote products derived from this software
52  *    without specific prior written permission.
53  *
54  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64  * SUCH DAMAGE.
65  *
66  *	@(#)proc.h	8.15 (Berkeley) 5/19/95
67  */
68 
69 #ifndef _SYS_PROC_H_
70 #define _SYS_PROC_H_
71 
72 #include <sys/appleapiopts.h>
73 #include <sys/cdefs.h>
74 #include <sys/select.h>                 /* For struct selinfo. */
75 #include <sys/queue.h>
76 #include <sys/lock.h>
77 #include <sys/param.h>
78 #include <sys/event.h>
79 #include <sys/time.h>
80 #include <mach/boolean.h>
81 
82 
83 
84 struct session;
85 struct pgrp;
86 struct proc;
87 
88 /* Exported fields for kern sysctls */
89 struct extern_proc {
90 	union {
91 		struct {
92 			struct  proc *__p_forw; /* Doubly-linked run/sleep queue. */
93 			struct  proc *__p_back;
94 		} p_st1;
95 		struct timeval __p_starttime;   /* process start time */
96 	} p_un;
97 #define p_forw p_un.p_st1.__p_forw
98 #define p_back p_un.p_st1.__p_back
99 #define p_starttime p_un.__p_starttime
100 	struct  vmspace *p_vmspace;     /* Address space. */
101 	struct  sigacts *p_sigacts;     /* Signal actions, state (PROC ONLY). */
102 	int     p_flag;                 /* P_* flags. */
103 	char    p_stat;                 /* S* process status. */
104 	pid_t   p_pid;                  /* Process identifier. */
105 	pid_t   p_oppid;         /* Save parent pid during ptrace. XXX */
106 	int     p_dupfd;         /* Sideways return value from fdopen. XXX */
107 	/* Mach related  */
108 	caddr_t user_stack;     /* where user stack was allocated */
109 	void    *exit_thread;   /* XXX Which thread is exiting? */
110 	int             p_debugger;             /* allow to debug */
111 	boolean_t       sigwait;        /* indication to suspend */
112 	/* scheduling */
113 	u_int   p_estcpu;        /* Time averaged value of p_cpticks. */
114 	int     p_cpticks;       /* Ticks of cpu time. */
115 	fixpt_t p_pctcpu;        /* %cpu for this process during p_swtime */
116 	void    *p_wchan;        /* Sleep address. */
117 	char    *p_wmesg;        /* Reason for sleep. */
118 	u_int   p_swtime;        /* Time swapped in or out. */
119 	u_int   p_slptime;       /* Time since last blocked. */
120 	struct  itimerval p_realtimer;  /* Alarm timer. */
121 	struct  timeval p_rtime;        /* Real time. */
122 	u_quad_t p_uticks;              /* Statclock hits in user mode. */
123 	u_quad_t p_sticks;              /* Statclock hits in system mode. */
124 	u_quad_t p_iticks;              /* Statclock hits processing intr. */
125 	int     p_traceflag;            /* Kernel trace points. */
126 	struct  vnode *p_tracep;        /* Trace to vnode. */
127 	int     p_siglist;              /* DEPRECATED. */
128 	struct  vnode *p_textvp;        /* Vnode of executable. */
129 	int     p_holdcnt;              /* If non-zero, don't swap. */
130 	sigset_t p_sigmask;     /* DEPRECATED. */
131 	sigset_t p_sigignore;   /* Signals being ignored. */
132 	sigset_t p_sigcatch;    /* Signals being caught by user. */
133 	u_char  p_priority;     /* Process priority. */
134 	u_char  p_usrpri;       /* User-priority based on p_cpu and p_nice. */
135 	char    p_nice;         /* Process "nice" value. */
136 	char    p_comm[MAXCOMLEN + 1];
137 	struct  pgrp *p_pgrp;   /* Pointer to process group. */
138 	struct  user *p_addr;   /* Kernel virtual addr of u-area (PROC ONLY). */
139 	u_short p_xstat;        /* Exit status for wait; also stop signal. */
140 	u_short p_acflag;       /* Accounting flags. */
141 	struct  rusage *p_ru;   /* Exit information. XXX */
142 };
143 
144 
145 /* Status values. */
146 #define SIDL    1               /* Process being created by fork. */
147 #define SRUN    2               /* Currently runnable. */
148 #define SSLEEP  3               /* Sleeping on an address. */
149 #define SSTOP   4               /* Process debugging or suspension. */
150 #define SZOMB   5               /* Awaiting collection by parent. */
151 
152 /* These flags are kept in extern_proc.p_flag. */
153 #define P_ADVLOCK       0x00000001      /* Process may hold POSIX adv. lock */
154 #define P_CONTROLT      0x00000002      /* Has a controlling terminal */
155 #define P_LP64          0x00000004      /* Process is LP64 */
156 #define P_NOCLDSTOP     0x00000008      /* No SIGCHLD when children stop */
157 
158 #define P_PPWAIT        0x00000010      /* Parent waiting for chld exec/exit */
159 #define P_PROFIL        0x00000020      /* Has started profiling */
160 #define P_SELECT        0x00000040      /* Selecting; wakeup/waiting danger */
161 #define P_CONTINUED     0x00000080      /* Process was stopped and continued */
162 
163 #define P_SUGID         0x00000100      /* Has set privileges since last exec */
164 #define P_SYSTEM        0x00000200      /* Sys proc: no sigs, stats or swap */
165 #define P_TIMEOUT       0x00000400      /* Timing out during sleep */
166 #define P_TRACED        0x00000800      /* Debugged process being traced */
167 
168 #define P_DISABLE_ASLR  0x00001000      /* Disable address space layout randomization */
169 #define P_WEXIT         0x00002000      /* Working on exiting */
170 #define P_EXEC          0x00004000      /* Process called exec. */
171 
172 /* Should be moved to machine-dependent areas. */
173 #define P_OWEUPC        0x00008000      /* Owe process an addupc() call at next ast. */
174 
175 #define P_AFFINITY      0x00010000      /* xxx */
176 #define P_TRANSLATED    0x00020000      /* xxx */
177 #define P_CLASSIC       P_TRANSLATED    /* xxx */
178 
179 #define P_DELAYIDLESLEEP 0x00040000     /* Process is marked to delay idle sleep on disk IO */
180 #define P_CHECKOPENEVT  0x00080000      /* check if a vnode has the OPENEVT flag set on open */
181 
182 #define P_DEPENDENCY_CAPABLE    0x00100000      /* process is ok to call vfs_markdependency() */
183 #define P_REBOOT        0x00200000      /* Process called reboot() */
184 #define P_RESV6         0x00400000      /* used to be P_TBE */
185 #define P_RESV7         0x00800000      /* (P_SIGEXC)signal exceptions */
186 
187 #define P_THCWD         0x01000000      /* process has thread cwd  */
188 #define P_RESV9         0x02000000      /* (P_VFORK)process has vfork children */
189 #define P_ADOPTPERSONA  0x04000000      /* process adopted a persona (used to be P_NOATTACH) */
190 #define P_RESV11        0x08000000      /* (P_INVFORK) proc in vfork */
191 
192 #define P_NOSHLIB       0x10000000      /* no shared libs are in use for proc */
193                                         /* flag set on exec */
194 #define P_FORCEQUOTA    0x20000000      /* Force quota for root */
195 #define P_NOCLDWAIT     0x40000000      /* No zombies when chil procs exit */
196 #define P_NOREMOTEHANG  0x80000000      /* Don't hang on remote FS ops */
197 
198 #define P_INMEM         0               /* Obsolete: retained for compilation */
199 #define P_NOSWAP        0               /* Obsolete: retained for compilation */
200 #define P_PHYSIO        0               /* Obsolete: retained for compilation */
201 #define P_FSTRACE       0               /* Obsolete: retained for compilation */
202 #define P_SSTEP         0               /* Obsolete: retained for compilation */
203 
204 #define P_DIRTY_TRACK                           0x00000001      /* track dirty state */
205 #define P_DIRTY_ALLOW_IDLE_EXIT                 0x00000002      /* process can be idle-exited when clean */
206 #define P_DIRTY_DEFER                           0x00000004      /* defer initial opt-in to idle-exit */
207 #define P_DIRTY                                 0x00000008      /* process is dirty */
208 #define P_DIRTY_SHUTDOWN                        0x00000010      /* process is dirty during shutdown */
209 #define P_DIRTY_TERMINATED                      0x00000020      /* process has been marked for termination */
210 #define P_DIRTY_BUSY                            0x00000040      /* serialization flag */
211 #define P_DIRTY_MARKED                          0x00000080      /* marked dirty previously */
212 #define P_DIRTY_AGING_IN_PROGRESS               0x00000100      /* aging in one of the 'aging bands' */
213 #define P_DIRTY_LAUNCH_IN_PROGRESS              0x00000200      /* launch is in progress */
214 #define P_DIRTY_DEFER_ALWAYS                    0x00000400      /* defer going to idle-exit after every dirty->clean transition.
215 	                                                         * For legacy jetsam policy only. This is the default with the other policies.*/
216 
217 #define P_DIRTY_IS_DIRTY                        (P_DIRTY | P_DIRTY_SHUTDOWN)
218 #define P_DIRTY_IDLE_EXIT_ENABLED               (P_DIRTY_TRACK|P_DIRTY_ALLOW_IDLE_EXIT)
219 
220 
221 
222 
223 #endif  /* !_SYS_PROC_H_ */