- Merge aicom-network-branch (still without the NDIS stuff)
[reactos.git] / reactos / lib / drivers / oskittcp / include / freebsd / src / sys / sys / proc.h
1 /*
2 * Copyright (c) 1996-1998 University of Utah and the Flux Group.
3 * All rights reserved.
4 *
5 * This file is part of the Flux OSKit. The OSKit is free software, also known
6 * as "open source;" you can redistribute it and/or modify it under the terms
7 * of the GNU General Public License (GPL), version 2, as published by the Free
8 * Software Foundation (FSF). To explore alternate licensing terms, contact
9 * the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
10 *
11 * The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GPL for more details. You should have
14 * received a copy of the GPL along with the OSKit; see the file COPYING. If
15 * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
16 */
17 /*-
18 * Copyright (c) 1986, 1989, 1991, 1993
19 * The Regents of the University of California. All rights reserved.
20 * (c) UNIX System Laboratories, Inc.
21 * All or some portions of this file are derived from material licensed
22 * to the University of California by American Telephone and Telegraph
23 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
24 * the permission of UNIX System Laboratories, Inc.
25 *
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
28 * are met:
29 * 1. Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in the
33 * documentation and/or other materials provided with the distribution.
34 * 3. All advertising materials mentioning features or use of this software
35 * must display the following acknowledgement:
36 * This product includes software developed by the University of
37 * California, Berkeley and its contributors.
38 * 4. Neither the name of the University nor the names of its contributors
39 * may be used to endorse or promote products derived from this software
40 * without specific prior written permission.
41 *
42 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 * SUCH DAMAGE.
53 *
54 * @(#)proc.h 8.8 (Berkeley) 1/21/94
55 * $\Id: proc.h,v 1.17.4.1 1996/06/04 02:45:01 davidg Exp $
56 */
57
58 #ifndef _SYS_PROC_H_
59 #define _SYS_PROC_H_
60
61 #include <machine/proc.h> /* Machine-dependent proc substruct. */
62 #include <sys/rtprio.h> /* For struct rtprio. */
63 #include <sys/select.h> /* For struct selinfo. */
64 #include <sys/time.h> /* For structs itimerval, timeval. */
65 #include <sys/socketvar.h>
66
67 #ifdef OSKIT
68 #ifndef __REACTOS__
69 #include <oskit/dev/dev.h>
70 #else
71 #include <osenv.h>
72 #endif
73 #endif
74
75 /*
76 * One structure allocated per session.
77 */
78 struct session {
79 int s_count; /* Ref cnt; pgrps in session. */
80 struct proc *s_leader; /* Session leader. */
81 struct vnode *s_ttyvp; /* Vnode of controlling terminal. */
82 struct tty *s_ttyp; /* Controlling terminal. */
83 char s_login[MAXLOGNAME]; /* Setlogin() name. */
84 };
85
86 /*
87 * One structure allocated per process group.
88 */
89 struct pgrp {
90 struct pgrp *pg_hforw; /* Forward link in hash bucket. */
91 struct proc *pg_mem; /* Pointer to pgrp members. */
92 struct session *pg_session; /* Pointer to session. */
93 pid_t pg_id; /* Pgrp id. */
94 int pg_jobc; /* # procs qualifying pgrp for job control */
95 };
96
97 /*
98 * Description of a process.
99 *
100 * This structure contains the information needed to manage a thread of
101 * control, known in UN*X as a process; it has references to substructures
102 * containing descriptions of things that the process uses, but may share
103 * with related processes. The process structure and the substructures
104 * are always addressible except for those marked "(PROC ONLY)" below,
105 * which might be addressible only on a processor on which the process
106 * is running.
107 */
108 struct proc {
109 #ifndef OSKIT
110 struct proc *p_forw; /* Doubly-linked run/sleep queue. */
111 struct proc *p_back;
112 struct proc *p_next; /* Linked list of active procs */
113 struct proc **p_prev; /* and zombies. */
114
115 /* substructures: */
116 struct pcred *p_cred; /* 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 vmspace *p_vmspace; /* Address space. */
121 struct sigacts *p_sigacts; /* Signal actions, state (PROC ONLY). */
122
123 #define p_ucred p_cred->pc_ucred
124 #define p_rlimit p_limit->pl_rlimit
125
126 int p_flag; /* P_* flags. */
127 char p_stat; /* S* process status. */
128
129 char p_pad1[3];
130
131 pid_t p_pid; /* Process identifier. */
132 struct proc *p_hash; /* Hashed based on p_pid for kill+exit+... */
133 struct proc *p_pgrpnxt; /* Pointer to next process in process group. */
134 struct proc *p_pptr; /* Pointer to process structure of parent. */
135 struct proc *p_osptr; /* Pointer to older sibling processes. */
136
137 /* The following fields are all zeroed upon creation in fork. */
138 #define p_startzero p_ysptr
139 struct proc *p_ysptr; /* Pointer to younger siblings. */
140 struct proc *p_cptr; /* Pointer to youngest living child. */
141 pid_t p_oppid; /* Save parent pid during ptrace. XXX */
142 int p_dupfd; /* Sideways return value from fdopen. XXX */
143
144 /* scheduling */
145 u_int p_estcpu; /* Time averaged value of p_cpticks. */
146 int p_cpticks; /* Ticks of cpu time. */
147 fixpt_t p_pctcpu; /* %cpu for this process during p_swtime */
148 void *p_wchan; /* Sleep address. */
149 char *p_wmesg; /* Reason for sleep. */
150 u_int p_swtime; /* Time swapped in or out. */
151 u_int p_slptime; /* Time since last blocked. */
152
153 struct itimerval p_realtimer; /* Alarm timer. */
154 struct timeval p_rtime; /* Real time. */
155 u_quad_t p_uticks; /* Statclock hits in user mode. */
156 u_quad_t p_sticks; /* Statclock hits in system mode. */
157 u_quad_t p_iticks; /* Statclock hits processing intr. */
158
159 int p_traceflag; /* Kernel trace points. */
160 struct vnode *p_tracep; /* Trace to vnode. */
161
162 int p_siglist; /* Signals arrived but not delivered. */
163
164 struct vnode *p_textvp; /* Vnode of executable. */
165
166 char p_lock; /* Process lock count. */
167 char p_pad2[3]; /* alignment */
168 long p_spare[2]; /* Pad to 256, avoid shifting eproc. XXX */
169
170 /* End area that is zeroed on creation. */
171 #define p_endzero p_startcopy
172
173 /* The following fields are all copied upon creation in fork. */
174 #define p_startcopy p_sigmask
175
176 sigset_t p_sigmask; /* Current signal mask. */
177 sigset_t p_sigignore; /* Signals being ignored. */
178 sigset_t p_sigcatch; /* Signals being caught by user. */
179
180 u_char p_priority; /* Process priority. */
181 u_char p_usrpri; /* User-priority based on p_cpu and p_nice. */
182 char p_nice; /* Process "nice" value. */
183 char p_comm[MAXCOMLEN+1];
184
185 struct pgrp *p_pgrp; /* Pointer to process group. */
186
187 struct sysentvec *p_sysent; /* System call dispatch information. */
188
189 struct rtprio p_rtprio; /* Realtime priority. */
190 /* End area that is copied on creation. */
191 #define p_endcopy p_thread
192 int p_thread; /* Id for this "thread"; Mach glue. XXX */
193 struct user *p_addr; /* Kernel virtual addr of u-area (PROC ONLY). */
194 struct mdproc p_md; /* Any machine-dependent fields. */
195
196 u_short p_xstat; /* Exit status for wait; also stop signal. */
197 u_short p_acflag; /* Accounting flags. */
198 struct rusage *p_ru; /* Exit information. XXX */
199 #else /* OSKIT */
200 /*
201 * let's build our own rudimentary struct proc
202 */
203 struct proc *p_forw; /* Doubly-linked run/sleep queue. */
204 struct pcred *p_cred; /* Process owner's identity. */
205 struct pstats *p_stats; /* Accounting/statistics (PROC ONLY). */
206 #define p_ucred p_cred->pc_ucred
207 int p_flag; /* P_* flags. */
208 char p_stat; /* S* process status. */
209 pid_t p_pid; /* Process identifier. */
210 void *p_wchan; /* Sleep address. */
211 char *p_wmesg; /* Reason for sleep. */
212 u_short p_acflag; /* Accounting flags. */
213
214 osenv_sleeprec_t p_sr;
215 /*
216 * When selrecord is invoked, this points to an object used to
217 * manage a set of listeners
218 */
219 struct listener_mgr *p_sel;
220 #endif /* !OSKIT */
221 };
222
223 #define p_session p_pgrp->pg_session
224 #define p_pgid p_pgrp->pg_id
225
226 /* Status values. */
227 #define SIDL 1 /* Process being created by fork. */
228 #define SRUN 2 /* Currently runnable. */
229 #define SSLEEP 3 /* Sleeping on an address. */
230 #define SSTOP 4 /* Process debugging or suspension. */
231 #define SZOMB 5 /* Awaiting collection by parent. */
232
233 /* These flags are kept in p_flags. */
234 #define P_ADVLOCK 0x00001 /* Process may hold a POSIX advisory lock. */
235 #define P_CONTROLT 0x00002 /* Has a controlling terminal. */
236 #define P_INMEM 0x00004 /* Loaded into memory. */
237 #define P_NOCLDSTOP 0x00008 /* No SIGCHLD when children stop. */
238 #define P_PPWAIT 0x00010 /* Parent is waiting for child to exec/exit. */
239 #define P_PROFIL 0x00020 /* Has started profiling. */
240 #define P_SELECT 0x00040 /* Selecting; wakeup/waiting danger. */
241 #define P_SINTR 0x00080 /* Sleep is interruptible. */
242 #define P_SUGID 0x00100 /* Had set id privileges since last exec. */
243 #define P_SYSTEM 0x00200 /* System proc: no sigs, stats or swapping. */
244 #define P_TIMEOUT 0x00400 /* Timing out during sleep. */
245 #define P_TRACED 0x00800 /* Debugged process being traced. */
246 #define P_WAITED 0x01000 /* Debugging process has waited for child. */
247 #define P_WEXIT 0x02000 /* Working on exiting. */
248 #define P_EXEC 0x04000 /* Process called exec. */
249 #define P_SWAPPING 0x40000 /* Process is being swapped. */
250
251 /* Should probably be changed into a hold count (They have. -DG). */
252 #define P_NOSWAP 0x08000 /* Another flag to prevent swap out. */
253 #define P_PHYSIO 0x10000 /* Doing physical I/O. */
254
255 /* Should be moved to machine-dependent areas. */
256 #define P_OWEUPC 0x20000 /* Owe process an addupc() call at next ast. */
257
258 /*
259 * MOVE TO ucred.h?
260 *
261 * Shareable process credentials (always resident). This includes a reference
262 * to the current user credentials as well as real and saved ids that may be
263 * used to change ids.
264 */
265 struct pcred {
266 struct ucred *pc_ucred; /* Current credentials. */
267 uid_t p_ruid; /* Real user id. */
268 uid_t p_svuid; /* Saved effective user id. */
269 gid_t p_rgid; /* Real group id. */
270 gid_t p_svgid; /* Saved effective group id. */
271 int p_refcnt; /* Number of references. */
272 };
273
274 #ifdef KERNEL
275 /*
276 * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
277 * as it is used to represent "no process group".
278 */
279 #define PID_MAX 30000
280 #define NO_PID 30001
281 #define PIDHASH(pid) ((pid) & pidhashmask)
282
283 #define SESS_LEADER(p) ((p)->p_session->s_leader == (p))
284 #define SESSHOLD(s) ((s)->s_count++)
285 #define SESSRELE(s) { \
286 if (--(s)->s_count == 0) \
287 FREE(s, M_SESSION); \
288 }
289
290 extern struct proc *pidhash[]; /* In param.c. */
291 extern struct pgrp *pgrphash[]; /* In param.c. */
292 extern struct proc *curproc; /* Current running proc. */
293 extern struct proc proc0; /* Process slot for swapper. */
294 extern int nprocs, maxproc; /* Current and max number of procs. */
295 extern int maxprocperuid; /* Max procs per uid. */
296 extern int pidhashmask; /* In param.c. */
297
298 extern volatile struct proc *allproc; /* List of active procs. */
299 extern struct proc *zombproc; /* List of zombie procs. */
300 extern struct proc *initproc, *pageproc; /* Process slots for init, pager. */
301
302 #define NQS 32 /* 32 run queues. */
303 struct prochd {
304 struct proc *ph_link; /* Linked list of running processes. */
305 struct proc *ph_rlink;
306 };
307 extern struct prochd qs[];
308 extern struct prochd rtqs[];
309 extern struct prochd idqs[];
310 extern int whichqs; /* Bit mask summary of non-empty Q's. */
311
312 int chgproccnt __P((uid_t, int));
313 struct proc *pfind __P((pid_t)); /* Find process by id. */
314 struct proc *zpfind __P((pid_t)); /* Find zombie process by id. */
315 struct pgrp *pgfind __P((pid_t)); /* Find process group by id. */
316 void mi_switch __P((void));
317 void resetpriority __P((struct proc *));
318 void roundrobin __P((void *));
319 void schedcpu __P((void *));
320 void setrunnable __P((struct proc *));
321 void setrunqueue __P((struct proc *));
322 void remrq __P((struct proc *));
323 void cpu_switch __P((struct proc *));
324 void sleep __P((void *chan, int pri));
325 int tsleep __P((void *chan, int pri, char *wmesg, int timo));
326 void unsleep __P((struct proc *));
327 void wakeup __P((struct socket *so, void *chan));
328
329 __dead void cpu_exit __P((struct proc *)) __dead2;
330 __dead void exit1 __P((struct proc *, int)) __dead2;
331 void fixjobc __P((struct proc *, struct pgrp *, int));
332 int acct_process __P((struct proc *));
333 int leavepgrp __P((struct proc *));
334 int enterpgrp __P((struct proc *, pid_t, int));
335 int trace_req __P((struct proc *));
336 void cpu_wait __P((struct proc *));
337 int cpu_coredump __P((struct proc *, struct vnode *, struct ucred *));
338 int inferior __P((struct proc *));
339 #endif /* KERNEL */
340
341 #endif /* !_SYS_PROC_H_ */