+#endif /* KERNEL_PRIVATE */
+
+#if XNU_KERNEL_PRIVATE
+
+#if defined (__x86_64__)
+struct thread;
+
+__abortlike __printflike(5, 6)
+void panic_with_thread_context(unsigned int reason, void *ctx,
+ uint64_t debugger_options_mask, struct thread* th, const char *str, ...);
+#endif
+
+/* limit the max size to a reasonable length */
+#define ADDITIONAL_PANIC_DATA_BUFFER_MAX_LEN 64
+
+struct additional_panic_data_buffer {
+ const char *producer_name;
+ void *buf;
+ int len;
+};
+
+extern struct additional_panic_data_buffer *panic_data_buffers;
+
+boolean_t oslog_is_safe(void);
+boolean_t debug_mode_active(void);
+boolean_t stackshot_active(void);
+void panic_stackshot_reset_state(void);
+
+/*
+ * @function stack_snapshot_from_kernel
+ *
+ * @abstract Stackshot function for kernel consumers who have their own buffer.
+ *
+ * @param pid the PID to be traced or -1 for the whole system
+ * @param buf a pointer to the buffer where the stackshot should be written
+ * @param size the size of the buffer
+ * @param flags flags to be passed to the stackshot
+ * @param delta_since_timestamp start time for delta period
+ * @bytes_traced a pointer to be filled with the length of the stackshot
+ *
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+kern_return_t
+stack_snapshot_from_kernel(int pid, void *buf, uint32_t size, uint32_t flags,
+ uint64_t delta_since_timestamp, unsigned *bytes_traced);
+
+/*
+ * Returns whether on device corefiles are enabled based on the build
+ * and boot configuration.
+ */
+boolean_t on_device_corefile_enabled(void);
+
+/*
+ * Returns whether panic stackshot to disk is enabled based on the build
+ * and boot configuration.
+ */
+boolean_t panic_stackshot_to_disk_enabled(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#if !CONFIG_EMBEDDED
+extern char debug_buf[];
+extern boolean_t coprocessor_paniclog_flush;
+extern boolean_t extended_debug_log_enabled;
+#endif /* !CONFIG_EMBEDDED */
+
+extern char *debug_buf_base;
+
+#if defined(XNU_TARGET_OS_BRIDGE)
+extern uint64_t macos_panic_base;
+extern unsigned int macos_panic_size;
+#endif /* defined(XNU_TARGET_OS_BRIDGE) */
+
+extern char kernel_uuid_string[];
+extern char panic_disk_error_description[];
+extern size_t panic_disk_error_description_size;
+
+extern unsigned char *kernel_uuid;
+extern unsigned int debug_boot_arg;
+#if DEVELOPMENT || DEBUG
+extern boolean_t debug_boot_arg_inited;
+#endif
+
+extern boolean_t kernelcache_uuid_valid;
+extern uuid_t kernelcache_uuid;
+extern uuid_string_t kernelcache_uuid_string;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern boolean_t doprnt_hide_pointers;
+
+#ifdef __cplusplus
+}
+#endif
+
+extern unsigned int halt_in_debugger; /* pending halt in debugger after boot */
+extern unsigned int current_debugger;
+#define NO_CUR_DB 0x0
+#define KDP_CUR_DB 0x1
+
+extern unsigned int active_debugger;
+extern unsigned int kernel_debugger_entry_count;
+
+extern unsigned int panicDebugging;
+extern unsigned int kdebug_serial;
+
+extern const char *debugger_panic_str;
+
+extern char *debug_buf_ptr;
+extern unsigned int debug_buf_size;
+
+extern void debug_log_init(void);
+extern void debug_putc(char);
+
+extern void panic_init(void);
+
+/*
+ * Initialize the physical carveout requested with the `phys_carveout_mb`
+ * boot-arg. This should only be called at kernel startup, when physically
+ * contiguous pages are plentiful.
+ */
+extern void phys_carveout_init(void);
+
+extern uintptr_t phys_carveout_pa;
+extern size_t phys_carveout_size;
+
+
+
+#if defined (__x86_64__)
+extern void extended_debug_log_init(void);
+
+int packA(char *inbuf, uint32_t length, uint32_t buflen);
+void unpackA(char *inbuf, uint32_t length);
+
+#define PANIC_STACKSHOT_BUFSIZE (1024 * 1024)
+
+extern uintptr_t panic_stackshot_buf;
+extern size_t panic_stackshot_buf_len;
+
+extern size_t panic_stackshot_len;
+#endif /* defined (__x86_64__) */
+
+void SavePanicInfo(const char *message, void *panic_data, uint64_t panic_options);
+void paniclog_flush(void);
+void panic_display_system_configuration(boolean_t launchd_exit);
+void panic_display_zprint(void);
+void panic_display_kernel_aslr(void);
+void panic_display_hibb(void);
+void panic_display_model_name(void);
+void panic_display_kernel_uuid(void);
+#if CONFIG_ZLEAKS
+void panic_display_ztrace(void);
+#endif /* CONFIG_ZLEAKS */
+#if CONFIG_ECC_LOGGING
+void panic_display_ecc_errors(void);
+#endif /* CONFIG_ECC_LOGGING */
+
+/*
+ * @var not_in_kdp
+ *
+ * @abstract True if we're in normal kernel operation, False if we're in a
+ * single-core debugger context.
+ */
+extern unsigned int not_in_kdp;
+
+#define DEBUGGER_NO_CPU -1
+
+typedef enum {
+ DBOP_NONE,
+ DBOP_STACKSHOT,
+ DBOP_RESET_PGO_COUNTERS,
+ DBOP_PANIC,
+ DBOP_DEBUGGER,
+ DBOP_BREAKPOINT,
+} debugger_op;
+
+kern_return_t DebuggerTrapWithState(debugger_op db_op, const char *db_message, const char *db_panic_str, va_list *db_panic_args,
+ uint64_t db_panic_options, void *db_panic_data_ptr, boolean_t db_proceed_on_sync_failure, unsigned long db_panic_caller);
+void handle_debugger_trap(unsigned int exception, unsigned int code, unsigned int subcode, void *state);
+
+void DebuggerWithContext(unsigned int reason, void *ctx, const char *message, uint64_t debugger_options_mask);
+
+#if DEBUG || DEVELOPMENT
+/* leak pointer scan definitions */
+
+enum{
+ kInstanceFlagAddress = 0x01UL,
+ kInstanceFlagReferenced = 0x02UL,
+ kInstanceFlags = 0x03UL
+};
+
+#define INSTANCE_GET(x) ((x) & ~kInstanceFlags)
+#define INSTANCE_PUT(x) ((x) ^ ~kInstanceFlags)
+
+typedef void (*leak_site_proc)(void * refCon, uint32_t siteCount, uint32_t zoneSize,
+ uintptr_t * backtrace, uint32_t btCount);
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern kern_return_t
+zone_leaks(const char * zoneName, uint32_t nameLen, leak_site_proc proc, void * refCon);
+
+extern void
+zone_leaks_scan(uintptr_t * instances, uint32_t count, uint32_t zoneSize, uint32_t * found);
+
+#ifdef __cplusplus
+}
+#endif
+
+extern boolean_t
+kdp_is_in_zone(void *addr, const char *zone_name);
+
+#endif /* DEBUG || DEVELOPMENT */
+#endif /* XNU_KERNEL_PRIVATE */