darwin-xnu/bsd/sys/proc.h
<<
>>
Prefs
   1/*
   2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
   3 *
   4 * @APPLE_LICENSE_HEADER_START@
   5 * 
   6 * The contents of this file constitute Original Code as defined in and
   7 * are subject to the Apple Public Source License Version 1.1 (the
   8 * "License").  You may not use this file except in compliance with the
   9 * License.  Please obtain a copy of the License at
  10 * http://www.apple.com/publicsource and read it before using this file.
  11 * 
  12 * This Original Code and all software distributed under the License are
  13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
  17 * License for the specific language governing rights and limitations
  18 * under the License.
  19 * 
  20 * @APPLE_LICENSE_HEADER_END@
  21 */
  22/* Copyright (c) 1995, 1997 Apple Computer, Inc. All Rights Reserved */
  23/*-
  24 * Copyright (c) 1986, 1989, 1991, 1993
  25 *      The Regents of the University of California.  All rights reserved.
  26 * (c) UNIX System Laboratories, Inc.
  27 * All or some portions of this file are derived from material licensed
  28 * to the University of California by American Telephone and Telegraph
  29 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
  30 * the permission of UNIX System Laboratories, Inc.
  31 *
  32 * Redistribution and use in source and binary forms, with or without
  33 * modification, are permitted provided that the following conditions
  34 * are met:
  35 * 1. Redistributions of source code must retain the above copyright
  36 *    notice, this list of conditions and the following disclaimer.
  37 * 2. Redistributions in binary form must reproduce the above copyright
  38 *    notice, this list of conditions and the following disclaimer in the
  39 *    documentation and/or other materials provided with the distribution.
  40 * 3. All advertising materials mentioning features or use of this software
  41 *    must display the following acknowledgement:
  42 *      This product includes software developed by the University of
  43 *      California, Berkeley and its contributors.
  44 * 4. Neither the name of the University nor the names of its contributors
  45 *    may be used to endorse or promote products derived from this software
  46 *    without specific prior written permission.
  47 *
  48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  51 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  58 * SUCH DAMAGE.
  59 *
  60 *      @(#)proc.h      8.15 (Berkeley) 5/19/95
  61 */
  62
  63#ifndef _SYS_PROC_H_
  64#define _SYS_PROC_H_
  65
  66#include <sys/appleapiopts.h>
  67#include <sys/cdefs.h>
  68#include <sys/select.h>                 /* For struct selinfo. */
  69#include <sys/queue.h>
  70#include <sys/lock.h>
  71#include <sys/param.h>
  72#include <sys/event.h>
  73#ifdef KERNEL
  74#include <sys/kernel_types.h>
  75#endif
  76#include <mach/boolean.h>
  77
  78#ifdef XNU_KERNEL_PRIVATE
  79#define PROC_DEF_ENABLED
  80#else
  81#ifndef KERNEL
  82#define PROC_DEF_ENABLED
  83#endif
  84#endif
  85
  86#ifdef PROC_DEF_ENABLED
  87
  88struct session;
  89struct pgrp;
  90struct proc;
  91
  92/* Exported fields for kern sysctls */
  93struct extern_proc {
  94        union {
  95                struct {
  96                        struct  proc *__p_forw; /* Doubly-linked run/sleep queue. */
  97                        struct  proc *__p_back;
  98                } p_st1;
  99                struct timeval __p_starttime;   /* process start time */
 100        } p_un;
 101#define p_forw p_un.p_st1.__p_forw
 102#define p_back p_un.p_st1.__p_back
 103#define p_starttime p_un.__p_starttime
 104        struct  vmspace *p_vmspace;     /* Address space. */
 105        struct  sigacts *p_sigacts;     /* Signal actions, state (PROC ONLY). */
 106        int     p_flag;                 /* P_* flags. */
 107        char    p_stat;                 /* S* process status. */
 108        pid_t   p_pid;                  /* Process identifier. */
 109        pid_t   p_oppid;         /* Save parent pid during ptrace. XXX */
 110        int     p_dupfd;         /* Sideways return value from fdopen. XXX */
 111        /* Mach related  */
 112        caddr_t user_stack;     /* where user stack was allocated */
 113        void    *exit_thread;   /* XXX Which thread is exiting? */
 114        int             p_debugger;             /* allow to debug */
 115        boolean_t       sigwait;        /* indication to suspend */
 116        /* scheduling */
 117        u_int   p_estcpu;        /* Time averaged value of p_cpticks. */
 118        int     p_cpticks;       /* Ticks of cpu time. */
 119        fixpt_t p_pctcpu;        /* %cpu for this process during p_swtime */
 120        void    *p_wchan;        /* Sleep address. */
 121        char    *p_wmesg;        /* Reason for sleep. */
 122        u_int   p_swtime;        /* Time swapped in or out. */
 123        u_int   p_slptime;       /* Time since last blocked. */
 124        struct  itimerval p_realtimer;  /* Alarm timer. */
 125        struct  timeval p_rtime;        /* Real time. */
 126        u_quad_t p_uticks;              /* Statclock hits in user mode. */
 127        u_quad_t p_sticks;              /* Statclock hits in system mode. */
 128        u_quad_t p_iticks;              /* Statclock hits processing intr. */
 129        int     p_traceflag;            /* Kernel trace points. */
 130        struct  vnode *p_tracep;        /* Trace to vnode. */
 131        int     p_siglist;              /* DEPRECATED */
 132        struct  vnode *p_textvp;        /* Vnode of executable. */
 133        int     p_holdcnt;              /* If non-zero, don't swap. */
 134        sigset_t p_sigmask;     /* DEPRECATED. */
 135        sigset_t p_sigignore;   /* Signals being ignored. */
 136        sigset_t p_sigcatch;    /* Signals being caught by user. */
 137        u_char  p_priority;     /* Process priority. */
 138        u_char  p_usrpri;       /* User-priority based on p_cpu and p_nice. */
 139        char    p_nice;         /* Process "nice" value. */
 140        char    p_comm[MAXCOMLEN+1];
 141        struct  pgrp *p_pgrp;   /* Pointer to process group. */
 142        struct  user *p_addr;   /* Kernel virtual addr of u-area (PROC ONLY). */
 143        u_short p_xstat;        /* Exit status for wait; also stop signal. */
 144        u_short p_acflag;       /* Accounting flags. */
 145        struct  rusage *p_ru;   /* Exit information. XXX */
 146};
 147
 148
 149/* Status values. */
 150#define SIDL    1               /* Process being created by fork. */
 151#define SRUN    2               /* Currently runnable. */
 152#define SSLEEP  3               /* Sleeping on an address. */
 153#define SSTOP   4               /* Process debugging or suspension. */
 154#define SZOMB   5               /* Awaiting collection by parent. */
 155
 156/* These flags are kept in p_flags. */
 157#define P_ADVLOCK       0x00000001      /* Process may hold POSIX adv. lock */
 158#define P_CONTROLT      0x00000002      /* Has a controlling terminal */
 159#define P_LP64          0x00000004      /* Process is LP64 */
 160#define P_NOCLDSTOP     0x00000008      /* No SIGCHLD when children stop */
 161
 162#define P_PPWAIT        0x00000010      /* Parent waiting for chld exec/exit */
 163#define P_PROFIL        0x00000020      /* Has started profiling */
 164#define P_SELECT        0x00000040      /* Selecting; wakeup/waiting danger */
 165#define P_CONTINUED     0x00000080      /* Process was stopped and continued */
 166
 167#define P_SUGID         0x00000100      /* Has set privileges since last exec */
 168#define P_SYSTEM        0x00000200      /* Sys proc: no sigs, stats or swap */
 169#define P_TIMEOUT       0x00000400      /* Timing out during sleep */
 170#define P_TRACED        0x00000800      /* Debugged process being traced */
 171
 172#define P_WAITED        0x00001000      /* Debugging prc has waited for child */
 173#define P_WEXIT         0x00002000      /* Working on exiting. */
 174#define P_EXEC          0x00004000      /* Process called exec. */
 175
 176/* Should be moved to machine-dependent areas. */
 177#define P_OWEUPC        0x00008000      /* Owe process an addupc() call at next ast. */
 178
 179#define P_AFFINITY      0x00010000      /* xxx */
 180#define P_CLASSIC       0x00020000      /* xxx */
 181/*
 182#define P_FSTRACE       0x10000 / * tracing via file system (elsewhere?) * /
 183#define P_SSTEP         0x20000 / * process needs single-step fixup ??? * /
 184*/
 185
 186#define P_WAITING       0x00040000      /* process has a wait() in progress */
 187#define P_KDEBUG        0x00080000      /* kdebug tracing on for this process */
 188
 189#define P_TTYSLEEP      0x00100000      /* blocked due to SIGTTOU or SIGTTIN */
 190#define P_REBOOT        0x00200000      /* Process called reboot() */
 191#define P_TBE           0x00400000      /* Process is TBE */
 192#define P_SIGEXC        0x00800000      /* signal exceptions */
 193
 194#define P_BTRACE        0x01000000      /* process is being branch traced */
 195#define P_VFORK         0x02000000      /* process has vfork children */
 196#define P_NOATTACH      0x04000000
 197#define P_INVFORK       0x08000000      /* proc in vfork */
 198
 199#define P_NOSHLIB       0x10000000      /* no shared libs are in use for proc */
 200                                        /* flag set on exec */
 201#define P_FORCEQUOTA    0x20000000      /* Force quota for root */
 202#define P_NOCLDWAIT     0x40000000      /* No zombies when chil procs exit */
 203#define P_NOREMOTEHANG  0x80000000      /* Don't hang on remote FS ops */
 204
 205#define P_INMEM         0               /* Obsolete: retained for compilation */
 206#define P_NOSWAP        0               /* Obsolete: retained for compilation */
 207#define P_PHYSIO        0               /* Obsolete: retained for compilation */
 208#define P_FSTRACE       0               /* Obsolete: retained for compilation */
 209#define P_SSTEP         0               /* Obsolete: retained for compilation */
 210
 211#endif /* PROC_DEF_ENABLED */
 212
 213#ifdef KERNEL
 214__BEGIN_DECLS
 215
 216extern proc_t kernproc;
 217
 218extern int proc_is_classic(struct proc *p);
 219struct proc *current_proc_EXTERNAL(void);
 220
 221extern int      msleep(void *chan, lck_mtx_t *mtx, int pri, const char *wmesg, struct timespec * ts );
 222extern void     unsleep(struct proc *);
 223extern void     wakeup(void *chan);
 224extern void wakeup_one(caddr_t chan);
 225
 226/* proc kpis */
 227/* this routine returns the pid of the current process */
 228extern int proc_selfpid(void);
 229/* this routine returns the pid of the parent of the current process */
 230extern int proc_selfppid(void);
 231/* this routine returns sends a signal signum to the process identified by the pid */
 232extern void proc_signal(int pid, int signum);
 233/* this routine checks whether any signal identified by the mask are pending in the  process identified by the pid. The check is  on all threads of the process. */
 234extern int proc_issignal(int pid, sigset_t mask);
 235/* this routine returns 1 if the pid1 is inferior of pid2 */
 236extern int proc_isinferior(int pid1, int pid2);
 237/* this routine copies the process's name of the executable to the passed in buffer. It 
 238 * is always null terminated. The size of the buffer is to be passed in as well. This 
 239 * routine is to be used typically for debugging 
 240 */
 241void proc_name(int pid, char * buf, int size);
 242/* This routine is simillar to proc_name except it returns for current process */
 243void proc_selfname(char * buf, int size);
 244
 245/* find a process with a given pid. This comes with a reference which needs to be dropped by proc_rele */
 246extern proc_t proc_find(int pid);
 247/* returns a handle to current process which is referenced. The reference needs to be dropped with proc_rele */
 248extern proc_t proc_self(void);
 249/* releases the held reference on the process */
 250extern int proc_rele(proc_t p);
 251/* returns the pid of the given process */
 252extern int proc_pid(proc_t);
 253/* returns the pid of the parent of a given process */
 254extern int proc_ppid(proc_t);
 255/* returns 1 if the process is marked for no remote hangs */
 256extern int proc_noremotehang(proc_t);
 257/* returns 1 is the process is marked for force quota */
 258extern int proc_forcequota(proc_t);
 259
 260/* this routine returns 1 if the process is running with 64bit address space, else 0 */
 261extern int proc_is64bit(proc_t);
 262/* is this process exiting? */
 263extern int proc_exiting(proc_t);
 264/* this routine returns error is the process is not one with super user privileges */
 265int proc_suser(struct proc *p);
 266/* returns the ucred assicaited with the process; temporary api */
 267struct ucred * proc_ucred(struct proc *p);
 268
 269/* LP64todo - figure out how to identify 64-bit processes if NULL procp */
 270extern int IS_64BIT_PROCESS(proc_t);
 271extern int proc_pendingsignals(struct proc *, sigset_t);
 272extern int proc_tbe(struct proc *);
 273
 274#ifdef KERNEL_PRIVATE
 275extern int      tsleep(void *chan, int pri, const char *wmesg, int timo);
 276extern int      msleep1(void *chan, lck_mtx_t *mtx, int pri, const char *wmesg, u_int64_t timo);
 277#endif
 278
 279__END_DECLS
 280
 281#endif  /* KERNEL */
 282
 283#endif  /* !_SYS_PROC_H_ */
 284
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.