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

Cache object: 1ba95d776e7a2bdba1a88670052bbd2b


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