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 59acbbeafSnn35248 * Common Development and Distribution License (the "License"). 69acbbeafSnn35248 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*8548bf79Snr123932 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _SYS_KLWP_H 277c478bd9Sstevel@tonic-gate #define _SYS_KLWP_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <sys/types.h> 327c478bd9Sstevel@tonic-gate #include <sys/condvar.h> 337c478bd9Sstevel@tonic-gate #include <sys/thread.h> 347c478bd9Sstevel@tonic-gate #include <sys/signal.h> 357c478bd9Sstevel@tonic-gate #include <sys/siginfo.h> 367c478bd9Sstevel@tonic-gate #include <sys/pcb.h> 377c478bd9Sstevel@tonic-gate #include <sys/time.h> 387c478bd9Sstevel@tonic-gate #include <sys/msacct.h> 397c478bd9Sstevel@tonic-gate #include <sys/ucontext.h> 407c478bd9Sstevel@tonic-gate #include <sys/lwp.h> 417c478bd9Sstevel@tonic-gate #include <sys/contract.h> 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #if (defined(_KERNEL) || defined(_KMEMUSER)) && defined(_MACHDEP) 447c478bd9Sstevel@tonic-gate #include <sys/machparam.h> 457c478bd9Sstevel@tonic-gate #endif 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #ifdef __cplusplus 487c478bd9Sstevel@tonic-gate extern "C" { 497c478bd9Sstevel@tonic-gate #endif 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate /* 527c478bd9Sstevel@tonic-gate * The light-weight process object and the methods by which it 537c478bd9Sstevel@tonic-gate * is accessed. 547c478bd9Sstevel@tonic-gate */ 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate #define MAXSYSARGS 8 /* Maximum # of arguments passed to a syscall */ 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate /* lwp_eosys values */ 597c478bd9Sstevel@tonic-gate #define NORMALRETURN 0 /* normal return; adjusts PC, registers */ 607c478bd9Sstevel@tonic-gate #define JUSTRETURN 1 /* just return, leave registers alone */ 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate /* 637c478bd9Sstevel@tonic-gate * Resource usage, per-lwp plus per-process (sum over defunct lwps). 647c478bd9Sstevel@tonic-gate */ 657c478bd9Sstevel@tonic-gate struct lrusage { 667c478bd9Sstevel@tonic-gate u_longlong_t minflt; /* minor page faults */ 677c478bd9Sstevel@tonic-gate u_longlong_t majflt; /* major page faults */ 687c478bd9Sstevel@tonic-gate u_longlong_t nswap; /* swaps */ 697c478bd9Sstevel@tonic-gate u_longlong_t inblock; /* input blocks */ 707c478bd9Sstevel@tonic-gate u_longlong_t oublock; /* output blocks */ 717c478bd9Sstevel@tonic-gate u_longlong_t msgsnd; /* messages sent */ 727c478bd9Sstevel@tonic-gate u_longlong_t msgrcv; /* messages received */ 737c478bd9Sstevel@tonic-gate u_longlong_t nsignals; /* signals received */ 747c478bd9Sstevel@tonic-gate u_longlong_t nvcsw; /* voluntary context switches */ 757c478bd9Sstevel@tonic-gate u_longlong_t nivcsw; /* involuntary context switches */ 767c478bd9Sstevel@tonic-gate u_longlong_t sysc; /* system calls */ 777c478bd9Sstevel@tonic-gate u_longlong_t ioch; /* chars read and written */ 787c478bd9Sstevel@tonic-gate }; 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate typedef struct _klwp *klwp_id_t; 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate typedef struct _klwp { 837c478bd9Sstevel@tonic-gate /* 847c478bd9Sstevel@tonic-gate * user-mode context 857c478bd9Sstevel@tonic-gate */ 867c478bd9Sstevel@tonic-gate struct pcb lwp_pcb; /* user regs save pcb */ 877c478bd9Sstevel@tonic-gate uintptr_t lwp_oldcontext; /* previous user context */ 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate /* 907c478bd9Sstevel@tonic-gate * system-call interface 917c478bd9Sstevel@tonic-gate */ 927c478bd9Sstevel@tonic-gate long *lwp_ap; /* pointer to arglist */ 937c478bd9Sstevel@tonic-gate int lwp_errno; /* error for current syscall (private) */ 947c478bd9Sstevel@tonic-gate /* 957c478bd9Sstevel@tonic-gate * support for I/O 967c478bd9Sstevel@tonic-gate */ 977c478bd9Sstevel@tonic-gate char lwp_error; /* return error code */ 987c478bd9Sstevel@tonic-gate char lwp_eosys; /* special action on end of syscall */ 997c478bd9Sstevel@tonic-gate char lwp_argsaved; /* are all args in lwp_arg */ 1007c478bd9Sstevel@tonic-gate char lwp_watchtrap; /* lwp undergoing watchpoint single-step */ 1017c478bd9Sstevel@tonic-gate long lwp_arg[MAXSYSARGS]; /* args to current syscall */ 1027c478bd9Sstevel@tonic-gate void *lwp_regs; /* pointer to saved regs on stack */ 1037c478bd9Sstevel@tonic-gate void *lwp_fpu; /* pointer to fpu regs */ 1047c478bd9Sstevel@tonic-gate label_t lwp_qsav; /* longjmp label for quits and interrupts */ 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate /* 1077c478bd9Sstevel@tonic-gate * signal handling and debugger (/proc) interface 1087c478bd9Sstevel@tonic-gate */ 1097c478bd9Sstevel@tonic-gate uchar_t lwp_cursig; /* current signal */ 1107c478bd9Sstevel@tonic-gate uchar_t lwp_curflt; /* current fault */ 1117c478bd9Sstevel@tonic-gate uchar_t lwp_sysabort; /* if set, abort syscall */ 1127c478bd9Sstevel@tonic-gate uchar_t lwp_asleep; /* lwp asleep in syscall */ 1137c478bd9Sstevel@tonic-gate uchar_t lwp_extsig; /* cursig sent from another contract */ 1147c478bd9Sstevel@tonic-gate stack_t lwp_sigaltstack; /* alternate signal stack */ 1157c478bd9Sstevel@tonic-gate struct sigqueue *lwp_curinfo; /* siginfo for current signal */ 1167c478bd9Sstevel@tonic-gate k_siginfo_t lwp_siginfo; /* siginfo for stop-on-fault */ 1177c478bd9Sstevel@tonic-gate k_sigset_t lwp_sigoldmask; /* for sigsuspend */ 1187c478bd9Sstevel@tonic-gate struct lwp_watch { /* used in watchpoint single-stepping */ 1197c478bd9Sstevel@tonic-gate caddr_t wpaddr; 1207c478bd9Sstevel@tonic-gate size_t wpsize; 1217c478bd9Sstevel@tonic-gate int wpcode; 1227c478bd9Sstevel@tonic-gate int wpmapped; 1237c478bd9Sstevel@tonic-gate greg_t wppc; 1247c478bd9Sstevel@tonic-gate } lwp_watch[4]; /* one for each of exec/write/read/read */ 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate uint32_t lwp_oweupc; /* profil(2) ticks owed to this lwp */ 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate /* 1297c478bd9Sstevel@tonic-gate * Microstate accounting. Timestamps are made at the start and the 1307c478bd9Sstevel@tonic-gate * end of each microstate (see <sys/msacct.h> for state definitions) 1317c478bd9Sstevel@tonic-gate * and the corresponding accounting info is updated. The current 1327c478bd9Sstevel@tonic-gate * microstate is kept in the thread struct, since there are cases 1337c478bd9Sstevel@tonic-gate * when one thread must update another thread's state (a no-no 1347c478bd9Sstevel@tonic-gate * for an lwp since it may be swapped/paged out). The rest of the 1357c478bd9Sstevel@tonic-gate * microstate stuff is kept here to avoid wasting space on things 1367c478bd9Sstevel@tonic-gate * like kernel threads that don't have an associated lwp. 1377c478bd9Sstevel@tonic-gate */ 1387c478bd9Sstevel@tonic-gate struct mstate { 1397c478bd9Sstevel@tonic-gate int ms_prev; /* previous running mstate */ 1407c478bd9Sstevel@tonic-gate hrtime_t ms_start; /* lwp creation time */ 1417c478bd9Sstevel@tonic-gate hrtime_t ms_term; /* lwp termination time */ 1427c478bd9Sstevel@tonic-gate hrtime_t ms_state_start; /* start time of this mstate */ 1437c478bd9Sstevel@tonic-gate hrtime_t ms_acct[NMSTATES]; /* per mstate accounting */ 1447c478bd9Sstevel@tonic-gate } lwp_mstate; 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate /* 1477c478bd9Sstevel@tonic-gate * Per-lwp resource usage. 1487c478bd9Sstevel@tonic-gate */ 1497c478bd9Sstevel@tonic-gate struct lrusage lwp_ru; 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate /* 1527c478bd9Sstevel@tonic-gate * Things to keep for real-time (SIGPROF) profiling. 1537c478bd9Sstevel@tonic-gate */ 1547c478bd9Sstevel@tonic-gate int lwp_lastfault; 1557c478bd9Sstevel@tonic-gate caddr_t lwp_lastfaddr; 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate /* 1587c478bd9Sstevel@tonic-gate * timers. Protected by lwp->procp->p_lock 1597c478bd9Sstevel@tonic-gate */ 1607c478bd9Sstevel@tonic-gate struct itimerval lwp_timer[3]; 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate /* 163*8548bf79Snr123932 * used to stop/alert lwps 1647c478bd9Sstevel@tonic-gate */ 1657c478bd9Sstevel@tonic-gate char lwp_unused; 1667c478bd9Sstevel@tonic-gate char lwp_state; /* Running in User/Kernel mode (no lock req) */ 167*8548bf79Snr123932 ushort_t lwp_nostop; /* Don't stop this lwp (no lock required) */ 168*8548bf79Snr123932 ushort_t lwp_pad; /* Reserved for future use */ 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate /* 1717c478bd9Sstevel@tonic-gate * Last failed privilege. 1727c478bd9Sstevel@tonic-gate */ 1737c478bd9Sstevel@tonic-gate short lwp_badpriv; 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate /* 1767c478bd9Sstevel@tonic-gate * linkage 1777c478bd9Sstevel@tonic-gate */ 1787c478bd9Sstevel@tonic-gate struct _kthread *lwp_thread; 1797c478bd9Sstevel@tonic-gate struct proc *lwp_procp; 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate size_t lwp_childstksz; /* kernel stksize for this lwp's descendants */ 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate uintptr_t lwp_ustack; /* current stack bounds */ 1847c478bd9Sstevel@tonic-gate size_t lwp_old_stk_ctl; /* old stack limit */ 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate /* 1877c478bd9Sstevel@tonic-gate * Contracts 1887c478bd9Sstevel@tonic-gate */ 1897c478bd9Sstevel@tonic-gate struct ct_template *lwp_ct_active[CTT_MAXTYPE]; /* active templates */ 1907c478bd9Sstevel@tonic-gate struct contract *lwp_ct_latest[CTT_MAXTYPE]; /* last created contract */ 1919acbbeafSnn35248 1929acbbeafSnn35248 void *lwp_brand; /* per-lwp brand data */ 1937c478bd9Sstevel@tonic-gate } klwp_t; 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate /* lwp states */ 1967c478bd9Sstevel@tonic-gate #define LWP_USER 0x01 /* Running in user mode */ 1977c478bd9Sstevel@tonic-gate #define LWP_SYS 0x02 /* Running in kernel mode */ 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate #if defined(_KERNEL) 2007c478bd9Sstevel@tonic-gate extern int lwp_default_stksize; 2017c478bd9Sstevel@tonic-gate extern int lwp_reapcnt; 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate extern struct _kthread *lwp_deathrow; 2047c478bd9Sstevel@tonic-gate extern kmutex_t reaplock; 2057c478bd9Sstevel@tonic-gate extern struct kmem_cache *lwp_cache; 2067c478bd9Sstevel@tonic-gate extern void *segkp_lwp; 2077c478bd9Sstevel@tonic-gate extern klwp_t lwp0; 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate /* where newly-created lwps normally start */ 2107c478bd9Sstevel@tonic-gate extern void lwp_rtt(void); 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2157c478bd9Sstevel@tonic-gate } 2167c478bd9Sstevel@tonic-gate #endif 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate #endif /* _SYS_KLWP_H */ 219