xref: /xnu-8020.101.4/osfmk/kdp/processor_core.h (revision e7776783b89a353188416a9a346c6cdb4928faad)
1*e7776783SApple OSS Distributions /*
2*e7776783SApple OSS Distributions  * Copyright (c) 2017 Apple Computer, Inc. All rights reserved.
3*e7776783SApple OSS Distributions  *
4*e7776783SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*e7776783SApple OSS Distributions  *
6*e7776783SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*e7776783SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*e7776783SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*e7776783SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*e7776783SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*e7776783SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*e7776783SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*e7776783SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*e7776783SApple OSS Distributions  *
15*e7776783SApple OSS Distributions  * Please obtain a copy of the License at
16*e7776783SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*e7776783SApple OSS Distributions  *
18*e7776783SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*e7776783SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*e7776783SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*e7776783SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*e7776783SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*e7776783SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*e7776783SApple OSS Distributions  * limitations under the License.
25*e7776783SApple OSS Distributions  *
26*e7776783SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*e7776783SApple OSS Distributions  */
28*e7776783SApple OSS Distributions #ifndef _PROCESSOR_CORE_H_
29*e7776783SApple OSS Distributions #define _PROCESSOR_CORE_H_
30*e7776783SApple OSS Distributions 
31*e7776783SApple OSS Distributions #include <stdint.h>
32*e7776783SApple OSS Distributions #include <mach/vm_types.h>
33*e7776783SApple OSS Distributions #include <mach/kern_return.h>
34*e7776783SApple OSS Distributions #include <mach/machine.h>
35*e7776783SApple OSS Distributions #include <mach_debug/mach_debug_types.h>
36*e7776783SApple OSS Distributions 
37*e7776783SApple OSS Distributions __BEGIN_DECLS
38*e7776783SApple OSS Distributions 
39*e7776783SApple OSS Distributions /*
40*e7776783SApple OSS Distributions  * Kernel support for generating corefiles on device.
41*e7776783SApple OSS Distributions  *
42*e7776783SApple OSS Distributions  * The kernel provides support for co-operatively generating core files
43*e7776783SApple OSS Distributions  * for any co/processors that register a coredump handler callback.
44*e7776783SApple OSS Distributions  *
45*e7776783SApple OSS Distributions  * The kernel will use the provided callbacks to generate a compressed
46*e7776783SApple OSS Distributions  * corefile in a file on disk.
47*e7776783SApple OSS Distributions  *
48*e7776783SApple OSS Distributions  * Corefiles consist of three main sections
49*e7776783SApple OSS Distributions  *      -- The headers that describe the corefile -- number of segments, etc
50*e7776783SApple OSS Distributions  *      -- The segment commands that describe the data in the corefile
51*e7776783SApple OSS Distributions  *      -- The segment data
52*e7776783SApple OSS Distributions  *
53*e7776783SApple OSS Distributions  * When a coredump handler is registered, a pointer to a kern_coredump_callback_config
54*e7776783SApple OSS Distributions  * structure is provided with callbacks that will be called as part of generating the
55*e7776783SApple OSS Distributions  * coredump.
56*e7776783SApple OSS Distributions  *
57*e7776783SApple OSS Distributions  * It's expected that each of these callbacks will return 0 on success (and non-zero on
58*e7776783SApple OSS Distributions  * error).
59*e7776783SApple OSS Distributions  */
60*e7776783SApple OSS Distributions 
61*e7776783SApple OSS Distributions void kern_coredump_log(void *context, const char *string, ...) __printflike(2, 3);
62*e7776783SApple OSS Distributions 
63*e7776783SApple OSS Distributions /*
64*e7776783SApple OSS Distributions  * The core_save_summary callback is provided with the call to the kcc_coredump_get_summary
65*e7776783SApple OSS Distributions  * routine that was registered. The caller should provide the following
66*e7776783SApple OSS Distributions  *
67*e7776783SApple OSS Distributions  * core_segment_count   -- Number of segments (LC_SEGMENT_KERNEL) that will be recorded
68*e7776783SApple OSS Distributions  * core_byte_count      -- Overall length of all data to be included across all segments
69*e7776783SApple OSS Distributions  * thread_count         -- Number of threads that will be recorded with thread state (LC_THREAD)
70*e7776783SApple OSS Distributions  * thread_state_size    -- Size of a thread's saved state (should be the overall LC_THREAD command size)
71*e7776783SApple OSS Distributions  * misc_bytes_count     -- Length of misc data that will be included in the core
72*e7776783SApple OSS Distributions  * mh_magic             -- mh_magic to be included in corefile
73*e7776783SApple OSS Distributions  * cpu_type             -- CPU type
74*e7776783SApple OSS Distributions  * cpu_subtype          -- CPU subtype
75*e7776783SApple OSS Distributions  * context              -- Passed to kcc_coredump_get_summary_routine
76*e7776783SApple OSS Distributions  */
77*e7776783SApple OSS Distributions typedef kern_return_t (*core_save_summary_cb)(uint64_t core_segment_count, uint64_t core_byte_count,
78*e7776783SApple OSS Distributions     uint64_t thread_count, uint64_t thread_state_size,
79*e7776783SApple OSS Distributions     uint64_t misc_bytes_count, void *context);
80*e7776783SApple OSS Distributions 
81*e7776783SApple OSS Distributions /*
82*e7776783SApple OSS Distributions  * The core_save_note_summary callback is provided with the call to the
83*e7776783SApple OSS Distributions  * kcc_coredump_save_note_summary routine that was registered. The caller should
84*e7776783SApple OSS Distributions  * provide the following
85*e7776783SApple OSS Distributions  *
86*e7776783SApple OSS Distributions  * core_note_count      -- the number of LC_NOTE segments that will be recorded
87*e7776783SApple OSS Distributions  * core_note_byte_count -- overall length of all data to be included across all LC_NOTE segments
88*e7776783SApple OSS Distributions  * context              -- Passed to kcc_coredump_save_note_summary routine
89*e7776783SApple OSS Distributions  */
90*e7776783SApple OSS Distributions typedef kern_return_t (*core_save_note_summary_cb)(uint64_t core_note_count, uint64_t core_note_byte_count,
91*e7776783SApple OSS Distributions     void *context);
92*e7776783SApple OSS Distributions 
93*e7776783SApple OSS Distributions /*
94*e7776783SApple OSS Distributions  * The core_save_segment_descriptions callback is provided with the call to the
95*e7776783SApple OSS Distributions  * kcc_coredump_save_segment_descriptions routine that was registered.
96*e7776783SApple OSS Distributions  *
97*e7776783SApple OSS Distributions  * It's expected that the caller should iterate all of the segments they want to include in
98*e7776783SApple OSS Distributions  * the corefile and call the callback with the following for each:
99*e7776783SApple OSS Distributions  *
100*e7776783SApple OSS Distributions  * Please note that seg_end is address of the byte immediately following the last byte in the segment.
101*e7776783SApple OSS Distributions  * For example, if a segment spans addresses 0x1000 to 0x1FFF, seg_end would be 0x2000.
102*e7776783SApple OSS Distributions  *
103*e7776783SApple OSS Distributions  * seg_start -- Start of the segment in the core's address space
104*e7776783SApple OSS Distributions  * seg_end   -- End of the segment in the core's address space
105*e7776783SApple OSS Distributions  * context   -- Passed to kcc_coredump_save_segment_descriptions routine
106*e7776783SApple OSS Distributions  */
107*e7776783SApple OSS Distributions typedef kern_return_t (*core_save_segment_descriptions_cb)(uint64_t seg_start, uint64_t seg_end,
108*e7776783SApple OSS Distributions     void *context);
109*e7776783SApple OSS Distributions /*
110*e7776783SApple OSS Distributions  * The core_save_thread_state callback is provided with the call to the
111*e7776783SApple OSS Distributions  * kcc_coredump_save_thread_state routine that was registered.
112*e7776783SApple OSS Distributions  *
113*e7776783SApple OSS Distributions  * The routine is provided a pointer to a buffer of thread_state_size (as specified
114*e7776783SApple OSS Distributions  * previously) that can be used to populate thread state.
115*e7776783SApple OSS Distributions  *
116*e7776783SApple OSS Distributions  * It's expected that the caller should iterate all of the threads
117*e7776783SApple OSS Distributions  * that they would like to include and call the callback with the following
118*e7776783SApple OSS Distributions  * for each:
119*e7776783SApple OSS Distributions  *
120*e7776783SApple OSS Distributions  * thread_state -- A pointer to the buffer with an LC_THREAD command
121*e7776783SApple OSS Distributions  * context      -- Passed to kcc_coredump_save_thread_state routine
122*e7776783SApple OSS Distributions  */
123*e7776783SApple OSS Distributions typedef kern_return_t (*core_save_thread_state_cb)(void *thread_state, void *context);
124*e7776783SApple OSS Distributions 
125*e7776783SApple OSS Distributions /*
126*e7776783SApple OSS Distributions  * The core_save_note_descriptions_cb callback is provided with the call to the
127*e7776783SApple OSS Distributions  * kcc_coredump_save_note_descriptions routine that was registered.
128*e7776783SApple OSS Distributions  *
129*e7776783SApple OSS Distributions  * It's expected that the caller should call this function for each LC_NOTE segment that
130*e7776783SApple OSS Distributions  * they want to include in the corefile and provide the following for each:
131*e7776783SApple OSS Distributions  *
132*e7776783SApple OSS Distributions  * data_owner   -- owner name for this LC_NOTE
133*e7776783SApple OSS Distributions  * length       -- length of the payload for this LC_NOTE
134*e7776783SApple OSS Distributions  * context      -- Passed to kcc_coredump_save_note_descriptions routine
135*e7776783SApple OSS Distributions  */
136*e7776783SApple OSS Distributions typedef kern_return_t (*core_save_note_descriptions_cb)(const char *data_owner, uint64_t length, void *context);
137*e7776783SApple OSS Distributions 
138*e7776783SApple OSS Distributions /*
139*e7776783SApple OSS Distributions  * deprecated - please switch to core_save_sw_vers_detail_cb
140*e7776783SApple OSS Distributions  *
141*e7776783SApple OSS Distributions  * The core_save_sw_vers callback is provided with the call to the
142*e7776783SApple OSS Distributions  * kcc_coredump_save_sw_vers routine that was registered.
143*e7776783SApple OSS Distributions  *
144*e7776783SApple OSS Distributions  * The caller should call the callback with the following:
145*e7776783SApple OSS Distributions  *
146*e7776783SApple OSS Distributions  * sw_vers -- A pointer the software version information
147*e7776783SApple OSS Distributions  * length  -- Length of the software version information to be copied (< KERN_COREDUMP_VERSIONSTRINGMAXSIZE)
148*e7776783SApple OSS Distributions  * context -- Passed to kcc_coredump_save_sw_vers routine
149*e7776783SApple OSS Distributions  */
150*e7776783SApple OSS Distributions typedef kern_return_t (*core_save_sw_vers_cb)(void *sw_vers, uint64_t length, void *context);
151*e7776783SApple OSS Distributions 
152*e7776783SApple OSS Distributions /*
153*e7776783SApple OSS Distributions  * The core_save_sw_vers_detail_cb callback is provided with the call to the
154*e7776783SApple OSS Distributions  * kcc_coredump_save_sw_vers_detail routine that was registered.
155*e7776783SApple OSS Distributions  *
156*e7776783SApple OSS Distributions  * The caller should call the callback with the following:
157*e7776783SApple OSS Distributions  *
158*e7776783SApple OSS Distributions  * address       -- base address of TEXT segment
159*e7776783SApple OSS Distributions  * uuid          -- uuid of running binary
160*e7776783SApple OSS Distributions  * log2_pagesize -- process page size in log base 2 (e.g. 4k pages are 12. 0 for unspecified)
161*e7776783SApple OSS Distributions  * context       -- Passed to kcc_coredump_save_sw_vers_detail routine
162*e7776783SApple OSS Distributions  */
163*e7776783SApple OSS Distributions typedef kern_return_t (*core_save_sw_vers_detail_cb)(uint64_t address, uuid_t uuid, uint32_t log2_pagesize, void *context);
164*e7776783SApple OSS Distributions 
165*e7776783SApple OSS Distributions /*
166*e7776783SApple OSS Distributions  * The core_save_segment_data callback is provided with the call to the
167*e7776783SApple OSS Distributions  * kcc_coredump_save_segment_data routine that was registered.
168*e7776783SApple OSS Distributions  *
169*e7776783SApple OSS Distributions  * It's expected that the caller should iterate all of the segments they want to include in
170*e7776783SApple OSS Distributions  * the corefile and call the callback with the following for each:
171*e7776783SApple OSS Distributions  *
172*e7776783SApple OSS Distributions  * seg_data -- A pointer to the segment data (mapped in the kernel's address space)
173*e7776783SApple OSS Distributions  * length   -- Length of the data to be copied from the segment
174*e7776783SApple OSS Distributions  * context  -- Passed to kcc_coredump_save_segment_data routine
175*e7776783SApple OSS Distributions  */
176*e7776783SApple OSS Distributions typedef kern_return_t (*core_save_segment_data_cb)(void *seg_data, uint64_t length, void *context);
177*e7776783SApple OSS Distributions 
178*e7776783SApple OSS Distributions /*
179*e7776783SApple OSS Distributions  * The core_save_note_data_cb callback is provided with the call to the
180*e7776783SApple OSS Distributions  * kcc_coredump_save_note_data routine that was registered.
181*e7776783SApple OSS Distributions  *
182*e7776783SApple OSS Distributions  * It's expected that the caller should iterate all of the notes they want to include in
183*e7776783SApple OSS Distributions  * the corefile and call the callback with the following for each:
184*e7776783SApple OSS Distributions  *
185*e7776783SApple OSS Distributions  * note_data    -- A pointer to the payload data for this LC_NOTE (mapped in the kernel's address space)
186*e7776783SApple OSS Distributions  * length       -- length of the payload for this LC_NOTE
187*e7776783SApple OSS Distributions  * context      -- Passed to kcc_coredump_save_note_data routine
188*e7776783SApple OSS Distributions  */
189*e7776783SApple OSS Distributions typedef kern_return_t (*core_save_note_data_cb)(void *note_data, uint64_t length, void *context);
190*e7776783SApple OSS Distributions 
191*e7776783SApple OSS Distributions /*
192*e7776783SApple OSS Distributions  * deprecated - please switch to core_save_note*
193*e7776783SApple OSS Distributions  *
194*e7776783SApple OSS Distributions  * The core_save_misc_data callback is provided with the call to the
195*e7776783SApple OSS Distributions  * kcc_coredump_save_misc_data routine that was registered
196*e7776783SApple OSS Distributions  *
197*e7776783SApple OSS Distributions  * The caller should call the callback with the following:
198*e7776783SApple OSS Distributions  *
199*e7776783SApple OSS Distributions  * misc_data -- A pointer to the data to be copied
200*e7776783SApple OSS Distributions  * length    -- The length of the data to be copied
201*e7776783SApple OSS Distributions  * context   -- Passed to kcc_coredump_save_misc_data routine
202*e7776783SApple OSS Distributions  */
203*e7776783SApple OSS Distributions typedef kern_return_t (*core_save_misc_data_cb)(void *misc_data, uint64_t length, void *context);
204*e7776783SApple OSS Distributions 
205*e7776783SApple OSS Distributions typedef struct {
206*e7776783SApple OSS Distributions 	kern_return_t (*kcc_coredump_init)(void *refcon, void *context); /* OPTIONAL -- return KERN_NODE_DOWN if the co-processor should be skipped */
207*e7776783SApple OSS Distributions 	kern_return_t (*kcc_coredump_get_summary)(void *refcon, core_save_summary_cb callback, void *context);
208*e7776783SApple OSS Distributions 	kern_return_t (*kcc_coredump_save_segment_descriptions)(void *refcon, core_save_segment_descriptions_cb callback, void *context);
209*e7776783SApple OSS Distributions 	kern_return_t (*kcc_coredump_save_thread_state)(void *refcon, void *buf, core_save_thread_state_cb callback, void *context);
210*e7776783SApple OSS Distributions 	kern_return_t (*kcc_coredump_save_sw_vers)(void *refcon, core_save_sw_vers_cb callback, void *context) __deprecated_msg("please switch to kcc_coredump_save_sw_vers_detail");
211*e7776783SApple OSS Distributions 	kern_return_t (*kcc_coredump_save_segment_data)(void *refcon, core_save_segment_data_cb callback, void *context);
212*e7776783SApple OSS Distributions 	kern_return_t (*kcc_coredump_save_misc_data)(void *refcon, core_save_misc_data_cb callback, void *context) __deprecated_msg("please switch to kcc_coredump_save_note_*");
213*e7776783SApple OSS Distributions 	/* End of version 1 */
214*e7776783SApple OSS Distributions 	kern_return_t (*kcc_coredump_save_note_summary)(void *refcon, core_save_note_summary_cb callback, void *context);
215*e7776783SApple OSS Distributions 	kern_return_t (*kcc_coredump_save_note_descriptions)(void *refcon, core_save_note_descriptions_cb callback, void *context);
216*e7776783SApple OSS Distributions 	kern_return_t (*kcc_coredump_save_note_data)(void *refcon, core_save_note_data_cb callback, void *context);
217*e7776783SApple OSS Distributions 	kern_return_t (*kcc_coredump_save_sw_vers_detail)(void *refcon, core_save_sw_vers_detail_cb callback, void *context);
218*e7776783SApple OSS Distributions 	/* End of version 2 */
219*e7776783SApple OSS Distributions } kern_coredump_callback_config;
220*e7776783SApple OSS Distributions 
221*e7776783SApple OSS Distributions #define KERN_COREDUMP_MAX_CORES 64
222*e7776783SApple OSS Distributions #define KERN_COREDUMP_MIN_CONFIG_VERSION 1
223*e7776783SApple OSS Distributions #define KERN_COREDUMP_MIN_CONFIG_NOTES 2
224*e7776783SApple OSS Distributions #define KERN_COREDUMP_CONFIG_VERSION 2
225*e7776783SApple OSS Distributions #define KERN_COREDUMP_VERSIONSTRINGMAXSIZE 256
226*e7776783SApple OSS Distributions 
227*e7776783SApple OSS Distributions /*
228*e7776783SApple OSS Distributions  * kern_register_coredump_helper is called to register a core with the kernel
229*e7776783SApple OSS Distributions  * coredump infrastructure. In addition to the callback config and version of the config
230*e7776783SApple OSS Distributions  * structure, a description of the core should be provided -- i.e.: AP
231*e7776783SApple OSS Distributions  */
232*e7776783SApple OSS Distributions kern_return_t kern_register_coredump_helper(int kern_coredump_config_vers, const kern_coredump_callback_config *kc_callbacks, void *refcon,
233*e7776783SApple OSS Distributions     const char *core_description, boolean_t is64bit, uint32_t mh_magic, cpu_type_t cpu_type, cpu_subtype_t cpu_subtype);
234*e7776783SApple OSS Distributions 
235*e7776783SApple OSS Distributions #if PRIVATE
236*e7776783SApple OSS Distributions 
237*e7776783SApple OSS Distributions kern_return_t kern_register_xnu_coredump_helper(kern_coredump_callback_config *kc_callbacks);
238*e7776783SApple OSS Distributions 
239*e7776783SApple OSS Distributions kern_return_t kern_do_coredump(void *core_outvars, boolean_t kernel_only, uint64_t first_file_offset, uint64_t *last_file_offset);
240*e7776783SApple OSS Distributions 
241*e7776783SApple OSS Distributions #define KERN_COREDUMP_MAXDEBUGLOGSIZE 16384
242*e7776783SApple OSS Distributions #define KERN_COREDUMP_BEGIN_FILEBYTES_ALIGN 4096
243*e7776783SApple OSS Distributions #define KERN_COREDUMP_THREADSIZE_MAX 1024
244*e7776783SApple OSS Distributions 
245*e7776783SApple OSS Distributions #endif /* PRIVATE */
246*e7776783SApple OSS Distributions 
247*e7776783SApple OSS Distributions __END_DECLS
248*e7776783SApple OSS Distributions #endif /* _PROCESSOR_CORE_H_ */
249