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.
27 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
33 #include <sys/types.h>
34 #include <sys/condvar.h>
35 #include <sys/thread.h>
36 #include <sys/signal.h>
37 #include <sys/siginfo.h>
40 #include <sys/msacct.h>
41 #include <sys/ucontext.h>
43 #include <sys/contract.h>
45 #if (defined(_KERNEL) || defined(_KMEMUSER)) && defined(_MACHDEP)
46 #include <sys/machparam.h>
54 * The light-weight process object and the methods by which it
58 #define MAXSYSARGS 8 /* Maximum # of arguments passed to a syscall */
60 /* lwp_eosys values */
61 #define NORMALRETURN 0 /* normal return; adjusts PC, registers */
62 #define JUSTRETURN 1 /* just return, leave registers alone */
65 * Resource usage, per-lwp plus per-process (sum over defunct lwps).
68 u_longlong_t minflt
; /* minor page faults */
69 u_longlong_t majflt
; /* major page faults */
70 u_longlong_t nswap
; /* swaps */
71 u_longlong_t inblock
; /* input blocks */
72 u_longlong_t oublock
; /* output blocks */
73 u_longlong_t msgsnd
; /* messages sent */
74 u_longlong_t msgrcv
; /* messages received */
75 u_longlong_t nsignals
; /* signals received */
76 u_longlong_t nvcsw
; /* voluntary context switches */
77 u_longlong_t nivcsw
; /* involuntary context switches */
78 u_longlong_t sysc
; /* system calls */
79 u_longlong_t ioch
; /* chars read and written */
82 typedef struct _klwp
*klwp_id_t
;
84 typedef struct _klwp
{
88 struct pcb lwp_pcb
; /* user regs save pcb */
89 uintptr_t lwp_oldcontext
; /* previous user context */
92 * system-call interface
94 long *lwp_ap
; /* pointer to arglist */
95 int lwp_errno
; /* error for current syscall (private) */
99 char lwp_error
; /* return error code */
100 char lwp_eosys
; /* special action on end of syscall */
101 char lwp_argsaved
; /* are all args in lwp_arg */
102 char lwp_watchtrap
; /* lwp undergoing watchpoint single-step */
103 long lwp_arg
[MAXSYSARGS
]; /* args to current syscall */
104 void *lwp_regs
; /* pointer to saved regs on stack */
105 void *lwp_fpu
; /* pointer to fpu regs */
106 label_t lwp_qsav
; /* longjmp label for quits and interrupts */
109 * signal handling and debugger (/proc) interface
111 uchar_t lwp_cursig
; /* current signal */
112 uchar_t lwp_curflt
; /* current fault */
113 uchar_t lwp_sysabort
; /* if set, abort syscall */
114 uchar_t lwp_asleep
; /* lwp asleep in syscall */
115 uchar_t lwp_extsig
; /* cursig sent from another contract */
116 stack_t lwp_sigaltstack
; /* alternate signal stack */
117 struct sigqueue
*lwp_curinfo
; /* siginfo for current signal */
118 k_siginfo_t lwp_siginfo
; /* siginfo for stop-on-fault */
119 k_sigset_t lwp_sigoldmask
; /* for sigsuspend */
120 struct lwp_watch
{ /* used in watchpoint single-stepping */
126 } lwp_watch
[4]; /* one for each of exec/write/read/read */
128 uint32_t lwp_oweupc
; /* profil(2) ticks owed to this lwp */
131 * Microstate accounting. Timestamps are made at the start and the
132 * end of each microstate (see <sys/msacct.h> for state definitions)
133 * and the corresponding accounting info is updated. The current
134 * microstate is kept in the thread struct, since there are cases
135 * when one thread must update another thread's state (a no-no
136 * for an lwp since it may be swapped/paged out). The rest of the
137 * microstate stuff is kept here to avoid wasting space on things
138 * like kernel threads that don't have an associated lwp.
141 int ms_prev
; /* previous running mstate */
142 hrtime_t ms_start
; /* lwp creation time */
143 hrtime_t ms_term
; /* lwp termination time */
144 hrtime_t ms_state_start
; /* start time of this mstate */
145 hrtime_t ms_acct
[NMSTATES
]; /* per mstate accounting */
149 * Per-lwp resource usage.
151 struct lrusage lwp_ru
;
154 * Things to keep for real-time (SIGPROF) profiling.
157 caddr_t lwp_lastfaddr
;
160 * timers. Protected by lwp->procp->p_lock
162 struct itimerval lwp_timer
[3];
165 * used to stop/alert lwps
168 char lwp_state
; /* Running in User/Kernel mode (no lock req) */
169 ushort_t lwp_nostop
; /* Don't stop this lwp (no lock required) */
170 ushort_t lwp_pad
; /* Reserved for future use */
173 * Last failed privilege.
180 struct _kthread
*lwp_thread
;
181 struct proc
*lwp_procp
;
183 size_t lwp_childstksz
; /* kernel stksize for this lwp's descendants */
185 uintptr_t lwp_ustack
; /* current stack bounds */
186 size_t lwp_old_stk_ctl
; /* old stack limit */
191 struct ct_template
*lwp_ct_active
[CTT_MAXTYPE
]; /* active templates */
192 struct contract
*lwp_ct_latest
[CTT_MAXTYPE
]; /* last created contract */
194 void *lwp_brand
; /* per-lwp brand data */
195 struct psinfo
*lwp_spymaster
; /* if an agent LWP, our spymaster */
199 #define LWP_USER 0x01 /* Running in user mode */
200 #define LWP_SYS 0x02 /* Running in kernel mode */
203 extern int lwp_default_stksize
;
204 extern int lwp_reapcnt
;
206 extern struct _kthread
*lwp_deathrow
;
207 extern kmutex_t reaplock
;
208 extern struct kmem_cache
*lwp_cache
;
209 extern void *segkp_lwp
;
212 /* where newly-created lwps normally start */
213 extern void lwp_rtt(void);
221 #endif /* _SYS_KLWP_H */