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