xref: /xnu-11215.41.3/bsd/sys/fasttrap.h (revision 33de042d024d46de5ff4e89f2471de6608e37fa4)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_FASTTRAP_H
28 #define	_SYS_FASTTRAP_H
29 
30 #include <sys/fasttrap_isa.h>
31 #include <sys/dtrace.h>
32 #include <sys/types.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 #if !defined(__APPLE__)
39 #define	FASTTRAPIOC		(('m' << 24) | ('r' << 16) | ('f' << 8))
40 #else
41 #define	FASTTRAPIOC		_IO('d', 0)
42 #endif /* __APPLE__ */
43 #define	FASTTRAPIOC_MAKEPROBE	(FASTTRAPIOC | 1)
44 #define	FASTTRAPIOC_GETINSTR	(FASTTRAPIOC | 2)
45 
46 typedef enum fasttrap_probe_type {
47 	DTFTP_NONE = 0,
48 	DTFTP_ENTRY,
49 	DTFTP_RETURN,
50 	DTFTP_OFFSETS,
51 	DTFTP_POST_OFFSETS,
52 	DTFTP_IS_ENABLED
53 } fasttrap_probe_type_t;
54 
55 #if defined(__APPLE__)
56 typedef enum fasttrap_provider_type {
57 	DTFTP_PROVIDER_NONE = 0,
58 	DTFTP_PROVIDER_USDT,
59 	DTFTP_PROVIDER_PID,
60 	DTFTP_PROVIDER_OBJC,
61 	DTFTP_PROVIDER_ONESHOT
62 } fasttrap_provider_type_t;
63 
64 /* Moved from fasttrap.c */
65 #define	FASTTRAP_PID_NAME		"pid"
66 #define	FASTTRAP_OBJC_NAME		"objc"
67 #define	FASTTRAP_ONESHOT_NAME		"oneshot"
68 
69 #endif
70 
71 typedef struct fasttrap_probe_spec {
72 	pid_t				ftps_pid;
73 #if defined(__APPLE__)
74 	fasttrap_provider_type_t	ftps_provider_type;
75 	fasttrap_probe_type_t		ftps_probe_type;
76 #if defined(__arm__) || defined(__arm64__)
77 	uint32_t			ftps_arch_subinfo;	// For any additional per probe architecture specific data
78 #endif
79 #endif
80 	char				ftps_func[DTRACE_FUNCNAMELEN];
81 	char				ftps_mod[DTRACE_MODNAMELEN];
82 
83 #if defined(__APPLE__)
84 #if defined(__arm__) || defined(__arm64__)
85 	// We already have 'padding' from the ftps_arch_subinfo above
86 #else
87 #if !defined(__LP64__)
88 	uint32_t			pad; /* Explicit pad to keep ILP32 and LP64 lined up. */
89 #endif
90 #endif
91 #endif
92 	uint64_t			ftps_pc;
93 	uint64_t			ftps_size;
94 	uint64_t			ftps_noffs;
95 	uint64_t			ftps_offs[1];
96 } fasttrap_probe_spec_t;
97 
98 typedef struct fasttrap_instr_query {
99 	uint64_t		ftiq_pc;
100 	pid_t			ftiq_pid;
101 	fasttrap_instr_t	ftiq_instr;
102 } fasttrap_instr_query_t;
103 
104 /*
105  * To support the fasttrap provider from very early in a process's life,
106  * the run-time linker, ld.so.1, has a program header of type PT_SUNWDTRACE
107  * which points to a data object which must be PT_SUNWDTRACE_SIZE bytes.
108  * This structure mimics the fasttrap provider section of the ulwp_t structure.
109  * When the fasttrap provider is changed to require new or different
110  * instructions, the data object in ld.so.1 and the thread initializers in libc
111  * (libc_init() and _thrp_create()) need to be updated to include the new
112  * instructions, and PT_SUNWDTRACE needs to be changed to a new unique number
113  * (while the old value gets assigned something like PT_SUNWDTRACE_1). Since the
114  * linker must be backward compatible with old Solaris releases, it must have
115  * program headers for each of the PT_SUNWDTRACE versions. The kernel's
116  * elfexec() function only has to look for the latest version of the
117  * PT_SUNWDTRACE program header.
118  */
119 #define	PT_SUNWDTRACE_SIZE	FASTTRAP_SUNWDTRACE_SIZE
120 
121 #ifdef	__cplusplus
122 }
123 #endif
124 
125 #endif	/* _SYS_FASTTRAP_H */
126