/*
 * $Header: /smsa/bsd:include/sys/proc.h:bsd.riscix1_2  1.20  $
 * $Source: /smsa/bsd:include/sys/proc.h: $
 *
 * Copyright (c) 1988 Acorn Computers Ltd., Cambridge, England
 *
 */
/*	@(#)proc.h	2.2 88/05/24 4.0NFSSRC SMI;	from UCB 7.1 6/4/86	*/
/*	@(#)proc.h	1.4 87/08/24 3.2/4.3NFSSRC */
/*
 * Copyright (c) 1982, 1986 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */

#ifndef	__sys_proc_h
#define	__sys_proc_h

#ifndef __sys_param_h
#include "param.h"
#endif
#ifndef __machine_pte_h
#include "../machine/pte.h"
#endif


/*
 * 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.
 */
struct	proc {
	struct	proc *p_link;	/* linked list of running processes */
	struct	proc *p_rlink;
	struct	proc *p_nxt;	/* linked list of allocated proc slots */
	struct	proc **p_prev;	/* also zombies, and free proc's */
	char	p_usrpri;	/* user-priority based on p_cpu and p_nice */
	char	p_pri;		/* priority, negative is high */
	char	p_cpu;		/* cpu usage for scheduling */
	char	p_stat;
	char	p_time;		/* resident time for scheduling */
	char	p_nice;		/* nice for cpu usage */
	char	p_slptime;	/* time since last block */
	char	p_cursig;
	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;
	uid_t	p_uid;		/* user id, used to direct tty signals */
	pid_t	p_pgrp;		/* name of process group leader */
	pid_t	p_pid;		/* unique process id */
	pid_t	p_ppid;		/* process id of parent */
	u_short	p_xstat;	/* Exit status for wait */
	u_char	p_exec_done;	/* exec has been done */
	union
	{
	    struct rusage *un_ru; /* -> buffer holding exit information */
	    struct ucred *un_cred; /* copy of u.u_cred for signal checks */
	} p_un;
#define p_ru	p_un.un_ru
#define p_cred	p_un.un_cred
	short	p_poip;		/* page outs in progress */
	short	p_szpt;		/* copy of page table size */
	int	p_swlocks;	/* number of swap vnode locks held */
	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 */
	swblk_t	*p_xswaddr;	/* disc addresses of text when debugging */
	caddr_t p_wchan;	/* event process is awaiting */
	/*
	 * The page table has now been moved out of the proc
	 * structure, to save space, since it can be placed in
	 * otherwise unused space in the process's u-page (note: the
	 * u-page is never paged out in this version of RISC iX).
	 * Hence the PT field is now a pointer, not an array.
	 */
	struct	pte *PT;	/* process page table */
	/*
	 * p_addr points at the first of the ptes (on ARM/MEMC1, just
	 * one) defining the process's u-area.  During process
	 * creation these ptes are actually in p_uareapte[] below. See
	 * procdup().
	 */
	struct	pte *p_addr;	/* u-area page table entry pointer */
	/*
	 * p_uspg0 contains the virtual page number of the first
	 * (highest address) page of the user's stack region (P1, in
	 * VAX terms, but not including the u-area). This is necessary
	 * to allow compatible operation with shared libraries built
	 * for a c.16Mb user address space (RISC iX 1.1 and before)
	 * and RISC iX 1.2 shared libraries which will be built
	 * assuming a c.24Mb user address space.
	 */
	unsigned int p_uspg0;
	/*
	 * The following field is used only during procdup() to avoid
	 * a circularity in the ordering of page table and u-area
	 * allocation, since the page tables now live in the u-area.
	 * It contains a copy of the ptes for the u-area, which
	 * normally live in the main page table (in the u-area...)
	 */
	struct	pte p_uareapte[UPAGES];
	/*
	 * Shared memory control structure is now indirected, since
	 * most processes don't use it.
	 */
	struct proc_shm *p_shm;
	/* Text structure pointers */
	struct text *p_textp;	/* pointer to text structure of main program */
	struct proc *p_xlinks[MAXSHLIBS+1];	
				/* linked lists of procs sharing same text   */
				/* and libraries. Libs in slot 0 (deepest)   */
				/* upwards, main text in slot MAXSHLIBS.     */
	short	p_cpticks;	/* ticks of cpu time */
	pid_t	p_sessldr;	/* pid of session leader for session this proc is in */
#ifdef	FLOAT
	float	p_pctcpu;	/* %cpu for this process during p_time */
#else	FLOAT
	int	p_pctcpu;
#endif	FLOAT
	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_cptr;	/* pointer to youngest living child */
	struct	proc *p_osptr;	/* pointer to older sibling processes */
	struct	proc *p_ysptr;	/* pointer to younger siblings */
	struct	itimerval p_realtimer;
	int	p_pginiorate;	/* moving avg of pages/sec in from disc */
};

typedef struct proc *proc_p;

#define	PIDHSZ		64
#define	PIDHASH(pid)	((pid) & (PIDHSZ - 1))

#ifdef _KERNEL
short	pidhash[PIDHSZ];
struct	proc *pfind();
struct	proc *proc, *procNPROC;	/* proc -> the proc table itself */
struct	proc *freeproc, *zombproc, *allproc;
			/* lists of procs in various states */
int	nproc;

#define	NQS	32		/* 32 run queues */
struct	prochd {
	struct	proc *ph_link;	/* linked list of running processes */
	struct	proc *ph_rlink;
} qs[NQS];
int	whichqs;		/* bit mask summarizing non-empty qs's */
#endif/*_KERNEL*/

/* stat codes */
#define	SSLEEP	1		/* awaiting an event */
#define	SWAIT	2		/* (abandoned state) */
#define	SRUN	3		/* running */
#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	/* another tracing flag */
#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	SPAGV	0x00008000	/* init data space on demand, from vnode */
#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 */
/* Temporary bodge flag to allow us to run the old compiler (with the old
 * system call SWI_OS field on the new kernel. A special magic number is
 * noticed by exec().
 */
#define SOLDSWI 0x00080000

#define	SOUSIG	0x00100000	/* using old signal mechanism */
#define	SOWEUPC	0x00200000	/* owe process an addupc() call at next ast */
#define	SSEL	0x00400000	/* selecting; wakeup/waiting danger */
#define	SLOGIN	0x00800000	/* a login process (legit child of init) */
#define	SPTECHG	0x01000000	/* pte's for process have changed */
#define SLKDONE 0x04000000     	/* record-locking has been done */

#define SORPHPG	0x08000000	/* proc in orphaned process group */
#define SNOCSTP 0x10000000	/* don't send SIGCHLD on child stop */
#define SBSDPG	0x20000000	/* proc is leader of BSD style process group */

#endif/*__sys_proc_h*/

/* EOF proc.h */
