1*2c2f96dcSApple OSS Distributions /*
2*2c2f96dcSApple OSS Distributions * Copyright (c) 2015 Apple Inc. All rights reserved.
3*2c2f96dcSApple OSS Distributions *
4*2c2f96dcSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*2c2f96dcSApple OSS Distributions *
6*2c2f96dcSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*2c2f96dcSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*2c2f96dcSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*2c2f96dcSApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*2c2f96dcSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*2c2f96dcSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*2c2f96dcSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*2c2f96dcSApple OSS Distributions * terms of an Apple operating system software license agreement.
14*2c2f96dcSApple OSS Distributions *
15*2c2f96dcSApple OSS Distributions * Please obtain a copy of the License at
16*2c2f96dcSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*2c2f96dcSApple OSS Distributions *
18*2c2f96dcSApple OSS Distributions * The Original Code and all software distributed under the License are
19*2c2f96dcSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*2c2f96dcSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*2c2f96dcSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*2c2f96dcSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*2c2f96dcSApple OSS Distributions * Please see the License for the specific language governing rights and
24*2c2f96dcSApple OSS Distributions * limitations under the License.
25*2c2f96dcSApple OSS Distributions *
26*2c2f96dcSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*2c2f96dcSApple OSS Distributions */
28*2c2f96dcSApple OSS Distributions
29*2c2f96dcSApple OSS Distributions
30*2c2f96dcSApple OSS Distributions /*
31*2c2f96dcSApple OSS Distributions *
32*2c2f96dcSApple OSS Distributions * THE KCDATA MANIFESTO
33*2c2f96dcSApple OSS Distributions *
34*2c2f96dcSApple OSS Distributions * Kcdata is a self-describing data serialization format. It is meant to get
35*2c2f96dcSApple OSS Distributions * nested data structures out of xnu with minimum fuss, but also for that data
36*2c2f96dcSApple OSS Distributions * to be easy to parse. It is also meant to allow us to add new fields and
37*2c2f96dcSApple OSS Distributions * evolve the data format without breaking old parsers.
38*2c2f96dcSApple OSS Distributions *
39*2c2f96dcSApple OSS Distributions * Kcdata is a permanent data format suitable for long-term storage including
40*2c2f96dcSApple OSS Distributions * in files. It is very important that we continue to be able to parse old
41*2c2f96dcSApple OSS Distributions * versions of kcdata-based formats. To this end, there are several
42*2c2f96dcSApple OSS Distributions * invariants you MUST MAINTAIN if you alter this file.
43*2c2f96dcSApple OSS Distributions *
44*2c2f96dcSApple OSS Distributions * * None of the magic numbers should ever be a byteswap of themselves or
45*2c2f96dcSApple OSS Distributions * of any of the other magic numbers.
46*2c2f96dcSApple OSS Distributions *
47*2c2f96dcSApple OSS Distributions * * Never remove any type.
48*2c2f96dcSApple OSS Distributions *
49*2c2f96dcSApple OSS Distributions * * All kcdata structs must be packed, and must exclusively use fixed-size
50*2c2f96dcSApple OSS Distributions * types.
51*2c2f96dcSApple OSS Distributions *
52*2c2f96dcSApple OSS Distributions * * Never change the definition of any type, except to add new fields to
53*2c2f96dcSApple OSS Distributions * the end.
54*2c2f96dcSApple OSS Distributions *
55*2c2f96dcSApple OSS Distributions * * If you do add new fields to the end of a type, do not actually change
56*2c2f96dcSApple OSS Distributions * the definition of the old structure. Instead, define a new structure
57*2c2f96dcSApple OSS Distributions * with the new fields. See thread_snapshot_v3 as an example. This
58*2c2f96dcSApple OSS Distributions * provides source compatibility for old readers, and also documents where
59*2c2f96dcSApple OSS Distributions * the potential size cutoffs are.
60*2c2f96dcSApple OSS Distributions *
61*2c2f96dcSApple OSS Distributions * * If you change libkdd, or kcdata.py run the unit tests under libkdd.
62*2c2f96dcSApple OSS Distributions *
63*2c2f96dcSApple OSS Distributions * * If you add a type or extend an existing one, add a sample test to
64*2c2f96dcSApple OSS Distributions * libkdd/tests so future changes to libkdd will always parse your struct
65*2c2f96dcSApple OSS Distributions * correctly.
66*2c2f96dcSApple OSS Distributions *
67*2c2f96dcSApple OSS Distributions * For example to add a field to this:
68*2c2f96dcSApple OSS Distributions *
69*2c2f96dcSApple OSS Distributions * struct foobar {
70*2c2f96dcSApple OSS Distributions * uint32_t baz;
71*2c2f96dcSApple OSS Distributions * uint32_t quux;
72*2c2f96dcSApple OSS Distributions * } __attribute__ ((packed));
73*2c2f96dcSApple OSS Distributions *
74*2c2f96dcSApple OSS Distributions * Make it look like this:
75*2c2f96dcSApple OSS Distributions *
76*2c2f96dcSApple OSS Distributions * struct foobar {
77*2c2f96dcSApple OSS Distributions * uint32_t baz;
78*2c2f96dcSApple OSS Distributions * uint32_t quux;
79*2c2f96dcSApple OSS Distributions * ///////// end version 1 of foobar. sizeof(struct foobar) was 8 ////////
80*2c2f96dcSApple OSS Distributions * uint32_t frozzle;
81*2c2f96dcSApple OSS Distributions * } __attribute__ ((packed));
82*2c2f96dcSApple OSS Distributions *
83*2c2f96dcSApple OSS Distributions * If you are parsing kcdata formats, you MUST
84*2c2f96dcSApple OSS Distributions *
85*2c2f96dcSApple OSS Distributions * * Check the length field of each struct, including array elements. If the
86*2c2f96dcSApple OSS Distributions * struct is longer than you expect, you must ignore the extra data.
87*2c2f96dcSApple OSS Distributions *
88*2c2f96dcSApple OSS Distributions * * Ignore any data types you do not understand.
89*2c2f96dcSApple OSS Distributions *
90*2c2f96dcSApple OSS Distributions * Additionally, we want to be as forward compatible as we can. Meaning old
91*2c2f96dcSApple OSS Distributions * tools should still be able to use new data whenever possible. To this end,
92*2c2f96dcSApple OSS Distributions * you should:
93*2c2f96dcSApple OSS Distributions *
94*2c2f96dcSApple OSS Distributions * * Try not to add new versions of types that supplant old ones. Instead
95*2c2f96dcSApple OSS Distributions * extend the length of existing types or add supplemental types.
96*2c2f96dcSApple OSS Distributions *
97*2c2f96dcSApple OSS Distributions * * Try not to remove information from existing kcdata formats, unless
98*2c2f96dcSApple OSS Distributions * removal was explicitly asked for. For example it is fine to add a
99*2c2f96dcSApple OSS Distributions * stackshot flag to remove unwanted information, but you should not
100*2c2f96dcSApple OSS Distributions * remove it from the default stackshot if the new flag is absent.
101*2c2f96dcSApple OSS Distributions *
102*2c2f96dcSApple OSS Distributions * * (TBD) If you do break old readers by removing information or
103*2c2f96dcSApple OSS Distributions * supplanting old structs, then increase the major version number.
104*2c2f96dcSApple OSS Distributions *
105*2c2f96dcSApple OSS Distributions *
106*2c2f96dcSApple OSS Distributions *
107*2c2f96dcSApple OSS Distributions * The following is a description of the kcdata format.
108*2c2f96dcSApple OSS Distributions *
109*2c2f96dcSApple OSS Distributions *
110*2c2f96dcSApple OSS Distributions * The format for data is setup in a generic format as follows
111*2c2f96dcSApple OSS Distributions *
112*2c2f96dcSApple OSS Distributions * Layout of data structure:
113*2c2f96dcSApple OSS Distributions *
114*2c2f96dcSApple OSS Distributions * | 8 - bytes |
115*2c2f96dcSApple OSS Distributions * | type = MAGIC | LENGTH |
116*2c2f96dcSApple OSS Distributions * | 0 |
117*2c2f96dcSApple OSS Distributions * | type | size |
118*2c2f96dcSApple OSS Distributions * | flags |
119*2c2f96dcSApple OSS Distributions * | data |
120*2c2f96dcSApple OSS Distributions * |___________data____________|
121*2c2f96dcSApple OSS Distributions * | type | size |
122*2c2f96dcSApple OSS Distributions * | flags |
123*2c2f96dcSApple OSS Distributions * |___________data____________|
124*2c2f96dcSApple OSS Distributions * | type = END | size=0 |
125*2c2f96dcSApple OSS Distributions * | 0 |
126*2c2f96dcSApple OSS Distributions *
127*2c2f96dcSApple OSS Distributions *
128*2c2f96dcSApple OSS Distributions * The type field describes what kind of data is passed. For example type = TASK_CRASHINFO_UUID means the following data is a uuid.
129*2c2f96dcSApple OSS Distributions * These types need to be defined in task_corpses.h for easy consumption by userspace inspection tools.
130*2c2f96dcSApple OSS Distributions *
131*2c2f96dcSApple OSS Distributions * Some range of types is reserved for special types like ints, longs etc. A cool new functionality made possible with this
132*2c2f96dcSApple OSS Distributions * extensible data format is that kernel can decide to put more information as required without requiring user space tools to
133*2c2f96dcSApple OSS Distributions * re-compile to be compatible. The case of rusage struct versions could be introduced without breaking existing tools.
134*2c2f96dcSApple OSS Distributions *
135*2c2f96dcSApple OSS Distributions * Feature description: Generic data with description
136*2c2f96dcSApple OSS Distributions * -------------------
137*2c2f96dcSApple OSS Distributions * Further more generic data with description is very much possible now. For example
138*2c2f96dcSApple OSS Distributions *
139*2c2f96dcSApple OSS Distributions * - kcdata_add_uint64_with_description(cdatainfo, 0x700, "NUM MACH PORTS");
140*2c2f96dcSApple OSS Distributions * - and more functions that allow adding description.
141*2c2f96dcSApple OSS Distributions * The userspace tools can then look at the description and print the data even if they are not compiled with knowledge of the field apriori.
142*2c2f96dcSApple OSS Distributions *
143*2c2f96dcSApple OSS Distributions * Example data:
144*2c2f96dcSApple OSS Distributions * 0000 57 f1 ad de 00 00 00 00 00 00 00 00 00 00 00 00 W...............
145*2c2f96dcSApple OSS Distributions * 0010 01 00 00 00 00 00 00 00 30 00 00 00 00 00 00 00 ........0.......
146*2c2f96dcSApple OSS Distributions * 0020 50 49 44 00 00 00 00 00 00 00 00 00 00 00 00 00 PID.............
147*2c2f96dcSApple OSS Distributions * 0030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
148*2c2f96dcSApple OSS Distributions * 0040 9c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
149*2c2f96dcSApple OSS Distributions * 0050 01 00 00 00 00 00 00 00 30 00 00 00 00 00 00 00 ........0.......
150*2c2f96dcSApple OSS Distributions * 0060 50 41 52 45 4e 54 20 50 49 44 00 00 00 00 00 00 PARENT PID......
151*2c2f96dcSApple OSS Distributions * 0070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
152*2c2f96dcSApple OSS Distributions * 0080 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
153*2c2f96dcSApple OSS Distributions * 0090 ed 58 91 f1
154*2c2f96dcSApple OSS Distributions *
155*2c2f96dcSApple OSS Distributions * Feature description: Container markers for compound data
156*2c2f96dcSApple OSS Distributions * ------------------
157*2c2f96dcSApple OSS Distributions * If a given kernel data type is complex and requires adding multiple optional fields inside a container
158*2c2f96dcSApple OSS Distributions * object for a consumer to understand arbitrary data, we package it using container markers.
159*2c2f96dcSApple OSS Distributions *
160*2c2f96dcSApple OSS Distributions * For example, the stackshot code gathers information and describes the state of a given task with respect
161*2c2f96dcSApple OSS Distributions * to many subsystems. It includes data such as io stats, vm counters, process names/flags and syscall counts.
162*2c2f96dcSApple OSS Distributions *
163*2c2f96dcSApple OSS Distributions * kcdata_add_container_marker(kcdata_p, KCDATA_TYPE_CONTAINER_BEGIN, STACKSHOT_KCCONTAINER_TASK, task_uniqueid);
164*2c2f96dcSApple OSS Distributions * // add multiple data, or add_<type>_with_description()s here
165*2c2f96dcSApple OSS Distributions *
166*2c2f96dcSApple OSS Distributions * kcdata_add_container_marker(kcdata_p, KCDATA_TYPE_CONTAINER_END, STACKSHOT_KCCONTAINER_TASK, task_uniqueid);
167*2c2f96dcSApple OSS Distributions *
168*2c2f96dcSApple OSS Distributions * Feature description: Custom Data formats on demand
169*2c2f96dcSApple OSS Distributions * --------------------
170*2c2f96dcSApple OSS Distributions * With the self describing nature of format, the kernel provider can describe a data type (uniquely identified by a number) and use
171*2c2f96dcSApple OSS Distributions * it in the buffer for sending data. The consumer can parse the type information and have knowledge of describing incoming data.
172*2c2f96dcSApple OSS Distributions * Following is an example of how we can describe a kernel specific struct sample_disk_io_stats in buffer.
173*2c2f96dcSApple OSS Distributions *
174*2c2f96dcSApple OSS Distributions * struct sample_disk_io_stats {
175*2c2f96dcSApple OSS Distributions * uint64_t disk_reads_count;
176*2c2f96dcSApple OSS Distributions * uint64_t disk_reads_size;
177*2c2f96dcSApple OSS Distributions * uint64_t io_priority_count[4];
178*2c2f96dcSApple OSS Distributions * uint64_t io_priority_size;
179*2c2f96dcSApple OSS Distributions * } __attribute__ ((packed));
180*2c2f96dcSApple OSS Distributions *
181*2c2f96dcSApple OSS Distributions *
182*2c2f96dcSApple OSS Distributions * struct kcdata_subtype_descriptor disk_io_stats_def[] = {
183*2c2f96dcSApple OSS Distributions * {KCS_SUBTYPE_FLAGS_NONE, KC_ST_UINT64, 0 * sizeof(uint64_t), sizeof(uint64_t), "disk_reads_count"},
184*2c2f96dcSApple OSS Distributions * {KCS_SUBTYPE_FLAGS_NONE, KC_ST_UINT64, 1 * sizeof(uint64_t), sizeof(uint64_t), "disk_reads_size"},
185*2c2f96dcSApple OSS Distributions * {KCS_SUBTYPE_FLAGS_ARRAY, KC_ST_UINT64, 2 * sizeof(uint64_t), KCS_SUBTYPE_PACK_SIZE(4, sizeof(uint64_t)), "io_priority_count"},
186*2c2f96dcSApple OSS Distributions * {KCS_SUBTYPE_FLAGS_ARRAY, KC_ST_UINT64, (2 + 4) * sizeof(uint64_t), sizeof(uint64_t), "io_priority_size"},
187*2c2f96dcSApple OSS Distributions * };
188*2c2f96dcSApple OSS Distributions *
189*2c2f96dcSApple OSS Distributions * Now you can add this custom type definition into the buffer as
190*2c2f96dcSApple OSS Distributions * kcdata_add_type_definition(kcdata_p, KCTYPE_SAMPLE_DISK_IO_STATS, "sample_disk_io_stats",
191*2c2f96dcSApple OSS Distributions * &disk_io_stats_def[0], sizeof(disk_io_stats_def)/sizeof(struct kcdata_subtype_descriptor));
192*2c2f96dcSApple OSS Distributions *
193*2c2f96dcSApple OSS Distributions * Feature description: Compression
194*2c2f96dcSApple OSS Distributions * --------------------
195*2c2f96dcSApple OSS Distributions * In order to avoid keeping large amounts of memory reserved for a panic stackshot, kcdata has support
196*2c2f96dcSApple OSS Distributions * for compressing the buffer in a streaming fashion. New data pushed to the kcdata buffer will be
197*2c2f96dcSApple OSS Distributions * automatically compressed using an algorithm selected by the API user (currently, we only support
198*2c2f96dcSApple OSS Distributions * pass-through and zlib, in the future we plan to add WKDM support, see: 57913859).
199*2c2f96dcSApple OSS Distributions *
200*2c2f96dcSApple OSS Distributions * To start using compression, call:
201*2c2f96dcSApple OSS Distributions * kcdata_init_compress(kcdata_p, hdr_tag, memcpy_f, comp_type);
202*2c2f96dcSApple OSS Distributions * where:
203*2c2f96dcSApple OSS Distributions * `kcdata_p` is the kcdata buffer that will be used
204*2c2f96dcSApple OSS Distributions * `hdr_tag` is the usual header tag denoting what type of kcdata buffer this will be
205*2c2f96dcSApple OSS Distributions * `memcpy_f` a memcpy(3) function to use to copy into the buffer, optional.
206*2c2f96dcSApple OSS Distributions * `compy_type` is the compression type, see KCDCT_ZLIB for an example.
207*2c2f96dcSApple OSS Distributions *
208*2c2f96dcSApple OSS Distributions * Once compression is initialized:
209*2c2f96dcSApple OSS Distributions * (1) all self-describing APIs will automatically compress
210*2c2f96dcSApple OSS Distributions * (2) you can now use the following APIs to compress data into the buffer:
211*2c2f96dcSApple OSS Distributions * (None of the following will compress unless kcdata_init_compress() has been called)
212*2c2f96dcSApple OSS Distributions *
213*2c2f96dcSApple OSS Distributions * - kcdata_push_data(kcdata_descriptor_t data, uint32_t type, uint32_t size, const void *input_data)
214*2c2f96dcSApple OSS Distributions * Pushes the buffer of kctype @type at[@input_data, @input_data + @size]
215*2c2f96dcSApple OSS Distributions * into the kcdata buffer @data, compressing if needed.
216*2c2f96dcSApple OSS Distributions *
217*2c2f96dcSApple OSS Distributions * - kcdata_push_array(kcdata_descriptor_t data, uint32_t type_of_element,
218*2c2f96dcSApple OSS Distributions * uint32_t size_of_element, uint32_t count, const void *input_data)
219*2c2f96dcSApple OSS Distributions * Pushes the array found at @input_data, with element type @type_of_element, where
220*2c2f96dcSApple OSS Distributions * each element is of size @size_of_element and there are @count elements into the kcdata buffer
221*2c2f96dcSApple OSS Distributions * at @data.
222*2c2f96dcSApple OSS Distributions *
223*2c2f96dcSApple OSS Distributions * - kcdata_compression_window_open/close(kcdata_descriptor_t data)
224*2c2f96dcSApple OSS Distributions * In case the data you are trying to push to the kcdata buffer @data is difficult to predict,
225*2c2f96dcSApple OSS Distributions * you can open a "compression window". Between an open and a close, no compression will be done.
226*2c2f96dcSApple OSS Distributions * Once you clsoe the window, the underlying compression algorithm will compress the data into the buffer
227*2c2f96dcSApple OSS Distributions * and automatically rewind the current end marker of the kcdata buffer.
228*2c2f96dcSApple OSS Distributions * There is an ASCII art in kern_cdata.c to aid the reader in understanding
229*2c2f96dcSApple OSS Distributions * this.
230*2c2f96dcSApple OSS Distributions *
231*2c2f96dcSApple OSS Distributions * - kcdata_finish_compression(kcdata_descriptor_t data)
232*2c2f96dcSApple OSS Distributions * Must be called at the end to flush any underlying buffers used by the compression algorithms.
233*2c2f96dcSApple OSS Distributions * This function will also add some statistics about the compression to the buffer which helps with
234*2c2f96dcSApple OSS Distributions * decompressing later.
235*2c2f96dcSApple OSS Distributions *
236*2c2f96dcSApple OSS Distributions */
237*2c2f96dcSApple OSS Distributions
238*2c2f96dcSApple OSS Distributions
239*2c2f96dcSApple OSS Distributions #ifndef _KCDATA_H_
240*2c2f96dcSApple OSS Distributions #define _KCDATA_H_
241*2c2f96dcSApple OSS Distributions
242*2c2f96dcSApple OSS Distributions #include <stdint.h>
243*2c2f96dcSApple OSS Distributions #include <string.h>
244*2c2f96dcSApple OSS Distributions #include <uuid/uuid.h>
245*2c2f96dcSApple OSS Distributions
246*2c2f96dcSApple OSS Distributions #define KCDATA_DESC_MAXLEN 32 /* including NULL byte at end */
247*2c2f96dcSApple OSS Distributions
248*2c2f96dcSApple OSS Distributions #define KCDATA_FLAGS_STRUCT_PADDING_MASK 0xf
249*2c2f96dcSApple OSS Distributions #define KCDATA_FLAGS_STRUCT_HAS_PADDING 0x80
250*2c2f96dcSApple OSS Distributions
251*2c2f96dcSApple OSS Distributions /*
252*2c2f96dcSApple OSS Distributions * kcdata aligns elements to 16 byte boundaries.
253*2c2f96dcSApple OSS Distributions */
254*2c2f96dcSApple OSS Distributions #define KCDATA_ALIGNMENT_SIZE 0x10
255*2c2f96dcSApple OSS Distributions
256*2c2f96dcSApple OSS Distributions struct kcdata_item {
257*2c2f96dcSApple OSS Distributions uint32_t type;
258*2c2f96dcSApple OSS Distributions uint32_t size; /* len(data) */
259*2c2f96dcSApple OSS Distributions /* flags.
260*2c2f96dcSApple OSS Distributions *
261*2c2f96dcSApple OSS Distributions * For structures:
262*2c2f96dcSApple OSS Distributions * padding = flags & 0xf
263*2c2f96dcSApple OSS Distributions * has_padding = (flags & 0x80) >> 7
264*2c2f96dcSApple OSS Distributions *
265*2c2f96dcSApple OSS Distributions * has_padding is needed to disambiguate cases such as
266*2c2f96dcSApple OSS Distributions * thread_snapshot_v2 and thread_snapshot_v3. Their
267*2c2f96dcSApple OSS Distributions * respective sizes are 0x68 and 0x70, and thread_snapshot_v2
268*2c2f96dcSApple OSS Distributions * was emitted by old kernels *before* we started recording
269*2c2f96dcSApple OSS Distributions * padding. Since legacy thread_snapsht_v2 and modern
270*2c2f96dcSApple OSS Distributions * thread_snapshot_v3 will both record 0 for the padding
271*2c2f96dcSApple OSS Distributions * flags, we need some other bit which will be nonzero in the
272*2c2f96dcSApple OSS Distributions * flags to disambiguate.
273*2c2f96dcSApple OSS Distributions *
274*2c2f96dcSApple OSS Distributions * This is why we hardcode a special case for
275*2c2f96dcSApple OSS Distributions * STACKSHOT_KCTYPE_THREAD_SNAPSHOT into the iterator
276*2c2f96dcSApple OSS Distributions * functions below. There is only a finite number of such
277*2c2f96dcSApple OSS Distributions * hardcodings which will ever be needed. They can occur
278*2c2f96dcSApple OSS Distributions * when:
279*2c2f96dcSApple OSS Distributions *
280*2c2f96dcSApple OSS Distributions * * We have a legacy structure that predates padding flags
281*2c2f96dcSApple OSS Distributions *
282*2c2f96dcSApple OSS Distributions * * which we want to extend without changing the kcdata type
283*2c2f96dcSApple OSS Distributions *
284*2c2f96dcSApple OSS Distributions * * by only so many bytes as would fit in the space that
285*2c2f96dcSApple OSS Distributions * was previously unused padding.
286*2c2f96dcSApple OSS Distributions *
287*2c2f96dcSApple OSS Distributions * For containers:
288*2c2f96dcSApple OSS Distributions * container_id = flags
289*2c2f96dcSApple OSS Distributions *
290*2c2f96dcSApple OSS Distributions * For arrays:
291*2c2f96dcSApple OSS Distributions * element_count = flags & UINT32_MAX
292*2c2f96dcSApple OSS Distributions * element_type = (flags >> 32) & UINT32_MAX
293*2c2f96dcSApple OSS Distributions */
294*2c2f96dcSApple OSS Distributions uint64_t flags;
295*2c2f96dcSApple OSS Distributions char data[]; /* must be at the end */
296*2c2f96dcSApple OSS Distributions };
297*2c2f96dcSApple OSS Distributions
298*2c2f96dcSApple OSS Distributions typedef struct kcdata_item * kcdata_item_t;
299*2c2f96dcSApple OSS Distributions
300*2c2f96dcSApple OSS Distributions enum KCDATA_SUBTYPE_TYPES { KC_ST_CHAR = 1, KC_ST_INT8, KC_ST_UINT8, KC_ST_INT16, KC_ST_UINT16, KC_ST_INT32, KC_ST_UINT32, KC_ST_INT64, KC_ST_UINT64 };
301*2c2f96dcSApple OSS Distributions typedef enum KCDATA_SUBTYPE_TYPES kctype_subtype_t;
302*2c2f96dcSApple OSS Distributions
303*2c2f96dcSApple OSS Distributions /*
304*2c2f96dcSApple OSS Distributions * A subtype description structure that defines
305*2c2f96dcSApple OSS Distributions * how a compound data is laid out in memory. This
306*2c2f96dcSApple OSS Distributions * provides on the fly definition of types and consumption
307*2c2f96dcSApple OSS Distributions * by the parser.
308*2c2f96dcSApple OSS Distributions */
309*2c2f96dcSApple OSS Distributions struct kcdata_subtype_descriptor {
310*2c2f96dcSApple OSS Distributions uint8_t kcs_flags;
311*2c2f96dcSApple OSS Distributions #define KCS_SUBTYPE_FLAGS_NONE 0x0
312*2c2f96dcSApple OSS Distributions #define KCS_SUBTYPE_FLAGS_ARRAY 0x1
313*2c2f96dcSApple OSS Distributions /* Force struct type even if only one element.
314*2c2f96dcSApple OSS Distributions *
315*2c2f96dcSApple OSS Distributions * Normally a kcdata_type_definition is treated as a structure if it has
316*2c2f96dcSApple OSS Distributions * more than one subtype descriptor. Otherwise it is treated as a simple
317*2c2f96dcSApple OSS Distributions * type. For example libkdd will represent a simple integer 42 as simply
318*2c2f96dcSApple OSS Distributions * 42, but it will represent a structure containing an integer 42 as
319*2c2f96dcSApple OSS Distributions * {"field_name": 42}..
320*2c2f96dcSApple OSS Distributions *
321*2c2f96dcSApple OSS Distributions * If a kcdata_type_definition has only single subtype, then it will be
322*2c2f96dcSApple OSS Distributions * treated as a structure iff KCS_SUBTYPE_FLAGS_STRUCT is set. If it has
323*2c2f96dcSApple OSS Distributions * multiple subtypes, it will always be treated as a structure.
324*2c2f96dcSApple OSS Distributions *
325*2c2f96dcSApple OSS Distributions * KCS_SUBTYPE_FLAGS_MERGE has the opposite effect. If this flag is used then
326*2c2f96dcSApple OSS Distributions * even if there are multiple elements, they will all be treated as individual
327*2c2f96dcSApple OSS Distributions * properties of the parent dictionary.
328*2c2f96dcSApple OSS Distributions */
329*2c2f96dcSApple OSS Distributions #define KCS_SUBTYPE_FLAGS_STRUCT 0x2 /* force struct type even if only one element */
330*2c2f96dcSApple OSS Distributions #define KCS_SUBTYPE_FLAGS_MERGE 0x4 /* treat as multiple elements of parents instead of struct */
331*2c2f96dcSApple OSS Distributions uint8_t kcs_elem_type; /* restricted to kctype_subtype_t */
332*2c2f96dcSApple OSS Distributions uint16_t kcs_elem_offset; /* offset in struct where data is found */
333*2c2f96dcSApple OSS Distributions uint32_t kcs_elem_size; /* size of element (or) packed state for array type */
334*2c2f96dcSApple OSS Distributions char kcs_name[KCDATA_DESC_MAXLEN]; /* max 31 bytes for name of field */
335*2c2f96dcSApple OSS Distributions };
336*2c2f96dcSApple OSS Distributions
337*2c2f96dcSApple OSS Distributions typedef struct kcdata_subtype_descriptor * kcdata_subtype_descriptor_t;
338*2c2f96dcSApple OSS Distributions
339*2c2f96dcSApple OSS Distributions /*
340*2c2f96dcSApple OSS Distributions * In case of array of basic c types in kctype_subtype_t,
341*2c2f96dcSApple OSS Distributions * size is packed in lower 16 bits and
342*2c2f96dcSApple OSS Distributions * count is packed in upper 16 bits of kcs_elem_size field.
343*2c2f96dcSApple OSS Distributions */
344*2c2f96dcSApple OSS Distributions #define KCS_SUBTYPE_PACK_SIZE(e_count, e_size) (((e_count)&0xffffu) << 16 | ((e_size)&0xffffu))
345*2c2f96dcSApple OSS Distributions
346*2c2f96dcSApple OSS Distributions static inline uint32_t
kcs_get_elem_size(kcdata_subtype_descriptor_t d)347*2c2f96dcSApple OSS Distributions kcs_get_elem_size(kcdata_subtype_descriptor_t d)
348*2c2f96dcSApple OSS Distributions {
349*2c2f96dcSApple OSS Distributions if (d->kcs_flags & KCS_SUBTYPE_FLAGS_ARRAY) {
350*2c2f96dcSApple OSS Distributions /* size is composed as ((count &0xffff)<<16 | (elem_size & 0xffff)) */
351*2c2f96dcSApple OSS Distributions return (uint32_t)((d->kcs_elem_size & 0xffff) * ((d->kcs_elem_size & 0xffff0000) >> 16));
352*2c2f96dcSApple OSS Distributions }
353*2c2f96dcSApple OSS Distributions return d->kcs_elem_size;
354*2c2f96dcSApple OSS Distributions }
355*2c2f96dcSApple OSS Distributions
356*2c2f96dcSApple OSS Distributions static inline uint32_t
kcs_get_elem_count(kcdata_subtype_descriptor_t d)357*2c2f96dcSApple OSS Distributions kcs_get_elem_count(kcdata_subtype_descriptor_t d)
358*2c2f96dcSApple OSS Distributions {
359*2c2f96dcSApple OSS Distributions if (d->kcs_flags & KCS_SUBTYPE_FLAGS_ARRAY) {
360*2c2f96dcSApple OSS Distributions return (d->kcs_elem_size >> 16) & 0xffff;
361*2c2f96dcSApple OSS Distributions }
362*2c2f96dcSApple OSS Distributions return 1;
363*2c2f96dcSApple OSS Distributions }
364*2c2f96dcSApple OSS Distributions
365*2c2f96dcSApple OSS Distributions static inline int
kcs_set_elem_size(kcdata_subtype_descriptor_t d,uint32_t size,uint32_t count)366*2c2f96dcSApple OSS Distributions kcs_set_elem_size(kcdata_subtype_descriptor_t d, uint32_t size, uint32_t count)
367*2c2f96dcSApple OSS Distributions {
368*2c2f96dcSApple OSS Distributions if (count > 1) {
369*2c2f96dcSApple OSS Distributions /* means we are setting up an array */
370*2c2f96dcSApple OSS Distributions if (size > 0xffff || count > 0xffff) {
371*2c2f96dcSApple OSS Distributions return -1; //invalid argument
372*2c2f96dcSApple OSS Distributions }
373*2c2f96dcSApple OSS Distributions d->kcs_elem_size = ((count & 0xffff) << 16 | (size & 0xffff));
374*2c2f96dcSApple OSS Distributions } else {
375*2c2f96dcSApple OSS Distributions d->kcs_elem_size = size;
376*2c2f96dcSApple OSS Distributions }
377*2c2f96dcSApple OSS Distributions return 0;
378*2c2f96dcSApple OSS Distributions }
379*2c2f96dcSApple OSS Distributions
380*2c2f96dcSApple OSS Distributions struct kcdata_type_definition {
381*2c2f96dcSApple OSS Distributions uint32_t kct_type_identifier;
382*2c2f96dcSApple OSS Distributions uint32_t kct_num_elements;
383*2c2f96dcSApple OSS Distributions char kct_name[KCDATA_DESC_MAXLEN];
384*2c2f96dcSApple OSS Distributions struct kcdata_subtype_descriptor kct_elements[];
385*2c2f96dcSApple OSS Distributions };
386*2c2f96dcSApple OSS Distributions
387*2c2f96dcSApple OSS Distributions
388*2c2f96dcSApple OSS Distributions /* chunk type definitions. 0 - 0x7ff are reserved and defined here
389*2c2f96dcSApple OSS Distributions * NOTE: Please update kcdata/libkdd/kcdtypes.c if you make any changes
390*2c2f96dcSApple OSS Distributions * in STACKSHOT_KCTYPE_* types.
391*2c2f96dcSApple OSS Distributions */
392*2c2f96dcSApple OSS Distributions
393*2c2f96dcSApple OSS Distributions /*
394*2c2f96dcSApple OSS Distributions * Types with description value.
395*2c2f96dcSApple OSS Distributions * these will have KCDATA_DESC_MAXLEN-1 length string description
396*2c2f96dcSApple OSS Distributions * and rest of kcdata_iter_size() - KCDATA_DESC_MAXLEN bytes as data
397*2c2f96dcSApple OSS Distributions */
398*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_INVALID 0x0u
399*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_STRING_DESC 0x1u
400*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_UINT32_DESC 0x2u
401*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_UINT64_DESC 0x3u
402*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_INT32_DESC 0x4u
403*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_INT64_DESC 0x5u
404*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_BINDATA_DESC 0x6u
405*2c2f96dcSApple OSS Distributions
406*2c2f96dcSApple OSS Distributions /*
407*2c2f96dcSApple OSS Distributions * Compound type definitions
408*2c2f96dcSApple OSS Distributions */
409*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_ARRAY 0x11u /* Array of data OBSOLETE DONT USE THIS*/
410*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_TYPEDEFINTION 0x12u /* Meta type that describes a type on the fly. */
411*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_CONTAINER_BEGIN \
412*2c2f96dcSApple OSS Distributions 0x13u /* Container type which has corresponding CONTAINER_END header. \
413*2c2f96dcSApple OSS Distributions * KCDATA_TYPE_CONTAINER_BEGIN has type in the data segment. \
414*2c2f96dcSApple OSS Distributions * Both headers have (uint64_t) ID for matching up nested data. \
415*2c2f96dcSApple OSS Distributions */
416*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_CONTAINER_END 0x14u
417*2c2f96dcSApple OSS Distributions
418*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_ARRAY_PAD0 0x20u /* Array of data with 0 byte of padding*/
419*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_ARRAY_PAD1 0x21u /* Array of data with 1 byte of padding*/
420*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_ARRAY_PAD2 0x22u /* Array of data with 2 byte of padding*/
421*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_ARRAY_PAD3 0x23u /* Array of data with 3 byte of padding*/
422*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_ARRAY_PAD4 0x24u /* Array of data with 4 byte of padding*/
423*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_ARRAY_PAD5 0x25u /* Array of data with 5 byte of padding*/
424*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_ARRAY_PAD6 0x26u /* Array of data with 6 byte of padding*/
425*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_ARRAY_PAD7 0x27u /* Array of data with 7 byte of padding*/
426*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_ARRAY_PAD8 0x28u /* Array of data with 8 byte of padding*/
427*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_ARRAY_PAD9 0x29u /* Array of data with 9 byte of padding*/
428*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_ARRAY_PADa 0x2au /* Array of data with a byte of padding*/
429*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_ARRAY_PADb 0x2bu /* Array of data with b byte of padding*/
430*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_ARRAY_PADc 0x2cu /* Array of data with c byte of padding*/
431*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_ARRAY_PADd 0x2du /* Array of data with d byte of padding*/
432*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_ARRAY_PADe 0x2eu /* Array of data with e byte of padding*/
433*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_ARRAY_PADf 0x2fu /* Array of data with f byte of padding*/
434*2c2f96dcSApple OSS Distributions
435*2c2f96dcSApple OSS Distributions /*
436*2c2f96dcSApple OSS Distributions * Generic data types that are most commonly used
437*2c2f96dcSApple OSS Distributions */
438*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_LIBRARY_LOADINFO 0x30u /* struct dyld_uuid_info_32 */
439*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_LIBRARY_LOADINFO64 0x31u /* struct dyld_uuid_info_64 */
440*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_TIMEBASE 0x32u /* struct mach_timebase_info */
441*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_MACH_ABSOLUTE_TIME 0x33u /* uint64_t */
442*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_TIMEVAL 0x34u /* struct timeval64 */
443*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_USECS_SINCE_EPOCH 0x35u /* time in usecs uint64_t */
444*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_PID 0x36u /* int32_t */
445*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_PROCNAME 0x37u /* char * */
446*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_NESTED_KCDATA 0x38u /* nested kcdata buffer */
447*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_LIBRARY_AOTINFO 0x39u /* struct user64_dyld_aot_info */
448*2c2f96dcSApple OSS Distributions
449*2c2f96dcSApple OSS Distributions #define KCDATA_TYPE_BUFFER_END 0xF19158EDu
450*2c2f96dcSApple OSS Distributions
451*2c2f96dcSApple OSS Distributions /* MAGIC numbers defined for each class of chunked data
452*2c2f96dcSApple OSS Distributions *
453*2c2f96dcSApple OSS Distributions * To future-proof against big-endian arches, make sure none of these magic
454*2c2f96dcSApple OSS Distributions * numbers are byteswaps of each other
455*2c2f96dcSApple OSS Distributions */
456*2c2f96dcSApple OSS Distributions
457*2c2f96dcSApple OSS Distributions #define KCDATA_BUFFER_BEGIN_CRASHINFO 0xDEADF157u /* owner: corpses/task_corpse.h */
458*2c2f96dcSApple OSS Distributions /* type-range: 0x800 - 0x8ff */
459*2c2f96dcSApple OSS Distributions #define KCDATA_BUFFER_BEGIN_STACKSHOT 0x59a25807u /* owner: sys/stackshot.h */
460*2c2f96dcSApple OSS Distributions /* type-range: 0x900 - 0x93f */
461*2c2f96dcSApple OSS Distributions #define KCDATA_BUFFER_BEGIN_COMPRESSED 0x434f4d50u /* owner: sys/stackshot.h */
462*2c2f96dcSApple OSS Distributions /* type-range: 0x900 - 0x93f */
463*2c2f96dcSApple OSS Distributions #define KCDATA_BUFFER_BEGIN_DELTA_STACKSHOT 0xDE17A59Au /* owner: sys/stackshot.h */
464*2c2f96dcSApple OSS Distributions /* type-range: 0x940 - 0x9ff */
465*2c2f96dcSApple OSS Distributions #define KCDATA_BUFFER_BEGIN_BTINFO 0x46414E47u /* owner: kern/kern_exit.c */
466*2c2f96dcSApple OSS Distributions /* type-range: 0xa01 - 0xaff */
467*2c2f96dcSApple OSS Distributions #define KCDATA_BUFFER_BEGIN_OS_REASON 0x53A20900u /* owner: sys/reason.h */
468*2c2f96dcSApple OSS Distributions /* type-range: 0x1000-0x103f */
469*2c2f96dcSApple OSS Distributions #define KCDATA_BUFFER_BEGIN_XNUPOST_CONFIG 0x1e21c09fu /* owner: osfmk/tests/kernel_tests.c */
470*2c2f96dcSApple OSS Distributions /* type-range: 0x1040-0x105f */
471*2c2f96dcSApple OSS Distributions
472*2c2f96dcSApple OSS Distributions /* next type range number available 0x1060 */
473*2c2f96dcSApple OSS Distributions /**************** definitions for XNUPOST *********************/
474*2c2f96dcSApple OSS Distributions #define XNUPOST_KCTYPE_TESTCONFIG 0x1040
475*2c2f96dcSApple OSS Distributions
476*2c2f96dcSApple OSS Distributions /**************** definitions for stackshot *********************/
477*2c2f96dcSApple OSS Distributions
478*2c2f96dcSApple OSS Distributions /* This value must always match IO_NUM_PRIORITIES defined in thread_info.h */
479*2c2f96dcSApple OSS Distributions #define STACKSHOT_IO_NUM_PRIORITIES 4
480*2c2f96dcSApple OSS Distributions /* This value must always match MAXTHREADNAMESIZE used in bsd */
481*2c2f96dcSApple OSS Distributions #define STACKSHOT_MAX_THREAD_NAME_SIZE 64
482*2c2f96dcSApple OSS Distributions
483*2c2f96dcSApple OSS Distributions /*
484*2c2f96dcSApple OSS Distributions * NOTE: Please update kcdata/libkdd/kcdtypes.c if you make any changes
485*2c2f96dcSApple OSS Distributions * in STACKSHOT_KCTYPE_* types.
486*2c2f96dcSApple OSS Distributions */
487*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_IOSTATS 0x901u /* io_stats_snapshot */
488*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_GLOBAL_MEM_STATS 0x902u /* struct mem_and_io_snapshot */
489*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCCONTAINER_TASK 0x903u
490*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCCONTAINER_THREAD 0x904u
491*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_TASK_SNAPSHOT 0x905u /* task_snapshot_v2 */
492*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_THREAD_SNAPSHOT 0x906u /* thread_snapshot_v2, thread_snapshot_v3 */
493*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_DONATING_PIDS 0x907u /* int[] */
494*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_SHAREDCACHE_LOADINFO 0x908u /* dyld_shared_cache_loadinfo */
495*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_THREAD_NAME 0x909u /* char[] */
496*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_KERN_STACKFRAME 0x90Au /* struct stack_snapshot_frame32 */
497*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_KERN_STACKFRAME64 0x90Bu /* struct stack_snapshot_frame64 */
498*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_USER_STACKFRAME 0x90Cu /* struct stack_snapshot_frame32 */
499*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_USER_STACKFRAME64 0x90Du /* struct stack_snapshot_frame64 */
500*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_BOOTARGS 0x90Eu /* boot args string */
501*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_OSVERSION 0x90Fu /* os version string */
502*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_KERN_PAGE_SIZE 0x910u /* kernel page size in uint32_t */
503*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_JETSAM_LEVEL 0x911u /* jetsam level in uint32_t */
504*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_DELTA_SINCE_TIMESTAMP 0x912u /* timestamp used for the delta stackshot */
505*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_KERN_STACKLR 0x913u /* uint32_t */
506*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_KERN_STACKLR64 0x914u /* uint64_t */
507*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_USER_STACKLR 0x915u /* uint32_t */
508*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_USER_STACKLR64 0x916u /* uint64_t */
509*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_NONRUNNABLE_TIDS 0x917u /* uint64_t */
510*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_NONRUNNABLE_TASKS 0x918u /* uint64_t */
511*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_CPU_TIMES 0x919u /* struct stackshot_cpu_times or stackshot_cpu_times_v2 */
512*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_STACKSHOT_DURATION 0x91au /* struct stackshot_duration */
513*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_STACKSHOT_FAULT_STATS 0x91bu /* struct stackshot_fault_stats */
514*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_KERNELCACHE_LOADINFO 0x91cu /* kernelcache UUID -- same as KCDATA_TYPE_LIBRARY_LOADINFO64 */
515*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_THREAD_WAITINFO 0x91du /* struct stackshot_thread_waitinfo */
516*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_THREAD_GROUP_SNAPSHOT 0x91eu /* struct thread_group_snapshot{,_v2,_v3} */
517*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_THREAD_GROUP 0x91fu /* uint64_t */
518*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_JETSAM_COALITION_SNAPSHOT 0x920u /* struct jetsam_coalition_snapshot */
519*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_JETSAM_COALITION 0x921u /* uint64_t */
520*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_THREAD_POLICY_VERSION 0x922u /* THREAD_POLICY_INTERNAL_STRUCT_VERSION in uint32 */
521*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_INSTRS_CYCLES 0x923u /* struct instrs_cycles_snapshot_v2 */
522*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_USER_STACKTOP 0x924u /* struct stack_snapshot_stacktop */
523*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_ASID 0x925u /* uint32_t */
524*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_PAGE_TABLES 0x926u /* uint64_t */
525*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_SYS_SHAREDCACHE_LAYOUT 0x927u /* same as KCDATA_TYPE_LIBRARY_LOADINFO64 */
526*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_THREAD_DISPATCH_QUEUE_LABEL 0x928u /* dispatch queue label */
527*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_THREAD_TURNSTILEINFO 0x929u /* struct stackshot_thread_turnstileinfo */
528*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_TASK_CPU_ARCHITECTURE 0x92au /* struct stackshot_cpu_architecture */
529*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_LATENCY_INFO 0x92bu /* struct stackshot_latency_collection */
530*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_LATENCY_INFO_TASK 0x92cu /* struct stackshot_latency_task */
531*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_LATENCY_INFO_THREAD 0x92du /* struct stackshot_latency_thread */
532*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_LOADINFO64_TEXT_EXEC 0x92eu /* TEXT_EXEC load info -- same as KCDATA_TYPE_LIBRARY_LOADINFO64 */
533*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_AOTCACHE_LOADINFO 0x92fu /* struct dyld_aot_cache_uuid_info */
534*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_TRANSITIONING_TASK_SNAPSHOT 0x930u /* transitioning_task_snapshot */
535*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCCONTAINER_TRANSITIONING_TASK 0x931u
536*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_USER_ASYNC_START_INDEX 0x932u /* uint32_t index in user_stack of beginning of async stack */
537*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_USER_ASYNC_STACKLR64 0x933u /* uint64_t async stack pointers */
538*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCCONTAINER_PORTLABEL 0x934u /* container for port label info */
539*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_PORTLABEL 0x935u /* struct stackshot_portlabel */
540*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_PORTLABEL_NAME 0x936u /* string port name */
541*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_DYLD_COMPACTINFO 0x937u /* binary blob of dyld info (variable size) */
542*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_SUSPENSION_INFO 0x938u /* struct stackshot_suspension_info */
543*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_SUSPENSION_SOURCE 0x939u /* struct stackshot_suspension_source */
544*2c2f96dcSApple OSS Distributions
545*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_TASK_DELTA_SNAPSHOT 0x940u /* task_delta_snapshot_v2 */
546*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_THREAD_DELTA_SNAPSHOT 0x941u /* thread_delta_snapshot_v* */
547*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCCONTAINER_SHAREDCACHE 0x942u /* container for shared cache info */
548*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_SHAREDCACHE_INFO 0x943u /* dyld_shared_cache_loadinfo_v2 */
549*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_SHAREDCACHE_AOTINFO 0x944u /* struct dyld_aot_cache_uuid_info */
550*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_SHAREDCACHE_ID 0x945u /* uint32_t in task: if we aren't attached to Primary, which one */
551*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_CODESIGNING_INFO 0x946u /* struct stackshot_task_codesigning_info */
552*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_KERN_EXCLAVES_THREADINFO 0x948u /* struct thread_exclaves_info */
553*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCCONTAINER_EXCLAVES 0x949u /* exclave threads info */
554*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCCONTAINER_EXCLAVE_SCRESULT 0x94au /* exclave thread container for one scid */
555*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_EXCLAVE_SCRESULT_INFO 0x94bu /* struct exclave_scresult_info */
556*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCCONTAINER_EXCLAVE_IPCSTACKENTRY 0x94cu /* container for one chunk of exclave IPC chain */
557*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_EXCLAVE_IPCSTACKENTRY_INFO 0x94du /* struct exclave_ipcstackentry_info */
558*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_EXCLAVE_IPCSTACKENTRY_ECSTACK 0x94eu /* exclave_ecstackentry_addr_t */
559*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCCONTAINER_EXCLAVE_ADDRESSSPACE 0x94fu /* exclave address space container */
560*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_EXCLAVE_ADDRESSSPACE_INFO 0x950u /* struct exclave_addressspace_info */
561*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_EXCLAVE_ADDRESSSPACE_NAME 0x951u /* exclave component name */
562*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCCONTAINER_EXCLAVE_TEXTLAYOUT 0x952u /* exclave text layout container */
563*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_EXCLAVE_TEXTLAYOUT_INFO 0x953u /* struct exclave_textlayout_info */
564*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_EXCLAVE_TEXTLAYOUT_SEGMENTS 0x954u /* struct exclave_textlayout_segment */
565*2c2f96dcSApple OSS Distributions #define STACKSHOT_KCTYPE_KERN_EXCLAVES_CRASH_THREADINFO 0x955u /* struct thread_crash_exclaves_info */
566*2c2f96dcSApple OSS Distributions
567*2c2f96dcSApple OSS Distributions struct stack_snapshot_frame32 {
568*2c2f96dcSApple OSS Distributions uint32_t lr;
569*2c2f96dcSApple OSS Distributions uint32_t sp;
570*2c2f96dcSApple OSS Distributions };
571*2c2f96dcSApple OSS Distributions
572*2c2f96dcSApple OSS Distributions struct stack_snapshot_frame64 {
573*2c2f96dcSApple OSS Distributions uint64_t lr;
574*2c2f96dcSApple OSS Distributions uint64_t sp;
575*2c2f96dcSApple OSS Distributions };
576*2c2f96dcSApple OSS Distributions
577*2c2f96dcSApple OSS Distributions struct dyld_uuid_info_32 {
578*2c2f96dcSApple OSS Distributions uint32_t imageLoadAddress; /* base address image is mapped at */
579*2c2f96dcSApple OSS Distributions uuid_t imageUUID;
580*2c2f96dcSApple OSS Distributions };
581*2c2f96dcSApple OSS Distributions
582*2c2f96dcSApple OSS Distributions struct dyld_uuid_info_64 {
583*2c2f96dcSApple OSS Distributions uint64_t imageLoadAddress; /* XXX image slide */
584*2c2f96dcSApple OSS Distributions uuid_t imageUUID;
585*2c2f96dcSApple OSS Distributions };
586*2c2f96dcSApple OSS Distributions
587*2c2f96dcSApple OSS Distributions /*
588*2c2f96dcSApple OSS Distributions * N.B.: Newer kernels output dyld_shared_cache_loadinfo structures
589*2c2f96dcSApple OSS Distributions * instead of this, since the field names match their contents better.
590*2c2f96dcSApple OSS Distributions */
591*2c2f96dcSApple OSS Distributions struct dyld_uuid_info_64_v2 {
592*2c2f96dcSApple OSS Distributions uint64_t imageLoadAddress; /* XXX image slide */
593*2c2f96dcSApple OSS Distributions uuid_t imageUUID;
594*2c2f96dcSApple OSS Distributions /* end of version 1 of dyld_uuid_info_64. sizeof v1 was 24 */
595*2c2f96dcSApple OSS Distributions uint64_t imageSlidBaseAddress; /* slid base address or slid first mapping of image */
596*2c2f96dcSApple OSS Distributions };
597*2c2f96dcSApple OSS Distributions
598*2c2f96dcSApple OSS Distributions enum dyld_shared_cache_flags {
599*2c2f96dcSApple OSS Distributions kSharedCacheSystemPrimary = 0x1, /* primary shared cache on the system; attached tasks will have kTaskSharedRegionSystem set */
600*2c2f96dcSApple OSS Distributions kSharedCacheDriverkit = 0x2, /* driverkit shared cache */
601*2c2f96dcSApple OSS Distributions kSharedCacheAOT = 0x4, /* Rosetta shared cache */
602*2c2f96dcSApple OSS Distributions };
603*2c2f96dcSApple OSS Distributions
604*2c2f96dcSApple OSS Distributions /*
605*2c2f96dcSApple OSS Distributions * This is the renamed version of dyld_uuid_info_64 with more accurate
606*2c2f96dcSApple OSS Distributions * field names, for STACKSHOT_KCTYPE_SHAREDCACHE_LOADINFO. Any users
607*2c2f96dcSApple OSS Distributions * must be aware of the dyld_uuid_info_64* version history and ensure
608*2c2f96dcSApple OSS Distributions * the fields they are accessing are within the actual bounds.
609*2c2f96dcSApple OSS Distributions *
610*2c2f96dcSApple OSS Distributions * OLD_FIELD NEW_FIELD
611*2c2f96dcSApple OSS Distributions * imageLoadAddress sharedCacheSlide
612*2c2f96dcSApple OSS Distributions * imageUUID sharedCacheUUID
613*2c2f96dcSApple OSS Distributions * imageSlidBaseAddress sharedCacheUnreliableSlidBaseAddress
614*2c2f96dcSApple OSS Distributions * - sharedCacheSlidFirstMapping
615*2c2f96dcSApple OSS Distributions * - sharedCacheID
616*2c2f96dcSApple OSS Distributions * - sharedCacheFlags
617*2c2f96dcSApple OSS Distributions */
618*2c2f96dcSApple OSS Distributions struct dyld_shared_cache_loadinfo_v2 {
619*2c2f96dcSApple OSS Distributions uint64_t sharedCacheSlide; /* image slide value */
620*2c2f96dcSApple OSS Distributions uuid_t sharedCacheUUID;
621*2c2f96dcSApple OSS Distributions /* end of version 1 of dyld_uuid_info_64. sizeof v1 was 24 */
622*2c2f96dcSApple OSS Distributions uint64_t sharedCacheUnreliableSlidBaseAddress; /* for backwards-compatibility; use sharedCacheSlidFirstMapping if available */
623*2c2f96dcSApple OSS Distributions /* end of version 2 of dyld_uuid_info_64. sizeof v2 was 32 */
624*2c2f96dcSApple OSS Distributions uint64_t sharedCacheSlidFirstMapping; /* slid base address of first mapping */
625*2c2f96dcSApple OSS Distributions /* end of version 1 of dyld_shared_cache_loadinfo. sizeof was 40 */
626*2c2f96dcSApple OSS Distributions uint32_t sharedCacheID; /* ID of shared cache */
627*2c2f96dcSApple OSS Distributions uint32_t sharedCacheFlags;
628*2c2f96dcSApple OSS Distributions };
629*2c2f96dcSApple OSS Distributions
630*2c2f96dcSApple OSS Distributions struct dyld_shared_cache_loadinfo {
631*2c2f96dcSApple OSS Distributions uint64_t sharedCacheSlide; /* image slide value */
632*2c2f96dcSApple OSS Distributions uuid_t sharedCacheUUID;
633*2c2f96dcSApple OSS Distributions /* end of version 1 of dyld_uuid_info_64. sizeof v1 was 24 */
634*2c2f96dcSApple OSS Distributions uint64_t sharedCacheUnreliableSlidBaseAddress; /* for backwards-compatibility; use sharedCacheSlidFirstMapping if available */
635*2c2f96dcSApple OSS Distributions /* end of version 2 of dyld_uuid_info_64. sizeof v2 was 32 */
636*2c2f96dcSApple OSS Distributions uint64_t sharedCacheSlidFirstMapping; /* slid base address of first mapping */
637*2c2f96dcSApple OSS Distributions };
638*2c2f96dcSApple OSS Distributions
639*2c2f96dcSApple OSS Distributions struct dyld_aot_cache_uuid_info {
640*2c2f96dcSApple OSS Distributions uint64_t x86SlidBaseAddress; /* slid first mapping address of x86 shared cache */
641*2c2f96dcSApple OSS Distributions uuid_t x86UUID; /* UUID of x86 shared cache */
642*2c2f96dcSApple OSS Distributions uint64_t aotSlidBaseAddress; /* slide first mapping address of aot cache */
643*2c2f96dcSApple OSS Distributions uuid_t aotUUID; /* UUID of aot shared cache */
644*2c2f96dcSApple OSS Distributions };
645*2c2f96dcSApple OSS Distributions
646*2c2f96dcSApple OSS Distributions struct user32_dyld_uuid_info {
647*2c2f96dcSApple OSS Distributions uint32_t imageLoadAddress; /* base address image is mapped into */
648*2c2f96dcSApple OSS Distributions uuid_t imageUUID; /* UUID of image */
649*2c2f96dcSApple OSS Distributions };
650*2c2f96dcSApple OSS Distributions
651*2c2f96dcSApple OSS Distributions struct user64_dyld_uuid_info {
652*2c2f96dcSApple OSS Distributions uint64_t imageLoadAddress; /* base address image is mapped into */
653*2c2f96dcSApple OSS Distributions uuid_t imageUUID; /* UUID of image */
654*2c2f96dcSApple OSS Distributions };
655*2c2f96dcSApple OSS Distributions
656*2c2f96dcSApple OSS Distributions #define DYLD_AOT_IMAGE_KEY_SIZE 32
657*2c2f96dcSApple OSS Distributions
658*2c2f96dcSApple OSS Distributions struct user64_dyld_aot_info {
659*2c2f96dcSApple OSS Distributions uint64_t x86LoadAddress;
660*2c2f96dcSApple OSS Distributions uint64_t aotLoadAddress;
661*2c2f96dcSApple OSS Distributions uint64_t aotImageSize;
662*2c2f96dcSApple OSS Distributions uint8_t aotImageKey[DYLD_AOT_IMAGE_KEY_SIZE];
663*2c2f96dcSApple OSS Distributions };
664*2c2f96dcSApple OSS Distributions
665*2c2f96dcSApple OSS Distributions enum task_snapshot_flags {
666*2c2f96dcSApple OSS Distributions /* k{User,Kernel}64_p (values 0x1 and 0x2) are defined in generic_snapshot_flags */
667*2c2f96dcSApple OSS Distributions kTaskRsrcFlagged = 0x4, // In the EXC_RESOURCE danger zone?
668*2c2f96dcSApple OSS Distributions kTerminatedSnapshot = 0x8,
669*2c2f96dcSApple OSS Distributions kPidSuspended = 0x10, // true for suspended task
670*2c2f96dcSApple OSS Distributions kFrozen = 0x20, // true for hibernated task (along with pidsuspended)
671*2c2f96dcSApple OSS Distributions kTaskDarwinBG = 0x40,
672*2c2f96dcSApple OSS Distributions kTaskExtDarwinBG = 0x80,
673*2c2f96dcSApple OSS Distributions kTaskVisVisible = 0x100,
674*2c2f96dcSApple OSS Distributions kTaskVisNonvisible = 0x200,
675*2c2f96dcSApple OSS Distributions kTaskIsForeground = 0x400,
676*2c2f96dcSApple OSS Distributions kTaskIsBoosted = 0x800,
677*2c2f96dcSApple OSS Distributions kTaskIsSuppressed = 0x1000,
678*2c2f96dcSApple OSS Distributions kTaskIsTimerThrottled = 0x2000, /* deprecated */
679*2c2f96dcSApple OSS Distributions kTaskIsImpDonor = 0x4000,
680*2c2f96dcSApple OSS Distributions kTaskIsLiveImpDonor = 0x8000,
681*2c2f96dcSApple OSS Distributions kTaskIsDirty = 0x10000,
682*2c2f96dcSApple OSS Distributions kTaskWqExceededConstrainedThreadLimit = 0x20000,
683*2c2f96dcSApple OSS Distributions kTaskWqExceededTotalThreadLimit = 0x40000,
684*2c2f96dcSApple OSS Distributions kTaskWqFlagsAvailable = 0x80000,
685*2c2f96dcSApple OSS Distributions kTaskUUIDInfoFaultedIn = 0x100000, /* successfully faulted in some UUID info */
686*2c2f96dcSApple OSS Distributions kTaskUUIDInfoMissing = 0x200000, /* some UUID info was paged out */
687*2c2f96dcSApple OSS Distributions kTaskUUIDInfoTriedFault = 0x400000, /* tried to fault in UUID info */
688*2c2f96dcSApple OSS Distributions kTaskSharedRegionInfoUnavailable = 0x800000, /* shared region info unavailable */
689*2c2f96dcSApple OSS Distributions kTaskTALEngaged = 0x1000000,
690*2c2f96dcSApple OSS Distributions /* 0x2000000 unused */
691*2c2f96dcSApple OSS Distributions kTaskIsDirtyTracked = 0x4000000,
692*2c2f96dcSApple OSS Distributions kTaskAllowIdleExit = 0x8000000,
693*2c2f96dcSApple OSS Distributions kTaskIsTranslated = 0x10000000,
694*2c2f96dcSApple OSS Distributions kTaskSharedRegionNone = 0x20000000, /* task doesn't have a shared region */
695*2c2f96dcSApple OSS Distributions kTaskSharedRegionSystem = 0x40000000, /* task attached to region with kSharedCacheSystemPrimary set */
696*2c2f96dcSApple OSS Distributions kTaskSharedRegionOther = 0x80000000, /* task is attached to a different shared region */
697*2c2f96dcSApple OSS Distributions kTaskDyldCompactInfoNone = 0x100000000,
698*2c2f96dcSApple OSS Distributions kTaskDyldCompactInfoTooBig = 0x200000000,
699*2c2f96dcSApple OSS Distributions kTaskDyldCompactInfoFaultedIn = 0x400000000,
700*2c2f96dcSApple OSS Distributions kTaskDyldCompactInfoMissing = 0x800000000,
701*2c2f96dcSApple OSS Distributions kTaskDyldCompactInfoTriedFault = 0x1000000000,
702*2c2f96dcSApple OSS Distributions }; // Note: Add any new flags to kcdata.py (ts_ss_flags)
703*2c2f96dcSApple OSS Distributions
704*2c2f96dcSApple OSS Distributions enum task_transition_type {
705*2c2f96dcSApple OSS Distributions kTaskIsTerminated = 0x1,// Past LPEXIT
706*2c2f96dcSApple OSS Distributions };
707*2c2f96dcSApple OSS Distributions
708*2c2f96dcSApple OSS Distributions enum thread_snapshot_flags {
709*2c2f96dcSApple OSS Distributions /* k{User,Kernel}64_p (values 0x1 and 0x2) are defined in generic_snapshot_flags */
710*2c2f96dcSApple OSS Distributions kHasDispatchSerial = 0x4,
711*2c2f96dcSApple OSS Distributions kStacksPCOnly = 0x8, /* Stack traces have no frame pointers. */
712*2c2f96dcSApple OSS Distributions kThreadDarwinBG = 0x10, /* Thread is darwinbg */
713*2c2f96dcSApple OSS Distributions kThreadIOPassive = 0x20, /* Thread uses passive IO */
714*2c2f96dcSApple OSS Distributions kThreadSuspended = 0x40, /* Thread is suspended */
715*2c2f96dcSApple OSS Distributions kThreadTruncatedBT = 0x80, /* Unmapped pages caused truncated backtrace */
716*2c2f96dcSApple OSS Distributions kGlobalForcedIdle = 0x100, /* Thread performs global forced idle */
717*2c2f96dcSApple OSS Distributions kThreadFaultedBT = 0x200, /* Some thread stack pages were faulted in as part of BT */
718*2c2f96dcSApple OSS Distributions kThreadTriedFaultBT = 0x400, /* We tried to fault in thread stack pages as part of BT */
719*2c2f96dcSApple OSS Distributions kThreadOnCore = 0x800, /* Thread was on-core when we entered debugger context */
720*2c2f96dcSApple OSS Distributions kThreadIdleWorker = 0x1000, /* Thread is an idle libpthread worker thread */
721*2c2f96dcSApple OSS Distributions kThreadMain = 0x2000, /* Thread is the main thread */
722*2c2f96dcSApple OSS Distributions kThreadTruncKernBT = 0x4000, /* Unmapped pages caused truncated kernel BT */
723*2c2f96dcSApple OSS Distributions kThreadTruncUserBT = 0x8000, /* Unmapped pages caused truncated user BT */
724*2c2f96dcSApple OSS Distributions kThreadTruncUserAsyncBT = 0x10000, /* Unmapped pages caused truncated user async BT */
725*2c2f96dcSApple OSS Distributions }; // Note: Add any new flags to kcdata.py (ths_ss_flags)
726*2c2f96dcSApple OSS Distributions
727*2c2f96dcSApple OSS Distributions struct mem_and_io_snapshot {
728*2c2f96dcSApple OSS Distributions uint32_t snapshot_magic;
729*2c2f96dcSApple OSS Distributions uint32_t free_pages;
730*2c2f96dcSApple OSS Distributions uint32_t active_pages;
731*2c2f96dcSApple OSS Distributions uint32_t inactive_pages;
732*2c2f96dcSApple OSS Distributions uint32_t purgeable_pages;
733*2c2f96dcSApple OSS Distributions uint32_t wired_pages;
734*2c2f96dcSApple OSS Distributions uint32_t speculative_pages;
735*2c2f96dcSApple OSS Distributions uint32_t throttled_pages;
736*2c2f96dcSApple OSS Distributions uint32_t filebacked_pages;
737*2c2f96dcSApple OSS Distributions uint32_t compressions;
738*2c2f96dcSApple OSS Distributions uint32_t decompressions;
739*2c2f96dcSApple OSS Distributions uint32_t compressor_size;
740*2c2f96dcSApple OSS Distributions int32_t busy_buffer_count;
741*2c2f96dcSApple OSS Distributions uint32_t pages_wanted;
742*2c2f96dcSApple OSS Distributions uint32_t pages_reclaimed;
743*2c2f96dcSApple OSS Distributions uint8_t pages_wanted_reclaimed_valid; // did mach_vm_pressure_monitor succeed?
744*2c2f96dcSApple OSS Distributions } __attribute__((packed));
745*2c2f96dcSApple OSS Distributions
746*2c2f96dcSApple OSS Distributions /* SS_TH_* macros are for ths_state */
747*2c2f96dcSApple OSS Distributions #define SS_TH_WAIT 0x01 /* queued for waiting */
748*2c2f96dcSApple OSS Distributions #define SS_TH_SUSP 0x02 /* stopped or requested to stop */
749*2c2f96dcSApple OSS Distributions #define SS_TH_RUN 0x04 /* running or on runq */
750*2c2f96dcSApple OSS Distributions #define SS_TH_UNINT 0x08 /* waiting uninteruptibly */
751*2c2f96dcSApple OSS Distributions #define SS_TH_TERMINATE 0x10 /* halted at termination */
752*2c2f96dcSApple OSS Distributions #define SS_TH_TERMINATE2 0x20 /* added to termination queue */
753*2c2f96dcSApple OSS Distributions #define SS_TH_IDLE 0x80 /* idling processor */
754*2c2f96dcSApple OSS Distributions
755*2c2f96dcSApple OSS Distributions struct thread_snapshot_v2 {
756*2c2f96dcSApple OSS Distributions uint64_t ths_thread_id;
757*2c2f96dcSApple OSS Distributions uint64_t ths_wait_event;
758*2c2f96dcSApple OSS Distributions uint64_t ths_continuation;
759*2c2f96dcSApple OSS Distributions uint64_t ths_total_syscalls;
760*2c2f96dcSApple OSS Distributions uint64_t ths_voucher_identifier;
761*2c2f96dcSApple OSS Distributions uint64_t ths_dqserialnum;
762*2c2f96dcSApple OSS Distributions uint64_t ths_user_time;
763*2c2f96dcSApple OSS Distributions uint64_t ths_sys_time;
764*2c2f96dcSApple OSS Distributions uint64_t ths_ss_flags;
765*2c2f96dcSApple OSS Distributions uint64_t ths_last_run_time;
766*2c2f96dcSApple OSS Distributions uint64_t ths_last_made_runnable_time;
767*2c2f96dcSApple OSS Distributions uint32_t ths_state;
768*2c2f96dcSApple OSS Distributions uint32_t ths_sched_flags;
769*2c2f96dcSApple OSS Distributions int16_t ths_base_priority;
770*2c2f96dcSApple OSS Distributions int16_t ths_sched_priority;
771*2c2f96dcSApple OSS Distributions uint8_t ths_eqos;
772*2c2f96dcSApple OSS Distributions uint8_t ths_rqos;
773*2c2f96dcSApple OSS Distributions uint8_t ths_rqos_override;
774*2c2f96dcSApple OSS Distributions uint8_t ths_io_tier;
775*2c2f96dcSApple OSS Distributions } __attribute__((packed));
776*2c2f96dcSApple OSS Distributions
777*2c2f96dcSApple OSS Distributions struct thread_snapshot_v3 {
778*2c2f96dcSApple OSS Distributions uint64_t ths_thread_id;
779*2c2f96dcSApple OSS Distributions uint64_t ths_wait_event;
780*2c2f96dcSApple OSS Distributions uint64_t ths_continuation;
781*2c2f96dcSApple OSS Distributions uint64_t ths_total_syscalls;
782*2c2f96dcSApple OSS Distributions uint64_t ths_voucher_identifier;
783*2c2f96dcSApple OSS Distributions uint64_t ths_dqserialnum;
784*2c2f96dcSApple OSS Distributions uint64_t ths_user_time;
785*2c2f96dcSApple OSS Distributions uint64_t ths_sys_time;
786*2c2f96dcSApple OSS Distributions uint64_t ths_ss_flags;
787*2c2f96dcSApple OSS Distributions uint64_t ths_last_run_time;
788*2c2f96dcSApple OSS Distributions uint64_t ths_last_made_runnable_time;
789*2c2f96dcSApple OSS Distributions uint32_t ths_state;
790*2c2f96dcSApple OSS Distributions uint32_t ths_sched_flags;
791*2c2f96dcSApple OSS Distributions int16_t ths_base_priority;
792*2c2f96dcSApple OSS Distributions int16_t ths_sched_priority;
793*2c2f96dcSApple OSS Distributions uint8_t ths_eqos;
794*2c2f96dcSApple OSS Distributions uint8_t ths_rqos;
795*2c2f96dcSApple OSS Distributions uint8_t ths_rqos_override;
796*2c2f96dcSApple OSS Distributions uint8_t ths_io_tier;
797*2c2f96dcSApple OSS Distributions uint64_t ths_thread_t;
798*2c2f96dcSApple OSS Distributions } __attribute__((packed));
799*2c2f96dcSApple OSS Distributions
800*2c2f96dcSApple OSS Distributions
801*2c2f96dcSApple OSS Distributions struct thread_snapshot_v4 {
802*2c2f96dcSApple OSS Distributions uint64_t ths_thread_id;
803*2c2f96dcSApple OSS Distributions uint64_t ths_wait_event;
804*2c2f96dcSApple OSS Distributions uint64_t ths_continuation;
805*2c2f96dcSApple OSS Distributions uint64_t ths_total_syscalls;
806*2c2f96dcSApple OSS Distributions uint64_t ths_voucher_identifier;
807*2c2f96dcSApple OSS Distributions uint64_t ths_dqserialnum;
808*2c2f96dcSApple OSS Distributions uint64_t ths_user_time;
809*2c2f96dcSApple OSS Distributions uint64_t ths_sys_time;
810*2c2f96dcSApple OSS Distributions uint64_t ths_ss_flags;
811*2c2f96dcSApple OSS Distributions uint64_t ths_last_run_time;
812*2c2f96dcSApple OSS Distributions uint64_t ths_last_made_runnable_time;
813*2c2f96dcSApple OSS Distributions uint32_t ths_state;
814*2c2f96dcSApple OSS Distributions uint32_t ths_sched_flags;
815*2c2f96dcSApple OSS Distributions int16_t ths_base_priority;
816*2c2f96dcSApple OSS Distributions int16_t ths_sched_priority;
817*2c2f96dcSApple OSS Distributions uint8_t ths_eqos;
818*2c2f96dcSApple OSS Distributions uint8_t ths_rqos;
819*2c2f96dcSApple OSS Distributions uint8_t ths_rqos_override;
820*2c2f96dcSApple OSS Distributions uint8_t ths_io_tier;
821*2c2f96dcSApple OSS Distributions uint64_t ths_thread_t;
822*2c2f96dcSApple OSS Distributions uint64_t ths_requested_policy;
823*2c2f96dcSApple OSS Distributions uint64_t ths_effective_policy;
824*2c2f96dcSApple OSS Distributions } __attribute__((packed));
825*2c2f96dcSApple OSS Distributions
826*2c2f96dcSApple OSS Distributions
827*2c2f96dcSApple OSS Distributions struct thread_group_snapshot {
828*2c2f96dcSApple OSS Distributions uint64_t tgs_id;
829*2c2f96dcSApple OSS Distributions char tgs_name[16];
830*2c2f96dcSApple OSS Distributions } __attribute__((packed));
831*2c2f96dcSApple OSS Distributions
832*2c2f96dcSApple OSS Distributions /*
833*2c2f96dcSApple OSS Distributions * In general these flags mirror their THREAD_GROUP_FLAGS_ counterparts.
834*2c2f96dcSApple OSS Distributions * THREAD_GROUP_FLAGS_UI_APP was repurposed and THREAD_GROUP_FLAGS_APPLICATION
835*2c2f96dcSApple OSS Distributions * introduced to take its place. To remain compatible, kThreadGroupUIApp is
836*2c2f96dcSApple OSS Distributions * kept around and kThreadGroupUIApplication introduced.
837*2c2f96dcSApple OSS Distributions */
838*2c2f96dcSApple OSS Distributions enum thread_group_flags {
839*2c2f96dcSApple OSS Distributions kThreadGroupEfficient = 0x1,
840*2c2f96dcSApple OSS Distributions kThreadGroupApplication = 0x2,
841*2c2f96dcSApple OSS Distributions kThreadGroupUIApp = 0x2,
842*2c2f96dcSApple OSS Distributions kThreadGroupCritical = 0x4,
843*2c2f96dcSApple OSS Distributions kThreadGroupBestEffort = 0x8,
844*2c2f96dcSApple OSS Distributions kThreadGroupUIApplication = 0x100,
845*2c2f96dcSApple OSS Distributions kThreadGroupManaged = 0x200,
846*2c2f96dcSApple OSS Distributions kThreadGroupStrictTimers = 0x400,
847*2c2f96dcSApple OSS Distributions }; // Note: Add any new flags to kcdata.py (tgs_flags)
848*2c2f96dcSApple OSS Distributions
849*2c2f96dcSApple OSS Distributions struct thread_group_snapshot_v2 {
850*2c2f96dcSApple OSS Distributions uint64_t tgs_id;
851*2c2f96dcSApple OSS Distributions char tgs_name[16];
852*2c2f96dcSApple OSS Distributions uint64_t tgs_flags;
853*2c2f96dcSApple OSS Distributions } __attribute__((packed));
854*2c2f96dcSApple OSS Distributions
855*2c2f96dcSApple OSS Distributions struct thread_group_snapshot_v3 {
856*2c2f96dcSApple OSS Distributions uint64_t tgs_id;
857*2c2f96dcSApple OSS Distributions char tgs_name[16];
858*2c2f96dcSApple OSS Distributions uint64_t tgs_flags;
859*2c2f96dcSApple OSS Distributions char tgs_name_cont[16];
860*2c2f96dcSApple OSS Distributions } __attribute__((packed));
861*2c2f96dcSApple OSS Distributions
862*2c2f96dcSApple OSS Distributions enum coalition_flags {
863*2c2f96dcSApple OSS Distributions kCoalitionTermRequested = 0x1,
864*2c2f96dcSApple OSS Distributions kCoalitionTerminated = 0x2,
865*2c2f96dcSApple OSS Distributions kCoalitionReaped = 0x4,
866*2c2f96dcSApple OSS Distributions kCoalitionPrivileged = 0x8,
867*2c2f96dcSApple OSS Distributions }; // Note: Add any new flags to kcdata.py (jcs_flags)
868*2c2f96dcSApple OSS Distributions
869*2c2f96dcSApple OSS Distributions struct jetsam_coalition_snapshot {
870*2c2f96dcSApple OSS Distributions uint64_t jcs_id;
871*2c2f96dcSApple OSS Distributions uint64_t jcs_flags;
872*2c2f96dcSApple OSS Distributions uint64_t jcs_thread_group;
873*2c2f96dcSApple OSS Distributions uint64_t jcs_leader_task_uniqueid;
874*2c2f96dcSApple OSS Distributions } __attribute__((packed));
875*2c2f96dcSApple OSS Distributions
876*2c2f96dcSApple OSS Distributions struct instrs_cycles_snapshot {
877*2c2f96dcSApple OSS Distributions uint64_t ics_instructions;
878*2c2f96dcSApple OSS Distributions uint64_t ics_cycles;
879*2c2f96dcSApple OSS Distributions } __attribute__((packed));
880*2c2f96dcSApple OSS Distributions
881*2c2f96dcSApple OSS Distributions struct instrs_cycles_snapshot_v2 {
882*2c2f96dcSApple OSS Distributions uint64_t ics_instructions;
883*2c2f96dcSApple OSS Distributions uint64_t ics_cycles;
884*2c2f96dcSApple OSS Distributions uint64_t ics_p_instructions;
885*2c2f96dcSApple OSS Distributions uint64_t ics_p_cycles;
886*2c2f96dcSApple OSS Distributions } __attribute__((packed));
887*2c2f96dcSApple OSS Distributions
888*2c2f96dcSApple OSS Distributions struct thread_delta_snapshot_v2 {
889*2c2f96dcSApple OSS Distributions uint64_t tds_thread_id;
890*2c2f96dcSApple OSS Distributions uint64_t tds_voucher_identifier;
891*2c2f96dcSApple OSS Distributions uint64_t tds_ss_flags;
892*2c2f96dcSApple OSS Distributions uint64_t tds_last_made_runnable_time;
893*2c2f96dcSApple OSS Distributions uint32_t tds_state;
894*2c2f96dcSApple OSS Distributions uint32_t tds_sched_flags;
895*2c2f96dcSApple OSS Distributions int16_t tds_base_priority;
896*2c2f96dcSApple OSS Distributions int16_t tds_sched_priority;
897*2c2f96dcSApple OSS Distributions uint8_t tds_eqos;
898*2c2f96dcSApple OSS Distributions uint8_t tds_rqos;
899*2c2f96dcSApple OSS Distributions uint8_t tds_rqos_override;
900*2c2f96dcSApple OSS Distributions uint8_t tds_io_tier;
901*2c2f96dcSApple OSS Distributions } __attribute__ ((packed));
902*2c2f96dcSApple OSS Distributions
903*2c2f96dcSApple OSS Distributions struct thread_delta_snapshot_v3 {
904*2c2f96dcSApple OSS Distributions uint64_t tds_thread_id;
905*2c2f96dcSApple OSS Distributions uint64_t tds_voucher_identifier;
906*2c2f96dcSApple OSS Distributions uint64_t tds_ss_flags;
907*2c2f96dcSApple OSS Distributions uint64_t tds_last_made_runnable_time;
908*2c2f96dcSApple OSS Distributions uint32_t tds_state;
909*2c2f96dcSApple OSS Distributions uint32_t tds_sched_flags;
910*2c2f96dcSApple OSS Distributions int16_t tds_base_priority;
911*2c2f96dcSApple OSS Distributions int16_t tds_sched_priority;
912*2c2f96dcSApple OSS Distributions uint8_t tds_eqos;
913*2c2f96dcSApple OSS Distributions uint8_t tds_rqos;
914*2c2f96dcSApple OSS Distributions uint8_t tds_rqos_override;
915*2c2f96dcSApple OSS Distributions uint8_t tds_io_tier;
916*2c2f96dcSApple OSS Distributions uint64_t tds_requested_policy;
917*2c2f96dcSApple OSS Distributions uint64_t tds_effective_policy;
918*2c2f96dcSApple OSS Distributions } __attribute__ ((packed));
919*2c2f96dcSApple OSS Distributions
920*2c2f96dcSApple OSS Distributions struct io_stats_snapshot {
921*2c2f96dcSApple OSS Distributions /*
922*2c2f96dcSApple OSS Distributions * I/O Statistics
923*2c2f96dcSApple OSS Distributions * XXX: These fields must be together.
924*2c2f96dcSApple OSS Distributions */
925*2c2f96dcSApple OSS Distributions uint64_t ss_disk_reads_count;
926*2c2f96dcSApple OSS Distributions uint64_t ss_disk_reads_size;
927*2c2f96dcSApple OSS Distributions uint64_t ss_disk_writes_count;
928*2c2f96dcSApple OSS Distributions uint64_t ss_disk_writes_size;
929*2c2f96dcSApple OSS Distributions uint64_t ss_io_priority_count[STACKSHOT_IO_NUM_PRIORITIES];
930*2c2f96dcSApple OSS Distributions uint64_t ss_io_priority_size[STACKSHOT_IO_NUM_PRIORITIES];
931*2c2f96dcSApple OSS Distributions uint64_t ss_paging_count;
932*2c2f96dcSApple OSS Distributions uint64_t ss_paging_size;
933*2c2f96dcSApple OSS Distributions uint64_t ss_non_paging_count;
934*2c2f96dcSApple OSS Distributions uint64_t ss_non_paging_size;
935*2c2f96dcSApple OSS Distributions uint64_t ss_data_count;
936*2c2f96dcSApple OSS Distributions uint64_t ss_data_size;
937*2c2f96dcSApple OSS Distributions uint64_t ss_metadata_count;
938*2c2f96dcSApple OSS Distributions uint64_t ss_metadata_size;
939*2c2f96dcSApple OSS Distributions /* XXX: I/O Statistics end */
940*2c2f96dcSApple OSS Distributions } __attribute__ ((packed));
941*2c2f96dcSApple OSS Distributions
942*2c2f96dcSApple OSS Distributions struct task_snapshot_v2 {
943*2c2f96dcSApple OSS Distributions uint64_t ts_unique_pid;
944*2c2f96dcSApple OSS Distributions uint64_t ts_ss_flags;
945*2c2f96dcSApple OSS Distributions uint64_t ts_user_time_in_terminated_threads;
946*2c2f96dcSApple OSS Distributions uint64_t ts_system_time_in_terminated_threads;
947*2c2f96dcSApple OSS Distributions uint64_t ts_p_start_sec;
948*2c2f96dcSApple OSS Distributions uint64_t ts_task_size;
949*2c2f96dcSApple OSS Distributions uint64_t ts_max_resident_size;
950*2c2f96dcSApple OSS Distributions uint32_t ts_suspend_count;
951*2c2f96dcSApple OSS Distributions uint32_t ts_faults;
952*2c2f96dcSApple OSS Distributions uint32_t ts_pageins;
953*2c2f96dcSApple OSS Distributions uint32_t ts_cow_faults;
954*2c2f96dcSApple OSS Distributions uint32_t ts_was_throttled;
955*2c2f96dcSApple OSS Distributions uint32_t ts_did_throttle;
956*2c2f96dcSApple OSS Distributions uint32_t ts_latency_qos;
957*2c2f96dcSApple OSS Distributions int32_t ts_pid;
958*2c2f96dcSApple OSS Distributions char ts_p_comm[32];
959*2c2f96dcSApple OSS Distributions } __attribute__ ((packed));
960*2c2f96dcSApple OSS Distributions
961*2c2f96dcSApple OSS Distributions struct transitioning_task_snapshot {
962*2c2f96dcSApple OSS Distributions uint64_t tts_unique_pid;
963*2c2f96dcSApple OSS Distributions uint64_t tts_ss_flags;
964*2c2f96dcSApple OSS Distributions uint64_t tts_transition_type;
965*2c2f96dcSApple OSS Distributions int32_t tts_pid;
966*2c2f96dcSApple OSS Distributions char tts_p_comm[32];
967*2c2f96dcSApple OSS Distributions } __attribute__ ((packed));
968*2c2f96dcSApple OSS Distributions
969*2c2f96dcSApple OSS Distributions struct task_delta_snapshot_v2 {
970*2c2f96dcSApple OSS Distributions uint64_t tds_unique_pid;
971*2c2f96dcSApple OSS Distributions uint64_t tds_ss_flags;
972*2c2f96dcSApple OSS Distributions uint64_t tds_user_time_in_terminated_threads;
973*2c2f96dcSApple OSS Distributions uint64_t tds_system_time_in_terminated_threads;
974*2c2f96dcSApple OSS Distributions uint64_t tds_task_size;
975*2c2f96dcSApple OSS Distributions uint64_t tds_max_resident_size;
976*2c2f96dcSApple OSS Distributions uint32_t tds_suspend_count;
977*2c2f96dcSApple OSS Distributions uint32_t tds_faults;
978*2c2f96dcSApple OSS Distributions uint32_t tds_pageins;
979*2c2f96dcSApple OSS Distributions uint32_t tds_cow_faults;
980*2c2f96dcSApple OSS Distributions uint32_t tds_was_throttled;
981*2c2f96dcSApple OSS Distributions uint32_t tds_did_throttle;
982*2c2f96dcSApple OSS Distributions uint32_t tds_latency_qos;
983*2c2f96dcSApple OSS Distributions } __attribute__ ((packed));
984*2c2f96dcSApple OSS Distributions
985*2c2f96dcSApple OSS Distributions #define KCDATA_INVALID_CS_TRUST_LEVEL 0xffffffff
986*2c2f96dcSApple OSS Distributions struct stackshot_task_codesigning_info {
987*2c2f96dcSApple OSS Distributions uint64_t csflags;
988*2c2f96dcSApple OSS Distributions uint32_t cs_trust_level;
989*2c2f96dcSApple OSS Distributions } __attribute__ ((packed));
990*2c2f96dcSApple OSS Distributions
991*2c2f96dcSApple OSS Distributions struct stackshot_cpu_times {
992*2c2f96dcSApple OSS Distributions uint64_t user_usec;
993*2c2f96dcSApple OSS Distributions uint64_t system_usec;
994*2c2f96dcSApple OSS Distributions } __attribute__((packed));
995*2c2f96dcSApple OSS Distributions
996*2c2f96dcSApple OSS Distributions struct stackshot_cpu_times_v2 {
997*2c2f96dcSApple OSS Distributions uint64_t user_usec;
998*2c2f96dcSApple OSS Distributions uint64_t system_usec;
999*2c2f96dcSApple OSS Distributions uint64_t runnable_usec;
1000*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1001*2c2f96dcSApple OSS Distributions
1002*2c2f96dcSApple OSS Distributions struct stackshot_duration {
1003*2c2f96dcSApple OSS Distributions uint64_t stackshot_duration;
1004*2c2f96dcSApple OSS Distributions uint64_t stackshot_duration_outer;
1005*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1006*2c2f96dcSApple OSS Distributions
1007*2c2f96dcSApple OSS Distributions struct stackshot_duration_v2 {
1008*2c2f96dcSApple OSS Distributions uint64_t stackshot_duration;
1009*2c2f96dcSApple OSS Distributions uint64_t stackshot_duration_outer;
1010*2c2f96dcSApple OSS Distributions uint64_t stackshot_duration_prior;
1011*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1012*2c2f96dcSApple OSS Distributions
1013*2c2f96dcSApple OSS Distributions struct stackshot_fault_stats {
1014*2c2f96dcSApple OSS Distributions uint32_t sfs_pages_faulted_in; /* number of pages faulted in using KDP fault path */
1015*2c2f96dcSApple OSS Distributions uint64_t sfs_time_spent_faulting; /* MATUs spent faulting */
1016*2c2f96dcSApple OSS Distributions uint64_t sfs_system_max_fault_time; /* MATUs fault time limit per stackshot */
1017*2c2f96dcSApple OSS Distributions uint8_t sfs_stopped_faulting; /* we stopped decompressing because we hit the limit */
1018*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1019*2c2f96dcSApple OSS Distributions
1020*2c2f96dcSApple OSS Distributions typedef struct stackshot_thread_waitinfo {
1021*2c2f96dcSApple OSS Distributions uint64_t owner; /* The thread that owns the object */
1022*2c2f96dcSApple OSS Distributions uint64_t waiter; /* The thread that's waiting on the object */
1023*2c2f96dcSApple OSS Distributions uint64_t context; /* A context uniquely identifying the object */
1024*2c2f96dcSApple OSS Distributions uint8_t wait_type; /* The type of object that the thread is waiting on */
1025*2c2f96dcSApple OSS Distributions } __attribute__((packed)) thread_waitinfo_t;
1026*2c2f96dcSApple OSS Distributions
1027*2c2f96dcSApple OSS Distributions typedef struct stackshot_thread_waitinfo_v2 {
1028*2c2f96dcSApple OSS Distributions uint64_t owner; /* The thread that owns the object */
1029*2c2f96dcSApple OSS Distributions uint64_t waiter; /* The thread that's waiting on the object */
1030*2c2f96dcSApple OSS Distributions uint64_t context; /* A context uniquely identifying the object */
1031*2c2f96dcSApple OSS Distributions uint8_t wait_type; /* The type of object that the thread is waiting on */
1032*2c2f96dcSApple OSS Distributions int16_t portlabel_id; /* matches to a stackshot_portlabel, or NONE or MISSING */
1033*2c2f96dcSApple OSS Distributions uint32_t wait_flags; /* info about the wait */
1034*2c2f96dcSApple OSS Distributions #define STACKSHOT_WAITINFO_FLAGS_SPECIALREPLY 0x1 /* We're waiting on a special reply port */
1035*2c2f96dcSApple OSS Distributions } __attribute__((packed)) thread_waitinfo_v2_t;
1036*2c2f96dcSApple OSS Distributions
1037*2c2f96dcSApple OSS Distributions
1038*2c2f96dcSApple OSS Distributions typedef struct stackshot_thread_turnstileinfo {
1039*2c2f96dcSApple OSS Distributions uint64_t waiter; /* The thread that's waiting on the object */
1040*2c2f96dcSApple OSS Distributions uint64_t turnstile_context; /* Associated data (either thread id, or workq addr) */
1041*2c2f96dcSApple OSS Distributions uint8_t turnstile_priority;
1042*2c2f96dcSApple OSS Distributions uint8_t number_of_hops;
1043*2c2f96dcSApple OSS Distributions uint64_t turnstile_flags; /* see below */
1044*2c2f96dcSApple OSS Distributions } __attribute__((packed)) thread_turnstileinfo_t;
1045*2c2f96dcSApple OSS Distributions
1046*2c2f96dcSApple OSS Distributions typedef struct stackshot_thread_turnstileinfo_v2 {
1047*2c2f96dcSApple OSS Distributions uint64_t waiter; /* The thread that's waiting on the object */
1048*2c2f96dcSApple OSS Distributions uint64_t turnstile_context; /* Associated data (either thread id, or workq addr) */
1049*2c2f96dcSApple OSS Distributions uint8_t turnstile_priority;
1050*2c2f96dcSApple OSS Distributions uint8_t number_of_hops;
1051*2c2f96dcSApple OSS Distributions #define STACKSHOT_TURNSTILE_STATUS_UNKNOWN 0x01 /* The final inheritor is unknown (bug?) */
1052*2c2f96dcSApple OSS Distributions #define STACKSHOT_TURNSTILE_STATUS_LOCKED_WAITQ 0x02 /* A waitq was found to be locked */
1053*2c2f96dcSApple OSS Distributions #define STACKSHOT_TURNSTILE_STATUS_WORKQUEUE 0x04 /* The final inheritor is a workqueue */
1054*2c2f96dcSApple OSS Distributions #define STACKSHOT_TURNSTILE_STATUS_THREAD 0x08 /* The final inheritor is a thread */
1055*2c2f96dcSApple OSS Distributions #define STACKSHOT_TURNSTILE_STATUS_BLOCKED_ON_TASK 0x10 /* blocked on task, dind't find thread */
1056*2c2f96dcSApple OSS Distributions #define STACKSHOT_TURNSTILE_STATUS_HELD_IPLOCK 0x20 /* the ip_lock was held */
1057*2c2f96dcSApple OSS Distributions #define STACKSHOT_TURNSTILE_STATUS_SENDPORT 0x40 /* port_labelid was from a send port */
1058*2c2f96dcSApple OSS Distributions #define STACKSHOT_TURNSTILE_STATUS_RECEIVEPORT 0x80 /* port_labelid was from a receive port */
1059*2c2f96dcSApple OSS Distributions uint64_t turnstile_flags; // Note: Add any new flags to kcdata.py (turnstile_flags)
1060*2c2f96dcSApple OSS Distributions int16_t portlabel_id; /* matches to a stackshot_portlabel, or NONE or MISSING */
1061*2c2f96dcSApple OSS Distributions } __attribute__((packed)) thread_turnstileinfo_v2_t;
1062*2c2f96dcSApple OSS Distributions
1063*2c2f96dcSApple OSS Distributions #define STACKSHOT_TURNSTILE_STATUS_PORTFLAGS (STACKSHOT_TURNSTILE_STATUS_SENDPORT | STACKSHOT_TURNSTILE_STATUS_RECEIVEPORT)
1064*2c2f96dcSApple OSS Distributions
1065*2c2f96dcSApple OSS Distributions #define STACKSHOT_PORTLABELID_NONE (0) /* No port label found */
1066*2c2f96dcSApple OSS Distributions #define STACKSHOT_PORTLABELID_MISSING (-1) /* portlabel found, but stackshot ran out of space to track it */
1067*2c2f96dcSApple OSS Distributions
1068*2c2f96dcSApple OSS Distributions #define STACKSHOT_WAITOWNER_KERNEL (UINT64_MAX - 1)
1069*2c2f96dcSApple OSS Distributions #define STACKSHOT_WAITOWNER_PORT_LOCKED (UINT64_MAX - 2)
1070*2c2f96dcSApple OSS Distributions #define STACKSHOT_WAITOWNER_PSET_LOCKED (UINT64_MAX - 3)
1071*2c2f96dcSApple OSS Distributions #define STACKSHOT_WAITOWNER_INTRANSIT (UINT64_MAX - 4)
1072*2c2f96dcSApple OSS Distributions #define STACKSHOT_WAITOWNER_MTXSPIN (UINT64_MAX - 5)
1073*2c2f96dcSApple OSS Distributions #define STACKSHOT_WAITOWNER_THREQUESTED (UINT64_MAX - 6) /* workloop waiting for a new worker thread */
1074*2c2f96dcSApple OSS Distributions #define STACKSHOT_WAITOWNER_SUSPENDED (UINT64_MAX - 7) /* workloop is suspended */
1075*2c2f96dcSApple OSS Distributions
1076*2c2f96dcSApple OSS Distributions #define STACKSHOT_PORTLABEL_READFAILED 0x1 /* could not read port information */
1077*2c2f96dcSApple OSS Distributions #define STACKSHOT_PORTLABEL_THROTTLED 0x2 /* service port is marked as throttled */
1078*2c2f96dcSApple OSS Distributions
1079*2c2f96dcSApple OSS Distributions struct portlabel_info {
1080*2c2f96dcSApple OSS Distributions int16_t portlabel_id; /* kcdata-specific ID for this port label */
1081*2c2f96dcSApple OSS Distributions uint16_t portlabel_flags; /* STACKSHOT_PORTLABEL_* */
1082*2c2f96dcSApple OSS Distributions uint8_t portlabel_domain; /* launchd domain */
1083*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1084*2c2f96dcSApple OSS Distributions
1085*2c2f96dcSApple OSS Distributions struct stackshot_cpu_architecture {
1086*2c2f96dcSApple OSS Distributions int32_t cputype;
1087*2c2f96dcSApple OSS Distributions int32_t cpusubtype;
1088*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1089*2c2f96dcSApple OSS Distributions
1090*2c2f96dcSApple OSS Distributions struct stack_snapshot_stacktop {
1091*2c2f96dcSApple OSS Distributions uint64_t sp;
1092*2c2f96dcSApple OSS Distributions uint8_t stack_contents[8];
1093*2c2f96dcSApple OSS Distributions };
1094*2c2f96dcSApple OSS Distributions
1095*2c2f96dcSApple OSS Distributions /* only collected if STACKSHOT_COLLECTS_LATENCY_INFO is set to !0 */
1096*2c2f96dcSApple OSS Distributions struct stackshot_latency_collection {
1097*2c2f96dcSApple OSS Distributions uint64_t latency_version;
1098*2c2f96dcSApple OSS Distributions uint64_t setup_latency;
1099*2c2f96dcSApple OSS Distributions uint64_t total_task_iteration_latency;
1100*2c2f96dcSApple OSS Distributions uint64_t total_terminated_task_iteration_latency;
1101*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1102*2c2f96dcSApple OSS Distributions
1103*2c2f96dcSApple OSS Distributions /* only collected if STACKSHOT_COLLECTS_LATENCY_INFO is set to !0 */
1104*2c2f96dcSApple OSS Distributions struct stackshot_latency_task {
1105*2c2f96dcSApple OSS Distributions uint64_t task_uniqueid;
1106*2c2f96dcSApple OSS Distributions uint64_t setup_latency;
1107*2c2f96dcSApple OSS Distributions uint64_t task_thread_count_loop_latency;
1108*2c2f96dcSApple OSS Distributions uint64_t task_thread_data_loop_latency;
1109*2c2f96dcSApple OSS Distributions uint64_t cur_tsnap_latency;
1110*2c2f96dcSApple OSS Distributions uint64_t pmap_latency;
1111*2c2f96dcSApple OSS Distributions uint64_t bsd_proc_ids_latency;
1112*2c2f96dcSApple OSS Distributions uint64_t misc_latency;
1113*2c2f96dcSApple OSS Distributions uint64_t misc2_latency;
1114*2c2f96dcSApple OSS Distributions uint64_t end_latency;
1115*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1116*2c2f96dcSApple OSS Distributions
1117*2c2f96dcSApple OSS Distributions /* only collected if STACKSHOT_COLLECTS_LATENCY_INFO is set to !0 */
1118*2c2f96dcSApple OSS Distributions struct stackshot_latency_thread {
1119*2c2f96dcSApple OSS Distributions uint64_t thread_id;
1120*2c2f96dcSApple OSS Distributions uint64_t cur_thsnap1_latency;
1121*2c2f96dcSApple OSS Distributions uint64_t dispatch_serial_latency;
1122*2c2f96dcSApple OSS Distributions uint64_t dispatch_label_latency;
1123*2c2f96dcSApple OSS Distributions uint64_t cur_thsnap2_latency;
1124*2c2f96dcSApple OSS Distributions uint64_t thread_name_latency;
1125*2c2f96dcSApple OSS Distributions uint64_t sur_times_latency;
1126*2c2f96dcSApple OSS Distributions uint64_t user_stack_latency;
1127*2c2f96dcSApple OSS Distributions uint64_t kernel_stack_latency;
1128*2c2f96dcSApple OSS Distributions uint64_t misc_latency;
1129*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1130*2c2f96dcSApple OSS Distributions
1131*2c2f96dcSApple OSS Distributions struct stackshot_suspension_info {
1132*2c2f96dcSApple OSS Distributions uint64_t tss_last_start; /* mach_absolute_time of beginning of last suspension*/
1133*2c2f96dcSApple OSS Distributions uint64_t tss_last_end; /* mach_absolute_time of end of last suspension */
1134*2c2f96dcSApple OSS Distributions uint64_t tss_count; /* number of times this task has been suspended */
1135*2c2f96dcSApple OSS Distributions uint64_t tss_duration; /* sum(mach_absolute_time) of time spend suspended */
1136*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1137*2c2f96dcSApple OSS Distributions
1138*2c2f96dcSApple OSS Distributions struct stackshot_suspension_source {
1139*2c2f96dcSApple OSS Distributions uint64_t tss_time; /* mach_absolute_time of suspend */
1140*2c2f96dcSApple OSS Distributions uint64_t tss_tid; /* tid of suspending thread */
1141*2c2f96dcSApple OSS Distributions int tss_pid; /* pid of suspending task */
1142*2c2f96dcSApple OSS Distributions char tss_procname[65]; /* name of suspending task */
1143*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1144*2c2f96dcSApple OSS Distributions
1145*2c2f96dcSApple OSS Distributions /**************** definitions for exclaves *********************/
1146*2c2f96dcSApple OSS Distributions
1147*2c2f96dcSApple OSS Distributions enum thread_exclaves_flags : uint32_t {
1148*2c2f96dcSApple OSS Distributions kExclaveRPCActive = 0x1, /* Thread is handling RPC call in secure world */
1149*2c2f96dcSApple OSS Distributions kExclaveUpcallActive = 0x2, /* Thread has upcalled back into xnu while handling RPC */
1150*2c2f96dcSApple OSS Distributions kExclaveSchedulerRequest = 0x4, /* Thread is handling scheduler request */
1151*2c2f96dcSApple OSS Distributions };
1152*2c2f96dcSApple OSS Distributions
1153*2c2f96dcSApple OSS Distributions struct thread_exclaves_info {
1154*2c2f96dcSApple OSS Distributions uint64_t tei_scid; /* Scheduling context for exclave IPC stack */
1155*2c2f96dcSApple OSS Distributions uint32_t tei_thread_offset; /* # frames from top of stack exclave frames should be inserted */
1156*2c2f96dcSApple OSS Distributions uint32_t tei_flags; /* A combination of enum thread_exclaves_flags values */
1157*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1158*2c2f96dcSApple OSS Distributions
1159*2c2f96dcSApple OSS Distributions struct thread_crash_exclaves_info {
1160*2c2f96dcSApple OSS Distributions uint64_t tcei_scid; /* Scheduling context for exclave IPC stack */
1161*2c2f96dcSApple OSS Distributions uint64_t tcei_thread_id; /* Corresponding xnu thread id */
1162*2c2f96dcSApple OSS Distributions uint32_t tcei_flags; /* A combination of enum thread_exclaves_flags values */
1163*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1164*2c2f96dcSApple OSS Distributions
1165*2c2f96dcSApple OSS Distributions enum exclave_scresult_flags : uint64_t {
1166*2c2f96dcSApple OSS Distributions kExclaveScresultHaveIPCStack = 0x1,
1167*2c2f96dcSApple OSS Distributions };
1168*2c2f96dcSApple OSS Distributions
1169*2c2f96dcSApple OSS Distributions struct exclave_scresult_info {
1170*2c2f96dcSApple OSS Distributions uint64_t esc_id;
1171*2c2f96dcSApple OSS Distributions uint64_t esc_flags; /* A combination of enum exclave_scresult_flags values */
1172*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1173*2c2f96dcSApple OSS Distributions
1174*2c2f96dcSApple OSS Distributions enum exclave_ipcstackentry_flags : uint64_t {
1175*2c2f96dcSApple OSS Distributions kExclaveIpcStackEntryHaveInvocationID = 0x1,
1176*2c2f96dcSApple OSS Distributions kExclaveIpcStackEntryHaveStack = 0x2,
1177*2c2f96dcSApple OSS Distributions };
1178*2c2f96dcSApple OSS Distributions
1179*2c2f96dcSApple OSS Distributions struct exclave_ipcstackentry_info {
1180*2c2f96dcSApple OSS Distributions uint64_t eise_asid; /* ASID */
1181*2c2f96dcSApple OSS Distributions uint64_t eise_tnid; /* Thread numeric ID, may be UINT64_MAX if ommitted */
1182*2c2f96dcSApple OSS Distributions uint64_t eise_invocationid; /* Invocation ID, may be UINT64_MAX if ommitted */
1183*2c2f96dcSApple OSS Distributions uint64_t eise_flags; /* A combination of enum exclave_ipcstackentry_flags values */
1184*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1185*2c2f96dcSApple OSS Distributions
1186*2c2f96dcSApple OSS Distributions typedef uint64_t exclave_ecstackentry_addr_t;
1187*2c2f96dcSApple OSS Distributions
1188*2c2f96dcSApple OSS Distributions enum exclave_addressspace_flags : uint64_t {
1189*2c2f96dcSApple OSS Distributions kExclaveAddressSpaceHaveSlide = 0x1, /* slide info provided */
1190*2c2f96dcSApple OSS Distributions };
1191*2c2f96dcSApple OSS Distributions
1192*2c2f96dcSApple OSS Distributions struct exclave_addressspace_info {
1193*2c2f96dcSApple OSS Distributions uint64_t eas_id; /* ASID */
1194*2c2f96dcSApple OSS Distributions uint64_t eas_flags; /* A combination of enum exclave_addressspace_flags values */
1195*2c2f96dcSApple OSS Distributions uint64_t eas_layoutid; /* textLayout for this address space */
1196*2c2f96dcSApple OSS Distributions uint64_t eas_slide; /* slide to apply to textlayout, or UINT64_MAX if omitted */
1197*2c2f96dcSApple OSS Distributions uint64_t eas_asroot; /* ASRoot/TTBR0 value used as an identifier for the address space by cL4 */
1198*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1199*2c2f96dcSApple OSS Distributions
1200*2c2f96dcSApple OSS Distributions enum exclave_textlayout_flags : uint64_t {
1201*2c2f96dcSApple OSS Distributions kExclaveTextLayoutLoadAddressesSynthetic = 0x1, /* Load Addresses are synthetic */
1202*2c2f96dcSApple OSS Distributions kExclaveTextLayoutLoadAddressesUnslid = 0x2, /* Load Addresses are accurate and unslid */
1203*2c2f96dcSApple OSS Distributions };
1204*2c2f96dcSApple OSS Distributions
1205*2c2f96dcSApple OSS Distributions struct exclave_textlayout_info {
1206*2c2f96dcSApple OSS Distributions uint64_t layout_id;
1207*2c2f96dcSApple OSS Distributions uint64_t etl_flags; /* A combination of enum exclave_textlayout_flags values */
1208*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1209*2c2f96dcSApple OSS Distributions
1210*2c2f96dcSApple OSS Distributions struct exclave_textlayout_segment {
1211*2c2f96dcSApple OSS Distributions uuid_t layoutSegment_uuid;
1212*2c2f96dcSApple OSS Distributions uint64_t layoutSegment_loadAddress; /* Load Address, either synthetic or unslid */
1213*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1214*2c2f96dcSApple OSS Distributions
1215*2c2f96dcSApple OSS Distributions /**************** definitions for crashinfo *********************/
1216*2c2f96dcSApple OSS Distributions
1217*2c2f96dcSApple OSS Distributions /*
1218*2c2f96dcSApple OSS Distributions * NOTE: Please update kcdata/libkdd/kcdtypes.c if you make any changes
1219*2c2f96dcSApple OSS Distributions * in TASK_CRASHINFO_* types.
1220*2c2f96dcSApple OSS Distributions */
1221*2c2f96dcSApple OSS Distributions
1222*2c2f96dcSApple OSS Distributions /* FIXME some of these types aren't clean (fixed width, packed, and defined *here*) */
1223*2c2f96dcSApple OSS Distributions
1224*2c2f96dcSApple OSS Distributions struct crashinfo_proc_uniqidentifierinfo {
1225*2c2f96dcSApple OSS Distributions uint8_t p_uuid[16]; /* UUID of the main executable */
1226*2c2f96dcSApple OSS Distributions uint64_t p_uniqueid; /* 64 bit unique identifier for process */
1227*2c2f96dcSApple OSS Distributions uint64_t p_puniqueid; /* unique identifier for process's parent */
1228*2c2f96dcSApple OSS Distributions uint64_t p_reserve2; /* reserved for future use */
1229*2c2f96dcSApple OSS Distributions uint64_t p_reserve3; /* reserved for future use */
1230*2c2f96dcSApple OSS Distributions uint64_t p_reserve4; /* reserved for future use */
1231*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1232*2c2f96dcSApple OSS Distributions
1233*2c2f96dcSApple OSS Distributions #define MAX_TRIAGE_STRING_LEN (128)
1234*2c2f96dcSApple OSS Distributions
1235*2c2f96dcSApple OSS Distributions struct kernel_triage_info_v1 {
1236*2c2f96dcSApple OSS Distributions char triage_string1[MAX_TRIAGE_STRING_LEN];
1237*2c2f96dcSApple OSS Distributions char triage_string2[MAX_TRIAGE_STRING_LEN];
1238*2c2f96dcSApple OSS Distributions char triage_string3[MAX_TRIAGE_STRING_LEN];
1239*2c2f96dcSApple OSS Distributions char triage_string4[MAX_TRIAGE_STRING_LEN];
1240*2c2f96dcSApple OSS Distributions char triage_string5[MAX_TRIAGE_STRING_LEN];
1241*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1242*2c2f96dcSApple OSS Distributions
1243*2c2f96dcSApple OSS Distributions #define MAX_CRASHINFO_SIGNING_ID_LEN 64
1244*2c2f96dcSApple OSS Distributions #define MAX_CRASHINFO_TEAM_ID_LEN 32
1245*2c2f96dcSApple OSS Distributions
1246*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_BEGIN KCDATA_BUFFER_BEGIN_CRASHINFO
1247*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_STRING_DESC KCDATA_TYPE_STRING_DESC
1248*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_UINT32_DESC KCDATA_TYPE_UINT32_DESC
1249*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_UINT64_DESC KCDATA_TYPE_UINT64_DESC
1250*2c2f96dcSApple OSS Distributions
1251*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_EXTMODINFO 0x801
1252*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_BSDINFOWITHUNIQID 0x802 /* struct crashinfo_proc_uniqidentifierinfo */
1253*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_TASKDYLD_INFO 0x803
1254*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_UUID 0x804
1255*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_PID 0x805
1256*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_PPID 0x806
1257*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_RUSAGE 0x807 /* struct rusage DEPRECATED do not use.
1258*2c2f96dcSApple OSS Distributions * This struct has longs in it */
1259*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_RUSAGE_INFO 0x808 /* struct rusage_info_v3 from resource.h */
1260*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_PROC_NAME 0x809 /* char * */
1261*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_PROC_STARTTIME 0x80B /* struct timeval64 */
1262*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_USERSTACK 0x80C /* uint64_t */
1263*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_ARGSLEN 0x80D
1264*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_EXCEPTION_CODES 0x80E /* mach_exception_data_t */
1265*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_PROC_PATH 0x80F /* string of len MAXPATHLEN */
1266*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_PROC_CSFLAGS 0x810 /* uint32_t */
1267*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_PROC_STATUS 0x811 /* char */
1268*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_UID 0x812 /* uid_t */
1269*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_GID 0x813 /* gid_t */
1270*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_PROC_ARGC 0x814 /* int */
1271*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_PROC_FLAGS 0x815 /* unsigned int */
1272*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_CPUTYPE 0x816 /* cpu_type_t */
1273*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_WORKQUEUEINFO 0x817 /* struct proc_workqueueinfo */
1274*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_RESPONSIBLE_PID 0x818 /* pid_t */
1275*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_DIRTY_FLAGS 0x819 /* int */
1276*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_CRASHED_THREADID 0x81A /* uint64_t */
1277*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_COALITION_ID 0x81B /* uint64_t */
1278*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_UDATA_PTRS 0x81C /* uint64_t */
1279*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_MEMORY_LIMIT 0x81D /* uint64_t */
1280*2c2f96dcSApple OSS Distributions
1281*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_INTERNAL 0x81E /* uint64_t */
1282*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_INTERNAL_COMPRESSED 0x81F /* uint64_t */
1283*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_IOKIT_MAPPED 0x820 /* uint64_t */
1284*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_ALTERNATE_ACCOUNTING 0x821 /* uint64_t */
1285*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_ALTERNATE_ACCOUNTING_COMPRESSED 0x822 /* uint64_t */
1286*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_PURGEABLE_NONVOLATILE 0x823 /* uint64_t */
1287*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_PURGEABLE_NONVOLATILE_COMPRESSED 0x824 /* uint64_t */
1288*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_PAGE_TABLE 0x825 /* uint64_t */
1289*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_PHYS_FOOTPRINT 0x826 /* uint64_t */
1290*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_PHYS_FOOTPRINT_LIFETIME_MAX 0x827 /* uint64_t */
1291*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_NETWORK_NONVOLATILE 0x828 /* uint64_t */
1292*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_NETWORK_NONVOLATILE_COMPRESSED 0x829 /* uint64_t */
1293*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_WIRED_MEM 0x82A /* uint64_t */
1294*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_PROC_PERSONA_ID 0x82B /* uid_t */
1295*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_MEMORY_LIMIT_INCREASE 0x82C /* uint32_t */
1296*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_TAGGED_FOOTPRINT 0x82D /* uint64_t */
1297*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_TAGGED_FOOTPRINT_COMPRESSED 0x82E /* uint64_t */
1298*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_MEDIA_FOOTPRINT 0x82F /* uint64_t */
1299*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_MEDIA_FOOTPRINT_COMPRESSED 0x830 /* uint64_t */
1300*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_GRAPHICS_FOOTPRINT 0x831 /* uint64_t */
1301*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_GRAPHICS_FOOTPRINT_COMPRESSED 0x832 /* uint64_t */
1302*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_NEURAL_FOOTPRINT 0x833 /* uint64_t */
1303*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_LEDGER_NEURAL_FOOTPRINT_COMPRESSED 0x834 /* uint64_t */
1304*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_MEMORYSTATUS_EFFECTIVE_PRIORITY 0x835 /* int32_t */
1305*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_KERNEL_TRIAGE_INFO_V1 0x836 /* struct kernel_triage_info_v1 */
1306*2c2f96dcSApple OSS Distributions
1307*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_TASK_IS_CORPSE_FORK 0x837 /* boolean_t */
1308*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_EXCEPTION_TYPE 0x838 /* int */
1309*2c2f96dcSApple OSS Distributions
1310*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_CRASH_COUNT 0x839 /* int */
1311*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_THROTTLE_TIMEOUT 0x83A /* int */
1312*2c2f96dcSApple OSS Distributions
1313*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_CS_SIGNING_ID 0x83B /* string of len MAX_CRASHINFO_SIGNING_ID_LEN */
1314*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_CS_TEAM_ID 0x83C /* string of len MAX_CRASHINFO_TEAM_ID_LEN */
1315*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_CS_VALIDATION_CATEGORY 0x83D /* uint32_t */
1316*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_CS_TRUST_LEVEL 0x83E /* uint32_t */
1317*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_PROC_CPUTYPE 0x83F /* cpu_type_t */
1318*2c2f96dcSApple OSS Distributions
1319*2c2f96dcSApple OSS Distributions #define TASK_CRASHINFO_END KCDATA_TYPE_BUFFER_END
1320*2c2f96dcSApple OSS Distributions
1321*2c2f96dcSApple OSS Distributions /**************** definitions for backtrace info *********************/
1322*2c2f96dcSApple OSS Distributions
1323*2c2f96dcSApple OSS Distributions /* tstate is variable length with count elements */
1324*2c2f96dcSApple OSS Distributions struct btinfo_thread_state_data_t {
1325*2c2f96dcSApple OSS Distributions uint32_t flavor;
1326*2c2f96dcSApple OSS Distributions uint32_t count;
1327*2c2f96dcSApple OSS Distributions int tstate[];
1328*2c2f96dcSApple OSS Distributions };
1329*2c2f96dcSApple OSS Distributions
1330*2c2f96dcSApple OSS Distributions struct btinfo_sc_load_info64 {
1331*2c2f96dcSApple OSS Distributions uint64_t sharedCacheSlide;
1332*2c2f96dcSApple OSS Distributions uuid_t sharedCacheUUID;
1333*2c2f96dcSApple OSS Distributions uint64_t sharedCacheBaseAddress;
1334*2c2f96dcSApple OSS Distributions };
1335*2c2f96dcSApple OSS Distributions
1336*2c2f96dcSApple OSS Distributions struct btinfo_sc_load_info {
1337*2c2f96dcSApple OSS Distributions uint32_t sharedCacheSlide;
1338*2c2f96dcSApple OSS Distributions uuid_t sharedCacheUUID;
1339*2c2f96dcSApple OSS Distributions uint32_t sharedCacheBaseAddress;
1340*2c2f96dcSApple OSS Distributions };
1341*2c2f96dcSApple OSS Distributions
1342*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_BEGIN KCDATA_BUFFER_BEGIN_BTINFO
1343*2c2f96dcSApple OSS Distributions
1344*2c2f96dcSApple OSS Distributions /* Shared keys with CRASHINFO */
1345*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_PID 0xA01
1346*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_PPID 0xA02
1347*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_PROC_NAME 0xA03
1348*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_PROC_PATH 0xA04
1349*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_UID 0xA05
1350*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_GID 0xA06
1351*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_PROC_FLAGS 0xA07
1352*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_CPUTYPE 0xA08
1353*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_EXCEPTION_CODES 0xA09
1354*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_EXCEPTION_TYPE 0xA0A
1355*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_RUSAGE_INFO 0xA0B
1356*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_COALITION_ID 0xA0C
1357*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_CRASH_COUNT 0xA0D
1358*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_THROTTLE_TIMEOUT 0xA0E
1359*2c2f96dcSApple OSS Distributions
1360*2c2f96dcSApple OSS Distributions /* Only in BTINFO */
1361*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_THREAD_ID 0xA20 /* uint64_t */
1362*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_THREAD_NAME 0xA21 /* string of len MAXTHREADNAMESIZE */
1363*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_THREAD_STATE 0xA22 /* struct btinfo_thread_state_data_t */
1364*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_THREAD_EXCEPTION_STATE 0xA23 /* struct btinfo_thread_state_data_t */
1365*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_BACKTRACE 0xA24 /* array of uintptr_t */
1366*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_BACKTRACE64 0xA25 /* array of uintptr_t */
1367*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_ASYNC_BACKTRACE64 0xA26 /* array of uintptr_t */
1368*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_ASYNC_START_INDEX 0xA27 /* uint32_t */
1369*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_PLATFORM 0xA28 /* uint32_t */
1370*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_SC_LOADINFO 0xA29 /* struct btinfo_sc_load_info */
1371*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_SC_LOADINFO64 0xA2A /* struct btinfo_sc_load_info64 */
1372*2c2f96dcSApple OSS Distributions
1373*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_DYLD_LOADINFO KCDATA_TYPE_LIBRARY_LOADINFO
1374*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_DYLD_LOADINFO64 KCDATA_TYPE_LIBRARY_LOADINFO64
1375*2c2f96dcSApple OSS Distributions
1376*2c2f96dcSApple OSS Distributions /* Last one */
1377*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_FLAGS 0xAFF /* uint32_t */
1378*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_FLAG_BT_TRUNCATED 0x1
1379*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_FLAG_ASYNC_BT_TRUNCATED 0x2
1380*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_FLAG_TASK_TERMINATED 0x4 /* task is terminated */
1381*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_FLAG_KCDATA_INCOMPLETE 0x8 /* lw corpse collection is incomplete */
1382*2c2f96dcSApple OSS Distributions
1383*2c2f96dcSApple OSS Distributions #define TASK_BTINFO_END KCDATA_TYPE_BUFFER_END
1384*2c2f96dcSApple OSS Distributions
1385*2c2f96dcSApple OSS Distributions /**************** definitions for os reasons *********************/
1386*2c2f96dcSApple OSS Distributions
1387*2c2f96dcSApple OSS Distributions #define EXIT_REASON_SNAPSHOT 0x1001
1388*2c2f96dcSApple OSS Distributions #define EXIT_REASON_USER_DESC 0x1002 /* string description of reason */
1389*2c2f96dcSApple OSS Distributions #define EXIT_REASON_USER_PAYLOAD 0x1003 /* user payload data */
1390*2c2f96dcSApple OSS Distributions #define EXIT_REASON_CODESIGNING_INFO 0x1004
1391*2c2f96dcSApple OSS Distributions #define EXIT_REASON_WORKLOOP_ID 0x1005
1392*2c2f96dcSApple OSS Distributions #define EXIT_REASON_DISPATCH_QUEUE_NO 0x1006
1393*2c2f96dcSApple OSS Distributions
1394*2c2f96dcSApple OSS Distributions struct exit_reason_snapshot {
1395*2c2f96dcSApple OSS Distributions uint32_t ers_namespace;
1396*2c2f96dcSApple OSS Distributions uint64_t ers_code;
1397*2c2f96dcSApple OSS Distributions /* end of version 1 of exit_reason_snapshot. sizeof v1 was 12 */
1398*2c2f96dcSApple OSS Distributions uint64_t ers_flags;
1399*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1400*2c2f96dcSApple OSS Distributions
1401*2c2f96dcSApple OSS Distributions #define EXIT_REASON_CODESIG_PATH_MAX 1024
1402*2c2f96dcSApple OSS Distributions
1403*2c2f96dcSApple OSS Distributions struct codesigning_exit_reason_info {
1404*2c2f96dcSApple OSS Distributions uint64_t ceri_virt_addr;
1405*2c2f96dcSApple OSS Distributions uint64_t ceri_file_offset;
1406*2c2f96dcSApple OSS Distributions char ceri_pathname[EXIT_REASON_CODESIG_PATH_MAX];
1407*2c2f96dcSApple OSS Distributions char ceri_filename[EXIT_REASON_CODESIG_PATH_MAX];
1408*2c2f96dcSApple OSS Distributions uint64_t ceri_codesig_modtime_secs;
1409*2c2f96dcSApple OSS Distributions uint64_t ceri_codesig_modtime_nsecs;
1410*2c2f96dcSApple OSS Distributions uint64_t ceri_page_modtime_secs;
1411*2c2f96dcSApple OSS Distributions uint64_t ceri_page_modtime_nsecs;
1412*2c2f96dcSApple OSS Distributions uint8_t ceri_path_truncated;
1413*2c2f96dcSApple OSS Distributions uint8_t ceri_object_codesigned;
1414*2c2f96dcSApple OSS Distributions uint8_t ceri_page_codesig_validated;
1415*2c2f96dcSApple OSS Distributions uint8_t ceri_page_codesig_tainted;
1416*2c2f96dcSApple OSS Distributions uint8_t ceri_page_codesig_nx;
1417*2c2f96dcSApple OSS Distributions uint8_t ceri_page_wpmapped;
1418*2c2f96dcSApple OSS Distributions uint8_t ceri_page_slid;
1419*2c2f96dcSApple OSS Distributions uint8_t ceri_page_dirty;
1420*2c2f96dcSApple OSS Distributions uint32_t ceri_page_shadow_depth;
1421*2c2f96dcSApple OSS Distributions } __attribute__((packed));
1422*2c2f96dcSApple OSS Distributions
1423*2c2f96dcSApple OSS Distributions #define EXIT_REASON_USER_DESC_MAX_LEN 1024
1424*2c2f96dcSApple OSS Distributions #define EXIT_REASON_PAYLOAD_MAX_LEN 2048
1425*2c2f96dcSApple OSS Distributions /**************** safe iterators *********************/
1426*2c2f96dcSApple OSS Distributions #if !__has_ptrcheck
1427*2c2f96dcSApple OSS Distributions
1428*2c2f96dcSApple OSS Distributions typedef struct kcdata_iter {
1429*2c2f96dcSApple OSS Distributions kcdata_item_t item;
1430*2c2f96dcSApple OSS Distributions void *end;
1431*2c2f96dcSApple OSS Distributions } kcdata_iter_t;
1432*2c2f96dcSApple OSS Distributions
1433*2c2f96dcSApple OSS Distributions
1434*2c2f96dcSApple OSS Distributions static inline
1435*2c2f96dcSApple OSS Distributions kcdata_iter_t
kcdata_iter(void * buffer,unsigned long size)1436*2c2f96dcSApple OSS Distributions kcdata_iter(void *buffer, unsigned long size)
1437*2c2f96dcSApple OSS Distributions {
1438*2c2f96dcSApple OSS Distributions kcdata_iter_t iter;
1439*2c2f96dcSApple OSS Distributions iter.item = (kcdata_item_t) buffer;
1440*2c2f96dcSApple OSS Distributions iter.end = (void*) (((uintptr_t)buffer) + size);
1441*2c2f96dcSApple OSS Distributions return iter;
1442*2c2f96dcSApple OSS Distributions }
1443*2c2f96dcSApple OSS Distributions
1444*2c2f96dcSApple OSS Distributions static inline
1445*2c2f96dcSApple OSS Distributions kcdata_iter_t kcdata_iter_unsafe(void *buffer) __attribute__((deprecated));
1446*2c2f96dcSApple OSS Distributions
1447*2c2f96dcSApple OSS Distributions static inline
1448*2c2f96dcSApple OSS Distributions kcdata_iter_t
kcdata_iter_unsafe(void * buffer)1449*2c2f96dcSApple OSS Distributions kcdata_iter_unsafe(void *buffer)
1450*2c2f96dcSApple OSS Distributions {
1451*2c2f96dcSApple OSS Distributions kcdata_iter_t iter;
1452*2c2f96dcSApple OSS Distributions iter.item = (kcdata_item_t) buffer;
1453*2c2f96dcSApple OSS Distributions iter.end = (void*) (uintptr_t) ~0;
1454*2c2f96dcSApple OSS Distributions return iter;
1455*2c2f96dcSApple OSS Distributions }
1456*2c2f96dcSApple OSS Distributions
1457*2c2f96dcSApple OSS Distributions static const kcdata_iter_t kcdata_invalid_iter = { .item = NULL, .end = NULL };
1458*2c2f96dcSApple OSS Distributions
1459*2c2f96dcSApple OSS Distributions static inline
1460*2c2f96dcSApple OSS Distributions int
kcdata_iter_valid(kcdata_iter_t iter)1461*2c2f96dcSApple OSS Distributions kcdata_iter_valid(kcdata_iter_t iter)
1462*2c2f96dcSApple OSS Distributions {
1463*2c2f96dcSApple OSS Distributions return
1464*2c2f96dcSApple OSS Distributions ((uintptr_t)iter.item + sizeof(struct kcdata_item) <= (uintptr_t)iter.end) &&
1465*2c2f96dcSApple OSS Distributions ((uintptr_t)iter.item + sizeof(struct kcdata_item) + iter.item->size <= (uintptr_t)iter.end);
1466*2c2f96dcSApple OSS Distributions }
1467*2c2f96dcSApple OSS Distributions
1468*2c2f96dcSApple OSS Distributions
1469*2c2f96dcSApple OSS Distributions static inline
1470*2c2f96dcSApple OSS Distributions kcdata_iter_t
kcdata_iter_next(kcdata_iter_t iter)1471*2c2f96dcSApple OSS Distributions kcdata_iter_next(kcdata_iter_t iter)
1472*2c2f96dcSApple OSS Distributions {
1473*2c2f96dcSApple OSS Distributions iter.item = (kcdata_item_t) (((uintptr_t)iter.item) + sizeof(struct kcdata_item) + (iter.item->size));
1474*2c2f96dcSApple OSS Distributions return iter;
1475*2c2f96dcSApple OSS Distributions }
1476*2c2f96dcSApple OSS Distributions
1477*2c2f96dcSApple OSS Distributions static inline uint32_t
kcdata_iter_type(kcdata_iter_t iter)1478*2c2f96dcSApple OSS Distributions kcdata_iter_type(kcdata_iter_t iter)
1479*2c2f96dcSApple OSS Distributions {
1480*2c2f96dcSApple OSS Distributions if ((iter.item->type & ~0xfu) == KCDATA_TYPE_ARRAY_PAD0) {
1481*2c2f96dcSApple OSS Distributions return KCDATA_TYPE_ARRAY;
1482*2c2f96dcSApple OSS Distributions } else {
1483*2c2f96dcSApple OSS Distributions return iter.item->type;
1484*2c2f96dcSApple OSS Distributions }
1485*2c2f96dcSApple OSS Distributions }
1486*2c2f96dcSApple OSS Distributions
1487*2c2f96dcSApple OSS Distributions static inline uint32_t
kcdata_calc_padding(uint32_t size)1488*2c2f96dcSApple OSS Distributions kcdata_calc_padding(uint32_t size)
1489*2c2f96dcSApple OSS Distributions {
1490*2c2f96dcSApple OSS Distributions /* calculate number of bytes to add to size to get something divisible by 16 */
1491*2c2f96dcSApple OSS Distributions return (-size) & 0xf;
1492*2c2f96dcSApple OSS Distributions }
1493*2c2f96dcSApple OSS Distributions
1494*2c2f96dcSApple OSS Distributions static inline uint32_t
kcdata_flags_get_padding(uint64_t flags)1495*2c2f96dcSApple OSS Distributions kcdata_flags_get_padding(uint64_t flags)
1496*2c2f96dcSApple OSS Distributions {
1497*2c2f96dcSApple OSS Distributions return flags & KCDATA_FLAGS_STRUCT_PADDING_MASK;
1498*2c2f96dcSApple OSS Distributions }
1499*2c2f96dcSApple OSS Distributions
1500*2c2f96dcSApple OSS Distributions /* see comment above about has_padding */
1501*2c2f96dcSApple OSS Distributions static inline int
kcdata_iter_is_legacy_item(kcdata_iter_t iter,uint32_t legacy_size)1502*2c2f96dcSApple OSS Distributions kcdata_iter_is_legacy_item(kcdata_iter_t iter, uint32_t legacy_size)
1503*2c2f96dcSApple OSS Distributions {
1504*2c2f96dcSApple OSS Distributions uint32_t legacy_size_padded = legacy_size + kcdata_calc_padding(legacy_size);
1505*2c2f96dcSApple OSS Distributions return iter.item->size == legacy_size_padded &&
1506*2c2f96dcSApple OSS Distributions (iter.item->flags & (KCDATA_FLAGS_STRUCT_PADDING_MASK | KCDATA_FLAGS_STRUCT_HAS_PADDING)) == 0;
1507*2c2f96dcSApple OSS Distributions }
1508*2c2f96dcSApple OSS Distributions
1509*2c2f96dcSApple OSS Distributions static inline uint32_t
kcdata_iter_size(kcdata_iter_t iter)1510*2c2f96dcSApple OSS Distributions kcdata_iter_size(kcdata_iter_t iter)
1511*2c2f96dcSApple OSS Distributions {
1512*2c2f96dcSApple OSS Distributions uint32_t legacy_size = 0;
1513*2c2f96dcSApple OSS Distributions
1514*2c2f96dcSApple OSS Distributions switch (kcdata_iter_type(iter)) {
1515*2c2f96dcSApple OSS Distributions case KCDATA_TYPE_ARRAY:
1516*2c2f96dcSApple OSS Distributions case KCDATA_TYPE_CONTAINER_BEGIN:
1517*2c2f96dcSApple OSS Distributions return iter.item->size;
1518*2c2f96dcSApple OSS Distributions case STACKSHOT_KCTYPE_THREAD_SNAPSHOT: {
1519*2c2f96dcSApple OSS Distributions legacy_size = sizeof(struct thread_snapshot_v2);
1520*2c2f96dcSApple OSS Distributions if (kcdata_iter_is_legacy_item(iter, legacy_size)) {
1521*2c2f96dcSApple OSS Distributions return legacy_size;
1522*2c2f96dcSApple OSS Distributions }
1523*2c2f96dcSApple OSS Distributions
1524*2c2f96dcSApple OSS Distributions goto not_legacy;
1525*2c2f96dcSApple OSS Distributions }
1526*2c2f96dcSApple OSS Distributions case STACKSHOT_KCTYPE_SHAREDCACHE_LOADINFO: {
1527*2c2f96dcSApple OSS Distributions legacy_size = sizeof(struct dyld_uuid_info_64);
1528*2c2f96dcSApple OSS Distributions if (kcdata_iter_is_legacy_item(iter, legacy_size)) {
1529*2c2f96dcSApple OSS Distributions return legacy_size;
1530*2c2f96dcSApple OSS Distributions }
1531*2c2f96dcSApple OSS Distributions
1532*2c2f96dcSApple OSS Distributions goto not_legacy;
1533*2c2f96dcSApple OSS Distributions }
1534*2c2f96dcSApple OSS Distributions not_legacy:
1535*2c2f96dcSApple OSS Distributions default:
1536*2c2f96dcSApple OSS Distributions if (iter.item->size < kcdata_flags_get_padding(iter.item->flags)) {
1537*2c2f96dcSApple OSS Distributions return 0;
1538*2c2f96dcSApple OSS Distributions } else {
1539*2c2f96dcSApple OSS Distributions return iter.item->size - kcdata_flags_get_padding(iter.item->flags);
1540*2c2f96dcSApple OSS Distributions }
1541*2c2f96dcSApple OSS Distributions }
1542*2c2f96dcSApple OSS Distributions }
1543*2c2f96dcSApple OSS Distributions
1544*2c2f96dcSApple OSS Distributions static inline uint64_t
kcdata_iter_flags(kcdata_iter_t iter)1545*2c2f96dcSApple OSS Distributions kcdata_iter_flags(kcdata_iter_t iter)
1546*2c2f96dcSApple OSS Distributions {
1547*2c2f96dcSApple OSS Distributions return iter.item->flags;
1548*2c2f96dcSApple OSS Distributions }
1549*2c2f96dcSApple OSS Distributions
1550*2c2f96dcSApple OSS Distributions static inline
1551*2c2f96dcSApple OSS Distributions void *
kcdata_iter_payload(kcdata_iter_t iter)1552*2c2f96dcSApple OSS Distributions kcdata_iter_payload(kcdata_iter_t iter)
1553*2c2f96dcSApple OSS Distributions {
1554*2c2f96dcSApple OSS Distributions return &iter.item->data;
1555*2c2f96dcSApple OSS Distributions }
1556*2c2f96dcSApple OSS Distributions
1557*2c2f96dcSApple OSS Distributions
1558*2c2f96dcSApple OSS Distributions static inline
1559*2c2f96dcSApple OSS Distributions uint32_t
kcdata_iter_array_elem_type(kcdata_iter_t iter)1560*2c2f96dcSApple OSS Distributions kcdata_iter_array_elem_type(kcdata_iter_t iter)
1561*2c2f96dcSApple OSS Distributions {
1562*2c2f96dcSApple OSS Distributions return (iter.item->flags >> 32) & UINT32_MAX;
1563*2c2f96dcSApple OSS Distributions }
1564*2c2f96dcSApple OSS Distributions
1565*2c2f96dcSApple OSS Distributions static inline
1566*2c2f96dcSApple OSS Distributions uint32_t
kcdata_iter_array_elem_count(kcdata_iter_t iter)1567*2c2f96dcSApple OSS Distributions kcdata_iter_array_elem_count(kcdata_iter_t iter)
1568*2c2f96dcSApple OSS Distributions {
1569*2c2f96dcSApple OSS Distributions return (iter.item->flags) & UINT32_MAX;
1570*2c2f96dcSApple OSS Distributions }
1571*2c2f96dcSApple OSS Distributions
1572*2c2f96dcSApple OSS Distributions /* KCDATA_TYPE_ARRAY is ambiguous about the size of the array elements. Size is
1573*2c2f96dcSApple OSS Distributions * calculated as total_size / elements_count, but total size got padded out to a
1574*2c2f96dcSApple OSS Distributions * 16 byte alignment. New kernels will generate KCDATA_TYPE_ARRAY_PAD* instead
1575*2c2f96dcSApple OSS Distributions * to explicitly tell us how much padding was used. Here we have a fixed, never
1576*2c2f96dcSApple OSS Distributions * to be altered list of the sizes of array elements that were used before I
1577*2c2f96dcSApple OSS Distributions * discovered this issue. If you find a KCDATA_TYPE_ARRAY that is not one of
1578*2c2f96dcSApple OSS Distributions * these types, treat it as invalid data. */
1579*2c2f96dcSApple OSS Distributions
1580*2c2f96dcSApple OSS Distributions static inline
1581*2c2f96dcSApple OSS Distributions uint32_t
kcdata_iter_array_size_switch(kcdata_iter_t iter)1582*2c2f96dcSApple OSS Distributions kcdata_iter_array_size_switch(kcdata_iter_t iter)
1583*2c2f96dcSApple OSS Distributions {
1584*2c2f96dcSApple OSS Distributions switch (kcdata_iter_array_elem_type(iter)) {
1585*2c2f96dcSApple OSS Distributions case KCDATA_TYPE_LIBRARY_LOADINFO:
1586*2c2f96dcSApple OSS Distributions return sizeof(struct dyld_uuid_info_32);
1587*2c2f96dcSApple OSS Distributions case KCDATA_TYPE_LIBRARY_LOADINFO64:
1588*2c2f96dcSApple OSS Distributions return sizeof(struct dyld_uuid_info_64);
1589*2c2f96dcSApple OSS Distributions case STACKSHOT_KCTYPE_KERN_STACKFRAME:
1590*2c2f96dcSApple OSS Distributions case STACKSHOT_KCTYPE_USER_STACKFRAME:
1591*2c2f96dcSApple OSS Distributions return sizeof(struct stack_snapshot_frame32);
1592*2c2f96dcSApple OSS Distributions case STACKSHOT_KCTYPE_KERN_STACKFRAME64:
1593*2c2f96dcSApple OSS Distributions case STACKSHOT_KCTYPE_USER_STACKFRAME64:
1594*2c2f96dcSApple OSS Distributions return sizeof(struct stack_snapshot_frame64);
1595*2c2f96dcSApple OSS Distributions case STACKSHOT_KCTYPE_DONATING_PIDS:
1596*2c2f96dcSApple OSS Distributions return sizeof(int32_t);
1597*2c2f96dcSApple OSS Distributions case STACKSHOT_KCTYPE_THREAD_DELTA_SNAPSHOT:
1598*2c2f96dcSApple OSS Distributions return sizeof(struct thread_delta_snapshot_v2);
1599*2c2f96dcSApple OSS Distributions // This one is only here to make some unit tests work. It should be OK to
1600*2c2f96dcSApple OSS Distributions // remove.
1601*2c2f96dcSApple OSS Distributions case TASK_CRASHINFO_CRASHED_THREADID:
1602*2c2f96dcSApple OSS Distributions return sizeof(uint64_t);
1603*2c2f96dcSApple OSS Distributions default:
1604*2c2f96dcSApple OSS Distributions return 0;
1605*2c2f96dcSApple OSS Distributions }
1606*2c2f96dcSApple OSS Distributions }
1607*2c2f96dcSApple OSS Distributions
1608*2c2f96dcSApple OSS Distributions static inline
1609*2c2f96dcSApple OSS Distributions int
kcdata_iter_array_valid(kcdata_iter_t iter)1610*2c2f96dcSApple OSS Distributions kcdata_iter_array_valid(kcdata_iter_t iter)
1611*2c2f96dcSApple OSS Distributions {
1612*2c2f96dcSApple OSS Distributions if (!kcdata_iter_valid(iter)) {
1613*2c2f96dcSApple OSS Distributions return 0;
1614*2c2f96dcSApple OSS Distributions }
1615*2c2f96dcSApple OSS Distributions if (kcdata_iter_type(iter) != KCDATA_TYPE_ARRAY) {
1616*2c2f96dcSApple OSS Distributions return 0;
1617*2c2f96dcSApple OSS Distributions }
1618*2c2f96dcSApple OSS Distributions if (kcdata_iter_array_elem_count(iter) == 0) {
1619*2c2f96dcSApple OSS Distributions return iter.item->size == 0;
1620*2c2f96dcSApple OSS Distributions }
1621*2c2f96dcSApple OSS Distributions if (iter.item->type == KCDATA_TYPE_ARRAY) {
1622*2c2f96dcSApple OSS Distributions uint32_t elem_size = kcdata_iter_array_size_switch(iter);
1623*2c2f96dcSApple OSS Distributions if (elem_size == 0) {
1624*2c2f96dcSApple OSS Distributions return 0;
1625*2c2f96dcSApple OSS Distributions }
1626*2c2f96dcSApple OSS Distributions /* sizes get aligned to the nearest 16. */
1627*2c2f96dcSApple OSS Distributions return
1628*2c2f96dcSApple OSS Distributions kcdata_iter_array_elem_count(iter) <= iter.item->size / elem_size &&
1629*2c2f96dcSApple OSS Distributions iter.item->size % kcdata_iter_array_elem_count(iter) < 16;
1630*2c2f96dcSApple OSS Distributions } else {
1631*2c2f96dcSApple OSS Distributions return
1632*2c2f96dcSApple OSS Distributions (iter.item->type & 0xf) <= iter.item->size &&
1633*2c2f96dcSApple OSS Distributions kcdata_iter_array_elem_count(iter) <= iter.item->size - (iter.item->type & 0xf) &&
1634*2c2f96dcSApple OSS Distributions (iter.item->size - (iter.item->type & 0xf)) % kcdata_iter_array_elem_count(iter) == 0;
1635*2c2f96dcSApple OSS Distributions }
1636*2c2f96dcSApple OSS Distributions }
1637*2c2f96dcSApple OSS Distributions
1638*2c2f96dcSApple OSS Distributions
1639*2c2f96dcSApple OSS Distributions static inline
1640*2c2f96dcSApple OSS Distributions uint32_t
kcdata_iter_array_elem_size(kcdata_iter_t iter)1641*2c2f96dcSApple OSS Distributions kcdata_iter_array_elem_size(kcdata_iter_t iter)
1642*2c2f96dcSApple OSS Distributions {
1643*2c2f96dcSApple OSS Distributions if (iter.item->type == KCDATA_TYPE_ARRAY) {
1644*2c2f96dcSApple OSS Distributions return kcdata_iter_array_size_switch(iter);
1645*2c2f96dcSApple OSS Distributions }
1646*2c2f96dcSApple OSS Distributions if (kcdata_iter_array_elem_count(iter) == 0) {
1647*2c2f96dcSApple OSS Distributions return 0;
1648*2c2f96dcSApple OSS Distributions }
1649*2c2f96dcSApple OSS Distributions return (iter.item->size - (iter.item->type & 0xf)) / kcdata_iter_array_elem_count(iter);
1650*2c2f96dcSApple OSS Distributions }
1651*2c2f96dcSApple OSS Distributions
1652*2c2f96dcSApple OSS Distributions static inline
1653*2c2f96dcSApple OSS Distributions int
kcdata_iter_container_valid(kcdata_iter_t iter)1654*2c2f96dcSApple OSS Distributions kcdata_iter_container_valid(kcdata_iter_t iter)
1655*2c2f96dcSApple OSS Distributions {
1656*2c2f96dcSApple OSS Distributions return
1657*2c2f96dcSApple OSS Distributions kcdata_iter_valid(iter) &&
1658*2c2f96dcSApple OSS Distributions kcdata_iter_type(iter) == KCDATA_TYPE_CONTAINER_BEGIN &&
1659*2c2f96dcSApple OSS Distributions iter.item->size >= sizeof(uint32_t);
1660*2c2f96dcSApple OSS Distributions }
1661*2c2f96dcSApple OSS Distributions
1662*2c2f96dcSApple OSS Distributions static inline
1663*2c2f96dcSApple OSS Distributions uint32_t
kcdata_iter_container_type(kcdata_iter_t iter)1664*2c2f96dcSApple OSS Distributions kcdata_iter_container_type(kcdata_iter_t iter)
1665*2c2f96dcSApple OSS Distributions {
1666*2c2f96dcSApple OSS Distributions return *(uint32_t *) kcdata_iter_payload(iter);
1667*2c2f96dcSApple OSS Distributions }
1668*2c2f96dcSApple OSS Distributions
1669*2c2f96dcSApple OSS Distributions static inline
1670*2c2f96dcSApple OSS Distributions uint64_t
kcdata_iter_container_id(kcdata_iter_t iter)1671*2c2f96dcSApple OSS Distributions kcdata_iter_container_id(kcdata_iter_t iter)
1672*2c2f96dcSApple OSS Distributions {
1673*2c2f96dcSApple OSS Distributions return iter.item->flags;
1674*2c2f96dcSApple OSS Distributions }
1675*2c2f96dcSApple OSS Distributions
1676*2c2f96dcSApple OSS Distributions
1677*2c2f96dcSApple OSS Distributions #define KCDATA_ITER_FOREACH(iter) for(; kcdata_iter_valid(iter) && iter.item->type != KCDATA_TYPE_BUFFER_END; iter = kcdata_iter_next(iter))
1678*2c2f96dcSApple OSS Distributions #define KCDATA_ITER_FOREACH_FAILED(iter) (!kcdata_iter_valid(iter) || (iter).item->type != KCDATA_TYPE_BUFFER_END)
1679*2c2f96dcSApple OSS Distributions
1680*2c2f96dcSApple OSS Distributions static inline
1681*2c2f96dcSApple OSS Distributions kcdata_iter_t
kcdata_iter_find_type(kcdata_iter_t iter,uint32_t type)1682*2c2f96dcSApple OSS Distributions kcdata_iter_find_type(kcdata_iter_t iter, uint32_t type)
1683*2c2f96dcSApple OSS Distributions {
1684*2c2f96dcSApple OSS Distributions KCDATA_ITER_FOREACH(iter)
1685*2c2f96dcSApple OSS Distributions {
1686*2c2f96dcSApple OSS Distributions if (kcdata_iter_type(iter) == type) {
1687*2c2f96dcSApple OSS Distributions return iter;
1688*2c2f96dcSApple OSS Distributions }
1689*2c2f96dcSApple OSS Distributions }
1690*2c2f96dcSApple OSS Distributions return kcdata_invalid_iter;
1691*2c2f96dcSApple OSS Distributions }
1692*2c2f96dcSApple OSS Distributions
1693*2c2f96dcSApple OSS Distributions static inline
1694*2c2f96dcSApple OSS Distributions int
kcdata_iter_data_with_desc_valid(kcdata_iter_t iter,uint32_t minsize)1695*2c2f96dcSApple OSS Distributions kcdata_iter_data_with_desc_valid(kcdata_iter_t iter, uint32_t minsize)
1696*2c2f96dcSApple OSS Distributions {
1697*2c2f96dcSApple OSS Distributions return
1698*2c2f96dcSApple OSS Distributions kcdata_iter_valid(iter) &&
1699*2c2f96dcSApple OSS Distributions kcdata_iter_size(iter) >= KCDATA_DESC_MAXLEN + minsize &&
1700*2c2f96dcSApple OSS Distributions ((char*)kcdata_iter_payload(iter))[KCDATA_DESC_MAXLEN - 1] == 0;
1701*2c2f96dcSApple OSS Distributions }
1702*2c2f96dcSApple OSS Distributions
1703*2c2f96dcSApple OSS Distributions static inline
1704*2c2f96dcSApple OSS Distributions char *
kcdata_iter_string(kcdata_iter_t iter,uint32_t offset)1705*2c2f96dcSApple OSS Distributions kcdata_iter_string(kcdata_iter_t iter, uint32_t offset)
1706*2c2f96dcSApple OSS Distributions {
1707*2c2f96dcSApple OSS Distributions if (offset > kcdata_iter_size(iter)) {
1708*2c2f96dcSApple OSS Distributions return NULL;
1709*2c2f96dcSApple OSS Distributions }
1710*2c2f96dcSApple OSS Distributions uint32_t maxlen = kcdata_iter_size(iter) - offset;
1711*2c2f96dcSApple OSS Distributions char *s = ((char*)kcdata_iter_payload(iter)) + offset;
1712*2c2f96dcSApple OSS Distributions if (strnlen(s, maxlen) < maxlen) {
1713*2c2f96dcSApple OSS Distributions return s;
1714*2c2f96dcSApple OSS Distributions } else {
1715*2c2f96dcSApple OSS Distributions return NULL;
1716*2c2f96dcSApple OSS Distributions }
1717*2c2f96dcSApple OSS Distributions }
1718*2c2f96dcSApple OSS Distributions
1719*2c2f96dcSApple OSS Distributions static inline void
kcdata_iter_get_data_with_desc(kcdata_iter_t iter,char ** desc_ptr,void ** data_ptr,uint32_t * size_ptr)1720*2c2f96dcSApple OSS Distributions kcdata_iter_get_data_with_desc(kcdata_iter_t iter, char **desc_ptr, void **data_ptr, uint32_t *size_ptr)
1721*2c2f96dcSApple OSS Distributions {
1722*2c2f96dcSApple OSS Distributions if (desc_ptr) {
1723*2c2f96dcSApple OSS Distributions *desc_ptr = (char *)kcdata_iter_payload(iter);
1724*2c2f96dcSApple OSS Distributions }
1725*2c2f96dcSApple OSS Distributions if (data_ptr) {
1726*2c2f96dcSApple OSS Distributions *data_ptr = (void *)((uintptr_t)kcdata_iter_payload(iter) + KCDATA_DESC_MAXLEN);
1727*2c2f96dcSApple OSS Distributions }
1728*2c2f96dcSApple OSS Distributions if (size_ptr) {
1729*2c2f96dcSApple OSS Distributions *size_ptr = kcdata_iter_size(iter) - KCDATA_DESC_MAXLEN;
1730*2c2f96dcSApple OSS Distributions }
1731*2c2f96dcSApple OSS Distributions }
1732*2c2f96dcSApple OSS Distributions
1733*2c2f96dcSApple OSS Distributions #endif /* !__has_ptrcheck */
1734*2c2f96dcSApple OSS Distributions #endif
1735