17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23*16ade92dScwb * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _SYS_KLWP_H 287c478bd9Sstevel@tonic-gate #define _SYS_KLWP_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <sys/types.h> 337c478bd9Sstevel@tonic-gate #include <sys/condvar.h> 347c478bd9Sstevel@tonic-gate #include <sys/thread.h> 357c478bd9Sstevel@tonic-gate #include <sys/signal.h> 367c478bd9Sstevel@tonic-gate #include <sys/siginfo.h> 377c478bd9Sstevel@tonic-gate #include <sys/pcb.h> 387c478bd9Sstevel@tonic-gate #include <sys/time.h> 397c478bd9Sstevel@tonic-gate #include <sys/msacct.h> 407c478bd9Sstevel@tonic-gate #include <sys/ucontext.h> 417c478bd9Sstevel@tonic-gate #include <sys/lwp.h> 427c478bd9Sstevel@tonic-gate #include <sys/contract.h> 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #if (defined(_KERNEL) || defined(_KMEMUSER)) && defined(_MACHDEP) 457c478bd9Sstevel@tonic-gate #include <sys/machparam.h> 467c478bd9Sstevel@tonic-gate #endif 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate #ifdef __cplusplus 497c478bd9Sstevel@tonic-gate extern "C" { 507c478bd9Sstevel@tonic-gate #endif 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate /* 537c478bd9Sstevel@tonic-gate * The light-weight process object and the methods by which it 547c478bd9Sstevel@tonic-gate * is accessed. 557c478bd9Sstevel@tonic-gate */ 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate #define MAXSYSARGS 8 /* Maximum # of arguments passed to a syscall */ 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate /* lwp_eosys values */ 607c478bd9Sstevel@tonic-gate #define NORMALRETURN 0 /* normal return; adjusts PC, registers */ 617c478bd9Sstevel@tonic-gate #define JUSTRETURN 1 /* just return, leave registers alone */ 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate /* 647c478bd9Sstevel@tonic-gate * Resource usage, per-lwp plus per-process (sum over defunct lwps). 657c478bd9Sstevel@tonic-gate */ 667c478bd9Sstevel@tonic-gate struct lrusage { 677c478bd9Sstevel@tonic-gate u_longlong_t minflt; /* minor page faults */ 687c478bd9Sstevel@tonic-gate u_longlong_t majflt; /* major page faults */ 697c478bd9Sstevel@tonic-gate u_longlong_t nswap; /* swaps */ 707c478bd9Sstevel@tonic-gate u_longlong_t inblock; /* input blocks */ 717c478bd9Sstevel@tonic-gate u_longlong_t oublock; /* output blocks */ 727c478bd9Sstevel@tonic-gate u_longlong_t msgsnd; /* messages sent */ 737c478bd9Sstevel@tonic-gate u_longlong_t msgrcv; /* messages received */ 747c478bd9Sstevel@tonic-gate u_longlong_t nsignals; /* signals received */ 757c478bd9Sstevel@tonic-gate u_longlong_t nvcsw; /* voluntary context switches */ 767c478bd9Sstevel@tonic-gate u_longlong_t nivcsw; /* involuntary context switches */ 777c478bd9Sstevel@tonic-gate u_longlong_t sysc; /* system calls */ 787c478bd9Sstevel@tonic-gate u_longlong_t ioch; /* chars read and written */ 797c478bd9Sstevel@tonic-gate }; 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate typedef struct _klwp *klwp_id_t; 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate typedef struct _klwp { 847c478bd9Sstevel@tonic-gate /* 857c478bd9Sstevel@tonic-gate * user-mode context 867c478bd9Sstevel@tonic-gate */ 877c478bd9Sstevel@tonic-gate struct pcb lwp_pcb; /* user regs save pcb */ 887c478bd9Sstevel@tonic-gate uintptr_t lwp_oldcontext; /* previous user context */ 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate /* 917c478bd9Sstevel@tonic-gate * system-call interface 927c478bd9Sstevel@tonic-gate */ 937c478bd9Sstevel@tonic-gate long *lwp_ap; /* pointer to arglist */ 947c478bd9Sstevel@tonic-gate int lwp_errno; /* error for current syscall (private) */ 957c478bd9Sstevel@tonic-gate /* 967c478bd9Sstevel@tonic-gate * support for I/O 977c478bd9Sstevel@tonic-gate */ 987c478bd9Sstevel@tonic-gate char lwp_error; /* return error code */ 997c478bd9Sstevel@tonic-gate char lwp_eosys; /* special action on end of syscall */ 1007c478bd9Sstevel@tonic-gate char lwp_argsaved; /* are all args in lwp_arg */ 1017c478bd9Sstevel@tonic-gate char lwp_watchtrap; /* lwp undergoing watchpoint single-step */ 1027c478bd9Sstevel@tonic-gate long lwp_arg[MAXSYSARGS]; /* args to current syscall */ 1037c478bd9Sstevel@tonic-gate void *lwp_regs; /* pointer to saved regs on stack */ 1047c478bd9Sstevel@tonic-gate void *lwp_fpu; /* pointer to fpu regs */ 1057c478bd9Sstevel@tonic-gate label_t lwp_qsav; /* longjmp label for quits and interrupts */ 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate /* 1087c478bd9Sstevel@tonic-gate * signal handling and debugger (/proc) interface 1097c478bd9Sstevel@tonic-gate */ 1107c478bd9Sstevel@tonic-gate uchar_t lwp_cursig; /* current signal */ 1117c478bd9Sstevel@tonic-gate uchar_t lwp_curflt; /* current fault */ 1127c478bd9Sstevel@tonic-gate uchar_t lwp_sysabort; /* if set, abort syscall */ 1137c478bd9Sstevel@tonic-gate uchar_t lwp_asleep; /* lwp asleep in syscall */ 1147c478bd9Sstevel@tonic-gate uchar_t lwp_extsig; /* cursig sent from another contract */ 1157c478bd9Sstevel@tonic-gate stack_t lwp_sigaltstack; /* alternate signal stack */ 1167c478bd9Sstevel@tonic-gate struct sigqueue *lwp_curinfo; /* siginfo for current signal */ 1177c478bd9Sstevel@tonic-gate k_siginfo_t lwp_siginfo; /* siginfo for stop-on-fault */ 1187c478bd9Sstevel@tonic-gate k_sigset_t lwp_sigoldmask; /* for sigsuspend */ 1197c478bd9Sstevel@tonic-gate struct lwp_watch { /* used in watchpoint single-stepping */ 1207c478bd9Sstevel@tonic-gate caddr_t wpaddr; 1217c478bd9Sstevel@tonic-gate size_t wpsize; 1227c478bd9Sstevel@tonic-gate int wpcode; 1237c478bd9Sstevel@tonic-gate int wpmapped; 1247c478bd9Sstevel@tonic-gate greg_t wppc; 1257c478bd9Sstevel@tonic-gate } lwp_watch[4]; /* one for each of exec/write/read/read */ 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate uint32_t lwp_oweupc; /* profil(2) ticks owed to this lwp */ 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate /* 1307c478bd9Sstevel@tonic-gate * Microstate accounting. Timestamps are made at the start and the 1317c478bd9Sstevel@tonic-gate * end of each microstate (see <sys/msacct.h> for state definitions) 1327c478bd9Sstevel@tonic-gate * and the corresponding accounting info is updated. The current 1337c478bd9Sstevel@tonic-gate * microstate is kept in the thread struct, since there are cases 1347c478bd9Sstevel@tonic-gate * when one thread must update another thread's state (a no-no 1357c478bd9Sstevel@tonic-gate * for an lwp since it may be swapped/paged out). The rest of the 1367c478bd9Sstevel@tonic-gate * microstate stuff is kept here to avoid wasting space on things 1377c478bd9Sstevel@tonic-gate * like kernel threads that don't have an associated lwp. 1387c478bd9Sstevel@tonic-gate */ 1397c478bd9Sstevel@tonic-gate struct mstate { 1407c478bd9Sstevel@tonic-gate int ms_prev; /* previous running mstate */ 1417c478bd9Sstevel@tonic-gate hrtime_t ms_start; /* lwp creation time */ 1427c478bd9Sstevel@tonic-gate hrtime_t ms_term; /* lwp termination time */ 1437c478bd9Sstevel@tonic-gate hrtime_t ms_state_start; /* start time of this mstate */ 1447c478bd9Sstevel@tonic-gate hrtime_t ms_acct[NMSTATES]; /* per mstate accounting */ 1457c478bd9Sstevel@tonic-gate } lwp_mstate; 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate /* 1487c478bd9Sstevel@tonic-gate * Per-lwp resource usage. 1497c478bd9Sstevel@tonic-gate */ 1507c478bd9Sstevel@tonic-gate struct lrusage lwp_ru; 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate /* 1537c478bd9Sstevel@tonic-gate * Things to keep for real-time (SIGPROF) profiling. 1547c478bd9Sstevel@tonic-gate */ 1557c478bd9Sstevel@tonic-gate int lwp_lastfault; 1567c478bd9Sstevel@tonic-gate caddr_t lwp_lastfaddr; 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate /* 1597c478bd9Sstevel@tonic-gate * timers. Protected by lwp->procp->p_lock 1607c478bd9Sstevel@tonic-gate */ 1617c478bd9Sstevel@tonic-gate struct itimerval lwp_timer[3]; 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate /* 164*16ade92dScwb * There are a number of places where you do not wish an lwp to 165*16ade92dScwb * be stopped due to some interaction with other lwps in the process. 166*16ade92dScwb * In these cases the lwp_nostop value is incremented. At places where 167*16ade92dScwb * the lwp would normally be stopped the stop is allowed if lwp_nostop 168*16ade92dScwb * is zero. There are a very few cases where even if lwp_nostop is set 169*16ade92dScwb * we need to allow the lwp to stop. In those cases the lwp is 170*16ade92dScwb * stopped if lwp_nostop_r is not set regardless of the state of 171*16ade92dScwb * lwp_nostop. These conditions are: 172*16ade92dScwb * 173*16ade92dScwb * 1. In issig_forreal() when another lwp is undergoing fork1() 174*16ade92dScwb * or watchpoint activity (p_flag contains either SHOLDFORK1 or 175*16ade92dScwb * SHOLDWATCH or t_proc_flag contains TP_HOLDLWP) 176*16ade92dScwb * 177*16ade92dScwb * 2. In stop() when the why argument is not PR_SUSPENDED or the what 178*16ade92dScwb * argument is not SUSPEND_NORMAL. 179*16ade92dScwb * 180*16ade92dScwb * 3. In cv_wait_stop() when another lwp is undergoing fork1() or 181*16ade92dScwb * watchpoint activity (p_flag contains either SHOLDFORK1 or 182*16ade92dScwb * SHOLDWATCH or t_proc_flag contains TP_HOLDLWP) 183*16ade92dScwb * 184*16ade92dScwb * lwp_nostop_r is set in prstop(). ie we honour the presence of 185*16ade92dScwb * SHOLDFORK1 or SHOLDWATCH or TP_HOLDLWP in the case of 186*16ade92dScwb * stop(PR_SUSPENDED, SUSPEND_NORMAL) 1877c478bd9Sstevel@tonic-gate */ 1887c478bd9Sstevel@tonic-gate char lwp_unused; 1897c478bd9Sstevel@tonic-gate char lwp_state; /* Running in User/Kernel mode (no lock req) */ 190*16ade92dScwb ushort_t lwp_nostop; /* Don't stop this lwp except SUSPEND_NORMAL */ 191*16ade92dScwb ushort_t lwp_nostop_r; /* Don't stop this lwp (avoid recursion) */ 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate /* 1947c478bd9Sstevel@tonic-gate * Last failed privilege. 1957c478bd9Sstevel@tonic-gate */ 1967c478bd9Sstevel@tonic-gate short lwp_badpriv; 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate /* 1997c478bd9Sstevel@tonic-gate * linkage 2007c478bd9Sstevel@tonic-gate */ 2017c478bd9Sstevel@tonic-gate struct _kthread *lwp_thread; 2027c478bd9Sstevel@tonic-gate struct proc *lwp_procp; 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate size_t lwp_childstksz; /* kernel stksize for this lwp's descendants */ 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate uintptr_t lwp_ustack; /* current stack bounds */ 2077c478bd9Sstevel@tonic-gate size_t lwp_old_stk_ctl; /* old stack limit */ 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate /* 2107c478bd9Sstevel@tonic-gate * Contracts 2117c478bd9Sstevel@tonic-gate */ 2127c478bd9Sstevel@tonic-gate struct ct_template *lwp_ct_active[CTT_MAXTYPE]; /* active templates */ 2137c478bd9Sstevel@tonic-gate struct contract *lwp_ct_latest[CTT_MAXTYPE]; /* last created contract */ 2147c478bd9Sstevel@tonic-gate } klwp_t; 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate /* lwp states */ 2177c478bd9Sstevel@tonic-gate #define LWP_USER 0x01 /* Running in user mode */ 2187c478bd9Sstevel@tonic-gate #define LWP_SYS 0x02 /* Running in kernel mode */ 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate #if defined(_KERNEL) 2217c478bd9Sstevel@tonic-gate extern int lwp_default_stksize; 2227c478bd9Sstevel@tonic-gate extern int lwp_reapcnt; 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate extern struct _kthread *lwp_deathrow; 2257c478bd9Sstevel@tonic-gate extern kmutex_t reaplock; 2267c478bd9Sstevel@tonic-gate extern struct kmem_cache *lwp_cache; 2277c478bd9Sstevel@tonic-gate extern void *segkp_lwp; 2287c478bd9Sstevel@tonic-gate extern klwp_t lwp0; 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate /* where newly-created lwps normally start */ 2317c478bd9Sstevel@tonic-gate extern void lwp_rtt(void); 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2367c478bd9Sstevel@tonic-gate } 2377c478bd9Sstevel@tonic-gate #endif 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate #endif /* _SYS_KLWP_H */ 240