]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/debug.h
xnu-6153.81.5.tar.gz
[apple/xnu.git] / osfmk / kern / debug.h
index 7e82f1b34d995e39618ee8f33e550919286edf66..981eb3619d41f86e34cb0c41ebe299e8b053090e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2016 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2019 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  *
@@ -217,8 +217,8 @@ enum micro_snapshot_flags {
  * Flags used in the following assortment of snapshots.
  */
 enum generic_snapshot_flags {
-       kUser64_p                       = 0x1,
-       kKernel64_p             = 0x2
+       kUser64_p               = 0x1, /* Userspace uses 64 bit pointers */
+       kKernel64_p             = 0x2  /* The kernel uses 64 bit pointers */
 };
 
 #define VM_PRESSURE_TIME_WINDOW 5 /* seconds */
@@ -270,6 +270,9 @@ enum {
 #define KF_MATV_OVRD (0x8)
 #define KF_STACKSHOT_OVRD (0x10)
 #define KF_COMPRSV_OVRD (0x20)
+#define KF_INTERRUPT_MASKED_DEBUG_OVRD (0x40)
+#define KF_TRAPTRACE_OVRD (0x80)
+#define KF_IOTRACE_OVRD (0x100)
 
 boolean_t kern_feature_override(uint32_t fmask);
 
@@ -351,6 +354,35 @@ struct macos_panic_header {
 #define MACOS_PANIC_HEADER_FLAG_COREDUMP_FAILED               0x200
 #define MACOS_PANIC_HEADER_FLAG_STACKSHOT_KERNEL_ONLY         0x400
 
+/*
+ * Any change to the below structure should mirror the structure defined in MacEFIFirmware
+ * (and vice versa)
+ */
+
+struct efi_aurr_panic_header {
+       uint32_t efi_aurr_magic;
+       uint32_t efi_aurr_crc;
+       uint32_t efi_aurr_version;
+       uint32_t efi_aurr_reset_cause;
+       uint32_t efi_aurr_reset_log_offset;
+       uint32_t efi_aurr_reset_log_len;
+       char efi_aurr_panic_data[];
+} __attribute__((packed));
+
+/*
+ * EXTENDED_/DEBUG_BUF_SIZE can't grow without updates to SMC and iBoot to store larger panic logs on co-processor systems
+ */
+#define EXTENDED_DEBUG_BUF_SIZE 0x0013ff80
+
+#define EFI_AURR_PANIC_STRING_MAX_LEN 112
+#define EFI_AURR_EXTENDED_LOG_SIZE (EXTENDED_DEBUG_BUF_SIZE - sizeof(struct efi_aurr_panic_header) - EFI_AURR_PANIC_STRING_MAX_LEN)
+
+struct efi_aurr_extended_panic_log {
+       char efi_aurr_extended_log_buf[EFI_AURR_EXTENDED_LOG_SIZE];
+       uint32_t efi_aurr_log_tail; /* Circular buffer indices */
+       uint32_t efi_aurr_log_head; /* ditto.. */
+} __attribute__((packed));
+
 #endif /* __APPLE_API_UNSTABLE */
 #endif /* __APPLE_API_PRIVATE */
 
@@ -358,7 +390,8 @@ struct macos_panic_header {
 
 __BEGIN_DECLS
 
-extern void panic(const char *string, ...) __printflike(1, 2);
+__abortlike __printflike(1, 2)
+extern void panic(const char *string, ...);
 
 __END_DECLS
 
@@ -445,6 +478,7 @@ enum {
                                         * release bridgeOS.
                                         */
 #define DB_REBOOT_ALWAYS        0x100000 /* Don't wait for debugger connection */
+#define DB_DISABLE_STACKSHOT_TO_DISK 0x200000 /* Disable writing stackshot to local disk */
 
 /*
  * Values for a 64-bit mask that's passed to the debugger.
@@ -460,6 +494,8 @@ enum {
 #define DEBUGGER_OPTION_SKIP_LOCAL_COREDUMP         0x80ULL /* don't try to save local coredumps for this panic */
 #define DEBUGGER_OPTION_ATTEMPTCOREDUMPANDREBOOT    0x100ULL /* attempt to save coredump. always reboot */
 #define DEBUGGER_INTERNAL_OPTION_THREAD_BACKTRACE   0x200ULL /* backtrace the specified thread in the paniclog (x86 only) */
+#define DEBUGGER_OPTION_PRINT_CPU_USAGE_PANICLOG    0x400ULL /* print extra CPU usage data in the panic log */
+#define DEBUGGER_OPTION_SKIP_PANICEND_CALLOUTS      0x800ULL /* (bridgeOS) skip the kPEPanicEnd callouts -- don't wait for x86 to finish sending panic data */
 
 #define DEBUGGER_INTERNAL_OPTIONS_MASK              (DEBUGGER_INTERNAL_OPTION_THREAD_BACKTRACE)
 
@@ -472,12 +508,20 @@ __BEGIN_DECLS
 #define PANIC_LOCATION __FILE__ ":" LINE_NUMBER(__LINE__)
 
 #if CONFIG_EMBEDDED
-#define panic(ex, ...) (panic)(# ex, ## __VA_ARGS__)
+#define panic(ex, ...)  ({ \
+               __asm__("" ::: "memory"); \
+               (panic)(# ex, ## __VA_ARGS__); \
+       })
 #else
-#define panic(ex, ...) (panic)(# ex "@" PANIC_LOCATION, ## __VA_ARGS__)
+#define panic(ex, ...)  ({ \
+               __asm__("" ::: "memory"); \
+               (panic)(# ex "@" PANIC_LOCATION, ## __VA_ARGS__); \
+       })
 #endif
 
-void panic_with_options(unsigned int reason, void *ctx, uint64_t debugger_options_mask, const char *str, ...);
+__abortlike __printflike(4, 5)
+void panic_with_options(unsigned int reason, void *ctx,
+    uint64_t debugger_options_mask, const char *str, ...);
 void Debugger(const char * message);
 void populate_model_name(char *);
 
@@ -497,7 +541,9 @@ __END_DECLS
 #if defined (__x86_64__)
 struct thread;
 
-void panic_with_thread_context(unsigned int reason, void *ctx, uint64_t debugger_options_mask, struct thread* th, const char *str, ...);
+__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 */
@@ -535,6 +581,19 @@ extern "C" {
 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
@@ -542,11 +601,16 @@ stack_snapshot_from_kernel(int pid, void *buf, uint32_t size, uint32_t flags,
 #if !CONFIG_EMBEDDED
 extern char debug_buf[];
 extern boolean_t coprocessor_paniclog_flush;
-extern boolean_t extended_debug_log_enabled;;
+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;
@@ -587,10 +651,22 @@ 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 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;
+
 
-extern void     panic_init(void);
 
 #if defined (__x86_64__)
 extern void extended_debug_log_init(void);
@@ -598,12 +674,12 @@ extern void extended_debug_log_init(void);
 int     packA(char *inbuf, uint32_t length, uint32_t buflen);
 void    unpackA(char *inbuf, uint32_t length);
 
-#if DEVELOPMENT || DEBUG
 #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 /* DEVELOPMENT || DEBUG */
 #endif /* defined (__x86_64__) */
 
 void    SavePanicInfo(const char *message, void *panic_data, uint64_t panic_options);