]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/proc.h
xnu-1504.9.26.tar.gz
[apple/xnu.git] / bsd / sys / proc.h
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/* Copyright (c) 1995, 1997 Apple Computer, Inc. All Rights Reserved */
29/*-
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.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
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.
53 *
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
64 * SUCH DAMAGE.
65 *
66 * @(#)proc.h 8.15 (Berkeley) 5/19/95
67 */
68
69#ifndef _SYS_PROC_H_
70#define _SYS_PROC_H_
71
9bccf70c 72#include <sys/appleapiopts.h>
1c79356b 73#include <sys/cdefs.h>
1c79356b
A
74#include <sys/select.h> /* For struct selinfo. */
75#include <sys/queue.h>
76#include <sys/lock.h>
77#include <sys/param.h>
55e303ae 78#include <sys/event.h>
91447636
A
79#ifdef KERNEL
80#include <sys/kernel_types.h>
81#endif
82#include <mach/boolean.h>
1c79356b 83
b0d623f7 84#if defined(XNU_KERNEL_PRIVATE) || !defined(KERNEL)
1c79356b 85
9bccf70c
A
86struct session;
87struct pgrp;
88struct proc;
9bccf70c 89
1c79356b
A
90/* Exported fields for kern sysctls */
91struct extern_proc {
9bccf70c
A
92 union {
93 struct {
94 struct proc *__p_forw; /* Doubly-linked run/sleep queue. */
95 struct proc *__p_back;
96 } p_st1;
97 struct timeval __p_starttime; /* process start time */
98 } p_un;
99#define p_forw p_un.p_st1.__p_forw
100#define p_back p_un.p_st1.__p_back
101#define p_starttime p_un.__p_starttime
1c79356b
A
102 struct vmspace *p_vmspace; /* Address space. */
103 struct sigacts *p_sigacts; /* Signal actions, state (PROC ONLY). */
104 int p_flag; /* P_* flags. */
105 char p_stat; /* S* process status. */
106 pid_t p_pid; /* Process identifier. */
107 pid_t p_oppid; /* Save parent pid during ptrace. XXX */
108 int p_dupfd; /* Sideways return value from fdopen. XXX */
109 /* Mach related */
110 caddr_t user_stack; /* where user stack was allocated */
111 void *exit_thread; /* XXX Which thread is exiting? */
112 int p_debugger; /* allow to debug */
113 boolean_t sigwait; /* indication to suspend */
114 /* scheduling */
115 u_int p_estcpu; /* Time averaged value of p_cpticks. */
116 int p_cpticks; /* Ticks of cpu time. */
117 fixpt_t p_pctcpu; /* %cpu for this process during p_swtime */
118 void *p_wchan; /* Sleep address. */
119 char *p_wmesg; /* Reason for sleep. */
120 u_int p_swtime; /* Time swapped in or out. */
121 u_int p_slptime; /* Time since last blocked. */
122 struct itimerval p_realtimer; /* Alarm timer. */
123 struct timeval p_rtime; /* Real time. */
124 u_quad_t p_uticks; /* Statclock hits in user mode. */
125 u_quad_t p_sticks; /* Statclock hits in system mode. */
126 u_quad_t p_iticks; /* Statclock hits processing intr. */
127 int p_traceflag; /* Kernel trace points. */
128 struct vnode *p_tracep; /* Trace to vnode. */
b0d623f7 129 int p_siglist; /* DEPRECATED. */
1c79356b
A
130 struct vnode *p_textvp; /* Vnode of executable. */
131 int p_holdcnt; /* If non-zero, don't swap. */
9bccf70c 132 sigset_t p_sigmask; /* DEPRECATED. */
1c79356b
A
133 sigset_t p_sigignore; /* Signals being ignored. */
134 sigset_t p_sigcatch; /* Signals being caught by user. */
135 u_char p_priority; /* Process priority. */
136 u_char p_usrpri; /* User-priority based on p_cpu and p_nice. */
137 char p_nice; /* Process "nice" value. */
138 char p_comm[MAXCOMLEN+1];
139 struct pgrp *p_pgrp; /* Pointer to process group. */
140 struct user *p_addr; /* Kernel virtual addr of u-area (PROC ONLY). */
141 u_short p_xstat; /* Exit status for wait; also stop signal. */
142 u_short p_acflag; /* Accounting flags. */
143 struct rusage *p_ru; /* Exit information. XXX */
144};
145
1c79356b
A
146
147/* Status values. */
148#define SIDL 1 /* Process being created by fork. */
149#define SRUN 2 /* Currently runnable. */
150#define SSLEEP 3 /* Sleeping on an address. */
151#define SSTOP 4 /* Process debugging or suspension. */
152#define SZOMB 5 /* Awaiting collection by parent. */
153
2d21ac55 154/* These flags are kept in extern_proc.p_flag. */
91447636
A
155#define P_ADVLOCK 0x00000001 /* Process may hold POSIX adv. lock */
156#define P_CONTROLT 0x00000002 /* Has a controlling terminal */
157#define P_LP64 0x00000004 /* Process is LP64 */
158#define P_NOCLDSTOP 0x00000008 /* No SIGCHLD when children stop */
159
160#define P_PPWAIT 0x00000010 /* Parent waiting for chld exec/exit */
161#define P_PROFIL 0x00000020 /* Has started profiling */
162#define P_SELECT 0x00000040 /* Selecting; wakeup/waiting danger */
163#define P_CONTINUED 0x00000080 /* Process was stopped and continued */
164
165#define P_SUGID 0x00000100 /* Has set privileges since last exec */
166#define P_SYSTEM 0x00000200 /* Sys proc: no sigs, stats or swap */
167#define P_TIMEOUT 0x00000400 /* Timing out during sleep */
168#define P_TRACED 0x00000800 /* Debugged process being traced */
169
2d21ac55
A
170#define P_RESV3 0x00001000 /* (P_WAITED)Debugging prc has waited for child */
171#define P_WEXIT 0x00002000 /* Working on exiting */
91447636 172#define P_EXEC 0x00004000 /* Process called exec. */
1c79356b 173
1c79356b 174/* Should be moved to machine-dependent areas. */
91447636 175#define P_OWEUPC 0x00008000 /* Owe process an addupc() call at next ast. */
1c79356b 176
91447636 177#define P_AFFINITY 0x00010000 /* xxx */
0c530ab8
A
178#define P_TRANSLATED 0x00020000 /* xxx */
179#define P_CLASSIC P_TRANSLATED /* xxx */
55e303ae 180/*
91447636
A
181#define P_FSTRACE 0x10000 / * tracing via file system (elsewhere?) * /
182#define P_SSTEP 0x20000 / * process needs single-step fixup ??? * /
55e303ae 183*/
1c79356b 184
2d21ac55
A
185#define P_RESV5 0x00040000 /* (P_WAITING) process has a wait() in progress */
186#define P_CHECKOPENEVT 0x00080000 /* check if a vnode has the OPENEVT flag set on open */
91447636 187
2d21ac55 188#define P_DEPENDENCY_CAPABLE 0x00100000 /* process is ok to call vfs_markdependency() */
91447636
A
189#define P_REBOOT 0x00200000 /* Process called reboot() */
190#define P_TBE 0x00400000 /* Process is TBE */
2d21ac55 191#define P_RESV7 0x00800000 /* (P_SIGEXC)signal exceptions */
91447636 192
2d21ac55
A
193#define P_THCWD 0x01000000 /* process has thread cwd */
194#define P_RESV9 0x02000000 /* (P_VFORK)process has vfork children */
195#define P_RESV10 0x04000000 /* used to be P_NOATTACH */
196#define P_RESV11 0x08000000 /* (P_INVFORK) proc in vfork */
91447636 197
9bccf70c
A
198#define P_NOSHLIB 0x10000000 /* no shared libs are in use for proc */
199 /* flag set on exec */
200#define P_FORCEQUOTA 0x20000000 /* Force quota for root */
201#define P_NOCLDWAIT 0x40000000 /* No zombies when chil procs exit */
55e303ae 202#define P_NOREMOTEHANG 0x80000000 /* Don't hang on remote FS ops */
0b4e3aa0 203
91447636
A
204#define P_INMEM 0 /* Obsolete: retained for compilation */
205#define P_NOSWAP 0 /* Obsolete: retained for compilation */
206#define P_PHYSIO 0 /* Obsolete: retained for compilation */
207#define P_FSTRACE 0 /* Obsolete: retained for compilation */
208#define P_SSTEP 0 /* Obsolete: retained for compilation */
1c79356b 209
b0d623f7 210#endif /* XNU_KERNEL_PRIVATE || !KERNEL */
1c79356b
A
211
212#ifdef KERNEL
1c79356b 213__BEGIN_DECLS
91447636
A
214
215extern proc_t kernproc;
216
2d21ac55
A
217extern int proc_is_classic(proc_t p);
218proc_t current_proc_EXTERNAL(void);
9bccf70c 219
91447636 220extern int msleep(void *chan, lck_mtx_t *mtx, int pri, const char *wmesg, struct timespec * ts );
91447636
A
221extern void wakeup(void *chan);
222extern void wakeup_one(caddr_t chan);
223
224/* proc kpis */
225/* this routine returns the pid of the current process */
226extern int proc_selfpid(void);
227/* this routine returns the pid of the parent of the current process */
228extern int proc_selfppid(void);
229/* this routine returns sends a signal signum to the process identified by the pid */
230extern void proc_signal(int pid, int signum);
231/* this routine checks whether any signal identified by the mask are pending in the process identified by the pid. The check is on all threads of the process. */
232extern int proc_issignal(int pid, sigset_t mask);
233/* this routine returns 1 if the pid1 is inferior of pid2 */
234extern int proc_isinferior(int pid1, int pid2);
235/* this routine copies the process's name of the executable to the passed in buffer. It
236 * is always null terminated. The size of the buffer is to be passed in as well. This
237 * routine is to be used typically for debugging
238 */
239void proc_name(int pid, char * buf, int size);
240/* This routine is simillar to proc_name except it returns for current process */
241void proc_selfname(char * buf, int size);
242
243/* find a process with a given pid. This comes with a reference which needs to be dropped by proc_rele */
244extern proc_t proc_find(int pid);
245/* returns a handle to current process which is referenced. The reference needs to be dropped with proc_rele */
246extern proc_t proc_self(void);
247/* releases the held reference on the process */
248extern int proc_rele(proc_t p);
249/* returns the pid of the given process */
250extern int proc_pid(proc_t);
251/* returns the pid of the parent of a given process */
252extern int proc_ppid(proc_t);
253/* returns 1 if the process is marked for no remote hangs */
254extern int proc_noremotehang(proc_t);
255/* returns 1 is the process is marked for force quota */
256extern int proc_forcequota(proc_t);
257
258/* this routine returns 1 if the process is running with 64bit address space, else 0 */
259extern int proc_is64bit(proc_t);
260/* is this process exiting? */
261extern int proc_exiting(proc_t);
2d21ac55
A
262/* this routine returns error if the process is not one with super user privileges */
263int proc_suser(proc_t p);
264/* returns the cred assicaited with the process; temporary api */
265kauth_cred_t proc_ucred(proc_t p);
2d21ac55 266
2d21ac55 267extern int proc_tbe(proc_t);
91447636 268
b0d623f7
A
269/*!
270 @function proc_selfpgrpid
271 @abstract Get the process group id for the current process, as with proc_pgrpid().
272 @return pgrpid of current process.
273 */
274pid_t proc_selfpgrpid(void);
275
276/*!
277 @function proc_pgrpid
278 @abstract Get the process group id for the passed-in process.
279 @param p Process whose pgrpid to grab.
280 @return pgrpid for "p".
281 */
282pid_t proc_pgrpid(proc_t);
283
2d21ac55 284#ifdef KERNEL_PRIVATE
b0d623f7
A
285// mark a process as being allowed to call vfs_markdependency()
286void bsd_set_dependency_capable(task_t task);
91447636 287extern int IS_64BIT_PROCESS(proc_t);
91447636 288
91447636
A
289extern int tsleep(void *chan, int pri, const char *wmesg, int timo);
290extern int msleep1(void *chan, lck_mtx_t *mtx, int pri, const char *wmesg, u_int64_t timo);
593a1d5f
A
291
292extern int proc_pidversion(proc_t);
293extern int proc_getcdhash(proc_t, unsigned char *);
294#endif /* KERNEL_PRIVATE */
1c79356b 295
91447636 296__END_DECLS
9bccf70c 297
1c79356b
A
298#endif /* KERNEL */
299
300#endif /* !_SYS_PROC_H_ */