xref: /xnu-11417.121.6/libkdd/kcdtypes.c (revision a1e26a70f38d1d7daa7b49b258e2f8538ad81650)
1 /*
2  * Copyright (c) 2015 Apple Inc. All rights reserved.
3  *
4  * @APPLE_LICENSE_HEADER_START@
5  *
6  * This file contains Original Code and/or Modifications of Original Code
7  * as defined in and that are subject to the Apple Public Source License
8  * Version 2.0 (the 'License'). You may not use this file except in
9  * compliance with the License. Please obtain a copy of the License at
10  * http://www.opensource.apple.com/apsl/ and read it before using this
11  * file.
12  *
13  * The Original Code and all software distributed under the License are
14  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18  * Please see the License for the specific language governing rights and
19  * limitations under the License.
20  *
21  * @APPLE_LICENSE_HEADER_END@
22  */
23 
24 #include <kcdata.h>
25 #include <sys/time.h>
26 #include <stdlib.h>
27 #include <stddef.h>
28 #include <string.h>
29 #include <assert.h>
30 #include <stdio.h>
31 #include <mach/mach_time.h>
32 #include <assert.h>
33 
34 /*!
35  * @function kcdata_get_typedescription
36  *
37  * @abstract
38  * Search the known type definitions for type with id type_id.
39  *
40  * @param type_id
41  * A unsinged int type specified by the KCDATA.
42  *
43  * @param buffer
44  * pointer to data area where type definition will be saved.
45  *
46  * @param buffer_size
47  * size of the buffer provided.
48  *
49  * @return struct kcdata_type_definition *
50  * pointer to a malloc'ed buffer holding the type definition and each subtype defintion for its fields.
51  * It may return NULL if no type with id == type_id is found.
52  * Note: The caller is responsible to free() the memory when its no longer used.
53  *
54  * @discussion
55  * This function queries the known type definitions table. If found the defintion data is returned
56  * else NULL is returned. It is advised to cache the return value from this function since the data
57  * is always going to be the same for same type_id. The definition setup requires memory on heap.
58  * The caller should make sure to free() the data once its done with using it.
59  *
60  */
61 struct kcdata_type_definition * kcdata_get_typedescription(unsigned type_id, uint8_t * buffer, uint32_t buffer_size);
62 
63 /* forward declarations for helper routines */
64 static uint32_t get_kctype_subtype_size(kctype_subtype_t type);
65 static void setup_subtype_description(kcdata_subtype_descriptor_t desc, kctype_subtype_t type, uint32_t offset, char * name);
66 static void setup_subtype_array_description(
67 	kcdata_subtype_descriptor_t desc, kctype_subtype_t type, uint32_t offset, uint32_t count, char * name);
68 static void setup_type_definition(struct kcdata_type_definition * d, uint32_t type, uint32_t num_elems, char * name);
69 
70 struct kcdata_type_definition *
kcdata_get_typedescription(unsigned type_id,uint8_t * buffer,uint32_t buffer_size)71 kcdata_get_typedescription(unsigned type_id, uint8_t * buffer, uint32_t buffer_size)
72 {
73 	unsigned int i = 0;
74 #define _STR_VALUE(x) #x
75 #define _SUBTYPE_TRUNC(t, s, f, name) do { \
76     setup_subtype_description(&subtypes[i++], (t), offsetof(s, f), name); \
77     _Static_assert(sizeof(name) == sizeof ((struct kcdata_subtype_descriptor *)0)->kcs_name, "\"" name "\" should fit exactly in kcs_name"); \
78 } while (0)
79 #define _SUBTYPE(t, s, f) do { \
80     setup_subtype_description(&subtypes[i++], (t), offsetof(s, f), _STR_VALUE(f)); \
81     _Static_assert(sizeof(_STR_VALUE(f)) <= sizeof ((struct kcdata_subtype_descriptor *)0)->kcs_name, "\"" _STR_VALUE(f) "\" should fit in kcs_name"); \
82 } while (0)
83 
84 #define _SUBTYPE_ARRAY(t, s, f, c) setup_subtype_array_description(&subtypes[i++], (t), offsetof(s, f), (c), _STR_VALUE(f))
85 #define _STRINGTYPE(f) setup_subtype_array_description(&subtypes[i++], KC_ST_CHAR, 0, UINT16_MAX, f)
86 
87 	if (buffer_size < sizeof(struct kcdata_type_definition) || buffer == NULL) {
88 		return NULL;
89 	}
90 
91 	struct kcdata_type_definition * retval = (struct kcdata_type_definition *)&buffer[0];
92 	kcdata_subtype_descriptor_t subtypes = (kcdata_subtype_descriptor_t)&buffer[sizeof(struct kcdata_type_definition)];
93 	switch (type_id) {
94 	case KCDATA_TYPE_STRING_DESC: {
95 		i = 0;
96 		setup_subtype_array_description(&subtypes[i++], KC_ST_CHAR, 0, KCDATA_DESC_MAXLEN, "desc");
97 		setup_subtype_array_description(&subtypes[i++], KC_ST_CHAR, KCDATA_DESC_MAXLEN, UINT16_MAX, "data");
98 		setup_type_definition(retval, type_id, i, "string_desc");
99 		break;
100 	}
101 
102 	case KCDATA_TYPE_UINT32_DESC: {
103 		i = 0;
104 		setup_subtype_array_description(&subtypes[i++], KC_ST_CHAR, 0, KCDATA_DESC_MAXLEN, "desc");
105 		setup_subtype_description(&subtypes[i++], KC_ST_UINT32, KCDATA_DESC_MAXLEN, "data");
106 		setup_type_definition(retval, type_id, i, "uint32_desc");
107 		break;
108 	}
109 
110 	case KCDATA_TYPE_UINT64_DESC: {
111 		i = 0;
112 		setup_subtype_array_description(&subtypes[i++], KC_ST_CHAR, 0, KCDATA_DESC_MAXLEN, "desc");
113 		setup_subtype_description(&subtypes[i++], KC_ST_UINT64, KCDATA_DESC_MAXLEN, "data");
114 		setup_type_definition(retval, type_id, i, "uint64_desc");
115 		break;
116 	}
117 
118 	case KCDATA_TYPE_INT32_DESC: {
119 		i = 0;
120 		setup_subtype_array_description(&subtypes[i++], KC_ST_CHAR, 0, KCDATA_DESC_MAXLEN, "desc");
121 		setup_subtype_description(&subtypes[i++], KC_ST_INT32, KCDATA_DESC_MAXLEN, "data");
122 		setup_type_definition(retval, type_id, i, "int32_desc");
123 		break;
124 	}
125 
126 	case KCDATA_TYPE_INT64_DESC: {
127 		i = 0;
128 		setup_subtype_array_description(&subtypes[i++], KC_ST_CHAR, 0, KCDATA_DESC_MAXLEN, "desc");
129 		setup_subtype_description(&subtypes[i++], KC_ST_INT64, KCDATA_DESC_MAXLEN, "data");
130 		setup_type_definition(retval, type_id, i, "int64_desc");
131 		break;
132 	}
133 
134 	case KCDATA_TYPE_TYPEDEFINTION: {
135 		i = 0;
136 		setup_subtype_description(&subtypes[i++], KC_ST_UINT32, offsetof(struct kcdata_type_definition, kct_type_identifier), "typeID");
137 		setup_subtype_description(&subtypes[i++], KC_ST_UINT32, offsetof(struct kcdata_type_definition, kct_num_elements), "numOfFields");
138 		setup_subtype_array_description(&subtypes[i++], KC_ST_CHAR, offsetof(struct kcdata_type_definition, kct_name), KCDATA_DESC_MAXLEN, "name");
139 		// Note "fields" is an array of run time defined length. So we populate fields at parsing time.
140 		setup_type_definition(retval, type_id, i, "typedef");
141 		break;
142 	}
143 
144 	case KCDATA_TYPE_CONTAINER_BEGIN: {
145 		i = 0;
146 		setup_subtype_description(&subtypes[i++], KC_ST_UINT32, 0, "kcContainerType");
147 		setup_type_definition(retval, type_id, i, "container_begin");
148 		break;
149 	}
150 
151 	case KCDATA_TYPE_LIBRARY_LOADINFO: {
152 		i = 0;
153 		_SUBTYPE(KC_ST_UINT32, struct user32_dyld_uuid_info, imageLoadAddress);
154 		_SUBTYPE_ARRAY(KC_ST_UINT8, struct user32_dyld_uuid_info, imageUUID, 16);
155 		setup_type_definition(retval, type_id, i, "dyld_load_info");
156 		break;
157 	}
158 
159 	case KCDATA_TYPE_LIBRARY_LOADINFO64: {
160 		i = 0;
161 		_SUBTYPE(KC_ST_UINT64, struct user64_dyld_uuid_info, imageLoadAddress);
162 		_SUBTYPE_ARRAY(KC_ST_UINT8, struct user64_dyld_uuid_info, imageUUID, 16);
163 		setup_type_definition(retval, type_id, i, "dyld_load_info");
164 		break;
165 	}
166 	case STACKSHOT_KCTYPE_LOADINFO64_TEXT_EXEC: {
167 		i = 0;
168 		_SUBTYPE(KC_ST_UINT64, struct user64_dyld_uuid_info, imageLoadAddress);
169 		_SUBTYPE_ARRAY(KC_ST_UINT8, struct user64_dyld_uuid_info, imageUUID, 16);
170 		setup_type_definition(retval, type_id, i, "dyld_load_info_text_exec");
171 		break;
172 	}
173 	case STACKSHOT_KCTYPE_SHAREDCACHE_LOADINFO: {
174 		i = 0;
175 		/*
176 		 * for backwards compatibility, we keep the old field names, but the
177 		 * new data is being put in dyld_shared_cache_loadinfo
178 		 */
179 		_SUBTYPE(KC_ST_UINT64, struct dyld_uuid_info_64_v2, imageLoadAddress);
180 		_SUBTYPE_ARRAY(KC_ST_UINT8, struct dyld_uuid_info_64_v2, imageUUID, 16);
181 		_SUBTYPE(KC_ST_UINT64, struct dyld_uuid_info_64_v2, imageSlidBaseAddress);
182 		_SUBTYPE(KC_ST_UINT64, struct dyld_shared_cache_loadinfo, sharedCacheSlidFirstMapping);
183 		_SUBTYPE(KC_ST_UINT32, struct dyld_shared_cache_loadinfo_v2, sharedCacheID);
184 		_SUBTYPE(KC_ST_UINT32, struct dyld_shared_cache_loadinfo_v2, sharedCacheFlags);
185 		setup_type_definition(retval, type_id, i, "shared_cache_dyld_load_info");
186 		break;
187 	}
188 	case STACKSHOT_KCTYPE_SHAREDCACHE_INFO: {
189 		i = 0;
190 		_SUBTYPE(KC_ST_UINT64, struct dyld_shared_cache_loadinfo_v2, sharedCacheSlide);
191 		_SUBTYPE_ARRAY(KC_ST_UINT8, struct dyld_shared_cache_loadinfo_v2, sharedCacheUUID, 16);
192 		_SUBTYPE_TRUNC(KC_ST_UINT64, struct dyld_shared_cache_loadinfo_v2, sharedCacheUnreliableSlidBaseAddress, "sharedCacheUnreliableSlidBaseAd");
193 		_SUBTYPE(KC_ST_UINT64, struct dyld_shared_cache_loadinfo_v2, sharedCacheSlidFirstMapping);
194 		_SUBTYPE(KC_ST_UINT32, struct dyld_shared_cache_loadinfo_v2, sharedCacheID);
195 		_SUBTYPE(KC_ST_UINT32, struct dyld_shared_cache_loadinfo_v2, sharedCacheFlags);
196 		setup_type_definition(retval, type_id, i, "shared_cache_dyld_load_info");
197 		break;
198 	}
199 
200 	case STACKSHOT_KCTYPE_KERNELCACHE_LOADINFO: {
201 		i = 0;
202 		_SUBTYPE(KC_ST_UINT64, struct dyld_uuid_info_64, imageLoadAddress);
203 		_SUBTYPE_ARRAY(KC_ST_UINT8, struct dyld_uuid_info_64, imageUUID, 16);
204 		setup_type_definition(retval, type_id, i, "kernelcache_load_info");
205 		break;
206 	}
207 
208 	case KCDATA_TYPE_TIMEBASE: {
209 		i = 0;
210 		_SUBTYPE(KC_ST_UINT32, struct mach_timebase_info, numer);
211 		_SUBTYPE(KC_ST_UINT32, struct mach_timebase_info, denom);
212 		setup_type_definition(retval, type_id, i, "mach_timebase_info");
213 		break;
214 	}
215 
216 	case KCDATA_TYPE_MACH_ABSOLUTE_TIME:
217 		setup_type_definition(retval, type_id, 1, "mach_absolute_time");
218 		setup_subtype_description(&subtypes[0], KC_ST_UINT64, 0, "mach_absolute_time");
219 		break;
220 
221 	case KCDATA_TYPE_TIMEVAL: {
222 		i = 0;
223 		_SUBTYPE(KC_ST_INT64, struct timeval64, tv_sec);
224 		_SUBTYPE(KC_ST_INT64, struct timeval64, tv_usec);
225 		setup_type_definition(retval, type_id, i, "timeval");
226 		break;
227 	}
228 
229 	case KCDATA_TYPE_USECS_SINCE_EPOCH:
230 		setup_type_definition(retval, type_id, 1, "usecs_since_epoch");
231 		setup_subtype_description(&subtypes[0], KC_ST_UINT64, 0, "usecs_since_epoch");
232 		break;
233 
234 	case KCDATA_TYPE_PID:
235 		setup_subtype_description(&subtypes[0], KC_ST_INT32, 0, "pid");
236 		setup_type_definition(retval, type_id, 1, "pid");
237 		break;
238 
239 	case KCDATA_TYPE_PROCNAME:
240 		i = 0;
241 		setup_subtype_array_description(&subtypes[i++], KC_ST_CHAR, 0, 64, "proc_name");
242 		setup_type_definition(retval, type_id, i, "proc_name");
243 		break;
244 
245 	case KCDATA_TYPE_LIBRARY_AOTINFO: {
246 		i = 0;
247 		_SUBTYPE(KC_ST_UINT64, struct user64_dyld_aot_info, x86LoadAddress);
248 		_SUBTYPE(KC_ST_UINT64, struct user64_dyld_aot_info, aotLoadAddress);
249 		_SUBTYPE(KC_ST_UINT64, struct user64_dyld_aot_info, aotImageSize);
250 		_SUBTYPE_ARRAY(KC_ST_UINT8, struct user64_dyld_aot_info, aotImageKey, DYLD_AOT_IMAGE_KEY_SIZE);
251 		setup_type_definition(retval, type_id, i, "dyld_aot_info");
252 		break;
253 	}
254 	case STACKSHOT_KCTYPE_AOTCACHE_LOADINFO: {
255 		i = 0;
256 		_SUBTYPE(KC_ST_UINT64, struct dyld_aot_cache_uuid_info, x86SlidBaseAddress);
257 		_SUBTYPE_ARRAY(KC_ST_UINT8, struct dyld_aot_cache_uuid_info, x86UUID, 16);
258 		_SUBTYPE(KC_ST_UINT64, struct dyld_aot_cache_uuid_info, aotSlidBaseAddress);
259 		_SUBTYPE_ARRAY(KC_ST_UINT8, struct dyld_aot_cache_uuid_info, aotUUID, 16);
260 		setup_type_definition(retval, type_id, i, "dyld_aot_cache_uuid_info");
261 		break;
262 	}
263 	case STACKSHOT_KCTYPE_SHAREDCACHE_AOTINFO: {
264 		i = 0;
265 		_SUBTYPE(KC_ST_UINT64, struct dyld_aot_cache_uuid_info, x86SlidBaseAddress);
266 		_SUBTYPE_ARRAY(KC_ST_UINT8, struct dyld_aot_cache_uuid_info, x86UUID, 16);
267 		_SUBTYPE(KC_ST_UINT64, struct dyld_aot_cache_uuid_info, aotSlidBaseAddress);
268 		_SUBTYPE_ARRAY(KC_ST_UINT8, struct dyld_aot_cache_uuid_info, aotUUID, 16);
269 		setup_type_definition(retval, type_id, i, "dyld_aot_cache_uuid_info");
270 		break;
271 	}
272 
273 	/* stackshot specific types */
274 	case STACKSHOT_KCTYPE_IOSTATS: {
275 		i = 0;
276 		_SUBTYPE(KC_ST_UINT64, struct io_stats_snapshot, ss_disk_reads_count);
277 		_SUBTYPE(KC_ST_UINT64, struct io_stats_snapshot, ss_disk_reads_size);
278 		_SUBTYPE(KC_ST_UINT64, struct io_stats_snapshot, ss_disk_writes_count);
279 		_SUBTYPE(KC_ST_UINT64, struct io_stats_snapshot, ss_disk_writes_size);
280 		_SUBTYPE_ARRAY(KC_ST_UINT64, struct io_stats_snapshot, ss_io_priority_count, STACKSHOT_IO_NUM_PRIORITIES);
281 		_SUBTYPE_ARRAY(KC_ST_UINT64, struct io_stats_snapshot, ss_io_priority_size, STACKSHOT_IO_NUM_PRIORITIES);
282 		_SUBTYPE(KC_ST_UINT64, struct io_stats_snapshot, ss_paging_count);
283 		_SUBTYPE(KC_ST_UINT64, struct io_stats_snapshot, ss_paging_size);
284 		_SUBTYPE(KC_ST_UINT64, struct io_stats_snapshot, ss_non_paging_count);
285 		_SUBTYPE(KC_ST_UINT64, struct io_stats_snapshot, ss_non_paging_size);
286 		_SUBTYPE(KC_ST_UINT64, struct io_stats_snapshot, ss_data_count);
287 		_SUBTYPE(KC_ST_UINT64, struct io_stats_snapshot, ss_data_size);
288 		_SUBTYPE(KC_ST_UINT64, struct io_stats_snapshot, ss_metadata_count);
289 		_SUBTYPE(KC_ST_UINT64, struct io_stats_snapshot, ss_metadata_size);
290 
291 		setup_type_definition(retval, type_id, i, "io_statistics");
292 		break;
293 	}
294 
295 	case STACKSHOT_KCTYPE_GLOBAL_MEM_STATS: {
296 		i = 0;
297 		_SUBTYPE(KC_ST_UINT32, struct mem_and_io_snapshot, snapshot_magic);
298 		_SUBTYPE(KC_ST_UINT32, struct mem_and_io_snapshot, free_pages);
299 		_SUBTYPE(KC_ST_UINT32, struct mem_and_io_snapshot, active_pages);
300 		_SUBTYPE(KC_ST_UINT32, struct mem_and_io_snapshot, inactive_pages);
301 		_SUBTYPE(KC_ST_UINT32, struct mem_and_io_snapshot, purgeable_pages);
302 		_SUBTYPE(KC_ST_UINT32, struct mem_and_io_snapshot, wired_pages);
303 		_SUBTYPE(KC_ST_UINT32, struct mem_and_io_snapshot, speculative_pages);
304 		_SUBTYPE(KC_ST_UINT32, struct mem_and_io_snapshot, throttled_pages);
305 		_SUBTYPE(KC_ST_UINT32, struct mem_and_io_snapshot, filebacked_pages);
306 		_SUBTYPE(KC_ST_UINT32, struct mem_and_io_snapshot, compressions);
307 		_SUBTYPE(KC_ST_UINT32, struct mem_and_io_snapshot, decompressions);
308 		_SUBTYPE(KC_ST_UINT32, struct mem_and_io_snapshot, compressor_size);
309 		_SUBTYPE(KC_ST_UINT32, struct mem_and_io_snapshot, busy_buffer_count);
310 		_SUBTYPE(KC_ST_UINT32, struct mem_and_io_snapshot, pages_wanted);
311 		_SUBTYPE(KC_ST_UINT32, struct mem_and_io_snapshot, pages_reclaimed);
312 		_SUBTYPE(KC_ST_UINT8, struct mem_and_io_snapshot, pages_wanted_reclaimed_valid);
313 		setup_type_definition(retval, type_id, i, "mem_and_io_snapshot");
314 		break;
315 	}
316 
317 	case STACKSHOT_KCCONTAINER_SHAREDCACHE:
318 		setup_type_definition(retval, type_id, 0, "shared_caches");
319 		break;
320 
321 	case STACKSHOT_KCCONTAINER_TASK:
322 		setup_type_definition(retval, type_id, 0, "task_snapshots");
323 		break;
324 
325 	case STACKSHOT_KCCONTAINER_TRANSITIONING_TASK:
326 		setup_type_definition(retval, type_id, 0, "transitioning_task_snapshots");
327 		break;
328 
329 	case STACKSHOT_KCCONTAINER_THREAD:
330 		setup_type_definition(retval, type_id, 0, "thread_snapshots");
331 		break;
332 
333 	case STACKSHOT_KCCONTAINER_PORTLABEL:
334 		setup_type_definition(retval, type_id, 0, "portlabels");
335 		break;
336 
337 	case STACKSHOT_KCTYPE_TASK_SNAPSHOT: {
338 		i = 0;
339 		_SUBTYPE(KC_ST_UINT64, struct task_snapshot_v2, ts_unique_pid);
340 		_SUBTYPE(KC_ST_UINT64, struct task_snapshot_v2, ts_ss_flags);
341 		_SUBTYPE_TRUNC(KC_ST_UINT64, struct task_snapshot_v2, ts_user_time_in_terminated_threads, "ts_user_time_in_terminated_thre");
342 		_SUBTYPE_TRUNC(KC_ST_UINT64, struct task_snapshot_v2, ts_system_time_in_terminated_threads, "ts_system_time_in_terminated_th");
343 		_SUBTYPE(KC_ST_UINT64, struct task_snapshot_v2, ts_p_start_sec);
344 		_SUBTYPE(KC_ST_UINT64, struct task_snapshot_v2, ts_task_size);
345 		_SUBTYPE(KC_ST_UINT64, struct task_snapshot_v2, ts_max_resident_size);
346 		_SUBTYPE(KC_ST_UINT32, struct task_snapshot_v2, ts_suspend_count);
347 		_SUBTYPE(KC_ST_UINT32, struct task_snapshot_v2, ts_faults);
348 		_SUBTYPE(KC_ST_UINT32, struct task_snapshot_v2, ts_pageins);
349 		_SUBTYPE(KC_ST_UINT32, struct task_snapshot_v2, ts_cow_faults);
350 		_SUBTYPE(KC_ST_UINT32, struct task_snapshot_v2, ts_was_throttled);
351 		_SUBTYPE(KC_ST_UINT32, struct task_snapshot_v2, ts_did_throttle);
352 		_SUBTYPE(KC_ST_UINT32, struct task_snapshot_v2, ts_latency_qos);
353 		_SUBTYPE(KC_ST_INT32, struct task_snapshot_v2, ts_pid);
354 		_SUBTYPE_ARRAY(KC_ST_CHAR, struct task_snapshot_v2, ts_p_comm, 32);
355 		setup_type_definition(retval, type_id, i, "task_snapshot");
356 		break;
357 	}
358 
359 	case STACKSHOT_KCTYPE_TRANSITIONING_TASK_SNAPSHOT: {
360 		i = 0;
361 		_SUBTYPE(KC_ST_UINT64, struct transitioning_task_snapshot, tts_unique_pid);
362 		_SUBTYPE(KC_ST_UINT64, struct transitioning_task_snapshot, tts_ss_flags);
363 		_SUBTYPE(KC_ST_UINT64, struct transitioning_task_snapshot, tts_transition_type);
364 		_SUBTYPE(KC_ST_INT32, struct transitioning_task_snapshot, tts_pid);
365 		_SUBTYPE_ARRAY(KC_ST_CHAR, struct transitioning_task_snapshot, tts_p_comm, 32);
366 		setup_type_definition(retval, type_id, i, "transitioning_task_snapshot");
367 		break;
368 	}
369 
370 	case STACKSHOT_KCTYPE_TASK_DELTA_SNAPSHOT: {
371 		i = 0;
372 		_SUBTYPE(KC_ST_UINT64, struct task_delta_snapshot_v2, tds_unique_pid);
373 		_SUBTYPE(KC_ST_UINT64, struct task_delta_snapshot_v2, tds_ss_flags);
374 		_SUBTYPE_TRUNC(KC_ST_UINT64, struct task_delta_snapshot_v2, tds_user_time_in_terminated_threads, "tds_user_time_in_terminated_thr");
375 		_SUBTYPE_TRUNC(KC_ST_UINT64, struct task_delta_snapshot_v2, tds_system_time_in_terminated_threads, "tds_system_time_in_terminated_t");
376 		_SUBTYPE(KC_ST_UINT64, struct task_delta_snapshot_v2, tds_task_size);
377 		_SUBTYPE(KC_ST_UINT64, struct task_delta_snapshot_v2, tds_max_resident_size);
378 		_SUBTYPE(KC_ST_UINT32, struct task_delta_snapshot_v2, tds_suspend_count);
379 		_SUBTYPE(KC_ST_UINT32, struct task_delta_snapshot_v2, tds_faults);
380 		_SUBTYPE(KC_ST_UINT32, struct task_delta_snapshot_v2, tds_pageins);
381 		_SUBTYPE(KC_ST_UINT32, struct task_delta_snapshot_v2, tds_cow_faults);
382 		_SUBTYPE(KC_ST_UINT32, struct task_delta_snapshot_v2, tds_was_throttled);
383 		_SUBTYPE(KC_ST_UINT32, struct task_delta_snapshot_v2, tds_did_throttle);
384 		_SUBTYPE(KC_ST_UINT32, struct task_delta_snapshot_v2, tds_latency_qos);
385 		setup_type_definition(retval, type_id, i, "task_delta_snapshot");
386 		break;
387 	}
388 
389 	case STACKSHOT_KCTYPE_THREAD_SNAPSHOT: {
390 		i = 0;
391 
392 		_SUBTYPE(KC_ST_UINT64, struct thread_snapshot_v3, ths_thread_id);
393 		_SUBTYPE(KC_ST_UINT64, struct thread_snapshot_v3, ths_wait_event);
394 		_SUBTYPE(KC_ST_UINT64, struct thread_snapshot_v3, ths_continuation);
395 		_SUBTYPE(KC_ST_UINT64, struct thread_snapshot_v3, ths_total_syscalls);
396 		_SUBTYPE(KC_ST_UINT64, struct thread_snapshot_v3, ths_voucher_identifier);
397 		_SUBTYPE(KC_ST_UINT64, struct thread_snapshot_v3, ths_dqserialnum);
398 		_SUBTYPE(KC_ST_UINT64, struct thread_snapshot_v3, ths_user_time);
399 		_SUBTYPE(KC_ST_UINT64, struct thread_snapshot_v3, ths_sys_time);
400 		_SUBTYPE(KC_ST_UINT64, struct thread_snapshot_v3, ths_ss_flags);
401 		_SUBTYPE(KC_ST_UINT64, struct thread_snapshot_v3, ths_last_run_time);
402 		_SUBTYPE(KC_ST_UINT64, struct thread_snapshot_v3, ths_last_made_runnable_time);
403 		_SUBTYPE(KC_ST_UINT32, struct thread_snapshot_v3, ths_state);
404 		_SUBTYPE(KC_ST_UINT32, struct thread_snapshot_v3, ths_sched_flags);
405 		_SUBTYPE(KC_ST_INT16, struct thread_snapshot_v3, ths_base_priority);
406 		_SUBTYPE(KC_ST_INT16, struct thread_snapshot_v3, ths_sched_priority);
407 		_SUBTYPE(KC_ST_UINT8, struct thread_snapshot_v3, ths_eqos);
408 		_SUBTYPE(KC_ST_UINT8, struct thread_snapshot_v3, ths_rqos);
409 		_SUBTYPE(KC_ST_UINT8, struct thread_snapshot_v3, ths_rqos_override);
410 		_SUBTYPE(KC_ST_UINT8, struct thread_snapshot_v3, ths_io_tier);
411 		_SUBTYPE(KC_ST_UINT64, struct thread_snapshot_v3, ths_thread_t);
412 		_SUBTYPE(KC_ST_UINT64, struct thread_snapshot_v4, ths_requested_policy);
413 		_SUBTYPE(KC_ST_UINT64, struct thread_snapshot_v4, ths_effective_policy);
414 
415 		setup_type_definition(retval, type_id, i, "thread_snapshot");
416 		break;
417 	}
418 
419 	case STACKSHOT_KCTYPE_THREAD_DELTA_SNAPSHOT: {
420 		i = 0;
421 
422 		_SUBTYPE(KC_ST_UINT64, struct thread_delta_snapshot_v2, tds_thread_id);
423 		_SUBTYPE(KC_ST_UINT64, struct thread_delta_snapshot_v2, tds_voucher_identifier);
424 		_SUBTYPE(KC_ST_UINT64, struct thread_delta_snapshot_v2, tds_ss_flags);
425 		_SUBTYPE(KC_ST_UINT64, struct thread_delta_snapshot_v2, tds_last_made_runnable_time);
426 		_SUBTYPE(KC_ST_UINT32, struct thread_delta_snapshot_v2, tds_state);
427 		_SUBTYPE(KC_ST_UINT32, struct thread_delta_snapshot_v2, tds_sched_flags);
428 		_SUBTYPE(KC_ST_INT16, struct thread_delta_snapshot_v2, tds_base_priority);
429 		_SUBTYPE(KC_ST_INT16, struct thread_delta_snapshot_v2, tds_sched_priority);
430 		_SUBTYPE(KC_ST_UINT8, struct thread_delta_snapshot_v2, tds_eqos);
431 		_SUBTYPE(KC_ST_UINT8, struct thread_delta_snapshot_v2, tds_rqos);
432 		_SUBTYPE(KC_ST_UINT8, struct thread_delta_snapshot_v2, tds_rqos_override);
433 		_SUBTYPE(KC_ST_UINT8, struct thread_delta_snapshot_v2, tds_io_tier);
434 		_SUBTYPE(KC_ST_UINT64, struct thread_delta_snapshot_v3, tds_requested_policy);
435 		_SUBTYPE(KC_ST_UINT64, struct thread_delta_snapshot_v3, tds_effective_policy);
436 
437 		setup_type_definition(retval, type_id, i, "thread_delta_snapshot");
438 
439 		break;
440 	}
441 
442 	case STACKSHOT_KCTYPE_DONATING_PIDS:
443 		setup_type_definition(retval, type_id, 1, "donating_pids");
444 		setup_subtype_description(&subtypes[0], KC_ST_INT32, 0, "donating_pids");
445 		break;
446 
447 	case STACKSHOT_KCTYPE_THREAD_NAME: {
448 		i = 0;
449 		setup_subtype_array_description(&subtypes[i++], KC_ST_CHAR, 0, 64, "pth_name");
450 		setup_type_definition(retval, type_id, i, "pth_name");
451 		break;
452 	}
453 
454 	case STACKSHOT_KCTYPE_KERN_STACKFRAME:
455 		setup_type_definition(retval, type_id, 2, "kernel_stack_frames");
456 		setup_subtype_description(&subtypes[0], KC_ST_UINT32, 0, "lr");
457 		setup_subtype_description(&subtypes[1], KC_ST_UINT32, sizeof(uint32_t), "sp");
458 		break;
459 
460 	case STACKSHOT_KCTYPE_KERN_STACKFRAME64:
461 		setup_type_definition(retval, type_id, 2, "kernel_stack_frames");
462 		setup_subtype_description(&subtypes[0], KC_ST_UINT64, 0, "lr");
463 		setup_subtype_description(&subtypes[1], KC_ST_UINT64, sizeof(uint64_t), "sp");
464 		break;
465 
466 	case STACKSHOT_KCTYPE_USER_STACKFRAME:
467 		setup_type_definition(retval, type_id, 2, "user_stack_frames");
468 		setup_subtype_description(&subtypes[0], KC_ST_UINT32, 0, "lr");
469 		setup_subtype_description(&subtypes[1], KC_ST_UINT32, sizeof(uint32_t), "sp");
470 		break;
471 
472 	case STACKSHOT_KCTYPE_USER_STACKFRAME64:
473 		setup_type_definition(retval, type_id, 2, "user_stack_frames");
474 		setup_subtype_description(&subtypes[0], KC_ST_UINT64, 0, "lr");
475 		setup_subtype_description(&subtypes[1], KC_ST_UINT64, sizeof(uint64_t), "sp");
476 		break;
477 
478 	case STACKSHOT_KCTYPE_KERN_STACKLR:
479 		setup_type_definition(retval, type_id, 1, "kernel_stack_frames");
480 		setup_subtype_description(&subtypes[0], KC_ST_UINT32, 0, "lr");
481 		subtypes[0].kcs_flags |= KCS_SUBTYPE_FLAGS_STRUCT;
482 		break;
483 
484 	case STACKSHOT_KCTYPE_KERN_STACKLR64:
485 		setup_type_definition(retval, type_id, 1, "kernel_stack_frames");
486 		setup_subtype_description(&subtypes[0], KC_ST_UINT64, 0, "lr");
487 		subtypes[0].kcs_flags |= KCS_SUBTYPE_FLAGS_STRUCT;
488 		break;
489 
490 	case STACKSHOT_KCTYPE_USER_STACKLR:
491 		setup_type_definition(retval, type_id, 1, "user_stack_frames");
492 		setup_subtype_description(&subtypes[0], KC_ST_UINT32, 0, "lr");
493 		subtypes[0].kcs_flags |= KCS_SUBTYPE_FLAGS_STRUCT;
494 		break;
495 
496 	case STACKSHOT_KCTYPE_USER_STACKLR64:
497 		setup_type_definition(retval, type_id, 1, "user_stack_frames");
498 		setup_subtype_description(&subtypes[0], KC_ST_UINT64, 0, "lr");
499 		subtypes[0].kcs_flags |= KCS_SUBTYPE_FLAGS_STRUCT;
500 		break;
501 
502 	case STACKSHOT_KCTYPE_USER_ASYNC_START_INDEX:
503 		setup_type_definition(retval, type_id, 1, "user_async_start_index");
504 		setup_subtype_description(&subtypes[0], KC_ST_UINT32, 0, "user_async_start_index");
505 		break;
506 
507 	case STACKSHOT_KCTYPE_USER_ASYNC_STACKLR64:
508 		setup_type_definition(retval, type_id, 1, "user_async_stack_frames");
509 		setup_subtype_description(&subtypes[0], KC_ST_UINT64, 0, "lr");
510 		subtypes[0].kcs_flags |= KCS_SUBTYPE_FLAGS_STRUCT;
511 		break;
512 
513 	case STACKSHOT_KCTYPE_NONRUNNABLE_TIDS:
514 		setup_type_definition(retval, type_id, 1, "nonrunnable_threads");
515 		setup_subtype_description(&subtypes[0], KC_ST_INT64, 0, "nonrunnable_threads");
516 		break;
517 
518 	case STACKSHOT_KCTYPE_NONRUNNABLE_TASKS:
519 		setup_type_definition(retval, type_id, 1, "nonrunnable_tasks");
520 		setup_subtype_description(&subtypes[0], KC_ST_INT64, 0, "nonrunnable_tasks");
521 		break;
522 
523 	case STACKSHOT_KCTYPE_SHAREDCACHE_ID:
524 		setup_type_definition(retval, type_id, 1, "sharedCacheID");
525 		setup_subtype_description(&subtypes[0], KC_ST_INT32, 0, "sharedCacheID");
526 		break;
527 
528 	case STACKSHOT_KCTYPE_CODESIGNING_INFO:
529 		i = 0;
530 		_SUBTYPE(KC_ST_UINT64, struct stackshot_task_codesigning_info, csflags);
531 		_SUBTYPE(KC_ST_UINT32, struct stackshot_task_codesigning_info, cs_trust_level);
532 		setup_type_definition(retval, type_id, i, "stackshot_task_codesigning_info");
533 		break;
534 
535 	case STACKSHOT_KCTYPE_KERN_EXCLAVES_THREADINFO:
536 		i = 0;
537 		_SUBTYPE(KC_ST_UINT64, struct thread_exclaves_info, tei_scid);
538 		_SUBTYPE(KC_ST_UINT32, struct thread_exclaves_info, tei_thread_offset);
539 		_SUBTYPE(KC_ST_UINT32, struct thread_exclaves_info, tei_flags);
540 		setup_type_definition(retval, type_id, i, "exclaves_thread_info");
541 		break;
542 
543 	case STACKSHOT_KCTYPE_KERN_EXCLAVES_CRASH_THREADINFO:
544 		i = 0;
545 		_SUBTYPE(KC_ST_UINT64, struct thread_crash_exclaves_info, tcei_scid);
546 		_SUBTYPE(KC_ST_UINT64, struct thread_crash_exclaves_info, tcei_thread_id);
547 		_SUBTYPE(KC_ST_UINT32, struct thread_crash_exclaves_info, tcei_flags);
548 		setup_type_definition(retval, type_id, i, "exclaves_crash_thread_info");
549 		break;
550 
551 	case STACKSHOT_KCCONTAINER_EXCLAVES:
552 		setup_type_definition(retval, type_id, 0, "threads_exclave");
553 		break;
554 
555 	case STACKSHOT_KCCONTAINER_EXCLAVE_SCRESULT:
556 		setup_type_definition(retval, type_id, 0, "thread_exclave");
557 		break;
558 
559 	case STACKSHOT_KCTYPE_EXCLAVE_SCRESULT_INFO:
560 		i = 0;
561 		_SUBTYPE(KC_ST_UINT64, struct exclave_scresult_info, esc_id);
562 		_SUBTYPE(KC_ST_UINT64, struct exclave_scresult_info, esc_flags);
563 		setup_type_definition(retval, type_id, i, "exclave_scresult_info");
564 		break;
565 
566 	case STACKSHOT_KCCONTAINER_EXCLAVE_IPCSTACKENTRY:
567 		setup_type_definition(retval, type_id, 0, "exclave_ipcstackentry");
568 		break;
569 
570 	case STACKSHOT_KCTYPE_EXCLAVE_IPCSTACKENTRY_INFO:
571 		i = 0;
572 		_SUBTYPE(KC_ST_UINT64, struct exclave_ipcstackentry_info, eise_asid);
573 		_SUBTYPE(KC_ST_UINT64, struct exclave_ipcstackentry_info, eise_tnid);
574 		_SUBTYPE(KC_ST_UINT64, struct exclave_ipcstackentry_info, eise_invocationid);
575 		_SUBTYPE(KC_ST_UINT64, struct exclave_ipcstackentry_info, eise_flags);
576 		setup_type_definition(retval, type_id, i, "exclave_ipcstackentry_info");
577 		break;
578 
579 	case STACKSHOT_KCTYPE_EXCLAVE_IPCSTACKENTRY_ECSTACK:
580 		setup_type_definition(retval, type_id, 1, "secure_ecstack_entry");
581 		setup_subtype_description(&subtypes[0], KC_ST_UINT64, 0, "lr");
582 		subtypes[0].kcs_flags |= KCS_SUBTYPE_FLAGS_STRUCT;
583 		break;
584 
585 	case STACKSHOT_KCCONTAINER_EXCLAVE_ADDRESSSPACE:
586 		setup_type_definition(retval, type_id, 0, "exclave_addressspace");
587 		break;
588 
589 	case STACKSHOT_KCTYPE_EXCLAVE_ADDRESSSPACE_INFO:
590 		i = 0;
591 		_SUBTYPE(KC_ST_UINT64, struct exclave_addressspace_info, eas_id);
592 		_SUBTYPE(KC_ST_UINT64, struct exclave_addressspace_info, eas_flags);
593 		_SUBTYPE(KC_ST_UINT64, struct exclave_addressspace_info, eas_layoutid);
594 		_SUBTYPE(KC_ST_UINT64, struct exclave_addressspace_info, eas_slide);
595 		_SUBTYPE(KC_ST_UINT64, struct exclave_addressspace_info, eas_asroot);
596 		setup_type_definition(retval, type_id, i, "exclave_addressspace_info");
597 		break;
598 
599 	case STACKSHOT_KCTYPE_EXCLAVE_ADDRESSSPACE_NAME:
600 		i = 0;
601 		_STRINGTYPE("exclave_addressspace_name");
602 		setup_type_definition(retval, type_id, i, "exclave_addressspace_name");
603 		break;
604 
605 	case STACKSHOT_KCCONTAINER_EXCLAVE_TEXTLAYOUT:
606 		setup_type_definition(retval, type_id, 0, "exclave_textlayout");
607 		break;
608 
609 	case STACKSHOT_KCTYPE_EXCLAVE_TEXTLAYOUT_INFO:
610 		i = 0;
611 		_SUBTYPE(KC_ST_UINT64, struct exclave_textlayout_info, layout_id);
612 		_SUBTYPE(KC_ST_UINT64, struct exclave_textlayout_info, etl_flags);
613 		_SUBTYPE(KC_ST_UINT32, struct exclave_textlayout_info, sharedcache_index);
614 		setup_type_definition(retval, type_id, i, "exclave_textlayout_info");
615 		break;
616 
617 	case STACKSHOT_KCTYPE_EXCLAVE_TEXTLAYOUT_SEGMENTS:
618 		i = 0;
619 		_SUBTYPE_ARRAY(KC_ST_UINT8, struct exclave_textlayout_segment_v2, layoutSegment_uuid, 16);
620 		_SUBTYPE(KC_ST_UINT64, struct exclave_textlayout_segment_v2, layoutSegment_loadAddress);
621 		_SUBTYPE(KC_ST_UINT64, struct exclave_textlayout_segment_v2, layoutSegment_rawLoadAddress);
622 		setup_type_definition(retval, type_id, i, "exclave_textlayout_segments");
623 		break;
624 
625 	case STACKSHOT_KCTYPE_BOOTARGS: {
626 		i = 0;
627 		_STRINGTYPE("boot_args");
628 		setup_type_definition(retval, type_id, i, "boot_args");
629 		break;
630 	}
631 
632 	case STACKSHOT_KCTYPE_OSVERSION: {
633 		i = 0;
634 		_STRINGTYPE("osversion");
635 		setup_type_definition(retval, type_id, i, "osversion");
636 		break;
637 	}
638 
639 	case STACKSHOT_KCTYPE_OS_BUILD_VERSION: {
640 		i = 0;
641 		_STRINGTYPE("os_build_version");
642 		setup_type_definition(retval, type_id, i, "os_build_version");
643 		break;
644 	}
645 
646 	case STACKSHOT_KCTYPE_KERN_PAGE_SIZE: {
647 		i = 0;
648 		setup_subtype_description(&subtypes[i++], KC_ST_UINT32, 0, "kernel_page_size");
649 		setup_type_definition(retval, type_id, i, "kernel_page_size");
650 		break;
651 	}
652 
653 	case STACKSHOT_KCTYPE_THREAD_POLICY_VERSION: {
654 		i = 0;
655 		setup_subtype_description(&subtypes[i++], KC_ST_UINT32, 0, "thread_policy_version");
656 		setup_type_definition(retval, type_id, i, "thread_policy_version");
657 		break;
658 	}
659 
660 	case STACKSHOT_KCTYPE_JETSAM_LEVEL: {
661 		i = 0;
662 		setup_subtype_description(&subtypes[i++], KC_ST_UINT32, 0, "jetsam_level");
663 		setup_type_definition(retval, type_id, i, "jetsam_level");
664 		break;
665 	}
666 
667 	case STACKSHOT_KCTYPE_DELTA_SINCE_TIMESTAMP: {
668 		i = 0;
669 		setup_subtype_description(&subtypes[i++], KC_ST_UINT64, 0, "stackshot_delta_since_timestamp");
670 		setup_type_definition(retval, type_id, i, "stackshot_delta_since_timestamp");
671 		break;
672 	}
673 
674 	/* crashinfo types */
675 	case TASK_CRASHINFO_BSDINFOWITHUNIQID: {
676 		i = 0;
677 		_SUBTYPE_ARRAY(KC_ST_UINT8, struct crashinfo_proc_uniqidentifierinfo, p_uuid, 16);
678 		_SUBTYPE(KC_ST_UINT64, struct crashinfo_proc_uniqidentifierinfo, p_uniqueid);
679 		_SUBTYPE(KC_ST_UINT64, struct crashinfo_proc_uniqidentifierinfo, p_puniqueid);
680 		/* Ignore the p_reserve fields */
681 		setup_type_definition(retval, type_id, i, "proc_uniqidentifierinfo");
682 		break;
683 	}
684 
685 	case TASK_CRASHINFO_PID: {
686 		setup_subtype_description(&subtypes[0], KC_ST_INT32, 0, "pid");
687 		setup_type_definition(retval, type_id, 1, "pid");
688 		break;
689 	}
690 
691 	case TASK_CRASHINFO_PPID: {
692 		setup_subtype_description(&subtypes[0], KC_ST_INT32, 0, "ppid");
693 		setup_type_definition(retval, type_id, 1, "ppid");
694 		break;
695 	}
696 
697 	/* case TASK_CRASHINFO_RUSAGE: { */
698 	/*      /\* */
699 	/*       * rusage is a complex structure and is only for legacy use for crashed processes rusage info. */
700 	/*       * So we just consider it as opaque data. */
701 	/*       *\/ */
702 	/*      i = 0; */
703 	/*      setup_subtype_array_description(&subtypes[i++], KC_ST_UINT8, 0, sizeof(struct rusage), "rusage"); */
704 	/*      setup_type_definition(retval, type_id, i, "rusage"); */
705 	/*      break; */
706 	/* } */
707 
708 	case TASK_CRASHINFO_RUSAGE_INFO: {
709 		i = 0;
710 		_SUBTYPE_ARRAY(KC_ST_UINT8, struct rusage_info_v3, ri_uuid, 16);
711 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_user_time);
712 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_system_time);
713 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_pkg_idle_wkups);
714 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_interrupt_wkups);
715 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_pageins);
716 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_wired_size);
717 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_resident_size);
718 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_phys_footprint);
719 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_proc_start_abstime);
720 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_proc_exit_abstime);
721 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_child_user_time);
722 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_child_system_time);
723 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_child_pkg_idle_wkups);
724 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_child_interrupt_wkups);
725 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_child_pageins);
726 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_child_elapsed_abstime);
727 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_diskio_bytesread);
728 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_diskio_byteswritten);
729 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_cpu_time_qos_default);
730 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_cpu_time_qos_maintenance);
731 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_cpu_time_qos_background);
732 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_cpu_time_qos_utility);
733 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_cpu_time_qos_legacy);
734 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_cpu_time_qos_user_initiated);
735 		_SUBTYPE_TRUNC(KC_ST_UINT64, struct rusage_info_v3, ri_cpu_time_qos_user_interactive, "ri_cpu_time_qos_user_interactiv");
736 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_billed_system_time);
737 		_SUBTYPE(KC_ST_UINT64, struct rusage_info_v3, ri_serviced_system_time);
738 		setup_type_definition(retval, type_id, i, "rusage_info");
739 		break;
740 	}
741 
742 	case STACKSHOT_KCTYPE_CPU_TIMES: {
743 		i = 0;
744 		_SUBTYPE(KC_ST_UINT64, struct stackshot_cpu_times_v2, user_usec);
745 		_SUBTYPE(KC_ST_UINT64, struct stackshot_cpu_times_v2, system_usec);
746 		_SUBTYPE(KC_ST_UINT64, struct stackshot_cpu_times_v2, runnable_usec);
747 		setup_type_definition(retval, type_id, i, "cpu_times");
748 		break;
749 	}
750 
751 	case STACKSHOT_KCTYPE_STACKSHOT_DURATION: {
752 		i = 0;
753 		_SUBTYPE(KC_ST_UINT64, struct stackshot_duration_v2, stackshot_duration);
754 		_SUBTYPE(KC_ST_UINT64, struct stackshot_duration_v2, stackshot_duration_outer);
755 		_SUBTYPE(KC_ST_UINT64, struct stackshot_duration_v2, stackshot_duration_prior);
756 		subtypes[0].kcs_flags |= KCS_SUBTYPE_FLAGS_MERGE;
757 		subtypes[1].kcs_flags |= KCS_SUBTYPE_FLAGS_MERGE;
758 		subtypes[2].kcs_flags |= KCS_SUBTYPE_FLAGS_MERGE;
759 		setup_type_definition(retval, type_id, i, "stackshot_duration");
760 		break;
761 	}
762 
763 	case STACKSHOT_KCTYPE_STACKSHOT_FAULT_STATS: {
764 		i = 0;
765 		_SUBTYPE(KC_ST_UINT32, struct stackshot_fault_stats, sfs_pages_faulted_in);
766 		_SUBTYPE(KC_ST_UINT64, struct stackshot_fault_stats, sfs_time_spent_faulting);
767 		_SUBTYPE(KC_ST_UINT64, struct stackshot_fault_stats, sfs_system_max_fault_time);
768 		_SUBTYPE(KC_ST_UINT8, struct stackshot_fault_stats, sfs_stopped_faulting);
769 
770 		setup_type_definition(retval, type_id, i, "stackshot_fault_stats");
771 		break;
772 	}
773 
774 	case STACKSHOT_KCTYPE_THREAD_WAITINFO: {
775 		i = 0;
776 		_SUBTYPE(KC_ST_UINT64, struct stackshot_thread_waitinfo_v2, owner);
777 		_SUBTYPE(KC_ST_UINT64, struct stackshot_thread_waitinfo_v2, waiter);
778 		_SUBTYPE(KC_ST_UINT64, struct stackshot_thread_waitinfo_v2, context);
779 		_SUBTYPE(KC_ST_UINT8, struct stackshot_thread_waitinfo_v2, wait_type);
780 		_SUBTYPE(KC_ST_INT16, struct stackshot_thread_waitinfo_v2, portlabel_id);
781 		_SUBTYPE(KC_ST_UINT32, struct stackshot_thread_waitinfo_v2, wait_flags);
782 		setup_type_definition(retval, type_id, i, "thread_waitinfo");
783 		break;
784 	}
785 
786 	case STACKSHOT_KCTYPE_THREAD_GROUP_SNAPSHOT: {
787 		i = 0;
788 		_SUBTYPE(KC_ST_UINT64, struct thread_group_snapshot_v3, tgs_id);
789 		_SUBTYPE_ARRAY(KC_ST_CHAR, struct thread_group_snapshot_v3, tgs_name, 16);
790 		_SUBTYPE(KC_ST_UINT64, struct thread_group_snapshot_v3, tgs_flags);
791 		_SUBTYPE_ARRAY(KC_ST_CHAR, struct thread_group_snapshot_v3, tgs_name_cont, 16);
792 		setup_type_definition(retval, type_id, i, "thread_group_snapshot");
793 		break;
794 	}
795 
796 	case STACKSHOT_KCTYPE_THREAD_GROUP: {
797 		i = 0;
798 		setup_subtype_description(&subtypes[i++], KC_ST_UINT64, 0, "thread_group");
799 		setup_type_definition(retval, type_id, i, "thread_group");
800 		break;
801 	};
802 
803 	case STACKSHOT_KCTYPE_JETSAM_COALITION_SNAPSHOT: {
804 		i = 0;
805 		_SUBTYPE(KC_ST_UINT64, struct jetsam_coalition_snapshot, jcs_id);
806 		_SUBTYPE(KC_ST_UINT64, struct jetsam_coalition_snapshot, jcs_flags);
807 		_SUBTYPE(KC_ST_UINT64, struct jetsam_coalition_snapshot, jcs_thread_group);
808 		_SUBTYPE(KC_ST_UINT64, struct jetsam_coalition_snapshot, jcs_leader_task_uniqueid);
809 		setup_type_definition(retval, type_id, i, "jetsam_coalition_snapshot");
810 		break;
811 	}
812 
813 	case STACKSHOT_KCTYPE_JETSAM_COALITION: {
814 		i = 0;
815 		setup_subtype_description(&subtypes[i++], KC_ST_UINT64, 0, "jetsam_coalition");
816 		setup_type_definition(retval, type_id, i, "jetsam_coalition");
817 		break;
818 	};
819 
820 	case STACKSHOT_KCTYPE_INSTRS_CYCLES: {
821 		i = 0;
822 		_SUBTYPE(KC_ST_UINT64, struct instrs_cycles_snapshot_v2, ics_instructions);
823 		_SUBTYPE(KC_ST_UINT64, struct instrs_cycles_snapshot_v2, ics_cycles);
824 		_SUBTYPE(KC_ST_UINT64, struct instrs_cycles_snapshot_v2, ics_p_instructions);
825 		_SUBTYPE(KC_ST_UINT64, struct instrs_cycles_snapshot_v2, ics_p_cycles);
826 		setup_type_definition(retval, type_id, i, "instrs_cycles_snapshot");
827 		break;
828 	}
829 
830 	case STACKSHOT_KCTYPE_USER_STACKTOP: {
831 		i = 0;
832 		_SUBTYPE(KC_ST_UINT64, struct stack_snapshot_stacktop, sp);
833 		_SUBTYPE_ARRAY(KC_ST_UINT8, struct stack_snapshot_stacktop, stack_contents, 8);
834 		setup_type_definition(retval, type_id, i, "user_stacktop");
835 		break;
836 	}
837 
838 	case TASK_CRASHINFO_PROC_STARTTIME: {
839 		i = 0;
840 		_SUBTYPE(KC_ST_INT64, struct timeval64, tv_sec);
841 		_SUBTYPE(KC_ST_INT64, struct timeval64, tv_usec);
842 		setup_type_definition(retval, type_id, i, "proc_starttime");
843 		break;
844 	}
845 
846 	case TASK_CRASHINFO_EXCEPTION_CODES: {
847 		i = 0;
848 		char codenum[100];
849 		for (i = 0; i < EXCEPTION_CODE_MAX; i++) {
850 			snprintf(codenum, sizeof(codenum), "code_%d", i);
851 			setup_subtype_description(&subtypes[i], KC_ST_UINT64, i * (sizeof(uint64_t)), codenum);
852 		}
853 		setup_type_definition(retval, type_id, i, "mach_exception_data_t");
854 		break;
855 	}
856 
857 	case TASK_CRASHINFO_PROC_NAME: {
858 		i = 0;
859 		_STRINGTYPE("p_comm");
860 		setup_type_definition(retval, type_id, i, "p_comm");
861 		break;
862 	}
863 
864 	case TASK_CRASHINFO_USERSTACK: {
865 		i = 0;
866 		setup_subtype_description(&subtypes[0], KC_ST_UINT64, 0, "userstack_ptr");
867 		setup_type_definition(retval, type_id, 1, "userstack_ptr");
868 		break;
869 	}
870 
871 	case TASK_CRASHINFO_ARGSLEN: {
872 		i = 0;
873 		setup_subtype_description(&subtypes[0], KC_ST_INT32, 0, "p_argslen");
874 		setup_type_definition(retval, type_id, 1, "p_argslen");
875 		break;
876 	}
877 
878 	case TASK_CRASHINFO_PROC_PATH: {
879 		i = 0;
880 		_STRINGTYPE("p_path");
881 		setup_type_definition(retval, type_id, i, "p_path");
882 		break;
883 	}
884 
885 	case TASK_CRASHINFO_PROC_CSFLAGS: {
886 		setup_subtype_description(&subtypes[0], KC_ST_UINT32, 0, "p_csflags");
887 		setup_type_definition(retval, type_id, 1, "p_csflags");
888 		break;
889 	}
890 
891 	case TASK_CRASHINFO_PROC_STATUS: {
892 		setup_subtype_description(&subtypes[0], KC_ST_UINT8, 0, "p_status");
893 		setup_type_definition(retval, type_id, 1, "p_status");
894 		break;
895 	}
896 
897 	case TASK_CRASHINFO_UID: {
898 		setup_subtype_description(&subtypes[0], KC_ST_INT32, 0, "uid");
899 		setup_type_definition(retval, type_id, 1, "uid");
900 		break;
901 	}
902 
903 	case TASK_CRASHINFO_GID: {
904 		setup_subtype_description(&subtypes[0], KC_ST_INT32, 0, "gid");
905 		setup_type_definition(retval, type_id, 1, "gid");
906 		break;
907 	}
908 
909 	case TASK_CRASHINFO_PROC_ARGC: {
910 		setup_subtype_description(&subtypes[0], KC_ST_INT32, 0, "argc");
911 		setup_type_definition(retval, type_id, 1, "argc");
912 		break;
913 	}
914 
915 	case TASK_CRASHINFO_PROC_FLAGS: {
916 		setup_subtype_description(&subtypes[0], KC_ST_UINT32, 0, "p_flags");
917 		setup_type_definition(retval, type_id, 1, "p_flags");
918 		break;
919 	}
920 
921 	case TASK_CRASHINFO_CPUTYPE: {
922 		setup_subtype_description(&subtypes[0], KC_ST_INT32, 0, "cputype");
923 		setup_type_definition(retval, type_id, 1, "cputype");
924 		break;
925 	}
926 
927 	case TASK_CRASHINFO_RESPONSIBLE_PID: {
928 		setup_subtype_description(&subtypes[0], KC_ST_INT32, 0, "responsible_pid");
929 		setup_type_definition(retval, type_id, 1, "responsible_pid");
930 		break;
931 	}
932 
933 	case TASK_CRASHINFO_DIRTY_FLAGS: {
934 		setup_subtype_description(&subtypes[0], KC_ST_UINT32, 0, "dirty_flags");
935 		setup_type_definition(retval, type_id, 1, "dirty_flags");
936 		break;
937 	}
938 
939 	case TASK_CRASHINFO_CRASHED_THREADID: {
940 		setup_subtype_description(&subtypes[0], KC_ST_UINT64, 0, "crashed_threadid");
941 		setup_type_definition(retval, type_id, 1, "crashed_threadid");
942 		break;
943 	}
944 
945 	case TASK_CRASHINFO_COALITION_ID: {
946 		setup_subtype_description(&subtypes[0], KC_ST_UINT64, 0, "coalition_id");
947 		setup_type_definition(retval, type_id, 1, "coalition_id");
948 		break;
949 	}
950 
951 	case TASK_CRASHINFO_UDATA_PTRS: {
952 		setup_subtype_description(&subtypes[0], KC_ST_UINT64, 0, "udata_ptrs");
953 		setup_type_definition(retval, type_id, 1, "udata_ptrs");
954 		break;
955 	}
956 
957 	case TASK_CRASHINFO_MEMORY_LIMIT: {
958 		setup_subtype_description(&subtypes[0], KC_ST_UINT64, 0, "task_phys_mem_limit");
959 		setup_type_definition(retval, type_id, 1, "task_phys_mem_limit");
960 		break;
961 	}
962 
963 	case TASK_CRASHINFO_TASK_IS_CORPSE_FORK: {
964 		setup_subtype_description(&subtypes[0], KC_ST_UINT32, 0, "task_is_corpse_fork");
965 		setup_type_definition(retval, type_id, 1, "task_is_corpse_fork");
966 		break;
967 	}
968 
969 	case TASK_CRASHINFO_EXCEPTION_TYPE: {
970 		setup_subtype_description(&subtypes[0], KC_ST_UINT32, 0, "exception_type");
971 		setup_type_definition(retval, type_id, 1, "exception_type");
972 		break;
973 	}
974 
975 	case TASK_CRASHINFO_CS_SIGNING_ID: {
976 		i = 0;
977 		_STRINGTYPE("cs_signing_id");
978 		setup_type_definition(retval, type_id, i, "cs_signing_id");
979 		break;
980 	}
981 
982 	case TASK_CRASHINFO_CS_TEAM_ID: {
983 		i = 0;
984 		_STRINGTYPE("cs_team_id");
985 		setup_type_definition(retval, type_id, i, "cs_team_id");
986 		break;
987 	}
988 
989 	case TASK_CRASHINFO_CS_VALIDATION_CATEGORY: {
990 		setup_subtype_description(&subtypes[0], KC_ST_UINT32, 0, "cs_validation_category");
991 		setup_type_definition(retval, type_id, 1, "cs_validation_category");
992 		break;
993 	}
994 	case TASK_CRASHINFO_CS_TRUST_LEVEL: {
995 		setup_subtype_description(&subtypes[0], KC_ST_UINT32, 0, "cs_trust_level");
996 		setup_type_definition(retval, type_id, 1, "cs_trust_level");
997 		break;
998 	}
999 	case TASK_CRASHINFO_JIT_ADDRESS_RANGE: {
1000 		i = 0;
1001 		_SUBTYPE(KC_ST_UINT64, struct crashinfo_jit_address_range, start_address);
1002 		_SUBTYPE(KC_ST_UINT64, struct crashinfo_jit_address_range, end_address);
1003 		setup_type_definition(retval, type_id, 1, "jit_address_range");
1004 		break;
1005 	}
1006 	case TASK_CRASHINFO_MB: {
1007 		_SUBTYPE(KC_ST_UINT64, struct crashinfo_mb, start_address);
1008 		_SUBTYPE_ARRAY(KC_ST_UINT64, struct crashinfo_mb, data, 64);
1009 		setup_type_definition(retval, type_id, 1, "tags");
1010 	}
1011 	case TASK_CRASHINFO_CS_AUXILIARY_INFO: {
1012 		setup_subtype_description(&subtypes[0], KC_ST_UINT64, 0, "cs_auxiliary_info");
1013 		setup_type_definition(retval, type_id, 1, "cs_auxiliary_info");
1014 		break;
1015 	}
1016 	case EXIT_REASON_SNAPSHOT: {
1017 		_SUBTYPE(KC_ST_UINT32, struct exit_reason_snapshot, ers_namespace);
1018 		_SUBTYPE(KC_ST_UINT64, struct exit_reason_snapshot, ers_code);
1019 		_SUBTYPE(KC_ST_UINT64, struct exit_reason_snapshot, ers_flags);
1020 		setup_type_definition(retval, type_id, i, "exit_reason_basic_info");
1021 
1022 		break;
1023 	}
1024 
1025 	case EXIT_REASON_USER_DESC: {
1026 		i = 0;
1027 
1028 		_STRINGTYPE("exit_reason_user_description");
1029 		setup_type_definition(retval, type_id, i, "exit_reason_user_description");
1030 		break;
1031 	}
1032 
1033 	case EXIT_REASON_USER_PAYLOAD: {
1034 		i = 0;
1035 
1036 		setup_subtype_array_description(&subtypes[i++], KC_ST_UINT8, 0, EXIT_REASON_PAYLOAD_MAX_LEN, "exit_reason_user_payload");
1037 		setup_type_definition(retval, type_id, i, "exit_reason_user_payload");
1038 		break;
1039 	}
1040 
1041 	case EXIT_REASON_CODESIGNING_INFO: {
1042 		_SUBTYPE(KC_ST_UINT64, struct codesigning_exit_reason_info, ceri_virt_addr);
1043 		_SUBTYPE(KC_ST_UINT64, struct codesigning_exit_reason_info, ceri_file_offset);
1044 		_SUBTYPE_ARRAY(KC_ST_CHAR, struct codesigning_exit_reason_info, ceri_pathname, EXIT_REASON_CODESIG_PATH_MAX);
1045 		_SUBTYPE_ARRAY(KC_ST_CHAR, struct codesigning_exit_reason_info, ceri_filename, EXIT_REASON_CODESIG_PATH_MAX);
1046 		_SUBTYPE(KC_ST_UINT64, struct codesigning_exit_reason_info, ceri_codesig_modtime_secs);
1047 		_SUBTYPE(KC_ST_UINT64, struct codesigning_exit_reason_info, ceri_codesig_modtime_nsecs);
1048 		_SUBTYPE(KC_ST_UINT64, struct codesigning_exit_reason_info, ceri_page_modtime_secs);
1049 		_SUBTYPE(KC_ST_UINT64, struct codesigning_exit_reason_info, ceri_page_modtime_nsecs);
1050 		_SUBTYPE(KC_ST_UINT8, struct codesigning_exit_reason_info, ceri_path_truncated);
1051 		_SUBTYPE(KC_ST_UINT8, struct codesigning_exit_reason_info, ceri_object_codesigned);
1052 		_SUBTYPE(KC_ST_UINT8, struct codesigning_exit_reason_info, ceri_page_codesig_validated);
1053 		_SUBTYPE(KC_ST_UINT8, struct codesigning_exit_reason_info, ceri_page_codesig_tainted);
1054 		_SUBTYPE(KC_ST_UINT8, struct codesigning_exit_reason_info, ceri_page_codesig_nx);
1055 		_SUBTYPE(KC_ST_UINT8, struct codesigning_exit_reason_info, ceri_page_wpmapped);
1056 		_SUBTYPE(KC_ST_UINT8, struct codesigning_exit_reason_info, ceri_page_slid);
1057 		_SUBTYPE(KC_ST_UINT8, struct codesigning_exit_reason_info, ceri_page_dirty);
1058 		_SUBTYPE(KC_ST_UINT32, struct codesigning_exit_reason_info, ceri_page_shadow_depth);
1059 		setup_type_definition(retval, type_id, i, "exit_reason_codesigning_info");
1060 		break;
1061 	}
1062 
1063 	case EXIT_REASON_WORKLOOP_ID: {
1064 		i = 0;
1065 		setup_subtype_description(&subtypes[i++], KC_ST_UINT64, 0, "exit_reason_workloop_id");
1066 		setup_type_definition(retval, type_id, i, "exit_reason_workloop_id");
1067 		break;
1068 	}
1069 
1070 	case EXIT_REASON_DISPATCH_QUEUE_NO: {
1071 		i = 0;
1072 		setup_subtype_description(&subtypes[i++], KC_ST_UINT64, 0, "exit_reason_dispatch_queue_no");
1073 		setup_type_definition(retval, type_id, i, "exit_reason_dispatch_queue_no");
1074 		break;
1075 	}
1076 
1077 	case STACKSHOT_KCTYPE_ASID: {
1078 		i = 0;
1079 		setup_subtype_description(&subtypes[i++], KC_ST_UINT32, 0, "ts_asid");
1080 		setup_type_definition(retval, type_id, i, "ts_asid");
1081 		break;
1082 	}
1083 
1084 	case STACKSHOT_KCTYPE_PAGE_TABLES: {
1085 		i = 0;
1086 		setup_subtype_description(&subtypes[i++], KC_ST_UINT64, 0, "ts_pagetable");
1087 		setup_type_definition(retval, type_id, i, "ts_pagetable");
1088 		break;
1089 	}
1090 
1091 	case STACKSHOT_KCTYPE_SYS_SHAREDCACHE_LAYOUT: {
1092 		i = 0;
1093 		_SUBTYPE(KC_ST_UINT64, struct user64_dyld_uuid_info, imageLoadAddress);
1094 		_SUBTYPE_ARRAY(KC_ST_UINT8, struct user64_dyld_uuid_info, imageUUID, 16);
1095 		setup_type_definition(retval, type_id, i, "system_shared_cache_layout");
1096 		break;
1097 	}
1098 
1099 	case STACKSHOT_KCTYPE_THREAD_DISPATCH_QUEUE_LABEL: {
1100 		i = 0;
1101 		_STRINGTYPE("dispatch_queue_label");
1102 		setup_type_definition(retval, type_id, i, "dispatch_queue_label");
1103 		break;
1104 	}
1105 
1106 	case STACKSHOT_KCTYPE_THREAD_TURNSTILEINFO: {
1107 		i = 0;
1108 		_SUBTYPE(KC_ST_UINT64, struct stackshot_thread_turnstileinfo_v2, waiter);
1109 		_SUBTYPE(KC_ST_UINT64, struct stackshot_thread_turnstileinfo_v2, turnstile_context);
1110 		_SUBTYPE(KC_ST_UINT8, struct stackshot_thread_turnstileinfo_v2, turnstile_priority);
1111 		_SUBTYPE(KC_ST_UINT8, struct stackshot_thread_turnstileinfo_v2, number_of_hops);
1112 		_SUBTYPE(KC_ST_UINT64, struct stackshot_thread_turnstileinfo_v2, turnstile_flags);
1113 		_SUBTYPE(KC_ST_INT16, struct stackshot_thread_turnstileinfo_v2, portlabel_id);
1114 		setup_type_definition(retval, type_id, i, "thread_turnstileinfo");
1115 		break;
1116 	}
1117 
1118 	case STACKSHOT_KCTYPE_PORTLABEL: {
1119 		i = 0;
1120 		_SUBTYPE(KC_ST_INT16, struct portlabel_info, portlabel_id);
1121 		_SUBTYPE(KC_ST_UINT16, struct portlabel_info, portlabel_flags);
1122 		_SUBTYPE(KC_ST_INT8, struct portlabel_info, portlabel_domain);
1123 		subtypes[0].kcs_flags |= KCS_SUBTYPE_FLAGS_MERGE;
1124 		subtypes[1].kcs_flags |= KCS_SUBTYPE_FLAGS_MERGE;
1125 		subtypes[2].kcs_flags |= KCS_SUBTYPE_FLAGS_MERGE;
1126 		setup_type_definition(retval, type_id, i, "portlabel_info");
1127 		break;
1128 	}
1129 
1130 	case STACKSHOT_KCTYPE_PORTLABEL_NAME:
1131 		i = 0;
1132 		_STRINGTYPE("portlabel_name");
1133 		setup_type_definition(retval, type_id, i, "portlabel_name");
1134 		break;
1135 
1136 	case STACKSHOT_KCTYPE_TASK_CPU_ARCHITECTURE: {
1137 		i = 0;
1138 		_SUBTYPE(KC_ST_INT32, struct stackshot_cpu_architecture, cputype);
1139 		_SUBTYPE(KC_ST_INT32, struct stackshot_cpu_architecture, cpusubtype);
1140 		setup_type_definition(retval, type_id, i, "task_cpu_architecture");
1141 		break;
1142 	}
1143 
1144 	case STACKSHOT_KCTYPE_LATENCY_INFO: {
1145 		i = 0;
1146 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_collection, latency_version);
1147 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_collection, setup_latency);
1148 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_collection, total_task_iteration_latency);
1149 		_SUBTYPE_TRUNC(KC_ST_UINT64, struct stackshot_latency_collection, total_terminated_task_iteration_latency, "total_terminated_task_iteration");
1150 		setup_type_definition(retval, type_id, i, "stackshot_latency_collection");
1151 		break;
1152 	}
1153 	case STACKSHOT_KCTYPE_LATENCY_INFO_TASK: {
1154 		i = 0;
1155 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_task, task_uniqueid);
1156 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_task, setup_latency);
1157 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_task, task_thread_count_loop_latency);
1158 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_task, task_thread_data_loop_latency);
1159 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_task, cur_tsnap_latency);
1160 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_task, pmap_latency);
1161 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_task, bsd_proc_ids_latency);
1162 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_task, misc_latency);
1163 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_task, misc2_latency);
1164 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_task, end_latency);
1165 		setup_type_definition(retval, type_id, i, "stackshot_latency_task");
1166 		break;
1167 	}
1168 	case STACKSHOT_KCTYPE_LATENCY_INFO_THREAD: {
1169 		i = 0;
1170 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_thread, thread_id);
1171 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_thread, cur_thsnap1_latency);
1172 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_thread, dispatch_serial_latency);
1173 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_thread, dispatch_label_latency);
1174 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_thread, cur_thsnap2_latency);
1175 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_thread, thread_name_latency);
1176 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_thread, sur_times_latency);
1177 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_thread, user_stack_latency);
1178 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_thread, kernel_stack_latency);
1179 		_SUBTYPE(KC_ST_UINT64, struct stackshot_latency_thread, misc_latency);
1180 		setup_type_definition(retval, type_id, i, "stackshot_latency_thread");
1181 		break;
1182 	}
1183 
1184 	case TASK_CRASHINFO_KERNEL_TRIAGE_INFO_V1: {
1185 		i = 0;
1186 		_SUBTYPE_ARRAY(KC_ST_CHAR, struct kernel_triage_info_v1, triage_string1, MAX_TRIAGE_STRING_LEN);
1187 		_SUBTYPE_ARRAY(KC_ST_CHAR, struct kernel_triage_info_v1, triage_string2, MAX_TRIAGE_STRING_LEN);
1188 		_SUBTYPE_ARRAY(KC_ST_CHAR, struct kernel_triage_info_v1, triage_string3, MAX_TRIAGE_STRING_LEN);
1189 		_SUBTYPE_ARRAY(KC_ST_CHAR, struct kernel_triage_info_v1, triage_string4, MAX_TRIAGE_STRING_LEN);
1190 		_SUBTYPE_ARRAY(KC_ST_CHAR, struct kernel_triage_info_v1, triage_string5, MAX_TRIAGE_STRING_LEN);
1191 		setup_type_definition(retval, type_id, i, "kernel_triage_info_v1");
1192 		break;
1193 	}
1194 
1195 	default:
1196 		retval = NULL;
1197 		break;
1198 	}
1199 
1200 	assert(retval == NULL || (buffer_size > sizeof(struct kcdata_type_definition) +
1201 	    (retval->kct_num_elements * sizeof(struct kcdata_subtype_descriptor))));
1202 	return retval;
1203 }
1204 
1205 static void
setup_type_definition(struct kcdata_type_definition * d,uint32_t type,uint32_t num_elems,char * name)1206 setup_type_definition(struct kcdata_type_definition * d, uint32_t type, uint32_t num_elems, char * name)
1207 {
1208 	d->kct_type_identifier = type;
1209 	d->kct_num_elements = num_elems;
1210 	memcpy(d->kct_name, name, sizeof(d->kct_name));
1211 	d->kct_name[sizeof(d->kct_name) - 1] = '\0';
1212 }
1213 
1214 static uint32_t
get_kctype_subtype_size(kctype_subtype_t type)1215 get_kctype_subtype_size(kctype_subtype_t type)
1216 {
1217 	switch (type) {
1218 	case KC_ST_CHAR:
1219 	case KC_ST_INT8:
1220 	case KC_ST_UINT8:
1221 		return sizeof(uint8_t);
1222 		break;
1223 	case KC_ST_INT16:
1224 	case KC_ST_UINT16:
1225 		return sizeof(uint16_t);
1226 		break;
1227 	case KC_ST_INT32:
1228 	case KC_ST_UINT32:
1229 		return sizeof(uint32_t);
1230 		break;
1231 	case KC_ST_INT64:
1232 	case KC_ST_UINT64:
1233 		return sizeof(uint64_t);
1234 		break;
1235 
1236 	default:
1237 		assert(0);
1238 		break;
1239 	}
1240 	return 0;
1241 }
1242 
1243 static void
setup_subtype_array_description(kcdata_subtype_descriptor_t desc,kctype_subtype_t type,uint32_t offset,uint32_t count,char * name)1244 setup_subtype_array_description(
1245 	kcdata_subtype_descriptor_t desc, kctype_subtype_t type, uint32_t offset, uint32_t count, char * name)
1246 {
1247 	desc->kcs_flags       = KCS_SUBTYPE_FLAGS_ARRAY;
1248 	desc->kcs_elem_type   = type;
1249 	desc->kcs_elem_offset = offset;
1250 	desc->kcs_elem_size = KCS_SUBTYPE_PACK_SIZE(count, get_kctype_subtype_size(type));
1251 	memcpy(desc->kcs_name, name, sizeof(desc->kcs_name));
1252 	desc->kcs_name[sizeof(desc->kcs_name) - 1] = '\0';
1253 }
1254 
1255 static void
setup_subtype_description(kcdata_subtype_descriptor_t desc,kctype_subtype_t type,uint32_t offset,char * name)1256 setup_subtype_description(kcdata_subtype_descriptor_t desc, kctype_subtype_t type, uint32_t offset, char * name)
1257 {
1258 	desc->kcs_flags       = KCS_SUBTYPE_FLAGS_NONE;
1259 	desc->kcs_elem_type   = type;
1260 	desc->kcs_elem_offset = offset;
1261 	desc->kcs_elem_size = get_kctype_subtype_size(type);
1262 	memcpy(desc->kcs_name, name, sizeof(desc->kcs_name));
1263 	desc->kcs_name[sizeof(desc->kcs_name) - 1] = '\0';
1264 }
1265