[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.236.2.4

1.236.2.4! yamt        1: /*     $NetBSD: proc.h,v 1.236.2.3 2007/02/23 15:57:45 yamt Exp $      */
1.233     ad          2:
                      3: /*-
                      4:  * Copyright (c) 2006, 2007 The NetBSD Foundation, Inc.
                      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:  * 3. All advertising materials mentioning features or use of this software
                     19:  *    must display the following acknowledgement:
                     20:  *        This product includes software developed by the NetBSD
                     21:  *        Foundation, Inc. and its contributors.
                     22:  * 4. Neither the name of The NetBSD Foundation nor the names of its
                     23:  *    contributors may be used to endorse or promote products derived
                     24:  *    from this software without specific prior written permission.
                     25:  *
                     26:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     27:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     28:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     29:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     30:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     31:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     32:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     33:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     34:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     35:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     36:  * POSSIBILITY OF SUCH DAMAGE.
                     37:  */
1.29      cgd        38:
                     39: /*-
                     40:  * Copyright (c) 1986, 1989, 1991, 1993
                     41:  *     The Regents of the University of California.  All rights reserved.
                     42:  * (c) UNIX System Laboratories, Inc.
                     43:  * All or some portions of this file are derived from material licensed
                     44:  * to the University of California by American Telephone and Telegraph
                     45:  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
                     46:  * the permission of UNIX System Laboratories, Inc.
                     47:  *
                     48:  * Redistribution and use in source and binary forms, with or without
                     49:  * modification, are permitted provided that the following conditions
                     50:  * are met:
                     51:  * 1. Redistributions of source code must retain the above copyright
                     52:  *    notice, this list of conditions and the following disclaimer.
                     53:  * 2. Redistributions in binary form must reproduce the above copyright
                     54:  *    notice, this list of conditions and the following disclaimer in the
                     55:  *    documentation and/or other materials provided with the distribution.
1.168     agc        56:  * 3. Neither the name of the University nor the names of its contributors
1.29      cgd        57:  *    may be used to endorse or promote products derived from this software
                     58:  *    without specific prior written permission.
                     59:  *
                     60:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     61:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     62:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     63:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     64:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     65:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     66:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     67:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     68:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     69:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     70:  * SUCH DAMAGE.
                     71:  *
1.59      fvdl       72:  *     @(#)proc.h      8.15 (Berkeley) 5/19/95
1.29      cgd        73:  */
                     74:
                     75: #ifndef _SYS_PROC_H_
                     76: #define        _SYS_PROC_H_
1.57      mrg        77:
1.131     mrg        78: #if defined(_KERNEL_OPT)
1.83      thorpej    79: #include "opt_multiprocessor.h"
1.139     yamt       80: #include "opt_kstack.h"
1.224     yamt       81: #include "opt_lockdebug.h"
1.83      thorpej    82: #endif
                     83:
1.122     lukem      84: #include <machine/proc.h>              /* Machine-dependent proc substruct */
1.79      thorpej    85: #include <sys/lock.h>
1.233     ad         86: #include <sys/rwlock.h>
                     87: #include <sys/mutex.h>
                     88: #include <sys/condvar.h>
1.153     thorpej    89: #include <sys/lwp.h>
1.32      mycroft    90: #include <sys/queue.h>
1.87      thorpej    91: #include <sys/callout.h>
1.118     jdolecek   92: #include <sys/signalvar.h>
1.170     christos   93: #include <sys/siginfo.h>
1.147     jdolecek   94: #include <sys/event.h>
1.228     thorpej    95: #include <sys/specificdata.h>
1.29      cgd        96:
1.220     yamt       97: #ifndef _KERNEL
                     98: #include <sys/time.h>
                     99: #include <sys/resource.h>
                    100: #endif
                    101:
1.29      cgd       102: /*
                    103:  * One structure allocated per session.
                    104:  */
1.122     lukem     105: struct session {
                    106:        int             s_count;        /* Ref cnt; pgrps in session */
1.159     dsl       107:        u_int           s_flags;
                    108: #define        S_LOGIN_SET     1               /* s_login set in this session */
1.122     lukem     109:        struct proc     *s_leader;      /* Session leader */
                    110:        struct vnode    *s_ttyvp;       /* Vnode of controlling terminal */
                    111:        struct tty      *s_ttyp;        /* Controlling terminal */
                    112:        char            s_login[MAXLOGNAME]; /* Setlogin() name */
                    113:        pid_t           s_sid;          /* Session ID (pid of leader) */
1.29      cgd       114: };
                    115:
                    116: /*
                    117:  * One structure allocated per process group.
                    118:  */
1.122     lukem     119: struct pgrp {
                    120:        LIST_HEAD(, proc) pg_members;   /* Pointer to pgrp members */
                    121:        struct session  *pg_session;    /* Pointer to session */
                    122:        pid_t           pg_id;          /* Pgrp id */
                    123:        int             pg_jobc;        /*
                    124:                                         * Number of processes qualifying
                    125:                                         * pgrp for job control
                    126:                                         */
1.29      cgd       127: };
                    128:
                    129: /*
1.40      christos  130:  * One structure allocated per emulation.
                    131:  */
                    132: struct exec_package;
                    133: struct ps_strings;
1.144     gmcgarry  134: struct ras;
1.221     elad      135: struct kauth_cred;
1.40      christos  136:
1.122     lukem     137: struct emul {
                    138:        const char      *e_name;        /* Symbolic name */
                    139:        const char      *e_path;        /* Extra emulation path (NULL if none)*/
1.130     manu      140: #ifndef __HAVE_MINIMAL_EMUL
1.129     manu      141:        int             e_flags;        /* Miscellaneous flags, see above */
1.116     mycroft   142:                                        /* Syscall handling function */
1.122     lukem     143:        const int       *e_errno;       /* Errno array */
                    144:        int             e_nosys;        /* Offset of the nosys() syscall */
                    145:        int             e_nsysent;      /* Number of system call entries */
1.116     mycroft   146: #endif
1.111     jdolecek  147:        const struct sysent *e_sysent;  /* System call array */
1.122     lukem     148:        const char * const *e_syscallnames; /* System call name array */
1.120     jdolecek  149:                                        /* Signal sending function */
1.196     perry     150:        void            (*e_sendsig)(const struct ksiginfo *,
                    151:                                          const sigset_t *);
1.233     ad        152:        void            (*e_trapsignal)(struct lwp *, struct ksiginfo *);
1.196     perry     153:        int             (*e_tracesig)(struct proc *, int);
1.122     lukem     154:        char            *e_sigcode;     /* Start of sigcode */
                    155:        char            *e_esigcode;    /* End of sigcode */
1.134     jdolecek  156:                                        /* Set registers before execution */
1.169     chs       157:        struct uvm_object **e_sigobject;/* shared sigcode object */
1.196     perry     158:        void            (*e_setregs)(struct lwp *, struct exec_package *,
                    159:                                          u_long);
1.106     jdolecek  160:
1.112     jdolecek  161:                                        /* Per-process hooks */
1.196     perry     162:        void            (*e_proc_exec)(struct proc *, struct exec_package *);
                    163:        void            (*e_proc_fork)(struct proc *, struct proc *, int);
                    164:        void            (*e_proc_exit)(struct proc *);
                    165:        void            (*e_lwp_fork)(struct lwp *, struct lwp *);
                    166:        void            (*e_lwp_exit)(struct lwp *);
1.112     jdolecek  167:
1.116     mycroft   168: #ifdef __HAVE_SYSCALL_INTERN
1.196     perry     169:        void            (*e_syscall_intern)(struct proc *);
1.116     mycroft   170: #else
1.196     perry     171:        void            (*e_syscall)(void);
1.116     mycroft   172: #endif
1.180     atatat    173:                                        /* Emulation specific sysctl data */
                    174:        struct sysctlnode *e_sysctlovly;
1.217     drochner  175:        int             (*e_fault)(struct proc *, vaddr_t, int);
1.198     fvdl      176:
                    177:        vaddr_t         (*e_vm_default_addr)(struct proc *, vaddr_t, vsize_t);
1.200     fvdl      178:
                    179:        /* Emulation-specific hook for userspace page faults */
                    180:        int             (*e_usertrap)(struct lwp *, vaddr_t, void *);
1.218     cube      181:
1.233     ad        182:        size_t          e_ucsize;       /* size of ucontext_t */
1.236.2.4! yamt      183:        void            (*e_startlwp)(void *);
1.40      christos  184: };
                    185:
1.197     perry     186: /*
1.127     manu      187:  * Emulation miscelaneous flags
                    188:  */
1.122     lukem     189: #define        EMUL_HAS_SYS___syscall  0x001   /* Has SYS___syscall */
1.114     mycroft   190:
1.40      christos  191: /*
1.29      cgd       192:  * Description of a process.
                    193:  *
                    194:  * This structure contains the information needed to manage a thread of
                    195:  * control, known in UN*X as a process; it has references to substructures
                    196:  * containing descriptions of things that the process uses, but may share
                    197:  * with related processes.  The process structure and the substructures
                    198:  * are always addressible except for those marked "(PROC ONLY)" below,
                    199:  * which might be addressible only on a processor on which the process
                    200:  * is running.
1.175     dsl       201:  *
1.223     ad        202:  * Field markings and the corresponding locks (not yet fully implemented,
                    203:  * more a statement of intent):
                    204:  *
1.233     ad        205:  * k:  ktrace_mutex
                    206:  * m:  proclist_mutex
1.223     ad        207:  * l:  proclist_lock
1.233     ad        208:  * s:  p_smutex
                    209:  * t:  p_stmutex
                    210:  * p:  p_mutex
                    211:  * r:  p_rasmutex
                    212:  * (:  unlocked, stable
1.29      cgd       213:  */
1.122     lukem     214: struct proc {
1.233     ad        215:        LIST_ENTRY(proc) p_list;        /* l, m: List of all processes */
1.122     lukem     216:
1.233     ad        217:        kmutex_t        p_rasmutex;     /* :: RAS mutex */
                    218:        kmutex_t        p_mutex;        /* :: general mutex */
                    219:        kmutex_t        p_smutex;       /* :: mutex on scheduling state */
                    220:        kmutex_t        p_stmutex;      /* :: mutex on profiling state */
                    221:        kcondvar_t      p_refcv;        /* p: reference count CV */
                    222:        kcondvar_t      p_waitcv;       /* s: wait, stop CV on children */
                    223:        kcondvar_t      p_lwpcv;        /* s: wait, stop CV on LWPs */
                    224:        int             p_refcnt;       /* p: ref count for procfs etc */
                    225:
1.122     lukem     226:        /* Substructures: */
1.233     ad        227:        struct kauth_cred *p_cred;      /* p: Master copy of credentials */
                    228:        struct filedesc *p_fd;          /*    Ptr to open files structure */
                    229:        struct cwdinfo  *p_cwdi;        /*    cdir/rdir/cmask info */
                    230:        struct pstats   *p_stats;       /*    Accounting/stats (PROC ONLY) */
                    231:        struct plimit   *p_limit;       /*    Process limits */
                    232:        struct vmspace  *p_vmspace;     /*    Address space */
                    233:        struct sigacts  *p_sigacts;     /*    Process sigactions */
1.29      cgd       234:
1.228     thorpej   235:        specificdata_reference
                    236:                        p_specdataref;  /* subsystem proc-specific data */
                    237:
1.233     ad        238:        int             p_exitsig;      /* l: signal to send to parent on exit */
                    239:        int             p_flag;         /* p: P_* flags */
                    240:        int             p_sflag;        /* s: PS_* flags */
                    241:        int             p_slflag;       /* s, l: PSL_* flags */
                    242:        int             p_lflag;        /* l: PL_* flags */
                    243:        int             p_stflag;       /* t: PST_* flags */
                    244:        char            p_stat;         /* s: S* process status. */
1.122     lukem     245:        char            p_pad1[3];
                    246:
1.233     ad        247:        pid_t           p_pid;          /* (: Process identifier. */
1.176     dsl       248:        LIST_ENTRY(proc) p_pglist;      /* l: List of processes in pgrp. */
                    249:        struct proc     *p_pptr;        /* l: Pointer to parent process. */
                    250:        LIST_ENTRY(proc) p_sibling;     /* l: List of sibling processes. */
1.233     ad        251:        LIST_HEAD(, proc) p_children;   /* l: List of children. */
                    252:        LIST_HEAD(, lwp) p_lwps;        /* s: List of LWPs. */
                    253:        LIST_HEAD(, ras) p_raslist;     /* r: List of RAS entries */
1.29      cgd       254:
1.153     thorpej   255: /* The following fields are all zeroed upon creation in fork. */
                    256: #define        p_startzero     p_nlwps
                    257:
1.233     ad        258:        int             p_nlwps;        /* s: Number of LWPs */
                    259:        int             p_nzlwps;       /* s: Number of zombie LWPs */
                    260:        int             p_nrlwps;       /* s: Number running/sleeping LWPs */
                    261:        int             p_nlwpwait;     /* s: Number of LWPs in lwp_wait1() */
                    262:        int             p_ndlwps;       /* s: Number of detached LWPs */
                    263:        int             p_nlwpid;       /* s: Next LWP ID */
                    264:        u_int           p_nstopchild;   /* m: Count of stopped/dead children */
                    265:        u_int           p_waited;       /* m: parent has waited on child */
                    266:        struct lwp      *p_zomblwp;     /* s: detached LWP to be reaped */
1.29      cgd       267:
1.153     thorpej   268:        /* scheduling */
1.233     ad        269:        fixpt_t         p_estcpu;       /* t: Time averaged value of p_cpticks XXX belongs in p_startcopy section */
1.210     yamt      270:        fixpt_t         p_estcpu_inherited;
                    271:        unsigned int    p_forktime;
1.233     ad        272:        int             p_cpticks;      /* t: Ticks of CPU time */
                    273:        fixpt_t         p_pctcpu;       /* t: %cpu for this process during p_swtime */
1.197     perry     274:
1.233     ad        275:        struct proc     *p_opptr;       /* l: save parent during ptrace. */
                    276:        struct ptimers  *p_timers;      /*    Timers: real, virtual, profiling */
                    277:        struct timeval  p_rtime;        /* s: real time */
                    278:        u_quad_t        p_uticks;       /* t: Statclock hits in user mode */
                    279:        u_quad_t        p_sticks;       /* t: Statclock hits in system mode */
                    280:        u_quad_t        p_iticks;       /* t: Statclock hits processing intr */
                    281:
                    282:        int             p_traceflag;    /* k: Kernel trace points */
                    283:        void            *p_tracep;      /* k: Trace private data */
                    284:        void            *p_systrace;    /*    Back pointer to systrace */
                    285:
                    286:        struct vnode    *p_textvp;      /*    Vnode of executable */
                    287:
1.235     ad        288:        void         (*p_userret)(void);/* p: return-to-user hook */
1.233     ad        289:        const struct emul *p_emul;      /*    Emulation information */
                    290:        void            *p_emuldata;    /*    Per-process emulation data, or NULL.
                    291:                                         *    Malloc type M_EMULDATA */
                    292:        const struct execsw *p_execsw;  /*    Exec package information */
                    293:        struct klist    p_klist;        /*    Knotes attached to this process */
1.197     perry     294:
1.233     ad        295:        LIST_HEAD(, lwp) p_sigwaiters;  /* s: LWPs waiting for signals */
                    296:        sigpend_t       p_sigpend;      /* s: pending signals */
1.29      cgd       297:
1.122     lukem     298: /*
                    299:  * End area that is zeroed on creation
                    300:  */
1.29      cgd       301: #define        p_endzero       p_startcopy
                    302:
1.122     lukem     303: /*
                    304:  * The following fields are all copied upon creation in fork.
                    305:  */
1.233     ad        306: #define        p_startcopy     p_sigctx
1.122     lukem     307:
1.233     ad        308:        struct sigctx   p_sigctx;       /* s: Shared signal state */
1.29      cgd       309:
1.233     ad        310:        u_char          p_nice;         /* s: Process "nice" value */
                    311:        char            p_comm[MAXCOMLEN+1];
                    312:                                        /* p: basename of last exec file */
                    313:        struct pgrp     *p_pgrp;        /* l: Pointer to process group */
                    314:
                    315:        struct ps_strings *p_psstr;     /* (: address of process's ps_strings */
                    316:        size_t          p_psargv;       /* (: offset of ps_argvstr in above */
                    317:        size_t          p_psnargv;      /* (: offset of ps_nargvstr in above */
                    318:        size_t          p_psenv;        /* (: offset of ps_envstr in above */
                    319:        size_t          p_psnenv;       /* (: offset of ps_nenvstr in above */
1.29      cgd       320:
1.197     perry     321: /*
1.122     lukem     322:  * End area that is copied on creation
                    323:  */
1.153     thorpej   324: #define        p_endcopy       p_xstat
1.122     lukem     325:
1.233     ad        326:        u_short         p_xstat;        /* s: Exit status for wait; also stop signal */
1.223     ad        327:        u_short         p_acflag;       /* p: Acc. flags; see struct lwp also */
1.233     ad        328:        struct rusage   *p_ru;          /*    Exit information. XXX */
                    329:        struct mdproc   p_md;           /*    Any machine-dependent fields */
1.29      cgd       330: };
                    331:
1.233     ad        332: #define        p_rlimit        p_limit->pl_rlimit
1.29      cgd       333: #define        p_session       p_pgrp->pg_session
                    334: #define        p_pgid          p_pgrp->pg_id
                    335:
1.91      thorpej   336: /*
                    337:  * Status values.
                    338:  */
1.122     lukem     339: #define        SIDL            1               /* Process being created by fork */
1.153     thorpej   340: #define        SACTIVE         2               /* Process is not stopped */
1.233     ad        341: #define        SDYING          3               /* About to die */
1.122     lukem     342: #define        SSTOP           4               /* Process debugging or suspension */
                    343: #define        SZOMB           5               /* Awaiting collection by parent */
1.233     ad        344: #define        SDEAD           6               /* Almost a zombie */
1.79      thorpej   345:
1.233     ad        346: #define        P_ZOMBIE(p)     \
                    347:     ((p)->p_stat == SZOMB || (p)->p_stat == SDYING || (p)->p_stat == SDEAD)
1.29      cgd       348:
1.233     ad        349: /*
                    350:  * These flags are kept in p_flag and are protected by p_mutex.  Access from
                    351:  * process context only.
                    352:  */
1.236.2.4! yamt      353: #define        PK_ADVLOCK      0x00000001 /* Process may hold a POSIX advisory lock */
        !           354: #define        PK_SYSTEM       0x00000002 /* System process (kthread) */
        !           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_SYSTRACE     0x00200000 /* Process system call tracing active */
        !           361: #define        PK_PAXMPROTECT  0x08000000 /* Explicitly enable PaX MPROTECT */
        !           362: #define        PK_PAXNOMPROTECT        0x10000000 /* Explicitly disable PaX MPROTECT */
        !           363: #define        PK_MARKER       0x80000000 /* Is a dummy marker process */
1.29      cgd       364:
1.233     ad        365: /*
                    366:  * These flags are kept in p_sflag and are protected by p_smutex.  Access from
                    367:  * process context or interrupt context.
                    368:  */
                    369: #define        PS_NOCLDSTOP    0x00000008 /* No SIGCHLD when children stop */
                    370: #define        PS_PPWAIT       0x00000010 /* Parent is waiting for child exec/exit */
                    371: #define        PS_WCORE        0x00001000 /* Process needs to dump core */
                    372: #define        PS_WEXIT        0x00002000 /* Working on exiting */
                    373: #define        PS_STOPFORK     0x00800000 /* Child will be stopped on fork(2) */
                    374: #define        PS_STOPEXEC     0x01000000 /* Will be stopped on exec(2) */
                    375: #define        PS_STOPEXIT     0x02000000 /* Will be stopped at process exit */
                    376: #define        PS_NOTIFYSTOP   0x10000000 /* Notify parent of successful STOP */
                    377: #define        PS_ORPHANPG     0x20000000 /* Member of an orphaned pgrp */
                    378: #define        PS_STOPPING     0x80000000 /* Transitioning SACTIVE -> SSTOP */
                    379:
                    380: /*
                    381:  * These flags are kept in p_sflag and are protected by the proclist_lock
                    382:  * and p_smutex.  Access from process context or interrupt context.
                    383:  */
                    384: #define        PSL_TRACED      0x00000800 /* Debugged process being traced */
                    385: #define        PSL_FSTRACE     0x00010000 /* Debugger process being traced by procfs */
                    386: #define        PSL_CHTRACED    0x00400000 /* Child has been traced & reparented */
                    387: #define        PSL_SYSCALL     0x04000000 /* process has PT_SYSCALL enabled */
                    388:
                    389: /*
                    390:  * Kept in p_stflag and protected by p_stmutex.
                    391:  */
                    392: #define        PST_PROFIL      0x00000020 /* Has started profiling */
                    393:
                    394: /*
                    395:  * The final set are protected by the proclist_lock.  Access
                    396:  * from process context only.
                    397:  */
                    398: #define        PL_CONTROLT     0x00000002 /* Has a controlling terminal */
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.122     lukem     444: #define        FORK_PPWAIT     0x01            /* Block parent until child exit */
                    445: #define        FORK_SHAREVM    0x02            /* Share vmspace with parent */
                    446: #define        FORK_SHARECWD   0x04            /* Share cdir/rdir/cmask */
                    447: #define        FORK_SHAREFILES 0x08            /* Share file descriptors */
                    448: #define        FORK_SHARESIGS  0x10            /* Share signal actions */
1.141     pooka     449: #define        FORK_NOWAIT     0x20            /* Make init the parent of the child */
1.143     pooka     450: #define        FORK_CLEANFILES 0x40            /* Start with a clean descriptor set */
1.233     ad        451: #define        FORK_SYSTEM     0x80            /* Fork a kernel thread */
1.41      mycroft   452:
1.67      pk        453: /*
1.93      thorpej   454:  * Allow machine-dependent code to override curproc in <machine/cpu.h> for
1.83      thorpej   455:  * its own convenience.  Otherwise, we declare it as appropriate.
1.67      pk        456:  */
1.153     thorpej   457: #if !defined(curlwp)
1.83      thorpej   458: #if defined(MULTIPROCESSOR)
1.153     thorpej   459: #define        curlwp          curcpu()->ci_curlwp     /* Current running LWP */
1.83      thorpej   460: #else
1.153     thorpej   461: extern struct lwp      *curlwp;                /* Current running LWP */
1.83      thorpej   462: #endif /* MULTIPROCESSOR */
                    463: #endif /* ! curproc */
                    464:
1.236.2.1  yamt      465: #define        CURCPU_IDLE_P() (curlwp == curcpu()->ci_data.cpu_idlelwp)
                    466:
1.174     yamt      467: static struct proc *__curproc(void);
                    468:
1.212     perry     469: static __inline struct proc *
1.174     yamt      470: __curproc()
                    471: {
                    472:        struct lwp *l = curlwp;
                    473:
                    474:        if (l == NULL)
                    475:                return NULL;
                    476:        return l->l_proc;
                    477: }
                    478: #define        curproc __curproc()
1.153     thorpej   479:
1.122     lukem     480: extern struct proc     proc0;          /* Process slot for swapper */
                    481: extern int             nprocs, maxproc; /* Current and max number of procs */
1.213     yamt      482: #define        vmspace_kernel()        (proc0.p_vmspace)
1.29      cgd       483:
1.233     ad        484: /* Process list locks; see kern_proc.c for locking protocol details */
                    485: extern krwlock_t       proclist_lock;
                    486: extern kmutex_t                proclist_mutex;
1.110     sommerfe  487:
1.122     lukem     488: extern struct proclist allproc;        /* List of all processes */
                    489: extern struct proclist zombproc;       /* List of zombie processes */
1.79      thorpej   490:
1.162     dsl       491: extern SLIST_HEAD(deadprocs, proc) deadprocs;  /* List of dead processes */
1.79      thorpej   492: extern struct simplelock deadproc_slock;
1.64      thorpej   493:
1.122     lukem     494: extern struct proc     *initproc;      /* Process slots for init, pager */
1.61      thorpej   495:
1.64      thorpej   496: extern const struct proclist_desc proclists[];
                    497:
1.122     lukem     498: extern struct pool     pcred_pool;     /* Memory pool for pcreds */
                    499: extern struct pool     plimit_pool;    /* Memory pool for plimits */
1.153     thorpej   500: extern struct pool     pstats_pool;    /* memory pool for pstats */
1.122     lukem     501: extern struct pool     rusage_pool;    /* Memory pool for rusages */
1.153     thorpej   502: extern struct pool     ptimer_pool;    /* Memory pool for ptimers */
1.29      cgd       503:
1.176     dsl       504: struct proc *p_find(pid_t, uint);      /* Find process by id */
                    505: struct pgrp *pg_find(pid_t, uint);     /* Find process group by id */
                    506: /* Flags values for p_find() and pg_find(). */
                    507: #define PFIND_ZOMBIE           1       /* look for zombies as well */
                    508: #define PFIND_LOCKED           2       /* proclist locked on entry */
                    509: #define PFIND_UNLOCK_FAIL      4       /* unlock proclist on failure */
                    510: #define PFIND_UNLOCK_OK                8       /* unlock proclist on success */
                    511: #define PFIND_UNLOCK           (PFIND_UNLOCK_OK | PFIND_UNLOCK_FAIL)
                    512: /* For source compatibility. but UNLOCK_OK gives a stale answer... */
                    513: #define pfind(pid) p_find((pid), PFIND_UNLOCK)
                    514: #define pgfind(pgid) pg_find((pgid), PFIND_UNLOCK)
1.29      cgd       515:
1.98      thorpej   516: struct simplelock;
1.233     ad        517: int    enterpgrp(struct proc *, pid_t, pid_t, int);
                    518: void   leavepgrp(struct proc *);
1.167     itojun    519: void   fixjobc(struct proc *, struct pgrp *, int);
                    520: int    inferior(struct proc *, struct proc *);
1.162     dsl       521: void   sessdelete(struct session *);
1.152     gmcgarry  522: void   yield(void);
1.167     itojun    523: void   pgdelete(struct pgrp *);
1.122     lukem     524: void   procinit(void);
                    525: void   suspendsched(void);
1.236.2.4! yamt      526: int    ltsleep(wchan_t, pri_t, const char *, int,
1.211     perry     527:            volatile struct simplelock *);
1.233     ad        528: void   wakeup(wchan_t);
                    529: void   wakeup_one(wchan_t);
1.236.2.4! yamt      530: int    kpause(const char *, bool, int, kmutex_t *);
1.153     thorpej   531: void   exit1(struct lwp *, int);
1.233     ad        532: int    find_stopped_child(struct proc *, pid_t, int, struct proc **, int *);
1.162     dsl       533: struct proc *proc_alloc(void);
1.204     junyoung  534: void   proc0_init(void);
1.236     ad        535: void   proc_free(struct proc *, struct rusage *);
1.162     dsl       536: void   proc_free_mem(struct proc *);
1.153     thorpej   537: void   exit_lwps(struct lwp *l);
                    538: int    fork1(struct lwp *, int, int, void *, size_t,
1.122     lukem     539:            void (*)(void *), void *, register_t *, struct proc **);
1.161     dsl       540: int    pgid_in_session(struct proc *, pid_t);
1.153     thorpej   541: void   cpu_lwp_fork(struct lwp *, struct lwp *, void *, size_t,
1.122     lukem     542:            void (*)(void *), void *);
1.189     matt      543: #ifndef cpu_lwp_free
1.186     jdolecek  544: void   cpu_lwp_free(struct lwp *, int);
1.233     ad        545: void   cpu_lwp_free2(struct lwp *);
1.189     matt      546: #endif
1.122     lukem     547:
1.202     christos  548: #ifdef __HAVE_SYSCALL_INTERN
                    549: void   syscall_intern(struct proc *);
                    550: #endif
                    551:
1.122     lukem     552: void   child_return(void *);
                    553:
1.209     christos  554: int    proc_isunder(struct proc *, struct lwp *);
1.233     ad        555: void   proc_stop(struct proc *, int, int);
1.122     lukem     556:
1.162     dsl       557: void   p_sugid(struct proc *);
1.98      thorpej   558:
1.213     yamt      559: int    proc_vmspace_getref(struct proc *, struct vmspace **);
1.236.2.4! yamt      560: void   proc_crmod_leave(kauth_cred_t, kauth_cred_t, bool);
1.233     ad        561: void   proc_crmod_enter(void);
                    562: int    proc_addref(struct proc *);
                    563: void   proc_delref(struct proc *);
                    564: void   proc_drainrefs(struct proc *);
1.213     yamt      565:
1.228     thorpej   566: int    proc_specific_key_create(specificdata_key_t *, specificdata_dtor_t);
                    567: void   proc_specific_key_delete(specificdata_key_t);
1.229     christos  568: void   proc_initspecific(struct proc *);
1.230     thorpej   569: void   proc_finispecific(struct proc *);
1.228     thorpej   570: void * proc_getspecific(struct proc *, specificdata_key_t);
                    571: void   proc_setspecific(struct proc *, specificdata_key_t, void *);
                    572:
1.195     yamt      573: int    proclist_foreach_call(struct proclist *,
                    574:     int (*)(struct proc *, void *arg), void *);
1.212     perry     575: static __inline struct proc *_proclist_skipmarker(struct proc *);
1.195     yamt      576:
1.212     perry     577: static __inline struct proc *
1.195     yamt      578: _proclist_skipmarker(struct proc *p0)
                    579: {
                    580:        struct proc *p = p0;
                    581:
1.236.2.4! yamt      582:        while (p != NULL && p->p_flag & PK_MARKER)
1.195     yamt      583:                p = LIST_NEXT(p, p_list);
                    584:
                    585:        return p;
                    586: }
                    587: #define        PROCLIST_FOREACH(var, head)                                     \
                    588:        for ((var) = LIST_FIRST(head);                                  \
                    589:                ((var) = _proclist_skipmarker(var)) != NULL;            \
                    590:                (var) = LIST_NEXT(var, p_list))
                    591:
1.224     yamt      592: #if defined(LOCKDEBUG)
                    593: void assert_sleepable(struct simplelock *, const char *);
                    594: #define        ASSERT_SLEEPABLE(lk, msg)       assert_sleepable((lk), (msg))
                    595: #else /* defined(LOCKDEBUG) */
                    596: #define        ASSERT_SLEEPABLE(lk, msg)       /* nothing */
                    597: #endif /* defined(LOCKDEBUG) */
                    598:
1.122     lukem     599: /* Compatibility with old, non-interlocked tsleep call */
1.98      thorpej   600: #define        tsleep(chan, pri, wmesg, timo)                                  \
                    601:        ltsleep(chan, pri, wmesg, timo, NULL)
1.102     thorpej   602:
1.139     yamt      603: #ifdef KSTACK_CHECK_MAGIC
1.154     yamt      604: void kstack_setup_magic(const struct lwp *);
                    605: void kstack_check_magic(const struct lwp *);
1.139     yamt      606: #endif
                    607:
                    608: /*
                    609:  * kernel stack paramaters
                    610:  * XXX require sizeof(struct user)
                    611:  */
                    612: /* the lowest address of kernel stack */
                    613: #ifndef KSTACK_LOWEST_ADDR
1.154     yamt      614: #define        KSTACK_LOWEST_ADDR(l)   ((caddr_t)ALIGN((l)->l_addr + 1))
1.139     yamt      615: #endif
                    616: /* size of kernel stack */
                    617: #ifndef KSTACK_SIZE
                    618: #define        KSTACK_SIZE     (USPACE - ALIGN(sizeof(struct user)))
1.102     thorpej   619: #endif
1.98      thorpej   620:
1.38      jtc       621: #endif /* _KERNEL */
1.29      cgd       622: #endif /* !_SYS_PROC_H_ */

CVSweb <webmaster@jp.NetBSD.org>