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