xref: /freebsd/sys/sys/sdt.h (revision 438ca68cef3c678de1c01630266831a59818e208)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright 2006-2008 John Birrell <jb@FreeBSD.org>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * Statically Defined Tracing (SDT) definitions.
28  *
29  */
30 
31 #ifndef _SYS_SDT_H
32 #define	_SYS_SDT_H
33 
34 #ifndef _KERNEL
35 
36 #define	_DTRACE_VERSION	1
37 
38 #define	DTRACE_PROBE(prov, name) {				\
39 	extern void __dtrace_##prov##___##name(void);		\
40 	__dtrace_##prov##___##name();				\
41 }
42 
43 #define	DTRACE_PROBE1(prov, name, arg1) {			\
44 	extern void __dtrace_##prov##___##name(unsigned long);	\
45 	__dtrace_##prov##___##name((unsigned long)arg1);	\
46 }
47 
48 #define	DTRACE_PROBE2(prov, name, arg1, arg2) {			\
49 	extern void __dtrace_##prov##___##name(unsigned long,	\
50 	    unsigned long);					\
51 	__dtrace_##prov##___##name((unsigned long)arg1,		\
52 	    (unsigned long)arg2);				\
53 }
54 
55 #define	DTRACE_PROBE3(prov, name, arg1, arg2, arg3) {		\
56 	extern void __dtrace_##prov##___##name(unsigned long,	\
57 	    unsigned long, unsigned long);			\
58 	__dtrace_##prov##___##name((unsigned long)arg1,		\
59 	    (unsigned long)arg2, (unsigned long)arg3);		\
60 }
61 
62 #define	DTRACE_PROBE4(prov, name, arg1, arg2, arg3, arg4) {	\
63 	extern void __dtrace_##prov##___##name(unsigned long,	\
64 	    unsigned long, unsigned long, unsigned long);	\
65 	__dtrace_##prov##___##name((unsigned long)arg1,		\
66 	    (unsigned long)arg2, (unsigned long)arg3,		\
67 	    (unsigned long)arg4);				\
68 }
69 
70 #define	DTRACE_PROBE5(prov, name, arg1, arg2, arg3, arg4, arg5) {	\
71 	extern void __dtrace_##prov##___##name(unsigned long,		\
72 	    unsigned long, unsigned long, unsigned long, unsigned long);\
73 	__dtrace_##prov##___##name((unsigned long)arg1,			\
74 	    (unsigned long)arg2, (unsigned long)arg3,			\
75 	    (unsigned long)arg4, (unsigned long)arg5);			\
76 }
77 
78 #else /* _KERNEL */
79 
80 #include <sys/linker_set.h>
81 #include <machine/sdt_machdep.h>
82 
83 extern volatile bool sdt_probes_enabled;
84 
85 #ifndef KDTRACE_HOOKS
86 
87 #define __sdt_used	__unused
88 
89 #define SDT_PROVIDER_DEFINE(prov)
90 #define SDT_PROVIDER_DECLARE(prov)
91 #define SDT_PROBE_DEFINE(prov, mod, func, name)
92 #define SDT_PROBE_DECLARE(prov, mod, func, name)
93 #define SDT_PROBES_ENABLED()	0
94 #define SDT_PROBE(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4)
95 #define SDT_PROBE_ARGTYPE(prov, mod, func, name, num, type, xtype)
96 
97 #define	SDT_PROBE_DEFINE0(prov, mod, func, name)
98 #define	SDT_PROBE_DEFINE1(prov, mod, func, name, arg0)
99 #define	SDT_PROBE_DEFINE2(prov, mod, func, name, arg0, arg1)
100 #define	SDT_PROBE_DEFINE3(prov, mod, func, name, arg0, arg1, arg2)
101 #define	SDT_PROBE_DEFINE4(prov, mod, func, name, arg0, arg1, arg2, arg3)
102 #define	SDT_PROBE_DEFINE5(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4)
103 #define	SDT_PROBE_DEFINE6(prov, mod, func, name, arg0, arg1, arg2,      \
104     arg3, arg4, arg5)
105 
106 #define	SDT_PROBE0(prov, mod, func, name)
107 #define	SDT_PROBE1(prov, mod, func, name, arg0)
108 #define	SDT_PROBE2(prov, mod, func, name, arg0, arg1)
109 #define	SDT_PROBE3(prov, mod, func, name, arg0, arg1, arg2)
110 #define	SDT_PROBE4(prov, mod, func, name, arg0, arg1, arg2, arg3)
111 #define	SDT_PROBE5(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4)
112 #define	SDT_PROBE6(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4, arg5)
113 
114 #define	MIB_SDT_PROBE1(...)
115 #define	MIB_SDT_PROBE2(...)
116 
117 #define	SDT_PROBE_DEFINE0_XLATE(prov, mod, func, name)
118 #define	SDT_PROBE_DEFINE1_XLATE(prov, mod, func, name, arg0, xarg0)
119 #define	SDT_PROBE_DEFINE2_XLATE(prov, mod, func, name, arg0, xarg0,     \
120     arg1, xarg1)
121 #define	SDT_PROBE_DEFINE3_XLATE(prov, mod, func, name, arg0, xarg0,     \
122     arg1, xarg1, arg2, xarg2)
123 #define SDT_PROBE_DEFINE4_XLATE(prov, mod, func, name, arg0, xarg0,     \
124     arg1, xarg1, arg2, xarg2, arg3, xarg3)
125 #define	SDT_PROBE_DEFINE5_XLATE(prov, mod, func, name, arg0, xarg0,     \
126     arg1, xarg1, arg2, xarg2, arg3, xarg3, arg4, xarg4)
127 #define	SDT_PROBE_DEFINE6_XLATE(prov, mod, func, name, arg0, xarg0,     \
128     arg1,  xarg1, arg2, xarg2, arg3, xarg3, arg4, xarg4, arg5, xarg5)
129 
130 #define	DTRACE_PROBE(name)
131 #define	DTRACE_PROBE1(name, type0, arg0)
132 #define	DTRACE_PROBE2(name, type0, arg0, type1, arg1)
133 #define	DTRACE_PROBE3(name, type0, arg0, type1, arg1, type2, arg2)
134 #define	DTRACE_PROBE4(name, type0, arg0, type1, arg1, type2, arg2, type3, arg3)
135 #define	DTRACE_PROBE5(name, type0, arg0, type1, arg1, type2, arg2, type3, arg3,\
136     type4, arg4)
137 
138 #else
139 
140 void sdt_probe(uint32_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t,
141     uintptr_t);
142 void sdt_probe6(uint32_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t,
143     uintptr_t, uintptr_t);
144 
145 #define	_SDT_TRACEPOINT_SET		sdt_tracepoint_set
146 #define	_SDT_TRACEPOINT_SECTION		"set_sdt_tracepoint_set"
147 
148 bool sdt_tracepoint_valid(uintptr_t patchpoint, uintptr_t target);
149 void sdt_tracepoint_patch(uintptr_t patchpoint, uintptr_t target);
150 void sdt_tracepoint_restore(uintptr_t patchpoint);
151 
152 #define __sdt_used
153 
154 SET_DECLARE(sdt_providers_set, struct sdt_provider);
155 SET_DECLARE(sdt_probes_set, struct sdt_probe);
156 SET_DECLARE(sdt_argtypes_set, struct sdt_argtype);
157 
158 #define	_SDT_PROBE_NAME(prov, mod, func, name)				\
159 	sdt_##prov##_##mod##_##func##_##name
160 #define	_SDT_PROVIDER_NAME(prov)					\
161 	sdt_provider_##prov
162 
163 #define SDT_PROVIDER_DEFINE(_prov)					\
164 	struct sdt_provider _SDT_PROVIDER_NAME(_prov) = {		\
165 		.name = #_prov,						\
166 	};								\
167 	DATA_SET(sdt_providers_set, _SDT_PROVIDER_NAME(_prov))
168 
169 #define SDT_PROVIDER_DECLARE(prov)					\
170 	extern struct sdt_provider _SDT_PROVIDER_NAME(prov)
171 
172 #define SDT_PROBE_DEFINE(_prov, _mod, _func, _name)			\
173 	struct sdt_probe _SDT_PROBE_NAME(_prov, _mod, _func, _name) = {	\
174 		.version = sizeof(struct sdt_probe),			\
175 		.prov = &_SDT_PROVIDER_NAME(_prov),			\
176 		.mod = #_mod,						\
177 		.func = #_func,						\
178 		.name = #_name,						\
179 	};								\
180 	DATA_SET(sdt_probes_set, _SDT_PROBE_NAME(_prov, _mod, _func, _name))
181 
182 #define SDT_PROBE_DECLARE(prov, mod, func, name)			\
183 	extern struct sdt_probe _SDT_PROBE_NAME(prov, mod, func, name)
184 
185 #define	SDT_PROBES_ENABLED()	__predict_false(sdt_probes_enabled)
186 
187 #ifdef _ILP32
188 #define	_SDT_ASM_WORD			".long"
189 #else
190 #define	_SDT_ASM_WORD			".quad"
191 #endif
192 
193 #ifndef _SDT_ASM_PROBE_CONSTRAINT
194 #define	_SDT_ASM_PROBE_CONSTRAINT	"i"
195 #endif
196 #ifndef	_SDT_ASM_PROBE_OPERAND
197 #define	_SDT_ASM_PROBE_OPERAND		"c"
198 #endif
199 
200 /*
201  * The asm below generates records corresponding to the structure's layout, so
202  * the two must be kept in sync.
203  */
204 struct sdt_tracepoint {
205 	struct sdt_probe *probe;
206 	uintptr_t	patchpoint;
207 	uintptr_t	target;
208 	STAILQ_ENTRY(sdt_tracepoint) tracepoint_entry;
209 };
210 
211 #define __SDT_PROBE(prov, mod, func, name, uniq, f, ...) do {		\
212 	__WEAK(__CONCAT(__start_set_, _SDT_TRACEPOINT_SET));		\
213 	__WEAK(__CONCAT(__stop_set_, _SDT_TRACEPOINT_SET));		\
214 	asm goto(							\
215 	    "0:\n"							\
216 	    _SDT_ASM_PATCH_INSTR "\n"					\
217 	    ".pushsection " _SDT_TRACEPOINT_SECTION ", \"aw\"\n"	\
218 	    _SDT_ASM_WORD " %" _SDT_ASM_PROBE_OPERAND "0\n"		\
219 	    _SDT_ASM_WORD " 0b\n"					\
220 	    _SDT_ASM_WORD " %l1\n"					\
221 	    _SDT_ASM_WORD " 0\n"					\
222 	    ".popsection\n"						\
223 	    :								\
224 	    : _SDT_ASM_PROBE_CONSTRAINT (&_SDT_PROBE_NAME(prov, mod,	\
225 	    func, name))						\
226 	    :								\
227 	    : __sdt_probe##uniq);					\
228 	if (0) {							\
229 __sdt_probe##uniq:;							\
230 		f(_SDT_PROBE_NAME(prov, mod, func, name).id, __VA_ARGS__); \
231 	}								\
232 } while (0)
233 #define _SDT_PROBE(prov, mod, func, name, uniq, f, ...)			\
234 	__SDT_PROBE(prov, mod, func, name, uniq, f, __VA_ARGS__)
235 #define SDT_PROBE(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4)	\
236 	_SDT_PROBE(prov, mod, func, name, __COUNTER__, sdt_probe,	\
237 	    (uintptr_t)arg0, (uintptr_t)arg1, (uintptr_t)arg2,		\
238 	    (uintptr_t)arg3, (uintptr_t)arg4)
239 
240 #define SDT_PROBE_ARGTYPE(_prov, _mod, _func, _name, _num, _type, _xtype) \
241 	static struct sdt_argtype					\
242 	    sdta_##_prov##_##_mod##_##_func##_##_name##_num[1] = {	\
243 		[0] = {							\
244 		    .ndx = _num,					\
245 		    .type = _type,					\
246 		    .xtype = _xtype,					\
247 		    .probe = &_SDT_PROBE_NAME(_prov, _mod, _func, _name), \
248 		},							\
249 	};								\
250 	DATA_SET(sdt_argtypes_set,					\
251 	    sdta_##_prov##_##_mod##_##_func##_##_name##_num);
252 
253 #define	SDT_PROBE_DEFINE0(prov, mod, func, name)			\
254 	SDT_PROBE_DEFINE(prov, mod, func, name)
255 
256 #define	SDT_PROBE_DEFINE1(prov, mod, func, name, arg0)			\
257 	SDT_PROBE_DEFINE(prov, mod, func, name);			\
258 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, NULL)
259 
260 #define	SDT_PROBE_DEFINE2(prov, mod, func, name, arg0, arg1)		\
261 	SDT_PROBE_DEFINE(prov, mod, func, name);			\
262 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, NULL);	\
263 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, NULL)
264 
265 #define	SDT_PROBE_DEFINE3(prov, mod, func, name, arg0, arg1, arg2)\
266 	SDT_PROBE_DEFINE(prov, mod, func, name);			\
267 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, NULL);	\
268 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, NULL);	\
269 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, NULL)
270 
271 #define	SDT_PROBE_DEFINE4(prov, mod, func, name, arg0, arg1, arg2, arg3) \
272 	SDT_PROBE_DEFINE(prov, mod, func, name);			\
273 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, NULL);	\
274 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, NULL);	\
275 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, NULL);	\
276 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, NULL)
277 
278 #define	SDT_PROBE_DEFINE5(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4) \
279 	SDT_PROBE_DEFINE(prov, mod, func, name);			\
280 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, NULL);	\
281 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, NULL);	\
282 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, NULL);	\
283 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, NULL);	\
284 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 4, arg4, NULL)
285 
286 #define	SDT_PROBE_DEFINE6(prov, mod, func, name, arg0, arg1, arg2, arg3,\
287     arg4, arg5) \
288 	SDT_PROBE_DEFINE(prov, mod, func, name);			\
289 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, NULL);	\
290 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, NULL);	\
291 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, NULL);	\
292 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, NULL);	\
293 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 4, arg4, NULL);	\
294 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 5, arg5, NULL)
295 
296 #define	SDT_PROBE_DEFINE0_XLATE(prov, mod, func, name)		\
297 	SDT_PROBE_DEFINE(prov, mod, func, name)
298 
299 #define	SDT_PROBE_DEFINE1_XLATE(prov, mod, func, name, arg0, xarg0) \
300 	SDT_PROBE_DEFINE(prov, mod, func, name);			\
301 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, xarg0)
302 
303 #define	SDT_PROBE_DEFINE2_XLATE(prov, mod, func, name, arg0, xarg0, \
304     arg1,  xarg1)							\
305 	SDT_PROBE_DEFINE(prov, mod, func, name);			\
306 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, xarg0);	\
307 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, xarg1)
308 
309 #define	SDT_PROBE_DEFINE3_XLATE(prov, mod, func, name, arg0, xarg0, \
310     arg1, xarg1, arg2, xarg2)						\
311 	SDT_PROBE_DEFINE(prov, mod, func, name);			\
312 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, xarg0);	\
313 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, xarg1);	\
314 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, xarg2)
315 
316 #define	SDT_PROBE_DEFINE4_XLATE(prov, mod, func, name, arg0, xarg0, \
317     arg1, xarg1, arg2, xarg2, arg3, xarg3)				\
318 	SDT_PROBE_DEFINE(prov, mod, func, name);			\
319 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, xarg0);	\
320 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, xarg1);	\
321 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, xarg2);	\
322 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, xarg3)
323 
324 #define	SDT_PROBE_DEFINE5_XLATE(prov, mod, func, name, arg0, xarg0, \
325     arg1, xarg1, arg2, xarg2, arg3, xarg3, arg4, xarg4)			\
326 	SDT_PROBE_DEFINE(prov, mod, func, name);			\
327 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, xarg0);	\
328 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, xarg1);	\
329 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, xarg2);	\
330 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, xarg3);	\
331 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 4, arg4, xarg4)
332 
333 #define	SDT_PROBE_DEFINE6_XLATE(prov, mod, func, name, arg0, xarg0, \
334     arg1, xarg1, arg2, xarg2, arg3, xarg3, arg4, xarg4, arg5, xarg5)	\
335 	SDT_PROBE_DEFINE(prov, mod, func, name);			\
336 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0, xarg0);	\
337 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1, xarg1);	\
338 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2, xarg2);	\
339 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3, xarg3);	\
340 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 4, arg4, xarg4);	\
341 	SDT_PROBE_ARGTYPE(prov, mod, func, name, 5, arg5, xarg5)
342 
343 #define	SDT_PROBE0(prov, mod, func, name)				\
344 	SDT_PROBE(prov, mod, func, name, 0, 0, 0, 0, 0)
345 #define	SDT_PROBE1(prov, mod, func, name, arg0)				\
346 	SDT_PROBE(prov, mod, func, name, arg0, 0, 0, 0, 0)
347 #define	SDT_PROBE2(prov, mod, func, name, arg0, arg1)			\
348 	SDT_PROBE(prov, mod, func, name, arg0, arg1, 0, 0, 0)
349 #define	SDT_PROBE3(prov, mod, func, name, arg0, arg1, arg2)		\
350 	SDT_PROBE(prov, mod, func, name, arg0, arg1, arg2,  0, 0)
351 #define	SDT_PROBE4(prov, mod, func, name, arg0, arg1, arg2, arg3)	\
352 	SDT_PROBE(prov, mod, func, name, arg0, arg1, arg2, arg3, 0)
353 #define	SDT_PROBE5(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4) \
354 	SDT_PROBE(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4)
355 #define	SDT_PROBE6(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4, arg5) \
356 	_SDT_PROBE(prov, mod, func, name, __COUNTER__, sdt_probe6,	\
357 	    (uintptr_t)arg0, (uintptr_t)arg1, (uintptr_t)arg2,		\
358 	    (uintptr_t)arg3, (uintptr_t)arg4, (uintptr_t)arg5)
359 
360 #ifdef KDTRACE_MIB_SDT
361 #define	MIB_SDT_PROBE1(...)	SDT_PROBE1(mib, __VA_ARGS__)
362 #define	MIB_SDT_PROBE2(...)	SDT_PROBE2(mib, __VA_ARGS__)
363 #else
364 #define	MIB_SDT_PROBE1(...)
365 #define	MIB_SDT_PROBE2(...)
366 #endif
367 
368 #define	DTRACE_PROBE_IMPL_START(name, arg0, arg1, arg2, arg3, arg4)	do { \
369 	static SDT_PROBE_DEFINE(sdt, , , name);				     \
370 	SDT_PROBE(sdt, , , name, arg0, arg1, arg2, arg3, arg4);
371 #define DTRACE_PROBE_IMPL_END	} while (0)
372 
373 #define DTRACE_PROBE(name)						\
374 	DTRACE_PROBE_IMPL_START(name, 0, 0, 0, 0, 0)			\
375 	DTRACE_PROBE_IMPL_END
376 
377 #define DTRACE_PROBE1(name, type0, arg0)				\
378 	DTRACE_PROBE_IMPL_START(name, arg0, 0, 0, 0, 0) 		\
379 	SDT_PROBE_ARGTYPE(sdt, , , name, 0, #type0, NULL);		\
380 	DTRACE_PROBE_IMPL_END
381 
382 #define DTRACE_PROBE2(name, type0, arg0, type1, arg1)			\
383 	DTRACE_PROBE_IMPL_START(name, arg0, arg1, 0, 0, 0) 		\
384 	SDT_PROBE_ARGTYPE(sdt, , , name, 0, #type0, NULL);		\
385 	SDT_PROBE_ARGTYPE(sdt, , , name, 1, #type1, NULL);		\
386 	DTRACE_PROBE_IMPL_END
387 
388 #define DTRACE_PROBE3(name, type0, arg0, type1, arg1, type2, arg2)	\
389 	DTRACE_PROBE_IMPL_START(name, arg0, arg1, arg2, 0, 0)	 	\
390 	SDT_PROBE_ARGTYPE(sdt, , , name, 0, #type0, NULL);		\
391 	SDT_PROBE_ARGTYPE(sdt, , , name, 1, #type1, NULL);		\
392 	SDT_PROBE_ARGTYPE(sdt, , , name, 2, #type2, NULL);		\
393 	DTRACE_PROBE_IMPL_END
394 
395 #define DTRACE_PROBE4(name, type0, arg0, type1, arg1, type2, arg2, type3, arg3)	\
396 	DTRACE_PROBE_IMPL_START(name, arg0, arg1, arg2, arg3, 0) 	\
397 	SDT_PROBE_ARGTYPE(sdt, , , name, 0, #type0, NULL);		\
398 	SDT_PROBE_ARGTYPE(sdt, , , name, 1, #type1, NULL);		\
399 	SDT_PROBE_ARGTYPE(sdt, , , name, 2, #type2, NULL);		\
400 	SDT_PROBE_ARGTYPE(sdt, , , name, 3, #type3, NULL);		\
401 	DTRACE_PROBE_IMPL_END
402 
403 #define DTRACE_PROBE5(name, type0, arg0, type1, arg1, type2, arg2, type3, arg3,	\
404     type4, arg4)								\
405 	DTRACE_PROBE_IMPL_START(name, arg0, arg1, arg2, arg3, arg4) 	\
406 	SDT_PROBE_ARGTYPE(sdt, , , name, 0, #type0, NULL);		\
407 	SDT_PROBE_ARGTYPE(sdt, , , name, 1, #type1, NULL);		\
408 	SDT_PROBE_ARGTYPE(sdt, , , name, 2, #type2, NULL);		\
409 	SDT_PROBE_ARGTYPE(sdt, , , name, 3, #type3, NULL);		\
410 	SDT_PROBE_ARGTYPE(sdt, , , name, 4, #type4, NULL);		\
411 	DTRACE_PROBE_IMPL_END
412 
413 #endif /* KDTRACE_HOOKS */
414 
415 /*
416  * This type definition must match that of dtrace_probe. It is defined this
417  * way to avoid having to rely on CDDL code.
418  */
419 typedef	void (*sdt_probe_func_t)(uint32_t, uintptr_t arg0, uintptr_t arg1,
420     uintptr_t arg2, uintptr_t arg3, uintptr_t arg4, uintptr_t arg5);
421 
422 /*
423  * The 'sdt' provider will set it to dtrace_probe when it loads.
424  */
425 extern sdt_probe_func_t		sdt_probe_func;
426 
427 struct sdt_probe;
428 struct sdt_provider;
429 struct linker_file;
430 
431 struct sdt_argtype {
432 	int		ndx;		/* Argument index. */
433 	const char	*type;		/* Argument type string. */
434 	const char	*xtype;		/* Translated argument type. */
435 	TAILQ_ENTRY(sdt_argtype)
436 			argtype_entry;	/* Argument type list entry. */
437 	struct sdt_probe *probe;	/* Ptr to the probe structure. */
438 };
439 
440 struct sdt_probe {
441 	int		version;	/* Set to sizeof(struct sdt_probe). */
442 	struct sdt_provider *prov;	/* Ptr to the provider structure. */
443 	TAILQ_ENTRY(sdt_probe)
444 			probe_entry;	/* SDT probe list entry. */
445 	TAILQ_HEAD(, sdt_argtype) argtype_list;
446 	STAILQ_HEAD(, sdt_tracepoint) tracepoint_list;
447 	const char	*mod;
448 	const char	*func;
449 	const char	*name;
450 	id_t		id;		/* DTrace probe ID. */
451 	int		n_args;		/* Number of arguments. */
452 	struct linker_file *sdtp_lf;	/* Module in which we're defined. */
453 };
454 
455 struct sdt_provider {
456 	char *name;			/* Provider name. */
457 	TAILQ_ENTRY(sdt_provider)
458 			prov_entry;	/* SDT provider list entry. */
459 	uintptr_t	id;		/* DTrace provider ID. */
460 	int		sdt_refs;	/* Number of module references. */
461 };
462 
463 void sdt_probe_stub(uint32_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t,
464     uintptr_t, uintptr_t);
465 
466 SDT_PROVIDER_DECLARE(sdt);
467 
468 #endif /* _KERNEL */
469 
470 #endif /* _SYS_SDT_H */
471