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