2 * Copyright (c) 2000-2005 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_internal.h 8.15 (Berkeley) 5/19/95
63 #ifndef _SYS_PROC_INTERNAL_H_
64 #define _SYS_PROC_INTERNAL_H_
68 #include <kern/locks.h>
72 * One structure allocated per session.
75 int s_count
; /* Ref cnt; pgrps in session. */
76 struct proc
*s_leader
; /* Session leader. */
77 struct vnode
*s_ttyvp
; /* Vnode of controlling terminal. */
78 struct tty
*s_ttyp
; /* Controlling terminal. */
79 pid_t s_sid
; /* Session ID */
80 char s_login
[MAXLOGNAME
]; /* Setlogin() name. */
84 * One structure allocated per process group.
87 LIST_ENTRY(pgrp
) pg_hash
; /* Hash chain. */
88 LIST_HEAD(, proc
) pg_members
; /* Pointer to pgrp members. */
89 struct session
*pg_session
; /* Pointer to session. */
90 pid_t pg_id
; /* Pgrp id. */
91 int pg_jobc
; /* # procs qualifying pgrp for job control */
96 #define PROC_NULL (struct proc *)0;
98 #define p_session p_pgrp->pg_session
99 #define p_pgid p_pgrp->pg_id
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 ucred
*p_ucred
; /* 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_rlimit p_limit->pl_rlimit
124 int p_flag
; /* P_* flags. */
125 char p_stat
; /* S* process status. */
126 char p_shutdownstate
;
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
; /* DEPRECATED (Time swapped in or out.) */
148 #define p_argslen p_swtime /* Length of process arguments. */
149 u_int p_slptime
; /* Time since last blocked. */
151 struct itimerval p_realtimer
; /* Alarm timer. */
152 struct timeval p_rtime
; /* Real time. */
153 u_quad_t p_uticks
; /* Statclock hits in user mode. */
154 u_quad_t p_sticks
; /* Statclock hits in system mode. */
155 u_quad_t p_iticks
; /* Statclock hits processing intr. */
157 int p_traceflag
; /* Kernel trace points. */
158 struct vnode
*p_tracep
; /* Trace to vnode. */
160 sigset_t p_siglist
; /* DEPRECATED. */
162 struct vnode
*p_textvp
; /* Vnode of executable. */
164 /* End area that is zeroed on creation. */
165 #define p_endzero p_hash.le_next
168 * Not copied, not zero'ed.
169 * Belongs after p_pid, but here to avoid shifting proc elements.
171 LIST_ENTRY(proc
) p_hash
; /* Hash chain. */
172 TAILQ_HEAD( ,eventqelt
) p_evlist
;
174 /* The following fields are all copied upon creation in fork. */
175 #define p_startcopy p_sigmask
177 sigset_t p_sigmask
; /* DEPRECATED */
178 sigset_t p_sigignore
; /* Signals being ignored. */
179 sigset_t p_sigcatch
; /* Signals being caught by user. */
181 u_char p_priority
; /* Process priority. */
182 u_char p_usrpri
; /* User-priority based on p_cpu and p_nice. */
183 char p_nice
; /* Process "nice" value. */
184 char p_comm
[MAXCOMLEN
+1];
186 struct pgrp
*p_pgrp
; /* Pointer to process group. */
188 /* End area that is copied on creation. */
189 #define p_endcopy p_xstat
191 u_short p_xstat
; /* Exit status for wait; also stop signal. */
192 u_short p_acflag
; /* Accounting flags. */
193 struct rusage
*p_ru
; /* Exit information. XXX */
195 int p_debugger
; /* 1: can exec set-bit programs if suser */
197 void *task
; /* corresponding task */
198 void *sigwait_thread
; /* 'thread' holding sigwait */
199 char signal_lock
[72];
200 boolean_t sigwait
; /* indication to suspend */
201 void *exit_thread
; /* Which thread is exiting? */
202 user_addr_t user_stack
; /* where user stack was allocated */
203 void * exitarg
; /* exit arg for proc terminate */
204 void * vm_shm
; /* for sysV shared memory */
205 int p_argc
; /* saved argc for sysctl_procargs() */
206 int p_vforkcnt
; /* number of outstanding vforks */
207 void * p_vforkact
; /* activation running this vfork proc */
208 TAILQ_HEAD( , uthread
) p_uthlist
; /* List of uthreads */
209 /* Following fields are info from SIGCHLD */
214 TAILQ_HEAD( , aio_workq_entry
) aio_activeq
; /* active async IO requests */
215 int aio_active_count
; /* entries on aio_activeq */
216 TAILQ_HEAD( , aio_workq_entry
) aio_doneq
; /* completed async IO requests */
217 int aio_done_count
; /* entries on aio_doneq */
219 struct klist p_klist
; /* knote list */
220 lck_mtx_t p_mlock
; /* proc lock to protect evques */
221 lck_mtx_t p_fdmlock
; /* proc lock to protect evques */
222 unsigned int p_fdlock_pc
[4];
223 unsigned int p_fdunlock_pc
[4];
225 unsigned int p_lflag
; /* local flags */
226 unsigned int p_ladvflag
; /* local adv flags*/
229 unsigned int lockpc
[8];
230 unsigned int unlockpc
[8];
231 #endif /* SIGNAL_DEBUG */
232 #endif /* DIAGNOSTIC */
237 #define P_LDELAYTERM 0x1 /* */
238 #define P_LNOZOMB 0x2 /* */
239 #define P_LLOW_PRI_IO 0x4
241 #define P_LBACKGROUND_IO 0x10
242 #define P_LWAITING 0x20
244 /* advisory flags in the proc */
245 #define P_LADVLOCK 0x01
247 // LP64todo - should this move?
248 /* LP64 version of extern_proc. all pointers
249 * grow when we're dealing with a 64-bit process.
250 * WARNING - keep in sync with extern_proc
251 * but use native alignment of 64-bit process.
255 #include <sys/time.h> /* user_timeval, user_itimerval */
257 #if __DARWIN_ALIGN_NATURAL
258 #pragma options align=natural
261 struct user_extern_proc
{
264 user_addr_t __p_forw
; /* Doubly-linked run/sleep queue. */
265 user_addr_t __p_back
;
267 struct user_timeval __p_starttime
; /* process start time */
269 user_addr_t p_vmspace
; /* Address space. */
270 user_addr_t p_sigacts
; /* Signal actions, state (PROC ONLY). */
271 int p_flag
; /* P_* flags. */
272 char p_stat
; /* S* process status. */
273 pid_t p_pid
; /* Process identifier. */
274 pid_t p_oppid
; /* Save parent pid during ptrace. XXX */
275 int p_dupfd
; /* Sideways return value from fdopen. XXX */
277 user_addr_t user_stack
; /* where user stack was allocated */
278 user_addr_t exit_thread
; /* XXX Which thread is exiting? */
279 int p_debugger
; /* allow to debug */
280 boolean_t sigwait
; /* indication to suspend */
282 u_int p_estcpu
; /* Time averaged value of p_cpticks. */
283 int p_cpticks
; /* Ticks of cpu time. */
284 fixpt_t p_pctcpu
; /* %cpu for this process during p_swtime */
285 user_addr_t p_wchan
; /* Sleep address. */
286 user_addr_t p_wmesg
; /* Reason for sleep. */
287 u_int p_swtime
; /* Time swapped in or out. */
288 u_int p_slptime
; /* Time since last blocked. */
289 struct user_itimerval p_realtimer
; /* Alarm timer. */
290 struct user_timeval p_rtime
; /* Real time. */
291 u_quad_t p_uticks
; /* Statclock hits in user mode. */
292 u_quad_t p_sticks
; /* Statclock hits in system mode. */
293 u_quad_t p_iticks
; /* Statclock hits processing intr. */
294 int p_traceflag
; /* Kernel trace points. */
295 user_addr_t p_tracep
; /* Trace to vnode. */
296 int p_siglist
; /* DEPRECATED */
297 user_addr_t p_textvp
; /* Vnode of executable. */
298 int p_holdcnt
; /* If non-zero, don't swap. */
299 sigset_t p_sigmask
; /* DEPRECATED. */
300 sigset_t p_sigignore
; /* Signals being ignored. */
301 sigset_t p_sigcatch
; /* Signals being caught by user. */
302 u_char p_priority
; /* Process priority. */
303 u_char p_usrpri
; /* User-priority based on p_cpu and p_nice. */
304 char p_nice
; /* Process "nice" value. */
305 char p_comm
[MAXCOMLEN
+1];
306 user_addr_t p_pgrp
; /* Pointer to process group. */
307 user_addr_t p_addr
; /* Kernel virtual addr of u-area (PROC ONLY). */
308 u_short p_xstat
; /* Exit status for wait; also stop signal. */
309 u_short p_acflag
; /* Accounting flags. */
310 user_addr_t p_ru
; /* Exit information. XXX */
313 #if __DARWIN_ALIGN_NATURAL
314 #pragma options align=reset
319 * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
320 * as it is used to represent "no process group".
322 extern int nprocs
, maxproc
; /* Current and max number of procs. */
323 __private_extern__
int hard_maxproc
; /* hard limit */
325 #define PID_MAX 30000
328 #define SESS_LEADER(p) ((p)->p_session->s_leader == (p))
329 #define SESSHOLD(s) ((s)->s_count++)
330 #define SESSRELE(s) sessrele(s)
332 #define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash])
333 extern LIST_HEAD(pidhashhead
, proc
) *pidhashtbl
;
334 extern u_long pidhash
;
336 #define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash])
337 extern LIST_HEAD(pgrphashhead
, pgrp
) *pgrphashtbl
;
338 extern u_long pgrphash
;
339 extern lck_grp_t
* proc_lck_grp
;
340 extern lck_grp_attr_t
* proc_lck_grp_attr
;
341 extern lck_attr_t
* proc_lck_attr
;
343 LIST_HEAD(proclist
, proc
);
344 extern struct proclist allproc
; /* List of all processes. */
345 extern struct proclist zombproc
; /* List of zombie processes. */
346 extern struct proc
*initproc
;
347 extern void pgdelete(struct pgrp
*pgrp
);
348 extern void sessrele(struct session
*sess
);
349 extern void procinit(void);
350 extern void proc_lock(struct proc
*);
351 extern void proc_unlock(struct proc
*);
352 extern void proc_fdlock(struct proc
*);
353 extern void proc_fdunlock(struct proc
*);
354 __private_extern__
char *proc_core_name(const char *name
, uid_t uid
, pid_t pid
);
355 extern int isinferior(struct proc
*, struct proc
*);
356 extern struct proc
*pfind(pid_t
); /* Find process by id. */
357 __private_extern__
struct proc
*pzfind(pid_t
); /* Find zombie by id. */
358 extern struct pgrp
*pgfind(pid_t
); /* Find process group by id. */
360 extern int chgproccnt(uid_t uid
, int diff
);
361 extern int enterpgrp(struct proc
*p
, pid_t pgid
, int mksess
);
362 extern void fixjobc(struct proc
*p
, struct pgrp
*pgrp
, int entering
);
363 extern int inferior(struct proc
*p
);
364 extern int leavepgrp(struct proc
*p
);
365 extern void resetpriority(struct proc
*);
366 extern void setrunnable(struct proc
*);
367 extern void setrunqueue(struct proc
*);
368 extern int sleep(void *chan
, int pri
);
369 extern int tsleep0(void *chan
, int pri
, const char *wmesg
, int timo
, int (*continuation
)(int));
370 extern int tsleep1(void *chan
, int pri
, const char *wmesg
, u_int64_t abstime
, int (*continuation
)(int));
371 extern int msleep0(void *chan
, lck_mtx_t
*mtx
, int pri
, const char *wmesg
, int timo
, int (*continuation
)(int));
372 extern void vfork_return(thread_t th_act
, struct proc
*p
, struct proc
*p2
, register_t
*retval
);
375 #endif /* !_SYS_PROC_INTERNAL_H_ */