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 /*-
    2  * Copyright (c) 1986, 1989, 1991, 1993
    3  *      The Regents of the University of California.  All rights reserved.
    4  * (c) UNIX System Laboratories, Inc.
    5  * All or some portions of this file are derived from material licensed
    6  * to the University of California by American Telephone and Telegraph
    7  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
    8  * the permission of UNIX System Laboratories, Inc.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  * 3. All advertising materials mentioning features or use of this software
   19  *    must display the following acknowledgement:
   20  *      This product includes software developed by the University of
   21  *      California, Berkeley and its contributors.
   22  * 4. Neither the name of the University nor the names of its contributors
   23  *    may be used to endorse or promote products derived from this software
   24  *    without specific prior written permission.
   25  *
   26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   36  * SUCH DAMAGE.
   37  *
   38  *      @(#)proc.h      8.15 (Berkeley) 5/19/95
   39  * $FreeBSD: releng/5.0/sys/sys/proc.h 107719 2002-12-10 02:33:45Z julian $
   40  */
   41 
   42 #ifndef _SYS_PROC_H_
   43 #define _SYS_PROC_H_
   44 
   45 #include <sys/callout.h>                /* For struct callout. */
   46 #include <sys/event.h>                  /* For struct klist. */
   47 #include <sys/filedesc.h>
   48 #include <sys/queue.h>
   49 #include <sys/priority.h>
   50 #include <sys/rtprio.h>                 /* XXX */
   51 #include <sys/runq.h>
   52 #include <sys/signal.h>
   53 #include <sys/_label.h>
   54 #ifndef _KERNEL
   55 #include <sys/time.h>                   /* For structs itimerval, timeval. */
   56 #else
   57 #include <sys/pcpu.h>
   58 #endif
   59 #include <sys/ucontext.h>
   60 #include <sys/ucred.h>
   61 #include <machine/proc.h>               /* Machine-dependent proc substruct. */
   62 
   63 /*
   64  * One structure allocated per session.
   65  *
   66  * List of locks
   67  * (m)          locked by s_mtx mtx
   68  * (e)          locked by proctree_lock sx
   69  * (c)          const until freeing
   70  */
   71 struct session {
   72         int             s_count;        /* (m) Ref cnt; pgrps in session. */
   73         struct  proc    *s_leader;      /* (m + e) Session leader. */
   74         struct  vnode   *s_ttyvp;       /* (m) Vnode of controlling tty. */
   75         struct  tty     *s_ttyp;        /* (m) Controlling tty. */
   76         pid_t           s_sid;          /* (c) Session ID. */
   77                                         /* (m) Setlogin() name: */
   78         char            s_login[roundup(MAXLOGNAME, sizeof(long))];
   79         struct  mtx     s_mtx;          /* Mutex to protect members */
   80 };
   81 
   82 /*
   83  * One structure allocated per process group.
   84  *
   85  * List of locks
   86  * (m)          locked by pg_mtx mtx
   87  * (e)          locked by proctree_lock sx
   88  * (c)          const until freeing
   89  */
   90 struct pgrp {
   91         LIST_ENTRY(pgrp) pg_hash;       /* (e) Hash chain. */
   92         LIST_HEAD(, proc) pg_members;   /* (m + e) Pointer to pgrp members. */
   93         struct session  *pg_session;    /* (c) Pointer to session. */
   94         struct sigiolst pg_sigiolst;    /* (m) List of sigio sources. */
   95         pid_t           pg_id;          /* (c) Pgrp id. */
   96         int             pg_jobc;        /* (m) job cntl proc count */
   97         struct  mtx     pg_mtx;         /*  Mutex to protect members */
   98 };
   99 
  100 struct procsig {
  101         sigset_t ps_sigignore;          /* Signals being ignored. */
  102         sigset_t ps_sigcatch;           /* Signals being caught by user. */
  103         int      ps_flag;
  104         struct   sigacts *ps_sigacts;   /* Signal actions, state. */
  105         int      ps_refcnt;
  106 };
  107 
  108 #define PS_NOCLDWAIT    0x0001  /* No zombies if child dies */
  109 #define PS_NOCLDSTOP    0x0002  /* No SIGCHLD when children stop. */
  110 #define PS_CLDSIGIGN    0x0004  /* The SIGCHLD handler is SIG_IGN. */
  111 
  112 /*
  113  * pargs, used to hold a copy of the command line, if it had a sane length.
  114  */
  115 struct pargs {
  116         u_int   ar_ref;         /* Reference count. */
  117         u_int   ar_length;      /* Length. */
  118         u_char  ar_args[1];     /* Arguments. */
  119 };
  120 
  121 /*-
  122  * Description of a process.
  123  *
  124  * This structure contains the information needed to manage a thread of
  125  * control, known in UN*X as a process; it has references to substructures
  126  * containing descriptions of things that the process uses, but may share
  127  * with related processes.  The process structure and the substructures
  128  * are always addressable except for those marked "(CPU)" below,
  129  * which might be addressable only on a processor on which the process
  130  * is running.
  131  *
  132  * Below is a key of locks used to protect each member of struct proc.  The
  133  * lock is indicated by a reference to a specific character in parens in the
  134  * associated comment.
  135  *      * - not yet protected
  136  *      a - only touched by curproc or parent during fork/wait
  137  *      b - created at fork, never changes
  138  *              (exception aiods switch vmspaces, but they are also
  139  *              marked 'P_SYSTEM' so hopefully it will be left alone)
  140  *      c - locked by proc mtx
  141  *      d - locked by allproc_lock lock
  142  *      e - locked by proctree_lock lock
  143  *      f - session mtx
  144  *      g - process group mtx
  145  *      h - callout_lock mtx
  146  *      i - by curproc or the master session mtx
  147  *      j - locked by sched_lock mtx
  148  *      k - only accessed by curthread
  149  *      l - the attaching proc or attaching proc parent
  150  *      m - Giant
  151  *      n - not locked, lazy
  152  *      o - ktrace lock
  153  *      p - select lock (sellock)
  154  *      r - p_peers lock
  155  *
  156  * If the locking key specifies two identifiers (for example, p_pptr) then
  157  * either lock is sufficient for read access, but both locks must be held
  158  * for write access.
  159  */
  160 struct ithd;
  161 struct ke_sched;
  162 struct kg_sched;
  163 struct nlminfo;
  164 struct p_sched;
  165 struct td_sched;
  166 struct trapframe;
  167 
  168 /*
  169  * Here we define the four structures used for process information.
  170  *
  171  * The first is the thread. It might be though of as a "Kernel
  172  * Schedulable Entity Context".
  173  * This structure contains all the information as to where a thread of 
  174  * execution is now, or was when it was suspended, why it was suspended,
  175  * and anything else that will be needed to restart it when it is
  176  * rescheduled. Always associated with a KSE when running, but can be
  177  * reassigned to an equivalent KSE  when being restarted for
  178  * load balancing. Each of these is associated with a kernel stack
  179  * and a pcb.
  180  * 
  181  * It is important to remember that a particular thread structure only
  182  * exists as long as the system call or kernel entrance (e.g. by pagefault)
  183  * which it is currently executing. It should threfore NEVER be referenced
  184  * by pointers in long lived structures that live longer than a single
  185  * request. If several threads complete their work at the same time,
  186  * they will all rewind their stacks to the user boundary, report their
  187  * completion state, and all but one will be freed. That last one will
  188  * be kept to provide a kernel stack and pcb for the NEXT syscall or kernel
  189  * entrance. (basically to save freeing and then re-allocating it) The KSE
  190  * keeps a cached thread available to allow it to quickly
  191  * get one when it needs a new one. There is also a system
  192  * cache of free threads. Threads have priority and partake in priority
  193  * inherritance schemes.
  194  */
  195 struct thread;
  196 
  197 /* 
  198  * The second structure is the Kernel Schedulable Entity. (KSE)
  199  * It represents the ability to take a slot in the scheduler queue.
  200  * As long as this is scheduled, it could continue to run any threads that
  201  * are assigned to the KSEGRP (see later) until either it runs out
  202  * of runnable threads of high enough priority, or CPU.
  203  * It runs on one CPU and is assigned a quantum of time. When a thread is
  204  * blocked, The KSE continues to run and will search for another thread
  205  * in a runnable state amongst those it has. It May decide to return to user
  206  * mode with a new 'empty' thread if there are no runnable threads.
  207  * Threads are temporarily associated with a KSE for scheduling reasons.
  208  */
  209 struct kse;
  210 
  211 /*
  212  * The KSEGRP is allocated resources across a number of CPUs.
  213  * (Including a number of CPUxQUANTA. It parcels these QUANTA up among
  214  * Its KSEs, each of which should be running in a different CPU.
  215  * BASE priority and total available quanta are properties of a KSEGRP.
  216  * Multiple KSEGRPs in a single process compete against each other
  217  * for total quanta in the same way that a forked child competes against
  218  * it's parent process.
  219  */
  220 struct ksegrp;
  221 
  222 /*
  223  * A process is the owner of all system resources allocated to a task
  224  * except CPU quanta.
  225  * All KSEGs under one process see, and have the same access to, these
  226  * resources (e.g. files, memory, sockets, permissions kqueues).
  227  * A process may compete for CPU cycles on the same basis as a
  228  * forked process cluster by spawning several KSEGRPs. 
  229  */
  230 struct proc;
  231 
  232 /***************
  233  * In pictures:
  234  With a single run queue used by all processors:
  235 
  236  RUNQ: --->KSE---KSE--...               SLEEPQ:[]---THREAD---THREAD---THREAD
  237            |   /                               []---THREAD
  238            KSEG---THREAD--THREAD--THREAD       []
  239                                                []---THREAD---THREAD
  240 
  241   (processors run THREADs from the KSEG until they are exhausted or
  242   the KSEG exhausts its quantum) 
  243 
  244 With PER-CPU run queues:
  245 KSEs on the separate run queues directly
  246 They would be given priorities calculated from the KSEG.
  247 
  248  *
  249  *****************/
  250 
  251 /*
  252  * Kernel runnable context (thread).
  253  * This is what is put to sleep and reactivated.
  254  * The first KSE available in the correct group will run this thread.
  255  * If several are available, use the one on the same CPU as last time.
  256  * When waing to be run, threads are hung off the KSEGRP in priority order.
  257  * with N runnable and queued KSEs in the KSEGRP, the first N threads
  258  * are linked to them. Other threads are not yet assigned.
  259  */
  260 struct thread {
  261         struct proc     *td_proc;       /* Associated process. */
  262         struct ksegrp   *td_ksegrp;     /* Associated KSEG. */
  263         TAILQ_ENTRY(thread) td_plist;   /* All threads in this proc */
  264         TAILQ_ENTRY(thread) td_kglist;  /* All threads in this ksegrp */
  265 
  266         /* The two queues below should someday be merged */
  267         TAILQ_ENTRY(thread) td_slpq;    /* (j) Sleep queue. XXXKSE */ 
  268         TAILQ_ENTRY(thread) td_lockq;   /* (j) Lock queue. XXXKSE */ 
  269         TAILQ_ENTRY(thread) td_runq;    /* (j) Run queue(s). XXXKSE */ 
  270 
  271         TAILQ_HEAD(, selinfo) td_selq;  /* (p) List of selinfos. */
  272 
  273 /* Cleared during fork1() or thread_sched_upcall() */
  274 #define td_startzero td_flags
  275         int             td_flags;       /* (j) TDF_* flags. */
  276         int             td_inhibitors;  /* (j) Why can not run */
  277         struct kse      *td_last_kse;   /* (j) Previous value of td_kse */
  278         struct kse      *td_kse;        /* (j) Current KSE if running. */
  279         int             td_dupfd;       /* (k) Ret value from fdopen. XXX */
  280         void            *td_wchan;      /* (j) Sleep address. */
  281         const char      *td_wmesg;      /* (j) Reason for sleep. */
  282         u_char          td_lastcpu;     /* (j) Last cpu we were on. */
  283         u_char          td_inktr;       /* (k) Currently handling a KTR. */
  284         u_char          td_inktrace;    /* (k) Currently handling a KTRACE. */
  285         short           td_locks;       /* (k) DEBUG: lockmgr count of locks */
  286         struct mtx      *td_blocked;    /* (j) Mutex process is blocked on. */
  287         struct ithd     *td_ithd;       /* (b) For interrupt threads only. */
  288         const char      *td_lockname;   /* (j) Name of lock blocked on. */
  289         LIST_HEAD(, mtx) td_contested;  /* (j) Contested locks. */
  290         struct lock_list_entry *td_sleeplocks; /* (k) Held sleep locks. */
  291         int             td_intr_nesting_level; /* (k) Interrupt recursion. */
  292         struct kse_thr_mailbox *td_mailbox; /* the userland mailbox address */
  293         struct ucred    *td_ucred;      /* (k) Reference to credentials. */
  294         void            (*td_switchin)(void); /* (k) Switchin special func. */
  295         struct thread   *td_standin;    /* (?) use this for an upcall */
  296         u_int           td_usticks;     /* Statclock hits in kernel, for UTS */
  297         u_int           td_critnest;    /* (k) Critical section nest level. */
  298 #define td_endzero td_base_pri
  299 
  300 /* Copied during fork1() or thread_sched_upcall() */
  301 #define td_startcopy td_endzero
  302         u_char          td_base_pri;    /* (j) Thread base kernel priority. */
  303         u_char          td_priority;    /* (j) Thread active priority. */
  304 #define td_endcopy td_pcb
  305 
  306 /*
  307  * fields that must be manually set in fork1() or thread_sched_upcall()
  308  * or already have been set in the allocator, contstructor, etc..
  309  */
  310         struct pcb      *td_pcb;        /* (k) Kernel VA of pcb and kstack. */
  311         enum {
  312                 TDS_INACTIVE = 0x20,
  313                 TDS_INHIBITED,
  314                 TDS_CAN_RUN,
  315                 TDS_RUNQ,
  316                 TDS_RUNNING
  317         } td_state;
  318         register_t      td_retval[2];   /* (k) Syscall aux returns. */
  319         struct callout  td_slpcallout;  /* (h) Callout for sleep. */
  320         struct trapframe *td_frame;     /* (k) */
  321         struct vm_object *td_kstack_obj;/* (a) Kstack object. */
  322         vm_offset_t     td_kstack;      /* Kernel VA of kstack. */
  323         int             td_kstack_pages; /* Size of the kstack */
  324         struct vm_object *td_altkstack_obj;/* (a) Alternate kstack object. */
  325         vm_offset_t     td_altkstack;   /* Kernel VA of alternate kstack. */
  326         int             td_altkstack_pages; /* Size of the alternate kstack */
  327         struct mdthread td_md;          /* (k) Any machine-dependent fields. */
  328         struct td_sched *td_sched;      /* Scheduler specific data */
  329 };
  330 /* flags kept in td_flags */ 
  331 #define TDF_UNBOUND     0x000001 /* May give away the kse, uses the kg runq. */
  332 #define TDF_INPANIC     0x000002 /* Caused a panic, let it drive crashdump. */
  333 #define TDF_SINTR       0x000008 /* Sleep is interruptible. */
  334 #define TDF_TIMEOUT     0x000010 /* Timing out during sleep. */
  335 #define TDF_SELECT      0x000040 /* Selecting; wakeup/waiting danger. */
  336 #define TDF_CVWAITQ     0x000080 /* Thread is on a cv_waitq (not slpq). */
  337 #define TDF_UPCALLING   0x000100 /* This thread is doing an upcall. */
  338 #define TDF_ONSLEEPQ    0x000200 /* On the sleep queue. */
  339 #define TDF_INMSLEEP    0x000400 /* Don't recurse in msleep(). */
  340 #define TDF_TIMOFAIL    0x001000 /* Timeout from sleep after we were awake. */
  341 #define TDF_INTERRUPT   0x002000 /* Thread is marked as interrupted. */
  342 #define TDF_DEADLKTREAT 0x800000 /* Lock aquisition - deadlock treatment. */
  343 
  344 #define TDI_SUSPENDED   0x01    /* On suspension queue. */
  345 #define TDI_SLEEPING    0x02    /* Actually asleep! (tricky). */
  346 #define TDI_SWAPPED     0x04    /* Stack not in mem.. bad juju if run. */
  347 #define TDI_LOCK        0x08    /* Stopped on a lock. */
  348 #define TDI_IWAIT       0x10    /* Awaiting interrupt. */
  349 #define TDI_LOAN        0x20    /* bound thread's KSE is lent */
  350 
  351 #define TD_IS_SLEEPING(td)      ((td)->td_inhibitors & TDI_SLEEPING)
  352 #define TD_ON_SLEEPQ(td)        ((td)->td_wchan != NULL)
  353 #define TD_IS_SUSPENDED(td)     ((td)->td_inhibitors & TDI_SUSPENDED)
  354 #define TD_IS_SWAPPED(td)       ((td)->td_inhibitors & TDI_SWAPPED)
  355 #define TD_ON_LOCK(td)          ((td)->td_inhibitors & TDI_LOCK)
  356 #define TD_LENT(td)             ((td)->td_inhibitors & TDI_LOAN)
  357 #define TD_AWAITING_INTR(td)    ((td)->td_inhibitors & TDI_IWAIT)
  358 #define TD_IS_RUNNING(td)       ((td)->td_state == TDS_RUNNING)
  359 #define TD_ON_RUNQ(td)          ((td)->td_state == TDS_RUNQ)
  360 #define TD_CAN_RUN(td)          ((td)->td_state == TDS_CAN_RUN)
  361 #define TD_IS_INHIBITED(td)     ((td)->td_state == TDS_INHIBITED)
  362 
  363 #define TD_SET_INHIB(td, inhib) do {                    \
  364         (td)->td_state = TDS_INHIBITED;                 \
  365         (td)->td_inhibitors |= inhib;                   \
  366 } while (0)
  367 
  368 #define TD_CLR_INHIB(td, inhib) do {                    \
  369         if (((td)->td_inhibitors & inhib) &&            \
  370             (((td)->td_inhibitors &= ~inhib) == 0))     \
  371                 (td)->td_state = TDS_CAN_RUN;           \
  372 } while (0)
  373 
  374 #define TD_SET_SLEEPING(td)     TD_SET_INHIB((td), TDI_SLEEPING)
  375 #define TD_SET_SWAPPED(td)      TD_SET_INHIB((td), TDI_SWAPPED)
  376 #define TD_SET_LOCK(td)         TD_SET_INHIB((td), TDI_LOCK)
  377 #define TD_SET_SUSPENDED(td)    TD_SET_INHIB((td), TDI_SUSPENDED)
  378 #define TD_SET_IWAIT(td)        TD_SET_INHIB((td), TDI_IWAIT)
  379 #define TD_SET_LOAN(td)         TD_SET_INHIB((td), TDI_LOAN)
  380 
  381 #define TD_CLR_SLEEPING(td)     TD_CLR_INHIB((td), TDI_SLEEPING)
  382 #define TD_CLR_SWAPPED(td)      TD_CLR_INHIB((td), TDI_SWAPPED)
  383 #define TD_CLR_LOCK(td)         TD_CLR_INHIB((td), TDI_LOCK)
  384 #define TD_CLR_SUSPENDED(td)    TD_CLR_INHIB((td), TDI_SUSPENDED)
  385 #define TD_CLR_IWAIT(td)        TD_CLR_INHIB((td), TDI_IWAIT)
  386 #define TD_CLR_LOAN(td)         TD_CLR_INHIB((td), TDI_LOAN)
  387 
  388 #define TD_SET_RUNNING(td)      do {(td)->td_state = TDS_RUNNING; } while (0)
  389 #define TD_SET_RUNQ(td)         do {(td)->td_state = TDS_RUNQ; } while (0)
  390 #define TD_SET_CAN_RUN(td)      do {(td)->td_state = TDS_CAN_RUN; } while (0)
  391 #define TD_SET_ON_SLEEPQ(td)    do {(td)->td_flags |= TDF_ONSLEEPQ; } while (0)
  392 #define TD_CLR_ON_SLEEPQ(td)    do {                    \
  393                 (td)->td_flags &= ~TDF_ONSLEEPQ;        \
  394                 (td)->td_wchan = NULL;                  \
  395 } while (0)
  396 
  397 
  398 /*
  399  * Traps for young players:
  400  * The main thread variable that controls whether a thread acts as a threaded
  401  * or unthreaded thread is the td_bound counter (0 == unbound).
  402  * UPCALLS run with the UNBOUND flags clear, after they are first scheduled.
  403  * i.e. they bind themselves to whatever thread thay are first scheduled with.
  404  * You may see BOUND threads in KSE processes but you should never see
  405  * UNBOUND threads in non KSE processes.
  406  */
  407 
  408 /*
  409  * The schedulable entity that can be given a context to run.
  410  * A process may have several of these. Probably one per processor
  411  * but posibly a few more. In this universe they are grouped
  412  * with a KSEG that contains the priority and niceness
  413  * for the group.
  414  */
  415 struct kse {
  416         struct proc     *ke_proc;       /* Associated process. */
  417         struct ksegrp   *ke_ksegrp;     /* Associated KSEG. */
  418         TAILQ_ENTRY(kse) ke_kglist;     /* Queue of all KSEs in ke_ksegrp. */
  419         TAILQ_ENTRY(kse) ke_kgrlist;    /* Queue of all KSEs in this state. */
  420         TAILQ_ENTRY(kse) ke_procq;      /* (j) Run queue. */
  421 
  422 #define ke_startzero ke_flags
  423         int             ke_flags;       /* (j) KEF_* flags. */
  424         struct thread   *ke_thread;     /* Active associated thread. */
  425         struct thread   *ke_bound;      /* Thread bound to this KSE (*) */
  426         int             ke_cpticks;     /* (j) Ticks of cpu time. */
  427         fixpt_t         ke_pctcpu;      /* (j) %cpu during p_swtime. */
  428         u_int64_t       ke_uu;          /* (j) Previous user time in usec. */
  429         u_int64_t       ke_su;          /* (j) Previous system time in usec. */
  430         u_int64_t       ke_iu;          /* (j) Previous intr time in usec. */
  431         u_int64_t       ke_uticks;      /* (j) Statclock hits in user mode. */
  432         u_int64_t       ke_sticks;      /* (j) Statclock hits in system mode. */
  433         u_int64_t       ke_iticks;      /* (j) Statclock hits in intr. */
  434         u_int           ke_uuticks;     /* Statclock hits in user, for UTS */
  435         u_int           ke_usticks;     /* Statclock hits in kernel, for UTS */
  436         u_char          ke_oncpu;       /* (j) Which cpu we are on. */
  437         char            ke_rqindex;     /* (j) Run queue index. */
  438         enum {
  439                 KES_IDLE = 0x10,
  440                 KES_ONRUNQ,
  441                 KES_UNQUEUED,           /* in transit */
  442                 KES_THREAD              /* slaved to thread state */
  443         } ke_state;                     /* (j) S* process status. */
  444         struct kse_mailbox *ke_mailbox; /* the userland mailbox address */
  445         stack_t         ke_stack;
  446         void            *ke_upcall;
  447         struct thread   *ke_tdspare;    /* spare thread for upcalls */
  448 #define ke_endzero ke_dummy
  449         u_char          ke_dummy;
  450         struct ke_sched *ke_sched;      /* Scheduler specific data */
  451 };
  452 
  453 /* flags kept in ke_flags */
  454 #define KEF_OWEUPC      0x00002 /* Owe process an addupc() call at next ast. */
  455 #define KEF_IDLEKSE     0x00004 /* A 'Per CPU idle process'.. has one thread */
  456 #define KEF_LOANED      0x00008 /* On loan from the bound thread to another */
  457 #define KEF_USER        0x00200 /* Process is not officially in the kernel */
  458 #define KEF_ASTPENDING  0x00400 /* KSE has a pending ast. */
  459 #define KEF_NEEDRESCHED 0x00800 /* Process needs to yield. */
  460 #define KEF_ONLOANQ     0x01000 /* KSE is on loan queue. */
  461 #define KEF_DIDRUN      0x02000 /* KSE actually ran. */
  462 #define KEF_EXIT        0x04000 /* KSE is being killed. */
  463 
  464 /*
  465  * (*) A bound KSE with a bound thread in a KSE process may be lent to
  466  * Other threads, as long as those threads do not leave the kernel. 
  467  * The other threads must be either exiting, or be unbound with a valid
  468  * mailbox so that they can save their state there rather than going
  469  * to user space. While this happens the real bound thread is still linked
  470  * to the kse via the ke_bound field, and the KSE has its "KEF_LOANED
  471  * flag set.
  472  */
  473 
  474 /*
  475  * Kernel-scheduled entity group (KSEG).  The scheduler considers each KSEG to
  476  * be an indivisible unit from a time-sharing perspective, though each KSEG may
  477  * contain multiple KSEs.
  478  */
  479 struct ksegrp {
  480         struct proc     *kg_proc;       /* Process that contains this KSEG. */
  481         TAILQ_ENTRY(ksegrp) kg_ksegrp;  /* Queue of KSEGs in kg_proc. */
  482         TAILQ_HEAD(, kse) kg_kseq;      /* (ke_kglist) All KSEs. */
  483         TAILQ_HEAD(, kse) kg_iq;        /* (ke_kgrlist) Idle KSEs. */
  484         TAILQ_HEAD(, kse) kg_lq;        /* (ke_kgrlist) Loan KSEs. */
  485         TAILQ_HEAD(, thread) kg_threads;/* (td_kglist) All threads. */
  486         TAILQ_HEAD(, thread) kg_runq;   /* (td_runq) waiting RUNNABLE threads */
  487         TAILQ_HEAD(, thread) kg_slpq;   /* (td_runq) NONRUNNABLE threads. */
  488 
  489 #define kg_startzero kg_estcpu
  490         u_int           kg_estcpu;      /* Sum of the same field in KSEs. */
  491         u_int           kg_slptime;     /* (j) How long completely blocked. */
  492         struct thread   *kg_last_assigned; /* Last thread assigned to a KSE */
  493         int             kg_runnable;    /* Num runnable threads on queue. */
  494         int             kg_runq_kses;   /* Num KSEs on runq. */
  495         int             kg_loan_kses;   /* Num KSEs on loan queue. */
  496         struct kse_thr_mailbox *kg_completed; /* (c) completed thread mboxes */
  497 #define kg_endzero kg_pri_class
  498 
  499 #define kg_startcopy    kg_endzero
  500         u_char          kg_pri_class;   /* (j) Scheduling class. */
  501         u_char          kg_user_pri;    /* (j) User pri from estcpu and nice. */
  502         char            kg_nice;        /* (j?/k?) Process "nice" value. */
  503 #define kg_endcopy kg_numthreads
  504         int             kg_numthreads;  /* Num threads in total */
  505         int             kg_idle_kses;   /* num KSEs idle */
  506         int             kg_kses;        /* Num KSEs in group. */
  507         struct kg_sched *kg_sched;      /* Scheduler specific data */
  508 };
  509 
  510 /*
  511  * The old fashionned process. May have multiple threads, KSEGRPs
  512  * and KSEs. Starts off with a single embedded KSEGRP, KSE and THREAD.
  513  */
  514 struct proc {
  515         LIST_ENTRY(proc) p_list;        /* (d) List of all processes. */
  516         TAILQ_HEAD(, ksegrp) p_ksegrps; /* (kg_ksegrp) All KSEGs. */
  517         TAILQ_HEAD(, thread) p_threads; /* (td_plist) Threads. (shortcut) */
  518         TAILQ_HEAD(, thread) p_suspended; /* (td_runq) suspended threads */
  519         struct ucred    *p_ucred;       /* (c) Process owner's identity. */
  520         struct filedesc *p_fd;          /* (b) Ptr to open files structure. */
  521                                         /* Accumulated stats for all KSEs? */
  522         struct pstats   *p_stats;       /* (b) Accounting/statistics (CPU). */
  523         struct plimit   *p_limit;       /* (m) Process limits. */
  524         struct vm_object *p_upages_obj; /* (a) Upages object. */
  525         struct procsig  *p_procsig;     /* (c) Signal actions, state (CPU). */
  526 
  527         /*struct ksegrp p_ksegrp;
  528         struct kse      p_kse; */
  529 
  530         /*
  531          * The following don't make too much sense..
  532          * See the td_ or ke_ versions of the same flags
  533          */
  534         int             p_flag;         /* (c) P_* flags. */
  535         int             p_sflag;        /* (j) PS_* flags. */
  536         enum {
  537                 PRS_NEW = 0,            /* In creation */
  538                 PRS_NORMAL,             /* KSEs can be run */
  539                 PRS_ZOMBIE
  540         } p_state;                      /* (j) S* process status. */
  541         pid_t           p_pid;          /* (b) Process identifier. */
  542         LIST_ENTRY(proc) p_hash;        /* (d) Hash chain. */
  543         LIST_ENTRY(proc) p_pglist;      /* (g + e) List of processes in pgrp. */
  544         struct proc     *p_pptr;        /* (c + e) Pointer to parent process. */
  545         LIST_ENTRY(proc) p_sibling;     /* (e) List of sibling processes. */
  546         LIST_HEAD(, proc) p_children;   /* (e) Pointer to list of children. */
  547         struct mtx      p_mtx;          /* (k) Lock for this struct. */
  548 
  549 /* The following fields are all zeroed upon creation in fork. */
  550 #define p_startzero     p_oppid
  551         pid_t           p_oppid;        /* (c + e) Save ppid in ptrace. XXX */
  552         struct vmspace  *p_vmspace;     /* (b) Address space. */
  553         u_int           p_swtime;       /* (j) Time swapped in or out. */
  554         struct itimerval p_realtimer;   /* (h?/k?) Alarm timer. */
  555         struct bintime  p_runtime;      /* (j) Real time. */
  556         int             p_traceflag;    /* (o) Kernel trace points. */
  557         struct vnode    *p_tracep;      /* (c + o) Trace to vnode. */
  558         sigset_t        p_siglist;      /* (c) Sigs arrived, not delivered. */
  559         struct vnode    *p_textvp;      /* (b) Vnode of executable. */
  560         char            p_lock;         /* (c) Proclock (prevent swap) count. */
  561         struct klist p_klist;           /* (c) Knotes attached to this proc. */
  562         struct sigiolst p_sigiolst;     /* (c) List of sigio sources. */
  563         int             p_sigparent;    /* (c) Signal to parent on exit. */
  564         sigset_t        p_oldsigmask;   /* (c) Saved mask from pre sigpause. */
  565         int             p_sig;          /* (n) For core dump/debugger XXX. */
  566         u_long          p_code;         /* (n) For core dump/debugger XXX. */
  567         u_int           p_stops;        /* (c) Stop event bitmask. */
  568         u_int           p_stype;        /* (c) Stop event type. */
  569         char            p_step;         /* (c) Process is stopped. */
  570         u_char          p_pfsflags;     /* (c) Procfs flags. */
  571         struct nlminfo  *p_nlminfo;     /* (?) Only used by/for lockd. */
  572         void            *p_aioinfo;     /* (c) ASYNC I/O info. */
  573         struct thread   *p_singlethread;/* (j) If single threading this is it */
  574         int             p_suspcount;    /* (j) # threads in suspended mode */
  575         int             p_userthreads;  /* (j) # threads in userland */
  576 /* End area that is zeroed on creation. */
  577 #define p_endzero       p_sigmask
  578 
  579 /* The following fields are all copied upon creation in fork. */
  580 #define p_startcopy     p_endzero
  581         sigset_t        p_sigmask;      /* (c) Current signal mask. */
  582         stack_t         p_sigstk;       /* (c) Stack ptr and on-stack flag. */
  583         u_int           p_magic;        /* (b) Magic number. */
  584         char            p_comm[MAXCOMLEN + 1];  /* (b) Process name. */
  585         struct pgrp     *p_pgrp;        /* (c + e) Pointer to process group. */
  586         struct sysentvec *p_sysent;     /* (b) Syscall dispatch info. */
  587         struct pargs    *p_args;        /* (c) Process arguments. */
  588         rlim_t          p_cpulimit;     /* (j) Current CPU limit in seconds. */
  589 /* End area that is copied on creation. */
  590 #define p_endcopy       p_xstat
  591 
  592         u_short         p_xstat;        /* (c) Exit status; also stop sig. */
  593         int             p_numthreads;   /* (?) number of threads */
  594         int             p_numksegrps;   /* (?) number of ksegrps */
  595         struct mdproc   p_md;           /* (c) Any machine-dependent fields. */
  596         struct callout  p_itcallout;    /* (h) Interval timer callout. */
  597         struct user     *p_uarea;       /* (k) Kernel VA of u-area (CPU) */
  598         u_short         p_acflag;       /* (c) Accounting flags. */
  599         struct rusage   *p_ru;          /* (a) Exit information. XXX */
  600         struct proc     *p_peers;       /* (r) */
  601         struct proc     *p_leader;      /* (b) */
  602         void            *p_emuldata;    /* (c) Emulator state data. */
  603         struct label    p_label;        /* process (not subject) MAC label */
  604         struct p_sched  *p_sched;       /* Scheduler specific data */
  605 };
  606 
  607 #define p_rlimit        p_limit->pl_rlimit
  608 #define p_sigacts       p_procsig->ps_sigacts
  609 #define p_sigignore     p_procsig->ps_sigignore
  610 #define p_sigcatch      p_procsig->ps_sigcatch
  611 #define p_session       p_pgrp->pg_session
  612 #define p_pgid          p_pgrp->pg_id
  613 
  614 #define NOCPU   0xff            /* For when we aren't on a CPU. (SMP) */
  615 
  616 /* Status values (p_stat). */
  617 
  618 /* These flags are kept in p_flag. */
  619 #define P_ADVLOCK       0x00001 /* Process may hold a POSIX advisory lock. */
  620 #define P_CONTROLT      0x00002 /* Has a controlling terminal. */
  621 #define P_KTHREAD       0x00004 /* Kernel thread. (*)*/
  622 #define P_NOLOAD        0x00008 /* Ignore during load avg calculations. */
  623 #define P_PPWAIT        0x00010 /* Parent is waiting for child to exec/exit. */
  624 #define P_SUGID         0x00100 /* Had set id privileges since last exec. */
  625 #define P_SYSTEM        0x00200 /* System proc: no sigs, stats or swapping. */
  626 #define P_WAITED        0x01000 /* Someone is waiting for us */
  627 #define P_WEXIT         0x02000 /* Working on exiting. */
  628 #define P_EXEC          0x04000 /* Process called exec. */
  629 #define P_KSES          0x08000 /* Process is using KSEs. */
  630 #define P_CONTINUED     0x10000 /* Proc has continued from a stopped state. */
  631 
  632 /* flags that control how threads may be suspended for some reason */
  633 #define P_STOPPED_SIG           0x20000 /* Stopped due to SIGSTOP/SIGTSTP */
  634 #define P_STOPPED_TRACE         0x40000 /* Stopped because of tracing */
  635 #define P_STOPPED_SINGLE        0x80000 /* Only one thread can continue */
  636                                         /* (not to user) */
  637 #define P_SINGLE_EXIT           0x00400 /* Threads suspending should exit, */
  638                                         /* not wait */
  639 #define P_TRACED                0x00800 /* Debugged process being traced. */
  640 #define P_STOPPED               (P_STOPPED_SIG|P_STOPPED_SINGLE|P_STOPPED_TRACE)
  641 #define P_SHOULDSTOP(p)         ((p)->p_flag & P_STOPPED)
  642 
  643 /* Should be moved to machine-dependent areas. */
  644 #define P_UNUSED100000  0x100000
  645 #define P_COWINPROGRESS 0x400000 /* Snapshot copy-on-write in progress. */
  646 
  647 #define P_JAILED        0x1000000 /* Process is in jail. */
  648 #define P_OLDMASK       0x2000000 /* Need to restore mask after suspend. */
  649 #define P_ALTSTACK      0x4000000 /* Have alternate signal stack. */
  650 #define P_INEXEC        0x8000000 /* Process is in execve(). */
  651 
  652 /* These flags are kept in p_sflag and are protected with sched_lock. */
  653 #define PS_INMEM        0x00001 /* Loaded into memory. */
  654 #define PS_XCPU         0x00002 /* Exceeded CPU limit. */
  655 #define PS_PROFIL       0x00004 /* Has started profiling. */
  656 #define PS_ALRMPEND     0x00020 /* Pending SIGVTALRM needs to be posted. */
  657 #define PS_PROFPEND     0x00040 /* Pending SIGPROF needs to be posted. */
  658 #define PS_SWAPINREQ    0x00100 /* Swapin request due to wakeup. */
  659 #define PS_SWAPPING     0x00200 /* Process is being swapped. */
  660 #define PS_NEEDSIGCHK   0x02000 /* Process may need signal delivery. */
  661 #define PS_SWAPPINGIN   0x04000 /* Swapin in progress. */
  662 #define PS_MACPEND      0x08000 /* Ast()-based MAC event pending. */
  663 
  664 /* used only in legacy conversion code */
  665 #define SIDL    1               /* Process being created by fork. */
  666 #define SRUN    2               /* Currently runnable. */
  667 #define SSLEEP  3               /* Sleeping on an address. */
  668 #define SSTOP   4               /* Process debugging or suspension. */
  669 #define SZOMB   5               /* Awaiting collection by parent. */
  670 #define SWAIT   6               /* Waiting for interrupt. */
  671 #define SLOCK   7               /* Blocked on a lock. */
  672 
  673 #define P_MAGIC         0xbeefface
  674 
  675 #ifdef _KERNEL
  676 
  677 #ifdef MALLOC_DECLARE
  678 MALLOC_DECLARE(M_PARGS);
  679 MALLOC_DECLARE(M_PGRP);
  680 MALLOC_DECLARE(M_SESSION);
  681 MALLOC_DECLARE(M_SUBPROC);
  682 MALLOC_DECLARE(M_ZOMBIE);
  683 #endif
  684 
  685 #define FOREACH_PROC_IN_SYSTEM(p)                                       \
  686         LIST_FOREACH((p), &allproc, p_list)
  687 #define FOREACH_KSEGRP_IN_PROC(p, kg)                                   \
  688         TAILQ_FOREACH((kg), &(p)->p_ksegrps, kg_ksegrp)
  689 #define FOREACH_THREAD_IN_GROUP(kg, td)                                 \
  690         TAILQ_FOREACH((td), &(kg)->kg_threads, td_kglist)
  691 #define FOREACH_KSE_IN_GROUP(kg, ke)                                    \
  692         TAILQ_FOREACH((ke), &(kg)->kg_kseq, ke_kglist)
  693 #define FOREACH_THREAD_IN_PROC(p, td)                                   \
  694         TAILQ_FOREACH((td), &(p)->p_threads, td_plist)
  695 
  696 /* XXXKSE the lines below should probably only be used in 1:1 code */
  697 #define FIRST_THREAD_IN_PROC(p) TAILQ_FIRST(&p->p_threads)
  698 #define FIRST_KSEGRP_IN_PROC(p) TAILQ_FIRST(&p->p_ksegrps)
  699 #define FIRST_KSE_IN_KSEGRP(kg) TAILQ_FIRST(&kg->kg_kseq)
  700 #define FIRST_KSE_IN_PROC(p) FIRST_KSE_IN_KSEGRP(FIRST_KSEGRP_IN_PROC(p))
  701 
  702 static __inline int
  703 sigonstack(size_t sp)
  704 {
  705         register struct thread *td = curthread;
  706         struct proc *p = td->td_proc;
  707 
  708         return ((p->p_flag & P_ALTSTACK) ?
  709 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
  710             ((p->p_sigstk.ss_size == 0) ? (p->p_sigstk.ss_flags & SS_ONSTACK) :
  711                 ((sp - (size_t)p->p_sigstk.ss_sp) < p->p_sigstk.ss_size))
  712 #else
  713             ((sp - (size_t)p->p_sigstk.ss_sp) < p->p_sigstk.ss_size)
  714 #endif
  715             : 0);
  716 }
  717 
  718 /* Handy macro to determine if p1 can mangle p2. */
  719 #define PRISON_CHECK(p1, p2) \
  720         ((p1)->p_prison == NULL || (p1)->p_prison == (p2)->p_prison)
  721 
  722 /*
  723  * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
  724  * as it is used to represent "no process group".
  725  */
  726 #define PID_MAX         99999
  727 #define NO_PID          100000
  728 
  729 #define SESS_LEADER(p)  ((p)->p_session->s_leader == (p))
  730 #define SESSHOLD(s)     ((s)->s_count++)
  731 #define SESSRELE(s) {                                                   \
  732         if (--(s)->s_count == 0)                                        \
  733                 FREE(s, M_SESSION);                                     \
  734 }
  735 
  736 #define STOPEVENT(p, e, v) do {                                         \
  737         PROC_LOCK(p);                                                   \
  738         _STOPEVENT((p), (e), (v));                                      \
  739         PROC_UNLOCK(p);                                                 \
  740 } while (0)
  741 #define _STOPEVENT(p, e, v) do {                                        \
  742         PROC_LOCK_ASSERT(p, MA_OWNED);                                  \
  743         if ((p)->p_stops & (e)) {                                       \
  744                 stopevent((p), (e), (v));                               \
  745         }                                                               \
  746 } while (0)
  747 
  748 /* Lock and unlock a process. */
  749 #define PROC_LOCK(p)    mtx_lock(&(p)->p_mtx)
  750 #define PROC_TRYLOCK(p) mtx_trylock(&(p)->p_mtx)
  751 #define PROC_UNLOCK(p)  mtx_unlock(&(p)->p_mtx)
  752 #define PROC_LOCKED(p)  mtx_owned(&(p)->p_mtx)
  753 #define PROC_LOCK_ASSERT(p, type)       mtx_assert(&(p)->p_mtx, (type))
  754 
  755 /* Lock and unlock a process group. */
  756 #define PGRP_LOCK(pg)   mtx_lock(&(pg)->pg_mtx)
  757 #define PGRP_UNLOCK(pg) mtx_unlock(&(pg)->pg_mtx)
  758 #define PGRP_LOCKED(pg) mtx_owned(&(pg)->pg_mtx)
  759 #define PGRP_LOCK_ASSERT(pg, type)      mtx_assert(&(pg)->pg_mtx, (type))
  760 
  761 #define PGRP_LOCK_PGSIGNAL(pg)                                          \
  762         do {                                                            \
  763                 if ((pg) != NULL)                                       \
  764                         PGRP_LOCK(pg);                                  \
  765         } while (0);
  766 
  767 #define PGRP_UNLOCK_PGSIGNAL(pg)                                        \
  768         do {                                                            \
  769                 if ((pg) != NULL)                                       \
  770                         PGRP_UNLOCK(pg);                                \
  771         } while (0);
  772 
  773 /* Lock and unlock a session. */
  774 #define SESS_LOCK(s)    mtx_lock(&(s)->s_mtx)
  775 #define SESS_UNLOCK(s)  mtx_unlock(&(s)->s_mtx)
  776 #define SESS_LOCKED(s)  mtx_owned(&(s)->s_mtx)
  777 #define SESS_LOCK_ASSERT(s, type)       mtx_assert(&(s)->s_mtx, (type))
  778 
  779 /* Hold process U-area in memory, normally for ptrace/procfs work. */
  780 #define PHOLD(p) do {                                                   \
  781         PROC_LOCK(p);                                                   \
  782         _PHOLD(p);                                                      \
  783         PROC_UNLOCK(p);                                                 \
  784 } while (0)
  785 #define _PHOLD(p) do {                                                  \
  786         PROC_LOCK_ASSERT((p), MA_OWNED);                                \
  787         if ((p)->p_lock++ == 0) {                                       \
  788                 mtx_lock_spin(&sched_lock);                             \
  789                 faultin((p));                                           \
  790                 mtx_unlock_spin(&sched_lock);                           \
  791         }                                                               \
  792 } while (0)
  793 
  794 #define PRELE(p) do {                                                   \
  795         PROC_LOCK((p));                                                 \
  796         _PRELE((p));                                                    \
  797         PROC_UNLOCK((p));                                               \
  798 } while (0)
  799 #define _PRELE(p) do {                                                  \
  800         PROC_LOCK_ASSERT((p), MA_OWNED);                                \
  801         (--(p)->p_lock);                                                \
  802 } while (0)
  803 
  804 /* Check whether a thread is safe to be swapped out. */
  805 #define thread_safetoswapout(td) (TD_IS_SLEEPING(td) || TD_IS_SUSPENDED(td))
  806 
  807 /* Lock and unlock process arguments. */
  808 #define PARGS_LOCK(p)           mtx_lock(&pargs_ref_lock)
  809 #define PARGS_UNLOCK(p)         mtx_unlock(&pargs_ref_lock)
  810 
  811 #define PIDHASH(pid)    (&pidhashtbl[(pid) & pidhash])
  812 extern LIST_HEAD(pidhashhead, proc) *pidhashtbl;
  813 extern u_long pidhash;
  814 
  815 #define PGRPHASH(pgid)  (&pgrphashtbl[(pgid) & pgrphash])
  816 extern LIST_HEAD(pgrphashhead, pgrp) *pgrphashtbl;
  817 extern u_long pgrphash;
  818 
  819 extern struct sx allproc_lock;
  820 extern struct sx proctree_lock;
  821 extern struct mtx pargs_ref_lock;
  822 extern struct mtx ppeers_lock;
  823 extern struct proc proc0;               /* Process slot for swapper. */
  824 extern struct thread thread0;           /* Primary thread in proc0 */
  825 extern struct ksegrp ksegrp0;           /* Primary ksegrp in proc0 */
  826 extern struct kse kse0;                 /* Primary kse in proc0 */
  827 extern int hogticks;                    /* Limit on kernel cpu hogs. */
  828 extern int nprocs, maxproc;             /* Current and max number of procs. */
  829 extern int maxprocperuid;               /* Max procs per uid. */
  830 extern u_long ps_arg_cache_limit;
  831 extern int ps_argsopen;
  832 extern int ps_showallprocs;
  833 extern int sched_quantum;               /* Scheduling quantum in ticks. */
  834 
  835 LIST_HEAD(proclist, proc);
  836 TAILQ_HEAD(procqueue, proc);
  837 TAILQ_HEAD(threadqueue, thread);
  838 extern struct proclist allproc;         /* List of all processes. */
  839 extern struct proclist zombproc;        /* List of zombie processes. */
  840 extern struct proc *initproc, *pageproc; /* Process slots for init, pager. */
  841 extern struct proc *updateproc;         /* Process slot for syncer (sic). */
  842 
  843 extern struct uma_zone *proc_zone;
  844 
  845 extern int lastpid;
  846 
  847 struct  proc *pfind(pid_t);     /* Find process by id. */
  848 struct  pgrp *pgfind(pid_t);    /* Find process group by id. */
  849 struct  proc *zpfind(pid_t);    /* Find zombie process by id. */
  850 
  851 void    adjustrunqueue(struct thread *, int newpri);
  852 void    ast(struct trapframe *framep);
  853 struct  thread *choosethread(void);
  854 int     cr_cansignal(struct ucred *cred, struct proc *proc, int signum);
  855 int     enterpgrp(struct proc *p, pid_t pgid, struct pgrp *pgrp, struct session *sess);
  856 int     enterthispgrp(struct proc *p, struct pgrp *pgrp);
  857 void    faultin(struct proc *p);
  858 void    fixjobc(struct proc *p, struct pgrp *pgrp, int entering);
  859 int     fork1(struct thread *, int, int, struct proc **);
  860 void    fork_exit(void (*)(void *, struct trapframe *), void *,
  861             struct trapframe *);
  862 void    fork_return(struct thread *, struct trapframe *);
  863 int     inferior(struct proc *p);
  864 int     leavepgrp(struct proc *p);
  865 void    mi_switch(void);
  866 int     p_candebug(struct thread *td, struct proc *p);
  867 int     p_cansee(struct thread *td, struct proc *p);
  868 int     p_cansched(struct thread *td, struct proc *p);
  869 int     p_cansignal(struct thread *td, struct proc *p, int signum);
  870 struct  pargs *pargs_alloc(int len);
  871 void    pargs_drop(struct pargs *pa);
  872 void    pargs_free(struct pargs *pa);
  873 void    pargs_hold(struct pargs *pa);
  874 void    procinit(void);
  875 void    threadinit(void);
  876 void    proc_linkup(struct proc *p, struct ksegrp *kg,
  877             struct kse *ke, struct thread *td);
  878 void    proc_reparent(struct proc *child, struct proc *newparent);
  879 int     securelevel_ge(struct ucred *cr, int level);
  880 int     securelevel_gt(struct ucred *cr, int level);
  881 void    setrunnable(struct thread *);
  882 void    setrunqueue(struct thread *);
  883 void    setsugid(struct proc *p);
  884 void    sleepinit(void);
  885 void    stopevent(struct proc *, u_int, u_int);
  886 void    cpu_idle(void);
  887 void    cpu_switch(void);
  888 void    cpu_throw(void) __dead2;
  889 void    unsleep(struct thread *);
  890 void    userret(struct thread *, struct trapframe *, u_int);
  891 
  892 void    cpu_exit(struct thread *);
  893 void    cpu_sched_exit(struct thread *);
  894 void    exit1(struct thread *, int) __dead2;
  895 void    cpu_fork(struct thread *, struct proc *, struct thread *, int);
  896 void    cpu_set_fork_handler(struct thread *, void (*)(void *), void *);
  897 void    cpu_wait(struct proc *);
  898 
  899 /* New in KSE. */
  900 struct  ksegrp *ksegrp_alloc(void);
  901 void    ksegrp_free(struct ksegrp *kg);
  902 void    ksegrp_stash(struct ksegrp *kg);
  903 struct  kse *kse_alloc(void);
  904 void    kse_free(struct kse *ke);
  905 void    kse_stash(struct kse *ke);
  906 void    cpu_set_upcall(struct thread *td, void *pcb);
  907 void    cpu_set_upcall_kse(struct thread *td, struct kse *ke);
  908 void    cpu_thread_clean(struct thread *);
  909 void    cpu_thread_exit(struct thread *);
  910 void    cpu_thread_setup(struct thread *td);
  911 void    kse_reassign(struct kse *ke);
  912 void    kse_link(struct kse *ke, struct ksegrp *kg);
  913 void    kse_unlink(struct kse *ke);
  914 void    ksegrp_link(struct ksegrp *kg, struct proc *p);
  915 void    ksegrp_unlink(struct ksegrp *kg);
  916 void    make_kse_runnable(struct kse *ke);
  917 struct thread *signal_upcall(struct proc *p, int sig);
  918 struct  thread *thread_alloc(void);
  919 void    thread_exit(void) __dead2;
  920 int     thread_export_context(struct thread *td);
  921 void    thread_free(struct thread *td);
  922 void    thread_getcontext(struct thread *td, ucontext_t *uc);
  923 void    thread_link(struct thread *td, struct ksegrp *kg);
  924 void    thread_reap(void);
  925 struct thread *thread_schedule_upcall(struct thread *td, struct kse *ke);
  926 int     thread_setcontext(struct thread *td, ucontext_t *uc);
  927 int     thread_single(int how);
  928 #define SINGLE_NO_EXIT 0                        /* values for 'how' */
  929 #define SINGLE_EXIT 1
  930 void    thread_single_end(void);
  931 void    thread_stash(struct thread *td);
  932 int     thread_suspend_check(int how);
  933 void    thread_suspend_one(struct thread *td);
  934 void    thread_unsuspend(struct proc *p);
  935 void    thread_unsuspend_one(struct thread *td);
  936 int     thread_userret(struct thread *td, struct trapframe *frame);
  937 void    thread_user_enter(struct proc *p, struct thread *td);
  938 void    thread_wait(struct proc *p);
  939 int     thread_add_ticks_intr(int user, uint ticks);
  940 
  941 void    thread_sanity_check(struct thread *td, char *);
  942 #endif  /* _KERNEL */
  943 
  944 #endif  /* !_SYS_PROC_H_ */

Cache object: 2a931cf4c903dde0cb08146a8a21df3e


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