1 /* Copyright (c) 2006, Google Inc.
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 
30 /* minidump_format.h: A cross-platform reimplementation of minidump-related
31  * portions of DbgHelp.h from the Windows Platform SDK.
32  *
33  * (This is C99 source, please don't corrupt it with C++.)
34  *
35  * This file contains the necessary definitions to read minidump files
36  * produced on x86.  These files may be read on any platform provided
37  * that the alignments of these structures on the processing system are
38  * identical to the alignments of these structures on the producing system.
39  * For this reason, precise-sized types are used.  The structures defined
40  * by this file have been laid out to minimize alignment problems by ensuring
41  * ensuring that all members are aligned on their natural boundaries.  In
42  * In some cases, tail-padding may be significant when different ABIs specify
43  * different tail-padding behaviors.  To avoid problems when reading or
44  * writing affected structures, MD_*_SIZE macros are provided where needed,
45  * containing the useful size of the structures without padding.
46  *
47  * Structures that are defined by Microsoft to contain a zero-length array
48  * are instead defined here to contain an array with one element, as
49  * zero-length arrays are forbidden by standard C and C++.  In these cases,
50  * *_minsize constants are provided to be used in place of sizeof.  For a
51  * cleaner interface to these sizes when using C++, see minidump_size.h.
52  *
53  * These structures are also sufficient to populate minidump files.
54  *
55  * These definitions may be extended to support handling minidump files
56  * for other CPUs and other operating systems.
57  *
58  * Because precise data type sizes are crucial for this implementation to
59  * function properly and portably in terms of interoperability with minidumps
60  * produced by DbgHelp on Windows, a set of primitive types with known sizes
61  * are used as the basis of each structure defined by this file.  DbgHelp
62  * on Windows is assumed to be the reference implementation; this file
63  * seeks to provide a cross-platform compatible implementation.  To avoid
64  * collisions with the types and values defined and used by DbgHelp in the
65  * event that this implementation is used on Windows, each type and value
66  * defined here is given a new name, beginning with "MD".  Names of the
67  * equivalent types and values in the Windows Platform SDK are given in
68  * comments.
69  *
70  * Author: Mark Mentovai */
71 
72 #ifndef GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_X86_H__
73 #define GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_X86_H__
74 
75 #define MD_FLOATINGSAVEAREA_X86_REGISTERAREA_SIZE 80
76      /* SIZE_OF_80387_REGISTERS */
77 
78 typedef struct {
79   uint32_t control_word;
80   uint32_t status_word;
81   uint32_t tag_word;
82   uint32_t error_offset;
83   uint32_t error_selector;
84   uint32_t data_offset;
85   uint32_t data_selector;
86 
87   /* register_area contains eight 80-bit (x87 "long double") quantities for
88    * floating-point registers %st0 (%mm0) through %st7 (%mm7). */
89   uint8_t  register_area[MD_FLOATINGSAVEAREA_X86_REGISTERAREA_SIZE];
90   uint32_t cr0_npx_state;
91 } MDFloatingSaveAreaX86;  /* FLOATING_SAVE_AREA */
92 
93 
94 #define MD_CONTEXT_X86_EXTENDED_REGISTERS_SIZE 512
95      /* MAXIMUM_SUPPORTED_EXTENSION */
96 
97 typedef struct {
98   /* The next field determines the layout of the structure, and which parts
99    * of it are populated */
100   uint32_t             context_flags;
101 
102   /* The next 6 registers are included with MD_CONTEXT_X86_DEBUG_REGISTERS */
103   uint32_t             dr0;
104   uint32_t             dr1;
105   uint32_t             dr2;
106   uint32_t             dr3;
107   uint32_t             dr6;
108   uint32_t             dr7;
109 
110   /* The next field is included with MD_CONTEXT_X86_FLOATING_POINT */
111   MDFloatingSaveAreaX86 float_save;
112 
113   /* The next 4 registers are included with MD_CONTEXT_X86_SEGMENTS */
114   uint32_t             gs;
115   uint32_t             fs;
116   uint32_t             es;
117   uint32_t             ds;
118   /* The next 6 registers are included with MD_CONTEXT_X86_INTEGER */
119   uint32_t             edi;
120   uint32_t             esi;
121   uint32_t             ebx;
122   uint32_t             edx;
123   uint32_t             ecx;
124   uint32_t             eax;
125 
126   /* The next 6 registers are included with MD_CONTEXT_X86_CONTROL */
127   uint32_t             ebp;
128   uint32_t             eip;
129   uint32_t             cs;      /* WinNT.h says "must be sanitized" */
130   uint32_t             eflags;  /* WinNT.h says "must be sanitized" */
131   uint32_t             esp;
132   uint32_t             ss;
133 
134   /* The next field is included with MD_CONTEXT_X86_EXTENDED_REGISTERS.
135    * It contains vector (MMX/SSE) registers.  It it laid out in the
136    * format used by the fxsave and fsrstor instructions, so it includes
137    * a copy of the x87 floating-point registers as well.  See FXSAVE in
138    * "Intel Architecture Software Developer's Manual, Volume 2." */
139   uint8_t              extended_registers[
140                          MD_CONTEXT_X86_EXTENDED_REGISTERS_SIZE];
141 } MDRawContextX86;  /* CONTEXT */
142 
143 /* For (MDRawContextX86).context_flags.  These values indicate the type of
144  * context stored in the structure.  The high 24 bits identify the CPU, the
145  * low 8 bits identify the type of context saved. */
146 #define MD_CONTEXT_X86                    0x00010000
147      /* CONTEXT_i386, CONTEXT_i486: identifies CPU */
148 #define MD_CONTEXT_X86_CONTROL            (MD_CONTEXT_X86 | 0x00000001)
149      /* CONTEXT_CONTROL */
150 #define MD_CONTEXT_X86_INTEGER            (MD_CONTEXT_X86 | 0x00000002)
151      /* CONTEXT_INTEGER */
152 #define MD_CONTEXT_X86_SEGMENTS           (MD_CONTEXT_X86 | 0x00000004)
153      /* CONTEXT_SEGMENTS */
154 #define MD_CONTEXT_X86_FLOATING_POINT     (MD_CONTEXT_X86 | 0x00000008)
155      /* CONTEXT_FLOATING_POINT */
156 #define MD_CONTEXT_X86_DEBUG_REGISTERS    (MD_CONTEXT_X86 | 0x00000010)
157      /* CONTEXT_DEBUG_REGISTERS */
158 #define MD_CONTEXT_X86_EXTENDED_REGISTERS (MD_CONTEXT_X86 | 0x00000020)
159      /* CONTEXT_EXTENDED_REGISTERS */
160 #define MD_CONTEXT_X86_XSTATE             (MD_CONTEXT_X86 | 0x00000040)
161      /* CONTEXT_XSTATE */
162 
163 #define MD_CONTEXT_X86_FULL              (MD_CONTEXT_X86_CONTROL | \
164                                           MD_CONTEXT_X86_INTEGER | \
165                                           MD_CONTEXT_X86_SEGMENTS)
166      /* CONTEXT_FULL */
167 
168 #define MD_CONTEXT_X86_ALL               (MD_CONTEXT_X86_FULL | \
169                                           MD_CONTEXT_X86_FLOATING_POINT | \
170                                           MD_CONTEXT_X86_DEBUG_REGISTERS | \
171                                           MD_CONTEXT_X86_EXTENDED_REGISTERS)
172      /* CONTEXT_ALL */
173 
174 #endif /* GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_X86_H__ */
175