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 5ac448965Sahl * Common Development and Distribution License (the "License"). 6ac448965Sahl * 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 */ 21ac448965Sahl 227c478bd9Sstevel@tonic-gate /* 23*6009dbc6Sahl * Copyright 2008 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 _FASTTRAP_IMPL_H 287c478bd9Sstevel@tonic-gate #define _FASTTRAP_IMPL_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/dtrace.h> 347c478bd9Sstevel@tonic-gate #include <sys/proc.h> 357c478bd9Sstevel@tonic-gate #include <sys/fasttrap.h> 367c478bd9Sstevel@tonic-gate #include <sys/fasttrap_isa.h> 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #ifdef __cplusplus 397c478bd9Sstevel@tonic-gate extern "C" { 407c478bd9Sstevel@tonic-gate #endif 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate /* 43b096140dSahl * Fasttrap Providers, Probes and Tracepoints 44b096140dSahl * 45b096140dSahl * Each Solaris process can have multiple providers -- the pid provider as 46b096140dSahl * well as any number of user-level statically defined tracing (USDT) 47b096140dSahl * providers. Those providers are each represented by a fasttrap_provider_t. 48b096140dSahl * All providers for a given process have a pointer to a shared 49b096140dSahl * fasttrap_proc_t. The fasttrap_proc_t has two states: active or defunct. 50*6009dbc6Sahl * When the count of active providers goes to zero it becomes defunct; a 51*6009dbc6Sahl * provider drops its active count when it is removed individually or as part 52*6009dbc6Sahl * of a mass removal when a process exits or performs an exec. 53b096140dSahl * 54b096140dSahl * Each probe is represented by a fasttrap_probe_t which has a pointer to 55b096140dSahl * its associated provider as well as a list of fasttrap_id_tp_t structures 56b096140dSahl * which are tuples combining a fasttrap_id_t and a fasttrap_tracepoint_t. 57b096140dSahl * A fasttrap_tracepoint_t represents the actual point of instrumentation 58b096140dSahl * and it contains two lists of fasttrap_id_t structures (to be fired pre- 59b096140dSahl * and post-instruction emulation) that identify the probes attached to the 60b096140dSahl * tracepoint. Tracepoints also have a pointer to the fasttrap_proc_t for the 61*6009dbc6Sahl * process they trace which is used when looking up a tracepoint both when a 62*6009dbc6Sahl * probe fires and when enabling and disabling probes. 63b096140dSahl * 64b096140dSahl * It's important to note that probes are preallocated with the necessary 65b096140dSahl * number of tracepoints, but that tracepoints can be shared by probes and 66b096140dSahl * swapped between probes. If a probe's preallocated tracepoint is enabled 67b096140dSahl * (and, therefore, the associated probe is enabled), and that probe is 68b096140dSahl * then disabled, ownership of that tracepoint may be exchanged for an 69b096140dSahl * unused tracepoint belonging to another probe that was attached to the 70b096140dSahl * enabled tracepoint. 717c478bd9Sstevel@tonic-gate */ 727c478bd9Sstevel@tonic-gate 73b096140dSahl typedef struct fasttrap_proc { 74b096140dSahl pid_t ftpc_pid; /* process ID for this proc */ 75038dc6b3Sahl uint64_t ftpc_acount; /* count of active providers */ 76*6009dbc6Sahl uint64_t ftpc_rcount; /* count of extant providers */ 77*6009dbc6Sahl kmutex_t ftpc_mtx; /* lock on all but acount */ 78b096140dSahl struct fasttrap_proc *ftpc_next; /* next proc in hash chain */ 79b096140dSahl } fasttrap_proc_t; 80b096140dSahl 81b096140dSahl typedef struct fasttrap_provider { 82b096140dSahl pid_t ftp_pid; /* process ID for this prov */ 83b096140dSahl char ftp_name[DTRACE_PROVNAMELEN]; /* prov name (w/o the pid) */ 847c478bd9Sstevel@tonic-gate dtrace_provider_id_t ftp_provid; /* DTrace provider handle */ 857c478bd9Sstevel@tonic-gate uint_t ftp_marked; /* mark for possible removal */ 86b096140dSahl uint_t ftp_retired; /* mark when retired */ 877c478bd9Sstevel@tonic-gate kmutex_t ftp_mtx; /* provider lock */ 88f498645aSahl kmutex_t ftp_cmtx; /* lock on creating probes */ 897c478bd9Sstevel@tonic-gate uint64_t ftp_rcount; /* enabled probes ref count */ 907c478bd9Sstevel@tonic-gate uint64_t ftp_ccount; /* consumers creating probes */ 91ab9a77c7Sahl uint64_t ftp_mcount; /* meta provider count */ 92b096140dSahl fasttrap_proc_t *ftp_proc; /* shared proc for all provs */ 93b096140dSahl struct fasttrap_provider *ftp_next; /* next prov in hash chain */ 94b096140dSahl } fasttrap_provider_t; 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate typedef struct fasttrap_id fasttrap_id_t; 977c478bd9Sstevel@tonic-gate typedef struct fasttrap_probe fasttrap_probe_t; 987c478bd9Sstevel@tonic-gate typedef struct fasttrap_tracepoint fasttrap_tracepoint_t; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate struct fasttrap_id { 1017c478bd9Sstevel@tonic-gate fasttrap_probe_t *fti_probe; /* referrring probe */ 1027c478bd9Sstevel@tonic-gate fasttrap_id_t *fti_next; /* enabled probe list on tp */ 103ac448965Sahl fasttrap_probe_type_t fti_ptype; /* probe type */ 1047c478bd9Sstevel@tonic-gate }; 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate typedef struct fasttrap_id_tp { 1077c478bd9Sstevel@tonic-gate fasttrap_id_t fit_id; 1087c478bd9Sstevel@tonic-gate fasttrap_tracepoint_t *fit_tp; 1097c478bd9Sstevel@tonic-gate } fasttrap_id_tp_t; 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate struct fasttrap_probe { 1127c478bd9Sstevel@tonic-gate dtrace_id_t ftp_id; /* DTrace probe identifier */ 1137c478bd9Sstevel@tonic-gate pid_t ftp_pid; /* pid for this probe */ 1147c478bd9Sstevel@tonic-gate fasttrap_provider_t *ftp_prov; /* this probe's provider */ 1157c478bd9Sstevel@tonic-gate uintptr_t ftp_faddr; /* associated function's addr */ 1167c478bd9Sstevel@tonic-gate size_t ftp_fsize; /* associated function's size */ 1177c478bd9Sstevel@tonic-gate uint64_t ftp_gen; /* modification generation */ 1187c478bd9Sstevel@tonic-gate uint64_t ftp_ntps; /* number of tracepoints */ 1197c478bd9Sstevel@tonic-gate uint8_t *ftp_argmap; /* native to translated args */ 1207c478bd9Sstevel@tonic-gate uint8_t ftp_nargs; /* translated argument count */ 121ac448965Sahl uint8_t ftp_enabled; /* is this probe enabled */ 1227c478bd9Sstevel@tonic-gate char *ftp_xtypes; /* translated types index */ 1237c478bd9Sstevel@tonic-gate char *ftp_ntypes; /* native types index */ 1247c478bd9Sstevel@tonic-gate fasttrap_id_tp_t ftp_tps[1]; /* flexible array */ 1257c478bd9Sstevel@tonic-gate }; 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate #define FASTTRAP_ID_INDEX(id) \ 1287c478bd9Sstevel@tonic-gate ((fasttrap_id_tp_t *)(((char *)(id) - offsetof(fasttrap_id_tp_t, fit_id))) - \ 1297c478bd9Sstevel@tonic-gate &(id)->fti_probe->ftp_tps[0]) 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate struct fasttrap_tracepoint { 132b096140dSahl fasttrap_proc_t *ftt_proc; /* associated process struct */ 1337c478bd9Sstevel@tonic-gate uintptr_t ftt_pc; /* address of tracepoint */ 1347c478bd9Sstevel@tonic-gate pid_t ftt_pid; /* pid of tracepoint */ 1357c478bd9Sstevel@tonic-gate fasttrap_machtp_t ftt_mtp; /* ISA-specific portion */ 1367c478bd9Sstevel@tonic-gate fasttrap_id_t *ftt_ids; /* NULL-terminated list */ 1377c478bd9Sstevel@tonic-gate fasttrap_id_t *ftt_retids; /* NULL-terminated list */ 1387c478bd9Sstevel@tonic-gate fasttrap_tracepoint_t *ftt_next; /* link in global hash */ 1397c478bd9Sstevel@tonic-gate }; 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate typedef struct fasttrap_bucket { 142ac448965Sahl kmutex_t ftb_mtx; /* bucket lock */ 143ac448965Sahl void *ftb_data; /* data payload */ 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate uint8_t ftb_pad[64 - sizeof (kmutex_t) - sizeof (void *)]; 1467c478bd9Sstevel@tonic-gate } fasttrap_bucket_t; 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate typedef struct fasttrap_hash { 149ac448965Sahl ulong_t fth_nent; /* power-of-2 num. of entries */ 150ac448965Sahl ulong_t fth_mask; /* fth_nent - 1 */ 151ac448965Sahl fasttrap_bucket_t *fth_table; /* array of buckets */ 1527c478bd9Sstevel@tonic-gate } fasttrap_hash_t; 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate /* 1557c478bd9Sstevel@tonic-gate * If at some future point these assembly functions become observable by 1567c478bd9Sstevel@tonic-gate * DTrace, then these defines should become separate functions so that the 1577c478bd9Sstevel@tonic-gate * fasttrap provider doesn't trigger probes during internal operations. 1587c478bd9Sstevel@tonic-gate */ 1597c478bd9Sstevel@tonic-gate #define fasttrap_copyout copyout 1607c478bd9Sstevel@tonic-gate #define fasttrap_fuword32 fuword32 1617c478bd9Sstevel@tonic-gate #define fasttrap_suword32 suword32 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate #define fasttrap_fulword fulword 1647c478bd9Sstevel@tonic-gate #define fasttrap_sulword sulword 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate extern void fasttrap_sigtrap(proc_t *, kthread_t *, uintptr_t); 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate extern dtrace_id_t fasttrap_probe_id; 1697c478bd9Sstevel@tonic-gate extern fasttrap_hash_t fasttrap_tpoints; 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate #define FASTTRAP_TPOINTS_INDEX(pid, pc) \ 1727c478bd9Sstevel@tonic-gate (((pc) / sizeof (fasttrap_instr_t) + (pid)) & fasttrap_tpoints.fth_mask) 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate /* 1757c478bd9Sstevel@tonic-gate * Must be implemented by fasttrap_isa.c 1767c478bd9Sstevel@tonic-gate */ 177ac448965Sahl extern int fasttrap_tracepoint_init(proc_t *, fasttrap_tracepoint_t *, 178ac448965Sahl uintptr_t, fasttrap_probe_type_t); 1797c478bd9Sstevel@tonic-gate extern int fasttrap_tracepoint_install(proc_t *, fasttrap_tracepoint_t *); 1807c478bd9Sstevel@tonic-gate extern int fasttrap_tracepoint_remove(proc_t *, fasttrap_tracepoint_t *); 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate extern int fasttrap_pid_probe(struct regs *); 1837c478bd9Sstevel@tonic-gate extern int fasttrap_return_probe(struct regs *); 1847c478bd9Sstevel@tonic-gate 185f498645aSahl extern uint64_t fasttrap_pid_getarg(void *, dtrace_id_t, void *, int, int); 1867c478bd9Sstevel@tonic-gate extern uint64_t fasttrap_usdt_getarg(void *, dtrace_id_t, void *, int, int); 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1897c478bd9Sstevel@tonic-gate } 1907c478bd9Sstevel@tonic-gate #endif 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate #endif /* _FASTTRAP_IMPL_H */ 193