
/*
 * @(#)user.h	1.1 (National Semiconductor) 8/4/87 13:39:34
 * @(#) copyrights and other release restrictions may apply
 */

#ifdef KERNEL
#include "time.h"
#include "resource.h"
#include "namei.h"
#else
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/namei.h>
#endif

/*
 * Per process structure containing data that
 * isn't needed in core when the process is swapped out.
 */
 
#define	MAXCOMLEN	16		/* <= MAXNAMLEN, >= sizeof(a_comm) */
 
struct	user {
	long	u_msrreg;		/* mmu msr register at last fault */
	long	u_eiareg;		/* mmu eia register at last fault */
	long	u_bpr0;			/* mmu bpr0 register */
	long	u_bpr1;			/* mmu bpr1 register */
	long	u_bcnt;			/* mmu bcnt register */
	long	u_pf0;			/* mmu pf0 register */
	long	u_pf1;			/* mmu pf1 register */
	long	u_sc;			/* mmu sc register */
	long	u_fsr;			/* fpu status register */
	long	u_fregs[8];		/* fpu general registers */
	struct	proc *u_procp;		/* pointer to proc structure */
	unsigned long 	u_spti;		/* spt index */
	long	u_xspti;		/* spt index of shared text segment */
	int	*u_ar0;			/* address of users saved R0 */
	int	*u_abtar0;		/* saved r0 on last page fault */
	char	u_comm[MAXNAMLEN + 1];

/* syscall parameters, results and catches */
	int	u_arg[8];		/* arguments to current system call */
	int	*u_ap;			/* pointer to arglist */
	label_t	u_qsave;		/* for non-local gotos on interrupts */
	char	u_error;		/* return error code */
	union {				/* syscall return values */
		struct	{
			int	R_val1;
			int	R_val2;
		} u_rv;
#define	r_val1	u_rv.R_val1
#define	r_val2	u_rv.R_val2
		off_t	r_off;
		time_t	r_time;
	} u_r;
	char	u_eosys;		/* special action on end of syscall */

/* 1.1 - processes and protection */
	short	u_uid;			/* effective user id */
	short	u_gid;			/* effective group id */
	int	u_groups[NGROUPS];	/* groups, 0 terminated */
	short	u_ruid;			/* real user id */
	short	u_rgid;			/* real group id */

/* 1.2 - memory management */
	size_t	u_tsize;		/* text size (clicks) */
	size_t	u_dsize;		/* data size (clicks) */
	size_t	u_ssize;		/* stack size (clicks) */
	label_t u_ssave;		/* label variable for swapping */

/* 1.3 - signal management */
	int	(*u_sigcatch)();	/* signal catcher in the user code */
	int	(*u_signal[NSIG])();	/* disposition of signals */
	int	u_sigmask[NSIG];	/* signals to be blocked */
	int	u_sigonstack;		/* signals to take on sigstack */
	int	u_oldmask;		/* saved mask from before sigpause */
	int	u_code;			/* ``code'' to trap */
	struct	sigstack u_sigstack;	/* sp & on stack state variable */
#define	u_onstack	u_sigstack.ss_onstack
#define	u_sigsp		u_sigstack.ss_sp

/* 1.4 - descriptor management */
	struct	file *u_ofile[NOFILE];	/* file structures for open files */
	char	u_pofile[NOFILE];	/* per-process flags of open files */
#define	UF_EXCLOSE 	0x1		/* auto-close on exec */
#define	UF_MAPPED 	0x2		/* mapped from device */
	struct	inode *u_cdir;		/* current directory */
	struct	inode *u_rdir;		/* root directory of current process */
	struct	inode *u_ndir;		/* naming directory */
	struct	tty *u_ttyp;		/* controlling tty pointer */
	dev_t	u_ttyd;			/* controlling tty dev */
	short	u_cmask;		/* mask for file creation */

/* 1.5 - timing and statistics */
	struct	rusage u_ru;		/* stats for this proc */
	struct	rusage u_cru;		/* sum of stats for reaped children */
	struct	itimerval u_timer[3];
	int	u_XXX[3];
	struct	timeval	u_start;
	short	u_acflag;

	struct uprof {			/* profile arguments */
		short	*pr_base;	/* buffer base */
		unsigned pr_size;	/* buffer size */
		unsigned pr_off;	/* pc offset */
		unsigned pr_scale;	/* pc scaling */
	} u_prof;

/* 1.6 - resource controls */
	struct	rlimit u_rlimit[RLIM_NLIMITS];
	struct	quota *u_quota;		/* user's quota structure */
	int	u_qflags;		/* per process quota flags */

/* namei & co. */
	struct nameicache {		/* last successful directory search */
		int nc_prevoffset;	/* offset at which last entry found */
		ino_t nc_inumber;	/* inum of cached directory */
		dev_t nc_dev;		/* dev of cached directory */
		time_t nc_time;		/* time stamp for cache entry */
	} u_ncache;
	struct	nameidata u_nd;

	int	u_stack[1];
};

/* u_eosys values */
#define	JUSTRETURN	0
#define	RESTARTSYS	1
#define	SIMULATERTI	2
#define	REALLYRETURN	3

/* u_error codes */
#ifdef KERNEL
#include "errno.h"
#else
#include <sys/errno.h>
#endif

#ifdef KERNEL
extern struct user u;
#endif
