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