1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 23 * Copyright (c) 2016 by Delphix. All rights reserved. 24 */ 25 26 #ifndef _SYS_PANIC_H 27 #define _SYS_PANIC_H 28 29 #if !defined(_ASM) 30 #include <sys/types.h> 31 #include <sys/thread.h> 32 #include <sys/cpuvar.h> 33 #include <sys/dditypes.h> 34 #endif /* !_ASM */ 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 #ifdef _LP64 41 #define PANICSTKSIZE 16384 42 #else 43 #define PANICSTKSIZE 8192 44 #endif 45 46 #define PANICBUFSIZE 8192 47 #define PANICBUFVERS 2 48 49 #define PANICNVNAMELEN 16 50 51 #define STACK_BUF_SIZE 2048 52 #define SUMMARY_MAGIC 0xdead0d8a 53 54 /* 55 * Panicbuf Format: 56 * 57 * The kernel records the formatted panic message and an optional array of 58 * name/value pairs into panicbuf[], a fixed-size buffer which is saved in 59 * the crash dump and, on some platforms, is persistent across reboots. 60 * The initial part of the buffer is a struct of type panic_data_t, which 61 * includes a version number for identifying the format of subsequent data. 62 * 63 * The pd_msgoff word identifies the byte offset into panicbuf[] at which the 64 * null-terminated panic message is located. This is followed by an optional 65 * variable-sized array of panic_nv_t items, which are used to record CPU 66 * register values. The number of items in pd_nvdata is computed as follows: 67 * 68 * (pd_msgoff - (sizeof (panic_data_t) - sizeof (panic_nv_t))) / 69 * sizeof (panic_nv_t); 70 * 71 * In addition to panicbuf, debuggers can access the panic_* variables shown 72 * below to determine more information about the initiator of the panic. 73 */ 74 75 #if !defined(_ASM) 76 77 typedef struct panic_nv { 78 char pnv_name[PANICNVNAMELEN]; /* String name */ 79 uint64_t pnv_value; /* Value */ 80 } panic_nv_t; 81 82 typedef struct panic_data { 83 uint32_t pd_version; /* Version number of panic_data_t */ 84 uint32_t pd_msgoff; /* Message byte offset in panicbuf */ 85 char pd_uuid[36 + 1]; /* image uuid */ 86 panic_nv_t pd_nvdata[1]; /* Array of named data */ 87 } panic_data_t; 88 89 typedef struct summary_dump { 90 uint32_t sd_magic; /* magic number */ 91 uint32_t sd_ssum; /* checsksum32(stack buffer) */ 92 /* 93 * stack buffer and other summary data follow here -- see 94 * dump_summary() 95 */ 96 } summary_dump_t; 97 98 #if defined(_KERNEL) 99 100 /* 101 * Kernel macros for adding information to pd_nvdata[]. PANICNVGET() returns 102 * a panic_nv_t pointer (pnv) after the end of the existing data, PANICNVADD() 103 * modifies the current item and increments pnv, and PANICNVSET() rewrites 104 * pd_msgoff to indicate the end of pd_nvdata[]. 105 */ 106 #define PANICNVGET(pdp) \ 107 ((pdp)->pd_nvdata + (((pdp)->pd_msgoff - \ 108 (sizeof (panic_data_t) - sizeof (panic_nv_t))) / sizeof (panic_nv_t))) 109 110 #define PANICNVADD(pnv, n, v) \ 111 { \ 112 (void) strncpy((pnv)->pnv_name, (n), PANICNVNAMELEN); \ 113 (pnv)->pnv_value = (uint64_t)(v); (pnv)++; \ 114 } 115 116 #define PANICNVSET(pdp, pnv) \ 117 (pdp)->pd_msgoff = (uint32_t)((char *)(pnv) - (char *)(pdp)); 118 119 /* 120 * Kernel panic data; preserved in crash dump for debuggers. 121 */ 122 #pragma align 8(panicbuf) 123 extern char panicbuf[PANICBUFSIZE]; 124 extern kthread_t *panic_thread; 125 extern cpu_t panic_cpu; 126 extern hrtime_t panic_hrtime; 127 extern timespec_t panic_hrestime; 128 129 /* 130 * Forward declarations for types: 131 */ 132 struct panic_trap_info; 133 struct regs; 134 135 /* 136 * Miscellaneous state variables defined in or used by the panic code: 137 */ 138 extern char *panic_bootstr; 139 extern int panic_bootfcn; 140 extern int panic_forced; 141 extern int halt_on_panic; 142 extern int nopanicdebug; 143 extern int do_polled_io; 144 extern int obpdebug; 145 extern int in_sync; 146 extern int panic_quiesce; 147 extern int panic_dump; 148 extern int64_t panic_lbolt64; 149 extern label_t panic_regs; 150 extern struct regs *panic_reg; 151 extern dev_info_t *panic_dip; 152 153 /* 154 * Panic functions called from the common panic code which must be 155 * implemented by architecture or platform-specific code: 156 */ 157 extern void panic_saveregs(panic_data_t *, struct regs *); 158 extern void panic_savetrap(panic_data_t *, struct panic_trap_info *); 159 extern void panic_showtrap(struct panic_trap_info *); 160 extern void panic_stopcpus(cpu_t *, kthread_t *, int); 161 extern void panic_enter_hw(int); 162 extern void panic_quiesce_hw(panic_data_t *); 163 extern void panic_dump_hw(int); 164 extern int panic_trigger(int *); 165 166 #endif /* _KERNEL */ 167 #endif /* !_ASM */ 168 169 #ifdef __cplusplus 170 } 171 #endif 172 173 #endif /* _SYS_PANIC_H */ 174