LCOV - code coverage report
Current view: top level - sys - proc.h (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 5 0.0 %
Date: 2018-10-19 03:25:38 Functions: 0 1 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*      $OpenBSD: proc.h,v 1.259 2018/08/30 03:30:25 visa 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/syslimits.h>                /* For LOGIN_NAME_MAX */
      46             : #include <sys/queue.h>
      47             : #include <sys/timeout.h>          /* For struct timeout */
      48             : #include <sys/event.h>                    /* For struct klist */
      49             : #include <sys/mutex.h>                    /* For struct mutex */
      50             : #include <sys/resource.h>         /* For struct rusage */
      51             : #include <sys/rwlock.h>                   /* For struct rwlock */
      52             : #include <sys/tree.h>
      53             : 
      54             : #ifdef _KERNEL
      55             : #include <sys/atomic.h>
      56             : #define __need_process
      57             : #endif
      58             : 
      59             : /*
      60             :  * One structure allocated per session.
      61             :  */
      62             : struct process;
      63             : struct  session {
      64             :         int     s_count;                /* Ref cnt; pgrps in session. */
      65             :         struct  process *s_leader;      /* Session leader. */
      66             :         struct  vnode *s_ttyvp;         /* Vnode of controlling terminal. */
      67             :         struct  tty *s_ttyp;            /* Controlling terminal. */
      68             :         char    s_login[LOGIN_NAME_MAX];        /* Setlogin() name. */
      69             :         pid_t   s_verauthppid;
      70             :         uid_t   s_verauthuid;
      71             :         struct timeout s_verauthto;
      72             : };
      73             : 
      74             : void zapverauth(/* struct session */ void *);
      75             : 
      76             : /*
      77             :  * One structure allocated per process group.
      78             :  */
      79             : struct  pgrp {
      80             :         LIST_ENTRY(pgrp) pg_hash;       /* Hash chain. */
      81             :         LIST_HEAD(, process) pg_members;/* Pointer to pgrp members. */
      82             :         struct  session *pg_session;    /* Pointer to session. */
      83             :         pid_t   pg_id;                  /* Pgrp id. */
      84             :         int     pg_jobc;        /* # procs qualifying pgrp for job control */
      85             : };
      86             : 
      87             : /*
      88             :  * One structure allocated per emulation.
      89             :  */
      90             : struct exec_package;
      91             : struct proc;
      92             : struct ps_strings;
      93             : struct uvm_object;
      94             : union sigval;
      95             : 
      96             : struct  emul {
      97             :         char    e_name[8];              /* Symbolic name */
      98             :         int     *e_errno;               /* Errno array */
      99             :         int     e_nosys;                /* Offset of the nosys() syscall */
     100             :         int     e_nsysent;              /* Number of system call entries */
     101             :         struct sysent *e_sysent;        /* System call array */
     102             :         char    **e_syscallnames;       /* System call name array */
     103             :         int     e_arglen;               /* Extra argument size in words */
     104             :                                         /* Copy arguments on the stack */
     105             :         void    *(*e_copyargs)(struct exec_package *, struct ps_strings *,
     106             :                                     void *, void *);
     107             :                                         /* Set registers before execution */
     108             :         void    (*e_setregs)(struct proc *, struct exec_package *,
     109             :                                   u_long, register_t *);
     110             :         int     (*e_fixup)(struct proc *, struct exec_package *);
     111             :         int     (*e_coredump)(struct proc *, void *cookie);
     112             :         char    *e_sigcode;             /* Start of sigcode */
     113             :         char    *e_esigcode;            /* End of sigcode */
     114             :         char    *e_esigret;             /* sigaction RET position */
     115             :         struct uvm_object *e_sigobject; /* shared sigcode object */
     116             : };
     117             : 
     118             : /*
     119             :  * time usage: accumulated times in ticks
     120             :  * Once a second, each thread's immediate counts (p_[usi]ticks) are
     121             :  * accumulated into these.
     122             :  */
     123             : struct tusage {
     124             :         struct  timespec tu_runtime;    /* Realtime. */
     125             :         uint64_t        tu_uticks;      /* Statclock hits in user mode. */
     126             :         uint64_t        tu_sticks;      /* Statclock hits in system mode. */
     127             :         uint64_t        tu_iticks;      /* Statclock hits processing intr. */
     128             : };
     129             : 
     130             : struct unvname {
     131             :         char                    *un_name;
     132             :         size_t                  un_namesize;
     133             :         u_char                  un_flags;
     134             :         RBT_ENTRY(unvnmae)      un_rbt;
     135             : };
     136             : 
     137             : RBT_HEAD(unvname_rbt, unvname);
     138             : 
     139             : /*
     140             :  * Description of a process.
     141             :  *
     142             :  * These structures contain the information needed to manage a thread of
     143             :  * control, known in UN*X as a process; it has references to substructures
     144             :  * containing descriptions of things that the process uses, but may share
     145             :  * with related processes.
     146             :  *
     147             :  * struct process is the higher level process containing information
     148             :  * shared by all threads in a process, while struct proc contains the
     149             :  * run-time information needed by threads.
     150             :  */
     151             : #ifdef __need_process
     152             : struct futex;
     153             : LIST_HEAD(futex_list, futex);
     154             : struct unveil;
     155             : struct process {
     156             :         /*
     157             :          * ps_mainproc is the original thread in the process.
     158             :          * It's only still special for the handling of p_xstat and
     159             :          * some signal and ptrace behaviors that need to be fixed.
     160             :          */
     161             :         struct  proc *ps_mainproc;
     162             :         struct  ucred *ps_ucred;        /* Process owner's identity. */
     163             : 
     164             :         LIST_ENTRY(process) ps_list;    /* List of all processes. */
     165             :         TAILQ_HEAD(,proc) ps_threads;   /* Threads in this process. */
     166             : 
     167             :         LIST_ENTRY(process) ps_pglist;  /* List of processes in pgrp. */
     168             :         struct  process *ps_pptr;       /* Pointer to parent process. */
     169             :         LIST_ENTRY(process) ps_sibling; /* List of sibling processes. */
     170             :         LIST_HEAD(, process) ps_children;/* Pointer to list of children. */
     171             :         LIST_ENTRY(process) ps_hash;    /* Hash chain. */
     172             : 
     173             :         struct  sigacts *ps_sigacts;    /* Signal actions, state */
     174             :         struct  vnode *ps_textvp;       /* Vnode of executable. */
     175             :         struct  filedesc *ps_fd;        /* Ptr to open files structure */
     176             :         struct  vmspace *ps_vmspace;    /* Address space */
     177             :         pid_t   ps_pid;                 /* Process identifier. */
     178             : 
     179             :         struct  futex_list ps_ftlist;   /* futexes attached to this process */
     180             :         LIST_HEAD(, kqueue) ps_kqlist;  /* kqueues attached to this process */
     181             : 
     182             : /* The following fields are all zeroed upon creation in process_new. */
     183             : #define ps_startzero    ps_klist
     184             :         struct  klist ps_klist;         /* knotes attached to this process */
     185             :         int     ps_flags;               /* PS_* flags. */
     186             : 
     187             :         struct  proc *ps_single;        /* Single threading to this thread. */
     188             :         int     ps_singlecount;         /* Not yet suspended threads. */
     189             : 
     190             :         int     ps_traceflag;           /* Kernel trace points. */
     191             :         struct  vnode *ps_tracevp;      /* Trace to vnode. */
     192             :         struct  ucred *ps_tracecred;    /* Creds for writing trace */
     193             : 
     194             :         pid_t   ps_oppid;               /* Save parent pid during ptrace. */
     195             :         int     ps_ptmask;              /* Ptrace event mask */
     196             :         struct  ptrace_state *ps_ptstat;/* Ptrace state */
     197             : 
     198             :         struct  rusage *ps_ru;          /* sum of stats for dead threads. */
     199             :         struct  tusage ps_tu;           /* accumulated times. */
     200             :         struct  rusage ps_cru;          /* sum of stats for reaped children */
     201             :         struct  itimerval ps_timer[3];  /* timers, indexed by ITIMER_* */
     202             : 
     203             :         u_int64_t ps_wxcounter;
     204             : 
     205             :         struct unveil *ps_uvpaths;      /* unveil vnodes and names */
     206             :         struct unveil *ps_uvpcwd;       /* pointer to unveil of cwd, NULL if none */
     207             :         size_t ps_uvvcount;             /* count of unveil vnodes held */
     208             :         size_t ps_uvncount;             /* count of unveil names allocated */
     209             :         int ps_uvshrink;                /* do we need to shrink vnode list */
     210             :         int ps_uvdone;                  /* no more unveil is permitted */
     211             :         int ps_uvpcwdgone;              /* need to reevaluate cwd unveil */
     212             : 
     213             : /* End area that is zeroed on creation. */
     214             : #define ps_endzero      ps_startcopy
     215             : 
     216             : /* The following fields are all copied upon creation in process_new. */
     217             : #define ps_startcopy    ps_limit
     218             :         struct  plimit *ps_limit;       /* Process limits. */
     219             :         struct  pgrp *ps_pgrp;          /* Pointer to process group. */
     220             :         struct  emul *ps_emul;          /* Emulation information */
     221             : 
     222             :         char    ps_comm[MAXCOMLEN+1];
     223             : 
     224             :         vaddr_t ps_strings;             /* User pointers to argv/env */
     225             :         vaddr_t ps_sigcode;             /* User pointer to the signal code */
     226             :         vaddr_t ps_sigcoderet;          /* User pointer to sigreturn retPC */
     227             :         u_long  ps_sigcookie;
     228             :         u_int   ps_rtableid;            /* Process routing table/domain. */
     229             :         char    ps_nice;                /* Process "nice" value. */
     230             : 
     231             :         struct uprof {                  /* profile arguments */
     232             :                 caddr_t pr_base;        /* buffer base */
     233             :                 size_t  pr_size;        /* buffer size */
     234             :                 u_long  pr_off;         /* pc offset */
     235             :                 u_int   pr_scale;       /* pc scaling */
     236             :         } ps_prof;
     237             : 
     238             :         u_short ps_acflag;              /* Accounting flags. */
     239             : 
     240             :         uint64_t ps_pledge;
     241             :         uint64_t ps_execpledge;
     242             : 
     243             :         int64_t ps_kbind_cookie;
     244             :         u_long  ps_kbind_addr;
     245             : 
     246             : /* End area that is copied on creation. */
     247             : #define ps_endcopy      ps_refcnt
     248             :         int     ps_refcnt;              /* Number of references. */
     249             : 
     250             :         struct  timespec ps_start;      /* starting time. */
     251             :         struct  timeout ps_realit_to;   /* real-time itimer trampoline. */
     252             : };
     253             : 
     254             : #define ps_session      ps_pgrp->pg_session
     255             : #define ps_pgid         ps_pgrp->pg_id
     256             : 
     257             : #endif /* __need_process */
     258             : 
     259             : /*
     260             :  * These flags are kept in ps_flags.
     261             :  */
     262             : #define PS_CONTROLT     0x00000001      /* Has a controlling terminal. */
     263             : #define PS_EXEC         0x00000002      /* Process called exec. */
     264             : #define PS_INEXEC       0x00000004      /* Process is doing an exec right now */
     265             : #define PS_EXITING      0x00000008      /* Process is exiting. */
     266             : #define PS_SUGID        0x00000010      /* Had set id privs since last exec. */
     267             : #define PS_SUGIDEXEC    0x00000020      /* last execve() was set[ug]id */
     268             : #define PS_PPWAIT       0x00000040      /* Parent waits for exec/exit. */
     269             : #define PS_ISPWAIT      0x00000080      /* Is parent of PPWAIT child. */
     270             : #define PS_PROFIL       0x00000100      /* Has started profiling. */
     271             : #define PS_TRACED       0x00000200      /* Being ptraced. */
     272             : #define PS_WAITED       0x00000400      /* Stopped proc was waited for. */
     273             : #define PS_COREDUMP     0x00000800      /* Busy coredumping */
     274             : #define PS_SINGLEEXIT   0x00001000      /* Other threads must die. */
     275             : #define PS_SINGLEUNWIND 0x00002000      /* Other threads must unwind. */
     276             : #define PS_NOZOMBIE     0x00004000      /* No signal or zombie at exit. */
     277             : #define PS_STOPPED      0x00008000      /* Just stopped, need sig to parent. */
     278             : #define PS_SYSTEM       0x00010000      /* No sigs, stats or swapping. */
     279             : #define PS_EMBRYO       0x00020000      /* New process, not yet fledged */
     280             : #define PS_ZOMBIE       0x00040000      /* Dead and ready to be waited for */
     281             : #define PS_NOBROADCASTKILL 0x00080000   /* Process excluded from kill -1. */
     282             : #define PS_PLEDGE       0x00100000      /* Has called pledge(2) */
     283             : #define PS_WXNEEDED     0x00200000      /* Process may violate W^X */
     284             : #define PS_EXECPLEDGE   0x00400000      /* Has exec pledges */
     285             : 
     286             : #define PS_BITS \
     287             :     ("\20" "\01CONTROLT" "\02EXEC" "\03INEXEC" "\04EXITING" "\05SUGID" \
     288             :      "\06SUGIDEXEC" "\07PPWAIT" "\010ISPWAIT" "\011PROFIL" "\012TRACED" \
     289             :      "\013WAITED" "\014COREDUMP" "\015SINGLEEXIT" "\016SINGLEUNWIND" \
     290             :      "\017NOZOMBIE" "\020STOPPED" "\021SYSTEM" "\022EMBRYO" "\023ZOMBIE" \
     291             :      "\024NOBROADCASTKILL" "\025PLEDGE" "\026WXNEEDED" "\027EXECPLEDGE" )
     292             : 
     293             : 
     294             : struct kcov_dev;
     295             : struct lock_list_entry;
     296             : 
     297             : struct proc {
     298             :         TAILQ_ENTRY(proc) p_runq;
     299             :         LIST_ENTRY(proc) p_list;        /* List of all threads. */
     300             : 
     301             :         struct  process *p_p;           /* The process of this thread. */
     302             :         TAILQ_ENTRY(proc) p_thr_link;   /* Threads in a process linkage. */
     303             : 
     304             :         TAILQ_ENTRY(proc) p_fut_link;   /* Threads in a futex linkage. */
     305             :         struct  futex   *p_futex;       /* Current sleeping futex. */
     306             : 
     307             :         /* substructures: */
     308             :         struct  filedesc *p_fd;         /* copy of p_p->ps_fd */
     309             :         struct  vmspace *p_vmspace;     /* copy of p_p->ps_vmspace */
     310             : #define p_rlimit        p_p->ps_limit->pl_rlimit
     311             : 
     312             :         int     p_flag;                 /* P_* flags. */
     313             :         u_char  p_spare;                /* unused */
     314             :         char    p_stat;                 /* S* process status. */
     315             :         char    p_pad1[1];
     316             :         u_char  p_descfd;               /* if not 255, fdesc permits this fd */
     317             : 
     318             :         pid_t   p_tid;                  /* Thread identifier. */
     319             :         LIST_ENTRY(proc) p_hash;        /* Hash chain. */
     320             : 
     321             : /* The following fields are all zeroed upon creation in fork. */
     322             : #define p_startzero     p_dupfd
     323             :         int     p_dupfd;         /* Sideways return value from filedescopen. XXX */
     324             : 
     325             :         long    p_thrslpid;     /* for thrsleep syscall */
     326             : 
     327             :         /* scheduling */
     328             :         u_int   p_estcpu;        /* Time averaged value of p_cpticks. */
     329             :         int     p_cpticks;       /* Ticks of cpu time. */
     330             :         const volatile void *p_wchan;/* Sleep address. */
     331             :         struct  timeout p_sleep_to;/* timeout for tsleep() */
     332             :         const char *p_wmesg;     /* Reason for sleep. */
     333             :         fixpt_t p_pctcpu;        /* %cpu for this thread */
     334             :         u_int   p_slptime;       /* Time since last blocked. */
     335             :         u_int   p_uticks;               /* Statclock hits in user mode. */
     336             :         u_int   p_sticks;               /* Statclock hits in system mode. */
     337             :         u_int   p_iticks;               /* Statclock hits processing intr. */
     338             :         struct  cpu_info * volatile p_cpu; /* CPU we're running on. */
     339             : 
     340             :         struct  rusage p_ru;            /* Statistics */
     341             :         struct  tusage p_tu;            /* accumulated times. */
     342             :         struct  timespec p_rtime;       /* Real time. */
     343             : 
     344             :         int      p_siglist;             /* Signals arrived but not delivered. */
     345             : 
     346             : /* End area that is zeroed on creation. */
     347             : #define p_endzero       p_startcopy
     348             : 
     349             : /* The following fields are all copied upon creation in fork. */
     350             : #define p_startcopy     p_sigmask
     351             :         sigset_t p_sigmask;     /* Current signal mask. */
     352             : 
     353             :         u_int    p_spserial;
     354             :         vaddr_t  p_spstart;
     355             :         vaddr_t  p_spend;
     356             : 
     357             :         u_char  p_priority;     /* Process priority. */
     358             :         u_char  p_usrpri;       /* User-priority based on p_estcpu and ps_nice. */
     359             :         int     p_pledge_syscall;       /* Cache of current syscall */
     360             : 
     361             :         struct  ucred *p_ucred;         /* cached credentials */
     362             :         struct  sigaltstack p_sigstk;   /* sp & on stack state variable */
     363             : 
     364             :         u_long  p_prof_addr;    /* tmp storage for profiling addr until AST */
     365             :         u_long  p_prof_ticks;   /* tmp storage for profiling ticks until AST */
     366             : 
     367             : /* End area that is copied on creation. */
     368             : #define p_endcopy       p_addr
     369             :         struct  user *p_addr;   /* Kernel virtual addr of u-area */
     370             :         struct  mdproc p_md;    /* Any machine-dependent fields. */
     371             : 
     372             :         sigset_t p_oldmask;     /* Saved mask from before sigpause */
     373             :         int     p_sisig;        /* For core dump/debugger XXX */
     374             :         union sigval p_sigval;  /* For core dump/debugger XXX */
     375             :         long    p_sitrapno;     /* For core dump/debugger XXX */
     376             :         int     p_sicode;       /* For core dump/debugger XXX */
     377             : 
     378             :         u_short p_xstat;        /* Exit status for wait; also stop signal. */
     379             : 
     380             :         struct  lock_list_entry *p_sleeplocks;
     381             : 
     382             :         struct  kcov_dev *p_kd;
     383             : };
     384             : 
     385             : /* Status values. */
     386             : #define SIDL    1               /* Thread being created by fork. */
     387             : #define SRUN    2               /* Currently runnable. */
     388             : #define SSLEEP  3               /* Sleeping on an address. */
     389             : #define SSTOP   4               /* Debugging or suspension. */
     390             : #define SZOMB   5               /* unused */
     391             : #define SDEAD   6               /* Thread is almost gone */
     392             : #define SONPROC 7               /* Thread is currently on a CPU. */
     393             : 
     394             : #define P_ZOMBIE(p)     ((p)->p_stat == SDEAD)
     395             : #define P_HASSIBLING(p) (TAILQ_FIRST(&(p)->p_p->ps_threads) != (p) || \
     396             :                          TAILQ_NEXT((p), p_thr_link) != NULL)
     397             : 
     398             : /*
     399             :  * These flags are per-thread and kept in p_flag
     400             :  */
     401             : #define P_INKTR         0x00000001      /* In a ktrace op, don't recurse */
     402             : #define P_PROFPEND      0x00000002      /* SIGPROF needs to be posted */
     403             : #define P_ALRMPEND      0x00000004      /* SIGVTALRM needs to be posted */
     404             : #define P_SIGSUSPEND    0x00000008      /* Need to restore before-suspend mask*/
     405             : #define P_CANTSLEEP     0x00000010      /* insomniac thread */
     406             : #define P_SELECT        0x00000040      /* Selecting; wakeup/waiting danger. */
     407             : #define P_SINTR         0x00000080      /* Sleep is interruptible. */
     408             : #define P_SYSTEM        0x00000200      /* No sigs, stats or swapping. */
     409             : #define P_TIMEOUT       0x00000400      /* Timing out during sleep. */
     410             : #define P_WEXIT         0x00002000      /* Working on exiting. */
     411             : #define P_OWEUPC        0x00008000      /* Owe proc an addupc() at next ast. */
     412             : #define P_SUSPSINGLE    0x00080000      /* Need to stop for single threading. */
     413             : #define P_CONTINUED     0x00800000      /* Proc has continued from a stopped state. */
     414             : #define P_THREAD        0x04000000      /* Only a thread, not a real process */
     415             : #define P_SUSPSIG       0x08000000      /* Stopped from signal. */
     416             : #define P_SOFTDEP       0x10000000      /* Stuck processing softdep worklist */
     417             : #define P_CPUPEG        0x40000000      /* Do not move to another cpu. */
     418             : 
     419             : #define P_BITS \
     420             :     ("\20" "\01INKTR" "\02PROFPEND" "\03ALRMPEND" "\04SIGSUSPEND" \
     421             :      "\05CANTSLEEP" "\07SELECT" "\010SINTR" "\012SYSTEM" "\013TIMEOUT" \
     422             :      "\016WEXIT" "\020OWEUPC" "\024SUSPSINGLE" "\027XX" \
     423             :      "\030CONTINUED" "\033THREAD" "\034SUSPSIG" "\035SOFTDEP" "\037CPUPEG")
     424             : 
     425             : #define THREAD_PID_OFFSET       100000
     426             : 
     427             : #ifdef _KERNEL
     428             : 
     429             : struct unveil {
     430             :         struct vnode            *uv_vp;
     431             :         struct unvname_rbt      uv_names;
     432             :         struct rwlock           uv_lock;
     433             :         u_char                  uv_flags;
     434             : };
     435             : 
     436             : struct uidinfo {
     437             :         LIST_ENTRY(uidinfo) ui_hash;
     438             :         uid_t   ui_uid;
     439             :         long    ui_proccnt;     /* proc structs */
     440             :         long    ui_lockcnt;     /* lockf structs */
     441             : };
     442             : 
     443             : struct uidinfo *uid_find(uid_t);
     444             : void uid_release(struct uidinfo *);
     445             : 
     446             : /*
     447             :  * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
     448             :  * as it is used to represent "no process group".
     449             :  * We set PID_MAX to 99999 to keep it in 5 columns in ps
     450             :  * When exposed to userspace, thread IDs have THREAD_PID_OFFSET
     451             :  * added to keep them from overlapping the PID range.  For them,
     452             :  * we use a * a (0 .. 2^n] range for cheapness, picking 'n' such
     453             :  * that 2^n + THREAD_PID_OFFSET and THREAD_PID_OFFSET have
     454             :  * the same number of columns when printed.
     455             :  */
     456             : #define PID_MAX                 99999
     457             : #define TID_MASK                0x7ffff
     458             : 
     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             :                 timeout_del(&(s)->s_verauthto);                  \
     466             :                 pool_put(&session_pool, (s));                               \
     467             :         }                                                               \
     468             : } while (/* CONSTCOND */ 0)
     469             : 
     470             : /*
     471             :  * Flags to fork1().
     472             :  */
     473             : #define FORK_FORK       0x00000001
     474             : #define FORK_VFORK      0x00000002
     475             : #define FORK_IDLE       0x00000004
     476             : #define FORK_PPWAIT     0x00000008
     477             : #define FORK_SHAREFILES 0x00000010
     478             : #define FORK_SYSTEM     0x00000020
     479             : #define FORK_NOZOMBIE   0x00000040
     480             : #define FORK_SHAREVM    0x00000080
     481             : #define FORK_SIGHAND    0x00000200
     482             : #define FORK_PTRACE     0x00000400
     483             : 
     484             : #define EXIT_NORMAL             0x00000001
     485             : #define EXIT_THREAD             0x00000002
     486             : #define EXIT_THREAD_NOCHECK     0x00000003
     487             : 
     488             : #define TIDHASH(tid)    (&tidhashtbl[(tid) & tidhash])
     489             : extern LIST_HEAD(tidhashhead, proc) *tidhashtbl;
     490             : extern u_long tidhash;
     491             : 
     492             : #define PIDHASH(pid)    (&pidhashtbl[(pid) & pidhash])
     493             : extern LIST_HEAD(pidhashhead, process) *pidhashtbl;
     494             : extern u_long pidhash;
     495             : 
     496             : #define PGRPHASH(pgid)  (&pgrphashtbl[(pgid) & pgrphash])
     497             : extern LIST_HEAD(pgrphashhead, pgrp) *pgrphashtbl;
     498             : extern u_long pgrphash;
     499             : 
     500             : extern struct proc proc0;               /* Process slot for swapper. */
     501             : extern struct process process0;         /* Process slot for kernel threads. */
     502             : extern int nprocesses, maxprocess;      /* Cur and max number of processes. */
     503             : extern int nthreads, maxthread;         /* Cur and max number of threads. */
     504             : extern int randompid;                   /* fork() should create random pid's */
     505             : 
     506             : LIST_HEAD(proclist, proc);
     507             : LIST_HEAD(processlist, process);
     508             : extern struct processlist allprocess;   /* List of all processes. */
     509             : extern struct processlist zombprocess;  /* List of zombie processes. */
     510             : extern struct proclist allproc;         /* List of all threads. */
     511             : 
     512             : extern struct process *initprocess;     /* Process slot for init. */
     513             : extern struct proc *reaperproc;         /* Thread slot for reaper. */
     514             : extern struct proc *syncerproc;         /* filesystem syncer daemon */
     515             : 
     516             : extern struct pool process_pool;        /* memory pool for processes */
     517             : extern struct pool proc_pool;           /* memory pool for procs */
     518             : extern struct pool rusage_pool;         /* memory pool for zombies */
     519             : extern struct pool ucred_pool;          /* memory pool for ucreds */
     520             : extern struct pool session_pool;        /* memory pool for sessions */
     521             : extern struct pool pgrp_pool;           /* memory pool for pgrps */
     522             : 
     523             : void    freepid(pid_t);
     524             : 
     525             : struct process *prfind(pid_t);  /* Find process by id. */
     526             : struct process *zombiefind(pid_t); /* Find zombie process by id. */
     527             : struct proc *tfind(pid_t);      /* Find thread by id. */
     528             : struct pgrp *pgfind(pid_t);     /* Find process group by id. */
     529             : void    proc_printit(struct proc *p, const char *modif,
     530             :     int (*pr)(const char *, ...));
     531             : 
     532             : int     chgproccnt(uid_t uid, int diff);
     533             : void    enternewpgrp(struct process *, struct pgrp *, struct session *);
     534             : void    enterthispgrp(struct process *, struct pgrp *);
     535             : int     inferior(struct process *, struct process *);
     536             : void    leavepgrp(struct process *);
     537             : void    killjobc(struct process *);
     538             : void    preempt(void);
     539             : void    procinit(void);
     540             : void    resetpriority(struct proc *);
     541             : void    setrunnable(struct proc *);
     542             : void    endtsleep(void *);
     543             : void    unsleep(struct proc *);
     544             : void    reaper(void *);
     545             : void    exit1(struct proc *, int, int);
     546             : void    exit2(struct proc *);
     547             : int     dowait4(struct proc *, pid_t, int *, int, struct rusage *,
     548             :             register_t *);
     549             : void    cpu_fork(struct proc *_curp, struct proc *_child, void *_stack,
     550             :             void *_tcb, void (*_func)(void *), void *_arg);
     551             : void    cpu_exit(struct proc *);
     552             : void    process_initialize(struct process *, struct proc *);
     553             : int     fork1(struct proc *_curp, int _flags, void (*_func)(void *),
     554             :             void *_arg, register_t *_retval, struct proc **_newprocp);
     555             : int     thread_fork(struct proc *_curp, void *_stack, void *_tcb,
     556             :             pid_t *_tidptr, register_t *_retval);
     557             : int     groupmember(gid_t, struct ucred *);
     558             : void    dorefreshcreds(struct process *, struct proc *);
     559             : void    dosigsuspend(struct proc *, sigset_t);
     560             : 
     561             : static inline void
     562           0 : refreshcreds(struct proc *p)
     563             : {
     564           0 :         struct process *pr = p->p_p;
     565             : 
     566             :         /* this is an unlocked access to ps_ucred, but the result is benign */
     567           0 :         if (pr->ps_ucred != p->p_ucred)
     568           0 :                 dorefreshcreds(pr, p);
     569           0 : }
     570             : 
     571             : enum single_thread_mode {
     572             :         SINGLE_SUSPEND,         /* other threads to stop wherever they are */
     573             :         SINGLE_PTRACE,          /* other threads to stop but don't wait */
     574             :         SINGLE_UNWIND,          /* other threads to unwind and stop */
     575             :         SINGLE_EXIT             /* other threads to unwind and then exit */
     576             : };
     577             : int     single_thread_set(struct proc *, enum single_thread_mode, int);
     578             : void    single_thread_wait(struct process *);
     579             : void    single_thread_clear(struct proc *, int);
     580             : int     single_thread_check(struct proc *, int);
     581             : 
     582             : void    child_return(void *);
     583             : 
     584             : int     proc_cansugid(struct proc *);
     585             : 
     586             : struct sleep_state {
     587             :         int sls_s;
     588             :         int sls_catch;
     589             :         int sls_do_sleep;
     590             :         int sls_sig;
     591             : };
     592             : 
     593             : struct cond {
     594             :         int     c_wait;
     595             : };
     596             : 
     597             : #define COND_INITIALIZER()              { 1 }
     598             : 
     599             : #if defined(MULTIPROCESSOR)
     600             : void    proc_trampoline_mp(void);       /* XXX */
     601             : #endif
     602             : 
     603             : /*
     604             :  * functions to handle sets of cpus.
     605             :  *
     606             :  * For now we keep the cpus in ints so that we can use the generic
     607             :  * atomic ops.
     608             :  */
     609             : #define CPUSET_ASIZE(x) (((x) - 1)/32 + 1)
     610             : #define CPUSET_SSIZE CPUSET_ASIZE(MAXCPUS)
     611             : struct cpuset {
     612             :         int cs_set[CPUSET_SSIZE];
     613             : };
     614             : 
     615             : void cpuset_init_cpu(struct cpu_info *);
     616             : 
     617             : void cpuset_clear(struct cpuset *);
     618             : void cpuset_add(struct cpuset *, struct cpu_info *);
     619             : void cpuset_del(struct cpuset *, struct cpu_info *);
     620             : int cpuset_isset(struct cpuset *, struct cpu_info *);
     621             : void cpuset_add_all(struct cpuset *);
     622             : void cpuset_copy(struct cpuset *, struct cpuset *);
     623             : void cpuset_union(struct cpuset *, struct cpuset *, struct cpuset *);
     624             : void cpuset_intersection(struct cpuset *t, struct cpuset *, struct cpuset *);
     625             : void cpuset_complement(struct cpuset *, struct cpuset *, struct cpuset *);
     626             : int cpuset_cardinality(struct cpuset *);
     627             : struct cpu_info *cpuset_first(struct cpuset *);
     628             : 
     629             : #endif  /* _KERNEL */
     630             : #endif  /* !_SYS_PROC_H_ */
     631             : 

Generated by: LCOV version 1.13