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.
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.
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]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
29 #pragma ident "%Z%%M% %I% %E% SMI"
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>
38 #include <sys/msacct.h>
39 #include <sys/ucontext.h>
41 #include <sys/contract.h>
43 #if (defined(_KERNEL) || defined(_KMEMUSER)) && defined(_MACHDEP)
44 #include <sys/machparam.h>
52 * The light-weight process object and the methods by which it
56 #define MAXSYSARGS 8 /* Maximum # of arguments passed to a syscall */
58 /* lwp_eosys values */
59 #define NORMALRETURN 0 /* normal return; adjusts PC, registers */
60 #define JUSTRETURN 1 /* just return, leave registers alone */
63 * Resource usage, per-lwp plus per-process (sum over defunct lwps).
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 */
80 typedef struct _klwp
*klwp_id_t
;
82 typedef struct _klwp
{
86 struct pcb lwp_pcb
; /* user regs save pcb */
87 uintptr_t lwp_oldcontext
; /* previous user context */
90 * system-call interface
92 long *lwp_ap
; /* pointer to arglist */
93 int lwp_errno
; /* error for current syscall (private) */
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 */
107 * signal handling and debugger (/proc) interface
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 */
124 } lwp_watch
[4]; /* one for each of exec/write/read/read */
126 uint32_t lwp_oweupc
; /* profil(2) ticks owed to this lwp */
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.
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 */
147 * Per-lwp resource usage.
149 struct lrusage lwp_ru
;
152 * Things to keep for real-time (SIGPROF) profiling.
155 caddr_t lwp_lastfaddr
;
158 * timers. Protected by lwp->procp->p_lock
160 struct itimerval lwp_timer
[3];
163 * used to stop/alert lwps
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 */
171 * Last failed privilege.
178 struct _kthread
*lwp_thread
;
179 struct proc
*lwp_procp
;
181 size_t lwp_childstksz
; /* kernel stksize for this lwp's descendants */
183 uintptr_t lwp_ustack
; /* current stack bounds */
184 size_t lwp_old_stk_ctl
; /* old stack limit */
189 struct ct_template
*lwp_ct_active
[CTT_MAXTYPE
]; /* active templates */
190 struct contract
*lwp_ct_latest
[CTT_MAXTYPE
]; /* last created contract */
192 void *lwp_brand
; /* per-lwp brand data */
196 #define LWP_USER 0x01 /* Running in user mode */
197 #define LWP_SYS 0x02 /* Running in kernel mode */
200 extern int lwp_default_stksize
;
201 extern int lwp_reapcnt
;
203 extern struct _kthread
*lwp_deathrow
;
204 extern kmutex_t reaplock
;
205 extern struct kmem_cache
*lwp_cache
;
206 extern void *segkp_lwp
;
209 /* where newly-created lwps normally start */
210 extern void lwp_rtt(void);
218 #endif /* _SYS_KLWP_H */