]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/debug.c
xnu-3247.10.11.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");
1c79356b 320 printf("double panic: We are hanging here...\n");
2d21ac55 321 panic_stop();
1c79356b
A
322 /* NOTREACHED */
323 }
324 }
325 panicstr = str;
326 paniccpu = cpu_number();
327 panicwait = 1;
328
329 PANIC_UNLOCK();
316670eb
A
330 return(s);
331}
1c79356b 332
316670eb
A
333
334static void
335panic_epilogue(spl_t s)
336{
1c79356b
A
337 /*
338 * Release panicstr so that we can handle normally other panics.
339 */
340 PANIC_LOCK();
341 panicstr = (char *)0;
342 PANIC_UNLOCK();
2d21ac55 343
55e303ae 344 if (return_on_panic) {
2d21ac55 345 panic_normal();
55e303ae
A
346 enable_preemption();
347 splx(s);
1c79356b 348 return;
55e303ae 349 }
9bccf70c 350 kdb_printf("panic: We are hanging here...\n");
2d21ac55 351 panic_stop();
1c79356b
A
352 /* NOTREACHED */
353}
354
316670eb
A
355void
356panic(const char *str, ...)
357{
358 va_list listp;
359 spl_t s;
3e170ce0 360 boolean_t old_doprnt_hide_pointers = doprnt_hide_pointers;
316670eb 361
39236c6e 362
316670eb
A
363 /* panic_caller is initialized to 0. If set, don't change it */
364 if ( ! panic_caller )
365 panic_caller = (unsigned long)(char *)__builtin_return_address(0);
366
367 s = panic_prologue(str);
3e170ce0
A
368
369 /* Never hide pointers from panic logs. */
370 doprnt_hide_pointers = FALSE;
371
316670eb
A
372 kdb_printf("panic(cpu %d caller 0x%lx): ", (unsigned) paniccpu, panic_caller);
373 if (str) {
374 va_start(listp, str);
375 _doprnt(str, &listp, consdebug_putc, 0);
376 va_end(listp);
377 }
378 kdb_printf("\n");
379
380 /*
381 * Release panicwait indicator so that other cpus may call Debugger().
382 */
383 panicwait = 0;
384 Debugger("panic");
3e170ce0
A
385
386 doprnt_hide_pointers = old_doprnt_hide_pointers;
387
316670eb
A
388 panic_epilogue(s);
389}
390
391void
392panic_context(unsigned int reason, void *ctx, const char *str, ...)
393{
394 va_list listp;
395 spl_t s;
396
39236c6e 397
316670eb
A
398 /* panic_caller is initialized to 0. If set, don't change it */
399 if ( ! panic_caller )
400 panic_caller = (unsigned long)(char *)__builtin_return_address(0);
401
402 s = panic_prologue(str);
403 kdb_printf("panic(cpu %d caller 0x%lx): ", (unsigned) paniccpu, panic_caller);
404 if (str) {
405 va_start(listp, str);
406 _doprnt(str, &listp, consdebug_putc, 0);
407 va_end(listp);
408 }
409 kdb_printf("\n");
410
411 /*
412 * Release panicwait indicator so that other cpus may call Debugger().
413 */
414 panicwait = 0;
415 DebuggerWithContext(reason, ctx, "panic");
416 panic_epilogue(s);
417}
418
1c79356b 419void
2d21ac55 420log(__unused int level, char *fmt, ...)
1c79356b
A
421{
422 va_list listp;
1c79356b
A
423
424#ifdef lint
425 level++;
426#endif /* lint */
427#ifdef MACH_BSD
428 disable_preemption();
429 va_start(listp, fmt);
430 _doprnt(fmt, &listp, conslog_putc, 0);
431 va_end(listp);
432 enable_preemption();
433#endif
434}
9bccf70c 435
9bccf70c
A
436void
437debug_putc(char c)
438{
2d21ac55 439 if ((debug_buf_size != 0) &&
fe8ab488 440 ((debug_buf_ptr-debug_buf_addr) < (int)debug_buf_size)) {
9bccf70c
A
441 *debug_buf_ptr=c;
442 debug_buf_ptr++;
443 }
444}
2d21ac55
A
445
446/* In-place packing routines -- inefficient, but they're called at most once.
6d2010ae 447 * Assumes "buflen" is a multiple of 8.
2d21ac55
A
448 */
449
450int packA(char *inbuf, uint32_t length, uint32_t buflen)
451{
452 unsigned int i, j = 0;
453 pasc_t pack;
454
6d2010ae 455 length = MIN(((length + 7) & ~7), buflen);
2d21ac55
A
456
457 for (i = 0; i < length; i+=8)
458 {
459 pack.a = inbuf[i];
460 pack.b = inbuf[i+1];
461 pack.c = inbuf[i+2];
462 pack.d = inbuf[i+3];
463 pack.e = inbuf[i+4];
464 pack.f = inbuf[i+5];
465 pack.g = inbuf[i+6];
466 pack.h = inbuf[i+7];
467 bcopy ((char *) &pack, inbuf + j, 7);
468 j += 7;
469 }
6d2010ae 470 return j;
2d21ac55
A
471}
472
473void unpackA(char *inbuf, uint32_t length)
474{
475 pasc_t packs;
476 unsigned i = 0;
477 length = (length * 8)/7;
478
479 while (i < length) {
480 packs = *(pasc_t *)&inbuf[i];
481 bcopy(&inbuf[i+7], &inbuf[i+8], MAX(0, (int) (length - i - 8)));
482 inbuf[i++] = packs.a;
483 inbuf[i++] = packs.b;
484 inbuf[i++] = packs.c;
485 inbuf[i++] = packs.d;
486 inbuf[i++] = packs.e;
487 inbuf[i++] = packs.f;
488 inbuf[i++] = packs.g;
489 inbuf[i++] = packs.h;
490 }
491}
492
493extern void *proc_name_address(void *p);
494
495static void
496panic_display_process_name(void) {
3e170ce0
A
497 /* because of scoping issues len(p_comm) from proc_t is hard coded here */
498 char proc_name[17] = "Unknown";
2d21ac55
A
499 task_t ctask = 0;
500 void *cbsd_info = 0;
501
502 if (ml_nofault_copy((vm_offset_t)&current_thread()->task, (vm_offset_t) &ctask, sizeof(task_t)) == sizeof(task_t))
3e170ce0 503 if(ml_nofault_copy((vm_offset_t)&ctask->bsd_info, (vm_offset_t)&cbsd_info, sizeof(cbsd_info)) == sizeof(cbsd_info))
2d21ac55
A
504 if (cbsd_info && (ml_nofault_copy((vm_offset_t) proc_name_address(cbsd_info), (vm_offset_t) &proc_name, sizeof(proc_name)) > 0))
505 proc_name[sizeof(proc_name) - 1] = '\0';
506 kdb_printf("\nBSD process name corresponding to current thread: %s\n", proc_name);
507}
508
509unsigned panic_active(void) {
510 return ((panicstr != (char *) 0));
511}
512
513void populate_model_name(char *model_string) {
514 strlcpy(model_name, model_string, sizeof(model_name));
515}
516
04b8595b 517void panic_display_model_name(void) {
2d21ac55
A
518 char tmp_model_name[sizeof(model_name)];
519
520 if (ml_nofault_copy((vm_offset_t) &model_name, (vm_offset_t) &tmp_model_name, sizeof(model_name)) != sizeof(model_name))
521 return;
522
6d2010ae
A
523 tmp_model_name[sizeof(tmp_model_name) - 1] = '\0';
524
525 if (tmp_model_name[0] != 0)
526 kdb_printf("System model name: %s\n", tmp_model_name);
527}
528
04b8595b 529void panic_display_kernel_uuid(void) {
39236c6e 530 char tmp_kernel_uuid[sizeof(kernel_uuid_string)];
6d2010ae 531
39236c6e 532 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 533 return;
2d21ac55 534
6d2010ae
A
535 if (tmp_kernel_uuid[0] != '\0')
536 kdb_printf("Kernel UUID: %s\n", tmp_kernel_uuid);
2d21ac55
A
537}
538
39236c6e 539void panic_display_kernel_aslr(void) {
316670eb 540 if (vm_kernel_slide) {
39236c6e 541 kdb_printf("Kernel slide: 0x%016lx\n", (unsigned long) vm_kernel_slide);
316670eb
A
542 kdb_printf("Kernel text base: %p\n", (void *) vm_kernel_stext);
543 }
316670eb
A
544}
545
fe8ab488
A
546void panic_display_hibb(void) {
547#if defined(__i386__) || defined (__x86_64__)
548 kdb_printf("__HIB text base: %p\n", (void *) vm_hib_base);
549#endif
550}
551
c910b4d9
A
552static void panic_display_uptime(void) {
553 uint64_t uptime;
554 absolutetime_to_nanoseconds(mach_absolute_time(), &uptime);
555
556 kdb_printf("\nSystem uptime in nanoseconds: %llu\n", uptime);
557}
558
2d21ac55
A
559extern const char version[];
560extern char osversion[];
561
6d2010ae
A
562static volatile uint32_t config_displayed = 0;
563
2d21ac55 564__private_extern__ void panic_display_system_configuration(void) {
2d21ac55
A
565
566 panic_display_process_name();
6d2010ae
A
567 if (OSCompareAndSwap(0, 1, &config_displayed)) {
568 char buf[256];
569 if (strlcpy(buf, PE_boot_args(), sizeof(buf)))
570 kdb_printf("Boot args: %s\n", buf);
2d21ac55
A
571 kdb_printf("\nMac OS version:\n%s\n",
572 (osversion[0] != 0) ? osversion : "Not yet set");
573 kdb_printf("\nKernel version:\n%s\n",version);
6d2010ae 574 panic_display_kernel_uuid();
316670eb 575 panic_display_kernel_aslr();
fe8ab488 576 panic_display_hibb();
6d2010ae 577 panic_display_pal_info();
2d21ac55 578 panic_display_model_name();
c910b4d9 579 panic_display_uptime();
b0d623f7 580 panic_display_zprint();
6d2010ae
A
581#if CONFIG_ZLEAKS
582 panic_display_ztrace();
583#endif /* CONFIG_ZLEAKS */
b0d623f7 584 kext_dump_panic_lists(&kdb_log);
2d21ac55
A
585 }
586}
587
c910b4d9
A
588extern zone_t first_zone;
589extern unsigned int num_zones, stack_total;
6d2010ae 590extern unsigned long long stack_allocs;
c910b4d9 591
b0d623f7 592#if defined(__i386__) || defined (__x86_64__)
c910b4d9 593extern unsigned int inuse_ptepages_count;
6d2010ae 594extern long long alloc_ptepages_count;
c910b4d9
A
595#endif
596
597extern boolean_t panic_include_zprint;
3e170ce0
A
598extern vm_offset_t panic_kext_memory_info;
599extern vm_size_t panic_kext_memory_size;
c910b4d9
A
600
601__private_extern__ void panic_display_zprint()
602{
603 if(panic_include_zprint == TRUE) {
604
605 unsigned int i;
606 struct zone zone_copy;
607
3e170ce0 608 kdb_printf("%-20s %10s %10s\n", "Zone Name", "Cur Size", "Free Size");
c910b4d9
A
609 if(first_zone!=NULL) {
610 if(ml_nofault_copy((vm_offset_t)first_zone, (vm_offset_t)&zone_copy, sizeof(struct zone)) == sizeof(struct zone)) {
611 for (i = 0; i < num_zones; i++) {
612 if(zone_copy.cur_size > (1024*1024)) {
3e170ce0 613 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
614 }
615
616 if(zone_copy.next_zone == NULL) {
617 break;
618 }
619
620 if(ml_nofault_copy((vm_offset_t)zone_copy.next_zone, (vm_offset_t)&zone_copy, sizeof(struct zone)) != sizeof(struct zone)) {
621 break;
622 }
623 }
624 }
625 }
626
3e170ce0 627 kdb_printf("%-20s %10lu\n", "Kernel Stacks", (uintptr_t)(kernel_stack_size * stack_total));
b0d623f7
A
628
629#if defined(__i386__) || defined (__x86_64__)
3e170ce0 630 kdb_printf("%-20s %10lu\n", "PageTables",(uintptr_t)(PAGE_SIZE * inuse_ptepages_count));
c910b4d9 631#endif
b0d623f7 632
3e170ce0
A
633 kdb_printf("%-20s %10lu\n", "Kalloc.Large", (uintptr_t)kalloc_large_total);
634 if (panic_kext_memory_info) {
635 mach_memory_info_t *mem_info = (mach_memory_info_t *)panic_kext_memory_info;
636 kdb_printf("\n%-5s %10s\n", "Kmod", "Size");
637 for (i = 0; i < VM_KERN_MEMORY_COUNT + VM_KERN_COUNTER_COUNT; i++) {
638 if (((mem_info[i].flags & VM_KERN_SITE_TYPE) == VM_KERN_SITE_KMOD) && (mem_info[i].size > (1024 * 1024))) {
639 kdb_printf("%-5lld %10lld\n", mem_info[i].site, mem_info[i].size);
640 }
641 }
642 }
c910b4d9
A
643 }
644}
645
fe8ab488
A
646#if CONFIG_ECC_LOGGING
647__private_extern__ void panic_display_ecc_errors()
648{
649 uint32_t count = ecc_log_get_correction_count();
650
651 if (count > 0) {
652 kdb_printf("ECC Corrections:%u\n", count);
653 }
654}
655#endif /* CONFIG_ECC_LOGGING */
656
6d2010ae
A
657#if CONFIG_ZLEAKS
658extern boolean_t panic_include_ztrace;
659extern struct ztrace* top_ztrace;
04b8595b
A
660void panic_print_symbol_name(vm_address_t search);
661
6d2010ae
A
662/*
663 * Prints the backtrace most suspected of being a leaker, if we paniced in the zone allocator.
664 * top_ztrace and panic_include_ztrace comes from osfmk/kern/zalloc.c
665 */
666__private_extern__ void panic_display_ztrace(void)
667{
668 if(panic_include_ztrace == TRUE) {
669 unsigned int i = 0;
04b8595b
A
670 boolean_t keepsyms = FALSE;
671
672 PE_parse_boot_argn("keepsyms", &keepsyms, sizeof (keepsyms));
6d2010ae
A
673 struct ztrace top_ztrace_copy;
674
675 /* Make sure not to trip another panic if there's something wrong with memory */
676 if(ml_nofault_copy((vm_offset_t)top_ztrace, (vm_offset_t)&top_ztrace_copy, sizeof(struct ztrace)) == sizeof(struct ztrace)) {
677 kdb_printf("\nBacktrace suspected of leaking: (outstanding bytes: %lu)\n", (uintptr_t)top_ztrace_copy.zt_size);
678 /* Print the backtrace addresses */
679 for (i = 0; (i < top_ztrace_copy.zt_depth && i < MAX_ZTRACE_DEPTH) ; i++) {
04b8595b
A
680 kdb_printf("%p ", top_ztrace_copy.zt_stack[i]);
681 if (keepsyms) {
682 panic_print_symbol_name((vm_address_t)top_ztrace_copy.zt_stack[i]);
683 }
684 kdb_printf("\n");
6d2010ae
A
685 }
686 /* Print any kexts in that backtrace, along with their link addresses so we can properly blame them */
687 kmod_panic_dump((vm_offset_t *)&top_ztrace_copy.zt_stack[0], top_ztrace_copy.zt_depth);
688 }
689 else {
690 kdb_printf("\nCan't access top_ztrace...\n");
691 }
692 kdb_printf("\n");
693 }
694}
695#endif /* CONFIG_ZLEAKS */
696
fe8ab488 697#if ! (MACH_KDP && CONFIG_KDP_INTERACTIVE_DEBUGGING)
39236c6e 698static struct kdp_ether_addr kdp_current_mac_address = {{0, 0, 0, 0, 0, 0}};
2d21ac55
A
699
700/* XXX ugly forward declares to stop warnings */
701void *kdp_get_interface(void);
39236c6e 702void kdp_set_ip_and_mac_addresses(struct kdp_in_addr *, struct kdp_ether_addr *);
2d21ac55
A
703void kdp_set_gateway_mac(void *);
704void kdp_set_interface(void *);
705void kdp_register_send_receive(void *, void *);
706void kdp_unregister_send_receive(void *, void *);
3e170ce0 707void kdp_snapshot_preflight(int, void *, uint32_t, uint32_t, kcdata_descriptor_t, boolean_t enable_faulting);
2d21ac55 708int kdp_stack_snapshot_geterror(void);
3e170ce0 709uint32_t kdp_stack_snapshot_bytes_traced(void);
2d21ac55
A
710
711void *
712kdp_get_interface( void)
713{
714 return(void *)0;
715}
716
717unsigned int
718kdp_get_ip_address(void )
719{ return 0; }
720
39236c6e 721struct kdp_ether_addr
2d21ac55
A
722kdp_get_mac_addr(void)
723{
724 return kdp_current_mac_address;
725}
726
727void
728kdp_set_ip_and_mac_addresses(
39236c6e
A
729 __unused struct kdp_in_addr *ipaddr,
730 __unused struct kdp_ether_addr *macaddr)
2d21ac55
A
731{}
732
733void
734kdp_set_gateway_mac(__unused void *gatewaymac)
735{}
736
737void
738kdp_set_interface(__unused void *ifp)
739{}
740
741void
742kdp_register_send_receive(__unused void *send, __unused void *receive)
743{}
744
745void
746kdp_unregister_send_receive(__unused void *send, __unused void *receive)
747{}
748
fe8ab488 749void kdp_register_link(__unused kdp_link_t link, __unused kdp_mode_t mode)
2d21ac55
A
750{}
751
fe8ab488
A
752void kdp_unregister_link(__unused kdp_link_t link, __unused kdp_mode_t mode)
753{}
2d21ac55
A
754
755#endif
39236c6e
A
756
757#if !CONFIG_TELEMETRY
758int telemetry_gather(user_addr_t buffer __unused, uint32_t *length __unused, boolean_t mark __unused)
759{
760 return KERN_NOT_SUPPORTED;
761}
762#endif