]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/proc.h
2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* Copyright (c) 1995, 1997 Apple Computer, Inc. All Rights Reserved */
27 * Copyright (c) 1986, 1989, 1991, 1993
28 * The Regents of the University of California. All rights reserved.
29 * (c) UNIX System Laboratories, Inc.
30 * All or some portions of this file are derived from material licensed
31 * to the University of California by American Telephone and Telegraph
32 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
33 * the permission of UNIX System Laboratories, Inc.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. All advertising materials mentioning features or use of this software
44 * must display the following acknowledgement:
45 * This product includes software developed by the University of
46 * California, Berkeley and its contributors.
47 * 4. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * @(#)proc.h 8.15 (Berkeley) 5/19/95
69 #include <sys/appleapiopts.h>
70 #include <sys/cdefs.h>
71 #include <sys/select.h> /* For struct selinfo. */
72 #include <sys/queue.h>
74 #include <sys/param.h>
75 #include <sys/event.h>
76 #include <sys/audit.h>
78 #ifdef __APPLE_API_PRIVATE
81 * One structure allocated per session.
84 int s_count
; /* Ref cnt; pgrps in session. */
85 struct proc
*s_leader
; /* Session leader. */
86 struct vnode
*s_ttyvp
; /* Vnode of controlling terminal. */
87 struct tty
*s_ttyp
; /* Controlling terminal. */
88 pid_t s_sid
; /* Session ID */
89 char s_login
[MAXLOGNAME
]; /* Setlogin() name. */
93 * One structure allocated per process group.
96 LIST_ENTRY(pgrp
) pg_hash
; /* Hash chain. */
97 LIST_HEAD(, proc
) pg_members
; /* Pointer to pgrp members. */
98 struct session
*pg_session
; /* Pointer to session. */
99 pid_t pg_id
; /* Pgrp id. */
100 int pg_jobc
; /* # procs qualifying pgrp for job control */
104 * Description of a process.
106 * This structure contains the information needed to manage a thread of
107 * control, known in UN*X as a process; it has references to substructures
108 * containing descriptions of things that the process uses, but may share
109 * with related processes. The process structure and the substructures
110 * are always addressible except for those marked "(PROC ONLY)" below,
111 * which might be addressible only on a processor on which the process
115 LIST_ENTRY(proc
) p_list
; /* List of all processes. */
118 struct pcred
*p_cred
; /* Process owner's identity. */
119 struct filedesc
*p_fd
; /* Ptr to open files structure. */
120 struct pstats
*p_stats
; /* Accounting/statistics (PROC ONLY). */
121 struct plimit
*p_limit
; /* Process limits. */
122 struct sigacts
*p_sigacts
; /* Signal actions, state (PROC ONLY). */
124 #define p_ucred p_cred->pc_ucred
125 #define p_rlimit p_limit->pl_rlimit
127 int p_flag
; /* P_* flags. */
128 char p_stat
; /* S* process status. */
131 pid_t p_pid
; /* Process identifier. */
132 LIST_ENTRY(proc
) p_pglist
; /* List of processes in pgrp. */
133 struct proc
*p_pptr
; /* Pointer to parent process. */
134 LIST_ENTRY(proc
) p_sibling
; /* List of sibling processes. */
135 LIST_HEAD(, proc
) p_children
; /* Pointer to list of children. */
137 /* The following fields are all zeroed upon creation in fork. */
138 #define p_startzero p_oppid
140 pid_t p_oppid
; /* Save parent pid during ptrace. XXX */
141 int p_dupfd
; /* Sideways return value from fdopen. XXX */
144 u_int p_estcpu
; /* Time averaged value of p_cpticks. */
145 int p_cpticks
; /* Ticks of cpu time. */
146 fixpt_t p_pctcpu
; /* %cpu for this process during p_swtime */
147 void *p_wchan
; /* Sleep address. */
148 char *p_wmesg
; /* Reason for sleep. */
149 u_int p_swtime
; /* DEPRECATED (Time swapped in or out.) */
150 #define p_argslen p_swtime /* Length of process arguments. */
151 u_int p_slptime
; /* Time since last blocked. */
153 struct itimerval p_realtimer
; /* Alarm timer. */
154 struct timeval p_rtime
; /* Real time. */
155 u_quad_t p_uticks
; /* Statclock hits in user mode. */
156 u_quad_t p_sticks
; /* Statclock hits in system mode. */
157 u_quad_t p_iticks
; /* Statclock hits processing intr. */
159 int p_traceflag
; /* Kernel trace points. */
160 struct vnode
*p_tracep
; /* Trace to vnode. */
162 sigset_t p_siglist
; /* DEPRECATED. */
164 struct vnode
*p_textvp
; /* Vnode of executable. */
166 /* End area that is zeroed on creation. */
167 #define p_endzero p_hash.le_next
170 * Not copied, not zero'ed.
171 * Belongs after p_pid, but here to avoid shifting proc elements.
173 LIST_ENTRY(proc
) p_hash
; /* Hash chain. */
174 TAILQ_HEAD( ,eventqelt
) p_evlist
;
176 /* The following fields are all copied upon creation in fork. */
177 #define p_startcopy p_sigmask
179 sigset_t p_sigmask
; /* DEPRECATED */
180 sigset_t p_sigignore
; /* Signals being ignored. */
181 sigset_t p_sigcatch
; /* Signals being caught by user. */
183 u_char p_priority
; /* Process priority. */
184 u_char p_usrpri
; /* User-priority based on p_cpu and p_nice. */
185 char p_nice
; /* Process "nice" value. */
186 char p_comm
[MAXCOMLEN
+1];
188 struct pgrp
*p_pgrp
; /* Pointer to process group. */
190 /* End area that is copied on creation. */
191 #define p_endcopy p_xstat
193 u_short p_xstat
; /* Exit status for wait; also stop signal. */
194 u_short p_acflag
; /* Accounting flags. */
195 struct rusage
*p_ru
; /* Exit information. XXX */
197 int p_debugger
; /* 1: can exec set-bit programs if suser */
199 void *task
; /* corresponding task */
200 void *sigwait_thread
; /* 'thread' holding sigwait */
201 struct lock__bsd__ signal_lock
; /* multilple thread prot for signals*/
202 boolean_t sigwait
; /* indication to suspend */
203 void *exit_thread
; /* Which thread is exiting? */
204 caddr_t user_stack
; /* where user stack was allocated */
205 void * exitarg
; /* exit arg for proc terminate */
206 void * vm_shm
; /* for sysV shared memory */
207 int p_argc
; /* saved argc for sysctl_procargs() */
208 int p_vforkcnt
; /* number of outstanding vforks */
209 void * p_vforkact
; /* activation running this vfork proc */
210 TAILQ_HEAD( , uthread
) p_uthlist
; /* List of uthreads */
211 /* Following fields are info from SIGCHLD */
216 TAILQ_HEAD( , aio_workq_entry
) aio_activeq
; /* active async IO requests */
217 int aio_active_count
; /* entries on aio_activeq */
218 TAILQ_HEAD( , aio_workq_entry
) aio_doneq
; /* completed async IO requests */
219 int aio_done_count
; /* entries on aio_doneq */
221 struct klist p_klist
; /* knote list */
222 struct auditinfo
*p_au
; /* User auditing data */
225 unsigned int lockpc
[8];
226 unsigned int unlockpc
[8];
227 #endif /* SIGNAL_DEBUG */
228 #endif /* DIAGNOSTIC */
231 #else /* !__APPLE_API_PRIVATE */
235 #endif /* !__APPLE_API_PRIVATE */
237 #ifdef __APPLE_API_UNSTABLE
238 /* Exported fields for kern sysctls */
242 struct proc
*__p_forw
; /* Doubly-linked run/sleep queue. */
243 struct proc
*__p_back
;
245 struct timeval __p_starttime
; /* process start time */
247 #define p_forw p_un.p_st1.__p_forw
248 #define p_back p_un.p_st1.__p_back
249 #define p_starttime p_un.__p_starttime
250 struct vmspace
*p_vmspace
; /* Address space. */
251 struct sigacts
*p_sigacts
; /* Signal actions, state (PROC ONLY). */
252 int p_flag
; /* P_* flags. */
253 char p_stat
; /* S* process status. */
254 pid_t p_pid
; /* Process identifier. */
255 pid_t p_oppid
; /* Save parent pid during ptrace. XXX */
256 int p_dupfd
; /* Sideways return value from fdopen. XXX */
258 caddr_t user_stack
; /* where user stack was allocated */
259 void *exit_thread
; /* XXX Which thread is exiting? */
260 int p_debugger
; /* allow to debug */
261 boolean_t sigwait
; /* indication to suspend */
263 u_int p_estcpu
; /* Time averaged value of p_cpticks. */
264 int p_cpticks
; /* Ticks of cpu time. */
265 fixpt_t p_pctcpu
; /* %cpu for this process during p_swtime */
266 void *p_wchan
; /* Sleep address. */
267 char *p_wmesg
; /* Reason for sleep. */
268 u_int p_swtime
; /* Time swapped in or out. */
269 u_int p_slptime
; /* Time since last blocked. */
270 struct itimerval p_realtimer
; /* Alarm timer. */
271 struct timeval p_rtime
; /* Real time. */
272 u_quad_t p_uticks
; /* Statclock hits in user mode. */
273 u_quad_t p_sticks
; /* Statclock hits in system mode. */
274 u_quad_t p_iticks
; /* Statclock hits processing intr. */
275 int p_traceflag
; /* Kernel trace points. */
276 struct vnode
*p_tracep
; /* Trace to vnode. */
277 int p_siglist
; /* DEPRECATED */
278 struct vnode
*p_textvp
; /* Vnode of executable. */
279 int p_holdcnt
; /* If non-zero, don't swap. */
280 sigset_t p_sigmask
; /* DEPRECATED. */
281 sigset_t p_sigignore
; /* Signals being ignored. */
282 sigset_t p_sigcatch
; /* Signals being caught by user. */
283 u_char p_priority
; /* Process priority. */
284 u_char p_usrpri
; /* User-priority based on p_cpu and p_nice. */
285 char p_nice
; /* Process "nice" value. */
286 char p_comm
[MAXCOMLEN
+1];
287 struct pgrp
*p_pgrp
; /* Pointer to process group. */
288 struct user
*p_addr
; /* Kernel virtual addr of u-area (PROC ONLY). */
289 u_short p_xstat
; /* Exit status for wait; also stop signal. */
290 u_short p_acflag
; /* Accounting flags. */
291 struct rusage
*p_ru
; /* Exit information. XXX */
294 #define p_session p_pgrp->pg_session
295 #define p_pgid p_pgrp->pg_id
298 #define SIDL 1 /* Process being created by fork. */
299 #define SRUN 2 /* Currently runnable. */
300 #define SSLEEP 3 /* Sleeping on an address. */
301 #define SSTOP 4 /* Process debugging or suspension. */
302 #define SZOMB 5 /* Awaiting collection by parent. */
304 /* These flags are kept in p_flags. */
305 #define P_ADVLOCK 0x00001 /* Process may hold a POSIX advisory lock. */
306 #define P_CONTROLT 0x00002 /* Has a controlling terminal. */
307 #define P_INMEM 0x00004 /* Loaded into memory. */
308 #define P_NOCLDSTOP 0x00008 /* No SIGCHLD when children stop. */
309 #define P_PPWAIT 0x00010 /* Parent is waiting for child to exec/exit. */
310 #define P_PROFIL 0x00020 /* Has started profiling. */
311 #define P_SELECT 0x00040 /* Selecting; wakeup/waiting danger. */
312 #define P_SINTR 0x00080 /* Sleep is interruptible. */
313 #define P_SUGID 0x00100 /* Had set id privileges since last exec. */
314 #define P_SYSTEM 0x00200 /* System proc: no sigs, stats or swapping. */
315 #define P_TIMEOUT 0x00400 /* Timing out during sleep. */
316 #define P_TRACED 0x00800 /* Debugged process being traced. */
317 #define P_WAITED 0x01000 /* Debugging process has waited for child. */
318 #define P_WEXIT 0x02000 /* Working on exiting. */
319 #define P_EXEC 0x04000 /* Process called exec. */
321 /* Should be moved to machine-dependent areas. */
322 #define P_OWEUPC 0x08000 /* Owe process an addupc() call at next ast. */
324 #define P_AFFINITY 0x0010000 /* xxx */
325 #define P_CLASSIC 0x0020000 /* xxx */
327 #define P_FSTRACE 0x10000 / * tracing via file system (elsewhere?) * /
328 #define P_SSTEP 0x20000 / * process needs single-step fixup ??? * /
331 #define P_WAITING 0x0040000 /* process has a wait() in progress */
332 #define P_KDEBUG 0x0080000 /* kdebug tracing is on for this process */
333 #define P_TTYSLEEP 0x0100000 /* blocked due to SIGTTOU or SIGTTIN */
334 #define P_REBOOT 0x0200000 /* Process called reboot() */
335 #define P_TBE 0x0400000 /* Process is TBE */
336 #define P_SIGEXC 0x0800000 /* signal exceptions */
337 #define P_BTRACE 0x1000000 /* process is being branch traced */
338 #define P_VFORK 0x2000000 /* process has vfork children */
339 #define P_NOATTACH 0x4000000
340 #define P_INVFORK 0x8000000 /* proc in vfork */
341 #define P_NOSHLIB 0x10000000 /* no shared libs are in use for proc */
342 /* flag set on exec */
343 #define P_FORCEQUOTA 0x20000000 /* Force quota for root */
344 #define P_NOCLDWAIT 0x40000000 /* No zombies when chil procs exit */
345 #define P_NOREMOTEHANG 0x80000000 /* Don't hang on remote FS ops */
347 #define P_NOSWAP 0 /* Obsolete: retained so that nothing breaks */
348 #define P_PHYSIO 0 /* Obsolete: retained so that nothing breaks */
349 #define P_FSTRACE 0 /* Obsolete: retained so that nothing breaks */
350 #define P_SSTEP 0 /* Obsolete: retained so that nothing breaks */
353 * Shareable process credentials (always resident). This includes a reference
354 * to the current user credentials as well as real and saved ids that may be
355 * used to change ids.
358 struct lock__bsd__ pc_lock
;
359 struct ucred
*pc_ucred
; /* Current credentials. */
360 uid_t p_ruid
; /* Real user id. */
361 uid_t p_svuid
; /* Saved effective user id. */
362 gid_t p_rgid
; /* Real group id. */
363 gid_t p_svgid
; /* Saved effective group id. */
364 int p_refcnt
; /* Number of references. */
367 #define pcred_readlock(p) lockmgr(&(p)->p_cred->pc_lock, \
369 #define pcred_writelock(p) lockmgr(&(p)->p_cred->pc_lock, \
370 LK_EXCLUSIVE, 0, (p))
371 #define pcred_unlock(p) lockmgr(&(p)->p_cred->pc_lock, \
373 #endif /* __APPLE_API_UNSTABLE */
378 #ifdef __APPLE_API_PRIVATE
380 * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
381 * as it is used to represent "no process group".
383 extern int nprocs
, maxproc
; /* Current and max number of procs. */
384 __private_extern__
int hard_maxproc
; /* hard limit */
386 #define PID_MAX 30000
389 #define SESS_LEADER(p) ((p)->p_session->s_leader == (p))
390 #define SESSHOLD(s) ((s)->s_count++)
391 #define SESSRELE(s) sessrele(s)
393 #define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash])
394 extern LIST_HEAD(pidhashhead
, proc
) *pidhashtbl
;
395 extern u_long pidhash
;
397 #define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash])
398 extern LIST_HEAD(pgrphashhead
, pgrp
) *pgrphashtbl
;
399 extern u_long pgrphash
;
401 LIST_HEAD(proclist
, proc
);
402 extern struct proclist allproc
; /* List of all processes. */
403 extern struct proclist zombproc
; /* List of zombie processes. */
404 extern struct proc
*initproc
, *kernproc
;
405 extern void pgdelete
__P((struct pgrp
*pgrp
));
406 extern void sessrele
__P((struct session
*sess
));
407 extern void procinit
__P((void));
408 #endif /* __APPLE_API_PRIVATE */
410 #ifdef __APPLE_API_UNSTABLE
412 extern struct proc
*pfind
__P((pid_t
)); /* Find process by id. */
413 __private_extern__
struct proc
*pzfind(pid_t
); /* Find zombie by id. */
414 extern struct pgrp
*pgfind
__P((pid_t
)); /* Find process group by id. */
416 extern int chgproccnt
__P((uid_t uid
, int diff
));
417 extern int enterpgrp
__P((struct proc
*p
, pid_t pgid
, int mksess
));
418 extern void fixjobc
__P((struct proc
*p
, struct pgrp
*pgrp
, int entering
));
419 extern int inferior
__P((struct proc
*p
));
420 extern int leavepgrp
__P((struct proc
*p
));
421 #ifdef __APPLE_API_OBSOLETE
422 extern void mi_switch
__P((void));
423 #endif /* __APPLE_API_OBSOLETE */
424 extern void resetpriority
__P((struct proc
*));
425 extern void setrunnable
__P((struct proc
*));
426 extern void setrunqueue
__P((struct proc
*));
427 extern int sleep
__P((void *chan
, int pri
));
428 extern int tsleep
__P((void *chan
, int pri
, char *wmesg
, int timo
));
429 extern int tsleep0
__P((void *chan
, int pri
, char *wmesg
, int timo
, int (*continuation
)(int)));
430 extern int tsleep1
__P((void *chan
, int pri
, char *wmesg
, u_int64_t abstime
, int (*continuation
)(int)));
431 extern void unsleep
__P((struct proc
*));
432 extern void wakeup
__P((void *chan
));
433 #endif /* __APPLE_API_UNSTABLE */
437 #ifdef __APPLE_API_OBSOLETE
438 /* FreeBSD source compatibility macro */
439 #define PRISON_CHECK(p1, p2) (1)
440 #endif /* __APPLE_API_OBSOLETE */
444 #endif /* !_SYS_PROC_H_ */