xref: /onnv-gate/usr/src/uts/common/sys/klwp.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef	_SYS_KLWP_H
28*0Sstevel@tonic-gate #define	_SYS_KLWP_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #include <sys/types.h>
33*0Sstevel@tonic-gate #include <sys/condvar.h>
34*0Sstevel@tonic-gate #include <sys/thread.h>
35*0Sstevel@tonic-gate #include <sys/signal.h>
36*0Sstevel@tonic-gate #include <sys/siginfo.h>
37*0Sstevel@tonic-gate #include <sys/pcb.h>
38*0Sstevel@tonic-gate #include <sys/time.h>
39*0Sstevel@tonic-gate #include <sys/msacct.h>
40*0Sstevel@tonic-gate #include <sys/ucontext.h>
41*0Sstevel@tonic-gate #include <sys/lwp.h>
42*0Sstevel@tonic-gate #include <sys/contract.h>
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate #if (defined(_KERNEL) || defined(_KMEMUSER)) && defined(_MACHDEP)
45*0Sstevel@tonic-gate #include <sys/machparam.h>
46*0Sstevel@tonic-gate #endif
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate #ifdef	__cplusplus
49*0Sstevel@tonic-gate extern "C" {
50*0Sstevel@tonic-gate #endif
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate /*
53*0Sstevel@tonic-gate  * The light-weight process object and the methods by which it
54*0Sstevel@tonic-gate  * is accessed.
55*0Sstevel@tonic-gate  */
56*0Sstevel@tonic-gate 
57*0Sstevel@tonic-gate #define	MAXSYSARGS	8	/* Maximum # of arguments passed to a syscall */
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate /* lwp_eosys values */
60*0Sstevel@tonic-gate #define	NORMALRETURN	0	/* normal return; adjusts PC, registers */
61*0Sstevel@tonic-gate #define	JUSTRETURN	1	/* just return, leave registers alone */
62*0Sstevel@tonic-gate 
63*0Sstevel@tonic-gate /*
64*0Sstevel@tonic-gate  * Resource usage, per-lwp plus per-process (sum over defunct lwps).
65*0Sstevel@tonic-gate  */
66*0Sstevel@tonic-gate struct lrusage {
67*0Sstevel@tonic-gate 	u_longlong_t	minflt;		/* minor page faults */
68*0Sstevel@tonic-gate 	u_longlong_t	majflt;		/* major page faults */
69*0Sstevel@tonic-gate 	u_longlong_t	nswap;		/* swaps */
70*0Sstevel@tonic-gate 	u_longlong_t	inblock;	/* input blocks */
71*0Sstevel@tonic-gate 	u_longlong_t	oublock;	/* output blocks */
72*0Sstevel@tonic-gate 	u_longlong_t	msgsnd;		/* messages sent */
73*0Sstevel@tonic-gate 	u_longlong_t	msgrcv;		/* messages received */
74*0Sstevel@tonic-gate 	u_longlong_t	nsignals;	/* signals received */
75*0Sstevel@tonic-gate 	u_longlong_t	nvcsw;		/* voluntary context switches */
76*0Sstevel@tonic-gate 	u_longlong_t	nivcsw;		/* involuntary context switches */
77*0Sstevel@tonic-gate 	u_longlong_t	sysc;		/* system calls */
78*0Sstevel@tonic-gate 	u_longlong_t	ioch;		/* chars read and written */
79*0Sstevel@tonic-gate };
80*0Sstevel@tonic-gate 
81*0Sstevel@tonic-gate typedef struct _klwp	*klwp_id_t;
82*0Sstevel@tonic-gate 
83*0Sstevel@tonic-gate typedef struct _klwp {
84*0Sstevel@tonic-gate 	/*
85*0Sstevel@tonic-gate 	 * user-mode context
86*0Sstevel@tonic-gate 	 */
87*0Sstevel@tonic-gate 	struct pcb	lwp_pcb;		/* user regs save pcb */
88*0Sstevel@tonic-gate 	uintptr_t	lwp_oldcontext;		/* previous user context */
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate 	/*
91*0Sstevel@tonic-gate 	 * system-call interface
92*0Sstevel@tonic-gate 	 */
93*0Sstevel@tonic-gate 	long	*lwp_ap;	/* pointer to arglist */
94*0Sstevel@tonic-gate 	int	lwp_errno;	/* error for current syscall (private) */
95*0Sstevel@tonic-gate 	/*
96*0Sstevel@tonic-gate 	 * support for I/O
97*0Sstevel@tonic-gate 	 */
98*0Sstevel@tonic-gate 	char	lwp_error;	/* return error code */
99*0Sstevel@tonic-gate 	char	lwp_eosys;	/* special action on end of syscall */
100*0Sstevel@tonic-gate 	char	lwp_argsaved;	/* are all args in lwp_arg */
101*0Sstevel@tonic-gate 	char	lwp_watchtrap;	/* lwp undergoing watchpoint single-step */
102*0Sstevel@tonic-gate 	long	lwp_arg[MAXSYSARGS];	/* args to current syscall */
103*0Sstevel@tonic-gate 	void	*lwp_regs;	/* pointer to saved regs on stack */
104*0Sstevel@tonic-gate 	void	*lwp_fpu;	/* pointer to fpu regs */
105*0Sstevel@tonic-gate 	label_t	lwp_qsav;	/* longjmp label for quits and interrupts */
106*0Sstevel@tonic-gate 
107*0Sstevel@tonic-gate 	/*
108*0Sstevel@tonic-gate 	 * signal handling and debugger (/proc) interface
109*0Sstevel@tonic-gate 	 */
110*0Sstevel@tonic-gate 	uchar_t	lwp_cursig;		/* current signal */
111*0Sstevel@tonic-gate 	uchar_t	lwp_curflt;		/* current fault */
112*0Sstevel@tonic-gate 	uchar_t	lwp_sysabort;		/* if set, abort syscall */
113*0Sstevel@tonic-gate 	uchar_t	lwp_asleep;		/* lwp asleep in syscall */
114*0Sstevel@tonic-gate 	uchar_t lwp_extsig;		/* cursig sent from another contract */
115*0Sstevel@tonic-gate 	stack_t lwp_sigaltstack;	/* alternate signal stack */
116*0Sstevel@tonic-gate 	struct sigqueue *lwp_curinfo;	/* siginfo for current signal */
117*0Sstevel@tonic-gate 	k_siginfo_t	lwp_siginfo;	/* siginfo for stop-on-fault */
118*0Sstevel@tonic-gate 	k_sigset_t	lwp_sigoldmask;	/* for sigsuspend */
119*0Sstevel@tonic-gate 	struct lwp_watch {		/* used in watchpoint single-stepping */
120*0Sstevel@tonic-gate 		caddr_t	wpaddr;
121*0Sstevel@tonic-gate 		size_t	wpsize;
122*0Sstevel@tonic-gate 		int	wpcode;
123*0Sstevel@tonic-gate 		int	wpmapped;
124*0Sstevel@tonic-gate 		greg_t	wppc;
125*0Sstevel@tonic-gate 	} lwp_watch[4];		/* one for each of exec/write/read/read */
126*0Sstevel@tonic-gate 
127*0Sstevel@tonic-gate 	uint32_t lwp_oweupc;		/* profil(2) ticks owed to this lwp */
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate 	/*
130*0Sstevel@tonic-gate 	 * Microstate accounting.  Timestamps are made at the start and the
131*0Sstevel@tonic-gate 	 * end of each microstate (see <sys/msacct.h> for state definitions)
132*0Sstevel@tonic-gate 	 * and the corresponding accounting info is updated.  The current
133*0Sstevel@tonic-gate 	 * microstate is kept in the thread struct, since there are cases
134*0Sstevel@tonic-gate 	 * when one thread must update another thread's state (a no-no
135*0Sstevel@tonic-gate 	 * for an lwp since it may be swapped/paged out).  The rest of the
136*0Sstevel@tonic-gate 	 * microstate stuff is kept here to avoid wasting space on things
137*0Sstevel@tonic-gate 	 * like kernel threads that don't have an associated lwp.
138*0Sstevel@tonic-gate 	 */
139*0Sstevel@tonic-gate 	struct mstate {
140*0Sstevel@tonic-gate 		int ms_prev;			/* previous running mstate */
141*0Sstevel@tonic-gate 		hrtime_t ms_start;		/* lwp creation time */
142*0Sstevel@tonic-gate 		hrtime_t ms_term;		/* lwp termination time */
143*0Sstevel@tonic-gate 		hrtime_t ms_state_start;	/* start time of this mstate */
144*0Sstevel@tonic-gate 		hrtime_t ms_acct[NMSTATES];	/* per mstate accounting */
145*0Sstevel@tonic-gate 	} lwp_mstate;
146*0Sstevel@tonic-gate 
147*0Sstevel@tonic-gate 	/*
148*0Sstevel@tonic-gate 	 * Per-lwp resource usage.
149*0Sstevel@tonic-gate 	 */
150*0Sstevel@tonic-gate 	struct lrusage lwp_ru;
151*0Sstevel@tonic-gate 
152*0Sstevel@tonic-gate 	/*
153*0Sstevel@tonic-gate 	 * Things to keep for real-time (SIGPROF) profiling.
154*0Sstevel@tonic-gate 	 */
155*0Sstevel@tonic-gate 	int	lwp_lastfault;
156*0Sstevel@tonic-gate 	caddr_t	lwp_lastfaddr;
157*0Sstevel@tonic-gate 
158*0Sstevel@tonic-gate 	/*
159*0Sstevel@tonic-gate 	 * timers. Protected by lwp->procp->p_lock
160*0Sstevel@tonic-gate 	 */
161*0Sstevel@tonic-gate 	struct itimerval lwp_timer[3];
162*0Sstevel@tonic-gate 
163*0Sstevel@tonic-gate 	/*
164*0Sstevel@tonic-gate 	 * used to stop/alert lwps
165*0Sstevel@tonic-gate 	 */
166*0Sstevel@tonic-gate 	char	lwp_unused;
167*0Sstevel@tonic-gate 	char	lwp_state;	/* Running in User/Kernel mode (no lock req) */
168*0Sstevel@tonic-gate 	ushort_t lwp_nostop;	/* Don't stop this lwp (no lock required) */
169*0Sstevel@tonic-gate 	kcondvar_t lwp_cv;
170*0Sstevel@tonic-gate 
171*0Sstevel@tonic-gate 	/*
172*0Sstevel@tonic-gate 	 * Last failed privilege.
173*0Sstevel@tonic-gate 	 */
174*0Sstevel@tonic-gate 	short	lwp_badpriv;
175*0Sstevel@tonic-gate 
176*0Sstevel@tonic-gate 	/*
177*0Sstevel@tonic-gate 	 * linkage
178*0Sstevel@tonic-gate 	 */
179*0Sstevel@tonic-gate 	struct _kthread	*lwp_thread;
180*0Sstevel@tonic-gate 	struct proc	*lwp_procp;
181*0Sstevel@tonic-gate 
182*0Sstevel@tonic-gate 	size_t lwp_childstksz;	/* kernel stksize for this lwp's descendants */
183*0Sstevel@tonic-gate 
184*0Sstevel@tonic-gate 	uintptr_t	lwp_ustack;		/* current stack bounds */
185*0Sstevel@tonic-gate 	size_t		lwp_old_stk_ctl;	/* old stack limit */
186*0Sstevel@tonic-gate 
187*0Sstevel@tonic-gate 	/*
188*0Sstevel@tonic-gate 	 * Contracts
189*0Sstevel@tonic-gate 	 */
190*0Sstevel@tonic-gate 	struct ct_template *lwp_ct_active[CTT_MAXTYPE]; /* active templates */
191*0Sstevel@tonic-gate 	struct contract	*lwp_ct_latest[CTT_MAXTYPE]; /* last created contract */
192*0Sstevel@tonic-gate } klwp_t;
193*0Sstevel@tonic-gate 
194*0Sstevel@tonic-gate /* lwp states */
195*0Sstevel@tonic-gate #define	LWP_USER	0x01		/* Running in user mode */
196*0Sstevel@tonic-gate #define	LWP_SYS		0x02		/* Running in kernel mode */
197*0Sstevel@tonic-gate 
198*0Sstevel@tonic-gate #if	defined(_KERNEL)
199*0Sstevel@tonic-gate extern	int	lwp_default_stksize;
200*0Sstevel@tonic-gate extern	int	lwp_reapcnt;
201*0Sstevel@tonic-gate 
202*0Sstevel@tonic-gate extern	struct _kthread *lwp_deathrow;
203*0Sstevel@tonic-gate extern	kmutex_t	reaplock;
204*0Sstevel@tonic-gate extern	struct kmem_cache *lwp_cache;
205*0Sstevel@tonic-gate extern	void		*segkp_lwp;
206*0Sstevel@tonic-gate extern	klwp_t		lwp0;
207*0Sstevel@tonic-gate 
208*0Sstevel@tonic-gate /* where newly-created lwps normally start */
209*0Sstevel@tonic-gate extern	void	lwp_rtt(void);
210*0Sstevel@tonic-gate 
211*0Sstevel@tonic-gate #endif	/* _KERNEL */
212*0Sstevel@tonic-gate 
213*0Sstevel@tonic-gate #ifdef	__cplusplus
214*0Sstevel@tonic-gate }
215*0Sstevel@tonic-gate #endif
216*0Sstevel@tonic-gate 
217*0Sstevel@tonic-gate #endif	/* _SYS_KLWP_H */
218