/*	@(#)proc.h	13.7 (RC International) 91/10/09	*/

/*
 *  proc.h -- memory-resident user process information
 *
 *	One structure allocated per active process. It contains all data
 *	needed about the process while the process may be swapped out.
 *	Other per process data (user.h) is swapped with the process.
 *
 *	P_link usage depends on p_stat: if SRUN, p_link is forward link
 *	for hash list of runnable procs; if pstat == SSLEEP or SSTOP, p_link
 *	is the hash chain links for procs on slpque.
 */


#if defined(LANGUAGE_C)

#include <sys/pid.h>

struct proc
{
    struct proc	*p_link;	/* linked list of running procs (see above) */
    struct proc	*p_rlink;	/* back link for hash list of runnable procs */
    char	p_processor;	/* [TX] which processor (used by txqueue.c) */
    char	p_runerr;	/* [TX] error code from child doing run() */
    short	p_swload;	/* [TX] swapload lock/count */
    struct proc	*p_txqlink;	/* [TX] for waiting in txqueues or semaphores */
    struct txqueue *p_q;	/* [TX] txqueue on which we are waiting */
    struct pte	*p_addr;	/* u-area kernel map address */
    int	   	p_tlbpid;	/* tlb context of this proc */
    struct tlbinfo *p_tlbinfo;	/* per process tlb mappings */
    int		p_tlbindx;	/* index of next wired tlb entry to use */
    struct shmat_ds *p_shmlist;	/* [sysv] shm segment attach descriptors */
    u_char	p_usrpri;	/* user-priority based on p_cpu and p_nice */
    u_char	p_pri;		/* priority, negative is high */
    u_char	p_cpu;		/* cpu usage for scheduling */
    char	p_stat;		/* process status (SSLEEP, etc. below) */
    u_char	p_time;		/* resident time for scheduling */
    u_char	p_nice;		/* nice for cpu usage */
    u_char	p_slptime;	/* time since last block */
    u_char	p_cursig;	/* signal now being handled */
    int		p_sig;		/* signals pending to this process */
    int		p_sigmask;	/* current signal mask */
    int		p_sigignore;	/* signals being ignored */
    int		p_sigcatch;	/* signals being caught by user */
    int		p_flag;		/* process flags (SLOAD, etc. below) */
    pid_t	p_pgrp;		/* name of process group leader */
    pid_t	p_pid;		/* unique process id */
    pid_t	p_ppid;         /* process id of parent*/
    struct pid_s *p_pidp;	/* ptr to process ID info */
    struct pid_s *p_pgidp;	/* prt to process group ID info */
    struct proc *p_pglink;	/* head of process group chain */
    struct sess *p_sessp;	/* session information */
    UID_T	p_subpu;	/* uid of associated subpu */
    u_short	p_xstat;	/* exit status for wait */
    short	p_code;		/* [TX] code for SIGTRANS */
    short	p_abocode;	/* [TX] code for SIGABORT */
    short	p_errcode;	/* [TX] code for SIGERR */
    struct trans_req	*p_transmsg;	/* [TX] sigtrans message */
    struct trans_req	*p_abortmsg;	/* [TX] sigabort message */
    struct rusage *p_ru;	/* mbuf holding exit information */
    long	p_textstart;	/* starting address of user text */
    long	p_datastart;	/* starting address of user data */
    short	p_poip;		/* page outs in progress */
    short	p_textpt;	/* copy of text  page table size */
    short	p_datapt;	/* copy of data  page table size */
    short	p_stakpt;	/* copy of stack page table size */
    size_t	p_tsize;	/* size of text (clicks) */
    size_t	p_dsize;	/* size of data space (clicks) */
    size_t	p_ssize;	/* copy of stack size (clicks) */
    size_t 	p_rssize; 	/* current resident set size in clicks */
    size_t	p_maxrss;	/* copy of u.u_limit[MAXRSS] */
    size_t	p_swrss;	/* resident set size before last swap */
    swblk_t	p_swaddr;	/* disk address of u area when swapped */
    caddr_t	p_wchan;	/* event process is awaiting */
    struct text	*p_textp;	/* pointer to text structure */
    struct pte 	*p_textbr;	/* text  page table base */
    struct pte	*p_databr;	/* data  page table base */
    struct pte	*p_stakbr;	/* stack page table base */
    struct proc	*p_xlink;	/* linked list of procs sharing same text */
    short	p_uid;		/* effective user id for process management */
    short	p_ruid;		/* real user id for process management */
    short	p_cpticks;	/* ticks of cpu time */
    long	p_pctcpu;	/* cpu fraction for this proc during p_time
				 * multiplied by "avenscale" (was a float) */
    short	p_suid;		/* saved euid (for SysV compat) */
    short	p_sgid;		/* saved egid (for SysV compat) */
    short	p_mflags;       /* more process flags (se below) */
    short	p_fp;		/* generate SIGFPE on all fp interrupts - MIPS*/
    short	p_ndx;		/* proc index for memall (because of vfork) */
    short	p_idhash;	/* hashed based on p_pid for kill+exit+... */
    struct proc	*p_pptr;	/* pointer to process structure of parent */
    struct proc	*p_child;	/* pointer to first child process  */
    struct proc	*p_sibling;	/* pointer to next sibling process */
    struct itimerval p_realtimer;	/* real time interval timer struct */
    struct quota *p_quota;	/* quotas for this process */
    u_int	p_smbeg;	/* [sysv] virtual pg # of shm base */
    u_int	p_smend;	/* [sysv] virtual pg # after shm end */
    struct uid_queue *p_myq;	/* [TX] for waiting for synchronous events */
    struct uid_queue *p_asyncq;	/* [TX] for receiving asynchronous events */
    int		p_sigdebug;	/* [TX] mask of signals NOT given to debugger */
    char	*p_debugstate;	/* [TX] debugger state for process */
    short	p_last_breakhit;/* [TX] last breakpoint hit for process */
    short	p_proceed_count;/* [TX] step/continue remaining count */
    char	p_sstep;	/* [TX] single step flag */
    UID_T	p_debuguid;	/* [TX] uid of async_q of debugger process */
    struct rp_rproc *p_rkids;	/* [TX] remote children list */
    struct inode *p_otty;	/* [TX] control terminal inode pointer */
    short	p_shmcnt;	/* [sysv] numbers of attached shm segments */
    short	p_syscalltime;	/* syscall to be timed (hackers junk)! */
    int		p_unused;	/* WAS : last syscall no */
    int		*p_syscallstat;	/* syscall stat array  (hackers junk)! */
};

/* process ID info */

struct pid_s {
    unsigned int pid_prinactive :1;
    unsigned int pid_pgorphaned :1;
    unsigned int pid_ref :6;
    unsigned int pid_prslot :24;
    pid_t pid_id;
    struct proc *pid_pglink;
    struct pid_s *pid_link;
};


#endif defined(LANGUAGE_C)


/* stat codes */
#define	SNULL	0		/* nothing doing */
#define	SSLEEP	1		/* awaiting an event */
#define	SWAIT	2		/* (abandoned state) */
#define	SRUN	3		/* running/want to run (might not be loaded)*/
#define	SIDL	4		/* intermediate state in process creation */
#define	SZOMB	5		/* intermediate state in process termination */
#define	SSTOP	6		/* process being traced */

/* flag codes */
#define	SLOAD	0x00000001	/* in core */
#define	SSYS	0x00000002	/* swapper or pager process */
#define	SLOCK	0x00000004	/* process being swapped out */
#define	SSWAP	0x00000008	/* save area flag */
#define	STRC	0x00000010	/* process is being traced */
#define	SWTED	0x00000020	/* stopped&traced proc has been wait()'ed for */
#define	SULOCK	0x00000040	/* user settable lock in core */
#define	SPAGE	0x00000080	/* process in page wait state */
#define	SKEEP	0x00000100	/* another flag to prevent swap out */
#define	SOMASK	0x00000200	/* restore old mask after taking signal */
#define	SWEXIT	0x00000400	/* working on exiting */
#define	SPHYSIO	0x00000800	/* doing physical i/o (bio.c) */
#define	SVFORK	0x00001000	/* process resulted from vfork() */
#define	SVFDONE	0x00002000	/* another vfork flag */
#define	SNOVM	0x00004000	/* no vm, parent in a vfork() */
#define	SPAGI	0x00008000	/* init data space on demand, from inode */
#define	SSEQL	0x00010000	/* user warned of sequential vm behavior */
#define	SUANOM	0x00020000	/* user warned of random vm behavior */
#define	STIMO	0x00040000	/* timing out during sleep */
/* was SDETACH */
#define SNEWDBG	0x00080000	/* process wants to trap for new debugger */
/* was SOUSIG */
#define	SPTTY	0x00100000	/* p_tty being inititalize by this process */
#define	SOWEUPC	0x00200000	/* owe process an addupc() call at next ast */
#define	SSEL	0x00400000	/* selecting; wakeup/waiting danger */
/* was SLOGIN */
#define	SRETIRE	0x00800000	/* waiting in retire */
#define	SPTECHG	0x01000000	/* pte's for process have changed */
#define SSHRINK	0x02000000	/* vm shrinking, cannot swapload */
/* was  SITRC */
#define	SRUNPCR	0x04000000	/* process being created via run() */
#define	SBREAKX	0x08000000	/* breakpoint on process exit */
#define	SSHMDT	0x10000000	/* shared memory detach in progress */
#define	SDBGX	0x20000000	/* brk_exit_process done */
#define	SNOWAIT	0x40000000	/* parent exited, nobody waiting for zombie */
#define SFIXADE 0x80000000	/* fixup unalligned address errors - MIPS */

/* mflag codes */
#define	MNOSIGCLD 0x00000001	/* do not sent SIGCLD when children stop/continue */
#define	SEXECED   0x00000002	/* */
#define	SSYSV	  0x00000004	/* Using SYSV flavour of system calls */

/* flags for p_fp */
#define P_FP_SIGINTR1	1
#define P_FP_SIGINTR2	2

