2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* Copyright (c) 1995, 1997 Apple Computer, Inc. All Rights Reserved */
30 * Copyright (c) 1986, 1989, 1991, 1993
31 * The Regents of the University of California. All rights reserved.
32 * (c) UNIX System Laboratories, Inc.
33 * All or some portions of this file are derived from material licensed
34 * to the University of California by American Telephone and Telegraph
35 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
36 * the permission of UNIX System Laboratories, Inc.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * @(#)proc_internal.h 8.15 (Berkeley) 5/19/95
69 #ifndef _SYS_PROC_INTERNAL_H_
70 #define _SYS_PROC_INTERNAL_H_
74 #include <kern/locks.h>
78 * One structure allocated per session.
81 int s_count
; /* Ref cnt; pgrps in session. */
82 struct proc
*s_leader
; /* Session leader. */
83 struct vnode
*s_ttyvp
; /* Vnode of controlling terminal. */
84 struct tty
*s_ttyp
; /* Controlling terminal. */
85 pid_t s_sid
; /* Session ID */
86 char s_login
[MAXLOGNAME
]; /* Setlogin() name. */
90 * One structure allocated per process group.
93 LIST_ENTRY(pgrp
) pg_hash
; /* Hash chain. */
94 LIST_HEAD(, proc
) pg_members
; /* Pointer to pgrp members. */
95 struct session
*pg_session
; /* Pointer to session. */
96 pid_t pg_id
; /* Pgrp id. */
97 int pg_jobc
; /* # procs qualifying pgrp for job control */
102 #define PROC_NULL (struct proc *)0
104 #define p_session p_pgrp->pg_session
105 #define p_pgid p_pgrp->pg_id
108 * Description of a process.
110 * This structure contains the information needed to manage a thread of
111 * control, known in UN*X as a process; it has references to substructures
112 * containing descriptions of things that the process uses, but may share
113 * with related processes. The process structure and the substructures
114 * are always addressible except for those marked "(PROC ONLY)" below,
115 * which might be addressible only on a processor on which the process
119 LIST_ENTRY(proc
) p_list
; /* List of all processes. */
122 struct ucred
*p_ucred
; /* Process owner's identity. */
123 struct filedesc
*p_fd
; /* Ptr to open files structure. */
124 struct pstats
*p_stats
; /* Accounting/statistics (PROC ONLY). */
125 struct plimit
*p_limit
; /* Process limits. */
126 struct sigacts
*p_sigacts
; /* Signal actions, state (PROC ONLY). */
128 #define p_rlimit p_limit->pl_rlimit
130 int p_flag
; /* P_* flags. */
131 char p_stat
; /* S* process status. */
132 char p_shutdownstate
;
135 pid_t p_pid
; /* Process identifier. */
136 LIST_ENTRY(proc
) p_pglist
; /* List of processes in pgrp. */
137 struct proc
*p_pptr
; /* Pointer to parent process. */
138 LIST_ENTRY(proc
) p_sibling
; /* List of sibling processes. */
139 LIST_HEAD(, proc
) p_children
; /* Pointer to list of children. */
141 /* The following fields are all zeroed upon creation in fork. */
142 #define p_startzero p_oppid
144 pid_t p_oppid
; /* Save parent pid during ptrace. XXX */
145 int p_dupfd
; /* Sideways return value from fdopen. XXX */
148 u_int p_estcpu
; /* Time averaged value of p_cpticks. */
149 int p_cpticks
; /* Ticks of cpu time. */
150 fixpt_t p_pctcpu
; /* %cpu for this process during p_swtime */
151 void *p_wchan
; /* Sleep address. */
152 char *p_wmesg
; /* Reason for sleep. */
153 u_int p_swtime
; /* DEPRECATED (Time swapped in or out.) */
154 #define p_argslen p_swtime /* Length of process arguments. */
155 u_int p_slptime
; /* Time since last blocked. */
157 struct itimerval p_realtimer
; /* Alarm timer. */
158 struct timeval p_rtime
; /* Real time. */
159 u_quad_t p_uticks
; /* Statclock hits in user mode. */
160 u_quad_t p_sticks
; /* Statclock hits in system mode. */
161 u_quad_t p_iticks
; /* Statclock hits processing intr. */
163 int p_traceflag
; /* Kernel trace points. */
164 struct vnode
*p_tracep
; /* Trace to vnode. */
166 sigset_t p_siglist
; /* DEPRECATED. */
168 struct vnode
*p_textvp
; /* Vnode of executable. */
170 /* End area that is zeroed on creation. */
171 #define p_endzero p_hash.le_next
174 * Not copied, not zero'ed.
175 * Belongs after p_pid, but here to avoid shifting proc elements.
177 LIST_ENTRY(proc
) p_hash
; /* Hash chain. */
178 TAILQ_HEAD( ,eventqelt
) p_evlist
;
180 /* The following fields are all copied upon creation in fork. */
181 #define p_startcopy p_sigmask
183 sigset_t p_sigmask
; /* DEPRECATED */
184 sigset_t p_sigignore
; /* Signals being ignored. */
185 sigset_t p_sigcatch
; /* Signals being caught by user. */
187 u_char p_priority
; /* Process priority. */
188 u_char p_usrpri
; /* User-priority based on p_cpu and p_nice. */
189 char p_nice
; /* Process "nice" value. */
190 char p_comm
[MAXCOMLEN
+1];
191 char p_name
[(2*MAXCOMLEN
)+1];
193 struct pgrp
*p_pgrp
; /* Pointer to process group. */
195 /* End area that is copied on creation. */
196 #define p_endcopy p_xstat
198 u_short p_xstat
; /* Exit status for wait; also stop signal. */
199 u_short p_acflag
; /* Accounting flags. */
200 struct rusage
*p_ru
; /* Exit information. XXX */
202 int p_debugger
; /* 1: can exec set-bit programs if suser */
204 void *task
; /* corresponding task */
205 void *sigwait_thread
; /* 'thread' holding sigwait */
206 char signal_lock
[72];
207 boolean_t sigwait
; /* indication to suspend */
208 void *exit_thread
; /* Which thread is exiting? */
209 user_addr_t user_stack
; /* where user stack was allocated */
210 void * exitarg
; /* exit arg for proc terminate */
211 void * vm_shm
; /* for sysV shared memory */
212 int p_argc
; /* saved argc for sysctl_procargs() */
213 int p_vforkcnt
; /* number of outstanding vforks */
214 void * p_vforkact
; /* activation running this vfork proc */
215 TAILQ_HEAD( , uthread
) p_uthlist
; /* List of uthreads */
216 /* Following fields are info from SIGCHLD */
221 TAILQ_HEAD( , aio_workq_entry
) aio_activeq
; /* active async IO requests */
222 int aio_active_count
; /* entries on aio_activeq */
223 TAILQ_HEAD( , aio_workq_entry
) aio_doneq
; /* completed async IO requests */
224 int aio_done_count
; /* entries on aio_doneq */
226 struct klist p_klist
; /* knote list */
227 lck_mtx_t p_mlock
; /* proc lock to protect evques */
228 lck_mtx_t p_fdmlock
; /* proc lock to protect evques */
229 unsigned int p_fdlock_pc
[4];
230 unsigned int p_fdunlock_pc
[4];
232 unsigned int p_lflag
; /* local flags */
233 unsigned int p_ladvflag
; /* local adv flags*/
234 unsigned int p_internalref
; /* temp refcount field */
237 unsigned int lockpc
[8];
238 unsigned int unlockpc
[8];
239 #endif /* SIGNAL_DEBUG */
240 #endif /* DIAGNOSTIC */
245 #define P_LDELAYTERM 0x1 /* */
246 #define P_LNOZOMB 0x2 /* */
247 #define P_LLOW_PRI_IO 0x4
249 #define P_LBACKGROUND_IO 0x10
250 #define P_LWAITING 0x20
251 #define P_LREFDRAIN 0x40
252 #define P_LREFDRAINWAIT 0x80
253 #define P_LREFDEAD 0x100
254 #define P_LTHSIGSTACK 0x200
256 /* advisory flags in the proc */
257 #define P_LADVLOCK 0x01
259 // LP64todo - should this move?
260 /* LP64 version of extern_proc. all pointers
261 * grow when we're dealing with a 64-bit process.
262 * WARNING - keep in sync with extern_proc
263 * but use native alignment of 64-bit process.
267 #include <sys/time.h> /* user_timeval, user_itimerval */
269 struct user_extern_proc
{
272 user_addr_t __p_forw
; /* Doubly-linked run/sleep queue. */
273 user_addr_t __p_back
;
275 struct user_timeval __p_starttime
; /* process start time */
277 user_addr_t p_vmspace
; /* Address space. */
278 user_addr_t p_sigacts
; /* Signal actions, state (PROC ONLY). */
279 int p_flag
; /* P_* flags. */
280 char p_stat
; /* S* process status. */
281 pid_t p_pid
; /* Process identifier. */
282 pid_t p_oppid
; /* Save parent pid during ptrace. XXX */
283 int p_dupfd
; /* Sideways return value from fdopen. XXX */
285 user_addr_t user_stack
__attribute((aligned(8))); /* where user stack was allocated */
286 user_addr_t exit_thread
; /* XXX Which thread is exiting? */
287 int p_debugger
; /* allow to debug */
288 boolean_t sigwait
; /* indication to suspend */
290 u_int p_estcpu
; /* Time averaged value of p_cpticks. */
291 int p_cpticks
; /* Ticks of cpu time. */
292 fixpt_t p_pctcpu
; /* %cpu for this process during p_swtime */
293 user_addr_t p_wchan
__attribute((aligned(8))); /* Sleep address. */
294 user_addr_t p_wmesg
; /* Reason for sleep. */
295 u_int p_swtime
; /* Time swapped in or out. */
296 u_int p_slptime
; /* Time since last blocked. */
297 struct user_itimerval p_realtimer
; /* Alarm timer. */
298 struct user_timeval p_rtime
; /* Real time. */
299 u_quad_t p_uticks
; /* Statclock hits in user mode. */
300 u_quad_t p_sticks
; /* Statclock hits in system mode. */
301 u_quad_t p_iticks
; /* Statclock hits processing intr. */
302 int p_traceflag
; /* Kernel trace points. */
303 user_addr_t p_tracep
__attribute((aligned(8))); /* Trace to vnode. */
304 int p_siglist
; /* DEPRECATED */
305 user_addr_t p_textvp
__attribute((aligned(8))); /* Vnode of executable. */
306 int p_holdcnt
; /* If non-zero, don't swap. */
307 sigset_t p_sigmask
; /* DEPRECATED. */
308 sigset_t p_sigignore
; /* Signals being ignored. */
309 sigset_t p_sigcatch
; /* Signals being caught by user. */
310 u_char p_priority
; /* Process priority. */
311 u_char p_usrpri
; /* User-priority based on p_cpu and p_nice. */
312 char p_nice
; /* Process "nice" value. */
313 char p_comm
[MAXCOMLEN
+1];
314 user_addr_t p_pgrp
__attribute((aligned(8))); /* Pointer to process group. */
315 user_addr_t p_addr
; /* Kernel virtual addr of u-area (PROC ONLY). */
316 u_short p_xstat
; /* Exit status for wait; also stop signal. */
317 u_short p_acflag
; /* Accounting flags. */
318 user_addr_t p_ru
__attribute((aligned(8))); /* Exit information. XXX */
323 * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
324 * as it is used to represent "no process group".
326 extern int nprocs
, maxproc
; /* Current and max number of procs. */
327 extern int maxprocperuid
; /* Current number of procs per uid */
328 __private_extern__
int hard_maxproc
; /* hard limit */
330 #define PID_MAX 30000
333 #define SESS_LEADER(p) ((p)->p_session->s_leader == (p))
334 #define SESSHOLD(s) ((s)->s_count++)
335 #define SESSRELE(s) sessrele(s)
337 #define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash])
338 extern LIST_HEAD(pidhashhead
, proc
) *pidhashtbl
;
339 extern u_long pidhash
;
341 #define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash])
342 extern LIST_HEAD(pgrphashhead
, pgrp
) *pgrphashtbl
;
343 extern u_long pgrphash
;
344 extern lck_grp_t
* proc_lck_grp
;
345 extern lck_grp_attr_t
* proc_lck_grp_attr
;
346 extern lck_attr_t
* proc_lck_attr
;
348 LIST_HEAD(proclist
, proc
);
349 extern struct proclist allproc
; /* List of all processes. */
350 extern struct proclist zombproc
; /* List of zombie processes. */
351 extern struct proc
*initproc
;
352 extern void pgdelete(struct pgrp
*pgrp
);
353 extern void sessrele(struct session
*sess
);
354 extern void procinit(void);
355 extern void proc_lock(struct proc
*);
356 extern void proc_unlock(struct proc
*);
357 extern void proc_fdlock(struct proc
*);
358 extern void proc_fdunlock(struct proc
*);
359 __private_extern__
char *proc_core_name(const char *name
, uid_t uid
, pid_t pid
);
360 extern int isinferior(struct proc
*, struct proc
*);
361 extern struct proc
*pfind(pid_t
); /* Find process by id. */
362 __private_extern__
struct proc
*pzfind(pid_t
); /* Find zombie by id. */
363 extern struct pgrp
*pgfind(pid_t
); /* Find process group by id. */
365 extern int chgproccnt(uid_t uid
, int diff
);
366 extern int enterpgrp(struct proc
*p
, pid_t pgid
, int mksess
);
367 extern void fixjobc(struct proc
*p
, struct pgrp
*pgrp
, int entering
);
368 extern int inferior(struct proc
*p
);
369 extern int leavepgrp(struct proc
*p
);
370 extern void resetpriority(struct proc
*);
371 extern void setrunnable(struct proc
*);
372 extern void setrunqueue(struct proc
*);
373 extern int sleep(void *chan
, int pri
);
374 extern int tsleep0(void *chan
, int pri
, const char *wmesg
, int timo
, int (*continuation
)(int));
375 extern int tsleep1(void *chan
, int pri
, const char *wmesg
, u_int64_t abstime
, int (*continuation
)(int));
376 extern int msleep0(void *chan
, lck_mtx_t
*mtx
, int pri
, const char *wmesg
, int timo
, int (*continuation
)(int));
377 extern void vfork_return(thread_t th_act
, struct proc
*p
, struct proc
*p2
, register_t
*retval
);
378 extern struct proc
* proc_findref(pid_t pid
);
379 extern void proc_dropref(struct proc
* p
);
380 extern struct proc
* proc_refinternal(proc_t p
, int funneled
);
381 extern void proc_dropinternal(struct proc
* p
, int funneled
);
383 #endif /* !_SYS_PROC_INTERNAL_H_ */