xref: /xnu-12377.81.4/libkern/firehose/firehose_types_private.h (revision 043036a2b3718f7f0be807e2870f8f47d3fa0796)
1 /*
2  * Copyright (c) 2015-2024 Apple Inc. All rights reserved.
3  *
4  * @APPLE_APACHE_LICENSE_HEADER_START@
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * @APPLE_APACHE_LICENSE_HEADER_END@
19  */
20 
21 #ifndef __FIREHOSE_TYPES_PRIVATE__
22 #define __FIREHOSE_TYPES_PRIVATE__
23 
24 #include <mach/mach_types.h>
25 #include <mach/std_types.h>
26 #include <os/base.h>
27 
28 OS_ASSUME_NONNULL_BEGIN
29 
30 __BEGIN_DECLS
31 
32 /*!
33  * @enum firehose_activity_flags_t
34  *
35  * @discussion
36  * The lower 8 bits are or-ed in the upper 8 bits of Activity ID and propagated
37  * to children activities
38  */
39 OS_OPTIONS(firehose_activity_flags, unsigned long,
40     firehose_activity_flags_default             = 0x0000,
41 
42     firehose_activity_flags_info_mode           = 0x0001,
43     firehose_activity_flags_debug_mode          = 0x0002,
44     firehose_activity_flags_stream_live_mode    = 0x0004,
45 
46     firehose_activity_flags_precise_timestamp   = 0x0080,
47     );
48 
49 /*!
50  * @typedef firehose_activity_id_t
51  *
52  * @abstract
53  * Opaque activity identifier.
54  *
55  * @discussion
56  * Scalar value type, not reference counted.
57  */
58 typedef uint64_t firehose_activity_id_t;
59 #define FIREHOSE_ACTIVITY_ID_NULL    ((firehose_activity_id_t)0)
60 #define FIREHOSE_ACTIVITY_ID_INVALID ((firehose_activity_id_t)~0ULL)
61 #define FIREHOSE_ACTIVITY_ID_FLAGS_SHIFT 56
62 #define FIREHOSE_ACTIVITY_ID_FLAGS(aid) \
63 	        ((firehose_activity_flags_t)((aid) >> FIREHOSE_ACTIVITY_ID_FLAGS_SHIFT))
64 #define FIREHOSE_ACTIVITY_ID_MERGE_FLAGS(aid, flags) (\
65 	        ((firehose_activity_id_t)(aid)) | \
66 	        ((firehose_activity_id_t)(flags) << FIREHOSE_ACTIVITY_ID_FLAGS_SHIFT))
67 
68 /*!
69  * @enum firehose_stream_t
70  */
71 OS_ENUM(firehose_stream, uint8_t,
72     firehose_stream_persist                     = 0,
73     firehose_stream_special                     = 1,
74     firehose_stream_memory                      = 2,
75     firehose_stream_metadata                    = 3,
76     firehose_stream_signpost                    = 4,
77     firehose_stream_memory_wifi                 = 5,
78     firehose_stream_memory_baseband             = 6,
79     firehose_stream_metric                      = 7,
80 
81     _firehose_stream_max,
82     _firehose_stream_disabled = (uint8_t)-1,
83     );
84 
85 /*!
86  * @enum firehose_tracepoint_namespace_t
87  *
88  * @abstract
89  * Namespaces of tracepoints.
90  */
91 OS_ENUM(firehose_tracepoint_namespace, uint8_t,
92     firehose_tracepoint_namespace_activity      = 0x02,
93     firehose_tracepoint_namespace_trace         = 0x03,
94     firehose_tracepoint_namespace_log           = 0x04,
95     firehose_tracepoint_namespace_metadata      = 0x05,
96     firehose_tracepoint_namespace_signpost      = 0x06,
97     firehose_tracepoint_namespace_loss          = 0x07,
98     firehose_tracepoint_namespace_metric        = 0x08,
99     );
100 
101 /*!
102  * @enum firehose_tracepoint_code_t
103  *
104  * @abstract
105  * Codes of tracepoints.
106  */
107 OS_ENUM(firehose_tracepoint_code, uint32_t,
108     firehose_tracepoint_code_invalid              = 0x00,
109     firehose_tracepoint_code_load                 = 0x01,
110     firehose_tracepoint_code_unload               = 0x02,
111     firehose_tracepoint_code_load_memory          = 0x08,
112     firehose_tracepoint_code_load_filesystem_ftab = 0x10,
113     firehose_tracepoint_code_load_exclavekit_dsc  = 0x20,
114     );
115 
116 /*!
117  * @typedef firehose_tracepoint_type_t
118  *
119  * @abstract
120  * Type of tracepoints.
121  */
122 typedef uint8_t firehose_tracepoint_type_t;
123 
124 /*!
125  * @typedef firehose_tracepoint_flags_t
126  *
127  * @abstract
128  * Flags for tracepoints.
129  */
130 OS_OPTIONS(firehose_tracepoint_flags, uint16_t,
131     _firehose_tracepoint_flags_base_has_current_aid         = 0x0001,
132 #define _firehose_tracepoint_flags_pc_style_mask                 (0x0007 << 1)
133     _firehose_tracepoint_flags_pc_style_none                = 0x0000 << 1,
134         _firehose_tracepoint_flags_pc_style_main_exe            = 0x0001 << 1,
135         _firehose_tracepoint_flags_pc_style_shared_cache        = 0x0002 << 1,
136         _firehose_tracepoint_flags_pc_style_main_plugin         = 0x0003 << 1,
137         _firehose_tracepoint_flags_pc_style_absolute            = 0x0004 << 1,
138         _firehose_tracepoint_flags_pc_style_uuid_relative       = 0x0005 << 1,
139         _firehose_tracepoint_flags_pc_style_large_shared_cache  = 0x0006 << 1,
140         _firehose_tracepoint_flags_pc_style__unused7            = 0x0007 << 1,
141         _firehose_tracepoint_flags_base_has_unique_pid          = 0x0010,
142         _firehose_tracepoint_flags_base_has_large_offset        = 0x0020,
143         _firehose_tracepoint_flags_base_has_persona             = 0x0040,
144     );
145 
146 /*
147  * Same as _OS_TRACE_DYNAMIC_BIT defined in libtrace/tracepoint_internal.h.
148  * This bit is used by logd to know how to evaluate the format
149  * string.
150  * If it is set, logd assumes that the format is "%s" and the content of the
151  * whole string is passed with the firehose_tracepoint.
152  * Otherwise it tries to find the unformatted string within the text
153  * section of the executable and expects only the content of the variables
154  * on the firehose_tracepoint.
155  */
156 #define FIREHOSE_TRACEPOINT_PC_DYNAMIC_BIT 0x80000000
157 
158 /*
159  * Same as KERNEL_MASK defined in logd/logd_main.c
160  * It is used by logd to mask the pc before calling
161  * OSKextCopyUUIDForAddress.
162  */
163 #define FIREHOSE_TRACEPOINT_PC_KERNEL_MASK 0xffff000000000000
164 
165 /*!
166  * @typedef firehose_tracepoint_id_t
167  *
168  * @abstract
169  * Opaque tracepoint identifier.
170  */
171 typedef uint64_t firehose_tracepoint_id_t;
172 
173 /*!
174  * @enum _firehose_tracepoint_type_activity_t
175  *
176  * @abstract
177  * Types of Activity tracepoints (namespace activity).
178  */
179 OS_ENUM(_firehose_tracepoint_type_activity, firehose_tracepoint_type_t,
180     _firehose_tracepoint_type_activity_create               = 0x01,
181     _firehose_tracepoint_type_activity_swap                 = 0x02,
182     _firehose_tracepoint_type_activity_useraction           = 0x03,
183     );
184 
185 /*!
186  * @enum firehose_tracepoint_flags_activity_t
187  *
188  * @abstract
189  * Flags for Activity tracepoints (namespace activity).
190  */
191 OS_OPTIONS(_firehose_tracepoint_flags_activity, uint16_t,
192     _firehose_tracepoint_flags_activity_user_interface      = 0x0100,
193     _firehose_tracepoint_flags_activity_has_other_aid       = 0x0200,
194     );
195 
196 /*!
197  * @enum firehose_tracepoint_type_trace_t
198  *
199  * @abstract
200  * Types of trace tracepoints (namespace trace).
201  */
202 OS_ENUM(_firehose_tracepoint_type_trace, firehose_tracepoint_type_t,
203     _firehose_tracepoint_type_trace_default                 = 0x00,
204     _firehose_tracepoint_type_trace_info                    = 0x01,
205     _firehose_tracepoint_type_trace_debug                   = 0x02,
206     _firehose_tracepoint_type_trace_error                   = 0x10,
207     _firehose_tracepoint_type_trace_fault                   = 0x11,
208     );
209 
210 /*!
211  * @enum firehose_tracepoint_type_log_t
212  *
213  * @abstract
214  * Types of Log tracepoints (namespace log).
215  */
216 OS_ENUM(_firehose_tracepoint_type_log, firehose_tracepoint_type_t,
217     _firehose_tracepoint_type_log_default                   = 0x00,
218     _firehose_tracepoint_type_log_info                      = 0x01,
219     _firehose_tracepoint_type_log_debug                     = 0x02,
220     _firehose_tracepoint_type_log_error                     = 0x10,
221     _firehose_tracepoint_type_log_fault                     = 0x11,
222     );
223 
224 /*!
225  * @enum firehose_tracepoint_flags_log_t
226  *
227  * @abstract
228  * Flags for Log tracepoints (namespace log).
229  */
230 OS_OPTIONS(_firehose_tracepoint_flags_log, uint16_t,
231     _firehose_tracepoint_flags_log_has_private_data         = 0x0100,
232     _firehose_tracepoint_flags_log_has_subsystem            = 0x0200,
233     _firehose_tracepoint_flags_log_has_rules                = 0x0400,
234     _firehose_tracepoint_flags_log_has_oversize             = 0x0800,
235     _firehose_tracepoint_flags_log_has_context_data         = 0x1000,
236     );
237 
238 /*!
239  * @enum _firehose_tracepoint_type_metadata_t
240  *
241  * @abstract
242  * Types for metadata tracepoints (namespace metadata).
243  */
244 OS_ENUM(_firehose_tracepoint_type_metadata, firehose_tracepoint_type_t,
245     _firehose_tracepoint_type_metadata_dyld                 = 0x01,
246     _firehose_tracepoint_type_metadata_subsystem            = 0x02,
247     _firehose_tracepoint_type_metadata_kext                 = 0x03,
248     _firehose_tracepoint_type_metadata_coprocessor          = 0x04,
249     _firehose_tracepoint_type_metadata_exclave              = 0x05,
250     );
251 
252 /*!
253  * @enum firehose_tracepoint_type_signpost_t
254  *
255  * @abstract
256  * Types of Log tracepoints (namespace signpost).
257  */
258 OS_ENUM(_firehose_tracepoint_type_signpost, firehose_tracepoint_type_t,
259     _firehose_tracepoint_type_signpost_event                = 0x00,
260     _firehose_tracepoint_type_signpost_interval_begin       = 0x01,
261     _firehose_tracepoint_type_signpost_interval_end         = 0x02,
262 
263     _firehose_tracepoint_type_signpost_scope_mask           = 0xc0,
264     _firehose_tracepoint_type_signpost_scope_thread         = 0x40,
265     _firehose_tracepoint_type_signpost_scope_process        = 0x80,
266     _firehose_tracepoint_type_signpost_scope_system         = 0xc0,
267     );
268 
269 /*!
270  * @enum firehose_tracepoint_flags_signpost_t
271  *
272  * @abstract
273  * Flags for Log tracepoints (namespace signpost).
274  *
275  * When flags are shared with the log type, they should have the same values.
276  */
277 OS_OPTIONS(_firehose_tracepoint_flags_signpost, uint16_t,
278     // shared with log
279     _firehose_tracepoint_flags_signpost_has_private_data    = 0x0100,
280     _firehose_tracepoint_flags_signpost_has_subsystem       = 0x0200,
281     _firehose_tracepoint_flags_signpost_has_rules           = 0x0400,
282     _firehose_tracepoint_flags_signpost_has_oversize        = 0x0800,
283     _firehose_tracepoint_flags_signpost_has_context_data    = 0x1000,
284 
285     // specific to signpost
286     _firehose_tracepoint_flags_signpost_has_name            = 0x8000,
287     );
288 
289 /*!
290  * @enum _firehose_tracepoint_type_metric_t
291  *
292  * @abstract
293  * Types of Metric tracepoints (namespace metric).
294  */
295 OS_ENUM(_firehose_tracepoint_type_metric, firehose_tracepoint_type_t,
296     _firehose_tracepoint_type_metric_integer                = 0x00,
297     _firehose_tracepoint_type_metric_double                 = 0x01,
298     );
299 
300 /*!
301  * @enum firehose_tracepoint_flags_metric_t
302  *
303  * @abstract
304  * Flags for Metric tracepoints (namespace metric).
305  *
306  * When flags are shared with the log type, they should have the same values.
307  */
308 OS_OPTIONS(_firehose_tracepoint_flags_metric, uint16_t,
309     // shared with log
310     _firehose_tracepoint_flags_metric_has_private_data      = 0x0100,
311     _firehose_tracepoint_flags_metric_has_subsystem         = 0x0200,
312     _firehose_tracepoint_flags_metric_has_rules             = 0x0400,
313     _firehose_tracepoint_flags_metric_has_oversize          = 0x0800,
314     _firehose_tracepoint_flags_metric_has_context_data      = 0x1000,
315     );
316 
317 /* MIG firehose push reply structure */
318 typedef struct firehose_push_reply_s {
319 	uint64_t fpr_mem_flushed_pos;
320 	uint64_t fpr_io_flushed_pos;
321 } firehose_push_reply_t;
322 
323 typedef struct firehose_buffer_map_info_s {
324 	mach_vm_address_t fbmi_addr;
325 	mach_vm_size_t fbmi_size;
326 } firehose_buffer_map_info_t;
327 
328 #define FIREHOSE_PUSH_REPLY_CORRUPTED  ((firehose_push_reply_t){ ~0ULL, ~0ULL })
329 
330 typedef union firehose_buffer_u *firehose_buffer_t;
331 
332 __END_DECLS
333 
334     OS_ASSUME_NONNULL_END
335 
336 #endif // __FIREHOSE_TYPES_PRIVATE__
337