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 x86. 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 71 #ifndef GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_X86_H__ 72 #define GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_X86_H__ 73 74 #define MD_FLOATINGSAVEAREA_X86_REGISTERAREA_SIZE 80 75 /* SIZE_OF_80387_REGISTERS */ 76 77 typedef struct { 78 uint32_t control_word; 79 uint32_t status_word; 80 uint32_t tag_word; 81 uint32_t error_offset; 82 uint32_t error_selector; 83 uint32_t data_offset; 84 uint32_t data_selector; 85 86 /* register_area contains eight 80-bit (x87 "long double") quantities for 87 * floating-point registers %st0 (%mm0) through %st7 (%mm7). */ 88 uint8_t register_area[MD_FLOATINGSAVEAREA_X86_REGISTERAREA_SIZE]; 89 uint32_t cr0_npx_state; 90 } MDFloatingSaveAreaX86; /* FLOATING_SAVE_AREA */ 91 92 93 #define MD_CONTEXT_X86_EXTENDED_REGISTERS_SIZE 512 94 /* MAXIMUM_SUPPORTED_EXTENSION */ 95 96 typedef struct { 97 /* The next field determines the layout of the structure, and which parts 98 * of it are populated */ 99 uint32_t context_flags; 100 101 /* The next 6 registers are included with MD_CONTEXT_X86_DEBUG_REGISTERS */ 102 uint32_t dr0; 103 uint32_t dr1; 104 uint32_t dr2; 105 uint32_t dr3; 106 uint32_t dr6; 107 uint32_t dr7; 108 109 /* The next field is included with MD_CONTEXT_X86_FLOATING_POINT */ 110 MDFloatingSaveAreaX86 float_save; 111 112 /* The next 4 registers are included with MD_CONTEXT_X86_SEGMENTS */ 113 uint32_t gs; 114 uint32_t fs; 115 uint32_t es; 116 uint32_t ds; 117 /* The next 6 registers are included with MD_CONTEXT_X86_INTEGER */ 118 uint32_t edi; 119 uint32_t esi; 120 uint32_t ebx; 121 uint32_t edx; 122 uint32_t ecx; 123 uint32_t eax; 124 125 /* The next 6 registers are included with MD_CONTEXT_X86_CONTROL */ 126 uint32_t ebp; 127 uint32_t eip; 128 uint32_t cs; /* WinNT.h says "must be sanitized" */ 129 uint32_t eflags; /* WinNT.h says "must be sanitized" */ 130 uint32_t esp; 131 uint32_t ss; 132 133 /* The next field is included with MD_CONTEXT_X86_EXTENDED_REGISTERS. 134 * It contains vector (MMX/SSE) registers. It it laid out in the 135 * format used by the fxsave and fsrstor instructions, so it includes 136 * a copy of the x87 floating-point registers as well. See FXSAVE in 137 * "Intel Architecture Software Developer's Manual, Volume 2." */ 138 uint8_t extended_registers[ 139 MD_CONTEXT_X86_EXTENDED_REGISTERS_SIZE]; 140 } MDRawContextX86; /* CONTEXT */ 141 142 /* For (MDRawContextX86).context_flags. These values indicate the type of 143 * context stored in the structure. The high 24 bits identify the CPU, the 144 * low 8 bits identify the type of context saved. */ 145 #define MD_CONTEXT_X86 0x00010000 146 /* CONTEXT_i386, CONTEXT_i486: identifies CPU */ 147 #define MD_CONTEXT_X86_CONTROL (MD_CONTEXT_X86 | 0x00000001) 148 /* CONTEXT_CONTROL */ 149 #define MD_CONTEXT_X86_INTEGER (MD_CONTEXT_X86 | 0x00000002) 150 /* CONTEXT_INTEGER */ 151 #define MD_CONTEXT_X86_SEGMENTS (MD_CONTEXT_X86 | 0x00000004) 152 /* CONTEXT_SEGMENTS */ 153 #define MD_CONTEXT_X86_FLOATING_POINT (MD_CONTEXT_X86 | 0x00000008) 154 /* CONTEXT_FLOATING_POINT */ 155 #define MD_CONTEXT_X86_DEBUG_REGISTERS (MD_CONTEXT_X86 | 0x00000010) 156 /* CONTEXT_DEBUG_REGISTERS */ 157 #define MD_CONTEXT_X86_EXTENDED_REGISTERS (MD_CONTEXT_X86 | 0x00000020) 158 /* CONTEXT_EXTENDED_REGISTERS */ 159 #define MD_CONTEXT_X86_XSTATE (MD_CONTEXT_X86 | 0x00000040) 160 /* CONTEXT_XSTATE */ 161 162 #define MD_CONTEXT_X86_FULL (MD_CONTEXT_X86_CONTROL | \ 163 MD_CONTEXT_X86_INTEGER | \ 164 MD_CONTEXT_X86_SEGMENTS) 165 /* CONTEXT_FULL */ 166 167 #define MD_CONTEXT_X86_ALL (MD_CONTEXT_X86_FULL | \ 168 MD_CONTEXT_X86_FLOATING_POINT | \ 169 MD_CONTEXT_X86_DEBUG_REGISTERS | \ 170 MD_CONTEXT_X86_EXTENDED_REGISTERS) 171 /* CONTEXT_ALL */ 172 173 #endif /* GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_X86_H__ */ 174