/*
 * $Header: /smsa/bsd:include/sys/user.h:bsd  1.16  $
 * $Source: /smsa/bsd:include/sys/user.h: $
 *
 * Copyright (c) 1988 Acorn Computers Ltd., Cambridge, England
 *
 */
/*	@(#)user.h	2.1 88/05/18 4.0NFSSRC SMI;	from UCB 7.1 6/4/86	*/
/*	@(#)user.h	1.8 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_user_h
#define __sys_user_h

#ifndef __sys_param_h
#include "param.h"
#endif
#ifndef __machine_fp_h
#include "../machine/fp.h"
#endif
#ifndef __machine_pte_h
#include "../machine/pte.h"
#endif
#ifndef __sys_dmap_h
#include "dmap.h"
#endif
#ifndef __sys_time_h
#include "time.h"
#endif
#ifndef __sys_resource_h
#include "resource.h"
#endif
#ifndef __sys_ucred_h
#include "ucred.h"
#endif

/*
 * Per process structure containing data that
 * isn't needed in core when the process is swapped out.
 */
 
#define	MAXCOMLEN	16		/* <= MAXNAMLEN, >= sizeof(ac_comm) */
 
struct	user {
	int	u_reserved;		/* If non-zero the page containing this */
					/* u-area has been allocated to the     */
					/* buffer cache, and must not be freed. */
#define U_RES_RESERVED	0x00000100	/* This u-area page is reserved for buffers */
#define U_RES_INDEX	0x0000003f	/* index into reserved_u_pages[] */
#define U_RES_8K_MBUF_a	0x00000200	/* 8K chunk 'a' allocated to mbufs */
#define U_RES_8K_MBUF_b	0x00000400	/* 8K chunk 'b' allocated to mbufs */
#define U_RES_8K_MBUF_c	0x00000800	/* 8K chunk 'c' allocated to mbufs */
#define U_RES_8K_CACHEa	0x00002000	/* 8K chunk 'a' allocated to buffer cache */
#define U_RES_8K_CACHEb	0x00004000	/* 8K chunk 'b' allocated to buffer cache */
#define U_RES_8K_CACHEc	0x00008000	/* 8K chunk 'c' allocated to buffer cache */
	char    *u_trampoline_code;	/* -> the trampoline code on user stack */
					/* which is executed to deliver a signal */

	struct	fp_regs u_fp_regs;	/* Saved user FP registers              */
	struct {			/* Pending FP (asynchronous) trap       */
		int fp_trap;		/*   caused by context switcher         */
		int fp_code;		/*   needing to pre-emptively dump      */
	} u_fp_pending;			/*   FP registers non-running proc      */

	struct	proc *u_procp;		/* pointer to proc structure */

	int	*u_ar0;			/* address of users saved R0 */
	char	u_comm[MAXCOMLEN + 1];

	u_char	u_ast;			/* Deliver asynch-software-trap         */
	u_char	u_kernel_may_fault;	/* Set if a data abort is allowed while */
					/* in _KERNEL mode - else panic()        */
	u_char	u_syscalltrace;		/* trace this proc's system calls */

/* 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 */
	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;
	u_char	u_error;		/* return error code */
	u_char	u_eosys;		/* special action on end of syscall */

/* 1.1 - processes and protection */
	struct ucred *u_cred;
#define	u_uid		u_cred->cr_uid
#define	u_gid		u_cred->cr_gid
#define	u_ruid		u_cred->cr_ruid
#define	u_rgid		u_cred->cr_rgid
#define	u_suid		u_cred->cr_suid
#define	u_sgid		u_cred->cr_sgid
#define	u_groups	u_cred->cr_groups

/* 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) */
	struct	dmap u_dmap;		/* disk map for data segment */
	struct	dmap u_smap;		/* disk map for stack segment */
	struct	dmap u_cdmap, u_csmap;	/* shadows of u_dmap, u_smap, for
					   use of parent during fork */
	label_t u_context;		/* label variable for context changing */
	time_t	u_outime;		/* user time at last sample */

	int	*u_ustackbase;		/* -> user's stack base */
	int	*u_kstacklimit;		/* -> KERNEL stack limit */

	/*
	 * Unsqueezing structure pointers; the structures live on the
	 * user stack, or may at some future point live in the u page
	 * if the page is not reserved.  The tables are organised as
	 * the sq3 table followed immediately by the sq4 table, with
	 * u_unsqueeze_end pointing at the first byte beyond the sq4
	 * table: this simplifies pagein()'s handling of unsqueeze
	 * tables a little.
	 */
	struct sq_unsqueeze {
		int	sq_items;
		long	sq_table[7*256];
	} *u_unsqueeze3, *u_unsqueeze4;
	caddr_t u_unsqueeze_end;

/* 1.3 - signal management */
	_signal_proc u_signal[NSIG];	/* disposition of signals */
	int	u_sigmask[NSIG];	/* signals to be blocked */
	int	u_sigonstack;		/* signals to take on sigstack */
	int	u_sigintr;		/* signals that interrupt syscalls */
	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 */
	u_char	u_pofile[NOFILE];	/* per-process flags of open files */
#define	UF_EXCLOSE 	0x1		/* auto-close on exec */
#define	UF_MAPPED 	0x2		/* file mapped from device */
#define	UF_FDLOCK 	0x4		/* file desc locked (SysV style) */
#define	UF_FBMAP	0x8		/* file is a handle on frame buffer */
	char	u_lastfile;		/* high-water mark of u_ofile */
	u_char	u_fbhandles;		/* count of files which have UF_FBMAP */
	short	u_cmask;		/* mask for file creation */
	struct	vnode *u_cdir;		/* current directory */
	struct	vnode *u_rdir;		/* root directory of current process */
	struct	tty *u_ttyp;		/* controlling tty pointer */
	dev_t	u_ttyd;			/* controlling tty dev */

/* 1.5 - timing and statistics */
	short	u_acflag;
	struct	timeval u_start;

	struct	rusage u_ru;		/* stats for this proc */
	struct	rusage u_cru;		/* sum of stats for reaped children */
	struct	itimerval u_timer[3];

	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];

/* 1.9 - ptrace */
	long	u_trapaddr;		/* address of ptrace trapped instruction */
	long	u_trapinstr;		/* ptrace trapped instruction */

	/*
	 * The software page-table for a process now lives here, not
	 * in the proc structure.
	 */
	struct pte  u_pagetable[MAXPT];
};

/* u_eosys values */
#define	JUSTRETURN	1
#define	RESTARTSYS	2
#define NORMALRETURN	3

#ifndef __sys_errno_h
#include "errno.h"
#endif

#ifdef _KERNEL
extern	struct user u;
extern	struct user swaputl;
extern	struct user forkutl;
extern	struct user xswaputl;
extern	struct user xswap2utl;
extern	struct user pushutl;
extern	struct user vfutl;
#endif/*_KERNEL*/

#endif/*__sys_user_h*/
