The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/proc.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: a888c5e470995b67cd97904f6d7c3f6f


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.