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 2004 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 * used to stop/alert lwps 165 */ 166 char lwp_unused; 167 char lwp_state; /* Running in User/Kernel mode (no lock req) */ 168 ushort_t lwp_nostop; /* Don't stop this lwp (no lock required) */ 169 kcondvar_t lwp_cv; 170 171 /* 172 * Last failed privilege. 173 */ 174 short lwp_badpriv; 175 176 /* 177 * linkage 178 */ 179 struct _kthread *lwp_thread; 180 struct proc *lwp_procp; 181 182 size_t lwp_childstksz; /* kernel stksize for this lwp's descendants */ 183 184 uintptr_t lwp_ustack; /* current stack bounds */ 185 size_t lwp_old_stk_ctl; /* old stack limit */ 186 187 /* 188 * Contracts 189 */ 190 struct ct_template *lwp_ct_active[CTT_MAXTYPE]; /* active templates */ 191 struct contract *lwp_ct_latest[CTT_MAXTYPE]; /* last created contract */ 192 } klwp_t; 193 194 /* lwp states */ 195 #define LWP_USER 0x01 /* Running in user mode */ 196 #define LWP_SYS 0x02 /* Running in kernel mode */ 197 198 #if defined(_KERNEL) 199 extern int lwp_default_stksize; 200 extern int lwp_reapcnt; 201 202 extern struct _kthread *lwp_deathrow; 203 extern kmutex_t reaplock; 204 extern struct kmem_cache *lwp_cache; 205 extern void *segkp_lwp; 206 extern klwp_t lwp0; 207 208 /* where newly-created lwps normally start */ 209 extern void lwp_rtt(void); 210 211 #endif /* _KERNEL */ 212 213 #ifdef __cplusplus 214 } 215 #endif 216 217 #endif /* _SYS_KLWP_H */ 218