]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/proc_internal.h
xnu-792.10.96.tar.gz
[apple/xnu.git] / bsd / sys / proc_internal.h
CommitLineData
91447636
A
1/*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
37839358
A
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.
91447636 11 *
37839358
A
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
91447636
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
37839358
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
91447636
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/* Copyright (c) 1995, 1997 Apple Computer, Inc. All Rights Reserved */
23/*-
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.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
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.
47 *
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
58 * SUCH DAMAGE.
59 *
60 * @(#)proc_internal.h 8.15 (Berkeley) 5/19/95
61 */
62
63#ifndef _SYS_PROC_INTERNAL_H_
64#define _SYS_PROC_INTERNAL_H_
65
66#include <sys/proc.h>
67__BEGIN_DECLS
68#include <kern/locks.h>
69__END_DECLS
70
71/*
72 * One structure allocated per session.
73 */
74struct 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. */
81};
82
83/*
84 * One structure allocated per process group.
85 */
86struct pgrp {
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 */
92};
93
94struct proc;
95
ff6e181a 96#define PROC_NULL (struct proc *)0
91447636
A
97
98#define p_session p_pgrp->pg_session
99#define p_pgid p_pgrp->pg_id
100
101/*
102 * Description of a process.
103 *
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
110 * is running.
111 */
112struct proc {
113 LIST_ENTRY(proc) p_list; /* List of all processes. */
114
115 /* substructures: */
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). */
121
122#define p_rlimit p_limit->pl_rlimit
123
124 int p_flag; /* P_* flags. */
125 char p_stat; /* S* process status. */
126 char p_shutdownstate;
127 char p_pad1[2];
128
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. */
134
135/* The following fields are all zeroed upon creation in fork. */
136#define p_startzero p_oppid
137
138 pid_t p_oppid; /* Save parent pid during ptrace. XXX */
139 int p_dupfd; /* Sideways return value from fdopen. XXX */
140
141 /* scheduling */
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. */
150
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. */
156
157 int p_traceflag; /* Kernel trace points. */
158 struct vnode *p_tracep; /* Trace to vnode. */
159
160 sigset_t p_siglist; /* DEPRECATED. */
161
162 struct vnode *p_textvp; /* Vnode of executable. */
163
164/* End area that is zeroed on creation. */
165#define p_endzero p_hash.le_next
166
167 /*
168 * Not copied, not zero'ed.
169 * Belongs after p_pid, but here to avoid shifting proc elements.
170 */
171 LIST_ENTRY(proc) p_hash; /* Hash chain. */
172 TAILQ_HEAD( ,eventqelt) p_evlist;
173
174/* The following fields are all copied upon creation in fork. */
175#define p_startcopy p_sigmask
176
177 sigset_t p_sigmask; /* DEPRECATED */
178 sigset_t p_sigignore; /* Signals being ignored. */
179 sigset_t p_sigcatch; /* Signals being caught by user. */
180
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];
c0fea474 185 char p_name[(2*MAXCOMLEN)+1];
91447636
A
186
187 struct pgrp *p_pgrp; /* Pointer to process group. */
188
189/* End area that is copied on creation. */
190#define p_endcopy p_xstat
191
192 u_short p_xstat; /* Exit status for wait; also stop signal. */
193 u_short p_acflag; /* Accounting flags. */
194 struct rusage *p_ru; /* Exit information. XXX */
195
196 int p_debugger; /* 1: can exec set-bit programs if suser */
197
198 void *task; /* corresponding task */
199 void *sigwait_thread; /* 'thread' holding sigwait */
200 char signal_lock[72];
201 boolean_t sigwait; /* indication to suspend */
202 void *exit_thread; /* Which thread is exiting? */
203 user_addr_t user_stack; /* where user stack was allocated */
204 void * exitarg; /* exit arg for proc terminate */
205 void * vm_shm; /* for sysV shared memory */
206 int p_argc; /* saved argc for sysctl_procargs() */
207 int p_vforkcnt; /* number of outstanding vforks */
208 void * p_vforkact; /* activation running this vfork proc */
209 TAILQ_HEAD( , uthread) p_uthlist; /* List of uthreads */
210 /* Following fields are info from SIGCHLD */
211 pid_t si_pid;
212 u_short si_status;
213 u_short si_code;
214 uid_t si_uid;
215 TAILQ_HEAD( , aio_workq_entry ) aio_activeq; /* active async IO requests */
216 int aio_active_count; /* entries on aio_activeq */
217 TAILQ_HEAD( , aio_workq_entry ) aio_doneq; /* completed async IO requests */
218 int aio_done_count; /* entries on aio_doneq */
219
220 struct klist p_klist; /* knote list */
221 lck_mtx_t p_mlock; /* proc lock to protect evques */
222 lck_mtx_t p_fdmlock; /* proc lock to protect evques */
223 unsigned int p_fdlock_pc[4];
224 unsigned int p_fdunlock_pc[4];
225 int p_fpdrainwait;
b36670ce
A
226 unsigned int p_lflag; /* local flags */
227 unsigned int p_ladvflag; /* local adv flags*/
ff6e181a 228 unsigned int p_internalref; /* temp refcount field */
91447636
A
229#if DIAGNOSTIC
230#if SIGNAL_DEBUG
231 unsigned int lockpc[8];
232 unsigned int unlockpc[8];
233#endif /* SIGNAL_DEBUG */
234#endif /* DIAGNOSTIC */
235};
236
237
b36670ce 238/* local flags */
91447636
A
239#define P_LDELAYTERM 0x1 /* */
240#define P_LNOZOMB 0x2 /* */
241#define P_LLOW_PRI_IO 0x4
242#define P_LPEXIT 0x8
243#define P_LBACKGROUND_IO 0x10
b36670ce 244#define P_LWAITING 0x20
ff6e181a
A
245#define P_LREFDRAIN 0x40
246#define P_LREFDRAINWAIT 0x80
247#define P_LREFDEAD 0x100
c0fea474 248#define P_LTHSIGSTACK 0x200
b36670ce
A
249
250/* advisory flags in the proc */
251#define P_LADVLOCK 0x01
91447636
A
252
253// LP64todo - should this move?
254/* LP64 version of extern_proc. all pointers
255 * grow when we're dealing with a 64-bit process.
256 * WARNING - keep in sync with extern_proc
257 * but use native alignment of 64-bit process.
258 */
259
260#ifdef KERNEL
261#include <sys/time.h> /* user_timeval, user_itimerval */
262
91447636
A
263struct user_extern_proc {
264 union {
265 struct {
266 user_addr_t __p_forw; /* Doubly-linked run/sleep queue. */
267 user_addr_t __p_back;
268 } p_st1;
269 struct user_timeval __p_starttime; /* process start time */
270 } p_un;
271 user_addr_t p_vmspace; /* Address space. */
272 user_addr_t p_sigacts; /* Signal actions, state (PROC ONLY). */
273 int p_flag; /* P_* flags. */
274 char p_stat; /* S* process status. */
275 pid_t p_pid; /* Process identifier. */
276 pid_t p_oppid; /* Save parent pid during ptrace. XXX */
277 int p_dupfd; /* Sideways return value from fdopen. XXX */
278 /* Mach related */
c0fea474 279 user_addr_t user_stack __attribute((aligned(8))); /* where user stack was allocated */
91447636
A
280 user_addr_t exit_thread; /* XXX Which thread is exiting? */
281 int p_debugger; /* allow to debug */
282 boolean_t sigwait; /* indication to suspend */
283 /* scheduling */
284 u_int p_estcpu; /* Time averaged value of p_cpticks. */
285 int p_cpticks; /* Ticks of cpu time. */
286 fixpt_t p_pctcpu; /* %cpu for this process during p_swtime */
c0fea474 287 user_addr_t p_wchan __attribute((aligned(8))); /* Sleep address. */
91447636
A
288 user_addr_t p_wmesg; /* Reason for sleep. */
289 u_int p_swtime; /* Time swapped in or out. */
290 u_int p_slptime; /* Time since last blocked. */
291 struct user_itimerval p_realtimer; /* Alarm timer. */
292 struct user_timeval p_rtime; /* Real time. */
293 u_quad_t p_uticks; /* Statclock hits in user mode. */
294 u_quad_t p_sticks; /* Statclock hits in system mode. */
295 u_quad_t p_iticks; /* Statclock hits processing intr. */
296 int p_traceflag; /* Kernel trace points. */
c0fea474 297 user_addr_t p_tracep __attribute((aligned(8))); /* Trace to vnode. */
91447636 298 int p_siglist; /* DEPRECATED */
c0fea474 299 user_addr_t p_textvp __attribute((aligned(8))); /* Vnode of executable. */
91447636
A
300 int p_holdcnt; /* If non-zero, don't swap. */
301 sigset_t p_sigmask; /* DEPRECATED. */
302 sigset_t p_sigignore; /* Signals being ignored. */
303 sigset_t p_sigcatch; /* Signals being caught by user. */
304 u_char p_priority; /* Process priority. */
305 u_char p_usrpri; /* User-priority based on p_cpu and p_nice. */
306 char p_nice; /* Process "nice" value. */
307 char p_comm[MAXCOMLEN+1];
c0fea474 308 user_addr_t p_pgrp __attribute((aligned(8))); /* Pointer to process group. */
91447636
A
309 user_addr_t p_addr; /* Kernel virtual addr of u-area (PROC ONLY). */
310 u_short p_xstat; /* Exit status for wait; also stop signal. */
311 u_short p_acflag; /* Accounting flags. */
c0fea474 312 user_addr_t p_ru __attribute((aligned(8))); /* Exit information. XXX */
91447636 313};
91447636
A
314#endif /* KERNEL */
315
316/*
317 * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
318 * as it is used to represent "no process group".
319 */
320extern int nprocs, maxproc; /* Current and max number of procs. */
c0fea474 321extern int maxprocperuid; /* Current number of procs per uid */
91447636
A
322__private_extern__ int hard_maxproc; /* hard limit */
323
324#define PID_MAX 30000
325#define NO_PID 30001
326
327#define SESS_LEADER(p) ((p)->p_session->s_leader == (p))
328#define SESSHOLD(s) ((s)->s_count++)
329#define SESSRELE(s) sessrele(s)
330
331#define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash])
332extern LIST_HEAD(pidhashhead, proc) *pidhashtbl;
333extern u_long pidhash;
334
335#define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash])
336extern LIST_HEAD(pgrphashhead, pgrp) *pgrphashtbl;
337extern u_long pgrphash;
338extern lck_grp_t * proc_lck_grp;
339extern lck_grp_attr_t * proc_lck_grp_attr;
340extern lck_attr_t * proc_lck_attr;
341
342LIST_HEAD(proclist, proc);
343extern struct proclist allproc; /* List of all processes. */
344extern struct proclist zombproc; /* List of zombie processes. */
345extern struct proc *initproc;
346extern void pgdelete(struct pgrp *pgrp);
347extern void sessrele(struct session *sess);
348extern void procinit(void);
349extern void proc_lock(struct proc *);
350extern void proc_unlock(struct proc *);
351extern void proc_fdlock(struct proc *);
352extern void proc_fdunlock(struct proc *);
353__private_extern__ char *proc_core_name(const char *name, uid_t uid, pid_t pid);
354extern int isinferior(struct proc *, struct proc *);
355extern struct proc *pfind(pid_t); /* Find process by id. */
356__private_extern__ struct proc *pzfind(pid_t); /* Find zombie by id. */
357extern struct pgrp *pgfind(pid_t); /* Find process group by id. */
358
359extern int chgproccnt(uid_t uid, int diff);
360extern int enterpgrp(struct proc *p, pid_t pgid, int mksess);
361extern void fixjobc(struct proc *p, struct pgrp *pgrp, int entering);
362extern int inferior(struct proc *p);
363extern int leavepgrp(struct proc *p);
364extern void resetpriority(struct proc *);
365extern void setrunnable(struct proc *);
366extern void setrunqueue(struct proc *);
367extern int sleep(void *chan, int pri);
368extern int tsleep0(void *chan, int pri, const char *wmesg, int timo, int (*continuation)(int));
369extern int tsleep1(void *chan, int pri, const char *wmesg, u_int64_t abstime, int (*continuation)(int));
370extern int msleep0(void *chan, lck_mtx_t *mtx, int pri, const char *wmesg, int timo, int (*continuation)(int));
371extern void vfork_return(thread_t th_act, struct proc *p, struct proc *p2, register_t *retval);
ff6e181a
A
372extern struct proc * proc_findref(pid_t pid);
373extern void proc_dropref(struct proc * p);
374extern struct proc * proc_refinternal(proc_t p, int funneled);
375extern void proc_dropinternal(struct proc * p, int funneled);
91447636
A
376
377#endif /* !_SYS_PROC_INTERNAL_H_ */