[BACK]Return to proc.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / sys

Annotation of src/sys/sys/proc.h, Revision 1.282.4.1

1.282.4.1! bouyer      1: /*     $NetBSD: proc.h,v 1.282 2008/10/22 11:14:33 ad Exp $    */
1.233     ad          2:
                      3: /*-
1.270     ad          4:  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
1.233     ad          5:  * All rights reserved.
                      6:  *
                      7:  * This code is derived from software contributed to The NetBSD Foundation
                      8:  * by Andrew Doran.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
                     18:  *
                     19:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     20:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     21:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     22:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     23:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     24:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     25:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     26:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     27:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     28:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     29:  * POSSIBILITY OF SUCH DAMAGE.
                     30:  */
1.29      cgd        31:
                     32: /*-
                     33:  * Copyright (c) 1986, 1989, 1991, 1993
                     34:  *     The Regents of the University of California.  All rights reserved.
                     35:  * (c) UNIX System Laboratories, Inc.
                     36:  * All or some portions of this file are derived from material licensed
                     37:  * to the University of California by American Telephone and Telegraph
                     38:  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
                     39:  * the permission of UNIX System Laboratories, Inc.
                     40:  *
                     41:  * Redistribution and use in source and binary forms, with or without
                     42:  * modification, are permitted provided that the following conditions
                     43:  * are met:
                     44:  * 1. Redistributions of source code must retain the above copyright
                     45:  *    notice, this list of conditions and the following disclaimer.
                     46:  * 2. Redistributions in binary form must reproduce the above copyright
                     47:  *    notice, this list of conditions and the following disclaimer in the
                     48:  *    documentation and/or other materials provided with the distribution.
1.168     agc        49:  * 3. Neither the name of the University nor the names of its contributors
1.29      cgd        50:  *    may be used to endorse or promote products derived from this software
                     51:  *    without specific prior written permission.
                     52:  *
                     53:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     54:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     55:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     56:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     57:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     58:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     59:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     60:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     61:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     62:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     63:  * SUCH DAMAGE.
                     64:  *
1.59      fvdl       65:  *     @(#)proc.h      8.15 (Berkeley) 5/19/95
1.29      cgd        66:  */
                     67:
                     68: #ifndef _SYS_PROC_H_
                     69: #define        _SYS_PROC_H_
1.57      mrg        70:
1.131     mrg        71: #if defined(_KERNEL_OPT)
1.83      thorpej    72: #include "opt_multiprocessor.h"
1.139     yamt       73: #include "opt_kstack.h"
1.224     yamt       74: #include "opt_lockdebug.h"
1.83      thorpej    75: #endif
                     76:
1.122     lukem      77: #include <machine/proc.h>              /* Machine-dependent proc substruct */
1.245     rmind      78: #include <sys/aio.h>
1.233     ad         79: #include <sys/rwlock.h>
1.254     rmind      80: #include <sys/mqueue.h>
1.233     ad         81: #include <sys/mutex.h>
                     82: #include <sys/condvar.h>
1.153     thorpej    83: #include <sys/lwp.h>
1.32      mycroft    84: #include <sys/queue.h>
1.118     jdolecek   85: #include <sys/signalvar.h>
1.170     christos   86: #include <sys/siginfo.h>
1.147     jdolecek   87: #include <sys/event.h>
1.228     thorpej    88: #include <sys/specificdata.h>
1.29      cgd        89:
1.220     yamt       90: #ifndef _KERNEL
                     91: #include <sys/time.h>
                     92: #include <sys/resource.h>
                     93: #endif
                     94:
1.29      cgd        95: /*
                     96:  * One structure allocated per session.
                     97:  */
1.122     lukem      98: struct session {
                     99:        int             s_count;        /* Ref cnt; pgrps in session */
1.159     dsl       100:        u_int           s_flags;
                    101: #define        S_LOGIN_SET     1               /* s_login set in this session */
1.122     lukem     102:        struct proc     *s_leader;      /* Session leader */
                    103:        struct vnode    *s_ttyvp;       /* Vnode of controlling terminal */
                    104:        struct tty      *s_ttyp;        /* Controlling terminal */
                    105:        char            s_login[MAXLOGNAME]; /* Setlogin() name */
                    106:        pid_t           s_sid;          /* Session ID (pid of leader) */
1.29      cgd       107: };
                    108:
                    109: /*
                    110:  * One structure allocated per process group.
                    111:  */
1.122     lukem     112: struct pgrp {
                    113:        LIST_HEAD(, proc) pg_members;   /* Pointer to pgrp members */
                    114:        struct session  *pg_session;    /* Pointer to session */
                    115:        pid_t           pg_id;          /* Pgrp id */
                    116:        int             pg_jobc;        /*
                    117:                                         * Number of processes qualifying
                    118:                                         * pgrp for job control
                    119:                                         */
1.29      cgd       120: };
                    121:
                    122: /*
1.40      christos  123:  * One structure allocated per emulation.
                    124:  */
                    125: struct exec_package;
                    126: struct ps_strings;
1.144     gmcgarry  127: struct ras;
1.221     elad      128: struct kauth_cred;
1.40      christos  129:
1.122     lukem     130: struct emul {
                    131:        const char      *e_name;        /* Symbolic name */
                    132:        const char      *e_path;        /* Extra emulation path (NULL if none)*/
1.130     manu      133: #ifndef __HAVE_MINIMAL_EMUL
1.129     manu      134:        int             e_flags;        /* Miscellaneous flags, see above */
1.116     mycroft   135:                                        /* Syscall handling function */
1.122     lukem     136:        const int       *e_errno;       /* Errno array */
                    137:        int             e_nosys;        /* Offset of the nosys() syscall */
                    138:        int             e_nsysent;      /* Number of system call entries */
1.116     mycroft   139: #endif
1.282     ad        140:        struct sysent   *e_sysent;      /* System call array */
1.122     lukem     141:        const char * const *e_syscallnames; /* System call name array */
1.120     jdolecek  142:                                        /* Signal sending function */
1.196     perry     143:        void            (*e_sendsig)(const struct ksiginfo *,
                    144:                                          const sigset_t *);
1.233     ad        145:        void            (*e_trapsignal)(struct lwp *, struct ksiginfo *);
1.196     perry     146:        int             (*e_tracesig)(struct proc *, int);
1.122     lukem     147:        char            *e_sigcode;     /* Start of sigcode */
                    148:        char            *e_esigcode;    /* End of sigcode */
1.134     jdolecek  149:                                        /* Set registers before execution */
1.169     chs       150:        struct uvm_object **e_sigobject;/* shared sigcode object */
1.196     perry     151:        void            (*e_setregs)(struct lwp *, struct exec_package *,
                    152:                                          u_long);
1.106     jdolecek  153:
1.112     jdolecek  154:                                        /* Per-process hooks */
1.196     perry     155:        void            (*e_proc_exec)(struct proc *, struct exec_package *);
                    156:        void            (*e_proc_fork)(struct proc *, struct proc *, int);
                    157:        void            (*e_proc_exit)(struct proc *);
                    158:        void            (*e_lwp_fork)(struct lwp *, struct lwp *);
                    159:        void            (*e_lwp_exit)(struct lwp *);
1.112     jdolecek  160:
1.116     mycroft   161: #ifdef __HAVE_SYSCALL_INTERN
1.196     perry     162:        void            (*e_syscall_intern)(struct proc *);
1.116     mycroft   163: #else
1.196     perry     164:        void            (*e_syscall)(void);
1.116     mycroft   165: #endif
1.180     atatat    166:                                        /* Emulation specific sysctl data */
                    167:        struct sysctlnode *e_sysctlovly;
1.217     drochner  168:        int             (*e_fault)(struct proc *, vaddr_t, int);
1.198     fvdl      169:
                    170:        vaddr_t         (*e_vm_default_addr)(struct proc *, vaddr_t, vsize_t);
1.200     fvdl      171:
                    172:        /* Emulation-specific hook for userspace page faults */
                    173:        int             (*e_usertrap)(struct lwp *, vaddr_t, void *);
1.218     cube      174:
1.281     wrstuden  175:        /* SA-related information */
                    176:        const struct sa_emul *e_sa;
                    177:
1.233     ad        178:        size_t          e_ucsize;       /* size of ucontext_t */
1.239     cube      179:        void            (*e_startlwp)(void *);
1.40      christos  180: };
                    181:
1.197     perry     182: /*
1.127     manu      183:  * Emulation miscelaneous flags
                    184:  */
1.122     lukem     185: #define        EMUL_HAS_SYS___syscall  0x001   /* Has SYS___syscall */
1.114     mycroft   186:
1.40      christos  187: /*
1.29      cgd       188:  * Description of a process.
                    189:  *
                    190:  * This structure contains the information needed to manage a thread of
                    191:  * control, known in UN*X as a process; it has references to substructures
                    192:  * containing descriptions of things that the process uses, but may share
                    193:  * with related processes.  The process structure and the substructures
                    194:  * are always addressible except for those marked "(PROC ONLY)" below,
                    195:  * which might be addressible only on a processor on which the process
                    196:  * is running.
1.175     dsl       197:  *
1.223     ad        198:  * Field markings and the corresponding locks (not yet fully implemented,
                    199:  * more a statement of intent):
                    200:  *
1.268     ad        201:  * a:  p_auxlock
1.233     ad        202:  * k:  ktrace_mutex
1.272     ad        203:  * l:  proc_lock
1.233     ad        204:  * t:  p_stmutex
1.273     ad        205:  * p:  p_lock
1.270     ad        206:  * q:  mqlist_mtx
                    207:  * ::  unlocked, stable
1.29      cgd       208:  */
1.122     lukem     209: struct proc {
1.272     ad        210:        LIST_ENTRY(proc) p_list;        /* l: List of all processes */
1.122     lukem     211:
1.268     ad        212:        kmutex_t        p_auxlock;      /* :: secondary, longer term lock */
1.273     ad        213:        kmutex_t        *p_lock;        /* :: general mutex */
1.233     ad        214:        kmutex_t        p_stmutex;      /* :: mutex on profiling state */
1.260     ad        215:        krwlock_t       p_reflock;      /* p: lock for debugger, procfs */
1.273     ad        216:        kcondvar_t      p_waitcv;       /* p: wait, stop CV on children */
                    217:        kcondvar_t      p_lwpcv;        /* p: wait, stop CV on LWPs */
1.233     ad        218:
1.122     lukem     219:        /* Substructures: */
1.233     ad        220:        struct kauth_cred *p_cred;      /* p: Master copy of credentials */
1.270     ad        221:        struct filedesc *p_fd;          /* :: Ptr to open files structure */
                    222:        struct cwdinfo  *p_cwdi;        /* :: cdir/rdir/cmask info */
                    223:        struct pstats   *p_stats;       /* :: Accounting/stats (PROC ONLY) */
                    224:        struct plimit   *p_limit;       /* :: Process limits */
                    225:        struct vmspace  *p_vmspace;     /* :: Address space */
                    226:        struct sigacts  *p_sigacts;     /* :: Process sigactions */
1.245     rmind     227:        struct aioproc  *p_aio;         /* p: Asynchronous I/O data */
1.270     ad        228:        u_int           p_mqueue_cnt;   /* q: Count of open mqueues */
1.228     thorpej   229:        specificdata_reference
1.270     ad        230:                        p_specdataref;  /*    subsystem proc-specific data */
1.228     thorpej   231:
1.233     ad        232:        int             p_exitsig;      /* l: signal to send to parent on exit */
                    233:        int             p_flag;         /* p: P_* flags */
1.273     ad        234:        int             p_sflag;        /* p: PS_* flags */
1.233     ad        235:        int             p_slflag;       /* s, l: PSL_* flags */
                    236:        int             p_lflag;        /* l: PL_* flags */
                    237:        int             p_stflag;       /* t: PST_* flags */
1.273     ad        238:        char            p_stat;         /* p: S* process status. */
                    239:        char            p_trace_enabled;/* p: cached by syscall_intern() */
1.270     ad        240:        char            p_pad1[2];      /*  unused */
1.122     lukem     241:
1.270     ad        242:        pid_t           p_pid;          /* :: Process identifier. */
1.176     dsl       243:        LIST_ENTRY(proc) p_pglist;      /* l: List of processes in pgrp. */
                    244:        struct proc     *p_pptr;        /* l: Pointer to parent process. */
                    245:        LIST_ENTRY(proc) p_sibling;     /* l: List of sibling processes. */
1.233     ad        246:        LIST_HEAD(, proc) p_children;   /* l: List of children. */
1.273     ad        247:        LIST_HEAD(, lwp) p_lwps;        /* p: List of LWPs. */
1.268     ad        248:        struct ras      *p_raslist;     /* a: List of RAS entries */
1.29      cgd       249:
1.153     thorpej   250: /* The following fields are all zeroed upon creation in fork. */
                    251: #define        p_startzero     p_nlwps
                    252:
1.273     ad        253:        int             p_nlwps;        /* p: Number of LWPs */
                    254:        int             p_nzlwps;       /* p: Number of zombie LWPs */
                    255:        int             p_nrlwps;       /* p: Number running/sleeping LWPs */
                    256:        int             p_nlwpwait;     /* p: Number of LWPs in lwp_wait1() */
                    257:        int             p_ndlwps;       /* p: Number of detached LWPs */
                    258:        int             p_nlwpid;       /* p: Next LWP ID */
1.272     ad        259:        u_int           p_nstopchild;   /* l: Count of stopped/dead children */
                    260:        u_int           p_waited;       /* l: parent has waited on child */
1.273     ad        261:        struct lwp      *p_zomblwp;     /* p: detached LWP to be reaped */
1.29      cgd       262:
1.281     wrstuden  263:        struct sadata   *p_sa;          /* p: Scheduler activation info */
                    264:
1.153     thorpej   265:        /* scheduling */
1.273     ad        266:        void            *p_sched_info;  /* p: Scheduler-specific structure */
                    267:        fixpt_t         p_estcpu;       /* p: Time avg. value of p_cpticks */
                    268:        fixpt_t         p_estcpu_inherited; /* p: cpu inherited from children */
1.210     yamt      269:        unsigned int    p_forktime;
1.273     ad        270:        fixpt_t         p_pctcpu;       /* p: %cpu from dead LWPs */
1.197     perry     271:
1.233     ad        272:        struct proc     *p_opptr;       /* l: save parent during ptrace. */
                    273:        struct ptimers  *p_timers;      /*    Timers: real, virtual, profiling */
1.273     ad        274:        struct bintime  p_rtime;        /* p: real time */
1.233     ad        275:        u_quad_t        p_uticks;       /* t: Statclock hits in user mode */
                    276:        u_quad_t        p_sticks;       /* t: Statclock hits in system mode */
                    277:        u_quad_t        p_iticks;       /* t: Statclock hits processing intr */
                    278:
                    279:        int             p_traceflag;    /* k: Kernel trace points */
1.281     wrstuden  280:        int             p_timerpend;    /* p: Pending itimer to run */
1.233     ad        281:        void            *p_tracep;      /* k: Trace private data */
1.270     ad        282:        struct vnode    *p_textvp;      /* :: Vnode of executable */
1.233     ad        283:
1.235     ad        284:        void         (*p_userret)(void);/* p: return-to-user hook */
1.270     ad        285:        const struct emul *p_emul;      /* :: emulation information */
                    286:        void            *p_emuldata;    /* :: per-proc emul data, or NULL */
                    287:        const struct execsw *p_execsw;  /* :: exec package information */
                    288:        struct klist    p_klist;        /* p: knotes attached to proc */
1.197     perry     289:
1.273     ad        290:        LIST_HEAD(, lwp) p_sigwaiters;  /* p: LWPs waiting for signals */
1.281     wrstuden  291:        sigstore_t      p_sigstore;     /* p: process-wide signal state */
1.273     ad        292:        sigpend_t       p_sigpend;      /* p: pending signals */
1.270     ad        293:        struct lcproc   *p_lwpctl;      /* p, a: _lwp_ctl() information */
1.277     ad        294:        pid_t           p_ppid;         /* :: cached parent pid */
1.29      cgd       295:
1.122     lukem     296: /*
                    297:  * End area that is zeroed on creation
                    298:  */
1.29      cgd       299: #define        p_endzero       p_startcopy
                    300:
1.122     lukem     301: /*
                    302:  * The following fields are all copied upon creation in fork.
                    303:  */
1.233     ad        304: #define        p_startcopy     p_sigctx
1.122     lukem     305:
1.273     ad        306:        struct sigctx   p_sigctx;       /* p: Shared signal state */
1.29      cgd       307:
1.273     ad        308:        u_char          p_nice;         /* p: Process "nice" value */
1.233     ad        309:        char            p_comm[MAXCOMLEN+1];
                    310:                                        /* p: basename of last exec file */
                    311:        struct pgrp     *p_pgrp;        /* l: Pointer to process group */
                    312:
1.270     ad        313:        struct ps_strings *p_psstr;     /* :: address of process's ps_strings */
                    314:        size_t          p_psargv;       /* :: offset of ps_argvstr in above */
                    315:        size_t          p_psnargv;      /* :: offset of ps_nargvstr in above */
                    316:        size_t          p_psenv;        /* :: offset of ps_envstr in above */
                    317:        size_t          p_psnenv;       /* :: offset of ps_nenvstr in above */
1.279     ad        318:        u_int           p_pax;          /* :: PAX flags */
1.29      cgd       319:
1.197     perry     320: /*
1.122     lukem     321:  * End area that is copied on creation
                    322:  */
1.153     thorpej   323: #define        p_endcopy       p_xstat
1.122     lukem     324:
1.273     ad        325:        u_short         p_xstat;        /* p: Exit status for wait; also stop signal */
1.223     ad        326:        u_short         p_acflag;       /* p: Acc. flags; see struct lwp also */
1.270     ad        327:        struct mdproc   p_md;           /* p: Any machine-dependent fields */
                    328:        vaddr_t         p_stackbase;    /* :: ASLR randomized stack base */
1.29      cgd       329: };
                    330:
1.233     ad        331: #define        p_rlimit        p_limit->pl_rlimit
1.29      cgd       332: #define        p_session       p_pgrp->pg_session
                    333: #define        p_pgid          p_pgrp->pg_id
                    334:
1.91      thorpej   335: /*
                    336:  * Status values.
                    337:  */
1.122     lukem     338: #define        SIDL            1               /* Process being created by fork */
1.153     thorpej   339: #define        SACTIVE         2               /* Process is not stopped */
1.233     ad        340: #define        SDYING          3               /* About to die */
1.122     lukem     341: #define        SSTOP           4               /* Process debugging or suspension */
                    342: #define        SZOMB           5               /* Awaiting collection by parent */
1.233     ad        343: #define        SDEAD           6               /* Almost a zombie */
1.79      thorpej   344:
1.233     ad        345: #define        P_ZOMBIE(p)     \
                    346:     ((p)->p_stat == SZOMB || (p)->p_stat == SDYING || (p)->p_stat == SDEAD)
1.29      cgd       347:
1.233     ad        348: /*
1.273     ad        349:  * These flags are kept in p_flag and are protected by p_lock.  Access from
1.233     ad        350:  * process context only.
                    351:  */
1.237     pavel     352: #define        PK_ADVLOCK      0x00000001 /* Process may hold a POSIX advisory lock */
                    353: #define        PK_SYSTEM       0x00000002 /* System process (kthread) */
1.274     ad        354: #define        PK_SYSVSEM      0x00000004 /* Used SysV semaphores */
1.237     pavel     355: #define        PK_SUGID        0x00000100 /* Had set id privileges since last exec */
                    356: #define        PK_EXEC         0x00004000 /* Process called exec */
                    357: #define        PK_NOCLDWAIT    0x00020000 /* No zombies if child dies */
                    358: #define        PK_32           0x00040000 /* 32-bit process (used on 64-bit kernels) */
                    359: #define        PK_CLDSIGIGN    0x00080000 /* Process is ignoring SIGCHLD */
                    360: #define        PK_MARKER       0x80000000 /* Is a dummy marker process */
1.29      cgd       361:
1.233     ad        362: /*
1.273     ad        363:  * These flags are kept in p_sflag and are protected by p_lock.  Access from
                    364:  * process context only.
1.233     ad        365:  */
                    366: #define        PS_NOCLDSTOP    0x00000008 /* No SIGCHLD when children stop */
1.281     wrstuden  367: #define        PS_SA           0x00000400 /* Process using scheduler activations */
1.233     ad        368: #define        PS_WCORE        0x00001000 /* Process needs to dump core */
                    369: #define        PS_WEXIT        0x00002000 /* Working on exiting */
                    370: #define        PS_STOPFORK     0x00800000 /* Child will be stopped on fork(2) */
                    371: #define        PS_STOPEXEC     0x01000000 /* Will be stopped on exec(2) */
                    372: #define        PS_STOPEXIT     0x02000000 /* Will be stopped at process exit */
                    373: #define        PS_NOTIFYSTOP   0x10000000 /* Notify parent of successful STOP */
1.281     wrstuden  374: #define        PS_NOSA         0x40000000 /* Do not enable SA */
1.233     ad        375: #define        PS_STOPPING     0x80000000 /* Transitioning SACTIVE -> SSTOP */
                    376:
                    377: /*
1.272     ad        378:  * These flags are kept in p_sflag and are protected by the proc_lock
1.273     ad        379:  * and p_lock.  Access from process context only.
1.233     ad        380:  */
                    381: #define        PSL_TRACED      0x00000800 /* Debugged process being traced */
                    382: #define        PSL_FSTRACE     0x00010000 /* Debugger process being traced by procfs */
                    383: #define        PSL_CHTRACED    0x00400000 /* Child has been traced & reparented */
                    384: #define        PSL_SYSCALL     0x04000000 /* process has PT_SYSCALL enabled */
1.282.4.1! bouyer    385: #define        PSL_SYSCALLEMU  0x08000000 /* cancel in-progress syscall */
1.233     ad        386:
                    387: /*
                    388:  * Kept in p_stflag and protected by p_stmutex.
                    389:  */
                    390: #define        PST_PROFIL      0x00000020 /* Has started profiling */
                    391:
                    392: /*
1.272     ad        393:  * The final set are protected by the proc_lock.  Access
1.233     ad        394:  * from process context only.
                    395:  */
                    396: #define        PL_CONTROLT     0x00000002 /* Has a controlling terminal */
1.280     ad        397: #define        PL_PPWAIT       0x00000010 /* Parent is waiting for child exec/exit */
1.272     ad        398: #define        PL_ORPHANPG     0x20000000 /* Member of an orphaned pgrp */
1.219     christos  399:
1.29      cgd       400: /*
1.78      thorpej   401:  * Macro to compute the exit signal to be delivered.
1.76      thorpej   402:  */
1.233     ad        403: #define        P_EXITSIG(p)    \
                    404:     (((p)->p_slflag & (PSL_TRACED|PSL_FSTRACE)) ? SIGCHLD : p->p_exitsig)
1.76      thorpej   405:
1.122     lukem     406: LIST_HEAD(proclist, proc);             /* A list of processes */
1.64      thorpej   407:
                    408: /*
                    409:  * This structure associates a proclist with its lock.
                    410:  */
                    411: struct proclist_desc {
1.122     lukem     412:        struct proclist *pd_list;       /* The list */
1.64      thorpej   413:        /*
                    414:         * XXX Add a pointer to the proclist's lock eventually.
                    415:         */
                    416: };
                    417:
1.38      jtc       418: #ifdef _KERNEL
1.156     thorpej   419: #include <sys/mallocvar.h>
                    420: MALLOC_DECLARE(M_EMULDATA);
                    421: MALLOC_DECLARE(M_PROC);
                    422: MALLOC_DECLARE(M_SESSION);
1.208     simonb    423: MALLOC_DECLARE(M_SUBPROC);     /* XXX - only used by sparc/sparc64 */
1.156     thorpej   424:
1.29      cgd       425: /*
1.162     dsl       426:  * We use process IDs <= PID_MAX until there are > 16k processes.
                    427:  * NO_PGID is used to represent "no process group" for a tty.
1.29      cgd       428:  */
                    429: #define        PID_MAX         30000
1.163     jdolecek  430: #define        NO_PGID         ((pid_t)-1)
1.29      cgd       431:
1.122     lukem     432: #define        SESS_LEADER(p)  ((p)->p_session->s_leader == (p))
1.29      cgd       433: #define        SESSHOLD(s)     ((s)->s_count++)
1.122     lukem     434: #define        SESSRELE(s)                                                     \
                    435: do {                                                                   \
1.29      cgd       436:        if (--(s)->s_count == 0)                                        \
1.162     dsl       437:                sessdelete(s);                                          \
1.126     lukem     438: } while (/* CONSTCOND */ 0)
1.29      cgd       439:
1.54      thorpej   440:
                    441: /*
                    442:  * Flags passed to fork1().
                    443:  */
1.255     dsl       444: #define        FORK_PPWAIT     0x0001          /* Block parent until child exit */
                    445: #define        FORK_SHAREVM    0x0002          /* Share vmspace with parent */
                    446: #define        FORK_SHARECWD   0x0004          /* Share cdir/rdir/cmask */
                    447: #define        FORK_SHAREFILES 0x0008          /* Share file descriptors */
                    448: #define        FORK_SHARESIGS  0x0010          /* Share signal actions */
                    449: #define        FORK_NOWAIT     0x0020          /* Make init the parent of the child */
                    450: #define        FORK_CLEANFILES 0x0040          /* Start with a clean descriptor set */
                    451: #define        FORK_SYSTEM     0x0080          /* Fork a kernel thread */
                    452: #define        FORK_SHARELIMIT 0x0100          /* Share rlimit values */
1.41      mycroft   453:
1.122     lukem     454: extern struct proc     proc0;          /* Process slot for swapper */
1.262     ad        455: extern u_int           nprocs;         /* Current number of procs */
                    456: extern int             maxproc;        /* Max number of procs */
1.213     yamt      457: #define        vmspace_kernel()        (proc0.p_vmspace)
1.29      cgd       458:
1.272     ad        459: extern kmutex_t                *proc_lock;
1.122     lukem     460: extern struct proclist allproc;        /* List of all processes */
                    461: extern struct proclist zombproc;       /* List of zombie processes */
1.79      thorpej   462:
1.162     dsl       463: extern SLIST_HEAD(deadprocs, proc) deadprocs;  /* List of dead processes */
1.79      thorpej   464: extern struct simplelock deadproc_slock;
1.64      thorpej   465:
1.122     lukem     466: extern struct proc     *initproc;      /* Process slots for init, pager */
1.61      thorpej   467:
1.64      thorpej   468: extern const struct proclist_desc proclists[];
                    469:
1.153     thorpej   470: extern struct pool     ptimer_pool;    /* Memory pool for ptimers */
1.29      cgd       471:
1.176     dsl       472: struct proc *p_find(pid_t, uint);      /* Find process by id */
                    473: struct pgrp *pg_find(pid_t, uint);     /* Find process group by id */
                    474: /* Flags values for p_find() and pg_find(). */
                    475: #define PFIND_ZOMBIE           1       /* look for zombies as well */
                    476: #define PFIND_LOCKED           2       /* proclist locked on entry */
                    477: #define PFIND_UNLOCK_FAIL      4       /* unlock proclist on failure */
                    478: #define PFIND_UNLOCK_OK                8       /* unlock proclist on success */
                    479: #define PFIND_UNLOCK           (PFIND_UNLOCK_OK | PFIND_UNLOCK_FAIL)
                    480: /* For source compatibility. but UNLOCK_OK gives a stale answer... */
                    481: #define pfind(pid) p_find((pid), PFIND_UNLOCK)
                    482: #define pgfind(pgid) pg_find((pgid), PFIND_UNLOCK)
1.29      cgd       483:
1.98      thorpej   484: struct simplelock;
1.233     ad        485: int    enterpgrp(struct proc *, pid_t, pid_t, int);
                    486: void   leavepgrp(struct proc *);
1.167     itojun    487: void   fixjobc(struct proc *, struct pgrp *, int);
                    488: int    inferior(struct proc *, struct proc *);
1.162     dsl       489: void   sessdelete(struct session *);
1.152     gmcgarry  490: void   yield(void);
1.167     itojun    491: void   pgdelete(struct pgrp *);
1.122     lukem     492: void   procinit(void);
                    493: void   suspendsched(void);
1.244     ad        494: int    ltsleep(wchan_t, pri_t, const char *, int, volatile struct simplelock *);
                    495: int    mtsleep(wchan_t, pri_t, const char *, int, kmutex_t *);
1.233     ad        496: void   wakeup(wchan_t);
                    497: void   wakeup_one(wchan_t);
1.240     thorpej   498: int    kpause(const char *, bool, int, kmutex_t *);
1.264     perry     499: void   exit1(struct lwp *, int) __dead;
1.247     dsl       500: int    do_sys_wait(struct lwp *, int *, int *, int, struct rusage *, int *);
1.162     dsl       501: struct proc *proc_alloc(void);
1.204     junyoung  502: void   proc0_init(void);
1.256     ad        503: void   proc_free_pid(struct proc *);
1.265     ad        504: void   proc_free_mem(struct proc *);
1.153     thorpej   505: void   exit_lwps(struct lwp *l);
                    506: int    fork1(struct lwp *, int, int, void *, size_t,
1.122     lukem     507:            void (*)(void *), void *, register_t *, struct proc **);
1.161     dsl       508: int    pgid_in_session(struct proc *, pid_t);
1.153     thorpej   509: void   cpu_lwp_fork(struct lwp *, struct lwp *, void *, size_t,
1.122     lukem     510:            void (*)(void *), void *);
1.189     matt      511: #ifndef cpu_lwp_free
1.186     jdolecek  512: void   cpu_lwp_free(struct lwp *, int);
1.250     yamt      513: #ifndef cpu_lwp_free2
1.233     ad        514: void   cpu_lwp_free2(struct lwp *);
1.189     matt      515: #endif
1.250     yamt      516: #endif
1.122     lukem     517:
1.202     christos  518: #ifdef __HAVE_SYSCALL_INTERN
                    519: void   syscall_intern(struct proc *);
                    520: #endif
                    521:
1.122     lukem     522: void   child_return(void *);
                    523:
1.209     christos  524: int    proc_isunder(struct proc *, struct lwp *);
1.233     ad        525: void   proc_stop(struct proc *, int, int);
1.122     lukem     526:
1.162     dsl       527: void   p_sugid(struct proc *);
1.98      thorpej   528:
1.213     yamt      529: int    proc_vmspace_getref(struct proc *, struct vmspace **);
1.240     thorpej   530: void   proc_crmod_leave(kauth_cred_t, kauth_cred_t, bool);
1.233     ad        531: void   proc_crmod_enter(void);
                    532: int    proc_addref(struct proc *);
                    533: void   proc_delref(struct proc *);
                    534: void   proc_drainrefs(struct proc *);
1.213     yamt      535:
1.228     thorpej   536: int    proc_specific_key_create(specificdata_key_t *, specificdata_dtor_t);
                    537: void   proc_specific_key_delete(specificdata_key_t);
1.229     christos  538: void   proc_initspecific(struct proc *);
1.230     thorpej   539: void   proc_finispecific(struct proc *);
1.228     thorpej   540: void * proc_getspecific(struct proc *, specificdata_key_t);
                    541: void   proc_setspecific(struct proc *, specificdata_key_t, void *);
                    542:
1.195     yamt      543: int    proclist_foreach_call(struct proclist *,
                    544:     int (*)(struct proc *, void *arg), void *);
1.212     perry     545: static __inline struct proc *_proclist_skipmarker(struct proc *);
1.195     yamt      546:
1.212     perry     547: static __inline struct proc *
1.195     yamt      548: _proclist_skipmarker(struct proc *p0)
                    549: {
                    550:        struct proc *p = p0;
                    551:
1.237     pavel     552:        while (p != NULL && p->p_flag & PK_MARKER)
1.195     yamt      553:                p = LIST_NEXT(p, p_list);
                    554:
                    555:        return p;
                    556: }
                    557: #define        PROCLIST_FOREACH(var, head)                                     \
                    558:        for ((var) = LIST_FIRST(head);                                  \
                    559:                ((var) = _proclist_skipmarker(var)) != NULL;            \
                    560:                (var) = LIST_NEXT(var, p_list))
                    561:
1.122     lukem     562: /* Compatibility with old, non-interlocked tsleep call */
1.98      thorpej   563: #define        tsleep(chan, pri, wmesg, timo)                                  \
                    564:        ltsleep(chan, pri, wmesg, timo, NULL)
1.102     thorpej   565:
1.139     yamt      566: #ifdef KSTACK_CHECK_MAGIC
1.154     yamt      567: void kstack_setup_magic(const struct lwp *);
                    568: void kstack_check_magic(const struct lwp *);
1.139     yamt      569: #endif
                    570:
                    571: /*
                    572:  * kernel stack paramaters
                    573:  * XXX require sizeof(struct user)
                    574:  */
                    575: /* the lowest address of kernel stack */
                    576: #ifndef KSTACK_LOWEST_ADDR
1.242     christos  577: #define        KSTACK_LOWEST_ADDR(l)   ((void *)ALIGN((l)->l_addr + 1))
1.139     yamt      578: #endif
                    579: /* size of kernel stack */
                    580: #ifndef KSTACK_SIZE
                    581: #define        KSTACK_SIZE     (USPACE - ALIGN(sizeof(struct user)))
1.102     thorpej   582: #endif
1.98      thorpej   583:
1.38      jtc       584: #endif /* _KERNEL */
1.29      cgd       585: #endif /* !_SYS_PROC_H_ */

CVSweb <webmaster@jp.NetBSD.org>