xref: /onnv-gate/usr/src/uts/common/sys/klwp.h (revision 3930:59477feabc54)
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
52712Snn35248  * Common Development and Distribution License (the "License").
62712Snn35248  * 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*3930Snr123932  * 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 #ifndef	_SYS_KLWP_H
270Sstevel@tonic-gate #define	_SYS_KLWP_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include <sys/types.h>
320Sstevel@tonic-gate #include <sys/condvar.h>
330Sstevel@tonic-gate #include <sys/thread.h>
340Sstevel@tonic-gate #include <sys/signal.h>
350Sstevel@tonic-gate #include <sys/siginfo.h>
360Sstevel@tonic-gate #include <sys/pcb.h>
370Sstevel@tonic-gate #include <sys/time.h>
380Sstevel@tonic-gate #include <sys/msacct.h>
390Sstevel@tonic-gate #include <sys/ucontext.h>
400Sstevel@tonic-gate #include <sys/lwp.h>
410Sstevel@tonic-gate #include <sys/contract.h>
420Sstevel@tonic-gate 
430Sstevel@tonic-gate #if (defined(_KERNEL) || defined(_KMEMUSER)) && defined(_MACHDEP)
440Sstevel@tonic-gate #include <sys/machparam.h>
450Sstevel@tonic-gate #endif
460Sstevel@tonic-gate 
470Sstevel@tonic-gate #ifdef	__cplusplus
480Sstevel@tonic-gate extern "C" {
490Sstevel@tonic-gate #endif
500Sstevel@tonic-gate 
510Sstevel@tonic-gate /*
520Sstevel@tonic-gate  * The light-weight process object and the methods by which it
530Sstevel@tonic-gate  * is accessed.
540Sstevel@tonic-gate  */
550Sstevel@tonic-gate 
560Sstevel@tonic-gate #define	MAXSYSARGS	8	/* Maximum # of arguments passed to a syscall */
570Sstevel@tonic-gate 
580Sstevel@tonic-gate /* lwp_eosys values */
590Sstevel@tonic-gate #define	NORMALRETURN	0	/* normal return; adjusts PC, registers */
600Sstevel@tonic-gate #define	JUSTRETURN	1	/* just return, leave registers alone */
610Sstevel@tonic-gate 
620Sstevel@tonic-gate /*
630Sstevel@tonic-gate  * Resource usage, per-lwp plus per-process (sum over defunct lwps).
640Sstevel@tonic-gate  */
650Sstevel@tonic-gate struct lrusage {
660Sstevel@tonic-gate 	u_longlong_t	minflt;		/* minor page faults */
670Sstevel@tonic-gate 	u_longlong_t	majflt;		/* major page faults */
680Sstevel@tonic-gate 	u_longlong_t	nswap;		/* swaps */
690Sstevel@tonic-gate 	u_longlong_t	inblock;	/* input blocks */
700Sstevel@tonic-gate 	u_longlong_t	oublock;	/* output blocks */
710Sstevel@tonic-gate 	u_longlong_t	msgsnd;		/* messages sent */
720Sstevel@tonic-gate 	u_longlong_t	msgrcv;		/* messages received */
730Sstevel@tonic-gate 	u_longlong_t	nsignals;	/* signals received */
740Sstevel@tonic-gate 	u_longlong_t	nvcsw;		/* voluntary context switches */
750Sstevel@tonic-gate 	u_longlong_t	nivcsw;		/* involuntary context switches */
760Sstevel@tonic-gate 	u_longlong_t	sysc;		/* system calls */
770Sstevel@tonic-gate 	u_longlong_t	ioch;		/* chars read and written */
780Sstevel@tonic-gate };
790Sstevel@tonic-gate 
800Sstevel@tonic-gate typedef struct _klwp	*klwp_id_t;
810Sstevel@tonic-gate 
820Sstevel@tonic-gate typedef struct _klwp {
830Sstevel@tonic-gate 	/*
840Sstevel@tonic-gate 	 * user-mode context
850Sstevel@tonic-gate 	 */
860Sstevel@tonic-gate 	struct pcb	lwp_pcb;		/* user regs save pcb */
870Sstevel@tonic-gate 	uintptr_t	lwp_oldcontext;		/* previous user context */
880Sstevel@tonic-gate 
890Sstevel@tonic-gate 	/*
900Sstevel@tonic-gate 	 * system-call interface
910Sstevel@tonic-gate 	 */
920Sstevel@tonic-gate 	long	*lwp_ap;	/* pointer to arglist */
930Sstevel@tonic-gate 	int	lwp_errno;	/* error for current syscall (private) */
940Sstevel@tonic-gate 	/*
950Sstevel@tonic-gate 	 * support for I/O
960Sstevel@tonic-gate 	 */
970Sstevel@tonic-gate 	char	lwp_error;	/* return error code */
980Sstevel@tonic-gate 	char	lwp_eosys;	/* special action on end of syscall */
990Sstevel@tonic-gate 	char	lwp_argsaved;	/* are all args in lwp_arg */
1000Sstevel@tonic-gate 	char	lwp_watchtrap;	/* lwp undergoing watchpoint single-step */
1010Sstevel@tonic-gate 	long	lwp_arg[MAXSYSARGS];	/* args to current syscall */
1020Sstevel@tonic-gate 	void	*lwp_regs;	/* pointer to saved regs on stack */
1030Sstevel@tonic-gate 	void	*lwp_fpu;	/* pointer to fpu regs */
1040Sstevel@tonic-gate 	label_t	lwp_qsav;	/* longjmp label for quits and interrupts */
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate 	/*
1070Sstevel@tonic-gate 	 * signal handling and debugger (/proc) interface
1080Sstevel@tonic-gate 	 */
1090Sstevel@tonic-gate 	uchar_t	lwp_cursig;		/* current signal */
1100Sstevel@tonic-gate 	uchar_t	lwp_curflt;		/* current fault */
1110Sstevel@tonic-gate 	uchar_t	lwp_sysabort;		/* if set, abort syscall */
1120Sstevel@tonic-gate 	uchar_t	lwp_asleep;		/* lwp asleep in syscall */
1130Sstevel@tonic-gate 	uchar_t lwp_extsig;		/* cursig sent from another contract */
1140Sstevel@tonic-gate 	stack_t lwp_sigaltstack;	/* alternate signal stack */
1150Sstevel@tonic-gate 	struct sigqueue *lwp_curinfo;	/* siginfo for current signal */
1160Sstevel@tonic-gate 	k_siginfo_t	lwp_siginfo;	/* siginfo for stop-on-fault */
1170Sstevel@tonic-gate 	k_sigset_t	lwp_sigoldmask;	/* for sigsuspend */
1180Sstevel@tonic-gate 	struct lwp_watch {		/* used in watchpoint single-stepping */
1190Sstevel@tonic-gate 		caddr_t	wpaddr;
1200Sstevel@tonic-gate 		size_t	wpsize;
1210Sstevel@tonic-gate 		int	wpcode;
1220Sstevel@tonic-gate 		int	wpmapped;
1230Sstevel@tonic-gate 		greg_t	wppc;
1240Sstevel@tonic-gate 	} lwp_watch[4];		/* one for each of exec/write/read/read */
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate 	uint32_t lwp_oweupc;		/* profil(2) ticks owed to this lwp */
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate 	/*
1290Sstevel@tonic-gate 	 * Microstate accounting.  Timestamps are made at the start and the
1300Sstevel@tonic-gate 	 * end of each microstate (see <sys/msacct.h> for state definitions)
1310Sstevel@tonic-gate 	 * and the corresponding accounting info is updated.  The current
1320Sstevel@tonic-gate 	 * microstate is kept in the thread struct, since there are cases
1330Sstevel@tonic-gate 	 * when one thread must update another thread's state (a no-no
1340Sstevel@tonic-gate 	 * for an lwp since it may be swapped/paged out).  The rest of the
1350Sstevel@tonic-gate 	 * microstate stuff is kept here to avoid wasting space on things
1360Sstevel@tonic-gate 	 * like kernel threads that don't have an associated lwp.
1370Sstevel@tonic-gate 	 */
1380Sstevel@tonic-gate 	struct mstate {
1390Sstevel@tonic-gate 		int ms_prev;			/* previous running mstate */
1400Sstevel@tonic-gate 		hrtime_t ms_start;		/* lwp creation time */
1410Sstevel@tonic-gate 		hrtime_t ms_term;		/* lwp termination time */
1420Sstevel@tonic-gate 		hrtime_t ms_state_start;	/* start time of this mstate */
1430Sstevel@tonic-gate 		hrtime_t ms_acct[NMSTATES];	/* per mstate accounting */
1440Sstevel@tonic-gate 	} lwp_mstate;
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate 	/*
1470Sstevel@tonic-gate 	 * Per-lwp resource usage.
1480Sstevel@tonic-gate 	 */
1490Sstevel@tonic-gate 	struct lrusage lwp_ru;
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate 	/*
1520Sstevel@tonic-gate 	 * Things to keep for real-time (SIGPROF) profiling.
1530Sstevel@tonic-gate 	 */
1540Sstevel@tonic-gate 	int	lwp_lastfault;
1550Sstevel@tonic-gate 	caddr_t	lwp_lastfaddr;
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate 	/*
1580Sstevel@tonic-gate 	 * timers. Protected by lwp->procp->p_lock
1590Sstevel@tonic-gate 	 */
1600Sstevel@tonic-gate 	struct itimerval lwp_timer[3];
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate 	/*
163*3930Snr123932 	 * used to stop/alert lwps
1640Sstevel@tonic-gate 	 */
1650Sstevel@tonic-gate 	char	lwp_unused;
1660Sstevel@tonic-gate 	char	lwp_state;	/* Running in User/Kernel mode (no lock req) */
167*3930Snr123932 	ushort_t lwp_nostop;	/* Don't stop this lwp (no lock required) */
168*3930Snr123932 	ushort_t lwp_pad;	/* Reserved for future use */
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate 	/*
1710Sstevel@tonic-gate 	 * Last failed privilege.
1720Sstevel@tonic-gate 	 */
1730Sstevel@tonic-gate 	short	lwp_badpriv;
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate 	/*
1760Sstevel@tonic-gate 	 * linkage
1770Sstevel@tonic-gate 	 */
1780Sstevel@tonic-gate 	struct _kthread	*lwp_thread;
1790Sstevel@tonic-gate 	struct proc	*lwp_procp;
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate 	size_t lwp_childstksz;	/* kernel stksize for this lwp's descendants */
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate 	uintptr_t	lwp_ustack;		/* current stack bounds */
1840Sstevel@tonic-gate 	size_t		lwp_old_stk_ctl;	/* old stack limit */
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate 	/*
1870Sstevel@tonic-gate 	 * Contracts
1880Sstevel@tonic-gate 	 */
1890Sstevel@tonic-gate 	struct ct_template *lwp_ct_active[CTT_MAXTYPE]; /* active templates */
1900Sstevel@tonic-gate 	struct contract	*lwp_ct_latest[CTT_MAXTYPE]; /* last created contract */
1912712Snn35248 
1922712Snn35248 	void	*lwp_brand;		/* per-lwp brand data */
1930Sstevel@tonic-gate } klwp_t;
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate /* lwp states */
1960Sstevel@tonic-gate #define	LWP_USER	0x01		/* Running in user mode */
1970Sstevel@tonic-gate #define	LWP_SYS		0x02		/* Running in kernel mode */
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate #if	defined(_KERNEL)
2000Sstevel@tonic-gate extern	int	lwp_default_stksize;
2010Sstevel@tonic-gate extern	int	lwp_reapcnt;
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate extern	struct _kthread *lwp_deathrow;
2040Sstevel@tonic-gate extern	kmutex_t	reaplock;
2050Sstevel@tonic-gate extern	struct kmem_cache *lwp_cache;
2060Sstevel@tonic-gate extern	void		*segkp_lwp;
2070Sstevel@tonic-gate extern	klwp_t		lwp0;
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate /* where newly-created lwps normally start */
2100Sstevel@tonic-gate extern	void	lwp_rtt(void);
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate #endif	/* _KERNEL */
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate #ifdef	__cplusplus
2150Sstevel@tonic-gate }
2160Sstevel@tonic-gate #endif
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate #endif	/* _SYS_KLWP_H */
219