1 /* Copyright 2006 Google LLC 2 * 3 * Redistribution and use in source and binary forms, with or without 4 * modification, are permitted provided that the following conditions are 5 * met: 6 * 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above 10 * copyright notice, this list of conditions and the following disclaimer 11 * in the documentation and/or other materials provided with the 12 * distribution. 13 * * Neither the name of Google LLC nor the names of its 14 * contributors may be used to endorse or promote products derived from 15 * this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 28 29 /* minidump_format.h: A cross-platform reimplementation of minidump-related 30 * portions of DbgHelp.h from the Windows Platform SDK. 31 * 32 * (This is C99 source, please don't corrupt it with C++.) 33 * 34 * This file contains the necessary definitions to read minidump files 35 * produced on amd64. These files may be read on any platform provided 36 * that the alignments of these structures on the processing system are 37 * identical to the alignments of these structures on the producing system. 38 * For this reason, precise-sized types are used. The structures defined 39 * by this file have been laid out to minimize alignment problems by ensuring 40 * ensuring that all members are aligned on their natural boundaries. In 41 * In some cases, tail-padding may be significant when different ABIs specify 42 * different tail-padding behaviors. To avoid problems when reading or 43 * writing affected structures, MD_*_SIZE macros are provided where needed, 44 * containing the useful size of the structures without padding. 45 * 46 * Structures that are defined by Microsoft to contain a zero-length array 47 * are instead defined here to contain an array with one element, as 48 * zero-length arrays are forbidden by standard C and C++. In these cases, 49 * *_minsize constants are provided to be used in place of sizeof. For a 50 * cleaner interface to these sizes when using C++, see minidump_size.h. 51 * 52 * These structures are also sufficient to populate minidump files. 53 * 54 * These definitions may be extended to support handling minidump files 55 * for other CPUs and other operating systems. 56 * 57 * Because precise data type sizes are crucial for this implementation to 58 * function properly and portably in terms of interoperability with minidumps 59 * produced by DbgHelp on Windows, a set of primitive types with known sizes 60 * are used as the basis of each structure defined by this file. DbgHelp 61 * on Windows is assumed to be the reference implementation; this file 62 * seeks to provide a cross-platform compatible implementation. To avoid 63 * collisions with the types and values defined and used by DbgHelp in the 64 * event that this implementation is used on Windows, each type and value 65 * defined here is given a new name, beginning with "MD". Names of the 66 * equivalent types and values in the Windows Platform SDK are given in 67 * comments. 68 * 69 * Author: Mark Mentovai 70 * Change to split into its own file: Neal Sidhwaney */ 71 72 #ifndef GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_AMD64_H__ 73 #define GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_AMD64_H__ 74 75 76 /* 77 * AMD64 support, see WINNT.H 78 */ 79 80 typedef struct { 81 uint16_t control_word; 82 uint16_t status_word; 83 uint8_t tag_word; 84 uint8_t reserved1; 85 uint16_t error_opcode; 86 uint32_t error_offset; 87 uint16_t error_selector; 88 uint16_t reserved2; 89 uint32_t data_offset; 90 uint16_t data_selector; 91 uint16_t reserved3; 92 uint32_t mx_csr; 93 uint32_t mx_csr_mask; 94 uint128_struct float_registers[8]; 95 uint128_struct xmm_registers[16]; 96 uint8_t reserved4[96]; 97 } MDXmmSaveArea32AMD64; /* XMM_SAVE_AREA32 */ 98 99 #define MD_CONTEXT_AMD64_VR_COUNT 26 100 101 typedef struct { 102 /* 103 * Register parameter home addresses. 104 */ 105 uint64_t p1_home; 106 uint64_t p2_home; 107 uint64_t p3_home; 108 uint64_t p4_home; 109 uint64_t p5_home; 110 uint64_t p6_home; 111 112 /* The next field determines the layout of the structure, and which parts 113 * of it are populated */ 114 uint32_t context_flags; 115 uint32_t mx_csr; 116 117 /* The next register is included with MD_CONTEXT_AMD64_CONTROL */ 118 uint16_t cs; 119 120 /* The next 4 registers are included with MD_CONTEXT_AMD64_SEGMENTS */ 121 uint16_t ds; 122 uint16_t es; 123 uint16_t fs; 124 uint16_t gs; 125 126 /* The next 2 registers are included with MD_CONTEXT_AMD64_CONTROL */ 127 uint16_t ss; 128 uint32_t eflags; 129 130 /* The next 6 registers are included with MD_CONTEXT_AMD64_DEBUG_REGISTERS */ 131 uint64_t dr0; 132 uint64_t dr1; 133 uint64_t dr2; 134 uint64_t dr3; 135 uint64_t dr6; 136 uint64_t dr7; 137 138 /* The next 4 registers are included with MD_CONTEXT_AMD64_INTEGER */ 139 uint64_t rax; 140 uint64_t rcx; 141 uint64_t rdx; 142 uint64_t rbx; 143 144 /* The next register is included with MD_CONTEXT_AMD64_CONTROL */ 145 uint64_t rsp; 146 147 /* The next 11 registers are included with MD_CONTEXT_AMD64_INTEGER */ 148 uint64_t rbp; 149 uint64_t rsi; 150 uint64_t rdi; 151 uint64_t r8; 152 uint64_t r9; 153 uint64_t r10; 154 uint64_t r11; 155 uint64_t r12; 156 uint64_t r13; 157 uint64_t r14; 158 uint64_t r15; 159 160 /* The next register is included with MD_CONTEXT_AMD64_CONTROL */ 161 uint64_t rip; 162 163 /* The next set of registers are included with 164 * MD_CONTEXT_AMD64_FLOATING_POINT 165 */ 166 union { 167 MDXmmSaveArea32AMD64 flt_save; 168 struct { 169 uint128_struct header[2]; 170 uint128_struct legacy[8]; 171 uint128_struct xmm0; 172 uint128_struct xmm1; 173 uint128_struct xmm2; 174 uint128_struct xmm3; 175 uint128_struct xmm4; 176 uint128_struct xmm5; 177 uint128_struct xmm6; 178 uint128_struct xmm7; 179 uint128_struct xmm8; 180 uint128_struct xmm9; 181 uint128_struct xmm10; 182 uint128_struct xmm11; 183 uint128_struct xmm12; 184 uint128_struct xmm13; 185 uint128_struct xmm14; 186 uint128_struct xmm15; 187 } sse_registers; 188 }; 189 190 uint128_struct vector_register[MD_CONTEXT_AMD64_VR_COUNT]; 191 uint64_t vector_control; 192 193 /* The next 5 registers are included with MD_CONTEXT_AMD64_DEBUG_REGISTERS */ 194 uint64_t debug_control; 195 uint64_t last_branch_to_rip; 196 uint64_t last_branch_from_rip; 197 uint64_t last_exception_to_rip; 198 uint64_t last_exception_from_rip; 199 200 } MDRawContextAMD64; /* CONTEXT */ 201 202 /* For (MDRawContextAMD64).context_flags. These values indicate the type of 203 * context stored in the structure. The high 24 bits identify the CPU, the 204 * low 8 bits identify the type of context saved. */ 205 #define MD_CONTEXT_AMD64 0x00100000 /* CONTEXT_AMD64 */ 206 #define MD_CONTEXT_AMD64_CONTROL (MD_CONTEXT_AMD64 | 0x00000001) 207 /* CONTEXT_CONTROL */ 208 #define MD_CONTEXT_AMD64_INTEGER (MD_CONTEXT_AMD64 | 0x00000002) 209 /* CONTEXT_INTEGER */ 210 #define MD_CONTEXT_AMD64_SEGMENTS (MD_CONTEXT_AMD64 | 0x00000004) 211 /* CONTEXT_SEGMENTS */ 212 #define MD_CONTEXT_AMD64_FLOATING_POINT (MD_CONTEXT_AMD64 | 0x00000008) 213 /* CONTEXT_FLOATING_POINT */ 214 #define MD_CONTEXT_AMD64_DEBUG_REGISTERS (MD_CONTEXT_AMD64 | 0x00000010) 215 /* CONTEXT_DEBUG_REGISTERS */ 216 #define MD_CONTEXT_AMD64_XSTATE (MD_CONTEXT_AMD64 | 0x00000040) 217 /* CONTEXT_XSTATE */ 218 219 /* WinNT.h refers to CONTEXT_MMX_REGISTERS but doesn't appear to define it 220 * I think it really means CONTEXT_FLOATING_POINT. 221 */ 222 223 #define MD_CONTEXT_AMD64_FULL (MD_CONTEXT_AMD64_CONTROL | \ 224 MD_CONTEXT_AMD64_INTEGER | \ 225 MD_CONTEXT_AMD64_FLOATING_POINT) 226 /* CONTEXT_FULL */ 227 228 #define MD_CONTEXT_AMD64_ALL (MD_CONTEXT_AMD64_FULL | \ 229 MD_CONTEXT_AMD64_SEGMENTS | \ 230 MD_CONTEXT_AMD64_DEBUG_REGISTERS) 231 /* CONTEXT_ALL */ 232 233 234 #endif /* GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_AMD64_H__ */ 235