]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kdp/kdp_core.h
xnu-6153.11.26.tar.gz
[apple/xnu.git] / osfmk / kdp / kdp_core.h
1 /*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 /* HISTORY
30 * 8 Aug. 2003 - Created (Derek Kumar)
31 */
32
33 /* Various protocol definitions
34 * for the core transfer protocol, which is a variant of TFTP
35 */
36 #ifndef __KDP_CORE_H
37 #define __KDP_CORE_H
38
39 #include <kern/thread.h>
40 #include <kdp/kdp_protocol.h>
41 #include <string.h>
42
43 /*
44 * Packet types.
45 */
46 #define KDP_RRQ 1 /* read request */
47 #define KDP_WRQ 2 /* write request */
48 #define KDP_DATA 3 /* data packet */
49 #define KDP_ACK 4 /* acknowledgement */
50 #define KDP_ERROR 5 /* error code */
51 #define KDP_SEEK 6 /* Seek to specified offset */
52 #define KDP_EOF 7 /* signal end of file */
53 #define KDP_FLUSH 8 /* flush outstanding data */
54 #define KDP_FEATURE_MASK_STRING "features"
55
56 enum {KDP_FEATURE_LARGE_CRASHDUMPS = 1, KDP_FEATURE_LARGE_PKT_SIZE = 2};
57 extern uint32_t kdp_feature_large_crashdumps, kdp_feature_large_pkt_size;
58
59 struct corehdr {
60 short th_opcode; /* packet type */
61 union {
62 unsigned int tu_block; /* block # */
63 unsigned int tu_code; /* error code */
64 char tu_rpl[1]; /* request packet payload */
65 } th_u;
66 char th_data[0]; /* data or error string */
67 }__attribute__((packed));
68
69 #define th_block th_u.tu_block
70 #define th_code th_u.tu_code
71 #define th_stuff th_u.tu_rpl
72 #define th_msg th_data
73
74 /*
75 * Error codes.
76 */
77 #define EUNDEF 0 /* not defined */
78 #define ENOTFOUND 1 /* file not found */
79 #define EACCESS 2 /* access violation */
80 #define ENOSPACE 3 /* disk full or allocation exceeded */
81 #define EBADOP 4 /* illegal TFTP operation */
82 #define EBADID 5 /* unknown transfer ID */
83 #define EEXISTS 6 /* file already exists */
84 #define ENOUSER 7 /* no such user */
85
86 #define CORE_REMOTE_PORT 1069 /* hardwired, we can't really query the services file */
87
88 #if CONFIG_EMBEDDED
89 /*
90 * xnu shared memory hardware debugger support
91 *
92 * A hardware debugger can connect, read the consistent debug
93 * header to determine the physical location of the handshake
94 * structure and communicate using commands in the structure as
95 * defined below.
96 *
97 * Currently used for sending compressed coredumps to
98 * astris.
99 */
100 struct xnu_hw_shmem_dbg_command_info {
101 volatile uint32_t xhsdci_status;
102 uint32_t xhsdci_seq_no;
103 volatile uint64_t xhsdci_buf_phys_addr;
104 volatile uint32_t xhsdci_buf_data_length;
105 /* end of version 0 structure */
106 uint64_t xhsdci_coredump_total_size_uncomp;
107 uint64_t xhsdci_coredump_total_size_sent_uncomp;
108 uint32_t xhsdci_page_size;
109 } __attribute__((packed));
110
111 #define CUR_XNU_HWSDCI_STRUCT_VERS 1
112
113 #define XHSDCI_STATUS_NONE 0 /* default status */
114 #define XHSDCI_STATUS_KERNEL_BUSY 1 /* kernel is busy with other procedure */
115 #define XHSDCI_STATUS_KERNEL_READY 2 /* kernel ready to begin command */
116 #define XHSDCI_COREDUMP_BEGIN 3 /* indicates hardware debugger is ready to begin consuming coredump info */
117 #define XHSDCI_COREDUMP_BUF_READY 4 /* indicates the kernel has populated the buffer */
118 #define XHSDCI_COREDUMP_BUF_EMPTY 5 /* indicates hardware debugger is done consuming the current data */
119 #define XHSDCI_COREDUMP_STATUS_DONE 6 /* indicates last compressed data is in buffer */
120 #define XHSDCI_COREDUMP_ERROR 7 /* indicates an error was encountered */
121 #define XHSDCI_COREDUMP_REMOTE_DONE 8 /* indicates that hardware debugger is done */
122
123 void panic_spin_shmcon(void);
124
125 #endif /* CONFIG_EMBEDDED */
126
127 void kdp_panic_dump(void);
128 void begin_panic_transfer(void);
129 void abort_panic_transfer(void);
130 void kdp_set_dump_info(const uint32_t flags, const char *file, const char *destip,
131 const char *routerip, const uint32_t port);
132 void kdp_get_dump_info(kdp_dumpinfo_reply_t *rp);
133
134 enum kern_dump_type {
135 KERN_DUMP_DISK, /* local, on device core dump */
136 KERN_DUMP_NET, /* kdp network core dump */
137 #if CONFIG_EMBEDDED
138 KERN_DUMP_HW_SHMEM_DBG, /* coordinated hardware shared memory debugger core dump */
139 #endif
140 KERN_DUMP_STACKSHOT_DISK, /* local, stackshot on device coredump */
141 };
142
143 int kern_dump(enum kern_dump_type kd_variant);
144
145 boolean_t dumped_kernel_core(void);
146
147 struct corehdr *create_panic_header(unsigned int request, const char *corename, unsigned length, unsigned block);
148
149 int kdp_send_crashdump_pkt(unsigned int request, char *corename,
150 uint64_t length, void *panic_data);
151
152 int kdp_send_crashdump_data(unsigned int request, char *corename,
153 uint64_t length, void * txstart);
154
155 void kern_collectth_state_size(uint64_t * tstate_count, uint64_t * tstate_size);
156
157 void kern_collectth_state(thread_t thread, void *buffer, uint64_t size, void **iter);
158
159 boolean_t kdp_has_polled_corefile(void);
160 kern_return_t kdp_polled_corefile_error(void);
161
162 void kdp_core_init(void);
163
164 extern boolean_t kdp_corezip_disabled;
165
166 #define KDP_CRASHDUMP_POLL_COUNT (2500)
167
168 #if PRIVATE
169 kern_return_t kdp_core_output(void *kdp_core_out_vars, uint64_t length, void * data);
170
171 kern_return_t kdp_reset_output_vars(void *kdp_core_out_vars, uint64_t totalbytes);
172
173 int kern_dump_record_file(void *kdp_core_out_vars, const char *filename, uint64_t file_offset, uint64_t *out_file_length);
174
175 int kern_dump_seek_to_next_file(void *kdp_core_out_varss, uint64_t next_file_offset);
176
177 extern boolean_t efi_valid_page(ppnum_t ppn);
178 #if defined(__x86_64__)
179 #define EFI_VALID_PAGE(x) efi_valid_page(x)
180 #elif defined(__arm__) || defined(__arm64__)
181 #define EFI_VALID_PAGE(x) (FALSE)
182 #endif /* defined (__x86_64__) */
183
184 #endif /* PRIVATE */
185
186 #endif /* __KDP_CORE_H */