10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51710Sahl * Common Development and Distribution License (the "License"). 61710Sahl * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 211710Sahl 220Sstevel@tonic-gate /* 231710Sahl * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _FASTTRAP_IMPL_H 280Sstevel@tonic-gate #define _FASTTRAP_IMPL_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #include <sys/dtrace.h> 340Sstevel@tonic-gate #include <sys/proc.h> 350Sstevel@tonic-gate #include <sys/fasttrap.h> 360Sstevel@tonic-gate #include <sys/fasttrap_isa.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate #ifdef __cplusplus 390Sstevel@tonic-gate extern "C" { 400Sstevel@tonic-gate #endif 410Sstevel@tonic-gate 420Sstevel@tonic-gate /* 43532Sahl * Fasttrap Providers, Probes and Tracepoints 44532Sahl * 45532Sahl * Each Solaris process can have multiple providers -- the pid provider as 46532Sahl * well as any number of user-level statically defined tracing (USDT) 47532Sahl * providers. Those providers are each represented by a fasttrap_provider_t. 48532Sahl * All providers for a given process have a pointer to a shared 49532Sahl * fasttrap_proc_t. The fasttrap_proc_t has two states: active or defunct. 50532Sahl * It becomes defunct when the process performs an exit or an exec. 51532Sahl * 52532Sahl * Each probe is represented by a fasttrap_probe_t which has a pointer to 53532Sahl * its associated provider as well as a list of fasttrap_id_tp_t structures 54532Sahl * which are tuples combining a fasttrap_id_t and a fasttrap_tracepoint_t. 55532Sahl * A fasttrap_tracepoint_t represents the actual point of instrumentation 56532Sahl * and it contains two lists of fasttrap_id_t structures (to be fired pre- 57532Sahl * and post-instruction emulation) that identify the probes attached to the 58532Sahl * tracepoint. Tracepoints also have a pointer to the fasttrap_proc_t for the 59532Sahl * process they trace which is used when looking up a tracepoint both at 60532Sahl * probe fire time and when enabling and disabling probes. 61532Sahl * 62532Sahl * It's important to note that probes are preallocated with the necessary 63532Sahl * number of tracepoints, but that tracepoints can be shared by probes and 64532Sahl * swapped between probes. If a probe's preallocated tracepoint is enabled 65532Sahl * (and, therefore, the associated probe is enabled), and that probe is 66532Sahl * then disabled, ownership of that tracepoint may be exchanged for an 67532Sahl * unused tracepoint belonging to another probe that was attached to the 68532Sahl * enabled tracepoint. 690Sstevel@tonic-gate */ 700Sstevel@tonic-gate 71532Sahl typedef struct fasttrap_proc { 72532Sahl pid_t ftpc_pid; /* process ID for this proc */ 73532Sahl uint_t ftpc_defunct; /* denotes a lame duck proc */ 74532Sahl uint64_t ftpc_count; /* reference count */ 75532Sahl kmutex_t ftpc_mtx; /* proc lock */ 76532Sahl struct fasttrap_proc *ftpc_next; /* next proc in hash chain */ 77532Sahl } fasttrap_proc_t; 78532Sahl 79532Sahl typedef struct fasttrap_provider { 80532Sahl pid_t ftp_pid; /* process ID for this prov */ 81532Sahl char ftp_name[DTRACE_PROVNAMELEN]; /* prov name (w/o the pid) */ 820Sstevel@tonic-gate dtrace_provider_id_t ftp_provid; /* DTrace provider handle */ 830Sstevel@tonic-gate uint_t ftp_marked; /* mark for possible removal */ 84532Sahl uint_t ftp_retired; /* mark when retired */ 850Sstevel@tonic-gate kmutex_t ftp_mtx; /* provider lock */ 860Sstevel@tonic-gate uint64_t ftp_rcount; /* enabled probes ref count */ 870Sstevel@tonic-gate uint64_t ftp_ccount; /* consumers creating probes */ 88*1880Sahl uint64_t ftp_mcount; /* meta provider count */ 89532Sahl fasttrap_proc_t *ftp_proc; /* shared proc for all provs */ 90532Sahl struct fasttrap_provider *ftp_next; /* next prov in hash chain */ 91532Sahl } fasttrap_provider_t; 920Sstevel@tonic-gate 930Sstevel@tonic-gate typedef struct fasttrap_id fasttrap_id_t; 940Sstevel@tonic-gate typedef struct fasttrap_probe fasttrap_probe_t; 950Sstevel@tonic-gate typedef struct fasttrap_tracepoint fasttrap_tracepoint_t; 960Sstevel@tonic-gate 970Sstevel@tonic-gate struct fasttrap_id { 980Sstevel@tonic-gate fasttrap_probe_t *fti_probe; /* referrring probe */ 990Sstevel@tonic-gate fasttrap_id_t *fti_next; /* enabled probe list on tp */ 1001710Sahl fasttrap_probe_type_t fti_ptype; /* probe type */ 1010Sstevel@tonic-gate }; 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate typedef struct fasttrap_id_tp { 1040Sstevel@tonic-gate fasttrap_id_t fit_id; 1050Sstevel@tonic-gate fasttrap_tracepoint_t *fit_tp; 1060Sstevel@tonic-gate } fasttrap_id_tp_t; 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate struct fasttrap_probe { 1090Sstevel@tonic-gate dtrace_id_t ftp_id; /* DTrace probe identifier */ 1100Sstevel@tonic-gate pid_t ftp_pid; /* pid for this probe */ 1110Sstevel@tonic-gate fasttrap_provider_t *ftp_prov; /* this probe's provider */ 1120Sstevel@tonic-gate uintptr_t ftp_faddr; /* associated function's addr */ 1130Sstevel@tonic-gate size_t ftp_fsize; /* associated function's size */ 1140Sstevel@tonic-gate uint64_t ftp_gen; /* modification generation */ 1150Sstevel@tonic-gate uint64_t ftp_ntps; /* number of tracepoints */ 1160Sstevel@tonic-gate uint8_t *ftp_argmap; /* native to translated args */ 1170Sstevel@tonic-gate uint8_t ftp_nargs; /* translated argument count */ 1181710Sahl uint8_t ftp_enabled; /* is this probe enabled */ 1190Sstevel@tonic-gate char *ftp_xtypes; /* translated types index */ 1200Sstevel@tonic-gate char *ftp_ntypes; /* native types index */ 1210Sstevel@tonic-gate fasttrap_id_tp_t ftp_tps[1]; /* flexible array */ 1220Sstevel@tonic-gate }; 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate #define FASTTRAP_ID_INDEX(id) \ 1250Sstevel@tonic-gate ((fasttrap_id_tp_t *)(((char *)(id) - offsetof(fasttrap_id_tp_t, fit_id))) - \ 1260Sstevel@tonic-gate &(id)->fti_probe->ftp_tps[0]) 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate struct fasttrap_tracepoint { 1291710Sahl fasttrap_proc_t *ftt_proc; /* associated process struct */ 1301710Sahl uintptr_t ftt_pc; /* address of tracepoint */ 1311710Sahl pid_t ftt_pid; /* pid of tracepoint */ 1321710Sahl fasttrap_machtp_t ftt_mtp; /* ISA-specific portion */ 1331710Sahl fasttrap_id_t *ftt_ids; /* NULL-terminated list */ 1341710Sahl fasttrap_id_t *ftt_retids; /* NULL-terminated list */ 1351710Sahl fasttrap_tracepoint_t *ftt_next; /* link in global hash */ 1360Sstevel@tonic-gate }; 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate typedef struct fasttrap_bucket { 1391710Sahl kmutex_t ftb_mtx; /* bucket lock */ 1401710Sahl void *ftb_data; /* data payload */ 1410Sstevel@tonic-gate 1421710Sahl uint8_t ftb_pad[64 - sizeof (kmutex_t) - sizeof (void *)]; 1430Sstevel@tonic-gate } fasttrap_bucket_t; 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate typedef struct fasttrap_hash { 1461710Sahl ulong_t fth_nent; /* power-of-2 num. of entries */ 1471710Sahl ulong_t fth_mask; /* fth_nent - 1 */ 1481710Sahl fasttrap_bucket_t *fth_table; /* array of buckets */ 1490Sstevel@tonic-gate } fasttrap_hash_t; 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate /* 1520Sstevel@tonic-gate * If at some future point these assembly functions become observable by 1530Sstevel@tonic-gate * DTrace, then these defines should become separate functions so that the 1540Sstevel@tonic-gate * fasttrap provider doesn't trigger probes during internal operations. 1550Sstevel@tonic-gate */ 1560Sstevel@tonic-gate #define fasttrap_copyout copyout 1570Sstevel@tonic-gate #define fasttrap_fuword32 fuword32 1580Sstevel@tonic-gate #define fasttrap_suword32 suword32 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate #define fasttrap_fulword fulword 1610Sstevel@tonic-gate #define fasttrap_sulword sulword 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate extern void fasttrap_sigtrap(proc_t *, kthread_t *, uintptr_t); 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate extern dtrace_id_t fasttrap_probe_id; 1660Sstevel@tonic-gate extern fasttrap_hash_t fasttrap_tpoints; 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate #define FASTTRAP_TPOINTS_INDEX(pid, pc) \ 1690Sstevel@tonic-gate (((pc) / sizeof (fasttrap_instr_t) + (pid)) & fasttrap_tpoints.fth_mask) 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate /* 1720Sstevel@tonic-gate * Must be implemented by fasttrap_isa.c 1730Sstevel@tonic-gate */ 1741710Sahl extern int fasttrap_tracepoint_init(proc_t *, fasttrap_tracepoint_t *, 1751710Sahl uintptr_t, fasttrap_probe_type_t); 1760Sstevel@tonic-gate extern int fasttrap_tracepoint_install(proc_t *, fasttrap_tracepoint_t *); 1770Sstevel@tonic-gate extern int fasttrap_tracepoint_remove(proc_t *, fasttrap_tracepoint_t *); 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate extern int fasttrap_probe(struct regs *); 1800Sstevel@tonic-gate extern int fasttrap_pid_probe(struct regs *); 1810Sstevel@tonic-gate extern int fasttrap_return_probe(struct regs *); 1820Sstevel@tonic-gate 1830Sstevel@tonic-gate extern uint64_t fasttrap_getarg(void *, dtrace_id_t, void *, int, int); 1840Sstevel@tonic-gate extern uint64_t fasttrap_usdt_getarg(void *, dtrace_id_t, void *, int, int); 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate #ifdef __cplusplus 1870Sstevel@tonic-gate } 1880Sstevel@tonic-gate #endif 1890Sstevel@tonic-gate 1900Sstevel@tonic-gate #endif /* _FASTTRAP_IMPL_H */ 191