]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
39236c6e | 2 | * Copyright (c) 2000-2013 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
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. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | /* | |
32 | * Mach Operating System | |
33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University | |
34 | * All Rights Reserved. | |
35 | * | |
36 | * Permission to use, copy, modify and distribute this software and its | |
37 | * documentation is hereby granted, provided that both the copyright | |
38 | * notice and this permission notice appear in all copies of the | |
39 | * software, derivative works or modified versions, and any portions | |
40 | * thereof, and that both notices appear in supporting documentation. | |
41 | * | |
42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
45 | * | |
46 | * Carnegie Mellon requests users of this software to return to | |
47 | * | |
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
49 | * School of Computer Science | |
50 | * Carnegie Mellon University | |
51 | * Pittsburgh PA 15213-3890 | |
52 | * | |
53 | * any improvements or extensions that they make and grant Carnegie Mellon | |
54 | * the rights to redistribute these changes. | |
55 | */ | |
56 | ||
57 | #include <mach_assert.h> | |
1c79356b | 58 | #include <mach_kdp.h> |
1c79356b A |
59 | |
60 | #include <kern/cpu_number.h> | |
b0d623f7 | 61 | #include <kern/kalloc.h> |
1c79356b A |
62 | #include <kern/spl.h> |
63 | #include <kern/thread.h> | |
64 | #include <kern/assert.h> | |
65 | #include <kern/sched_prim.h> | |
66 | #include <kern/misc_protos.h> | |
c910b4d9 | 67 | #include <kern/clock.h> |
39236c6e | 68 | #include <kern/telemetry.h> |
fe8ab488 | 69 | #include <kern/ecc.h> |
9bccf70c | 70 | #include <vm/vm_kern.h> |
91447636 | 71 | #include <vm/pmap.h> |
1c79356b | 72 | #include <stdarg.h> |
fe8ab488 | 73 | #if !(MACH_KDP && CONFIG_KDP_INTERACTIVE_DEBUGGING) |
2d21ac55 A |
74 | #include <kdp/kdp_udp.h> |
75 | #endif | |
1c79356b | 76 | |
b0d623f7 | 77 | #if defined(__i386__) || defined(__x86_64__) |
2d21ac55 A |
78 | #include <i386/cpu_threads.h> |
79 | #include <i386/pmCPU.h> | |
80 | #endif | |
81 | ||
82 | #include <IOKit/IOPlatformExpert.h> | |
6d2010ae | 83 | #include <machine/pal_routines.h> |
2d21ac55 | 84 | |
b0d623f7 A |
85 | #include <sys/kdebug.h> |
86 | #include <libkern/OSKextLibPrivate.h> | |
6d2010ae A |
87 | #include <libkern/OSAtomic.h> |
88 | #include <libkern/kernel_mach_header.h> | |
89 | #include <uuid/uuid.h> | |
b0d623f7 | 90 | |
fe8ab488 A |
91 | #if (defined(__arm64__) || defined(NAND_PANIC_DEVICE)) && !defined(LEGACY_PANIC_LOGS) |
92 | #include <pexpert/pexpert.h> /* For gPanicBase */ | |
93 | #endif | |
94 | ||
1c79356b A |
95 | unsigned int halt_in_debugger = 0; |
96 | unsigned int switch_debugger = 0; | |
97 | unsigned int current_debugger = 0; | |
98 | unsigned int active_debugger = 0; | |
99 | unsigned int debug_mode=0; | |
2d21ac55 | 100 | unsigned int disable_debug_output = TRUE; |
1c79356b | 101 | unsigned int systemLogDiags = FALSE; |
91447636 | 102 | unsigned int panicDebugging = FALSE; |
2d21ac55 | 103 | unsigned int logPanicDataToScreen = FALSE; |
04b8595b | 104 | unsigned int kdebug_serial = FALSE; |
1c79356b A |
105 | |
106 | int mach_assert = 1; | |
107 | ||
55e303ae | 108 | const char *panicstr = (char *) 0; |
1c79356b A |
109 | decl_simple_lock_data(,panic_lock) |
110 | int paniccpu; | |
111 | volatile int panicwait; | |
91447636 | 112 | volatile unsigned int nestedpanic= 0; |
1c79356b A |
113 | unsigned int panic_is_inited = 0; |
114 | unsigned int return_on_panic = 0; | |
91447636 | 115 | unsigned long panic_caller; |
1c79356b | 116 | |
c910b4d9 | 117 | #define DEBUG_BUF_SIZE (3 * PAGE_SIZE) |
c910b4d9 | 118 | |
fe8ab488 A |
119 | /* debug_buf is directly linked with iBoot panic region for ARM64 targets */ |
120 | #if (defined(__arm64__) || defined(NAND_PANIC_DEVICE)) && !defined(LEGACY_PANIC_LOGS) | |
121 | char *debug_buf_addr = NULL; | |
122 | char *debug_buf_ptr = NULL; | |
123 | unsigned int debug_buf_size = 0; | |
124 | #else | |
c910b4d9 | 125 | char debug_buf[DEBUG_BUF_SIZE]; |
fe8ab488 | 126 | __used char *debug_buf_addr = debug_buf; |
c910b4d9 A |
127 | char *debug_buf_ptr = debug_buf; |
128 | unsigned int debug_buf_size = sizeof(debug_buf); | |
fe8ab488 | 129 | #endif |
2d21ac55 A |
130 | |
131 | static char model_name[64]; | |
39236c6e A |
132 | unsigned char *kernel_uuid; |
133 | /* uuid_string_t */ char kernel_uuid_string[37]; | |
2d21ac55 | 134 | |
316670eb A |
135 | static spl_t panic_prologue(const char *str); |
136 | static void panic_epilogue(spl_t s); | |
137 | ||
2d21ac55 A |
138 | struct pasc { |
139 | unsigned a: 7; | |
140 | unsigned b: 7; | |
141 | unsigned c: 7; | |
142 | unsigned d: 7; | |
143 | unsigned e: 7; | |
144 | unsigned f: 7; | |
145 | unsigned g: 7; | |
146 | unsigned h: 7; | |
147 | } __attribute__((packed)); | |
148 | ||
149 | typedef struct pasc pasc_t; | |
9bccf70c | 150 | |
b0d623f7 A |
151 | /* Prevent CPP from breaking the definition below */ |
152 | #if CONFIG_NO_PANIC_STRINGS | |
153 | #undef Assert | |
154 | #endif | |
155 | ||
fe8ab488 | 156 | void __attribute__((noinline)) |
1c79356b A |
157 | Assert( |
158 | const char *file, | |
159 | int line, | |
2d21ac55 | 160 | const char *expression |
2d21ac55 | 161 | ) |
1c79356b | 162 | { |
2d21ac55 A |
163 | int saved_return_on_panic; |
164 | ||
1c79356b A |
165 | if (!mach_assert) { |
166 | return; | |
167 | } | |
2d21ac55 A |
168 | |
169 | saved_return_on_panic = return_on_panic; | |
39236c6e A |
170 | |
171 | /* | |
172 | * If we don't have a debugger configured, returning from an | |
173 | * assert is a bad, bad idea; there is no guarantee that we | |
174 | * didn't simply assert before we were able to restart the | |
175 | * platform. | |
176 | */ | |
177 | if (current_debugger != NO_CUR_DB) | |
178 | return_on_panic = 1; | |
2d21ac55 A |
179 | |
180 | panic_plain("%s:%d Assertion failed: %s", file, line, expression); | |
181 | ||
182 | return_on_panic = saved_return_on_panic; | |
1c79356b A |
183 | } |
184 | ||
185 | /* | |
186 | * Carefully use the panic_lock. There's always a chance that | |
187 | * somehow we'll call panic before getting to initialize the | |
188 | * panic_lock -- in this case, we'll assume that the world is | |
189 | * in uniprocessor mode and just avoid using the panic lock. | |
190 | */ | |
191 | #define PANIC_LOCK() \ | |
192 | MACRO_BEGIN \ | |
193 | if (panic_is_inited) \ | |
194 | simple_lock(&panic_lock); \ | |
195 | MACRO_END | |
196 | ||
197 | #define PANIC_UNLOCK() \ | |
198 | MACRO_BEGIN \ | |
199 | if (panic_is_inited) \ | |
200 | simple_unlock(&panic_lock); \ | |
201 | MACRO_END | |
202 | ||
1c79356b A |
203 | void |
204 | panic_init(void) | |
205 | { | |
6d2010ae A |
206 | unsigned long uuidlen = 0; |
207 | void *uuid; | |
208 | ||
209 | uuid = getuuidfromheader(&_mh_execute_header, &uuidlen); | |
210 | if ((uuid != NULL) && (uuidlen == sizeof(uuid_t))) { | |
39236c6e A |
211 | kernel_uuid = uuid; |
212 | uuid_unparse_upper(*(uuid_t *)uuid, kernel_uuid_string); | |
6d2010ae A |
213 | } |
214 | ||
91447636 | 215 | simple_lock_init(&panic_lock, 0); |
1c79356b | 216 | panic_is_inited = 1; |
91447636 | 217 | panic_caller = 0; |
1c79356b A |
218 | } |
219 | ||
2d21ac55 A |
220 | void |
221 | debug_log_init(void) | |
222 | { | |
223 | if (debug_buf_size != 0) | |
224 | return; | |
fe8ab488 A |
225 | #if (defined(__arm64__) || defined(NAND_PANIC_DEVICE)) && !defined(LEGACY_PANIC_LOGS) |
226 | if (!gPanicBase) { | |
227 | printf("debug_log_init: Error!! gPanicBase is still not initialized\n"); | |
228 | return; | |
229 | } | |
230 | /* Shift debug buf start location and size by 8 bytes for magic header and crc value */ | |
231 | debug_buf_addr = (char*)gPanicBase + 8; | |
232 | debug_buf_ptr = debug_buf_addr; | |
233 | debug_buf_size = gPanicSize - 8; | |
234 | #else | |
235 | debug_buf_addr = debug_buf; | |
2d21ac55 | 236 | debug_buf_ptr = debug_buf; |
c910b4d9 | 237 | debug_buf_size = sizeof(debug_buf); |
fe8ab488 | 238 | #endif |
2d21ac55 A |
239 | } |
240 | ||
b0d623f7 | 241 | #if defined(__i386__) || defined(__x86_64__) |
2d21ac55 A |
242 | #define panic_stop() pmCPUHalt(PM_HALT_PANIC) |
243 | #define panic_safe() pmSafeMode(x86_lcpu(), PM_SAFE_FL_SAFE) | |
244 | #define panic_normal() pmSafeMode(x86_lcpu(), PM_SAFE_FL_NORMAL) | |
245 | #else | |
246 | #define panic_stop() { while (1) ; } | |
247 | #define panic_safe() | |
248 | #define panic_normal() | |
249 | #endif | |
250 | ||
b0d623f7 A |
251 | /* |
252 | * Prevent CPP from breaking the definition below, | |
253 | * since all clients get a #define to prepend line numbers | |
254 | */ | |
255 | #undef panic | |
256 | ||
257 | void _consume_panic_args(int a __unused, ...) | |
258 | { | |
6d2010ae | 259 | panic("panic"); |
b0d623f7 A |
260 | } |
261 | ||
fe8ab488 A |
262 | extern unsigned int write_trace_on_panic; |
263 | ||
316670eb A |
264 | static spl_t |
265 | panic_prologue(const char *str) | |
1c79356b | 266 | { |
1c79356b | 267 | spl_t s; |
1c79356b | 268 | |
fe8ab488 | 269 | if (write_trace_on_panic && kdebug_enable) { |
39236c6e A |
270 | if (get_preemption_level() == 0 && !ml_at_interrupt_context()) { |
271 | ml_set_interrupts_enabled(TRUE); | |
272 | kdbg_dump_trace_to_file("/var/tmp/panic.trace"); | |
273 | } | |
7ddcb079 A |
274 | } |
275 | ||
276 | s = splhigh(); | |
277 | disable_preemption(); | |
278 | ||
6d2010ae A |
279 | #if defined(__i386__) || defined(__x86_64__) |
280 | /* Attempt to display the unparsed panic string */ | |
281 | const char *tstr = str; | |
b0d623f7 | 282 | |
6d2010ae A |
283 | kprintf("Panic initiated, string: "); |
284 | while (tstr && *tstr) | |
285 | kprintf("%c", *tstr++); | |
286 | kprintf("\n"); | |
287 | #endif | |
1c79356b | 288 | |
2d21ac55 A |
289 | panic_safe(); |
290 | ||
9bccf70c | 291 | if( logPanicDataToScreen ) |
2d21ac55 | 292 | disable_debug_output = FALSE; |
9bccf70c | 293 | |
1c79356b | 294 | debug_mode = TRUE; |
91447636 | 295 | |
1c79356b A |
296 | restart: |
297 | PANIC_LOCK(); | |
316670eb | 298 | |
1c79356b A |
299 | if (panicstr) { |
300 | if (cpu_number() != paniccpu) { | |
301 | PANIC_UNLOCK(); | |
302 | /* | |
303 | * Wait until message has been printed to identify correct | |
304 | * cpu that made the first panic. | |
305 | */ | |
306 | while (panicwait) | |
307 | continue; | |
308 | goto restart; | |
309 | } else { | |
310 | nestedpanic +=1; | |
311 | PANIC_UNLOCK(); | |
312 | Debugger("double panic"); | |
1c79356b | 313 | printf("double panic: We are hanging here...\n"); |
2d21ac55 | 314 | panic_stop(); |
1c79356b A |
315 | /* NOTREACHED */ |
316 | } | |
317 | } | |
318 | panicstr = str; | |
319 | paniccpu = cpu_number(); | |
320 | panicwait = 1; | |
321 | ||
322 | PANIC_UNLOCK(); | |
316670eb A |
323 | return(s); |
324 | } | |
1c79356b | 325 | |
316670eb A |
326 | |
327 | static void | |
328 | panic_epilogue(spl_t s) | |
329 | { | |
1c79356b A |
330 | /* |
331 | * Release panicstr so that we can handle normally other panics. | |
332 | */ | |
333 | PANIC_LOCK(); | |
334 | panicstr = (char *)0; | |
335 | PANIC_UNLOCK(); | |
2d21ac55 | 336 | |
55e303ae | 337 | if (return_on_panic) { |
2d21ac55 | 338 | panic_normal(); |
55e303ae A |
339 | enable_preemption(); |
340 | splx(s); | |
1c79356b | 341 | return; |
55e303ae | 342 | } |
9bccf70c | 343 | kdb_printf("panic: We are hanging here...\n"); |
2d21ac55 | 344 | panic_stop(); |
1c79356b A |
345 | /* NOTREACHED */ |
346 | } | |
347 | ||
316670eb A |
348 | void |
349 | panic(const char *str, ...) | |
350 | { | |
351 | va_list listp; | |
352 | spl_t s; | |
353 | ||
39236c6e | 354 | |
316670eb A |
355 | /* panic_caller is initialized to 0. If set, don't change it */ |
356 | if ( ! panic_caller ) | |
357 | panic_caller = (unsigned long)(char *)__builtin_return_address(0); | |
358 | ||
359 | s = panic_prologue(str); | |
360 | kdb_printf("panic(cpu %d caller 0x%lx): ", (unsigned) paniccpu, panic_caller); | |
361 | if (str) { | |
362 | va_start(listp, str); | |
363 | _doprnt(str, &listp, consdebug_putc, 0); | |
364 | va_end(listp); | |
365 | } | |
366 | kdb_printf("\n"); | |
367 | ||
368 | /* | |
369 | * Release panicwait indicator so that other cpus may call Debugger(). | |
370 | */ | |
371 | panicwait = 0; | |
372 | Debugger("panic"); | |
373 | panic_epilogue(s); | |
374 | } | |
375 | ||
376 | void | |
377 | panic_context(unsigned int reason, void *ctx, const char *str, ...) | |
378 | { | |
379 | va_list listp; | |
380 | spl_t s; | |
381 | ||
39236c6e | 382 | |
316670eb A |
383 | /* panic_caller is initialized to 0. If set, don't change it */ |
384 | if ( ! panic_caller ) | |
385 | panic_caller = (unsigned long)(char *)__builtin_return_address(0); | |
386 | ||
387 | s = panic_prologue(str); | |
388 | kdb_printf("panic(cpu %d caller 0x%lx): ", (unsigned) paniccpu, panic_caller); | |
389 | if (str) { | |
390 | va_start(listp, str); | |
391 | _doprnt(str, &listp, consdebug_putc, 0); | |
392 | va_end(listp); | |
393 | } | |
394 | kdb_printf("\n"); | |
395 | ||
396 | /* | |
397 | * Release panicwait indicator so that other cpus may call Debugger(). | |
398 | */ | |
399 | panicwait = 0; | |
400 | DebuggerWithContext(reason, ctx, "panic"); | |
401 | panic_epilogue(s); | |
402 | } | |
403 | ||
1c79356b | 404 | void |
2d21ac55 | 405 | log(__unused int level, char *fmt, ...) |
1c79356b A |
406 | { |
407 | va_list listp; | |
1c79356b A |
408 | |
409 | #ifdef lint | |
410 | level++; | |
411 | #endif /* lint */ | |
412 | #ifdef MACH_BSD | |
413 | disable_preemption(); | |
414 | va_start(listp, fmt); | |
415 | _doprnt(fmt, &listp, conslog_putc, 0); | |
416 | va_end(listp); | |
417 | enable_preemption(); | |
418 | #endif | |
419 | } | |
9bccf70c | 420 | |
9bccf70c A |
421 | void |
422 | debug_putc(char c) | |
423 | { | |
2d21ac55 | 424 | if ((debug_buf_size != 0) && |
fe8ab488 | 425 | ((debug_buf_ptr-debug_buf_addr) < (int)debug_buf_size)) { |
9bccf70c A |
426 | *debug_buf_ptr=c; |
427 | debug_buf_ptr++; | |
428 | } | |
429 | } | |
2d21ac55 A |
430 | |
431 | /* In-place packing routines -- inefficient, but they're called at most once. | |
6d2010ae | 432 | * Assumes "buflen" is a multiple of 8. |
2d21ac55 A |
433 | */ |
434 | ||
435 | int packA(char *inbuf, uint32_t length, uint32_t buflen) | |
436 | { | |
437 | unsigned int i, j = 0; | |
438 | pasc_t pack; | |
439 | ||
6d2010ae | 440 | length = MIN(((length + 7) & ~7), buflen); |
2d21ac55 A |
441 | |
442 | for (i = 0; i < length; i+=8) | |
443 | { | |
444 | pack.a = inbuf[i]; | |
445 | pack.b = inbuf[i+1]; | |
446 | pack.c = inbuf[i+2]; | |
447 | pack.d = inbuf[i+3]; | |
448 | pack.e = inbuf[i+4]; | |
449 | pack.f = inbuf[i+5]; | |
450 | pack.g = inbuf[i+6]; | |
451 | pack.h = inbuf[i+7]; | |
452 | bcopy ((char *) &pack, inbuf + j, 7); | |
453 | j += 7; | |
454 | } | |
6d2010ae | 455 | return j; |
2d21ac55 A |
456 | } |
457 | ||
458 | void unpackA(char *inbuf, uint32_t length) | |
459 | { | |
460 | pasc_t packs; | |
461 | unsigned i = 0; | |
462 | length = (length * 8)/7; | |
463 | ||
464 | while (i < length) { | |
465 | packs = *(pasc_t *)&inbuf[i]; | |
466 | bcopy(&inbuf[i+7], &inbuf[i+8], MAX(0, (int) (length - i - 8))); | |
467 | inbuf[i++] = packs.a; | |
468 | inbuf[i++] = packs.b; | |
469 | inbuf[i++] = packs.c; | |
470 | inbuf[i++] = packs.d; | |
471 | inbuf[i++] = packs.e; | |
472 | inbuf[i++] = packs.f; | |
473 | inbuf[i++] = packs.g; | |
474 | inbuf[i++] = packs.h; | |
475 | } | |
476 | } | |
477 | ||
478 | extern void *proc_name_address(void *p); | |
479 | ||
480 | static void | |
481 | panic_display_process_name(void) { | |
482 | char proc_name[32] = "Unknown"; | |
483 | task_t ctask = 0; | |
484 | void *cbsd_info = 0; | |
485 | ||
486 | if (ml_nofault_copy((vm_offset_t)¤t_thread()->task, (vm_offset_t) &ctask, sizeof(task_t)) == sizeof(task_t)) | |
487 | if(ml_nofault_copy((vm_offset_t)&ctask->bsd_info, (vm_offset_t)&cbsd_info, sizeof(&ctask->bsd_info)) == sizeof(&ctask->bsd_info)) | |
488 | if (cbsd_info && (ml_nofault_copy((vm_offset_t) proc_name_address(cbsd_info), (vm_offset_t) &proc_name, sizeof(proc_name)) > 0)) | |
489 | proc_name[sizeof(proc_name) - 1] = '\0'; | |
490 | kdb_printf("\nBSD process name corresponding to current thread: %s\n", proc_name); | |
491 | } | |
492 | ||
493 | unsigned panic_active(void) { | |
494 | return ((panicstr != (char *) 0)); | |
495 | } | |
496 | ||
497 | void populate_model_name(char *model_string) { | |
498 | strlcpy(model_name, model_string, sizeof(model_name)); | |
499 | } | |
500 | ||
04b8595b | 501 | void panic_display_model_name(void) { |
2d21ac55 A |
502 | char tmp_model_name[sizeof(model_name)]; |
503 | ||
504 | if (ml_nofault_copy((vm_offset_t) &model_name, (vm_offset_t) &tmp_model_name, sizeof(model_name)) != sizeof(model_name)) | |
505 | return; | |
506 | ||
6d2010ae A |
507 | tmp_model_name[sizeof(tmp_model_name) - 1] = '\0'; |
508 | ||
509 | if (tmp_model_name[0] != 0) | |
510 | kdb_printf("System model name: %s\n", tmp_model_name); | |
511 | } | |
512 | ||
04b8595b | 513 | void panic_display_kernel_uuid(void) { |
39236c6e | 514 | char tmp_kernel_uuid[sizeof(kernel_uuid_string)]; |
6d2010ae | 515 | |
39236c6e | 516 | if (ml_nofault_copy((vm_offset_t) &kernel_uuid_string, (vm_offset_t) &tmp_kernel_uuid, sizeof(kernel_uuid_string)) != sizeof(kernel_uuid_string)) |
6d2010ae | 517 | return; |
2d21ac55 | 518 | |
6d2010ae A |
519 | if (tmp_kernel_uuid[0] != '\0') |
520 | kdb_printf("Kernel UUID: %s\n", tmp_kernel_uuid); | |
2d21ac55 A |
521 | } |
522 | ||
39236c6e | 523 | void panic_display_kernel_aslr(void) { |
316670eb | 524 | if (vm_kernel_slide) { |
39236c6e | 525 | kdb_printf("Kernel slide: 0x%016lx\n", (unsigned long) vm_kernel_slide); |
316670eb A |
526 | kdb_printf("Kernel text base: %p\n", (void *) vm_kernel_stext); |
527 | } | |
316670eb A |
528 | } |
529 | ||
fe8ab488 A |
530 | void panic_display_hibb(void) { |
531 | #if defined(__i386__) || defined (__x86_64__) | |
532 | kdb_printf("__HIB text base: %p\n", (void *) vm_hib_base); | |
533 | #endif | |
534 | } | |
535 | ||
c910b4d9 A |
536 | static void panic_display_uptime(void) { |
537 | uint64_t uptime; | |
538 | absolutetime_to_nanoseconds(mach_absolute_time(), &uptime); | |
539 | ||
540 | kdb_printf("\nSystem uptime in nanoseconds: %llu\n", uptime); | |
541 | } | |
542 | ||
2d21ac55 A |
543 | extern const char version[]; |
544 | extern char osversion[]; | |
545 | ||
6d2010ae A |
546 | static volatile uint32_t config_displayed = 0; |
547 | ||
2d21ac55 | 548 | __private_extern__ void panic_display_system_configuration(void) { |
2d21ac55 A |
549 | |
550 | panic_display_process_name(); | |
6d2010ae A |
551 | if (OSCompareAndSwap(0, 1, &config_displayed)) { |
552 | char buf[256]; | |
553 | if (strlcpy(buf, PE_boot_args(), sizeof(buf))) | |
554 | kdb_printf("Boot args: %s\n", buf); | |
2d21ac55 A |
555 | kdb_printf("\nMac OS version:\n%s\n", |
556 | (osversion[0] != 0) ? osversion : "Not yet set"); | |
557 | kdb_printf("\nKernel version:\n%s\n",version); | |
6d2010ae | 558 | panic_display_kernel_uuid(); |
316670eb | 559 | panic_display_kernel_aslr(); |
fe8ab488 | 560 | panic_display_hibb(); |
6d2010ae | 561 | panic_display_pal_info(); |
2d21ac55 | 562 | panic_display_model_name(); |
c910b4d9 | 563 | panic_display_uptime(); |
b0d623f7 | 564 | panic_display_zprint(); |
6d2010ae A |
565 | #if CONFIG_ZLEAKS |
566 | panic_display_ztrace(); | |
567 | #endif /* CONFIG_ZLEAKS */ | |
b0d623f7 | 568 | kext_dump_panic_lists(&kdb_log); |
2d21ac55 A |
569 | } |
570 | } | |
571 | ||
c910b4d9 A |
572 | extern zone_t first_zone; |
573 | extern unsigned int num_zones, stack_total; | |
6d2010ae | 574 | extern unsigned long long stack_allocs; |
c910b4d9 | 575 | |
b0d623f7 | 576 | #if defined(__i386__) || defined (__x86_64__) |
c910b4d9 | 577 | extern unsigned int inuse_ptepages_count; |
6d2010ae | 578 | extern long long alloc_ptepages_count; |
c910b4d9 A |
579 | #endif |
580 | ||
581 | extern boolean_t panic_include_zprint; | |
c910b4d9 A |
582 | |
583 | __private_extern__ void panic_display_zprint() | |
584 | { | |
585 | if(panic_include_zprint == TRUE) { | |
586 | ||
587 | unsigned int i; | |
588 | struct zone zone_copy; | |
589 | ||
590 | if(first_zone!=NULL) { | |
591 | if(ml_nofault_copy((vm_offset_t)first_zone, (vm_offset_t)&zone_copy, sizeof(struct zone)) == sizeof(struct zone)) { | |
592 | for (i = 0; i < num_zones; i++) { | |
593 | if(zone_copy.cur_size > (1024*1024)) { | |
594 | kdb_printf("%.20s:%lu\n",zone_copy.zone_name,(uintptr_t)zone_copy.cur_size); | |
595 | } | |
596 | ||
597 | if(zone_copy.next_zone == NULL) { | |
598 | break; | |
599 | } | |
600 | ||
601 | if(ml_nofault_copy((vm_offset_t)zone_copy.next_zone, (vm_offset_t)&zone_copy, sizeof(struct zone)) != sizeof(struct zone)) { | |
602 | break; | |
603 | } | |
604 | } | |
605 | } | |
606 | } | |
607 | ||
b0d623f7 A |
608 | kdb_printf("Kernel Stacks:%lu\n",(uintptr_t)(kernel_stack_size * stack_total)); |
609 | ||
610 | #if defined(__i386__) || defined (__x86_64__) | |
c910b4d9 A |
611 | kdb_printf("PageTables:%lu\n",(uintptr_t)(PAGE_SIZE * inuse_ptepages_count)); |
612 | #endif | |
b0d623f7 | 613 | |
c910b4d9 A |
614 | kdb_printf("Kalloc.Large:%lu\n",(uintptr_t)kalloc_large_total); |
615 | } | |
616 | } | |
617 | ||
fe8ab488 A |
618 | #if CONFIG_ECC_LOGGING |
619 | __private_extern__ void panic_display_ecc_errors() | |
620 | { | |
621 | uint32_t count = ecc_log_get_correction_count(); | |
622 | ||
623 | if (count > 0) { | |
624 | kdb_printf("ECC Corrections:%u\n", count); | |
625 | } | |
626 | } | |
627 | #endif /* CONFIG_ECC_LOGGING */ | |
628 | ||
6d2010ae A |
629 | #if CONFIG_ZLEAKS |
630 | extern boolean_t panic_include_ztrace; | |
631 | extern struct ztrace* top_ztrace; | |
04b8595b A |
632 | void panic_print_symbol_name(vm_address_t search); |
633 | ||
6d2010ae A |
634 | /* |
635 | * Prints the backtrace most suspected of being a leaker, if we paniced in the zone allocator. | |
636 | * top_ztrace and panic_include_ztrace comes from osfmk/kern/zalloc.c | |
637 | */ | |
638 | __private_extern__ void panic_display_ztrace(void) | |
639 | { | |
640 | if(panic_include_ztrace == TRUE) { | |
641 | unsigned int i = 0; | |
04b8595b A |
642 | boolean_t keepsyms = FALSE; |
643 | ||
644 | PE_parse_boot_argn("keepsyms", &keepsyms, sizeof (keepsyms)); | |
6d2010ae A |
645 | struct ztrace top_ztrace_copy; |
646 | ||
647 | /* Make sure not to trip another panic if there's something wrong with memory */ | |
648 | if(ml_nofault_copy((vm_offset_t)top_ztrace, (vm_offset_t)&top_ztrace_copy, sizeof(struct ztrace)) == sizeof(struct ztrace)) { | |
649 | kdb_printf("\nBacktrace suspected of leaking: (outstanding bytes: %lu)\n", (uintptr_t)top_ztrace_copy.zt_size); | |
650 | /* Print the backtrace addresses */ | |
651 | for (i = 0; (i < top_ztrace_copy.zt_depth && i < MAX_ZTRACE_DEPTH) ; i++) { | |
04b8595b A |
652 | kdb_printf("%p ", top_ztrace_copy.zt_stack[i]); |
653 | if (keepsyms) { | |
654 | panic_print_symbol_name((vm_address_t)top_ztrace_copy.zt_stack[i]); | |
655 | } | |
656 | kdb_printf("\n"); | |
6d2010ae A |
657 | } |
658 | /* Print any kexts in that backtrace, along with their link addresses so we can properly blame them */ | |
659 | kmod_panic_dump((vm_offset_t *)&top_ztrace_copy.zt_stack[0], top_ztrace_copy.zt_depth); | |
660 | } | |
661 | else { | |
662 | kdb_printf("\nCan't access top_ztrace...\n"); | |
663 | } | |
664 | kdb_printf("\n"); | |
665 | } | |
666 | } | |
667 | #endif /* CONFIG_ZLEAKS */ | |
668 | ||
fe8ab488 | 669 | #if ! (MACH_KDP && CONFIG_KDP_INTERACTIVE_DEBUGGING) |
39236c6e | 670 | static struct kdp_ether_addr kdp_current_mac_address = {{0, 0, 0, 0, 0, 0}}; |
2d21ac55 A |
671 | |
672 | /* XXX ugly forward declares to stop warnings */ | |
673 | void *kdp_get_interface(void); | |
39236c6e | 674 | void kdp_set_ip_and_mac_addresses(struct kdp_in_addr *, struct kdp_ether_addr *); |
2d21ac55 A |
675 | void kdp_set_gateway_mac(void *); |
676 | void kdp_set_interface(void *); | |
677 | void kdp_register_send_receive(void *, void *); | |
678 | void kdp_unregister_send_receive(void *, void *); | |
679 | void kdp_snapshot_preflight(int, void *, uint32_t, uint32_t); | |
680 | int kdp_stack_snapshot_geterror(void); | |
681 | int kdp_stack_snapshot_bytes_traced(void); | |
682 | ||
683 | void * | |
684 | kdp_get_interface( void) | |
685 | { | |
686 | return(void *)0; | |
687 | } | |
688 | ||
689 | unsigned int | |
690 | kdp_get_ip_address(void ) | |
691 | { return 0; } | |
692 | ||
39236c6e | 693 | struct kdp_ether_addr |
2d21ac55 A |
694 | kdp_get_mac_addr(void) |
695 | { | |
696 | return kdp_current_mac_address; | |
697 | } | |
698 | ||
699 | void | |
700 | kdp_set_ip_and_mac_addresses( | |
39236c6e A |
701 | __unused struct kdp_in_addr *ipaddr, |
702 | __unused struct kdp_ether_addr *macaddr) | |
2d21ac55 A |
703 | {} |
704 | ||
705 | void | |
706 | kdp_set_gateway_mac(__unused void *gatewaymac) | |
707 | {} | |
708 | ||
709 | void | |
710 | kdp_set_interface(__unused void *ifp) | |
711 | {} | |
712 | ||
713 | void | |
714 | kdp_register_send_receive(__unused void *send, __unused void *receive) | |
715 | {} | |
716 | ||
717 | void | |
718 | kdp_unregister_send_receive(__unused void *send, __unused void *receive) | |
719 | {} | |
720 | ||
fe8ab488 | 721 | void kdp_register_link(__unused kdp_link_t link, __unused kdp_mode_t mode) |
2d21ac55 A |
722 | {} |
723 | ||
fe8ab488 A |
724 | void kdp_unregister_link(__unused kdp_link_t link, __unused kdp_mode_t mode) |
725 | {} | |
2d21ac55 A |
726 | |
727 | #endif | |
39236c6e A |
728 | |
729 | #if !CONFIG_TELEMETRY | |
730 | int telemetry_gather(user_addr_t buffer __unused, uint32_t *length __unused, boolean_t mark __unused) | |
731 | { | |
732 | return KERN_NOT_SUPPORTED; | |
733 | } | |
734 | #endif |