xref: /illumos-gate/usr/src/uts/common/sys/sdt_impl.h (revision bb65110f7220d348d063c325407fdf3f616f4ee8)
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 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
29  * Copyright 2024 Oxide Computer Company
30  */
31 
32 #ifndef _SYS_SDT_IMPL_H
33 #define	_SYS_SDT_IMPL_H
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #include <sys/dtrace.h>
40 
41 #if defined(__i386) || defined(__amd64)
42 #define	SDT_CALL	0xe8
43 #define	SDT_NOP		0x90
44 #define	SDT_RET		0xc3
45 
46 /*
47  * The kernel runtime linker (krtld) will perform the patching described above
48  * and note the offset of the instruction that was patched for the SDT module
49  * in the sdpd_offset field of the sdt_probedesc_t structure.  In the case of
50  * a tail call, this index will be a RET otherwise it will be a NOP.
51  */
52 #define	SDT_OFF_RET_IDX	3
53 
54 typedef uint8_t sdt_instr_t;
55 #else
56 typedef uint32_t sdt_instr_t;
57 #endif
58 
59 typedef struct sdt_provider {
60 	char			*sdtp_name;	/* name of provider */
61 	char			*sdtp_prefix;	/* prefix for probe names */
62 	dtrace_pattr_t		*sdtp_attr;	/* stability attributes */
63 	uint32_t		sdtp_priv;	/* privilege, if any */
64 	dtrace_provider_id_t	sdtp_id;	/* provider ID */
65 } sdt_provider_t;
66 
67 extern sdt_provider_t sdt_providers[];		/* array of providers */
68 
69 typedef struct sdt_probe {
70 	sdt_provider_t	*sdp_provider;		/* provider */
71 	char		*sdp_name;		/* name of probe */
72 	int		sdp_namelen;		/* length of allocated name */
73 	dtrace_id_t	sdp_id;			/* probe ID */
74 	struct modctl	*sdp_ctl;		/* modctl for module */
75 	int		sdp_loadcnt;		/* load count for module */
76 	int		sdp_primary;		/* non-zero if primary mod */
77 	sdt_instr_t	*sdp_patchpoint;	/* patch point */
78 	sdt_instr_t	sdp_patchval;		/* instruction to patch */
79 	sdt_instr_t	sdp_savedval;		/* saved instruction value */
80 	boolean_t	sdp_is_tailcall;	/* invoked as a tail call */
81 	struct sdt_probe *sdp_next;		/* next probe */
82 	struct sdt_probe *sdp_hashnext;		/* next on hash */
83 } sdt_probe_t;
84 
85 typedef struct sdt_argdesc {
86 	const char *sda_provider;		/* provider for arg */
87 	const char *sda_name;			/* name of probe */
88 	const int sda_ndx;			/* argument index */
89 	const int sda_mapping;			/* mapping of argument */
90 	const char *sda_native;			/* native type of argument */
91 	const char *sda_xlate;			/* translated type of arg */
92 } sdt_argdesc_t;
93 
94 extern void sdt_getargdesc(void *, dtrace_id_t, void *, dtrace_argdesc_t *);
95 extern int sdt_mode(void *, dtrace_id_t, void *);
96 
97 #ifdef	__cplusplus
98 }
99 #endif
100 
101 #endif	/* _SYS_SDT_IMPL_H */
102