xref: /onnv-gate/usr/src/uts/common/sys/fasttrap_impl.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef	_FASTTRAP_IMPL_H
28*0Sstevel@tonic-gate #define	_FASTTRAP_IMPL_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #include <sys/types.h>
33*0Sstevel@tonic-gate #include <sys/dtrace.h>
34*0Sstevel@tonic-gate #include <sys/proc.h>
35*0Sstevel@tonic-gate #include <sys/fasttrap.h>
36*0Sstevel@tonic-gate #include <sys/fasttrap_isa.h>
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate #ifdef	__cplusplus
39*0Sstevel@tonic-gate extern "C" {
40*0Sstevel@tonic-gate #endif
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate /*
43*0Sstevel@tonic-gate  * Interfaces for fasttrap_isa.c to consume.
44*0Sstevel@tonic-gate  */
45*0Sstevel@tonic-gate typedef struct fasttrap_provider fasttrap_provider_t;
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate struct fasttrap_provider {
48*0Sstevel@tonic-gate 	pid_t ftp_pid;				/* process ID for this prov. */
49*0Sstevel@tonic-gate 	char ftp_name[DTRACE_PROVNAMELEN];	/* prov. name (w/o the pid) */
50*0Sstevel@tonic-gate 	dtrace_provider_id_t ftp_provid;	/* DTrace provider handle */
51*0Sstevel@tonic-gate 	uint_t ftp_marked;			/* mark for possible removal */
52*0Sstevel@tonic-gate 	uint_t ftp_defunct;			/* denotes a lame duck prov. */
53*0Sstevel@tonic-gate 	kmutex_t ftp_mtx;			/* provider lock */
54*0Sstevel@tonic-gate 	uint64_t ftp_rcount;			/* enabled probes ref count */
55*0Sstevel@tonic-gate 	uint64_t ftp_ccount;			/* consumers creating probes */
56*0Sstevel@tonic-gate 	fasttrap_provider_t *ftp_next;		/* next prov. in hash chain */
57*0Sstevel@tonic-gate };
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate typedef struct fasttrap_id fasttrap_id_t;
60*0Sstevel@tonic-gate typedef struct fasttrap_probe fasttrap_probe_t;
61*0Sstevel@tonic-gate typedef struct fasttrap_tracepoint fasttrap_tracepoint_t;
62*0Sstevel@tonic-gate 
63*0Sstevel@tonic-gate struct fasttrap_id {
64*0Sstevel@tonic-gate 	fasttrap_probe_t *fti_probe;		/* referrring probe */
65*0Sstevel@tonic-gate 	fasttrap_id_t *fti_next;		/* enabled probe list on tp */
66*0Sstevel@tonic-gate };
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate typedef struct fasttrap_id_tp {
69*0Sstevel@tonic-gate 	fasttrap_id_t fit_id;
70*0Sstevel@tonic-gate 	fasttrap_tracepoint_t *fit_tp;
71*0Sstevel@tonic-gate } fasttrap_id_tp_t;
72*0Sstevel@tonic-gate 
73*0Sstevel@tonic-gate struct fasttrap_probe {
74*0Sstevel@tonic-gate 	dtrace_id_t ftp_id;			/* DTrace probe identifier */
75*0Sstevel@tonic-gate 	pid_t ftp_pid;				/* pid for this probe */
76*0Sstevel@tonic-gate 	fasttrap_provider_t *ftp_prov;		/* this probe's provider */
77*0Sstevel@tonic-gate 	uintptr_t ftp_faddr;			/* associated function's addr */
78*0Sstevel@tonic-gate 	size_t ftp_fsize;			/* associated function's size */
79*0Sstevel@tonic-gate 	fasttrap_probe_type_t ftp_type;		/* type of probe */
80*0Sstevel@tonic-gate 	uint_t ftp_enabled;			/* is this probe enabled */
81*0Sstevel@tonic-gate 	uint64_t ftp_gen;			/* modification generation */
82*0Sstevel@tonic-gate 	uint64_t ftp_ntps;			/* number of tracepoints */
83*0Sstevel@tonic-gate 	uint8_t *ftp_argmap;			/* native to translated args */
84*0Sstevel@tonic-gate 	uint8_t ftp_nargs;			/* translated argument count */
85*0Sstevel@tonic-gate 	char *ftp_xtypes;			/* translated types index */
86*0Sstevel@tonic-gate 	char *ftp_ntypes;			/* native types index */
87*0Sstevel@tonic-gate 	fasttrap_id_tp_t ftp_tps[1];		/* flexible array */
88*0Sstevel@tonic-gate };
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate #define	FASTTRAP_ID_INDEX(id)	\
91*0Sstevel@tonic-gate ((fasttrap_id_tp_t *)(((char *)(id) - offsetof(fasttrap_id_tp_t, fit_id))) - \
92*0Sstevel@tonic-gate &(id)->fti_probe->ftp_tps[0])
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate struct fasttrap_tracepoint {
95*0Sstevel@tonic-gate 	fasttrap_provider_t	*ftt_prov;	/* tracepoint's provider */
96*0Sstevel@tonic-gate 	uintptr_t		ftt_pc;		/* address of tracepoint */
97*0Sstevel@tonic-gate 	pid_t			ftt_pid;	/* pid of tracepoint */
98*0Sstevel@tonic-gate 	fasttrap_machtp_t	ftt_mtp;	/* ISA-specific portion */
99*0Sstevel@tonic-gate 	fasttrap_id_t		*ftt_ids;	/* NULL-terminated list */
100*0Sstevel@tonic-gate 	fasttrap_id_t		*ftt_retids;	/* NULL-terminated list */
101*0Sstevel@tonic-gate 	fasttrap_tracepoint_t	*ftt_next;	/* link in global hash */
102*0Sstevel@tonic-gate };
103*0Sstevel@tonic-gate 
104*0Sstevel@tonic-gate typedef struct fasttrap_bucket {
105*0Sstevel@tonic-gate 	kmutex_t		ftb_mtx;
106*0Sstevel@tonic-gate 	void 			*ftb_data;
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate 	uint8_t		ftb_pad[64 - sizeof (kmutex_t) - sizeof (void *)];
109*0Sstevel@tonic-gate } fasttrap_bucket_t;
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate typedef struct fasttrap_hash {
112*0Sstevel@tonic-gate 	ulong_t			fth_nent;
113*0Sstevel@tonic-gate 	ulong_t			fth_mask;
114*0Sstevel@tonic-gate 	fasttrap_bucket_t	*fth_table;
115*0Sstevel@tonic-gate } fasttrap_hash_t;
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate /*
118*0Sstevel@tonic-gate  * If at some future point these assembly functions become observable by
119*0Sstevel@tonic-gate  * DTrace, then these defines should become separate functions so that the
120*0Sstevel@tonic-gate  * fasttrap provider doesn't trigger probes during internal operations.
121*0Sstevel@tonic-gate  */
122*0Sstevel@tonic-gate #define	fasttrap_copyout	copyout
123*0Sstevel@tonic-gate #define	fasttrap_fuword32	fuword32
124*0Sstevel@tonic-gate #define	fasttrap_suword32	suword32
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate #define	fasttrap_fulword	fulword
127*0Sstevel@tonic-gate #define	fasttrap_sulword	sulword
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate extern void fasttrap_sigtrap(proc_t *, kthread_t *, uintptr_t);
130*0Sstevel@tonic-gate 
131*0Sstevel@tonic-gate extern dtrace_id_t 		fasttrap_probe_id;
132*0Sstevel@tonic-gate extern fasttrap_hash_t		fasttrap_tpoints;
133*0Sstevel@tonic-gate 
134*0Sstevel@tonic-gate #define	FASTTRAP_TPOINTS_INDEX(pid, pc) \
135*0Sstevel@tonic-gate 	(((pc) / sizeof (fasttrap_instr_t) + (pid)) & fasttrap_tpoints.fth_mask)
136*0Sstevel@tonic-gate 
137*0Sstevel@tonic-gate /*
138*0Sstevel@tonic-gate  * Must be implemented by fasttrap_isa.c
139*0Sstevel@tonic-gate  */
140*0Sstevel@tonic-gate extern int fasttrap_tracepoint_init(proc_t *, fasttrap_probe_t *,
141*0Sstevel@tonic-gate     fasttrap_tracepoint_t *, uintptr_t);
142*0Sstevel@tonic-gate extern int fasttrap_tracepoint_install(proc_t *, fasttrap_tracepoint_t *);
143*0Sstevel@tonic-gate extern int fasttrap_tracepoint_remove(proc_t *, fasttrap_tracepoint_t *);
144*0Sstevel@tonic-gate 
145*0Sstevel@tonic-gate extern int fasttrap_probe(struct regs *);
146*0Sstevel@tonic-gate extern int fasttrap_pid_probe(struct regs *);
147*0Sstevel@tonic-gate extern int fasttrap_return_probe(struct regs *);
148*0Sstevel@tonic-gate 
149*0Sstevel@tonic-gate extern uint64_t fasttrap_getarg(void *, dtrace_id_t, void *, int, int);
150*0Sstevel@tonic-gate extern uint64_t fasttrap_usdt_getarg(void *, dtrace_id_t, void *, int, int);
151*0Sstevel@tonic-gate 
152*0Sstevel@tonic-gate #ifdef	__cplusplus
153*0Sstevel@tonic-gate }
154*0Sstevel@tonic-gate #endif
155*0Sstevel@tonic-gate 
156*0Sstevel@tonic-gate #endif	/* _FASTTRAP_IMPL_H */
157