xref: /illumos-gate/usr/src/uts/common/sys/klwp.h (revision f971a346)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
59acbbeafSnn35248  * Common Development and Distribution License (the "License").
69acbbeafSnn35248  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
228548bf79Snr123932  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
26*f971a346SBryan Cantrill /*
27*f971a346SBryan Cantrill  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
28*f971a346SBryan Cantrill  */
29*f971a346SBryan Cantrill 
307c478bd9Sstevel@tonic-gate #ifndef	_SYS_KLWP_H
317c478bd9Sstevel@tonic-gate #define	_SYS_KLWP_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <sys/condvar.h>
357c478bd9Sstevel@tonic-gate #include <sys/thread.h>
367c478bd9Sstevel@tonic-gate #include <sys/signal.h>
377c478bd9Sstevel@tonic-gate #include <sys/siginfo.h>
387c478bd9Sstevel@tonic-gate #include <sys/pcb.h>
397c478bd9Sstevel@tonic-gate #include <sys/time.h>
407c478bd9Sstevel@tonic-gate #include <sys/msacct.h>
417c478bd9Sstevel@tonic-gate #include <sys/ucontext.h>
427c478bd9Sstevel@tonic-gate #include <sys/lwp.h>
437c478bd9Sstevel@tonic-gate #include <sys/contract.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #if (defined(_KERNEL) || defined(_KMEMUSER)) && defined(_MACHDEP)
467c478bd9Sstevel@tonic-gate #include <sys/machparam.h>
477c478bd9Sstevel@tonic-gate #endif
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
507c478bd9Sstevel@tonic-gate extern "C" {
517c478bd9Sstevel@tonic-gate #endif
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate  * The light-weight process object and the methods by which it
557c478bd9Sstevel@tonic-gate  * is accessed.
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate #define	MAXSYSARGS	8	/* Maximum # of arguments passed to a syscall */
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /* lwp_eosys values */
617c478bd9Sstevel@tonic-gate #define	NORMALRETURN	0	/* normal return; adjusts PC, registers */
627c478bd9Sstevel@tonic-gate #define	JUSTRETURN	1	/* just return, leave registers alone */
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate  * Resource usage, per-lwp plus per-process (sum over defunct lwps).
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate struct lrusage {
687c478bd9Sstevel@tonic-gate 	u_longlong_t	minflt;		/* minor page faults */
697c478bd9Sstevel@tonic-gate 	u_longlong_t	majflt;		/* major page faults */
707c478bd9Sstevel@tonic-gate 	u_longlong_t	nswap;		/* swaps */
717c478bd9Sstevel@tonic-gate 	u_longlong_t	inblock;	/* input blocks */
727c478bd9Sstevel@tonic-gate 	u_longlong_t	oublock;	/* output blocks */
737c478bd9Sstevel@tonic-gate 	u_longlong_t	msgsnd;		/* messages sent */
747c478bd9Sstevel@tonic-gate 	u_longlong_t	msgrcv;		/* messages received */
757c478bd9Sstevel@tonic-gate 	u_longlong_t	nsignals;	/* signals received */
767c478bd9Sstevel@tonic-gate 	u_longlong_t	nvcsw;		/* voluntary context switches */
777c478bd9Sstevel@tonic-gate 	u_longlong_t	nivcsw;		/* involuntary context switches */
787c478bd9Sstevel@tonic-gate 	u_longlong_t	sysc;		/* system calls */
797c478bd9Sstevel@tonic-gate 	u_longlong_t	ioch;		/* chars read and written */
807c478bd9Sstevel@tonic-gate };
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate typedef struct _klwp	*klwp_id_t;
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate typedef struct _klwp {
857c478bd9Sstevel@tonic-gate 	/*
867c478bd9Sstevel@tonic-gate 	 * user-mode context
877c478bd9Sstevel@tonic-gate 	 */
887c478bd9Sstevel@tonic-gate 	struct pcb	lwp_pcb;		/* user regs save pcb */
897c478bd9Sstevel@tonic-gate 	uintptr_t	lwp_oldcontext;		/* previous user context */
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate 	/*
927c478bd9Sstevel@tonic-gate 	 * system-call interface
937c478bd9Sstevel@tonic-gate 	 */
947c478bd9Sstevel@tonic-gate 	long	*lwp_ap;	/* pointer to arglist */
957c478bd9Sstevel@tonic-gate 	int	lwp_errno;	/* error for current syscall (private) */
967c478bd9Sstevel@tonic-gate 	/*
977c478bd9Sstevel@tonic-gate 	 * support for I/O
987c478bd9Sstevel@tonic-gate 	 */
997c478bd9Sstevel@tonic-gate 	char	lwp_error;	/* return error code */
1007c478bd9Sstevel@tonic-gate 	char	lwp_eosys;	/* special action on end of syscall */
1017c478bd9Sstevel@tonic-gate 	char	lwp_argsaved;	/* are all args in lwp_arg */
1027c478bd9Sstevel@tonic-gate 	char	lwp_watchtrap;	/* lwp undergoing watchpoint single-step */
1037c478bd9Sstevel@tonic-gate 	long	lwp_arg[MAXSYSARGS];	/* args to current syscall */
1047c478bd9Sstevel@tonic-gate 	void	*lwp_regs;	/* pointer to saved regs on stack */
1057c478bd9Sstevel@tonic-gate 	void	*lwp_fpu;	/* pointer to fpu regs */
1067c478bd9Sstevel@tonic-gate 	label_t	lwp_qsav;	/* longjmp label for quits and interrupts */
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 	/*
1097c478bd9Sstevel@tonic-gate 	 * signal handling and debugger (/proc) interface
1107c478bd9Sstevel@tonic-gate 	 */
1117c478bd9Sstevel@tonic-gate 	uchar_t	lwp_cursig;		/* current signal */
1127c478bd9Sstevel@tonic-gate 	uchar_t	lwp_curflt;		/* current fault */
1137c478bd9Sstevel@tonic-gate 	uchar_t	lwp_sysabort;		/* if set, abort syscall */
1147c478bd9Sstevel@tonic-gate 	uchar_t	lwp_asleep;		/* lwp asleep in syscall */
1157c478bd9Sstevel@tonic-gate 	uchar_t lwp_extsig;		/* cursig sent from another contract */
1167c478bd9Sstevel@tonic-gate 	stack_t lwp_sigaltstack;	/* alternate signal stack */
1177c478bd9Sstevel@tonic-gate 	struct sigqueue *lwp_curinfo;	/* siginfo for current signal */
1187c478bd9Sstevel@tonic-gate 	k_siginfo_t	lwp_siginfo;	/* siginfo for stop-on-fault */
1197c478bd9Sstevel@tonic-gate 	k_sigset_t	lwp_sigoldmask;	/* for sigsuspend */
1207c478bd9Sstevel@tonic-gate 	struct lwp_watch {		/* used in watchpoint single-stepping */
1217c478bd9Sstevel@tonic-gate 		caddr_t	wpaddr;
1227c478bd9Sstevel@tonic-gate 		size_t	wpsize;
1237c478bd9Sstevel@tonic-gate 		int	wpcode;
1247c478bd9Sstevel@tonic-gate 		int	wpmapped;
1257c478bd9Sstevel@tonic-gate 		greg_t	wppc;
1267c478bd9Sstevel@tonic-gate 	} lwp_watch[4];		/* one for each of exec/write/read/read */
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 	uint32_t lwp_oweupc;		/* profil(2) ticks owed to this lwp */
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	/*
1317c478bd9Sstevel@tonic-gate 	 * Microstate accounting.  Timestamps are made at the start and the
1327c478bd9Sstevel@tonic-gate 	 * end of each microstate (see <sys/msacct.h> for state definitions)
1337c478bd9Sstevel@tonic-gate 	 * and the corresponding accounting info is updated.  The current
1347c478bd9Sstevel@tonic-gate 	 * microstate is kept in the thread struct, since there are cases
1357c478bd9Sstevel@tonic-gate 	 * when one thread must update another thread's state (a no-no
1367c478bd9Sstevel@tonic-gate 	 * for an lwp since it may be swapped/paged out).  The rest of the
1377c478bd9Sstevel@tonic-gate 	 * microstate stuff is kept here to avoid wasting space on things
1387c478bd9Sstevel@tonic-gate 	 * like kernel threads that don't have an associated lwp.
1397c478bd9Sstevel@tonic-gate 	 */
1407c478bd9Sstevel@tonic-gate 	struct mstate {
1417c478bd9Sstevel@tonic-gate 		int ms_prev;			/* previous running mstate */
1427c478bd9Sstevel@tonic-gate 		hrtime_t ms_start;		/* lwp creation time */
1437c478bd9Sstevel@tonic-gate 		hrtime_t ms_term;		/* lwp termination time */
1447c478bd9Sstevel@tonic-gate 		hrtime_t ms_state_start;	/* start time of this mstate */
1457c478bd9Sstevel@tonic-gate 		hrtime_t ms_acct[NMSTATES];	/* per mstate accounting */
1467c478bd9Sstevel@tonic-gate 	} lwp_mstate;
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 	/*
1497c478bd9Sstevel@tonic-gate 	 * Per-lwp resource usage.
1507c478bd9Sstevel@tonic-gate 	 */
1517c478bd9Sstevel@tonic-gate 	struct lrusage lwp_ru;
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate 	/*
1547c478bd9Sstevel@tonic-gate 	 * Things to keep for real-time (SIGPROF) profiling.
1557c478bd9Sstevel@tonic-gate 	 */
1567c478bd9Sstevel@tonic-gate 	int	lwp_lastfault;
1577c478bd9Sstevel@tonic-gate 	caddr_t	lwp_lastfaddr;
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	/*
1607c478bd9Sstevel@tonic-gate 	 * timers. Protected by lwp->procp->p_lock
1617c478bd9Sstevel@tonic-gate 	 */
1627c478bd9Sstevel@tonic-gate 	struct itimerval lwp_timer[3];
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	/*
1658548bf79Snr123932 	 * used to stop/alert lwps
1667c478bd9Sstevel@tonic-gate 	 */
1677c478bd9Sstevel@tonic-gate 	char	lwp_unused;
1687c478bd9Sstevel@tonic-gate 	char	lwp_state;	/* Running in User/Kernel mode (no lock req) */
1698548bf79Snr123932 	ushort_t lwp_nostop;	/* Don't stop this lwp (no lock required) */
1708548bf79Snr123932 	ushort_t lwp_pad;	/* Reserved for future use */
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 	/*
1737c478bd9Sstevel@tonic-gate 	 * Last failed privilege.
1747c478bd9Sstevel@tonic-gate 	 */
1757c478bd9Sstevel@tonic-gate 	short	lwp_badpriv;
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	/*
1787c478bd9Sstevel@tonic-gate 	 * linkage
1797c478bd9Sstevel@tonic-gate 	 */
1807c478bd9Sstevel@tonic-gate 	struct _kthread	*lwp_thread;
1817c478bd9Sstevel@tonic-gate 	struct proc	*lwp_procp;
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate 	size_t lwp_childstksz;	/* kernel stksize for this lwp's descendants */
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	uintptr_t	lwp_ustack;		/* current stack bounds */
1867c478bd9Sstevel@tonic-gate 	size_t		lwp_old_stk_ctl;	/* old stack limit */
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate 	/*
1897c478bd9Sstevel@tonic-gate 	 * Contracts
1907c478bd9Sstevel@tonic-gate 	 */
1917c478bd9Sstevel@tonic-gate 	struct ct_template *lwp_ct_active[CTT_MAXTYPE]; /* active templates */
1927c478bd9Sstevel@tonic-gate 	struct contract	*lwp_ct_latest[CTT_MAXTYPE]; /* last created contract */
1939acbbeafSnn35248 
1949acbbeafSnn35248 	void	*lwp_brand;		/* per-lwp brand data */
195*f971a346SBryan Cantrill 	struct psinfo *lwp_spymaster;	/* if an agent LWP, our spymaster */
1967c478bd9Sstevel@tonic-gate } klwp_t;
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate /* lwp states */
1997c478bd9Sstevel@tonic-gate #define	LWP_USER	0x01		/* Running in user mode */
2007c478bd9Sstevel@tonic-gate #define	LWP_SYS		0x02		/* Running in kernel mode */
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate #if	defined(_KERNEL)
2037c478bd9Sstevel@tonic-gate extern	int	lwp_default_stksize;
2047c478bd9Sstevel@tonic-gate extern	int	lwp_reapcnt;
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate extern	struct _kthread *lwp_deathrow;
2077c478bd9Sstevel@tonic-gate extern	kmutex_t	reaplock;
2087c478bd9Sstevel@tonic-gate extern	struct kmem_cache *lwp_cache;
2097c478bd9Sstevel@tonic-gate extern	void		*segkp_lwp;
2107c478bd9Sstevel@tonic-gate extern	klwp_t		lwp0;
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate /* where newly-created lwps normally start */
2137c478bd9Sstevel@tonic-gate extern	void	lwp_rtt(void);
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2187c478bd9Sstevel@tonic-gate }
2197c478bd9Sstevel@tonic-gate #endif
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate #endif	/* _SYS_KLWP_H */
222