xref: /onnv-gate/usr/src/uts/common/sys/fasttrap_impl.h (revision 6390:2262f1092e41)
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 /*
23*6390Sahl  * Copyright 2008 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.
50*6390Sahl  * When the count of active providers goes to zero it becomes defunct; a
51*6390Sahl  * provider drops its active count when it is removed individually or as part
52*6390Sahl  * of a mass removal when a process exits or performs an exec.
53532Sahl  *
54532Sahl  * Each probe is represented by a fasttrap_probe_t which has a pointer to
55532Sahl  * its associated provider as well as a list of fasttrap_id_tp_t structures
56532Sahl  * which are tuples combining a fasttrap_id_t and a fasttrap_tracepoint_t.
57532Sahl  * A fasttrap_tracepoint_t represents the actual point of instrumentation
58532Sahl  * and it contains two lists of fasttrap_id_t structures (to be fired pre-
59532Sahl  * and post-instruction emulation) that identify the probes attached to the
60532Sahl  * tracepoint. Tracepoints also have a pointer to the fasttrap_proc_t for the
61*6390Sahl  * process they trace which is used when looking up a tracepoint both when a
62*6390Sahl  * probe fires and when enabling and disabling probes.
63532Sahl  *
64532Sahl  * It's important to note that probes are preallocated with the necessary
65532Sahl  * number of tracepoints, but that tracepoints can be shared by probes and
66532Sahl  * swapped between probes. If a probe's preallocated tracepoint is enabled
67532Sahl  * (and, therefore, the associated probe is enabled), and that probe is
68532Sahl  * then disabled, ownership of that tracepoint may be exchanged for an
69532Sahl  * unused tracepoint belonging to another probe that was attached to the
70532Sahl  * enabled tracepoint.
710Sstevel@tonic-gate  */
720Sstevel@tonic-gate 
73532Sahl typedef struct fasttrap_proc {
74532Sahl 	pid_t ftpc_pid;				/* process ID for this proc */
754821Sahl 	uint64_t ftpc_acount;			/* count of active providers */
76*6390Sahl 	uint64_t ftpc_rcount;			/* count of extant providers */
77*6390Sahl 	kmutex_t ftpc_mtx;			/* lock on all but acount */
78532Sahl 	struct fasttrap_proc *ftpc_next;	/* next proc in hash chain */
79532Sahl } fasttrap_proc_t;
80532Sahl 
81532Sahl typedef struct fasttrap_provider {
82532Sahl 	pid_t ftp_pid;				/* process ID for this prov */
83532Sahl 	char ftp_name[DTRACE_PROVNAMELEN];	/* prov name (w/o the pid) */
840Sstevel@tonic-gate 	dtrace_provider_id_t ftp_provid;	/* DTrace provider handle */
850Sstevel@tonic-gate 	uint_t ftp_marked;			/* mark for possible removal */
86532Sahl 	uint_t ftp_retired;			/* mark when retired */
870Sstevel@tonic-gate 	kmutex_t ftp_mtx;			/* provider lock */
882179Sahl 	kmutex_t ftp_cmtx;			/* lock on creating probes */
890Sstevel@tonic-gate 	uint64_t ftp_rcount;			/* enabled probes ref count */
900Sstevel@tonic-gate 	uint64_t ftp_ccount;			/* consumers creating probes */
911880Sahl 	uint64_t ftp_mcount;			/* meta provider count */
92532Sahl 	fasttrap_proc_t *ftp_proc;		/* shared proc for all provs */
93532Sahl 	struct fasttrap_provider *ftp_next;	/* next prov in hash chain */
94532Sahl } fasttrap_provider_t;
950Sstevel@tonic-gate 
960Sstevel@tonic-gate typedef struct fasttrap_id fasttrap_id_t;
970Sstevel@tonic-gate typedef struct fasttrap_probe fasttrap_probe_t;
980Sstevel@tonic-gate typedef struct fasttrap_tracepoint fasttrap_tracepoint_t;
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate struct fasttrap_id {
1010Sstevel@tonic-gate 	fasttrap_probe_t *fti_probe;		/* referrring probe */
1020Sstevel@tonic-gate 	fasttrap_id_t *fti_next;		/* enabled probe list on tp */
1031710Sahl 	fasttrap_probe_type_t fti_ptype;	/* probe type */
1040Sstevel@tonic-gate };
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate typedef struct fasttrap_id_tp {
1070Sstevel@tonic-gate 	fasttrap_id_t fit_id;
1080Sstevel@tonic-gate 	fasttrap_tracepoint_t *fit_tp;
1090Sstevel@tonic-gate } fasttrap_id_tp_t;
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate struct fasttrap_probe {
1120Sstevel@tonic-gate 	dtrace_id_t ftp_id;			/* DTrace probe identifier */
1130Sstevel@tonic-gate 	pid_t ftp_pid;				/* pid for this probe */
1140Sstevel@tonic-gate 	fasttrap_provider_t *ftp_prov;		/* this probe's provider */
1150Sstevel@tonic-gate 	uintptr_t ftp_faddr;			/* associated function's addr */
1160Sstevel@tonic-gate 	size_t ftp_fsize;			/* associated function's size */
1170Sstevel@tonic-gate 	uint64_t ftp_gen;			/* modification generation */
1180Sstevel@tonic-gate 	uint64_t ftp_ntps;			/* number of tracepoints */
1190Sstevel@tonic-gate 	uint8_t *ftp_argmap;			/* native to translated args */
1200Sstevel@tonic-gate 	uint8_t ftp_nargs;			/* translated argument count */
1211710Sahl 	uint8_t ftp_enabled;			/* is this probe enabled */
1220Sstevel@tonic-gate 	char *ftp_xtypes;			/* translated types index */
1230Sstevel@tonic-gate 	char *ftp_ntypes;			/* native types index */
1240Sstevel@tonic-gate 	fasttrap_id_tp_t ftp_tps[1];		/* flexible array */
1250Sstevel@tonic-gate };
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate #define	FASTTRAP_ID_INDEX(id)	\
1280Sstevel@tonic-gate ((fasttrap_id_tp_t *)(((char *)(id) - offsetof(fasttrap_id_tp_t, fit_id))) - \
1290Sstevel@tonic-gate &(id)->fti_probe->ftp_tps[0])
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate struct fasttrap_tracepoint {
1321710Sahl 	fasttrap_proc_t *ftt_proc;		/* associated process struct */
1331710Sahl 	uintptr_t ftt_pc;			/* address of tracepoint */
1341710Sahl 	pid_t ftt_pid;				/* pid of tracepoint */
1351710Sahl 	fasttrap_machtp_t ftt_mtp;		/* ISA-specific portion */
1361710Sahl 	fasttrap_id_t *ftt_ids;			/* NULL-terminated list */
1371710Sahl 	fasttrap_id_t *ftt_retids;		/* NULL-terminated list */
1381710Sahl 	fasttrap_tracepoint_t *ftt_next;	/* link in global hash */
1390Sstevel@tonic-gate };
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate typedef struct fasttrap_bucket {
1421710Sahl 	kmutex_t ftb_mtx;			/* bucket lock */
1431710Sahl 	void *ftb_data;				/* data payload */
1440Sstevel@tonic-gate 
1451710Sahl 	uint8_t ftb_pad[64 - sizeof (kmutex_t) - sizeof (void *)];
1460Sstevel@tonic-gate } fasttrap_bucket_t;
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate typedef struct fasttrap_hash {
1491710Sahl 	ulong_t fth_nent;			/* power-of-2 num. of entries */
1501710Sahl 	ulong_t fth_mask;			/* fth_nent - 1 */
1511710Sahl 	fasttrap_bucket_t *fth_table;		/* array of buckets */
1520Sstevel@tonic-gate } fasttrap_hash_t;
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate /*
1550Sstevel@tonic-gate  * If at some future point these assembly functions become observable by
1560Sstevel@tonic-gate  * DTrace, then these defines should become separate functions so that the
1570Sstevel@tonic-gate  * fasttrap provider doesn't trigger probes during internal operations.
1580Sstevel@tonic-gate  */
1590Sstevel@tonic-gate #define	fasttrap_copyout	copyout
1600Sstevel@tonic-gate #define	fasttrap_fuword32	fuword32
1610Sstevel@tonic-gate #define	fasttrap_suword32	suword32
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate #define	fasttrap_fulword	fulword
1640Sstevel@tonic-gate #define	fasttrap_sulword	sulword
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate extern void fasttrap_sigtrap(proc_t *, kthread_t *, uintptr_t);
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate extern dtrace_id_t 		fasttrap_probe_id;
1690Sstevel@tonic-gate extern fasttrap_hash_t		fasttrap_tpoints;
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate #define	FASTTRAP_TPOINTS_INDEX(pid, pc) \
1720Sstevel@tonic-gate 	(((pc) / sizeof (fasttrap_instr_t) + (pid)) & fasttrap_tpoints.fth_mask)
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate /*
1750Sstevel@tonic-gate  * Must be implemented by fasttrap_isa.c
1760Sstevel@tonic-gate  */
1771710Sahl extern int fasttrap_tracepoint_init(proc_t *, fasttrap_tracepoint_t *,
1781710Sahl     uintptr_t, fasttrap_probe_type_t);
1790Sstevel@tonic-gate extern int fasttrap_tracepoint_install(proc_t *, fasttrap_tracepoint_t *);
1800Sstevel@tonic-gate extern int fasttrap_tracepoint_remove(proc_t *, fasttrap_tracepoint_t *);
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate extern int fasttrap_pid_probe(struct regs *);
1830Sstevel@tonic-gate extern int fasttrap_return_probe(struct regs *);
1840Sstevel@tonic-gate 
1852179Sahl extern uint64_t fasttrap_pid_getarg(void *, dtrace_id_t, void *, int, int);
1860Sstevel@tonic-gate extern uint64_t fasttrap_usdt_getarg(void *, dtrace_id_t, void *, int, int);
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate #ifdef	__cplusplus
1890Sstevel@tonic-gate }
1900Sstevel@tonic-gate #endif
1910Sstevel@tonic-gate 
1920Sstevel@tonic-gate #endif	/* _FASTTRAP_IMPL_H */
193