xref: /onnv-gate/usr/src/uts/common/sys/user.h (revision 3446:5903aece022d)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51846Scraigm  * Common Development and Distribution License (the "License").
61846Scraigm  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*3446Smrj  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
270Sstevel@tonic-gate /*	  All Rights Reserved	*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #ifndef _SYS_USER_H
310Sstevel@tonic-gate #define	_SYS_USER_H
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #include <sys/types.h>
360Sstevel@tonic-gate #include <sys/signal.h>
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #ifdef	__cplusplus
390Sstevel@tonic-gate extern "C" {
400Sstevel@tonic-gate #endif
410Sstevel@tonic-gate 
420Sstevel@tonic-gate /*
430Sstevel@tonic-gate  * struct exdata is visible in and out of the kernel. This is because it
440Sstevel@tonic-gate  * is referenced in <sys/core.h> which doesn't have this kind of magic.
450Sstevel@tonic-gate  */
460Sstevel@tonic-gate struct exdata {
470Sstevel@tonic-gate 	struct vnode	*vp;
480Sstevel@tonic-gate 	size_t	ux_tsize;	/* text size */
490Sstevel@tonic-gate 	size_t	ux_dsize;	/* data size */
500Sstevel@tonic-gate 	size_t	ux_bsize;	/* bss size */
510Sstevel@tonic-gate 	size_t	ux_lsize;	/* lib size */
520Sstevel@tonic-gate 	long	ux_nshlibs;	/* number of shared libs needed */
530Sstevel@tonic-gate 	short	ux_mach;	/* machine type */
540Sstevel@tonic-gate 	short	ux_mag;		/* magic number MUST be here */
550Sstevel@tonic-gate 	off_t	ux_toffset;	/* file offset to raw text */
560Sstevel@tonic-gate 	off_t	ux_doffset;	/* file offset to raw data */
570Sstevel@tonic-gate 	off_t	ux_loffset;	/* file offset to lib sctn */
580Sstevel@tonic-gate 	caddr_t	ux_txtorg;	/* start addr of text in mem */
590Sstevel@tonic-gate 	caddr_t	ux_datorg;	/* start addr of data in mem */
600Sstevel@tonic-gate 	caddr_t	ux_entloc;	/* entry location */
610Sstevel@tonic-gate };
620Sstevel@tonic-gate 
630Sstevel@tonic-gate #ifdef	__cplusplus
640Sstevel@tonic-gate }
650Sstevel@tonic-gate #endif
660Sstevel@tonic-gate 
670Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER)
680Sstevel@tonic-gate 
690Sstevel@tonic-gate #include <sys/param.h>
700Sstevel@tonic-gate #include <sys/pcb.h>
710Sstevel@tonic-gate #include <sys/siginfo.h>
720Sstevel@tonic-gate #include <sys/resource.h>
730Sstevel@tonic-gate #include <sys/time.h>
740Sstevel@tonic-gate #include <sys/auxv.h>
750Sstevel@tonic-gate #include <sys/errno.h>
760Sstevel@tonic-gate #include <sys/t_lock.h>
770Sstevel@tonic-gate #include <sys/refstr.h>
780Sstevel@tonic-gate 
790Sstevel@tonic-gate #ifdef	__cplusplus
800Sstevel@tonic-gate extern "C" {
810Sstevel@tonic-gate #endif
820Sstevel@tonic-gate 
830Sstevel@tonic-gate /*
840Sstevel@tonic-gate  * Entry in the per-process list of open files.
850Sstevel@tonic-gate  * Note: only certain fields are copied in flist_grow() and flist_fork().
860Sstevel@tonic-gate  * This is indicated in brackets in the structure member comments.
870Sstevel@tonic-gate  */
880Sstevel@tonic-gate typedef struct uf_entry {
890Sstevel@tonic-gate 	kmutex_t	uf_lock;	/* per-fd lock [never copied] */
900Sstevel@tonic-gate 	struct file	*uf_file;	/* file pointer [grow, fork] */
910Sstevel@tonic-gate 	struct fpollinfo *uf_fpollinfo;	/* poll state [grow] */
920Sstevel@tonic-gate 	int		uf_refcnt;	/* LWPs accessing this file [grow] */
930Sstevel@tonic-gate 	int		uf_alloc;	/* right subtree allocs [grow, fork] */
940Sstevel@tonic-gate 	short		uf_flag;	/* fcntl F_GETFD flags [grow, fork] */
950Sstevel@tonic-gate 	short		uf_busy;	/* file is allocated [grow, fork] */
960Sstevel@tonic-gate 	kcondvar_t	uf_wanted_cv;	/* waiting for setf() [never copied] */
970Sstevel@tonic-gate 	kcondvar_t	uf_closing_cv;	/* waiting for close() [never copied] */
980Sstevel@tonic-gate 	struct portfd 	*uf_portfd;	/* associated with port [grow] */
990Sstevel@tonic-gate 	/* Avoid false sharing - pad to coherency granularity (64 bytes) */
1000Sstevel@tonic-gate 	char		uf_pad[64 - sizeof (kmutex_t) - 2 * sizeof (void*) -
1010Sstevel@tonic-gate 		2 * sizeof (int) - 2 * sizeof (short) -
1020Sstevel@tonic-gate 		2 * sizeof (kcondvar_t) - sizeof (struct portfd *)];
1030Sstevel@tonic-gate } uf_entry_t;
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate /*
1060Sstevel@tonic-gate  * Retired file lists -- see flist_grow() for details.
1070Sstevel@tonic-gate  */
1080Sstevel@tonic-gate typedef struct uf_rlist {
1090Sstevel@tonic-gate 	struct uf_rlist	*ur_next;
1100Sstevel@tonic-gate 	uf_entry_t	*ur_list;
1110Sstevel@tonic-gate 	int		ur_nfiles;
1120Sstevel@tonic-gate } uf_rlist_t;
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate /*
1150Sstevel@tonic-gate  * Per-process file information.
1160Sstevel@tonic-gate  */
1170Sstevel@tonic-gate typedef struct uf_info {
1180Sstevel@tonic-gate 	kmutex_t	fi_lock;	/* see below */
1191846Scraigm 	int		fi_badfd;	/* bad file descriptor # */
1201846Scraigm 	int		fi_action;	/* action to take on bad fd use */
1210Sstevel@tonic-gate 	int		fi_nfiles;	/* number of entries in fi_list[] */
1220Sstevel@tonic-gate 	uf_entry_t *volatile fi_list;	/* current file list */
1230Sstevel@tonic-gate 	uf_rlist_t	*fi_rlist;	/* retired file lists */
1240Sstevel@tonic-gate } uf_info_t;
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate /*
1270Sstevel@tonic-gate  * File list locking.
1280Sstevel@tonic-gate  *
1290Sstevel@tonic-gate  * Each process has a list of open files, fi_list, indexed by fd.
1300Sstevel@tonic-gate  * fi_list is an array of uf_entry_t structures, each with its own lock.
1310Sstevel@tonic-gate  * One might think that the correct way to lock a file descriptor would be:
1320Sstevel@tonic-gate  *
1330Sstevel@tonic-gate  *	ufp = fip->fi_list[fd];
1340Sstevel@tonic-gate  *	mutex_enter(&ufp->uf_lock);
1350Sstevel@tonic-gate  *
1360Sstevel@tonic-gate  * However, that construct is only safe if fi_lock is already held.  If not,
1370Sstevel@tonic-gate  * fi_list can change in the window between loading ufp and entering uf_lock.
1380Sstevel@tonic-gate  * The UF_ENTER() macro deals with this possibility.  UF_ENTER(ufp, fip, fd)
1390Sstevel@tonic-gate  * locks fd and sets ufp to fd's uf_entry.  The locking rules are as follows:
1400Sstevel@tonic-gate  *
1410Sstevel@tonic-gate  * (1) fi_lock protects fi_list and fi_nfiles.  It also protects the
1420Sstevel@tonic-gate  *     uf_alloc and uf_busy fields of every fd's ufp; see fd_find() for
1430Sstevel@tonic-gate  *     details on file descriptor allocation.
1440Sstevel@tonic-gate  *
1450Sstevel@tonic-gate  * (2) UF_ENTER(ufp, fip, fd) locks descriptor fd and sets ufp to point
1460Sstevel@tonic-gate  *     to the uf_entry_t for fd.  UF_ENTER() protects all fields in ufp
1470Sstevel@tonic-gate  *     except uf_alloc and uf_busy.  UF_ENTER(ufp, fip, fd) also prevents
1480Sstevel@tonic-gate  *     ufp->uf_alloc, ufp->uf_busy, fip->fi_list and fip->fi_nfiles from
1490Sstevel@tonic-gate  *     changing.
1500Sstevel@tonic-gate  *
1510Sstevel@tonic-gate  * (3) The lock ordering is (1), (2).
1520Sstevel@tonic-gate  *
1530Sstevel@tonic-gate  * (4) Note that fip->fi_list and fip->fi_nfiles cannot change while *any*
1540Sstevel@tonic-gate  *     file list lock is held.  Thus flist_grow() must acquire all such
1550Sstevel@tonic-gate  *     locks -- fi_lock and every fd's uf_lock -- to install a new file list.
1560Sstevel@tonic-gate  */
1570Sstevel@tonic-gate #define	UF_ENTER(ufp, fip, fd)					\
1580Sstevel@tonic-gate 	for (;;) {						\
1590Sstevel@tonic-gate 		uf_entry_t *_flist = (fip)->fi_list;		\
1600Sstevel@tonic-gate 		ufp = &_flist[fd];				\
1610Sstevel@tonic-gate 		ASSERT((fd) < (fip)->fi_nfiles);		\
1620Sstevel@tonic-gate 		mutex_enter(&ufp->uf_lock);			\
1630Sstevel@tonic-gate 		if (_flist == (fip)->fi_list)			\
1640Sstevel@tonic-gate 			break;					\
1650Sstevel@tonic-gate 		mutex_exit(&ufp->uf_lock);			\
1660Sstevel@tonic-gate 	}
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate #define	UF_EXIT(ufp)	mutex_exit(&ufp->uf_lock)
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate #define	PSARGSZ		80	/* Space for exec arguments (used by ps(1)) */
1710Sstevel@tonic-gate #define	MAXCOMLEN	16	/* <= MAXNAMLEN, >= sizeof (ac_comm) */
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate typedef struct {		/* kernel syscall set type */
1740Sstevel@tonic-gate 	uint_t	word[9];	/* space for syscall numbers [1..288] */
1750Sstevel@tonic-gate } k_sysset_t;
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate /*
1780Sstevel@tonic-gate  * __KERN_NAUXV_IMPL is defined as a convenience sizing mechanism
1790Sstevel@tonic-gate  * for the portions of the kernel that care about aux vectors.
1800Sstevel@tonic-gate  *
1810Sstevel@tonic-gate  * Applications that need to know how many aux vectors the kernel
1820Sstevel@tonic-gate  * supplies should use the proc(4) interface to read /proc/PID/auxv.
1830Sstevel@tonic-gate  *
1840Sstevel@tonic-gate  * This value should not be changed in a patch.
1850Sstevel@tonic-gate  */
1860Sstevel@tonic-gate #if defined(__sparc)
1870Sstevel@tonic-gate #define	__KERN_NAUXV_IMPL 19
1880Sstevel@tonic-gate #elif defined(__i386) || defined(__amd64)
1890Sstevel@tonic-gate #define	__KERN_NAUXV_IMPL 21
1900Sstevel@tonic-gate #endif
1910Sstevel@tonic-gate 
1920Sstevel@tonic-gate struct execsw;
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate /*
1950Sstevel@tonic-gate  * The user structure; one allocated per process.  Contains all the
1960Sstevel@tonic-gate  * per-process data that doesn't need to be referenced while the
1970Sstevel@tonic-gate  * process is swapped.
1980Sstevel@tonic-gate  */
1990Sstevel@tonic-gate typedef	struct	user {
2000Sstevel@tonic-gate 	/*
2010Sstevel@tonic-gate 	 * These fields are initialized at process creation time and never
2020Sstevel@tonic-gate 	 * modified.  They can be accessed without acquiring locks.
2030Sstevel@tonic-gate 	 */
2040Sstevel@tonic-gate 	struct execsw *u_execsw;	/* pointer to exec switch entry */
2050Sstevel@tonic-gate 	auxv_t  u_auxv[__KERN_NAUXV_IMPL]; /* aux vector from exec */
2060Sstevel@tonic-gate 	timestruc_t u_start;		/* hrestime at process start */
2070Sstevel@tonic-gate 	clock_t	u_ticks;		/* lbolt at process start */
2080Sstevel@tonic-gate 	char	u_comm[MAXCOMLEN + 1];	/* executable file name from exec */
2090Sstevel@tonic-gate 	char	u_psargs[PSARGSZ];	/* arguments from exec */
2100Sstevel@tonic-gate 	int	u_argc;			/* value of argc passed to main() */
2110Sstevel@tonic-gate 	uintptr_t u_argv;		/* value of argv passed to main() */
2120Sstevel@tonic-gate 	uintptr_t u_envp;		/* value of envp passed to main() */
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate 	/*
2150Sstevel@tonic-gate 	 * These fields are protected by p_lock:
2160Sstevel@tonic-gate 	 */
2170Sstevel@tonic-gate 	struct vnode *u_cdir;		/* current directory */
2180Sstevel@tonic-gate 	struct vnode *u_rdir;		/* root directory */
2190Sstevel@tonic-gate 	uint64_t u_mem;			/* accumulated memory usage */
2200Sstevel@tonic-gate 	size_t	u_mem_max;		/* peak RSS (K) */
2210Sstevel@tonic-gate 	mode_t	u_cmask;		/* mask for file creation */
2220Sstevel@tonic-gate 	char	u_acflag;		/* accounting flag */
2230Sstevel@tonic-gate 	char	u_systrap;		/* /proc: any syscall mask bits set? */
2240Sstevel@tonic-gate 	refstr_t *u_cwd;		/* cached string for cwd */
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate 	k_sysset_t u_entrymask;		/* /proc syscall stop-on-entry mask */
2270Sstevel@tonic-gate 	k_sysset_t u_exitmask;		/* /proc syscall stop-on-exit mask */
2280Sstevel@tonic-gate 	k_sigset_t u_signodefer;	/* signals defered when caught */
2290Sstevel@tonic-gate 	k_sigset_t u_sigonstack;	/* signals taken on alternate stack */
2300Sstevel@tonic-gate 	k_sigset_t u_sigresethand;	/* signals reset when caught */
2310Sstevel@tonic-gate 	k_sigset_t u_sigrestart;	/* signals that restart system calls */
2320Sstevel@tonic-gate 	k_sigset_t u_sigmask[MAXSIG];	/* signals held while in catcher */
2330Sstevel@tonic-gate 	void	(*u_signal[MAXSIG])();	/* Disposition of signals */
2340Sstevel@tonic-gate 
2350Sstevel@tonic-gate 	/*
2360Sstevel@tonic-gate 	 * Resource controls provide the backend for process resource limits,
2370Sstevel@tonic-gate 	 * the interfaces for which are maintained for compatibility.  To
2380Sstevel@tonic-gate 	 * preserve the behaviour associated with the RLIM_SAVED_CUR and
2390Sstevel@tonic-gate 	 * RLIM_SAVED_MAX tokens, we retain the "saved" rlimits.
2400Sstevel@tonic-gate 	 */
2410Sstevel@tonic-gate 	struct rlimit64	u_saved_rlimit[RLIM_NSAVED];
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate 	uf_info_t	u_finfo;	/* open file information */
2440Sstevel@tonic-gate } user_t;
2450Sstevel@tonic-gate 
2460Sstevel@tonic-gate #include <sys/proc.h>			/* cannot include before user defined */
2470Sstevel@tonic-gate 
2480Sstevel@tonic-gate #ifdef	_KERNEL
2490Sstevel@tonic-gate #define	P_FINFO(p)	(&(p)->p_user.u_finfo)
2500Sstevel@tonic-gate #endif	/* _KERNEL */
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate #ifdef	__cplusplus
2530Sstevel@tonic-gate }
2540Sstevel@tonic-gate #endif
2550Sstevel@tonic-gate 
2560Sstevel@tonic-gate #else	/* defined(_KERNEL) || defined(_KMEMUSER) */
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate /*
2590Sstevel@tonic-gate  * Here, we define a fake version of struct user for programs
2600Sstevel@tonic-gate  * (debuggers) that use ptrace() to read and modify the saved
2610Sstevel@tonic-gate  * registers directly in the u-area.  ptrace() has been removed
2620Sstevel@tonic-gate  * from the operating system and now exists as a library function
2630Sstevel@tonic-gate  * in libc, built on the /proc process filesystem.  The ptrace()
2640Sstevel@tonic-gate  * library function provides access only to the members of the
2650Sstevel@tonic-gate  * fake struct user defined here.
2660Sstevel@tonic-gate  *
2670Sstevel@tonic-gate  * User-level programs that must know the real contents of struct
2680Sstevel@tonic-gate  * user will have to define _KMEMUSER before including <sys/user.h>.
2690Sstevel@tonic-gate  * Such programs also become machine specific. Carefully consider
2700Sstevel@tonic-gate  * the consequences of your actions.
2710Sstevel@tonic-gate  */
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate #include <sys/regset.h>
2740Sstevel@tonic-gate 
2750Sstevel@tonic-gate #ifdef	__cplusplus
2760Sstevel@tonic-gate extern "C" {
2770Sstevel@tonic-gate #endif
2780Sstevel@tonic-gate 
2790Sstevel@tonic-gate #define	PSARGSZ		80	/* Space for exec arguments (used by ps(1)) */
2800Sstevel@tonic-gate 
2810Sstevel@tonic-gate typedef	struct	user {
2820Sstevel@tonic-gate 	gregset_t	u_reg;		/* user's saved registers */
2830Sstevel@tonic-gate 	greg_t		*u_ar0;		/* address of user's saved R0 */
2840Sstevel@tonic-gate 	char	u_psargs[PSARGSZ];	/* arguments from exec */
2850Sstevel@tonic-gate 	void	(*u_signal[MAXSIG])();	/* Disposition of signals */
2860Sstevel@tonic-gate 	int		u_code;		/* fault code on trap */
2870Sstevel@tonic-gate 	caddr_t		u_addr;		/* fault PC on trap */
2880Sstevel@tonic-gate } user_t;
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate #ifdef	__cplusplus
2910Sstevel@tonic-gate }
2920Sstevel@tonic-gate #endif
2930Sstevel@tonic-gate 
2940Sstevel@tonic-gate #endif	/* defined(_KERNEL) || defined(_KMEMUSER) */
2950Sstevel@tonic-gate 
2960Sstevel@tonic-gate #endif	/* _SYS_USER_H */
297