]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/proc.h
2 * Copyright (c) 2000-2002 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>
76 #ifdef __APPLE_API_PRIVATE
79 * One structure allocated per session.
82 int s_count
; /* Ref cnt; pgrps in session. */
83 struct proc
*s_leader
; /* Session leader. */
84 struct vnode
*s_ttyvp
; /* Vnode of controlling terminal. */
85 struct tty
*s_ttyp
; /* Controlling terminal. */
86 pid_t s_sid
; /* Session ID */
87 char s_login
[MAXLOGNAME
]; /* Setlogin() name. */
91 * One structure allocated per process group.
94 LIST_ENTRY(pgrp
) pg_hash
; /* Hash chain. */
95 LIST_HEAD(, proc
) pg_members
; /* Pointer to pgrp members. */
96 struct session
*pg_session
; /* Pointer to session. */
97 pid_t pg_id
; /* Pgrp id. */
98 int pg_jobc
; /* # procs qualifying pgrp for job control */
102 * Description of a process.
104 * This structure contains the information needed to manage a thread of
105 * control, known in UN*X as a process; it has references to substructures
106 * containing descriptions of things that the process uses, but may share
107 * with related processes. The process structure and the substructures
108 * are always addressible except for those marked "(PROC ONLY)" below,
109 * which might be addressible only on a processor on which the process
113 LIST_ENTRY(proc
) p_list
; /* List of all processes. */
116 struct pcred
*p_cred
; /* Process owner's identity. */
117 struct filedesc
*p_fd
; /* Ptr to open files structure. */
118 struct pstats
*p_stats
; /* Accounting/statistics (PROC ONLY). */
119 struct plimit
*p_limit
; /* Process limits. */
120 struct sigacts
*p_sigacts
; /* Signal actions, state (PROC ONLY). */
122 #define p_ucred p_cred->pc_ucred
123 #define p_rlimit p_limit->pl_rlimit
125 int p_flag
; /* P_* flags. */
126 char p_stat
; /* S* process status. */
129 pid_t p_pid
; /* Process identifier. */
130 LIST_ENTRY(proc
) p_pglist
; /* List of processes in pgrp. */
131 struct proc
*p_pptr
; /* Pointer to parent process. */
132 LIST_ENTRY(proc
) p_sibling
; /* List of sibling processes. */
133 LIST_HEAD(, proc
) p_children
; /* Pointer to list of children. */
135 /* The following fields are all zeroed upon creation in fork. */
136 #define p_startzero p_oppid
138 pid_t p_oppid
; /* Save parent pid during ptrace. XXX */
139 int p_dupfd
; /* Sideways return value from fdopen. XXX */
142 u_int p_estcpu
; /* Time averaged value of p_cpticks. */
143 int p_cpticks
; /* Ticks of cpu time. */
144 fixpt_t p_pctcpu
; /* %cpu for this process during p_swtime */
145 void *p_wchan
; /* Sleep address. */
146 char *p_wmesg
; /* Reason for sleep. */
147 u_int p_swtime
; /* Time swapped in or out. */
148 u_int p_slptime
; /* Time since last blocked. */
150 struct itimerval p_realtimer
; /* Alarm timer. */
151 struct timeval p_rtime
; /* Real time. */
152 u_quad_t p_uticks
; /* Statclock hits in user mode. */
153 u_quad_t p_sticks
; /* Statclock hits in system mode. */
154 u_quad_t p_iticks
; /* Statclock hits processing intr. */
156 int p_traceflag
; /* Kernel trace points. */
157 struct vnode
*p_tracep
; /* Trace to vnode. */
159 sigset_t p_siglist
; /* DEPRECATED. */
161 struct vnode
*p_textvp
; /* Vnode of executable. */
163 /* End area that is zeroed on creation. */
164 #define p_endzero p_hash.le_next
167 * Not copied, not zero'ed.
168 * Belongs after p_pid, but here to avoid shifting proc elements.
170 LIST_ENTRY(proc
) p_hash
; /* Hash chain. */
171 TAILQ_HEAD( ,eventqelt
) p_evlist
;
173 /* The following fields are all copied upon creation in fork. */
174 #define p_startcopy p_sigmask
176 sigset_t p_sigmask
; /* DEPRECATED */
177 sigset_t p_sigignore
; /* Signals being ignored. */
178 sigset_t p_sigcatch
; /* Signals being caught by user. */
180 u_char p_priority
; /* Process priority. */
181 u_char p_usrpri
; /* User-priority based on p_cpu and p_nice. */
182 char p_nice
; /* Process "nice" value. */
183 char p_comm
[MAXCOMLEN
+1];
185 struct pgrp
*p_pgrp
; /* Pointer to process group. */
187 /* End area that is copied on creation. */
188 #define p_endcopy p_xstat
190 u_short p_xstat
; /* Exit status for wait; also stop signal. */
191 u_short p_acflag
; /* Accounting flags. */
192 struct rusage
*p_ru
; /* Exit information. XXX */
194 int p_debugger
; /* 1: can exec set-bit programs if suser */
196 void *task
; /* corresponding task */
197 void *sigwait_thread
; /* 'thread' holding sigwait */
198 struct lock__bsd__ signal_lock
; /* multilple thread prot for signals*/
199 boolean_t sigwait
; /* indication to suspend */
200 void *exit_thread
; /* Which thread is exiting? */
201 caddr_t user_stack
; /* where user stack was allocated */
202 void * exitarg
; /* exit arg for proc terminate */
203 void * vm_shm
; /* for sysV shared memory */
204 sigset_t p_xxxsigpending
; /* DEPRECATED . */
205 int p_vforkcnt
; /* number of outstanding vforks */
206 void * p_vforkact
; /* activation running this vfork proc */
207 TAILQ_HEAD( , uthread
) p_uthlist
; /* List of uthreads */
208 /* Following fields are info from SIGCHLD */
215 unsigned int lockpc
[8];
216 unsigned int unlockpc
[8];
217 #endif /* SIGNAL_DEBUG */
218 #endif /* DIAGNOSTIC */
221 #else /* __APPLE_API_PRIVATE */
225 #endif /* __APPLE_API_PRIVATE */
227 #ifdef __APPLE_API_UNSTABLE
228 /* Exported fields for kern sysctls */
232 struct proc
*__p_forw
; /* Doubly-linked run/sleep queue. */
233 struct proc
*__p_back
;
235 struct timeval __p_starttime
; /* process start time */
237 #define p_forw p_un.p_st1.__p_forw
238 #define p_back p_un.p_st1.__p_back
239 #define p_starttime p_un.__p_starttime
240 struct vmspace
*p_vmspace
; /* Address space. */
241 struct sigacts
*p_sigacts
; /* Signal actions, state (PROC ONLY). */
242 int p_flag
; /* P_* flags. */
243 char p_stat
; /* S* process status. */
244 pid_t p_pid
; /* Process identifier. */
245 pid_t p_oppid
; /* Save parent pid during ptrace. XXX */
246 int p_dupfd
; /* Sideways return value from fdopen. XXX */
248 caddr_t user_stack
; /* where user stack was allocated */
249 void *exit_thread
; /* XXX Which thread is exiting? */
250 int p_debugger
; /* allow to debug */
251 boolean_t sigwait
; /* indication to suspend */
253 u_int p_estcpu
; /* Time averaged value of p_cpticks. */
254 int p_cpticks
; /* Ticks of cpu time. */
255 fixpt_t p_pctcpu
; /* %cpu for this process during p_swtime */
256 void *p_wchan
; /* Sleep address. */
257 char *p_wmesg
; /* Reason for sleep. */
258 u_int p_swtime
; /* Time swapped in or out. */
259 u_int p_slptime
; /* Time since last blocked. */
260 struct itimerval p_realtimer
; /* Alarm timer. */
261 struct timeval p_rtime
; /* Real time. */
262 u_quad_t p_uticks
; /* Statclock hits in user mode. */
263 u_quad_t p_sticks
; /* Statclock hits in system mode. */
264 u_quad_t p_iticks
; /* Statclock hits processing intr. */
265 int p_traceflag
; /* Kernel trace points. */
266 struct vnode
*p_tracep
; /* Trace to vnode. */
267 int p_siglist
; /* DEPRECATED */
268 struct vnode
*p_textvp
; /* Vnode of executable. */
269 int p_holdcnt
; /* If non-zero, don't swap. */
270 sigset_t p_sigmask
; /* DEPRECATED. */
271 sigset_t p_sigignore
; /* Signals being ignored. */
272 sigset_t p_sigcatch
; /* Signals being caught by user. */
273 u_char p_priority
; /* Process priority. */
274 u_char p_usrpri
; /* User-priority based on p_cpu and p_nice. */
275 char p_nice
; /* Process "nice" value. */
276 char p_comm
[MAXCOMLEN
+1];
277 struct pgrp
*p_pgrp
; /* Pointer to process group. */
278 struct user
*p_addr
; /* Kernel virtual addr of u-area (PROC ONLY). */
279 u_short p_xstat
; /* Exit status for wait; also stop signal. */
280 u_short p_acflag
; /* Accounting flags. */
281 struct rusage
*p_ru
; /* Exit information. XXX */
284 #define p_session p_pgrp->pg_session
285 #define p_pgid p_pgrp->pg_id
288 #define SIDL 1 /* Process being created by fork. */
289 #define SRUN 2 /* Currently runnable. */
290 #define SSLEEP 3 /* Sleeping on an address. */
291 #define SSTOP 4 /* Process debugging or suspension. */
292 #define SZOMB 5 /* Awaiting collection by parent. */
294 /* These flags are kept in p_flags. */
295 #define P_ADVLOCK 0x00001 /* Process may hold a POSIX advisory lock. */
296 #define P_CONTROLT 0x00002 /* Has a controlling terminal. */
297 #define P_INMEM 0x00004 /* Loaded into memory. */
298 #define P_NOCLDSTOP 0x00008 /* No SIGCHLD when children stop. */
299 #define P_PPWAIT 0x00010 /* Parent is waiting for child to exec/exit. */
300 #define P_PROFIL 0x00020 /* Has started profiling. */
301 #define P_SELECT 0x00040 /* Selecting; wakeup/waiting danger. */
302 #define P_SINTR 0x00080 /* Sleep is interruptible. */
303 #define P_SUGID 0x00100 /* Had set id privileges since last exec. */
304 #define P_SYSTEM 0x00200 /* System proc: no sigs, stats or swapping. */
305 #define P_TIMEOUT 0x00400 /* Timing out during sleep. */
306 #define P_TRACED 0x00800 /* Debugged process being traced. */
307 #define P_WAITED 0x01000 /* Debugging process has waited for child. */
308 #define P_WEXIT 0x02000 /* Working on exiting. */
309 #define P_EXEC 0x04000 /* Process called exec. */
311 /* Should be moved to machine-dependent areas. */
312 #define P_OWEUPC 0x08000 /* Owe process an addupc() call at next ast. */
314 /* XXX Not sure what to do with these, yet. */
315 #define P_FSTRACE 0x10000 /* tracing via file system (elsewhere?) */
316 #define P_SSTEP 0x20000 /* process needs single-step fixup ??? */
318 #define P_WAITING 0x0040000 /* process has a wait() in progress */
319 #define P_KDEBUG 0x0080000 /* kdebug tracing is on for this process */
320 #define P_TTYSLEEP 0x0100000 /* blocked due to SIGTTOU or SIGTTIN */
321 #define P_REBOOT 0x0200000 /* Process called reboot() */
322 #define P_TBE 0x0400000 /* Process is TBE */
323 #define P_SIGEXC 0x0800000 /* signal exceptions */
324 #define P_BTRACE 0x1000000 /* process is being branch traced */
325 #define P_VFORK 0x2000000 /* process has vfork children */
326 #define P_NOATTACH 0x4000000
327 #define P_INVFORK 0x8000000 /* proc in vfork */
328 #define P_NOSHLIB 0x10000000 /* no shared libs are in use for proc */
329 /* flag set on exec */
330 #define P_FORCEQUOTA 0x20000000 /* Force quota for root */
331 #define P_NOCLDWAIT 0x40000000 /* No zombies when chil procs exit */
333 #define P_NOSWAP 0 /* Obsolete: retained so that nothing breaks */
334 #define P_PHYSIO 0 /* Obsolete: retained so that nothing breaks */
337 * Shareable process credentials (always resident). This includes a reference
338 * to the current user credentials as well as real and saved ids that may be
339 * used to change ids.
342 struct lock__bsd__ pc_lock
;
343 struct ucred
*pc_ucred
; /* Current credentials. */
344 uid_t p_ruid
; /* Real user id. */
345 uid_t p_svuid
; /* Saved effective user id. */
346 gid_t p_rgid
; /* Real group id. */
347 gid_t p_svgid
; /* Saved effective group id. */
348 int p_refcnt
; /* Number of references. */
351 #define pcred_readlock(p) lockmgr(&(p)->p_cred->pc_lock, \
353 #define pcred_writelock(p) lockmgr(&(p)->p_cred->pc_lock, \
354 LK_EXCLUSIVE, 0, (p))
355 #define pcred_unlock(p) lockmgr(&(p)->p_cred->pc_lock, \
357 #endif /* __APPLE_API_UNSTABLE */
362 #ifdef __APPLE_API_PRIVATE
364 * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
365 * as it is used to represent "no process group".
367 extern int nprocs
, maxproc
; /* Current and max number of procs. */
369 #define PID_MAX 30000
372 #define SESS_LEADER(p) ((p)->p_session->s_leader == (p))
373 #define SESSHOLD(s) ((s)->s_count++)
374 #define SESSRELE(s) sessrele(s)
376 #define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash])
377 extern LIST_HEAD(pidhashhead
, proc
) *pidhashtbl
;
378 extern u_long pidhash
;
380 #define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash])
381 extern LIST_HEAD(pgrphashhead
, pgrp
) *pgrphashtbl
;
382 extern u_long pgrphash
;
384 LIST_HEAD(proclist
, proc
);
385 extern struct proclist allproc
; /* List of all processes. */
386 extern struct proclist zombproc
; /* List of zombie processes. */
387 extern struct proc
*initproc
, *kernproc
;
388 extern void pgdelete
__P((struct pgrp
*pgrp
));
389 extern void sessrele
__P((struct session
*sess
));
390 extern void procinit
__P((void));
391 #endif /* __APPLE_API_PRIVATE */
393 #ifdef __APPLE_API_UNSTABLE
395 extern struct proc
*pfind
__P((pid_t
)); /* Find process by id. */
396 extern struct pgrp
*pgfind
__P((pid_t
)); /* Find process group by id. */
398 extern int chgproccnt
__P((uid_t uid
, int diff
));
399 extern int enterpgrp
__P((struct proc
*p
, pid_t pgid
, int mksess
));
400 extern void fixjobc
__P((struct proc
*p
, struct pgrp
*pgrp
, int entering
));
401 extern int inferior
__P((struct proc
*p
));
402 extern int leavepgrp
__P((struct proc
*p
));
403 #ifdef __APPLE_API_OBSOLETE
404 extern void mi_switch
__P((void));
405 #endif /* __APPLE_API_OBSOLETE */
406 extern void resetpriority
__P((struct proc
*));
407 extern void setrunnable
__P((struct proc
*));
408 extern void setrunqueue
__P((struct proc
*));
409 extern int sleep
__P((void *chan
, int pri
));
410 extern int tsleep
__P((void *chan
, int pri
, char *wmesg
, int timo
));
411 extern int tsleep0
__P((void *chan
, int pri
, char *wmesg
, int timo
, int (*continuation
)(int)));
412 extern int tsleep1
__P((void *chan
, int pri
, char *wmesg
, u_int64_t abstime
, int (*continuation
)(int)));
413 extern void unsleep
__P((struct proc
*));
414 extern void wakeup
__P((void *chan
));
415 #endif /* __APPLE_API_UNSTABLE */
419 #ifdef __APPLE_API_OBSOLETE
420 /* FreeBSD source compatibility macro */
421 #define PRISON_CHECK(p1, p2) (1)
422 #endif /* __APPLE_API_OBSOLETE */
426 #endif /* !_SYS_PROC_H_ */