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