]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/proc.h
161b7b1f37e4dcaf81403bc928ce2e9935cb6cd4
[apple/xnu.git] / bsd / sys / proc.h
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /* Copyright (c) 1995, 1997 Apple Computer, Inc. All Rights Reserved */
23 /*-
24 * Copyright (c) 1986, 1989, 1991, 1993
25 * The Regents of the University of California. All rights reserved.
26 * (c) UNIX System Laboratories, Inc.
27 * All or some portions of this file are derived from material licensed
28 * to the University of California by American Telephone and Telegraph
29 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
30 * the permission of UNIX System Laboratories, Inc.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 *
60 * @(#)proc.h 8.15 (Berkeley) 5/19/95
61 */
62
63 #ifndef _SYS_PROC_H_
64 #define _SYS_PROC_H_
65
66 #include <sys/appleapiopts.h>
67 #include <sys/cdefs.h>
68 #include <sys/select.h> /* For struct selinfo. */
69 #include <sys/queue.h>
70 #include <sys/lock.h>
71 #include <sys/param.h>
72 #include <sys/event.h>
73 #ifdef KERNEL
74 #include <sys/kernel_types.h>
75 #endif
76 #include <mach/boolean.h>
77
78 #ifdef XNU_KERNEL_PRIVATE
79 #define PROC_DEF_ENABLED
80 #else
81 #ifndef KERNEL
82 #define PROC_DEF_ENABLED
83 #endif
84 #endif
85
86 #ifdef PROC_DEF_ENABLED
87
88 struct session;
89 struct pgrp;
90 struct proc;
91
92 /* Exported fields for kern sysctls */
93 struct extern_proc {
94 union {
95 struct {
96 struct proc *__p_forw; /* Doubly-linked run/sleep queue. */
97 struct proc *__p_back;
98 } p_st1;
99 struct timeval __p_starttime; /* process start time */
100 } p_un;
101 #define p_forw p_un.p_st1.__p_forw
102 #define p_back p_un.p_st1.__p_back
103 #define p_starttime p_un.__p_starttime
104 struct vmspace *p_vmspace; /* Address space. */
105 struct sigacts *p_sigacts; /* Signal actions, state (PROC ONLY). */
106 int p_flag; /* P_* flags. */
107 char p_stat; /* S* process status. */
108 pid_t p_pid; /* Process identifier. */
109 pid_t p_oppid; /* Save parent pid during ptrace. XXX */
110 int p_dupfd; /* Sideways return value from fdopen. XXX */
111 /* Mach related */
112 caddr_t user_stack; /* where user stack was allocated */
113 void *exit_thread; /* XXX Which thread is exiting? */
114 int p_debugger; /* allow to debug */
115 boolean_t sigwait; /* indication to suspend */
116 /* scheduling */
117 u_int p_estcpu; /* Time averaged value of p_cpticks. */
118 int p_cpticks; /* Ticks of cpu time. */
119 fixpt_t p_pctcpu; /* %cpu for this process during p_swtime */
120 void *p_wchan; /* Sleep address. */
121 char *p_wmesg; /* Reason for sleep. */
122 u_int p_swtime; /* Time swapped in or out. */
123 u_int p_slptime; /* Time since last blocked. */
124 struct itimerval p_realtimer; /* Alarm timer. */
125 struct timeval p_rtime; /* Real time. */
126 u_quad_t p_uticks; /* Statclock hits in user mode. */
127 u_quad_t p_sticks; /* Statclock hits in system mode. */
128 u_quad_t p_iticks; /* Statclock hits processing intr. */
129 int p_traceflag; /* Kernel trace points. */
130 struct vnode *p_tracep; /* Trace to vnode. */
131 int p_siglist; /* DEPRECATED */
132 struct vnode *p_textvp; /* Vnode of executable. */
133 int p_holdcnt; /* If non-zero, don't swap. */
134 sigset_t p_sigmask; /* DEPRECATED. */
135 sigset_t p_sigignore; /* Signals being ignored. */
136 sigset_t p_sigcatch; /* Signals being caught by user. */
137 u_char p_priority; /* Process priority. */
138 u_char p_usrpri; /* User-priority based on p_cpu and p_nice. */
139 char p_nice; /* Process "nice" value. */
140 char p_comm[MAXCOMLEN+1];
141 struct pgrp *p_pgrp; /* Pointer to process group. */
142 struct user *p_addr; /* Kernel virtual addr of u-area (PROC ONLY). */
143 u_short p_xstat; /* Exit status for wait; also stop signal. */
144 u_short p_acflag; /* Accounting flags. */
145 struct rusage *p_ru; /* Exit information. XXX */
146 };
147
148
149 /* Status values. */
150 #define SIDL 1 /* Process being created by fork. */
151 #define SRUN 2 /* Currently runnable. */
152 #define SSLEEP 3 /* Sleeping on an address. */
153 #define SSTOP 4 /* Process debugging or suspension. */
154 #define SZOMB 5 /* Awaiting collection by parent. */
155
156 /* These flags are kept in p_flags. */
157 #define P_ADVLOCK 0x00000001 /* Process may hold POSIX adv. lock */
158 #define P_CONTROLT 0x00000002 /* Has a controlling terminal */
159 #define P_LP64 0x00000004 /* Process is LP64 */
160 #define P_NOCLDSTOP 0x00000008 /* No SIGCHLD when children stop */
161
162 #define P_PPWAIT 0x00000010 /* Parent waiting for chld exec/exit */
163 #define P_PROFIL 0x00000020 /* Has started profiling */
164 #define P_SELECT 0x00000040 /* Selecting; wakeup/waiting danger */
165 #define P_CONTINUED 0x00000080 /* Process was stopped and continued */
166
167 #define P_SUGID 0x00000100 /* Has set privileges since last exec */
168 #define P_SYSTEM 0x00000200 /* Sys proc: no sigs, stats or swap */
169 #define P_TIMEOUT 0x00000400 /* Timing out during sleep */
170 #define P_TRACED 0x00000800 /* Debugged process being traced */
171
172 #define P_WAITED 0x00001000 /* Debugging prc has waited for child */
173 #define P_WEXIT 0x00002000 /* Working on exiting. */
174 #define P_EXEC 0x00004000 /* Process called exec. */
175
176 /* Should be moved to machine-dependent areas. */
177 #define P_OWEUPC 0x00008000 /* Owe process an addupc() call at next ast. */
178
179 #define P_AFFINITY 0x00010000 /* xxx */
180 #define P_TRANSLATED 0x00020000 /* xxx */
181 #define P_CLASSIC P_TRANSLATED /* xxx */
182 /*
183 #define P_FSTRACE 0x10000 / * tracing via file system (elsewhere?) * /
184 #define P_SSTEP 0x20000 / * process needs single-step fixup ??? * /
185 */
186
187 #define P_WAITING 0x00040000 /* process has a wait() in progress */
188 #define P_KDEBUG 0x00080000 /* kdebug tracing on for this process */
189
190 #define P_TTYSLEEP 0x00100000 /* blocked due to SIGTTOU or SIGTTIN */
191 #define P_REBOOT 0x00200000 /* Process called reboot() */
192 #define P_TBE 0x00400000 /* Process is TBE */
193 #define P_SIGEXC 0x00800000 /* signal exceptions */
194
195 #define P_BTRACE 0x01000000 /* process is being branch traced */
196 #define P_VFORK 0x02000000 /* process has vfork children */
197 #define P_NOATTACH 0x04000000
198 #define P_INVFORK 0x08000000 /* proc in vfork */
199
200 #define P_NOSHLIB 0x10000000 /* no shared libs are in use for proc */
201 /* flag set on exec */
202 #define P_FORCEQUOTA 0x20000000 /* Force quota for root */
203 #define P_NOCLDWAIT 0x40000000 /* No zombies when chil procs exit */
204 #define P_NOREMOTEHANG 0x80000000 /* Don't hang on remote FS ops */
205
206 #define P_INMEM 0 /* Obsolete: retained for compilation */
207 #define P_NOSWAP 0 /* Obsolete: retained for compilation */
208 #define P_PHYSIO 0 /* Obsolete: retained for compilation */
209 #define P_FSTRACE 0 /* Obsolete: retained for compilation */
210 #define P_SSTEP 0 /* Obsolete: retained for compilation */
211
212 #endif /* PROC_DEF_ENABLED */
213
214 #ifdef KERNEL
215 __BEGIN_DECLS
216
217 extern proc_t kernproc;
218
219 extern int proc_is_classic(struct proc *p);
220 struct proc *current_proc_EXTERNAL(void);
221
222 extern int msleep(void *chan, lck_mtx_t *mtx, int pri, const char *wmesg, struct timespec * ts );
223 extern void unsleep(struct proc *);
224 extern void wakeup(void *chan);
225 extern void wakeup_one(caddr_t chan);
226
227 /* proc kpis */
228 /* this routine returns the pid of the current process */
229 extern int proc_selfpid(void);
230 /* this routine returns the pid of the parent of the current process */
231 extern int proc_selfppid(void);
232 /* this routine returns sends a signal signum to the process identified by the pid */
233 extern void proc_signal(int pid, int signum);
234 /* this routine checks whether any signal identified by the mask are pending in the process identified by the pid. The check is on all threads of the process. */
235 extern int proc_issignal(int pid, sigset_t mask);
236 /* this routine returns 1 if the pid1 is inferior of pid2 */
237 extern int proc_isinferior(int pid1, int pid2);
238 /* this routine copies the process's name of the executable to the passed in buffer. It
239 * is always null terminated. The size of the buffer is to be passed in as well. This
240 * routine is to be used typically for debugging
241 */
242 void proc_name(int pid, char * buf, int size);
243 /* This routine is simillar to proc_name except it returns for current process */
244 void proc_selfname(char * buf, int size);
245
246 /* find a process with a given pid. This comes with a reference which needs to be dropped by proc_rele */
247 extern proc_t proc_find(int pid);
248 /* returns a handle to current process which is referenced. The reference needs to be dropped with proc_rele */
249 extern proc_t proc_self(void);
250 /* releases the held reference on the process */
251 extern int proc_rele(proc_t p);
252 /* returns the pid of the given process */
253 extern int proc_pid(proc_t);
254 /* returns the pid of the parent of a given process */
255 extern int proc_ppid(proc_t);
256 /* returns 1 if the process is marked for no remote hangs */
257 extern int proc_noremotehang(proc_t);
258 /* returns 1 is the process is marked for force quota */
259 extern int proc_forcequota(proc_t);
260
261 /* this routine returns 1 if the process is running with 64bit address space, else 0 */
262 extern int proc_is64bit(proc_t);
263 /* is this process exiting? */
264 extern int proc_exiting(proc_t);
265 /* this routine returns error is the process is not one with super user privileges */
266 int proc_suser(struct proc *p);
267 /* returns the ucred assicaited with the process; temporary api */
268 struct ucred * proc_ucred(struct proc *p);
269
270 /* LP64todo - figure out how to identify 64-bit processes if NULL procp */
271 extern int IS_64BIT_PROCESS(proc_t);
272 extern int proc_pendingsignals(struct proc *, sigset_t);
273 extern int proc_tbe(struct proc *);
274
275 #ifdef KERNEL_PRIVATE
276 extern int tsleep(void *chan, int pri, const char *wmesg, int timo);
277 extern int msleep1(void *chan, lck_mtx_t *mtx, int pri, const char *wmesg, u_int64_t timo);
278 #endif
279
280 __END_DECLS
281
282 #endif /* KERNEL */
283
284 #endif /* !_SYS_PROC_H_ */