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 int p_lflag
; /* local flags */
228 unsigned int lockpc
[8];
229 unsigned int unlockpc
[8];
230 #endif /* SIGNAL_DEBUG */
231 #endif /* DIAGNOSTIC */
235 #define P_LDELAYTERM 0x1 /* */
236 #define P_LNOZOMB 0x2 /* */
237 #define P_LLOW_PRI_IO 0x4
239 #define P_LBACKGROUND_IO 0x10
241 // LP64todo - should this move?
242 /* LP64 version of extern_proc. all pointers
243 * grow when we're dealing with a 64-bit process.
244 * WARNING - keep in sync with extern_proc
245 * but use native alignment of 64-bit process.
249 #include <sys/time.h> /* user_timeval, user_itimerval */
251 #if __DARWIN_ALIGN_NATURAL
252 #pragma options align=natural
255 struct user_extern_proc
{
258 user_addr_t __p_forw
; /* Doubly-linked run/sleep queue. */
259 user_addr_t __p_back
;
261 struct user_timeval __p_starttime
; /* process start time */
263 user_addr_t p_vmspace
; /* Address space. */
264 user_addr_t p_sigacts
; /* Signal actions, state (PROC ONLY). */
265 int p_flag
; /* P_* flags. */
266 char p_stat
; /* S* process status. */
267 pid_t p_pid
; /* Process identifier. */
268 pid_t p_oppid
; /* Save parent pid during ptrace. XXX */
269 int p_dupfd
; /* Sideways return value from fdopen. XXX */
271 user_addr_t user_stack
; /* where user stack was allocated */
272 user_addr_t exit_thread
; /* XXX Which thread is exiting? */
273 int p_debugger
; /* allow to debug */
274 boolean_t sigwait
; /* indication to suspend */
276 u_int p_estcpu
; /* Time averaged value of p_cpticks. */
277 int p_cpticks
; /* Ticks of cpu time. */
278 fixpt_t p_pctcpu
; /* %cpu for this process during p_swtime */
279 user_addr_t p_wchan
; /* Sleep address. */
280 user_addr_t p_wmesg
; /* Reason for sleep. */
281 u_int p_swtime
; /* Time swapped in or out. */
282 u_int p_slptime
; /* Time since last blocked. */
283 struct user_itimerval p_realtimer
; /* Alarm timer. */
284 struct user_timeval p_rtime
; /* Real time. */
285 u_quad_t p_uticks
; /* Statclock hits in user mode. */
286 u_quad_t p_sticks
; /* Statclock hits in system mode. */
287 u_quad_t p_iticks
; /* Statclock hits processing intr. */
288 int p_traceflag
; /* Kernel trace points. */
289 user_addr_t p_tracep
; /* Trace to vnode. */
290 int p_siglist
; /* DEPRECATED */
291 user_addr_t p_textvp
; /* Vnode of executable. */
292 int p_holdcnt
; /* If non-zero, don't swap. */
293 sigset_t p_sigmask
; /* DEPRECATED. */
294 sigset_t p_sigignore
; /* Signals being ignored. */
295 sigset_t p_sigcatch
; /* Signals being caught by user. */
296 u_char p_priority
; /* Process priority. */
297 u_char p_usrpri
; /* User-priority based on p_cpu and p_nice. */
298 char p_nice
; /* Process "nice" value. */
299 char p_comm
[MAXCOMLEN
+1];
300 user_addr_t p_pgrp
; /* Pointer to process group. */
301 user_addr_t p_addr
; /* Kernel virtual addr of u-area (PROC ONLY). */
302 u_short p_xstat
; /* Exit status for wait; also stop signal. */
303 u_short p_acflag
; /* Accounting flags. */
304 user_addr_t p_ru
; /* Exit information. XXX */
307 #if __DARWIN_ALIGN_NATURAL
308 #pragma options align=reset
313 * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
314 * as it is used to represent "no process group".
316 extern int nprocs
, maxproc
; /* Current and max number of procs. */
317 __private_extern__
int hard_maxproc
; /* hard limit */
319 #define PID_MAX 30000
322 #define SESS_LEADER(p) ((p)->p_session->s_leader == (p))
323 #define SESSHOLD(s) ((s)->s_count++)
324 #define SESSRELE(s) sessrele(s)
326 #define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash])
327 extern LIST_HEAD(pidhashhead
, proc
) *pidhashtbl
;
328 extern u_long pidhash
;
330 #define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash])
331 extern LIST_HEAD(pgrphashhead
, pgrp
) *pgrphashtbl
;
332 extern u_long pgrphash
;
333 extern lck_grp_t
* proc_lck_grp
;
334 extern lck_grp_attr_t
* proc_lck_grp_attr
;
335 extern lck_attr_t
* proc_lck_attr
;
337 LIST_HEAD(proclist
, proc
);
338 extern struct proclist allproc
; /* List of all processes. */
339 extern struct proclist zombproc
; /* List of zombie processes. */
340 extern struct proc
*initproc
;
341 extern void pgdelete(struct pgrp
*pgrp
);
342 extern void sessrele(struct session
*sess
);
343 extern void procinit(void);
344 extern void proc_lock(struct proc
*);
345 extern void proc_unlock(struct proc
*);
346 extern void proc_fdlock(struct proc
*);
347 extern void proc_fdunlock(struct proc
*);
348 __private_extern__
char *proc_core_name(const char *name
, uid_t uid
, pid_t pid
);
349 extern int isinferior(struct proc
*, struct proc
*);
350 extern struct proc
*pfind(pid_t
); /* Find process by id. */
351 __private_extern__
struct proc
*pzfind(pid_t
); /* Find zombie by id. */
352 extern struct pgrp
*pgfind(pid_t
); /* Find process group by id. */
354 extern int chgproccnt(uid_t uid
, int diff
);
355 extern int enterpgrp(struct proc
*p
, pid_t pgid
, int mksess
);
356 extern void fixjobc(struct proc
*p
, struct pgrp
*pgrp
, int entering
);
357 extern int inferior(struct proc
*p
);
358 extern int leavepgrp(struct proc
*p
);
359 extern void resetpriority(struct proc
*);
360 extern void setrunnable(struct proc
*);
361 extern void setrunqueue(struct proc
*);
362 extern int sleep(void *chan
, int pri
);
363 extern int tsleep0(void *chan
, int pri
, const char *wmesg
, int timo
, int (*continuation
)(int));
364 extern int tsleep1(void *chan
, int pri
, const char *wmesg
, u_int64_t abstime
, int (*continuation
)(int));
365 extern int msleep0(void *chan
, lck_mtx_t
*mtx
, int pri
, const char *wmesg
, int timo
, int (*continuation
)(int));
366 extern void vfork_return(thread_t th_act
, struct proc
*p
, struct proc
*p2
, register_t
*retval
);
369 #endif /* !_SYS_PROC_INTERNAL_H_ */