]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/proc.h
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1995, 1997 Apple Computer, Inc. All Rights Reserved */
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.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
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.
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
60 * @(#)proc.h 8.15 (Berkeley) 5/19/95
66 #include <sys/cdefs.h>
68 #include <sys/select.h> /* For struct selinfo. */
69 #include <sys/queue.h>
71 #include <sys/param.h>
74 * One structure allocated per session.
77 int s_count
; /* Ref cnt; pgrps in session. */
78 struct proc
*s_leader
; /* Session leader. */
79 struct vnode
*s_ttyvp
; /* Vnode of controlling terminal. */
80 struct tty
*s_ttyp
; /* Controlling terminal. */
81 char s_login
[MAXLOGNAME
]; /* Setlogin() name. */
85 * One structure allocated per process group.
88 LIST_ENTRY(pgrp
) pg_hash
; /* Hash chain. */
89 LIST_HEAD(, proc
) pg_members
; /* Pointer to pgrp members. */
90 struct session
*pg_session
; /* Pointer to session. */
91 pid_t pg_id
; /* Pgrp id. */
92 int pg_jobc
; /* # procs qualifying pgrp for job control */
96 * Description of a process.
98 * This structure contains the information needed to manage a thread of
99 * control, known in UN*X as a process; it has references to substructures
100 * containing descriptions of things that the process uses, but may share
101 * with related processes. The process structure and the substructures
102 * are always addressible except for those marked "(PROC ONLY)" below,
103 * which might be addressible only on a processor on which the process
107 LIST_ENTRY(proc
) p_list
; /* List of all processes. */
110 struct pcred
*p_cred
; /* Process owner's identity. */
111 struct filedesc
*p_fd
; /* Ptr to open files structure. */
112 struct pstats
*p_stats
; /* Accounting/statistics (PROC ONLY). */
113 struct plimit
*p_limit
; /* Process limits. */
114 struct sigacts
*p_sigacts
; /* Signal actions, state (PROC ONLY). */
116 #define p_ucred p_cred->pc_ucred
117 #define p_rlimit p_limit->pl_rlimit
119 int p_flag
; /* P_* flags. */
120 char p_stat
; /* S* process status. */
123 pid_t p_pid
; /* Process identifier. */
124 LIST_ENTRY(proc
) p_pglist
; /* List of processes in pgrp. */
125 struct proc
*p_pptr
; /* Pointer to parent process. */
126 LIST_ENTRY(proc
) p_sibling
; /* List of sibling processes. */
127 LIST_HEAD(, proc
) p_children
; /* Pointer to list of children. */
129 /* The following fields are all zeroed upon creation in fork. */
130 #define p_startzero p_oppid
132 pid_t p_oppid
; /* Save parent pid during ptrace. XXX */
133 int p_dupfd
; /* Sideways return value from fdopen. XXX */
136 u_int p_estcpu
; /* Time averaged value of p_cpticks. */
137 int p_cpticks
; /* Ticks of cpu time. */
138 fixpt_t p_pctcpu
; /* %cpu for this process during p_swtime */
139 void *p_wchan
; /* Sleep address. */
140 char *p_wmesg
; /* Reason for sleep. */
141 u_int p_swtime
; /* Time swapped in or out. */
142 u_int p_slptime
; /* Time since last blocked. */
144 struct itimerval p_realtimer
; /* Alarm timer. */
145 struct timeval p_rtime
; /* Real time. */
146 u_quad_t p_uticks
; /* Statclock hits in user mode. */
147 u_quad_t p_sticks
; /* Statclock hits in system mode. */
148 u_quad_t p_iticks
; /* Statclock hits processing intr. */
150 int p_traceflag
; /* Kernel trace points. */
151 struct vnode
*p_tracep
; /* Trace to vnode. */
153 sigset_t p_siglist
; /* Signals arrived but not delivered. */
155 struct vnode
*p_textvp
; /* Vnode of executable. */
157 /* End area that is zeroed on creation. */
158 #define p_endzero p_hash.le_next
161 * Not copied, not zero'ed.
162 * Belongs after p_pid, but here to avoid shifting proc elements.
164 LIST_ENTRY(proc
) p_hash
; /* Hash chain. */
165 TAILQ_HEAD( ,eventqelt
) p_evlist
;
167 /* The following fields are all copied upon creation in fork. */
168 #define p_startcopy p_sigmask
170 sigset_t p_sigmask
; /* Current signal mask. */
171 sigset_t p_sigignore
; /* Signals being ignored. */
172 sigset_t p_sigcatch
; /* Signals being caught by user. */
174 u_char p_priority
; /* Process priority. */
175 u_char p_usrpri
; /* User-priority based on p_cpu and p_nice. */
176 char p_nice
; /* Process "nice" value. */
177 char p_comm
[MAXCOMLEN
+1];
179 struct pgrp
*p_pgrp
; /* Pointer to process group. */
181 /* End area that is copied on creation. */
182 #define p_endcopy p_xstat
184 u_short p_xstat
; /* Exit status for wait; also stop signal. */
185 u_short p_acflag
; /* Accounting flags. */
186 struct rusage
*p_ru
; /* Exit information. XXX */
188 int p_debugger
; /* 1: can exec set-bit programs if suser */
190 void *task
; /* corresponding task */
191 void *sigwait_thread
; /* 'thread' holding sigwait */
192 struct lock__bsd__ signal_lock
; /* multilple thread prot for signals*/
193 boolean_t sigwait
; /* indication to suspend */
194 void *exit_thread
; /* Which thread is exiting? */
195 caddr_t user_stack
; /* where user stack was allocated */
196 void * exitarg
; /* exit arg for proc terminate */
197 void * vm_shm
; /* for sysV shared memory */
198 sigset_t p_sigpending
; /* pended Signals as traced process is blocked. */
199 int p_vforkcnt
; /* number of outstanding vforks */
200 void * p_vforkact
; /* activation running this vfork proc */
203 unsigned int lockpc
[8];
204 unsigned int unlockpc
[8];
205 #endif /* SIGNAL_DEBUG */
206 #endif /* DIAGNOSTIC */
209 /* Exported fields for kern sysctls */
211 struct proc
*p_forw
; /* Doubly-linked run/sleep queue. */
213 struct vmspace
*p_vmspace
; /* Address space. */
214 struct sigacts
*p_sigacts
; /* Signal actions, state (PROC ONLY). */
215 int p_flag
; /* P_* flags. */
216 char p_stat
; /* S* process status. */
217 pid_t p_pid
; /* Process identifier. */
218 pid_t p_oppid
; /* Save parent pid during ptrace. XXX */
219 int p_dupfd
; /* Sideways return value from fdopen. XXX */
221 caddr_t user_stack
; /* where user stack was allocated */
222 void *exit_thread
; /* XXX Which thread is exiting? */
223 int p_debugger
; /* allow to debug */
224 boolean_t sigwait
; /* indication to suspend */
226 u_int p_estcpu
; /* Time averaged value of p_cpticks. */
227 int p_cpticks
; /* Ticks of cpu time. */
228 fixpt_t p_pctcpu
; /* %cpu for this process during p_swtime */
229 void *p_wchan
; /* Sleep address. */
230 char *p_wmesg
; /* Reason for sleep. */
231 u_int p_swtime
; /* Time swapped in or out. */
232 u_int p_slptime
; /* Time since last blocked. */
233 struct itimerval p_realtimer
; /* Alarm timer. */
234 struct timeval p_rtime
; /* Real time. */
235 u_quad_t p_uticks
; /* Statclock hits in user mode. */
236 u_quad_t p_sticks
; /* Statclock hits in system mode. */
237 u_quad_t p_iticks
; /* Statclock hits processing intr. */
238 int p_traceflag
; /* Kernel trace points. */
239 struct vnode
*p_tracep
; /* Trace to vnode. */
240 int p_siglist
; /* Signals arrived but not delivered. */
241 struct vnode
*p_textvp
; /* Vnode of executable. */
242 int p_holdcnt
; /* If non-zero, don't swap. */
243 sigset_t p_sigmask
; /* Current signal mask. */
244 sigset_t p_sigignore
; /* Signals being ignored. */
245 sigset_t p_sigcatch
; /* Signals being caught by user. */
246 u_char p_priority
; /* Process priority. */
247 u_char p_usrpri
; /* User-priority based on p_cpu and p_nice. */
248 char p_nice
; /* Process "nice" value. */
249 char p_comm
[MAXCOMLEN
+1];
250 struct pgrp
*p_pgrp
; /* Pointer to process group. */
251 struct user
*p_addr
; /* Kernel virtual addr of u-area (PROC ONLY). */
252 u_short p_xstat
; /* Exit status for wait; also stop signal. */
253 u_short p_acflag
; /* Accounting flags. */
254 struct rusage
*p_ru
; /* Exit information. XXX */
257 #define p_session p_pgrp->pg_session
258 #define p_pgid p_pgrp->pg_id
261 #define SIDL 1 /* Process being created by fork. */
262 #define SRUN 2 /* Currently runnable. */
263 #define SSLEEP 3 /* Sleeping on an address. */
264 #define SSTOP 4 /* Process debugging or suspension. */
265 #define SZOMB 5 /* Awaiting collection by parent. */
267 /* These flags are kept in p_flags. */
268 #define P_ADVLOCK 0x00001 /* Process may hold a POSIX advisory lock. */
269 #define P_CONTROLT 0x00002 /* Has a controlling terminal. */
270 #define P_INMEM 0x00004 /* Loaded into memory. */
271 #define P_NOCLDSTOP 0x00008 /* No SIGCHLD when children stop. */
272 #define P_PPWAIT 0x00010 /* Parent is waiting for child to exec/exit. */
273 #define P_PROFIL 0x00020 /* Has started profiling. */
274 #define P_SELECT 0x00040 /* Selecting; wakeup/waiting danger. */
275 #define P_SINTR 0x00080 /* Sleep is interruptible. */
276 #define P_SUGID 0x00100 /* Had set id privileges since last exec. */
277 #define P_SYSTEM 0x00200 /* System proc: no sigs, stats or swapping. */
278 #define P_TIMEOUT 0x00400 /* Timing out during sleep. */
279 #define P_TRACED 0x00800 /* Debugged process being traced. */
280 #define P_WAITED 0x01000 /* Debugging process has waited for child. */
281 #define P_WEXIT 0x02000 /* Working on exiting. */
282 #define P_EXEC 0x04000 /* Process called exec. */
284 /* Should probably be changed into a hold count. */
285 #define P_NOSWAP 0x08000 /* Another flag to prevent swap out. */
286 #define P_PHYSIO 0x10000 /* Doing physical I/O. */
288 /* Should be moved to machine-dependent areas. */
289 #define P_OWEUPC 0x08000 /* Owe process an addupc() call at next ast. */
291 /* XXX Not sure what to do with these, yet. */
292 #define P_FSTRACE 0x10000 /* tracing via file system (elsewhere?) */
293 #define P_SSTEP 0x20000 /* process needs single-step fixup ??? */
295 #define P_WAITING 0x0040000 /* process has a wait() in progress */
296 #define P_KDEBUG 0x0080000 /* kdebug tracing is on for this process */
297 #define P_TTYSLEEP 0x0100000 /* blocked due to SIGTTOU or SIGTTIN */
298 #define P_REBOOT 0x0200000 /* Process called reboot() */
299 #define P_TBE 0x0400000 /* Process is TBE */
300 #define P_SIGTHR 0x0800000 /* signal pending handling thread scheduled */
301 #define P_BTRACE 0x1000000 /* process is being branch traced */
302 #define P_VFORK 0x2000000 /* process has vfork children */
303 #define P_NOATTACH 0x4000000
304 #define P_INVFORK 0x8000000 /* proc in vfork */
308 * Shareable process credentials (always resident). This includes a reference
309 * to the current user credentials as well as real and saved ids that may be
310 * used to change ids.
313 struct lock__bsd__ pc_lock
;
314 struct ucred
*pc_ucred
; /* Current credentials. */
315 uid_t p_ruid
; /* Real user id. */
316 uid_t p_svuid
; /* Saved effective user id. */
317 gid_t p_rgid
; /* Real group id. */
318 gid_t p_svgid
; /* Saved effective group id. */
319 int p_refcnt
; /* Number of references. */
322 #define pcred_readlock(p) lockmgr(&(p)->p_cred->pc_lock, \
324 #define pcred_writelock(p) lockmgr(&(p)->p_cred->pc_lock, \
325 LK_EXCLUSIVE, 0, (p))
326 #define pcred_unlock(p) lockmgr(&(p)->p_cred->pc_lock, \
333 * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
334 * as it is used to represent "no process group".
336 #define PID_MAX 30000
339 #define SESS_LEADER(p) ((p)->p_session->s_leader == (p))
340 #define SESSHOLD(s) ((s)->s_count++)
341 #define SESSRELE(s) sessrele(s)
343 #define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash])
344 extern LIST_HEAD(pidhashhead
, proc
) *pidhashtbl
;
345 extern u_long pidhash
;
347 #define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash])
348 extern LIST_HEAD(pgrphashhead
, pgrp
) *pgrphashtbl
;
349 extern u_long pgrphash
;
351 extern int nprocs
, maxproc
; /* Current and max number of procs. */
353 LIST_HEAD(proclist
, proc
);
354 extern struct proclist allproc
; /* List of all processes. */
355 extern struct proclist zombproc
; /* List of zombie processes. */
356 extern struct proc
*initproc
, *kernproc
;
358 extern struct proc
*pfind
__P((pid_t
)); /* Find process by id. */
359 extern struct pgrp
*pgfind
__P((pid_t
)); /* Find process group by id. */
361 extern int chgproccnt
__P((uid_t uid
, int diff
));
362 extern int enterpgrp
__P((struct proc
*p
, pid_t pgid
, int mksess
));
363 extern void fixjobc
__P((struct proc
*p
, struct pgrp
*pgrp
, int entering
));
364 extern int inferior
__P((struct proc
*p
));
365 extern int leavepgrp
__P((struct proc
*p
));
366 extern void mi_switch
__P((void));
367 extern void pgdelete
__P((struct pgrp
*pgrp
));
368 extern void sessrele
__P((struct session
*sess
));
369 extern void procinit
__P((void));
370 extern void resetpriority
__P((struct proc
*));
371 extern void setrunnable
__P((struct proc
*));
372 extern void setrunqueue
__P((struct proc
*));
373 extern int sleep
__P((void *chan
, int pri
));
374 extern int tsleep
__P((void *chan
, int pri
, char *wmesg
, int timo
));
375 extern int tsleep0
__P((void *chan
, int pri
, char *wmesg
, int timo
, int (*continuation
)(int) ));
376 extern void unsleep
__P((struct proc
*));
377 extern void wakeup
__P((void *chan
));
382 #endif /* !_SYS_PROC_H_ */