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