Annotation of src/sys/sys/proc.h, Revision 1.136
1.136 ! christos 1: /* $NetBSD: proc.h,v 1.135 2001/12/08 00:35:32 thorpej Exp $ */
1.29 cgd 2:
3: /*-
4: * Copyright (c) 1986, 1989, 1991, 1993
5: * The Regents of the University of California. All rights reserved.
6: * (c) UNIX System Laboratories, Inc.
7: * All or some portions of this file are derived from material licensed
8: * to the University of California by American Telephone and Telegraph
9: * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10: * the permission of UNIX System Laboratories, Inc.
11: *
12: * Redistribution and use in source and binary forms, with or without
13: * modification, are permitted provided that the following conditions
14: * are met:
15: * 1. Redistributions of source code must retain the above copyright
16: * notice, this list of conditions and the following disclaimer.
17: * 2. Redistributions in binary form must reproduce the above copyright
18: * notice, this list of conditions and the following disclaimer in the
19: * documentation and/or other materials provided with the distribution.
20: * 3. All advertising materials mentioning features or use of this software
21: * must display the following acknowledgement:
22: * This product includes software developed by the University of
23: * California, Berkeley and its contributors.
24: * 4. Neither the name of the University nor the names of its contributors
25: * may be used to endorse or promote products derived from this software
26: * without specific prior written permission.
27: *
28: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38: * SUCH DAMAGE.
39: *
1.59 fvdl 40: * @(#)proc.h 8.15 (Berkeley) 5/19/95
1.29 cgd 41: */
42:
43: #ifndef _SYS_PROC_H_
44: #define _SYS_PROC_H_
1.57 mrg 45:
1.131 mrg 46: #if defined(_KERNEL_OPT)
1.83 thorpej 47: #include "opt_multiprocessor.h"
48: #endif
49:
1.93 thorpej 50: #if defined(_KERNEL)
1.83 thorpej 51: #include <machine/cpu.h> /* curcpu() and cpu_info */
52: #endif
1.122 lukem 53: #include <machine/proc.h> /* Machine-dependent proc substruct */
1.79 thorpej 54: #include <sys/lock.h>
1.32 mycroft 55: #include <sys/queue.h>
1.87 thorpej 56: #include <sys/callout.h>
1.118 jdolecek 57: #include <sys/signalvar.h>
1.29 cgd 58:
59: /*
60: * One structure allocated per session.
61: */
1.122 lukem 62: struct session {
63: int s_count; /* Ref cnt; pgrps in session */
64: struct proc *s_leader; /* Session leader */
65: struct vnode *s_ttyvp; /* Vnode of controlling terminal */
66: struct tty *s_ttyp; /* Controlling terminal */
67: char s_login[MAXLOGNAME]; /* Setlogin() name */
68: pid_t s_sid; /* Session ID (pid of leader) */
1.29 cgd 69: };
70:
71: /*
72: * One structure allocated per process group.
73: */
1.122 lukem 74: struct pgrp {
75: LIST_ENTRY(pgrp) pg_hash; /* Hash chain */
76: LIST_HEAD(, proc) pg_members; /* Pointer to pgrp members */
77: struct session *pg_session; /* Pointer to session */
78: pid_t pg_id; /* Pgrp id */
79: int pg_jobc; /*
80: * Number of processes qualifying
81: * pgrp for job control
82: */
1.29 cgd 83: };
84:
85: /*
1.40 christos 86: * One structure allocated per emulation.
87: */
88: struct exec_package;
89: struct ps_strings;
90:
1.122 lukem 91: struct emul {
92: const char *e_name; /* Symbolic name */
93: const char *e_path; /* Extra emulation path (NULL if none)*/
1.130 manu 94: #ifndef __HAVE_MINIMAL_EMUL
1.129 manu 95: int e_flags; /* Miscellaneous flags, see above */
1.116 mycroft 96: /* Syscall handling function */
1.122 lukem 97: const int *e_errno; /* Errno array */
98: int e_nosys; /* Offset of the nosys() syscall */
99: int e_nsysent; /* Number of system call entries */
1.116 mycroft 100: #endif
1.111 jdolecek 101: const struct sysent *e_sysent; /* System call array */
1.122 lukem 102: const char * const *e_syscallnames; /* System call name array */
1.120 jdolecek 103: /* Signal sending function */
1.122 lukem 104: void (*e_sendsig) __P((sig_t, int, sigset_t *, u_long));
1.133 christos 105: void (*e_trapsignal) __P((struct proc *, int, u_long));
1.122 lukem 106: char *e_sigcode; /* Start of sigcode */
107: char *e_esigcode; /* End of sigcode */
1.134 jdolecek 108: /* Set registers before execution */
109: void (*e_setregs) __P((struct proc *, struct exec_package *,
110: u_long));
1.106 jdolecek 111:
1.112 jdolecek 112: /* Per-process hooks */
1.122 lukem 113: void (*e_proc_exec) __P((struct proc *,
114: struct exec_package *));
115: void (*e_proc_fork) __P((struct proc *p,
116: struct proc *parent));
117: void (*e_proc_exit) __P((struct proc *));
1.112 jdolecek 118:
1.116 mycroft 119: #ifdef __HAVE_SYSCALL_INTERN
1.122 lukem 120: void (*e_syscall_intern) __P((struct proc *));
1.116 mycroft 121: #else
1.122 lukem 122: void (*e_syscall) __P((void));
1.116 mycroft 123: #endif
1.40 christos 124: };
125:
1.127 manu 126: /*
127: * Emulation miscelaneous flags
128: */
1.122 lukem 129: #define EMUL_HAS_SYS___syscall 0x001 /* Has SYS___syscall */
1.114 mycroft 130:
1.40 christos 131: /*
1.29 cgd 132: * Description of a process.
133: *
134: * This structure contains the information needed to manage a thread of
135: * control, known in UN*X as a process; it has references to substructures
136: * containing descriptions of things that the process uses, but may share
137: * with related processes. The process structure and the substructures
138: * are always addressible except for those marked "(PROC ONLY)" below,
139: * which might be addressible only on a processor on which the process
140: * is running.
141: */
1.122 lukem 142: struct proc {
143: struct proc *p_forw; /* Doubly-linked run/sleep queue */
144: struct proc *p_back;
145: LIST_ENTRY(proc) p_list; /* List of all processes */
146:
147: /* Substructures: */
148: struct pcred *p_cred; /* Process owner's identity */
149: struct filedesc *p_fd; /* Ptr to open files structure */
150: struct cwdinfo *p_cwdi; /* cdir/rdir/cmask info */
151: struct pstats *p_stats; /* Accounting/statistics (PROC ONLY) */
152: struct plimit *p_limit; /* Process limits */
153: struct vmspace *p_vmspace; /* Address space */
154: struct sigacts *p_sigacts; /* Process sigactions (state is below)*/
1.29 cgd 155:
156: #define p_ucred p_cred->pc_ucred
157: #define p_rlimit p_limit->pl_rlimit
158:
1.122 lukem 159: int p_exitsig; /* Signal to sent to parent on exit */
160: int p_flag; /* P_* flags */
161: struct cpu_info * __volatile p_cpu;
162: /* CPU we're running on if SONPROC */
163: char p_stat; /* S* process status */
164: char p_pad1[3];
165:
166: pid_t p_pid; /* Process identifier */
167: LIST_ENTRY(proc) p_hash; /* Hash chain */
168: LIST_ENTRY(proc) p_pglist; /* List of processes in pgrp */
169: struct proc *p_pptr; /* Pointer to parent process */
170: LIST_ENTRY(proc) p_sibling; /* List of sibling processes */
171: LIST_HEAD(, proc) p_children; /* Pointer to list of children */
1.29 cgd 172:
1.122 lukem 173: /*
174: * The following fields are all zeroed upon creation in fork.
175: */
1.32 mycroft 176: #define p_startzero p_oppid
1.29 cgd 177:
1.122 lukem 178: pid_t p_oppid; /* Save parent pid during ptrace. XXX */
179: int p_dupfd; /* Sideways return value from filedescopen. XXX */
1.29 cgd 180:
1.122 lukem 181: /* Scheduling */
182: u_int p_estcpu; /* Time averaged value of p_cpticks. XXX belongs in p_startcopy section */
183: int p_cpticks; /* Ticks of cpu time */
184: fixpt_t p_pctcpu; /* %cpu for this proc during p_swtime */
185: void *p_wchan; /* Sleep address */
186: struct callout p_tsleep_ch; /* Callout for tsleep */
187: const char *p_wmesg; /* Reason for sleep */
188: u_int p_swtime; /* Time swapped in or out */
189: u_int p_slptime; /* Time since last blocked */
190:
191: struct callout p_realit_ch; /* Real time callout */
192: struct itimerval p_realtimer; /* Alarm timer */
193: struct timeval p_rtime; /* Real time */
194: u_quad_t p_uticks; /* Statclock hits in user mode */
195: u_quad_t p_sticks; /* Statclock hits in system mode */
196: u_quad_t p_iticks; /* Statclock hits processing intr */
1.29 cgd 197:
1.122 lukem 198: int p_traceflag; /* Kernel trace points */
199: struct file *p_tracep; /* Trace to file */
1.29 cgd 200:
1.122 lukem 201: struct vnode *p_textvp; /* Vnode of executable */
1.50 fvdl 202:
1.122 lukem 203: int p_locks; /* DEBUG: lockmgr count of held locks */
1.29 cgd 204:
1.122 lukem 205: int p_holdcnt; /* If non-zero, don't swap */
1.111 jdolecek 206: const struct emul *p_emul; /* Emulation information */
1.122 lukem 207: void *p_emuldata; /*
208: * Per-process emulation data, or NULL.
209: * Malloc type M_EMULDATA
210: */
1.135 thorpej 211: const struct execsw *p_execsw; /* Exec package information */
1.29 cgd 212:
1.122 lukem 213: /*
214: * End area that is zeroed on creation
215: */
1.29 cgd 216: #define p_endzero p_startcopy
217:
1.122 lukem 218: /*
219: * The following fields are all copied upon creation in fork.
220: */
1.118 jdolecek 221: #define p_startcopy p_sigctx.ps_startcopy
1.29 cgd 222:
1.122 lukem 223: struct sigctx p_sigctx; /* Signal state */
224:
225: u_char p_priority; /* Process priority */
226: u_char p_usrpri; /* User-priority based on p_cpu and p_nice */
227: u_char p_nice; /* Process "nice" value */
1.125 simonb 228: char p_comm[MAXCOMLEN+1]; /* basename of last exec file */
1.122 lukem 229:
230: struct pgrp *p_pgrp; /* Pointer to process group */
231: void *p_ctxlink; /* uc_link {get,set}context */
1.29 cgd 232:
1.122 lukem 233: struct ps_strings *p_psstr; /* Address of process's ps_strings */
234: size_t p_psargv; /* Offset of ps_argvstr in above */
235: size_t p_psnargv; /* Offset of ps_nargvstr in above */
236: size_t p_psenv; /* Offset of ps_envstr in above */
237: size_t p_psnenv; /* Offset of ps_nenvstr in above */
1.29 cgd 238:
1.122 lukem 239: /*
240: * End area that is copied on creation
241: */
1.29 cgd 242: #define p_endcopy p_thread
243:
1.122 lukem 244: void *p_thread; /* Id for this "thread"; Mach glue. XXX */
245: struct user *p_addr; /* Kernel virtual addr of u-area (PROC ONLY) */
246: struct mdproc p_md; /* Any machine-dependent fields */
247:
248: u_short p_xstat; /* Exit status for wait; also stop signal */
249: u_short p_acflag; /* Accounting flags */
250: struct rusage *p_ru; /* Exit information. XXX */
1.29 cgd 251: };
252:
253: #define p_session p_pgrp->pg_session
254: #define p_pgid p_pgrp->pg_id
255:
1.91 thorpej 256: /*
257: * Status values.
258: *
259: * A note about SRUN and SONPROC: SRUN indicates that a process is
260: * runnable but *not* yet running, i.e. is on a run queue. SONPROC
261: * indicates that the process is actually executing on a CPU, i.e.
262: * it is no longer on a run queue.
263: */
1.122 lukem 264: #define SIDL 1 /* Process being created by fork */
265: #define SRUN 2 /* Currently runnable */
266: #define SSLEEP 3 /* Sleeping on an address */
267: #define SSTOP 4 /* Process debugging or suspension */
268: #define SZOMB 5 /* Awaiting collection by parent */
269: #define SDEAD 6 /* Process is almost a zombie */
270: #define SONPROC 7 /* Process is currently on a CPU */
1.79 thorpej 271:
272: #define P_ZOMBIE(p) ((p)->p_stat == SZOMB || (p)->p_stat == SDEAD)
1.29 cgd 273:
1.41 mycroft 274: /* These flags are kept in p_flag. */
1.136 ! christos 275: #define P_ADVLOCK 0x000001 /* Process may hold a POSIX advisory lock */
! 276: #define P_CONTROLT 0x000002 /* Has a controlling terminal */
! 277: #define P_INMEM 0x000004 /* Loaded into memory */
! 278: #define P_NOCLDSTOP 0x000008 /* No SIGCHLD when children stop */
! 279: #define P_PPWAIT 0x000010 /* Parent is waiting for child to exec/exit */
! 280: #define P_PROFIL 0x000020 /* Has started profiling */
! 281: #define P_SELECT 0x000040 /* Selecting; wakeup/waiting danger */
! 282: #define P_SINTR 0x000080 /* Sleep is interruptible */
! 283: #define P_SUGID 0x000100 /* Had set id privileges since last exec */
! 284: #define P_SYSTEM 0x000200 /* System proc: no sigs, stats or swapping */
! 285: #define P_TIMEOUT 0x000400 /* Timing out during sleep */
! 286: #define P_TRACED 0x000800 /* Debugged process being traced */
! 287: #define P_WAITED 0x001000 /* Debugging process has waited for child */
! 288: #define P_WEXIT 0x002000 /* Working on exiting */
! 289: #define P_EXEC 0x004000 /* Process called exec */
! 290: #define P_OWEUPC 0x008000 /* Owe process an addupc() call at next ast */
! 291: #define P_FSTRACE 0x010000 /* Debugger process being traced by procfs */
! 292: #define P_NOCLDWAIT 0x020000 /* No zombies if child dies */
! 293: #define P_32 0x040000 /* 32-bit process (used on 64-bit kernels) */
! 294: #define P_BIGLOCK 0x080000 /* Process needs kernel "big lock" to run */
! 295: #define P_INEXEC 0x100000 /* Process is exec'ing and cannot be traced */
1.100 sommerfe 296:
1.29 cgd 297:
298: /*
1.78 thorpej 299: * Macro to compute the exit signal to be delivered.
1.76 thorpej 300: */
1.78 thorpej 301: #define P_EXITSIG(p) (((p)->p_flag & (P_TRACED|P_FSTRACE)) ? SIGCHLD : \
302: p->p_exitsig)
1.76 thorpej 303:
304: /*
1.29 cgd 305: * MOVE TO ucred.h?
306: *
307: * Shareable process credentials (always resident). This includes a reference
308: * to the current user credentials as well as real and saved ids that may be
309: * used to change ids.
310: */
1.122 lukem 311: struct pcred {
312: struct ucred *pc_ucred; /* Current credentials */
313: uid_t p_ruid; /* Real user id */
314: uid_t p_svuid; /* Saved effective user id */
315: gid_t p_rgid; /* Real group id */
316: gid_t p_svgid; /* Saved effective group id */
317: int p_refcnt; /* Number of references */
1.29 cgd 318: };
319:
1.122 lukem 320: LIST_HEAD(proclist, proc); /* A list of processes */
1.64 thorpej 321:
322: /*
323: * This structure associates a proclist with its lock.
324: */
325: struct proclist_desc {
1.122 lukem 326: struct proclist *pd_list; /* The list */
1.64 thorpej 327: /*
328: * XXX Add a pointer to the proclist's lock eventually.
329: */
330: };
331:
1.38 jtc 332: #ifdef _KERNEL
1.29 cgd 333: /*
334: * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
335: * as it is used to represent "no process group".
336: */
337: #define PID_MAX 30000
338: #define NO_PID 30001
339:
1.122 lukem 340: #define SESS_LEADER(p) ((p)->p_session->s_leader == (p))
1.29 cgd 341: #define SESSHOLD(s) ((s)->s_count++)
1.122 lukem 342: #define SESSRELE(s) \
343: do { \
1.29 cgd 344: if (--(s)->s_count == 0) \
345: FREE(s, M_SESSION); \
1.126 lukem 346: } while (/* CONSTCOND */ 0)
1.29 cgd 347:
1.122 lukem 348: #define PHOLD(p) \
349: do { \
1.56 mrg 350: if ((p)->p_holdcnt++ == 0 && ((p)->p_flag & P_INMEM) == 0) \
351: uvm_swapin(p); \
1.126 lukem 352: } while (/* CONSTCOND */ 0)
1.41 mycroft 353: #define PRELE(p) (--(p)->p_holdcnt)
1.54 thorpej 354:
355: /*
356: * Flags passed to fork1().
357: */
1.122 lukem 358: #define FORK_PPWAIT 0x01 /* Block parent until child exit */
359: #define FORK_SHAREVM 0x02 /* Share vmspace with parent */
360: #define FORK_SHARECWD 0x04 /* Share cdir/rdir/cmask */
361: #define FORK_SHAREFILES 0x08 /* Share file descriptors */
362: #define FORK_SHARESIGS 0x10 /* Share signal actions */
1.41 mycroft 363:
1.32 mycroft 364: #define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash])
365: extern LIST_HEAD(pidhashhead, proc) *pidhashtbl;
1.122 lukem 366: extern u_long pidhash;
1.32 mycroft 367:
368: #define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash])
369: extern LIST_HEAD(pgrphashhead, pgrp) *pgrphashtbl;
1.122 lukem 370: extern u_long pgrphash;
1.32 mycroft 371:
1.67 pk 372: /*
1.93 thorpej 373: * Allow machine-dependent code to override curproc in <machine/cpu.h> for
1.83 thorpej 374: * its own convenience. Otherwise, we declare it as appropriate.
1.67 pk 375: */
1.83 thorpej 376: #if !defined(curproc)
377: #if defined(MULTIPROCESSOR)
1.122 lukem 378: #define curproc curcpu()->ci_curproc /* Current running proc */
1.83 thorpej 379: #else
1.122 lukem 380: extern struct proc *curproc; /* Current running proc */
1.83 thorpej 381: #endif /* MULTIPROCESSOR */
382: #endif /* ! curproc */
383:
1.122 lukem 384: extern struct proc proc0; /* Process slot for swapper */
385: extern int nprocs, maxproc; /* Current and max number of procs */
1.29 cgd 386:
1.122 lukem 387: /* Process list lock; see kern_proc.c for locking protocol details */
388: extern struct lock proclist_lock;
1.110 sommerfe 389:
1.122 lukem 390: extern struct proclist allproc; /* List of all processes */
391: extern struct proclist zombproc; /* List of zombie processes */
1.79 thorpej 392:
1.122 lukem 393: extern struct proclist deadproc; /* List of dead processes */
1.79 thorpej 394: extern struct simplelock deadproc_slock;
1.64 thorpej 395:
1.122 lukem 396: extern struct proc *initproc; /* Process slots for init, pager */
1.61 thorpej 397:
1.64 thorpej 398: extern const struct proclist_desc proclists[];
399:
1.122 lukem 400: extern struct pool proc_pool; /* Memory pool for procs */
401: extern struct pool pcred_pool; /* Memory pool for pcreds */
402: extern struct pool plimit_pool; /* Memory pool for plimits */
403: extern struct pool rusage_pool; /* Memory pool for rusages */
1.29 cgd 404:
1.122 lukem 405: struct proc *pfind(pid_t); /* Find process by id */
406: struct pgrp *pgfind(pid_t); /* Find process group by id */
1.29 cgd 407:
1.98 thorpej 408: struct simplelock;
409:
1.122 lukem 410: int chgproccnt(uid_t uid, int diff);
411: int enterpgrp(struct proc *p, pid_t pgid, int mksess);
412: void fixjobc(struct proc *p, struct pgrp *pgrp, int entering);
413: int inferior(struct proc *p, struct proc *q);
414: int leavepgrp(struct proc *p);
415: void yield(void);
416: void preempt(struct proc *);
417: void mi_switch(struct proc *);
418: void pgdelete(struct pgrp *pgrp);
419: void procinit(void);
1.124 matt 420: #ifndef remrunqueue
1.122 lukem 421: void remrunqueue(struct proc *);
1.124 matt 422: #endif
1.122 lukem 423: void resetpriority(struct proc *);
424: void setrunnable(struct proc *);
1.124 matt 425: #ifndef setrunqueue
1.122 lukem 426: void setrunqueue(struct proc *);
1.124 matt 427: #endif
1.122 lukem 428: void suspendsched(void);
429: int ltsleep(void *chan, int pri, const char *wmesg, int timo,
430: __volatile struct simplelock *);
431: void unsleep(struct proc *);
432: void wakeup(void *chan);
433: void wakeup_one(void *chan);
434: void reaper(void *);
435: void exit1(struct proc *, int);
436: void exit2(struct proc *);
437: int fork1(struct proc *, int, int, void *, size_t,
438: void (*)(void *), void *, register_t *, struct proc **);
439: void rqinit(void);
440: int groupmember(gid_t, struct ucred *);
1.124 matt 441: #ifndef cpu_switch
1.122 lukem 442: void cpu_switch(struct proc *);
1.124 matt 443: #endif
1.122 lukem 444: void cpu_exit(struct proc *);
445: void cpu_fork(struct proc *, struct proc *, void *, size_t,
446: void (*)(void *), void *);
1.123 lukem 447:
448: /*
449: * XXX: use __P() to allow ports to have as a #define.
450: * XXX: we need a better way to solve this.
451: */
452: void cpu_wait __P((struct proc *));
1.122 lukem 453:
454: void child_return(void *);
455:
456: int proc_isunder(struct proc *, struct proc*);
457:
458: void proclist_lock_read(void);
459: void proclist_unlock_read(void);
460: int proclist_lock_write(void);
461: void proclist_unlock_write(int);
462: void p_sugid(struct proc*);
1.98 thorpej 463:
1.122 lukem 464: /* Compatibility with old, non-interlocked tsleep call */
1.98 thorpej 465: #define tsleep(chan, pri, wmesg, timo) \
466: ltsleep(chan, pri, wmesg, timo, NULL)
1.102 thorpej 467:
468: #if defined(MULTIPROCESSOR)
469: void proc_trampoline_mp(void); /* XXX */
470: #endif
1.98 thorpej 471:
1.38 jtc 472: #endif /* _KERNEL */
1.29 cgd 473: #endif /* !_SYS_PROC_H_ */
CVSweb <webmaster@jp.NetBSD.org>