xref: /onnv-gate/usr/src/uts/common/sys/fasttrap_impl.h (revision 532:665869cfc853)
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
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate  * Copyright 2005 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 /*
43*532Sahl  * Fasttrap Providers, Probes and Tracepoints
44*532Sahl  *
45*532Sahl  * Each Solaris process can have multiple providers -- the pid provider as
46*532Sahl  * well as any number of user-level statically defined tracing (USDT)
47*532Sahl  * providers. Those providers are each represented by a fasttrap_provider_t.
48*532Sahl  * All providers for a given process have a pointer to a shared
49*532Sahl  * fasttrap_proc_t. The fasttrap_proc_t has two states: active or defunct.
50*532Sahl  * It becomes defunct when the process performs an exit or an exec.
51*532Sahl  *
52*532Sahl  * Each probe is represented by a fasttrap_probe_t which has a pointer to
53*532Sahl  * its associated provider as well as a list of fasttrap_id_tp_t structures
54*532Sahl  * which are tuples combining a fasttrap_id_t and a fasttrap_tracepoint_t.
55*532Sahl  * A fasttrap_tracepoint_t represents the actual point of instrumentation
56*532Sahl  * and it contains two lists of fasttrap_id_t structures (to be fired pre-
57*532Sahl  * and post-instruction emulation) that identify the probes attached to the
58*532Sahl  * tracepoint. Tracepoints also have a pointer to the fasttrap_proc_t for the
59*532Sahl  * process they trace which is used when looking up a tracepoint both at
60*532Sahl  * probe fire time and when enabling and disabling probes.
61*532Sahl  *
62*532Sahl  * It's important to note that probes are preallocated with the necessary
63*532Sahl  * number of tracepoints, but that tracepoints can be shared by probes and
64*532Sahl  * swapped between probes. If a probe's preallocated tracepoint is enabled
65*532Sahl  * (and, therefore, the associated probe is enabled), and that probe is
66*532Sahl  * then disabled, ownership of that tracepoint may be exchanged for an
67*532Sahl  * unused tracepoint belonging to another probe that was attached to the
68*532Sahl  * enabled tracepoint.
690Sstevel@tonic-gate  */
700Sstevel@tonic-gate 
71*532Sahl typedef struct fasttrap_proc {
72*532Sahl 	pid_t ftpc_pid;				/* process ID for this proc */
73*532Sahl 	uint_t ftpc_defunct;			/* denotes a lame duck proc */
74*532Sahl 	uint64_t ftpc_count;			/* reference count */
75*532Sahl 	kmutex_t ftpc_mtx;			/* proc lock */
76*532Sahl 	struct fasttrap_proc *ftpc_next;	/* next proc in hash chain */
77*532Sahl } fasttrap_proc_t;
78*532Sahl 
79*532Sahl typedef struct fasttrap_provider {
80*532Sahl 	pid_t ftp_pid;				/* process ID for this prov */
81*532Sahl 	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 */
84*532Sahl 	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*532Sahl 	fasttrap_proc_t *ftp_proc;		/* shared proc for all provs */
89*532Sahl 	struct fasttrap_provider *ftp_next;	/* next prov in hash chain */
90*532Sahl } fasttrap_provider_t;
910Sstevel@tonic-gate 
920Sstevel@tonic-gate typedef struct fasttrap_id fasttrap_id_t;
930Sstevel@tonic-gate typedef struct fasttrap_probe fasttrap_probe_t;
940Sstevel@tonic-gate typedef struct fasttrap_tracepoint fasttrap_tracepoint_t;
950Sstevel@tonic-gate 
960Sstevel@tonic-gate struct fasttrap_id {
970Sstevel@tonic-gate 	fasttrap_probe_t *fti_probe;		/* referrring probe */
980Sstevel@tonic-gate 	fasttrap_id_t *fti_next;		/* enabled probe list on tp */
990Sstevel@tonic-gate };
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate typedef struct fasttrap_id_tp {
1020Sstevel@tonic-gate 	fasttrap_id_t fit_id;
1030Sstevel@tonic-gate 	fasttrap_tracepoint_t *fit_tp;
1040Sstevel@tonic-gate } fasttrap_id_tp_t;
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate struct fasttrap_probe {
1070Sstevel@tonic-gate 	dtrace_id_t ftp_id;			/* DTrace probe identifier */
1080Sstevel@tonic-gate 	pid_t ftp_pid;				/* pid for this probe */
1090Sstevel@tonic-gate 	fasttrap_provider_t *ftp_prov;		/* this probe's provider */
1100Sstevel@tonic-gate 	uintptr_t ftp_faddr;			/* associated function's addr */
1110Sstevel@tonic-gate 	size_t ftp_fsize;			/* associated function's size */
1120Sstevel@tonic-gate 	fasttrap_probe_type_t ftp_type;		/* type of probe */
1130Sstevel@tonic-gate 	uint_t ftp_enabled;			/* is this probe enabled */
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 */
1180Sstevel@tonic-gate 	char *ftp_xtypes;			/* translated types index */
1190Sstevel@tonic-gate 	char *ftp_ntypes;			/* native types index */
1200Sstevel@tonic-gate 	fasttrap_id_tp_t ftp_tps[1];		/* flexible array */
1210Sstevel@tonic-gate };
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate #define	FASTTRAP_ID_INDEX(id)	\
1240Sstevel@tonic-gate ((fasttrap_id_tp_t *)(((char *)(id) - offsetof(fasttrap_id_tp_t, fit_id))) - \
1250Sstevel@tonic-gate &(id)->fti_probe->ftp_tps[0])
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate struct fasttrap_tracepoint {
128*532Sahl 	fasttrap_proc_t		*ftt_proc;	/* associated process struct */
1290Sstevel@tonic-gate 	uintptr_t		ftt_pc;		/* address of tracepoint */
1300Sstevel@tonic-gate 	pid_t			ftt_pid;	/* pid of tracepoint */
1310Sstevel@tonic-gate 	fasttrap_machtp_t	ftt_mtp;	/* ISA-specific portion */
1320Sstevel@tonic-gate 	fasttrap_id_t		*ftt_ids;	/* NULL-terminated list */
1330Sstevel@tonic-gate 	fasttrap_id_t		*ftt_retids;	/* NULL-terminated list */
1340Sstevel@tonic-gate 	fasttrap_tracepoint_t	*ftt_next;	/* link in global hash */
1350Sstevel@tonic-gate };
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate typedef struct fasttrap_bucket {
1380Sstevel@tonic-gate 	kmutex_t		ftb_mtx;
1390Sstevel@tonic-gate 	void 			*ftb_data;
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate 	uint8_t		ftb_pad[64 - sizeof (kmutex_t) - sizeof (void *)];
1420Sstevel@tonic-gate } fasttrap_bucket_t;
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate typedef struct fasttrap_hash {
1450Sstevel@tonic-gate 	ulong_t			fth_nent;
1460Sstevel@tonic-gate 	ulong_t			fth_mask;
1470Sstevel@tonic-gate 	fasttrap_bucket_t	*fth_table;
1480Sstevel@tonic-gate } fasttrap_hash_t;
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate /*
1510Sstevel@tonic-gate  * If at some future point these assembly functions become observable by
1520Sstevel@tonic-gate  * DTrace, then these defines should become separate functions so that the
1530Sstevel@tonic-gate  * fasttrap provider doesn't trigger probes during internal operations.
1540Sstevel@tonic-gate  */
1550Sstevel@tonic-gate #define	fasttrap_copyout	copyout
1560Sstevel@tonic-gate #define	fasttrap_fuword32	fuword32
1570Sstevel@tonic-gate #define	fasttrap_suword32	suword32
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate #define	fasttrap_fulword	fulword
1600Sstevel@tonic-gate #define	fasttrap_sulword	sulword
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate extern void fasttrap_sigtrap(proc_t *, kthread_t *, uintptr_t);
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate extern dtrace_id_t 		fasttrap_probe_id;
1650Sstevel@tonic-gate extern fasttrap_hash_t		fasttrap_tpoints;
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate #define	FASTTRAP_TPOINTS_INDEX(pid, pc) \
1680Sstevel@tonic-gate 	(((pc) / sizeof (fasttrap_instr_t) + (pid)) & fasttrap_tpoints.fth_mask)
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate /*
1710Sstevel@tonic-gate  * Must be implemented by fasttrap_isa.c
1720Sstevel@tonic-gate  */
1730Sstevel@tonic-gate extern int fasttrap_tracepoint_init(proc_t *, fasttrap_probe_t *,
1740Sstevel@tonic-gate     fasttrap_tracepoint_t *, uintptr_t);
1750Sstevel@tonic-gate extern int fasttrap_tracepoint_install(proc_t *, fasttrap_tracepoint_t *);
1760Sstevel@tonic-gate extern int fasttrap_tracepoint_remove(proc_t *, fasttrap_tracepoint_t *);
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate extern int fasttrap_probe(struct regs *);
1790Sstevel@tonic-gate extern int fasttrap_pid_probe(struct regs *);
1800Sstevel@tonic-gate extern int fasttrap_return_probe(struct regs *);
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate extern uint64_t fasttrap_getarg(void *, dtrace_id_t, void *, int, int);
1830Sstevel@tonic-gate extern uint64_t fasttrap_usdt_getarg(void *, dtrace_id_t, void *, int, int);
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate #ifdef	__cplusplus
1860Sstevel@tonic-gate }
1870Sstevel@tonic-gate #endif
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate #endif	/* _FASTTRAP_IMPL_H */
190