2 * Copyright (c) 2000-2016 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
34 * All Rights Reserved.
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.
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.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
57 #include <mach_assert.h>
60 #include <kdp/kdp_core.h>
61 #include <kdp/kdp_internal.h>
62 #include <kdp/kdp_callout.h>
63 #include <kern/cpu_number.h>
64 #include <kern/kalloc.h>
66 #include <kern/thread.h>
67 #include <kern/assert.h>
68 #include <kern/sched_prim.h>
69 #include <kern/misc_protos.h>
70 #include <kern/clock.h>
71 #include <kern/telemetry.h>
73 #include <kern/kern_cdata.h>
74 #include <kern/zalloc.h>
75 #include <vm/vm_kern.h>
78 #include <stdatomic.h>
80 #include <console/serial_protos.h>
82 #if !(MACH_KDP && CONFIG_KDP_INTERACTIVE_DEBUGGING)
83 #include <kdp/kdp_udp.h>
85 #include <kern/processor.h>
87 #if defined(__i386__) || defined(__x86_64__)
88 #include <i386/cpu_threads.h>
89 #include <i386/pmCPU.h>
92 #include <IOKit/IOPlatformExpert.h>
93 #include <machine/pal_routines.h>
95 #include <sys/kdebug.h>
96 #include <libkern/OSKextLibPrivate.h>
97 #include <libkern/OSAtomic.h>
98 #include <libkern/kernel_mach_header.h>
99 #include <libkern/section_keywords.h>
100 #include <uuid/uuid.h>
101 #include <mach_debug/zone_info.h>
103 #include <os/log_private.h>
106 #include <pexpert/pexpert.h> /* For gPanicBase */
107 #include <arm/caches_internal.h>
108 #include <arm/misc_protos.h>
109 extern volatile struct xnu_hw_shmem_dbg_command_info
*hwsd_info
;
113 unsigned int halt_in_debugger
= 0;
114 unsigned int current_debugger
= 0;
115 unsigned int active_debugger
= 0;
116 unsigned int panicDebugging
= FALSE
;
117 unsigned int kdebug_serial
= FALSE
;
118 unsigned int kernel_debugger_entry_count
= 0;
122 #define TRAP_DEBUGGER __asm__ volatile("trap")
123 #elif defined(__arm64__)
125 * Magic number; this should be identical to the __arm__ encoding for trap.
127 #define TRAP_DEBUGGER __asm__ volatile(".long 0xe7ffdeff")
128 #elif defined (__x86_64__)
129 #define TRAP_DEBUGGER __asm__("int3")
131 #error No TRAP_DEBUGGER for this architecture
134 #if defined(__i386__) || defined(__x86_64__)
135 #define panic_stop() pmCPUHalt(PM_HALT_PANIC)
137 #define panic_stop() panic_spin_forever()
140 #define CPUDEBUGGEROP PROCESSOR_DATA(current_processor(), debugger_state).db_current_op
141 #define CPUDEBUGGERMSG PROCESSOR_DATA(current_processor(), debugger_state).db_message
142 #define CPUPANICSTR PROCESSOR_DATA(current_processor(), debugger_state).db_panic_str
143 #define CPUPANICARGS PROCESSOR_DATA(current_processor(), debugger_state).db_panic_args
144 #define CPUPANICOPTS PROCESSOR_DATA(current_processor(), debugger_state).db_panic_options
145 #define CPUDEBUGGERSYNC PROCESSOR_DATA(current_processor(), debugger_state).db_proceed_on_sync_failure
146 #define CPUDEBUGGERCOUNT PROCESSOR_DATA(current_processor(), debugger_state).db_entry_count
147 #define CPUDEBUGGERRET PROCESSOR_DATA(current_processor(), debugger_state).db_op_return
148 #define CPUPANICCALLER PROCESSOR_DATA(current_processor(), debugger_state).db_panic_caller
150 #if DEVELOPMENT || DEBUG
151 #define DEBUGGER_DEBUGGING_NESTED_PANIC_IF_REQUESTED(requested) \
154 volatile int *badpointer = (int *)4; \
158 #endif /* DEVELOPMENT || DEBUG */
160 debugger_op debugger_current_op
= DBOP_NONE
;
161 const char *debugger_panic_str
= NULL
;
162 va_list *debugger_panic_args
= NULL
;
163 uint64_t debugger_panic_options
= 0;
164 const char *debugger_message
= NULL
;
165 unsigned long debugger_panic_caller
= 0;
167 void panic_trap_to_debugger(const char *panic_format_str
, va_list *panic_args
, unsigned int reason
, void *ctx
, uint64_t panic_options_mask
, unsigned long panic_caller
);
168 static void kdp_machine_reboot_type(unsigned int type
);
169 __attribute__((noreturn
)) void panic_spin_forever(void);
170 extern kern_return_t
do_stackshot(void);
174 #define NESTEDDEBUGGERENTRYMAX 5
177 #define DEBUG_BUF_SIZE (4096)
178 #define KDBG_TRACE_PANIC_FILENAME "/var/log/panic.trace"
181 * EXTENDED_/DEBUG_BUF_SIZE can't grow without updates to SMC and iBoot to store larger panic logs on co-processor systems */
182 #define DEBUG_BUF_SIZE ((3 * PAGE_SIZE) + offsetof(struct macos_panic_header, mph_data))
183 #define EXTENDED_DEBUG_BUF_SIZE 0x0013ff80
184 static_assert(((EXTENDED_DEBUG_BUF_SIZE
% PANIC_FLUSH_BOUNDARY
) == 0), "Extended debug buf size must match SMC alignment requirements");
185 #define KDBG_TRACE_PANIC_FILENAME "/var/tmp/panic.trace"
188 /* debug_buf is directly linked with iBoot panic region for embedded targets */
190 char *debug_buf_base
= NULL
;
191 char *debug_buf_ptr
= NULL
;
192 unsigned int debug_buf_size
= 0;
194 char debug_buf
[DEBUG_BUF_SIZE
];
195 struct macos_panic_header
*panic_info
= (struct macos_panic_header
*)debug_buf
;
196 char *debug_buf_base
= (debug_buf
+ offsetof(struct macos_panic_header
, mph_data
));
197 char *debug_buf_ptr
= (debug_buf
+ offsetof(struct macos_panic_header
, mph_data
));
200 * We don't include the size of the panic header in the length of the data we actually write.
201 * On co-processor platforms, we lose sizeof(struct macos_panic_header) bytes from the end of
202 * the end of the log because we only support writing (3*PAGESIZE) bytes.
204 unsigned int debug_buf_size
= (DEBUG_BUF_SIZE
- offsetof(struct macos_panic_header
, mph_data
));
206 boolean_t extended_debug_log_enabled
= FALSE
;
210 atomic_int debugger_cpu
= ATOMIC_VAR_INIT(DEBUGGER_NO_CPU
);
211 boolean_t debugger_allcpus_halted
= FALSE
;
212 boolean_t debugger_safe_to_return
= TRUE
;
213 unsigned int debugger_context
= 0;
215 static char model_name
[64];
216 unsigned char *kernel_uuid
;
219 * By default we treat Debugger() the same as calls to panic(), unless
220 * we have debug boot-args present and the DB_KERN_DUMP_ON_NMI *NOT* set.
221 * If DB_KERN_DUMP_ON_NMI is *NOT* set, return from Debugger() is supported.
223 * Return from Debugger() is currently only implemented on x86
225 static boolean_t debugger_is_panic
= TRUE
;
227 #if DEVELOPMENT || DEBUG
228 boolean_t debug_boot_arg_inited
= FALSE
;
231 SECURITY_READ_ONLY_LATE(unsigned int) debug_boot_arg
;
233 char kernel_uuid_string
[37]; /* uuid_string_t */
234 char panic_disk_error_description
[512];
235 size_t panic_disk_error_description_size
= sizeof(panic_disk_error_description
);
237 extern unsigned int write_trace_on_panic
;
238 int kext_assertions_enable
=
239 #if DEBUG || DEVELOPMENT
248 unsigned long uuidlen
= 0;
251 uuid
= getuuidfromheader(&_mh_execute_header
, &uuidlen
);
252 if ((uuid
!= NULL
) && (uuidlen
== sizeof(uuid_t
))) {
254 uuid_unparse_upper(*(uuid_t
*)uuid
, kernel_uuid_string
);
257 if (!PE_parse_boot_argn("assertions", &mach_assert
, sizeof(mach_assert
))) {
262 * Initialize the value of the debug boot-arg
265 #if ((CONFIG_EMBEDDED && MACH_KDP) || defined(__x86_64__))
266 if (PE_parse_boot_argn("debug", &debug_boot_arg
, sizeof (debug_boot_arg
))) {
267 #if DEVELOPMENT || DEBUG
268 if (debug_boot_arg
& DB_HALT
) {
274 if (debug_boot_arg
& DB_NMI
) {
275 panicDebugging
= TRUE
;
278 panicDebugging
= TRUE
;
279 #if KDEBUG_MOJO_TRACE
280 if (debug_boot_arg
& DB_PRT_KDEBUG
) {
281 kdebug_serial
= TRUE
;
284 #endif /* CONFIG_EMBEDDED */
286 #endif /* ((CONFIG_EMBEDDED && MACH_KDP) || defined(__x86_64__)) */
288 #if DEVELOPMENT || DEBUG
289 debug_boot_arg_inited
= TRUE
;
294 * By default we treat Debugger() the same as calls to panic(), unless
295 * we have debug boot-args present and the DB_KERN_DUMP_ON_NMI *NOT* set.
296 * If DB_KERN_DUMP_ON_NMI is *NOT* set, return from Debugger() is supported.
297 * This is because writing an on-device corefile is a destructive operation.
299 * Return from Debugger() is currently only implemented on x86
301 if (PE_i_can_has_debugger(NULL
) && !(debug_boot_arg
& DB_KERN_DUMP_ON_NMI
)) {
302 debugger_is_panic
= FALSE
;
308 #if defined (__x86_64__)
310 extended_debug_log_init(void)
312 assert(coprocessor_paniclog_flush
);
314 * Allocate an extended panic log buffer that has space for the panic
315 * stackshot at the end. Update the debug buf pointers appropriately
316 * to point at this new buffer.
318 char *new_debug_buf
= kalloc(EXTENDED_DEBUG_BUF_SIZE
);
320 * iBoot pre-initializes the panic region with the NULL character. We set this here
321 * so we can accurately calculate the CRC for the region without needing to flush the
322 * full region over SMC.
324 memset(new_debug_buf
, '\0', EXTENDED_DEBUG_BUF_SIZE
);
326 panic_info
= (struct macos_panic_header
*)new_debug_buf
;
327 debug_buf_ptr
= debug_buf_base
= (new_debug_buf
+ offsetof(struct macos_panic_header
, mph_data
));
328 debug_buf_size
= (EXTENDED_DEBUG_BUF_SIZE
- offsetof(struct macos_panic_header
, mph_data
));
330 extended_debug_log_enabled
= TRUE
;
332 #endif /* defined (__x86_64__) */
339 printf("debug_log_init: Error!! gPanicBase is still not initialized\n");
342 /* Shift debug buf start location and size by the length of the panic header */
343 debug_buf_base
= (char *)gPanicBase
+ sizeof(struct embedded_panic_header
);
344 debug_buf_ptr
= debug_buf_base
;
345 debug_buf_size
= gPanicSize
- sizeof(struct embedded_panic_header
);
347 bzero(panic_info
, DEBUG_BUF_SIZE
);
349 assert(debug_buf_base
!= NULL
);
350 assert(debug_buf_ptr
!= NULL
);
351 assert(debug_buf_size
!= 0);
358 int my_cpu
= cpu_number();
359 int debugger_exp_cpu
= DEBUGGER_NO_CPU
;
360 assert(ml_get_interrupts_enabled() == FALSE
);
362 if (debugger_cpu
== my_cpu
) {
366 while(!atomic_compare_exchange_strong(&debugger_cpu
, &debugger_exp_cpu
, my_cpu
)) {
367 debugger_exp_cpu
= DEBUGGER_NO_CPU
;
376 assert(debugger_cpu
== cpu_number());
379 * We don't do an atomic exchange here in case
380 * there's another CPU spinning to acquire the debugger_lock
381 * and we never get a chance to update it. We already have the
382 * lock so we can simply store DEBUGGER_NO_CPU and follow with
385 debugger_cpu
= DEBUGGER_NO_CPU
;
392 DebuggerHaltOtherCores(boolean_t proceed_on_failure
)
395 return DebuggerXCallEnter(proceed_on_failure
);
396 #else /* CONFIG_EMBEDDED */
397 #pragma unused(proceed_on_failure)
398 mp_kdp_enter(proceed_on_failure
);
404 DebuggerResumeOtherCores()
407 DebuggerXCallReturn();
408 #else /* CONFIG_EMBEDDED */
414 DebuggerSaveState(debugger_op db_op
, const char *db_message
, const char *db_panic_str
,
415 va_list *db_panic_args
, uint64_t db_panic_options
,
416 boolean_t db_proceed_on_sync_failure
, unsigned long db_panic_caller
)
418 CPUDEBUGGEROP
= db_op
;
420 /* Preserve the original panic message */
421 if (CPUDEBUGGERCOUNT
== 1 || CPUPANICSTR
== NULL
) {
422 CPUDEBUGGERMSG
= db_message
;
423 CPUPANICSTR
= db_panic_str
;
424 CPUPANICARGS
= db_panic_args
;
425 CPUPANICCALLER
= db_panic_caller
;
426 } else if (CPUDEBUGGERCOUNT
> 1 && db_panic_str
!= NULL
) {
427 kprintf("Nested panic detected:");
428 if (db_panic_str
!= NULL
)
429 _doprnt(db_panic_str
, db_panic_args
, PE_kputc
, 0);
432 CPUDEBUGGERSYNC
= db_proceed_on_sync_failure
;
433 CPUDEBUGGERRET
= KERN_SUCCESS
;
435 /* Reset these on any nested panics */
436 CPUPANICOPTS
= db_panic_options
;
442 * Save the requested debugger state/action into the current processor's processor_data
443 * and trap to the debugger.
446 DebuggerTrapWithState(debugger_op db_op
, const char *db_message
, const char *db_panic_str
,
447 va_list *db_panic_args
, uint64_t db_panic_options
,
448 boolean_t db_proceed_on_sync_failure
, unsigned long db_panic_caller
)
452 assert(ml_get_interrupts_enabled() == FALSE
);
453 DebuggerSaveState(db_op
, db_message
, db_panic_str
,
454 db_panic_args
, db_panic_options
, db_proceed_on_sync_failure
,
459 ret
= CPUDEBUGGERRET
;
461 DebuggerSaveState(DBOP_NONE
, NULL
, NULL
, NULL
, 0, FALSE
, 0);
466 void __attribute__((noinline
))
470 const char *expression
474 kprintf("%s:%d non-fatal Assertion: %s", file
, line
, expression
);
478 panic_plain("%s:%d Assertion failed: %s", file
, line
, expression
);
483 Debugger(const char *message
)
485 DebuggerWithContext(0, NULL
, message
, DEBUGGER_OPTION_NONE
);
489 DebuggerWithContext(unsigned int reason
, void *ctx
, const char *message
,
490 uint64_t debugger_options_mask
)
492 spl_t previous_interrupts_state
;
493 boolean_t old_doprnt_hide_pointers
= doprnt_hide_pointers
;
495 previous_interrupts_state
= ml_set_interrupts_enabled(FALSE
);
496 disable_preemption();
500 if (CPUDEBUGGERCOUNT
> NESTEDDEBUGGERENTRYMAX
) {
501 static boolean_t in_panic_kprintf
= FALSE
;
503 /* Notify any listeners that we've started a panic */
504 PEHaltRestart(kPEPanicBegin
);
506 if (!in_panic_kprintf
) {
507 in_panic_kprintf
= TRUE
;
508 kprintf("Detected nested debugger entry count exceeding %d\n",
509 NESTEDDEBUGGERENTRYMAX
);
510 in_panic_kprintf
= FALSE
;
513 if (!panicDebugging
) {
514 kdp_machine_reboot_type(kPEPanicRestartCPU
);
517 panic_spin_forever();
520 #if DEVELOPMENT || DEBUG
521 DEBUGGER_DEBUGGING_NESTED_PANIC_IF_REQUESTED((debugger_options_mask
& DEBUGGER_OPTION_RECURPANIC_ENTRY
));
524 doprnt_hide_pointers
= FALSE
;
527 DebuggerSaveState(DBOP_DEBUGGER
, message
,
528 NULL
, NULL
, debugger_options_mask
, TRUE
, 0);
529 handle_debugger_trap(reason
, 0, 0, ctx
);
530 DebuggerSaveState(DBOP_NONE
, NULL
, NULL
,
533 DebuggerTrapWithState(DBOP_DEBUGGER
, message
,
534 NULL
, NULL
, debugger_options_mask
, TRUE
, 0);
538 doprnt_hide_pointers
= old_doprnt_hide_pointers
;
540 ml_set_interrupts_enabled(previous_interrupts_state
);
543 static struct kdp_callout
{
544 struct kdp_callout
* callout_next
;
545 kdp_callout_fn_t callout_fn
;
546 boolean_t callout_in_progress
;
548 } * kdp_callout_list
= NULL
;
551 * Called from kernel context to register a kdp event callout.
554 kdp_register_callout(kdp_callout_fn_t fn
, void * arg
)
556 struct kdp_callout
* kcp
;
557 struct kdp_callout
* list_head
;
559 kcp
= kalloc(sizeof(*kcp
));
561 panic("kdp_register_callout() kalloc failed");
563 kcp
->callout_fn
= fn
;
564 kcp
->callout_arg
= arg
;
565 kcp
->callout_in_progress
= FALSE
;
567 /* Lock-less list insertion using compare and exchange. */
569 list_head
= kdp_callout_list
;
570 kcp
->callout_next
= list_head
;
571 } while (!OSCompareAndSwapPtr(list_head
, kcp
, &kdp_callout_list
));
575 kdp_callouts(kdp_event_t event
)
577 struct kdp_callout
*kcp
= kdp_callout_list
;
580 if (!kcp
->callout_in_progress
) {
581 kcp
->callout_in_progress
= TRUE
;
582 kcp
->callout_fn(kcp
->callout_arg
, event
);
583 kcp
->callout_in_progress
= FALSE
;
585 kcp
= kcp
->callout_next
;
590 * An overview of the xnu panic path:
592 * Several panic wrappers (panic(), panic_with_options(), etc.) all funnel into panic_trap_to_debugger().
593 * panic_trap_to_debugger() sets the panic state in the current processor's processor_data_t prior
594 * to trapping into the debugger. Once we trap to the debugger, we end up in handle_debugger_trap()
595 * which tries to acquire the panic lock by atomically swapping the current CPU number into debugger_cpu.
596 * debugger_cpu acts as a synchronization point, from which the winning CPU can halt the other cores and
597 * continue to debugger_collect_diagnostics() where we write the paniclog, corefile (if appropriate) and proceed
598 * according to the device's boot-args.
602 panic(const char *str
, ...)
604 va_list panic_str_args
;
606 va_start(panic_str_args
, str
);
607 panic_trap_to_debugger(str
, &panic_str_args
, 0, NULL
, 0, (unsigned long)(char *)__builtin_return_address(0));
608 va_end(panic_str_args
);
612 panic_with_options(unsigned int reason
, void *ctx
, uint64_t debugger_options_mask
, const char *str
, ...)
614 va_list panic_str_args
;
616 va_start(panic_str_args
, str
);
617 panic_trap_to_debugger(str
, &panic_str_args
, reason
, ctx
, debugger_options_mask
, (unsigned long)(char *)__builtin_return_address(0));
618 va_end(panic_str_args
);
622 panic_context(unsigned int reason
, void *ctx
, const char *str
, ...)
624 va_list panic_str_args
;
626 va_start(panic_str_args
, str
);
627 panic_trap_to_debugger(str
, &panic_str_args
, reason
, ctx
, 0, (unsigned long)(char *)__builtin_return_address(0));
628 va_end(panic_str_args
);
631 #pragma clang diagnostic push
632 #pragma clang diagnostic ignored "-Wmissing-noreturn"
634 panic_trap_to_debugger(const char *panic_format_str
, va_list *panic_args
, unsigned int reason
, void
635 *ctx
, uint64_t panic_options_mask
, unsigned long panic_caller
)
637 #pragma clang diagnostic pop
639 if (ml_wants_panic_trap_to_debugger()) {
640 ml_panic_trap_to_debugger(panic_format_str
, panic_args
, reason
, ctx
, panic_options_mask
, panic_caller
);
643 * This should not return, but we return here for the tail call
644 * as it simplifies the backtrace.
651 if (CPUDEBUGGERCOUNT
> NESTEDDEBUGGERENTRYMAX
) {
652 static boolean_t in_panic_kprintf
= FALSE
;
654 /* Notify any listeners that we've started a panic */
655 PEHaltRestart(kPEPanicBegin
);
657 if (!in_panic_kprintf
) {
658 in_panic_kprintf
= TRUE
;
659 kprintf("Detected nested debugger entry count exceeding %d\n",
660 NESTEDDEBUGGERENTRYMAX
);
661 in_panic_kprintf
= FALSE
;
664 if (!panicDebugging
) {
665 kdp_machine_reboot_type(kPEPanicRestartCPU
);
668 panic_spin_forever();
671 #if DEVELOPMENT || DEBUG
672 DEBUGGER_DEBUGGING_NESTED_PANIC_IF_REQUESTED((panic_options_mask
& DEBUGGER_OPTION_RECURPANIC_ENTRY
));
676 if (PE_arm_debug_panic_hook
)
677 PE_arm_debug_panic_hook(panic_format_str
);
680 #if defined (__x86_64__)
684 if (write_trace_on_panic
&& kdebug_enable
) {
685 if (get_preemption_level() == 0 && !ml_at_interrupt_context()) {
686 ml_set_interrupts_enabled(TRUE
);
688 kdbg_dump_trace_to_file(KDBG_TRACE_PANIC_FILENAME
);
692 ml_set_interrupts_enabled(FALSE
);
693 disable_preemption();
695 #if defined (__x86_64__)
696 pmSafeMode(x86_lcpu(), PM_SAFE_FL_SAFE
);
697 #endif /* defined (__x86_64__) */
699 /* Never hide pointers from panic logs. */
700 doprnt_hide_pointers
= FALSE
;
704 * We called into panic from a trap, no need to trap again. Set the
705 * state on the current CPU and then jump to handle_debugger_trap.
707 DebuggerSaveState(DBOP_PANIC
, "panic",
708 panic_format_str
, panic_args
,
709 panic_options_mask
, TRUE
, panic_caller
);
710 handle_debugger_trap(reason
, 0, 0, ctx
);
713 #if defined(__arm64__)
715 * Signal to fastsim that it should open debug ports (nop on hardware)
717 __asm__
volatile("HINT 0x45");
718 #endif /* defined(__arm64__) */
720 DebuggerTrapWithState(DBOP_PANIC
, "panic", panic_format_str
,
721 panic_args
, panic_options_mask
, TRUE
, panic_caller
);
729 __attribute__((noreturn
))
733 paniclog_append_noflush("\nPlease go to https://panic.apple.com to report this panic\n");
739 kdp_machine_reboot_type(unsigned int type
)
741 printf("Attempting system restart...");
747 kdp_machine_reboot(void)
749 kdp_machine_reboot_type(kPEPanicRestartCPU
);
753 * Gather and save diagnostic information about a panic (or Debugger call).
755 * On embedded, Debugger and Panic are treated very similarly -- WDT uses Debugger so we can
756 * theoretically return from it. On desktop, Debugger is treated as a conventional debugger -- i.e no
757 * paniclog is written and no core is written unless we request a core on NMI.
759 * This routine handles kicking off local coredumps, paniclogs, calling into the Debugger/KDP (if it's configured),
760 * and calling out to any other functions we have for collecting diagnostic info.
763 debugger_collect_diagnostics(unsigned int exception
, unsigned int code
, unsigned int subcode
, void *state
)
765 #if DEVELOPMENT || DEBUG
766 DEBUGGER_DEBUGGING_NESTED_PANIC_IF_REQUESTED((debugger_panic_options
& DEBUGGER_OPTION_RECURPANIC_PRELOG
));
769 #if defined(__x86_64__)
770 kprintf("Debugger called: <%s>\n", debugger_message
? debugger_message
: "");
773 * DB_HALT (halt_in_debugger) can be requested on startup, we shouldn't generate
774 * a coredump/paniclog for this type of debugger entry. If KDP isn't configured,
775 * we'll just spin in kdp_raise_exception.
777 if (debugger_current_op
== DBOP_DEBUGGER
&& halt_in_debugger
) {
778 kdp_raise_exception(exception
, code
, subcode
, state
);
779 if (debugger_safe_to_return
&& !debugger_is_panic
) {
784 if ((debugger_current_op
== DBOP_PANIC
) ||
785 ((debugger_current_op
== DBOP_DEBUGGER
) && debugger_is_panic
)) {
787 * Attempt to notify listeners once and only once that we've started
788 * panicking. Only do this for Debugger() calls if we're treating
789 * Debugger() calls like panic().
791 PEHaltRestart(kPEPanicBegin
);
794 * Set the begin pointer in the panic log structure. We key off of this
795 * static variable rather than contents from the panic header itself in case someone
796 * has stomped over the panic_info structure. Also initializes the header magic.
798 static boolean_t began_writing_paniclog
= FALSE
;
799 if (!began_writing_paniclog
) {
800 PE_init_panicheader();
801 began_writing_paniclog
= TRUE
;
804 * If we reached here, update the panic header to keep it as consistent
805 * as possible during a nested panic
807 PE_update_panicheader_nestedpanic();
812 * Write panic string if this was a panic.
814 * TODO: Consider moving to SavePanicInfo as this is part of the panic log.
816 if (debugger_current_op
== DBOP_PANIC
) {
817 paniclog_append_noflush("panic(cpu %d caller 0x%lx): ", (unsigned) cpu_number(), debugger_panic_caller
);
818 if (debugger_panic_str
) {
819 _doprnt(debugger_panic_str
, debugger_panic_args
, consdebug_putc
, 0);
821 paniclog_append_noflush("\n");
823 #if defined(__x86_64__)
824 else if (((debugger_current_op
== DBOP_DEBUGGER
) && debugger_is_panic
)) {
825 paniclog_append_noflush("Debugger called: <%s>\n", debugger_message
? debugger_message
: "");
829 * Debugger() is treated like panic() on embedded -- for example we use it for WDT
830 * panics (so we need to write a paniclog). On desktop Debugger() is used in the
831 * conventional sense.
833 if (debugger_current_op
== DBOP_PANIC
|| ((debugger_current_op
== DBOP_DEBUGGER
) && debugger_is_panic
))
836 kdp_callouts(KDP_EVENT_PANICLOG
);
839 * Write paniclog and panic stackshot (if supported)
840 * TODO: Need to clear panic log when return from debugger
841 * hooked up for embedded
843 SavePanicInfo(debugger_message
, debugger_panic_options
);
845 #if DEVELOPMENT || DEBUG
846 DEBUGGER_DEBUGGING_NESTED_PANIC_IF_REQUESTED((debugger_panic_options
& DEBUGGER_OPTION_RECURPANIC_POSTLOG
));
849 /* DEBUGGER_OPTION_PANICLOGANDREBOOT is used for two finger resets on embedded so we get a paniclog */
850 if (debugger_panic_options
& DEBUGGER_OPTION_PANICLOGANDREBOOT
)
851 PEHaltRestart(kPEPanicRestartCPU
);
854 #if CONFIG_KDP_INTERACTIVE_DEBUGGING
856 * If reboot on panic is enabled and the caller of panic indicated that we should skip
857 * local coredumps, don't try to write these and instead go straight to reboot. This
858 * allows us to persist any data that's stored in the panic log.
860 if ((debugger_panic_options
& DEBUGGER_OPTION_SKIP_LOCAL_COREDUMP
) &&
861 (debug_boot_arg
& DB_REBOOT_POST_CORE
)) {
862 kdp_machine_reboot_type(kPEPanicRestartCPU
);
866 * Consider generating a local corefile if the infrastructure is configured
867 * and we haven't disabled on-device coredumps.
869 if (kdp_has_polled_corefile() && !(debug_boot_arg
& DB_DISABLE_LOCAL_CORE
)) {
872 #if defined (__x86_64__)
873 /* On x86 we don't do a coredump on Debugger unless the DB_KERN_DUMP_ON_NMI boot-arg is specified. */
874 if (debugger_current_op
!= DBOP_DEBUGGER
|| (debug_boot_arg
& DB_KERN_DUMP_ON_NMI
))
878 * Doing an on-device coredump leaves the disk driver in a state
879 * that can not be resumed.
881 debugger_safe_to_return
= FALSE
;
882 begin_panic_transfer();
883 ret
= kern_dump(KERN_DUMP_DISK
);
884 abort_panic_transfer();
886 #if DEVELOPMENT || DEBUG
887 DEBUGGER_DEBUGGING_NESTED_PANIC_IF_REQUESTED((debugger_panic_options
& DEBUGGER_OPTION_RECURPANIC_POSTCORE
));
891 /* If we wrote a corefile and DB_REBOOT_POST_CORE is set, reboot */
892 if (ret
== 0 && (debug_boot_arg
& DB_REBOOT_POST_CORE
)) {
893 kdp_machine_reboot_type(kPEPanicRestartCPU
);
897 if (debug_boot_arg
& DB_REBOOT_ALWAYS
) {
898 kdp_machine_reboot_type(kPEPanicRestartCPU
);
901 /* If KDP is configured, try to trap to the debugger */
902 if (current_debugger
!= NO_CUR_DB
) {
903 kdp_raise_exception(exception
, code
, subcode
, state
);
905 * Only return if we entered via Debugger and it's safe to return
906 * (we halted the other cores successfully, this isn't a nested panic, etc)
908 if (debugger_current_op
== DBOP_DEBUGGER
&&
909 debugger_safe_to_return
&&
910 kernel_debugger_entry_count
== 1 &&
911 !debugger_is_panic
) {
917 if (panicDebugging
) {
918 /* If panic debugging is configured, spin for astris to connect */
921 #endif /* CONFIG_EMBEDDED */
922 #endif /* CONFIG_KDP_INTERACTIVE_DEBUGGING */
924 if (!panicDebugging
) {
925 kdp_machine_reboot_type(kPEPanicRestartCPU
);
928 panic_spin_forever();
931 #if INTERRUPT_MASKED_DEBUG
932 uint64_t debugger_trap_timestamps
[9];
933 # define DEBUGGER_TRAP_TIMESTAMP(i) debugger_trap_timestamps[i] = mach_absolute_time();
935 # define DEBUGGER_TRAP_TIMESTAMP(i)
939 handle_debugger_trap(unsigned int exception
, unsigned int code
, unsigned int subcode
, void *state
)
941 unsigned int initial_not_in_kdp
= not_in_kdp
;
943 debugger_op db_prev_op
= debugger_current_op
;
945 DEBUGGER_TRAP_TIMESTAMP(0);
948 ret
= DebuggerHaltOtherCores(CPUDEBUGGERSYNC
);
950 DEBUGGER_TRAP_TIMESTAMP(1);
952 #if INTERRUPT_MASKED_DEBUG
953 if (serialmode
& SERIALMODE_OUTPUT
) {
954 ml_spin_debug_reset(current_thread());
957 if (ret
!= KERN_SUCCESS
) {
958 CPUDEBUGGERRET
= ret
;
963 /* Update the global panic/debugger nested entry level */
964 kernel_debugger_entry_count
= CPUDEBUGGERCOUNT
;
967 * TODO: Should we do anything special for nested panics here? i.e. if we've trapped more than twice
968 * should we call into the debugger if it's configured and then reboot if the panic log has been written?
971 if (CPUDEBUGGEROP
== DBOP_NONE
) {
972 /* If there was no debugger context setup, we trapped due to a software breakpoint */
973 debugger_current_op
= DBOP_BREAKPOINT
;
975 /* Not safe to return from a nested panic/debugger call */
976 if (debugger_current_op
== DBOP_PANIC
||
977 debugger_current_op
== DBOP_DEBUGGER
) {
978 debugger_safe_to_return
= FALSE
;
981 debugger_current_op
= CPUDEBUGGEROP
;
983 /* Only overwrite the panic message if there is none already - save the data from the first call */
984 if (debugger_panic_str
== NULL
) {
985 debugger_panic_str
= CPUPANICSTR
;
986 debugger_panic_args
= CPUPANICARGS
;
987 debugger_message
= CPUDEBUGGERMSG
;
988 debugger_panic_caller
= CPUPANICCALLER
;
991 debugger_panic_options
= CPUPANICOPTS
;
995 * Clear the op from the processor debugger context so we can handle
996 * breakpoints in the debugger
998 CPUDEBUGGEROP
= DBOP_NONE
;
1000 DEBUGGER_TRAP_TIMESTAMP(2);
1002 kdp_callouts(KDP_EVENT_ENTER
);
1005 DEBUGGER_TRAP_TIMESTAMP(3);
1007 if (debugger_current_op
== DBOP_BREAKPOINT
) {
1008 kdp_raise_exception(exception
, code
, subcode
, state
);
1009 } else if (debugger_current_op
== DBOP_STACKSHOT
) {
1010 CPUDEBUGGERRET
= do_stackshot();
1012 } else if (debugger_current_op
== DBOP_RESET_PGO_COUNTERS
) {
1013 CPUDEBUGGERRET
= do_pgo_reset_counters();
1016 debugger_collect_diagnostics(exception
, code
, subcode
, state
);
1019 DEBUGGER_TRAP_TIMESTAMP(4);
1021 not_in_kdp
= initial_not_in_kdp
;
1022 kdp_callouts(KDP_EVENT_EXIT
);
1024 DEBUGGER_TRAP_TIMESTAMP(5);
1026 if (debugger_current_op
!= DBOP_BREAKPOINT
) {
1027 debugger_panic_str
= NULL
;
1028 debugger_panic_args
= NULL
;
1029 debugger_panic_options
= 0;
1030 debugger_message
= NULL
;
1033 /* Restore the previous debugger state */
1034 debugger_current_op
= db_prev_op
;
1036 DEBUGGER_TRAP_TIMESTAMP(6);
1038 DebuggerResumeOtherCores();
1040 DEBUGGER_TRAP_TIMESTAMP(7);
1044 DEBUGGER_TRAP_TIMESTAMP(8);
1049 __attribute__((noinline
,not_tail_called
))
1050 void log(__unused
int level
, char *fmt
, ...)
1052 void *caller
= __builtin_return_address(0);
1061 va_start(listp
, fmt
);
1062 va_copy(listp2
, listp
);
1064 disable_preemption();
1065 _doprnt(fmt
, &listp
, cons_putc_locked
, 0);
1066 enable_preemption();
1070 os_log_with_args(OS_LOG_DEFAULT
, OS_LOG_TYPE_DEFAULT
, fmt
, listp2
, caller
);
1076 * Per <rdar://problem/24974766>, skip appending log messages to
1077 * the new logging infrastructure in contexts where safety is
1078 * uncertain. These contexts include:
1079 * - When we're in the debugger
1080 * - We're in a panic
1081 * - Interrupts are disabled
1082 * - Or Pre-emption is disabled
1083 * In all the above cases, it is potentially unsafe to log messages.
1087 oslog_is_safe(void) {
1088 return (kernel_debugger_entry_count
== 0 &&
1090 get_preemption_level() == 0 &&
1091 ml_get_interrupts_enabled() == TRUE
);
1095 debug_mode_active(void)
1097 return ((0 != kernel_debugger_entry_count
!= 0) || (0 == not_in_kdp
));
1103 if ((debug_buf_size
!= 0) &&
1104 ((debug_buf_ptr
- debug_buf_base
) < (int)debug_buf_size
)) {
1110 #if defined (__x86_64__)
1120 } __attribute__((packed
));
1122 typedef struct pasc pasc_t
;
1125 * In-place packing routines -- inefficient, but they're called at most once.
1126 * Assumes "buflen" is a multiple of 8. Used for compressing paniclogs on x86.
1129 packA(char *inbuf
, uint32_t length
, uint32_t buflen
)
1131 unsigned int i
, j
= 0;
1134 length
= MIN(((length
+ 7) & ~7), buflen
);
1136 for (i
= 0; i
< length
; i
+=8)
1139 pack
.b
= inbuf
[i
+1];
1140 pack
.c
= inbuf
[i
+2];
1141 pack
.d
= inbuf
[i
+3];
1142 pack
.e
= inbuf
[i
+4];
1143 pack
.f
= inbuf
[i
+5];
1144 pack
.g
= inbuf
[i
+6];
1145 pack
.h
= inbuf
[i
+7];
1146 bcopy ((char *) &pack
, inbuf
+ j
, 7);
1153 unpackA(char *inbuf
, uint32_t length
)
1157 length
= (length
* 8)/7;
1159 while (i
< length
) {
1160 packs
= *(pasc_t
*)&inbuf
[i
];
1161 bcopy(&inbuf
[i
+7], &inbuf
[i
+8], MAX(0, (int) (length
- i
- 8)));
1162 inbuf
[i
++] = packs
.a
;
1163 inbuf
[i
++] = packs
.b
;
1164 inbuf
[i
++] = packs
.c
;
1165 inbuf
[i
++] = packs
.d
;
1166 inbuf
[i
++] = packs
.e
;
1167 inbuf
[i
++] = packs
.f
;
1168 inbuf
[i
++] = packs
.g
;
1169 inbuf
[i
++] = packs
.h
;
1172 #endif /* defined (__x86_64__) */
1174 extern void *proc_name_address(void *p
);
1177 panic_display_process_name(void) {
1178 /* because of scoping issues len(p_comm) from proc_t is hard coded here */
1179 char proc_name
[17] = "Unknown";
1181 void *cbsd_info
= 0;
1183 if (ml_nofault_copy((vm_offset_t
)¤t_thread()->task
, (vm_offset_t
) &ctask
, sizeof(task_t
)) == sizeof(task_t
))
1184 if(ml_nofault_copy((vm_offset_t
)&ctask
->bsd_info
, (vm_offset_t
)&cbsd_info
, sizeof(cbsd_info
)) == sizeof(cbsd_info
))
1185 if (cbsd_info
&& (ml_nofault_copy((vm_offset_t
) proc_name_address(cbsd_info
), (vm_offset_t
) &proc_name
, sizeof(proc_name
)) > 0))
1186 proc_name
[sizeof(proc_name
) - 1] = '\0';
1187 paniclog_append_noflush("\nBSD process name corresponding to current thread: %s\n", proc_name
);
1191 panic_active(void) {
1192 return ((debugger_panic_str
!= (char *) 0));
1196 populate_model_name(char *model_string
) {
1197 strlcpy(model_name
, model_string
, sizeof(model_name
));
1201 panic_display_model_name(void) {
1202 char tmp_model_name
[sizeof(model_name
)];
1204 if (ml_nofault_copy((vm_offset_t
) &model_name
, (vm_offset_t
) &tmp_model_name
, sizeof(model_name
)) != sizeof(model_name
))
1207 tmp_model_name
[sizeof(tmp_model_name
) - 1] = '\0';
1209 if (tmp_model_name
[0] != 0)
1210 paniclog_append_noflush("System model name: %s\n", tmp_model_name
);
1214 panic_display_kernel_uuid(void) {
1215 char tmp_kernel_uuid
[sizeof(kernel_uuid_string
)];
1217 if (ml_nofault_copy((vm_offset_t
) &kernel_uuid_string
, (vm_offset_t
) &tmp_kernel_uuid
, sizeof(kernel_uuid_string
)) != sizeof(kernel_uuid_string
))
1220 if (tmp_kernel_uuid
[0] != '\0')
1221 paniclog_append_noflush("Kernel UUID: %s\n", tmp_kernel_uuid
);
1225 panic_display_kernel_aslr(void) {
1226 if (vm_kernel_slide
) {
1227 paniclog_append_noflush("Kernel slide: 0x%016lx\n", (unsigned long) vm_kernel_slide
);
1228 paniclog_append_noflush("Kernel text base: %p\n", (void *) vm_kernel_stext
);
1233 panic_display_hibb(void) {
1234 #if defined(__i386__) || defined (__x86_64__)
1235 paniclog_append_noflush("__HIB text base: %p\n", (void *) vm_hib_base
);
1240 panic_display_uptime(void) {
1242 absolutetime_to_nanoseconds(mach_absolute_time(), &uptime
);
1244 paniclog_append_noflush("\nSystem uptime in nanoseconds: %llu\n", uptime
);
1248 panic_display_disk_errors(void) {
1250 if (panic_disk_error_description
[0]) {
1251 panic_disk_error_description
[sizeof(panic_disk_error_description
) - 1] = '\0';
1252 paniclog_append_noflush("Root disk errors: \"%s\"\n", panic_disk_error_description
);
1256 extern const char version
[];
1257 extern char osversion
[];
1259 static volatile uint32_t config_displayed
= 0;
1261 __private_extern__
void
1262 panic_display_system_configuration(boolean_t launchd_exit
) {
1264 if (!launchd_exit
) panic_display_process_name();
1265 if (OSCompareAndSwap(0, 1, &config_displayed
)) {
1267 if (!launchd_exit
&& strlcpy(buf
, PE_boot_args(), sizeof(buf
)))
1268 paniclog_append_noflush("Boot args: %s\n", buf
);
1269 paniclog_append_noflush("\nMac OS version:\n%s\n",
1270 (osversion
[0] != 0) ? osversion
: "Not yet set");
1271 paniclog_append_noflush("\nKernel version:\n%s\n",version
);
1272 panic_display_kernel_uuid();
1273 if (!launchd_exit
) {
1274 panic_display_kernel_aslr();
1275 panic_display_hibb();
1276 panic_display_pal_info();
1278 panic_display_model_name();
1279 panic_display_disk_errors();
1280 if (!launchd_exit
) {
1281 panic_display_uptime();
1282 panic_display_zprint();
1284 panic_display_ztrace();
1285 #endif /* CONFIG_ZLEAKS */
1286 kext_dump_panic_lists(&paniclog_append_noflush
);
1291 extern unsigned int stack_total
;
1292 extern unsigned long long stack_allocs
;
1294 #if defined (__x86_64__)
1295 extern unsigned int inuse_ptepages_count
;
1296 extern long long alloc_ptepages_count
;
1299 extern boolean_t panic_include_zprint
;
1300 extern mach_memory_info_t
*panic_kext_memory_info
;
1301 extern vm_size_t panic_kext_memory_size
;
1303 __private_extern__
void
1304 panic_display_zprint()
1306 if(panic_include_zprint
== TRUE
) {
1309 struct zone zone_copy
;
1311 paniclog_append_noflush("%-20s %10s %10s\n", "Zone Name", "Cur Size", "Free Size");
1312 for (i
= 0; i
< num_zones
; i
++) {
1313 if(ml_nofault_copy((vm_offset_t
)(&zone_array
[i
]), (vm_offset_t
)&zone_copy
, sizeof(struct zone
)) == sizeof(struct zone
)) {
1314 if(zone_copy
.cur_size
> (1024*1024)) {
1315 paniclog_append_noflush("%-20s %10lu %10lu\n",zone_copy
.zone_name
, (uintptr_t)zone_copy
.cur_size
,(uintptr_t)(zone_copy
.countfree
* zone_copy
.elem_size
));
1320 paniclog_append_noflush("%-20s %10lu\n", "Kernel Stacks", (uintptr_t)(kernel_stack_size
* stack_total
));
1322 #if defined (__x86_64__)
1323 paniclog_append_noflush("%-20s %10lu\n", "PageTables",(uintptr_t)(PAGE_SIZE
* inuse_ptepages_count
));
1326 paniclog_append_noflush("%-20s %10lu\n", "Kalloc.Large", (uintptr_t)kalloc_large_total
);
1327 if (panic_kext_memory_info
) {
1328 mach_memory_info_t
*mem_info
= panic_kext_memory_info
;
1329 paniclog_append_noflush("\n%-5s %10s\n", "Kmod", "Size");
1330 for (i
= 0; i
< (panic_kext_memory_size
/ sizeof(mach_zone_info_t
)); i
++) {
1331 if (((mem_info
[i
].flags
& VM_KERN_SITE_TYPE
) == VM_KERN_SITE_KMOD
) && (mem_info
[i
].size
> (1024 * 1024))) {
1332 paniclog_append_noflush("%-5lld %10lld\n", mem_info
[i
].site
, mem_info
[i
].size
);
1339 #if CONFIG_ECC_LOGGING
1340 __private_extern__
void
1341 panic_display_ecc_errors()
1343 uint32_t count
= ecc_log_get_correction_count();
1346 paniclog_append_noflush("ECC Corrections:%u\n", count
);
1349 #endif /* CONFIG_ECC_LOGGING */
1352 extern boolean_t panic_include_ztrace
;
1353 extern struct ztrace
* top_ztrace
;
1354 void panic_print_symbol_name(vm_address_t search
);
1357 * Prints the backtrace most suspected of being a leaker, if we paniced in the zone allocator.
1358 * top_ztrace and panic_include_ztrace comes from osfmk/kern/zalloc.c
1360 __private_extern__
void
1361 panic_display_ztrace(void)
1363 if(panic_include_ztrace
== TRUE
) {
1365 boolean_t keepsyms
= FALSE
;
1367 PE_parse_boot_argn("keepsyms", &keepsyms
, sizeof (keepsyms
));
1368 struct ztrace top_ztrace_copy
;
1370 /* Make sure not to trip another panic if there's something wrong with memory */
1371 if(ml_nofault_copy((vm_offset_t
)top_ztrace
, (vm_offset_t
)&top_ztrace_copy
, sizeof(struct ztrace
)) == sizeof(struct ztrace
)) {
1372 paniclog_append_noflush("\nBacktrace suspected of leaking: (outstanding bytes: %lu)\n", (uintptr_t)top_ztrace_copy
.zt_size
);
1373 /* Print the backtrace addresses */
1374 for (i
= 0; (i
< top_ztrace_copy
.zt_depth
&& i
< MAX_ZTRACE_DEPTH
) ; i
++) {
1375 paniclog_append_noflush("%p ", top_ztrace_copy
.zt_stack
[i
]);
1377 panic_print_symbol_name((vm_address_t
)top_ztrace_copy
.zt_stack
[i
]);
1379 paniclog_append_noflush("\n");
1381 /* Print any kexts in that backtrace, along with their link addresses so we can properly blame them */
1382 kmod_panic_dump((vm_offset_t
*)&top_ztrace_copy
.zt_stack
[0], top_ztrace_copy
.zt_depth
);
1385 paniclog_append_noflush("\nCan't access top_ztrace...\n");
1387 paniclog_append_noflush("\n");
1390 #endif /* CONFIG_ZLEAKS */
1392 #if !CONFIG_TELEMETRY
1394 telemetry_gather(user_addr_t buffer __unused
, uint32_t *length __unused
, boolean_t mark __unused
)
1396 return KERN_NOT_SUPPORTED
;
1400 #include <machine/machine_cpu.h>
1402 uint32_t kern_feature_overrides
= 0;
1404 boolean_t
kern_feature_override(uint32_t fmask
) {
1405 if (kern_feature_overrides
== 0) {
1406 uint32_t fdisables
= 0;
1407 /* Expected to be first invoked early, in a single-threaded
1410 if (PE_parse_boot_argn("validation_disables", &fdisables
, sizeof(fdisables
))) {
1411 fdisables
|= KF_INITIALIZED
;
1412 kern_feature_overrides
= fdisables
;
1414 kern_feature_overrides
|= KF_INITIALIZED
;
1417 return ((kern_feature_overrides
& fmask
) == fmask
);