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

1.80    ! thorpej     1: /*     $NetBSD: proc.h,v 1.79 1999/07/22 18:13:36 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.29      cgd        46: #include <machine/proc.h>              /* Machine-dependent proc substruct. */
1.79      thorpej    47: #include <sys/lock.h>
1.32      mycroft    48: #include <sys/queue.h>
1.29      cgd        49:
                     50: /*
                     51:  * One structure allocated per session.
                     52:  */
                     53: struct session {
                     54:        int     s_count;                /* Ref cnt; pgrps in session. */
                     55:        struct  proc *s_leader;         /* Session leader. */
                     56:        struct  vnode *s_ttyvp;         /* Vnode of controlling terminal. */
                     57:        struct  tty *s_ttyp;            /* Controlling terminal. */
                     58:        char    s_login[MAXLOGNAME];    /* Setlogin() name. */
1.58      thorpej    59:        pid_t   s_sid;                  /* session ID (pid of leader) */
1.29      cgd        60: };
                     61:
                     62: /*
                     63:  * One structure allocated per process group.
                     64:  */
                     65: struct pgrp {
1.32      mycroft    66:        LIST_ENTRY(pgrp) pg_hash;       /* Hash chain. */
                     67:        LIST_HEAD(, proc) pg_members;   /* Pointer to pgrp members. */
1.29      cgd        68:        struct  session *pg_session;    /* Pointer to session. */
                     69:        pid_t   pg_id;                  /* Pgrp id. */
                     70:        int     pg_jobc;        /* # procs qualifying pgrp for job control */
                     71: };
                     72:
                     73: /*
1.40      christos   74:  * One structure allocated per emulation.
                     75:  */
                     76: struct exec_package;
                     77: struct ps_strings;
                     78:
                     79: struct emul {
                     80:        char    e_name[8];              /* Symbolic name */
                     81:        int     *e_errno;               /* Errno array */
                     82:                                        /* Signal sending function */
1.65      mycroft    83:        void    (*e_sendsig) __P((sig_t, int, sigset_t *, u_long));
1.40      christos   84:        int     e_nosys;                /* Offset of the nosys() syscall */
                     85:        int     e_nsysent;              /* Number of system call entries */
                     86:        struct sysent *e_sysent;        /* System call array */
                     87:        char    **e_syscallnames;       /* System call name array */
                     88:        int     e_arglen;               /* Extra argument size in words */
                     89:                                        /* Copy arguments on the stack */
                     90:        void    *(*e_copyargs) __P((struct exec_package *, struct ps_strings *,
                     91:                                    void *, void *));
                     92:                                        /* Set registers before execution */
                     93:        void    (*e_setregs) __P((struct proc *, struct exec_package *,
1.51      mycroft    94:                                  u_long));
1.40      christos   95:        char    *e_sigcode;             /* Start of sigcode */
                     96:        char    *e_esigcode;            /* End of sigcode */
                     97: };
                     98:
                     99: /*
1.29      cgd       100:  * Description of a process.
                    101:  *
                    102:  * This structure contains the information needed to manage a thread of
                    103:  * control, known in UN*X as a process; it has references to substructures
                    104:  * containing descriptions of things that the process uses, but may share
                    105:  * with related processes.  The process structure and the substructures
                    106:  * are always addressible except for those marked "(PROC ONLY)" below,
                    107:  * which might be addressible only on a processor on which the process
                    108:  * is running.
                    109:  */
                    110: struct proc {
                    111:        struct  proc *p_forw;           /* Doubly-linked run/sleep queue. */
                    112:        struct  proc *p_back;
1.32      mycroft   113:        LIST_ENTRY(proc) p_list;        /* List of all processes. */
1.29      cgd       114:
                    115:        /* substructures: */
                    116:        struct  pcred *p_cred;          /* Process owner's identity. */
                    117:        struct  filedesc *p_fd;         /* Ptr to open files structure. */
1.75      thorpej   118:        struct  cwdinfo *p_cwdi;        /* cdir/rdir/cmask info */
1.29      cgd       119:        struct  pstats *p_stats;        /* Accounting/statistics (PROC ONLY). */
                    120:        struct  plimit *p_limit;        /* Process limits. */
                    121:        struct  vmspace *p_vmspace;     /* Address space. */
                    122:        struct  sigacts *p_sigacts;     /* Signal actions, state (PROC ONLY). */
                    123:
                    124: #define        p_ucred         p_cred->pc_ucred
                    125: #define        p_rlimit        p_limit->pl_rlimit
                    126:
1.76      thorpej   127:        int     p_exitsig;              /* signal to sent to parent on exit */
1.29      cgd       128:        int     p_flag;                 /* P_* flags. */
1.40      christos  129:        u_char  p_unused;               /* XXX: used to be emulation flag */
1.29      cgd       130:        char    p_stat;                 /* S* process status. */
1.32      mycroft   131:        char    p_pad1[2];
1.29      cgd       132:
                    133:        pid_t   p_pid;                  /* Process identifier. */
1.32      mycroft   134:        LIST_ENTRY(proc) p_hash;        /* Hash chain. */
                    135:        LIST_ENTRY(proc) p_pglist;      /* List of processes in pgrp. */
                    136:        struct  proc *p_pptr;           /* Pointer to parent process. */
                    137:        LIST_ENTRY(proc) p_sibling;     /* List of sibling processes. */
                    138:        LIST_HEAD(, proc) p_children;   /* Pointer to list of children. */
1.29      cgd       139:
                    140: /* The following fields are all zeroed upon creation in fork. */
1.32      mycroft   141: #define        p_startzero     p_oppid
1.29      cgd       142:
                    143:        pid_t   p_oppid;         /* Save parent pid during ptrace. XXX */
1.43      christos  144:        int     p_dupfd;         /* Sideways return value from filedescopen. XXX */
1.29      cgd       145:
                    146:        /* scheduling */
1.71      sommerfe  147:        u_int   p_estcpu;        /* Time averaged value of p_cpticks. XXX belongs in p_startcopy section */
1.29      cgd       148:        int     p_cpticks;       /* Ticks of cpu time. */
                    149:        fixpt_t p_pctcpu;        /* %cpu for this process during p_swtime */
                    150:        void    *p_wchan;        /* Sleep address. */
1.52      mycroft   151:        const char *p_wmesg;     /* Reason for sleep. */
1.29      cgd       152:        u_int   p_swtime;        /* Time swapped in or out. */
                    153:        u_int   p_slptime;       /* Time since last blocked. */
                    154:
                    155:        struct  itimerval p_realtimer;  /* Alarm timer. */
                    156:        struct  timeval p_rtime;        /* Real time. */
                    157:        u_quad_t p_uticks;              /* Statclock hits in user mode. */
                    158:        u_quad_t p_sticks;              /* Statclock hits in system mode. */
                    159:        u_quad_t p_iticks;              /* Statclock hits processing intr. */
                    160:
                    161:        int     p_traceflag;            /* Kernel trace points. */
1.60      christos  162:        void    *p_tracep;              /* Trace to vnode or file */
1.29      cgd       163:
1.65      mycroft   164:        sigset_t p_siglist;             /* Signals arrived but not delivered. */
                    165:        char    p_sigcheck;             /* May have deliverable signals. */
1.29      cgd       166:
                    167:        struct  vnode *p_textvp;        /* Vnode of executable. */
1.50      fvdl      168:
                    169:        short   p_locks;                /* DEBUG: lockmgr count of held locks */
                    170:        short   p_simple_locks;         /* DEBUG: count of held simple locks */
1.29      cgd       171:
                    172:        int     p_holdcnt;              /* If non-zero, don't swap. */
1.40      christos  173:        struct  emul *p_emul;           /* Emulation information */
1.29      cgd       174:
                    175: /* End area that is zeroed on creation. */
                    176: #define        p_endzero       p_startcopy
                    177:
                    178: /* The following fields are all copied upon creation in fork. */
                    179: #define        p_startcopy     p_sigmask
                    180:
                    181:        sigset_t p_sigmask;     /* Current signal mask. */
                    182:        sigset_t p_sigignore;   /* Signals being ignored. */
                    183:        sigset_t p_sigcatch;    /* Signals being caught by user. */
                    184:
                    185:        u_char  p_priority;     /* Process priority. */
                    186:        u_char  p_usrpri;       /* User-priority based on p_cpu and p_nice. */
1.46      ws        187:        u_char  p_nice;         /* Process "nice" value. */
1.29      cgd       188:        char    p_comm[MAXCOMLEN+1];
                    189:
                    190:        struct  pgrp *p_pgrp;   /* Pointer to process group. */
1.72      kleink    191:        void    *p_ctxlink;     /* uc_link {get,set}context */
1.29      cgd       192:
                    193: /* End area that is copied on creation. */
                    194: #define        p_endcopy       p_thread
                    195:
1.36      cgd       196:        void    *p_thread;      /* Id for this "thread"; Mach glue. XXX */
1.29      cgd       197:        struct  user *p_addr;   /* Kernel virtual addr of u-area (PROC ONLY). */
                    198:        struct  mdproc p_md;    /* Any machine-dependent fields. */
                    199:
                    200:        u_short p_xstat;        /* Exit status for wait; also stop signal. */
                    201:        u_short p_acflag;       /* Accounting flags. */
                    202:        struct  rusage *p_ru;   /* Exit information. XXX */
                    203: };
                    204:
                    205: #define        p_session       p_pgrp->pg_session
                    206: #define        p_pgid          p_pgrp->pg_id
                    207:
                    208: /* Status values. */
                    209: #define        SIDL    1               /* Process being created by fork. */
                    210: #define        SRUN    2               /* Currently runnable. */
                    211: #define        SSLEEP  3               /* Sleeping on an address. */
                    212: #define        SSTOP   4               /* Process debugging or suspension. */
                    213: #define        SZOMB   5               /* Awaiting collection by parent. */
1.79      thorpej   214: #define        SDEAD   6               /* Process is almost a zombie. */
                    215:
                    216: #define        P_ZOMBIE(p)     ((p)->p_stat == SZOMB || (p)->p_stat == SDEAD)
1.29      cgd       217:
1.41      mycroft   218: /* These flags are kept in p_flag. */
1.29      cgd       219: #define        P_ADVLOCK       0x00001 /* Process may hold a POSIX advisory lock. */
                    220: #define        P_CONTROLT      0x00002 /* Has a controlling terminal. */
                    221: #define        P_INMEM         0x00004 /* Loaded into memory. */
                    222: #define        P_NOCLDSTOP     0x00008 /* No SIGCHLD when children stop. */
                    223: #define        P_PPWAIT        0x00010 /* Parent is waiting for child to exec/exit. */
                    224: #define        P_PROFIL        0x00020 /* Has started profiling. */
                    225: #define        P_SELECT        0x00040 /* Selecting; wakeup/waiting danger. */
                    226: #define        P_SINTR         0x00080 /* Sleep is interruptible. */
                    227: #define        P_SUGID         0x00100 /* Had set id privileges since last exec. */
                    228: #define        P_SYSTEM        0x00200 /* System proc: no sigs, stats or swapping. */
                    229: #define        P_TIMEOUT       0x00400 /* Timing out during sleep. */
                    230: #define        P_TRACED        0x00800 /* Debugged process being traced. */
                    231: #define        P_WAITED        0x01000 /* Debugging process has waited for child. */
                    232: #define        P_WEXIT         0x02000 /* Working on exiting. */
                    233: #define        P_EXEC          0x04000 /* Process called exec. */
                    234: #define        P_OWEUPC        0x08000 /* Owe process an addupc() call at next ast. */
1.66      christos  235: #define        P_FSTRACE       0x10000 /* Debugger process being traced by procfs */
                    236: #define        P_NOCLDWAIT     0x20000 /* No zombies if child dies */
1.29      cgd       237:
                    238: /*
1.78      thorpej   239:  * Macro to compute the exit signal to be delivered.
1.76      thorpej   240:  */
1.78      thorpej   241: #define        P_EXITSIG(p)    (((p)->p_flag & (P_TRACED|P_FSTRACE)) ? SIGCHLD : \
                    242:                         p->p_exitsig)
1.76      thorpej   243:
                    244: /*
1.29      cgd       245:  * MOVE TO ucred.h?
                    246:  *
                    247:  * Shareable process credentials (always resident).  This includes a reference
                    248:  * to the current user credentials as well as real and saved ids that may be
                    249:  * used to change ids.
                    250:  */
                    251: struct pcred {
                    252:        struct  ucred *pc_ucred;        /* Current credentials. */
                    253:        uid_t   p_ruid;                 /* Real user id. */
                    254:        uid_t   p_svuid;                /* Saved effective user id. */
                    255:        gid_t   p_rgid;                 /* Real group id. */
                    256:        gid_t   p_svgid;                /* Saved effective group id. */
                    257:        int     p_refcnt;               /* Number of references. */
                    258: };
                    259:
1.64      thorpej   260: LIST_HEAD(proclist, proc);             /* a list of processes */
                    261:
                    262: /*
                    263:  * This structure associates a proclist with its lock.
                    264:  */
                    265: struct proclist_desc {
                    266:        struct proclist *pd_list;       /* the list */
                    267:        /*
                    268:         * XXX Add a pointer to the proclist's lock eventually.
                    269:         */
                    270: };
                    271:
1.38      jtc       272: #ifdef _KERNEL
1.29      cgd       273: /*
                    274:  * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
                    275:  * as it is used to represent "no process group".
                    276:  */
                    277: #define        PID_MAX         30000
                    278: #define        NO_PID          30001
                    279:
                    280: #define SESS_LEADER(p) ((p)->p_session->s_leader == (p))
                    281: #define        SESSHOLD(s)     ((s)->s_count++)
                    282: #define        SESSRELE(s) {                                                   \
                    283:        if (--(s)->s_count == 0)                                        \
                    284:                FREE(s, M_SESSION);                                     \
                    285: }
                    286:
1.56      mrg       287: #define        PHOLD(p) {                                                      \
                    288:        if ((p)->p_holdcnt++ == 0 && ((p)->p_flag & P_INMEM) == 0)      \
                    289:                uvm_swapin(p);                                          \
                    290: }
1.41      mycroft   291: #define        PRELE(p)        (--(p)->p_holdcnt)
1.54      thorpej   292:
                    293: /*
                    294:  * Flags passed to fork1().
                    295:  */
                    296: #define        FORK_PPWAIT     0x01            /* block parent until child exit */
                    297: #define        FORK_SHAREVM    0x02            /* share vmspace with parent */
1.75      thorpej   298: #define        FORK_SHARECWD   0x04            /* share cdir/rdir/cmask */
                    299: #define        FORK_SHAREFILES 0x08            /* share file descriptors */
                    300: #define        FORK_SHARESIGS  0x10            /* share signal actions */
1.41      mycroft   301:
1.32      mycroft   302: #define        PIDHASH(pid)    (&pidhashtbl[(pid) & pidhash])
                    303: extern LIST_HEAD(pidhashhead, proc) *pidhashtbl;
                    304: extern u_long pidhash;
                    305:
                    306: #define        PGRPHASH(pgid)  (&pgrphashtbl[(pgid) & pgrphash])
                    307: extern LIST_HEAD(pgrphashhead, pgrp) *pgrphashtbl;
                    308: extern u_long pgrphash;
                    309:
1.67      pk        310: /*
                    311:  * Note: <machine/proc.h> may provide a definition of `curproc' while
                    312:  * transition to multi processor support is in progress.
                    313:  */
                    314: #ifndef curproc
1.29      cgd       315: extern struct proc *curproc;           /* Current running proc. */
1.67      pk        316: #endif
1.29      cgd       317: extern struct proc proc0;              /* Process slot for swapper. */
                    318: extern int nprocs, maxproc;            /* Current and max number of procs. */
                    319:
1.80    ! thorpej   320: /* Process list lock; see kern_proc.c for locking protocol details. */
        !           321: extern struct lock proclist_lock;
        !           322:
1.32      mycroft   323: extern struct proclist allproc;                /* List of all processes. */
1.79      thorpej   324: extern struct proclist zombproc;       /* List of zombie processes. */
                    325:
1.64      thorpej   326: extern struct proclist deadproc;       /* List of dead processes. */
1.79      thorpej   327: extern struct simplelock deadproc_slock;
1.64      thorpej   328:
1.53      mycroft   329: struct proc *initproc;                 /* Process slots for init, pager. */
1.61      thorpej   330:
1.64      thorpej   331: extern const struct proclist_desc proclists[];
                    332:
1.61      thorpej   333: extern struct pool proc_pool;          /* memory pool for procs */
1.62      thorpej   334: extern struct pool pcred_pool;         /* memory pool for pcreds */
                    335: extern struct pool plimit_pool;                /* memory pool for plimits */
1.63      thorpej   336: extern struct pool rusage_pool;                /* memory pool for rusages */
1.29      cgd       337:
                    338: #define        NQS     32                      /* 32 run queues. */
                    339: int    whichqs;                        /* Bit mask summary of non-empty Q's. */
                    340: struct prochd {
                    341:        struct  proc *ph_link;          /* Linked list of running processes. */
                    342:        struct  proc *ph_rlink;
                    343: } qs[NQS];
                    344:
                    345: struct proc *pfind __P((pid_t));       /* Find process by id. */
                    346: struct pgrp *pgfind __P((pid_t));      /* Find process group by id. */
                    347:
1.35      cgd       348: int    chgproccnt __P((uid_t uid, int diff));
                    349: int    enterpgrp __P((struct proc *p, pid_t pgid, int mksess));
1.29      cgd       350: void   fixjobc __P((struct proc *p, struct pgrp *pgrp, int entering));
1.35      cgd       351: int    inferior __P((struct proc *p));
                    352: int    leavepgrp __P((struct proc *p));
1.29      cgd       353: void   mi_switch __P((void));
1.36      cgd       354: void   pgdelete __P((struct pgrp *pgrp));
1.35      cgd       355: void   procinit __P((void));
1.47      cgd       356: void   remrunqueue __P((struct proc *));
1.29      cgd       357: void   resetpriority __P((struct proc *));
                    358: void   setrunnable __P((struct proc *));
                    359: void   setrunqueue __P((struct proc *));
                    360: void   sleep __P((void *chan, int pri));
1.56      mrg       361: void   uvm_swapin __P((struct proc *));  /* XXX: uvm_extern.h? */
1.52      mycroft   362: int    tsleep __P((void *chan, int pri, const char *wmesg, int timo));
1.29      cgd       363: void   unsleep __P((struct proc *));
                    364: void   wakeup __P((void *chan));
1.64      thorpej   365: void   reaper __P((void));
1.42      christos  366: void   exit1 __P((struct proc *, int));
1.64      thorpej   367: void   exit2 __P((struct proc *));
1.77      thorpej   368: int    fork1 __P((struct proc *, int, int, void *, size_t, register_t *,
                    369:            struct proc **));
1.42      christos  370: void   kmeminit __P((void));
                    371: void   rqinit __P((void));
                    372: int    groupmember __P((gid_t, struct ucred *));
1.44      christos  373: void   cpu_switch __P((struct proc *));
                    374: void   cpu_wait __P((struct proc *));
                    375: void   cpu_exit __P((struct proc *));
1.74      sommerfe  376: int    proc_isunder __P((struct proc *, struct proc*));
1.80    ! thorpej   377:
        !           378: void   proclist_lock_read __P((int));
        !           379: void   proclist_unlock_read __P((void));
        !           380: int    proclist_lock_write __P((void));
        !           381: void   proclist_unlock_write __P((int));
1.38      jtc       382: #endif /* _KERNEL */
1.29      cgd       383: #endif /* !_SYS_PROC_H_ */

CVSweb <webmaster@jp.NetBSD.org>