gonzui


Format: Advanced Search

t2ex/bsd_source/lib/libc/src_bsd/include/sys/proc.hbare sourcepermlink (0.05 seconds)

Search this content:

    1: /*      $OpenBSD: proc.h,v 1.153 2012/03/23 15:51:26 guenther Exp $  */
    2: /*      $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $    */
    3: 
    4: /*-
    5:  * Copyright (c) 1986, 1989, 1991, 1993
    6:  *      The Regents of the University of California.  All rights reserved.
    7:  * (c) UNIX System Laboratories, Inc.
    8:  * All or some portions of this file are derived from material licensed
    9:  * to the University of California by American Telephone and Telegraph
   10:  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
   11:  * the permission of UNIX System Laboratories, Inc.
   12:  *
   13:  * Redistribution and use in source and binary forms, with or without
   14:  * modification, are permitted provided that the following conditions
   15:  * are met:
   16:  * 1. Redistributions of source code must retain the above copyright
   17:  *    notice, this list of conditions and the following disclaimer.
   18:  * 2. Redistributions in binary form must reproduce the above copyright
   19:  *    notice, this list of conditions and the following disclaimer in the
   20:  *    documentation and/or other materials provided with the distribution.
   21:  * 3. Neither the name of the University nor the names of its contributors
   22:  *    may be used to endorse or promote products derived from this software
   23:  *    without specific prior written permission.
   24:  *
   25:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   26:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   27:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   28:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   29:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   30:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   31:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   32:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   33:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   34:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   35:  * SUCH DAMAGE.
   36:  *
   37:  *      @(#)proc.h   8.8 (Berkeley) 1/21/94
   38:  */
   39: 
   40: #ifndef _SYS_PROC_H_
   41: #define _SYS_PROC_H_
   42: 
   43: #include <machine/proc.h>               /* Machine-dependent proc substruct. */
   44: #include <sys/selinfo.h>                /* For struct selinfo */
   45: #include <sys/queue.h>
   46: #include <sys/timeout.h>                /* For struct timeout */
   47: #include <sys/event.h>                  /* For struct klist */
   48: #include <sys/mutex.h>                  /* For struct mutex */
   49: #include <sys/resource.h>               /* For struct rusage */
   50: #include <machine/atomic.h>
   51: 
   52: #ifdef _KERNEL
   53: #define __need_process
   54: #endif
   55: 
   56: /*
   57:  * One structure allocated per session.
   58:  */
   59: struct process;
   60: struct  session {
   61:         int    s_count;           /* Ref cnt; pgrps in session. */
   62:         struct process *s_leader;      /* Session leader. */
   63:         struct vnode *s_ttyvp;         /* Vnode of controlling terminal. */
   64:         struct tty *s_ttyp;            /* Controlling terminal. */
   65:         char   s_login[MAXLOGNAME];      /* Setlogin() name. */
   66: };
   67: 
   68: /*
   69:  * One structure allocated per process group.
   70:  */
   71: struct  pgrp {
   72:         LIST_ENTRY(pgrp) pg_hash;      /* Hash chain. */
   73:         LIST_HEAD(, process) pg_members;/* Pointer to pgrp members. */
   74:         struct session *pg_session;    /* Pointer to session. */
   75:         pid_t  pg_id;                   /* Pgrp id. */
   76:         int    pg_jobc;   /* # procs qualifying pgrp for job control */
   77: };
   78: 
   79: /*
   80:  * One structure allocated per emulation.
   81:  */
   82: struct exec_package;
   83: struct proc;
   84: struct ps_strings;
   85: struct uvm_object;
   86: union sigval;
   87: 
   88: struct  emul {
   89:         char   e_name[8];                /* Symbolic name */
   90:         int    *e_errno;          /* Errno array */
   91:                                         /* Signal sending function */
   92:         void   (*e_sendsig)(sig_t, int, int, u_long, int, union sigval);
   93:         int    e_nosys;           /* Offset of the nosys() syscall */
   94:         int    e_nsysent;         /* Number of system call entries */
   95:         struct sysent *e_sysent;       /* System call array */
   96:         char   **e_syscallnames; /* System call name array */
   97:         int    e_arglen;          /* Extra argument size in words */
   98:                                         /* Copy arguments on the stack */
   99:         void   *(*e_copyargs)(struct exec_package *, struct ps_strings *,
  100:                                     void *, void *);
  101:                                         /* Set registers before execution */
  102:         void   (*e_setregs)(struct proc *, struct exec_package *,
  103:                                   u_long, register_t *);
  104:         int    (*e_fixup)(struct proc *, struct exec_package *);
  105:         int    (*e_coredump)(struct proc *, void *cookie);
  106:         char   *e_sigcode;               /* Start of sigcode */
  107:         char   *e_esigcode;              /* End of sigcode */
  108:         int    e_flags;           /* Flags, see below */
  109:         struct uvm_object *e_sigobject;        /* shared sigcode object */
  110:                                         /* Per-process hooks */
  111:         void   (*e_proc_exec)(struct proc *, struct exec_package *);
  112:         void   (*e_proc_fork)(struct proc *p, struct proc *parent);
  113:         void   (*e_proc_exit)(struct proc *);
  114: };
  115: /* Flags for e_flags */
  116: #define EMUL_ENABLED    0x0001             /* Allow exec to continue */
  117: #define EMUL_NATIVE     0x0002              /* Always enabled */
  118: 
  119: extern struct emul *emulsw[];           /* All emuls in system */
  120: extern int nemuls;                      /* Number of emuls */
  121: 
  122: /*
  123:  * time usage: accumulated times in ticks
  124:  * One a second, each thread's immediate counts (p_[usi]ticks) are
  125:  * accumulated into these.
  126:  */
  127: struct tusage {
  128:         struct timeval tu_runtime;     /* Realtime. */
  129:         uint64_t       tu_uticks;    /* Statclock hits in user mode. */
  130:         uint64_t       tu_sticks;    /* Statclock hits in system mode. */
  131:         uint64_t       tu_iticks;    /* Statclock hits processing intr. */
  132: };
  133: 
  134: /*
  135:  * Description of a process.
  136:  *
  137:  * These structures contain the information needed to manage a thread of
  138:  * control, known in UN*X as a process; it has references to substructures
  139:  * containing descriptions of things that the process uses, but may share
  140:  * with related processes.
  141:  *
  142:  * struct process is the higher level process containing information
  143:  * shared by all threads in a process, while struct proc contains the
  144:  * run-time information needed by threads.
  145:  */
  146: #ifdef __need_process
  147: struct process {
  148:         /*
  149:          * ps_mainproc is the main thread in the process.
  150:          * Ultimately, we shouldn't need that, threads should be able to exit
  151:          * at will. Unfortunately until the pid is moved into struct process
  152:          * we'll have to remember the main threads and abuse its pid as the
  153:          * the pid of the process. This is gross, but considering the horrible
  154:          * pid semantics we have right now, it's unavoidable.
  155:          */
  156:         struct proc *ps_mainproc;
  157:         struct pcred *ps_cred;         /* Process owner's identity. */
  158: 
  159:         TAILQ_HEAD(,proc) ps_threads;  /* Threads in this process. */
  160: 
  161:         LIST_ENTRY(process) ps_pglist; /* List of processes in pgrp. */
  162:         struct process *ps_pptr;       /* Pointer to parent process. */
  163:         LIST_ENTRY(process) ps_sibling;        /* List of sibling processes. */
  164:         LIST_HEAD(, process) ps_children;/* Pointer to list of children. */
  165: 
  166: /* The following fields are all zeroed upon creation in process_new. */
  167: #define ps_startzero    ps_klist
  168:         struct klist ps_klist;         /* knotes attached to this process */
  169:         int    ps_flags;          /* PS_* flags. */
  170: 
  171:         struct proc *ps_single;        /* Single threading to this thread. */
  172:         int    ps_singlecount;            /* Not yet suspended threads. */
  173: 
  174:         int    ps_traceflag;              /* Kernel trace points. */
  175:         struct vnode *ps_tracevp;      /* Trace to vnode. */
  176:         struct ucred *ps_tracecred;    /* Creds for writing trace */
  177: 
  178:         pid_t  ps_oppid;               /* Save parent pid during ptrace. */
  179:         int    ps_ptmask;         /* Ptrace event mask */
  180:         struct ptrace_state *ps_ptstat;/* Ptrace state */
  181: 
  182:         struct rusage *ps_ru;          /* sum of stats for dead threads. */
  183:         struct tusage ps_tu;           /* accumulated times. */
  184:         struct rusage ps_cru;          /* sum of stats for reaped children */
  185:         struct itimerval ps_timer[3];  /* timers, indexed by ITIMER_* */
  186: 
  187: /* End area that is zeroed on creation. */
  188: #define ps_endzero      ps_startcopy
  189: 
  190: /* The following fields are all copied upon creation in process_new. */
  191: #define ps_startcopy    ps_limit
  192: 
  193:         struct plimit *ps_limit;       /* Process limits. */
  194:         struct pgrp *ps_pgrp;          /* Pointer to process group. */
  195:         u_int  ps_rtableid;             /* Process routing table/domain. */
  196:         char   ps_nice;          /* Process "nice" value. */
  197: 
  198:         struct uprof {                 /* profile arguments */
  199:                 caddr_t       pr_base;      /* buffer base */
  200:                 size_t  pr_size;      /* buffer size */
  201:                 u_long        pr_off;                /* pc offset */
  202:                 u_int   pr_scale;     /* pc scaling */
  203:         } ps_prof;
  204: 
  205: /* End area that is copied on creation. */
  206: #define ps_endcopy      ps_refcnt
  207: 
  208:         struct timeval ps_start;       /* starting time. */
  209:         struct timeout ps_realit_to;   /* real-time itimer trampoline. */
  210:         struct timeout ps_virt_to;     /* virtual itimer trampoline. */
  211:         struct timeout ps_prof_to;     /* prof itimer trampoline. */
  212: 
  213:         int    ps_refcnt;         /* Number of references. */
  214: };
  215: 
  216: #define ps_pid          ps_mainproc->p_pid
  217: #define ps_session      ps_pgrp->pg_session
  218: #define ps_pgid         ps_pgrp->pg_id
  219: 
  220: #endif /* __need_process */
  221: 
  222: /*
  223:  * These flags are kept in ps_flags, but they used to be in proc's p_flag
  224:  * and were exported to userspace via the KERN_PROC sysctl.  We'll retain
  225:  * compat by using non-overlapping bits for PS_* and P_* flags and just
  226:  * OR them together for export.
  227:  */
  228: #define PS_CONTROLT     _P_CONTROLT
  229: #define PS_PPWAIT       _P_PPWAIT
  230: #define PS_PROFIL       _P_PROFIL
  231: #define PS_SUGID        _P_SUGID
  232: #define PS_SYSTEM       _P_SYSTEM
  233: #define PS_TRACED       _P_TRACED
  234: #define PS_WAITED       _P_WAITED
  235: #define PS_EXEC         _P_EXEC
  236: #define PS_ISPWAIT      _P_ISPWAIT
  237: #define PS_SUGIDEXEC    _P_SUGIDEXEC
  238: #define PS_NOZOMBIE     _P_NOZOMBIE
  239: #define PS_INEXEC       _P_INEXEC
  240: #define PS_SYSTRACE     _P_SYSTRACE
  241: #define PS_CONTINUED    _P_CONTINUED
  242: #define PS_STOPPED      _P_STOPPED
  243: #define PS_SINGLEEXIT   _P_SINGLEEXIT
  244: #define PS_SINGLEUNWIND _P_SINGLEUNWIND
  245: #define PS_EXITING      _P_EXITING
  246: 
  247: struct proc {
  248:         TAILQ_ENTRY(proc) p_runq;
  249:         LIST_ENTRY(proc) p_list;       /* List of all processes. */
  250: 
  251:         struct process *p_p;           /* The process of this thread. */
  252:         TAILQ_ENTRY(proc) p_thr_link;/* Threads in a process linkage. */
  253: 
  254:         /* substructures: */
  255:         struct filedesc *p_fd;         /* Ptr to open files structure. */
  256:         struct vmspace *p_vmspace;     /* Address space. */
  257:         struct sigacts *p_sigacts;     /* Signal actions, state */
  258: #define p_cred          p_p->ps_cred
  259: #define p_ucred         p_cred->pc_ucred
  260: #define p_rlimit        p_p->ps_limit->pl_rlimit
  261: 
  262:         int    p_exitsig;         /* Signal to send to parent on exit. */
  263:         int    p_flag;                    /* P_* flags. */
  264:         u_char p_os;                   /* OS tag */
  265:         char   p_stat;                   /* S* process status. */
  266:         char   p_pad1[1];
  267:         u_char p_descfd;               /* if not 255, fdesc permits this fd */
  268: 
  269:         pid_t  p_pid;                   /* Process identifier. */
  270:         LIST_ENTRY(proc) p_hash;       /* Hash chain. */
  271: 
  272: /* The following fields are all zeroed upon creation in fork. */
  273: #define p_startzero     p_dupfd
  274: 
  275:         int    p_dupfd;    /* Sideways return value from filedescopen. XXX */
  276: 
  277:         long   p_thrslpid;      /* for thrsleep syscall */
  278:         int    p_sigwait; /* signal handled by sigwait() */
  279: 
  280:         /* scheduling */
  281:         u_int  p_estcpu;         /* Time averaged value of p_cpticks. */
  282:         int    p_cpticks;  /* Ticks of cpu time. */
  283:         fixpt_t        p_pctcpu;       /* %cpu for this process during p_swtime */
  284:         const volatile void *p_wchan;/* Sleep address. */
  285:         struct timeout p_sleep_to;/* timeout for tsleep() */
  286:         const char *p_wmesg;    /* Reason for sleep. */
  287:         u_int  p_swtime;         /* Time swapped in or out. */
  288:         u_int  p_slptime;        /* Time since last blocked. */
  289:         struct cpu_info * __volatile p_cpu; /* CPU we're running on. */
  290: 
  291:         struct rusage p_ru;            /* Statistics */
  292:         struct tusage p_tu;            /* accumulated times. */
  293:         struct timeval p_rtime;        /* Real time. */
  294:         u_int  p_uticks;                /* Statclock hits in user mode. */
  295:         u_int  p_sticks;                /* Statclock hits in system mode. */
  296:         u_int  p_iticks;                /* Statclock hits processing intr. */
  297: 
  298:         void   *p_systrace;              /* Back pointer to systrace */
  299: 
  300:         int    p_siglist;         /* Signals arrived but not delivered. */
  301: 
  302:         struct vnode *p_textvp;        /* Vnode of executable. */
  303: 
  304:         void   *p_emuldata;              /* Per-process emulation data, or */
  305:                                         /* NULL. Malloc type M_EMULDATA */
  306: 
  307:         sigset_t p_sigdivert;          /* Signals to be diverted to thread. */
  308: 
  309: /* End area that is zeroed on creation. */
  310: #define p_endzero       p_startcopy
  311: 
  312: /* The following fields are all copied upon creation in fork. */
  313: #define p_startcopy     p_sigmask
  314: 
  315:         sigset_t p_sigmask;    /* Current signal mask. */
  316: 
  317:         u_char p_priority;     /* Process priority. */
  318:         u_char p_usrpri;       /* User-priority based on p_cpu and ps_nice. */
  319:         char   p_comm[MAXCOMLEN+1];
  320: 
  321: #ifndef __HAVE_MD_TCB
  322:         void   *p_tcb;           /* user-space thread-control-block address */
  323: # define TCB_SET(p, addr)       ((p)->p_tcb = (addr))
  324: # define TCB_GET(p)             ((p)->p_tcb)
  325: #endif
  326: 
  327:         struct emul *p_emul;           /* Emulation information */
  328:         struct sigaltstack p_sigstk;   /* sp & on stack state variable */
  329:         vaddr_t        p_sigcode;             /* user pointer to the signal code. */
  330: 
  331: /* End area that is copied on creation. */
  332: #define p_endcopy       p_addr
  333: 
  334:         struct user *p_addr;   /* Kernel virtual addr of u-area */
  335:         struct mdproc p_md;    /* Any machine-dependent fields. */
  336: 
  337:         sigset_t p_oldmask;    /* Saved mask from before sigpause */
  338:         union sigval p_sigval; /* For core dump/debugger XXX */
  339:         int    p_sisig;   /* For core dump/debugger XXX */
  340:         int    p_sicode;  /* For core dump/debugger XXX */
  341:         long   p_sitrapno;       /* For core dump/debugger XXX */
  342: 
  343:         u_long p_prof_addr;    /* temp storage for profiling addr util AST */
  344:         u_long p_prof_ticks;   /* temp storage for profiling ticks util AST */
  345: 
  346:         u_short        p_xstat;       /* Exit status for wait; also stop signal. */
  347:         u_short        p_acflag;      /* Accounting flags. */
  348: };
  349: 
  350: /* Status values. */
  351: #define SIDL    1          /* Process being created by fork. */
  352: #define SRUN    2          /* Currently runnable. */
  353: #define SSLEEP  3                /* Sleeping on an address. */
  354: #define SSTOP   4         /* Process debugging or suspension. */
  355: #define SZOMB   5         /* Awaiting collection by parent. */
  356: #define SDEAD   6         /* Process is almost a zombie. */
  357: #define SONPROC 7               /* Process is currently on a CPU. */
  358: 
  359: #define P_ZOMBIE(p)     ((p)->p_stat == SZOMB || (p)->p_stat == SDEAD)
  360: 
  361: /*
  362:  * These flags are kept in p_flag, except those with a leading underbar,
  363:  * which are in process's ps_flags
  364:  */
  365: #define P_INKTR         0x000001       /* In a ktrace op, don't recurse */
  366: #define _P_CONTROLT     0x000002    /* Has a controlling terminal. */
  367: #define P_INMEM         0x000004       /* Loaded into memory. UNUSED */
  368: #define P_SIGSUSPEND    0x000008   /* Need to restore before-suspend mask*/
  369: #define _P_PPWAIT       0x000010      /* Parent waits for exec/exit. */
  370: #define P_PROFIL        0x000020       /* Has started profiling. */
  371: #define P_SELECT        0x000040       /* Selecting; wakeup/waiting danger. */
  372: #define P_SINTR         0x000080       /* Sleep is interruptible. */
  373: #define _P_SUGID        0x000100       /* Had set id privs since last exec. */
  374: #define P_SYSTEM        0x000200       /* No sigs, stats or swapping. */
  375: #define P_TIMEOUT       0x000400      /* Timing out during sleep. */
  376: #define _P_TRACED       0x000800      /* Debugged process being traced. */
  377: #define P_WAITED        0x001000       /* Debugging proc has waited for child. */
  378: #define P_WEXIT         0x002000       /* Working on exiting. */
  379: #define _P_EXEC         0x004000       /* Process called exec. */
  380: 
  381: /* Should be moved to machine-dependent areas. */
  382: #define P_OWEUPC        0x008000       /* Owe proc an addupc() at next ast. */
  383: #define _P_ISPWAIT      0x010000     /* Is parent of PPWAIT child. */
  384: 
  385: /* XXX Not sure what to do with these, yet. */
  386: #define P_SSTEP         0x020000       /* proc needs single-step fixup ??? */
  387: #define _P_SUGIDEXEC    0x040000   /* last execve() was set[ug]id */
  388: 
  389: #define P_SUSPSINGLE    0x080000   /* Need to stop for single threading. */
  390: #define P_NOZOMBIE      0x100000     /* Pid 1 waits for me instead of dad */
  391: #define _P_INEXEC       0x200000      /* Process is doing an exec right now */
  392: #define P_SYSTRACE      0x400000     /* Process system call tracing active*/
  393: #define P_CONTINUED     0x800000    /* Proc has continued from a stopped state. */
  394: #define _P_SINGLEEXIT   0x1000000 /* Other threads must die. */
  395: #define _P_SINGLEUNWIND 0x2000000       /* Other threads must unwind. */
  396: #define P_THREAD        0x4000000      /* Only a thread, not a real process */
  397: #define P_SUSPSIG       0x8000000     /* Stopped from signal. */
  398: #define P_SOFTDEP       0x10000000    /* Stuck processing softdep worklist */
  399: #define P_STOPPED       0x20000000    /* Just stopped, need sig to parent. */
  400: #define P_CPUPEG        0x40000000     /* Do not move to another cpu. */
  401: #define _P_EXITING      0x80000000   /* Process is exiting. */
  402: 
  403: #ifndef _KERNEL
  404: #define P_CONTROLT      _P_CONTROLT
  405: #define P_PPWAIT        _P_PPWAIT
  406: #define P_SUGID         _P_SUGID
  407: #define P_TRACED        _P_TRACED
  408: #define P_EXEC          _P_EXEC
  409: #define P_SUGIDEXEC     _P_SUGIDEXEC
  410: #define P_INEXEC        _P_INEXEC
  411: #endif
  412: 
  413: #define P_BITS \
  414:     ("\20\02CONTROLT\03INMEM\04SIGPAUSE\05PPWAIT\06PROFIL\07SELECT" \
  415:      "\010SINTR\011SUGID\012SYSTEM\013TIMEOUT\014TRACED\015WAITED\016WEXIT" \
  416:      "\017EXEC\020PWEUPC\021ISPWAIT\022SSTEP\023SUGIDEXEC\024SUSPSINGLE" \
  417:      "\025NOZOMBIE\026INEXEC\027SYSTRACE\030CONTINUED" \
  418:      "\031SINGLEEXIT\032SINGLEUNWIND" \
  419:      "\033THREAD\034SUSPSIG\035SOFTDEP\036STOPPED\037CPUPEG")
  420: 
  421: /* Macro to compute the exit signal to be delivered. */
  422: #define P_EXITSIG(p) \
  423:     (((p)->p_p->ps_flags & PS_TRACED) ? SIGCHLD : (p)->p_exitsig)
  424: 
  425: #define THREAD_PID_OFFSET       1000000
  426: 
  427: /*
  428:  * MOVE TO ucred.h?
  429:  *
  430:  * Shareable process credentials (always resident).  This includes a reference
  431:  * to the current user credentials as well as real and saved ids that may be
  432:  * used to change ids.
  433:  */
  434: struct  pcred {
  435:         struct ucred *pc_ucred;        /* Current credentials. */
  436:         uid_t  p_ruid;                  /* Real user id. */
  437:         uid_t  p_svuid;         /* Saved effective user id. */
  438:         gid_t  p_rgid;                  /* Real group id. */
  439:         gid_t  p_svgid;         /* Saved effective group id. */
  440: };
  441: 
  442: #ifdef _KERNEL
  443: 
  444: struct uidinfo {
  445:         LIST_ENTRY(uidinfo) ui_hash;
  446:         uid_t   ui_uid;
  447:         long    ui_proccnt;    /* proc structs */
  448:         long   ui_lockcnt;       /* lockf structs */
  449: };
  450: 
  451: struct uidinfo *uid_find(uid_t);
  452: 
  453: /*
  454:  * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
  455:  * as it is used to represent "no process group".
  456:  * We set PID_MAX to (SHRT_MAX - 1) so we don't break sys/compat.
  457:  */
  458: #define PID_MAX         32766
  459: #define NO_PID          (PID_MAX+1)
  460: 
  461: #define SESS_LEADER(pr) ((pr)->ps_session->s_leader == (pr))
  462: #define SESSHOLD(s)     ((s)->s_count++)
  463: #define SESSRELE(s) do {                                                \
  464:         if (--(s)->s_count == 0)                                       \
  465:                 pool_put(&session_pool, (s));                         \
  466: } while (/* CONSTCOND */ 0)
  467: 
  468: /*
  469:  * Flags to fork1().
  470:  */
  471: #define FORK_FORK       0x00000001
  472: #define FORK_VFORK      0x00000002
  473: #define FORK_RFORK      0x00000004
  474: #define FORK_PPWAIT     0x00000008
  475: #define FORK_SHAREFILES 0x00000010
  476: #define FORK_CLEANFILES 0x00000020
  477: #define FORK_NOZOMBIE   0x00000040
  478: #define FORK_SHAREVM    0x00000080
  479: #define FORK_TFORK      0x00000100
  480: #define FORK_SIGHAND    0x00000200
  481: #define FORK_PTRACE     0x00000400
  482: #define FORK_THREAD     0x00000800
  483: 
  484: #define EXIT_NORMAL     0x00000001
  485: #define EXIT_THREAD     0x00000002
  486: 
  487: #define PIDHASH(pid)    (&pidhashtbl[(pid) & pidhash])
  488: extern LIST_HEAD(pidhashhead, proc) *pidhashtbl;
  489: extern u_long pidhash;
  490: 
  491: #define PGRPHASH(pgid)  (&pgrphashtbl[(pgid) & pgrphash])
  492: extern LIST_HEAD(pgrphashhead, pgrp) *pgrphashtbl;
  493: extern u_long pgrphash;
  494: 
  495: extern struct proc proc0;               /* Process slot for swapper. */
  496: extern int nprocs, maxproc;             /* Current and max number of procs. */
  497: extern int randompid;                   /* fork() should create random pid's */
  498: 
  499: LIST_HEAD(proclist, proc);
  500: extern struct proclist allproc;         /* List of all processes. */
  501: extern struct proclist zombproc;        /* List of zombie processes. */
  502: 
  503: extern struct proc *initproc;           /* Process slots for init, pager. */
  504: extern struct proc *syncerproc;         /* filesystem syncer daemon */
  505: 
  506: extern struct pool process_pool;        /* memory pool for processes */
  507: extern struct pool proc_pool;           /* memory pool for procs */
  508: extern struct pool rusage_pool;         /* memory pool for zombies */
  509: extern struct pool ucred_pool;          /* memory pool for ucreds */
  510: extern struct pool session_pool;        /* memory pool for sessions */
  511: extern struct pool pgrp_pool;           /* memory pool for pgrps */
  512: extern struct pool pcred_pool;          /* memory pool for pcreds */
  513: 
  514: struct simplelock;
  515: 
  516: struct process *prfind(pid_t);  /* Find process by id. */
  517: struct proc *pfind(pid_t);      /* Find thread by id. */
  518: struct pgrp *pgfind(pid_t);     /* Find process group by id. */
  519: void    proc_printit(struct proc *p, const char *modif,
  520:     int (*pr)(const char *, ...));
  521: 
  522: int     chgproccnt(uid_t uid, int diff);
  523: int     enterpgrp(struct process *, pid_t, struct pgrp *, struct session *);
  524: void    fixjobc(struct process *, struct pgrp *, int);
  525: int     inferior(struct process *, struct process *);
  526: void    leavepgrp(struct process *);
  527: void    preempt(struct proc *);
  528: void    pgdelete(struct pgrp *);
  529: void    procinit(void);
  530: void    resetpriority(struct proc *);
  531: void    setrunnable(struct proc *);
  532: void    endtsleep(void *);
  533: void    unsleep(struct proc *);
  534: void    reaper(void);
  535: void    exit1(struct proc *, int, int);
  536: void    exit2(struct proc *);
  537: void    cpu_exit(struct proc *);
  538: int     fork1(struct proc *, int, int, void *, pid_t *, void (*)(void *),
  539:             void *, register_t *, struct proc **);
  540: int     groupmember(gid_t, struct ucred *);
  541: 
  542: enum single_thread_mode {
  543:         SINGLE_SUSPEND,                /* other threads to stop wherever they are */
  544:         SINGLE_UNWIND,         /* other threads to unwind and stop */
  545:         SINGLE_EXIT            /* other threads to unwind and then exit */
  546: };
  547: int     single_thread_set(struct proc *, enum single_thread_mode, int);
  548: void    single_thread_clear(struct proc *);
  549: int     single_thread_check(struct proc *, int);
  550: 
  551: void    child_return(void *);
  552: 
  553: int     proc_cansugid(struct proc *);
  554: void    proc_finish_wait(struct proc *, struct proc *);
  555: void    proc_zap(struct proc *);
  556: 
  557: struct sleep_state {
  558:         int sls_s;
  559:         int sls_catch;
  560:         int sls_do_sleep;
  561:         int sls_sig;
  562: };
  563: 
  564: #if defined(MULTIPROCESSOR)
  565: void    proc_trampoline_mp(void);  /* XXX */
  566: #endif
  567: 
  568: /*
  569:  * functions to handle sets of cpus.
  570:  *
  571:  * For now we keep the cpus in ints so that we can use the generic
  572:  * atomic ops.
  573:  */
  574: #define CPUSET_ASIZE(x) (((x) - 1)/32 + 1)
  575: #define CPUSET_SSIZE CPUSET_ASIZE(MAXCPUS)
  576: struct cpuset {
  577:         int cs_set[CPUSET_SSIZE];
  578: };
  579: 
  580: void cpuset_init_cpu(struct cpu_info *);
  581: 
  582: void cpuset_clear(struct cpuset *);
  583: void cpuset_add(struct cpuset *, struct cpu_info *);
  584: void cpuset_del(struct cpuset *, struct cpu_info *);
  585: int cpuset_isset(struct cpuset *, struct cpu_info *);
  586: void cpuset_add_all(struct cpuset *);
  587: void cpuset_copy(struct cpuset *, struct cpuset *);
  588: void cpuset_union(struct cpuset *, struct cpuset *, struct cpuset *);
  589: void cpuset_intersection(struct cpuset *t, struct cpuset *, struct cpuset *);
  590: void cpuset_complement(struct cpuset *, struct cpuset *, struct cpuset *);
  591: struct cpu_info *cpuset_first(struct cpuset *);
  592: 
  593: #endif  /* _KERNEL */
  594: #endif  /* !_SYS_PROC_H_ */
  595: