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