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  * Structures that are defined by Microsoft to contain a zero-length array
36  * are instead defined here to contain an array with one element, as
37  * zero-length arrays are forbidden by standard C and C++.  In these cases,
38  * *_minsize constants are provided to be used in place of sizeof.  For a
39  * cleaner interface to these sizes when using C++, see minidump_size.h.
40  *
41  * These structures are also sufficient to populate minidump files.
42  *
43  * These definitions may be extended to support handling minidump files
44  * for other CPUs and other operating systems.
45  *
46  * Because precise data type sizes are crucial for this implementation to
47  * function properly and portably in terms of interoperability with minidumps
48  * produced by DbgHelp on Windows, a set of primitive types with known sizes
49  * are used as the basis of each structure defined by this file.  DbgHelp
50  * on Windows is assumed to be the reference implementation; this file
51  * seeks to provide a cross-platform compatible implementation.  To avoid
52  * collisions with the types and values defined and used by DbgHelp in the
53  * event that this implementation is used on Windows, each type and value
54  * defined here is given a new name, beginning with "MD".  Names of the
55  * equivalent types and values in the Windows Platform SDK are given in
56  * comments.
57  *
58  * Author: Mark Mentovai */
59 
60 
61 #ifndef GOOGLE_BREAKPAD_COMMON_MINIDUMP_FORMAT_H__
62 #define GOOGLE_BREAKPAD_COMMON_MINIDUMP_FORMAT_H__
63 
64 #include <stddef.h>
65 
66 #include "google_breakpad/common/breakpad_types.h"
67 
68 
69 #if defined(_MSC_VER)
70 /* Disable "zero-sized array in struct/union" warnings when compiling in
71  * MSVC.  DbgHelp.h does this too. */
72 #pragma warning(push)
73 #pragma warning(disable:4200)
74 #endif  /* _MSC_VER */
75 
76 
77 /*
78  * guiddef.h
79  */
80 
81 typedef struct {
82   uint32_t data1;
83   uint16_t data2;
84   uint16_t data3;
85   uint8_t  data4[8];
86 } MDGUID;  /* GUID */
87 
88 
89 /*
90  * WinNT.h
91  */
92 
93 /* Non-x86 CPU identifiers found in the high 24 bits of
94  * (MDRawContext*).context_flags.  These aren't used by Breakpad, but are
95  * defined here for reference, to avoid assigning values that conflict
96  * (although some values already conflict). */
97 #define MD_CONTEXT_IA64  0x00080000  /* CONTEXT_IA64 */
98 /* Additional values from winnt.h in the Windows CE 5.0 SDK: */
99 #define MD_CONTEXT_SHX   0x000000c0  /* CONTEXT_SH4 (Super-H, includes SH3) */
100 #define MD_CONTEXT_ALPHA 0x00020000  /* CONTEXT_ALPHA */
101 
102 /* As of Windows 7 SP1, the number of flag bits has increased to
103  * include 0x40 (CONTEXT_XSTATE):
104  * http://msdn.microsoft.com/en-us/library/hh134238%28v=vs.85%29.aspx */
105 #define MD_CONTEXT_CPU_MASK 0xffffff00
106 
107 
108 /* This is a base type for MDRawContextX86 and MDRawContextPPC.  This
109  * structure should never be allocated directly.  The actual structure type
110  * can be determined by examining the context_flags field. */
111 typedef struct {
112   uint32_t context_flags;
113 } MDRawContextBase;
114 
115 #include "minidump_cpu_amd64.h"
116 #include "minidump_cpu_arm.h"
117 #include "minidump_cpu_arm64.h"
118 #include "minidump_cpu_mips.h"
119 #include "minidump_cpu_ppc.h"
120 #include "minidump_cpu_ppc64.h"
121 #include "minidump_cpu_sparc.h"
122 #include "minidump_cpu_x86.h"
123 
124 /*
125  * WinVer.h
126  */
127 
128 
129 typedef struct {
130   uint32_t signature;
131   uint32_t struct_version;
132   uint32_t file_version_hi;
133   uint32_t file_version_lo;
134   uint32_t product_version_hi;
135   uint32_t product_version_lo;
136   uint32_t file_flags_mask;    /* Identifies valid bits in fileFlags */
137   uint32_t file_flags;
138   uint32_t file_os;
139   uint32_t file_type;
140   uint32_t file_subtype;
141   uint32_t file_date_hi;
142   uint32_t file_date_lo;
143 } MDVSFixedFileInfo;  /* VS_FIXEDFILEINFO */
144 
145 /* For (MDVSFixedFileInfo).signature */
146 #define MD_VSFIXEDFILEINFO_SIGNATURE 0xfeef04bd
147      /* VS_FFI_SIGNATURE */
148 
149 /* For (MDVSFixedFileInfo).version */
150 #define MD_VSFIXEDFILEINFO_VERSION 0x00010000
151      /* VS_FFI_STRUCVERSION */
152 
153 /* For (MDVSFixedFileInfo).file_flags_mask and
154  * (MDVSFixedFileInfo).file_flags */
155 #define MD_VSFIXEDFILEINFO_FILE_FLAGS_DEBUG        0x00000001
156      /* VS_FF_DEBUG */
157 #define MD_VSFIXEDFILEINFO_FILE_FLAGS_PRERELEASE   0x00000002
158      /* VS_FF_PRERELEASE */
159 #define MD_VSFIXEDFILEINFO_FILE_FLAGS_PATCHED      0x00000004
160      /* VS_FF_PATCHED */
161 #define MD_VSFIXEDFILEINFO_FILE_FLAGS_PRIVATEBUILD 0x00000008
162      /* VS_FF_PRIVATEBUILD */
163 #define MD_VSFIXEDFILEINFO_FILE_FLAGS_INFOINFERRED 0x00000010
164      /* VS_FF_INFOINFERRED */
165 #define MD_VSFIXEDFILEINFO_FILE_FLAGS_SPECIALBUILD 0x00000020
166      /* VS_FF_SPECIALBUILD */
167 
168 /* For (MDVSFixedFileInfo).file_os: high 16 bits */
169 #define MD_VSFIXEDFILEINFO_FILE_OS_UNKNOWN    0          /* VOS_UNKNOWN */
170 #define MD_VSFIXEDFILEINFO_FILE_OS_DOS        (1 << 16)  /* VOS_DOS */
171 #define MD_VSFIXEDFILEINFO_FILE_OS_OS216      (2 << 16)  /* VOS_OS216 */
172 #define MD_VSFIXEDFILEINFO_FILE_OS_OS232      (3 << 16)  /* VOS_OS232 */
173 #define MD_VSFIXEDFILEINFO_FILE_OS_NT         (4 << 16)  /* VOS_NT */
174 #define MD_VSFIXEDFILEINFO_FILE_OS_WINCE      (5 << 16)  /* VOS_WINCE */
175 /* Low 16 bits */
176 #define MD_VSFIXEDFILEINFO_FILE_OS__BASE      0          /* VOS__BASE */
177 #define MD_VSFIXEDFILEINFO_FILE_OS__WINDOWS16 1          /* VOS__WINDOWS16 */
178 #define MD_VSFIXEDFILEINFO_FILE_OS__PM16      2          /* VOS__PM16 */
179 #define MD_VSFIXEDFILEINFO_FILE_OS__PM32      3          /* VOS__PM32 */
180 #define MD_VSFIXEDFILEINFO_FILE_OS__WINDOWS32 4          /* VOS__WINDOWS32 */
181 
182 /* For (MDVSFixedFileInfo).file_type */
183 #define MD_VSFIXEDFILEINFO_FILE_TYPE_UNKNOWN    0  /* VFT_UNKNOWN */
184 #define MD_VSFIXEDFILEINFO_FILE_TYPE_APP        1  /* VFT_APP */
185 #define MD_VSFIXEDFILEINFO_FILE_TYPE_DLL        2  /* VFT_DLL */
186 #define MD_VSFIXEDFILEINFO_FILE_TYPE_DRV        3  /* VFT_DLL */
187 #define MD_VSFIXEDFILEINFO_FILE_TYPE_FONT       4  /* VFT_FONT */
188 #define MD_VSFIXEDFILEINFO_FILE_TYPE_VXD        5  /* VFT_VXD */
189 #define MD_VSFIXEDFILEINFO_FILE_TYPE_STATIC_LIB 7  /* VFT_STATIC_LIB */
190 
191 /* For (MDVSFixedFileInfo).file_subtype */
192 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_UNKNOWN                0
193      /* VFT2_UNKNOWN */
194 /* with file_type = MD_VSFIXEDFILEINFO_FILETYPE_DRV */
195 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_PRINTER            1
196      /* VFT2_DRV_PRINTER */
197 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_KEYBOARD           2
198      /* VFT2_DRV_KEYBOARD */
199 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_LANGUAGE           3
200      /* VFT2_DRV_LANGUAGE */
201 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_DISPLAY            4
202      /* VFT2_DRV_DISPLAY */
203 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_MOUSE              5
204      /* VFT2_DRV_MOUSE */
205 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_NETWORK            6
206      /* VFT2_DRV_NETWORK */
207 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_SYSTEM             7
208      /* VFT2_DRV_SYSTEM */
209 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_INSTALLABLE        8
210      /* VFT2_DRV_INSTALLABLE */
211 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_SOUND              9
212      /* VFT2_DRV_SOUND */
213 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_COMM              10
214      /* VFT2_DRV_COMM */
215 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_INPUTMETHOD       11
216      /* VFT2_DRV_INPUTMETHOD */
217 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_VERSIONED_PRINTER 12
218      /* VFT2_DRV_VERSIONED_PRINTER */
219 /* with file_type = MD_VSFIXEDFILEINFO_FILETYPE_FONT */
220 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_FONT_RASTER            1
221      /* VFT2_FONT_RASTER */
222 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_FONT_VECTOR            2
223      /* VFT2_FONT_VECTOR */
224 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_FONT_TRUETYPE          3
225      /* VFT2_FONT_TRUETYPE */
226 
227 
228 /*
229  * DbgHelp.h
230  */
231 
232 
233 /* An MDRVA is an offset into the minidump file.  The beginning of the
234  * MDRawHeader is at offset 0. */
235 typedef uint32_t MDRVA;  /* RVA */
236 
237 typedef struct {
238   uint32_t  data_size;
239   MDRVA     rva;
240 } MDLocationDescriptor;  /* MINIDUMP_LOCATION_DESCRIPTOR */
241 
242 
243 typedef struct {
244   /* The base address of the memory range on the host that produced the
245    * minidump. */
246   uint64_t             start_of_memory_range;
247 
248   MDLocationDescriptor memory;
249 } MDMemoryDescriptor;  /* MINIDUMP_MEMORY_DESCRIPTOR */
250 
251 
252 typedef struct {
253   uint32_t  signature;
254   uint32_t  version;
255   uint32_t  stream_count;
256   MDRVA     stream_directory_rva;  /* A |stream_count|-sized array of
257                                     * MDRawDirectory structures. */
258   uint32_t  checksum;              /* Can be 0.  In fact, that's all that's
259                                     * been found in minidump files. */
260   uint32_t  time_date_stamp;       /* time_t */
261   uint64_t  flags;
262 } MDRawHeader;  /* MINIDUMP_HEADER */
263 
264 /* For (MDRawHeader).signature and (MDRawHeader).version.  Note that only the
265  * low 16 bits of (MDRawHeader).version are MD_HEADER_VERSION.  Per the
266  * documentation, the high 16 bits are implementation-specific. */
267 #define MD_HEADER_SIGNATURE 0x504d444d /* 'PMDM' */
268      /* MINIDUMP_SIGNATURE */
269 #define MD_HEADER_VERSION   0x0000a793 /* 42899 */
270      /* MINIDUMP_VERSION */
271 
272 /* For (MDRawHeader).flags: */
273 typedef enum {
274   /* MD_NORMAL is the standard type of minidump.  It includes full
275    * streams for the thread list, module list, exception, system info,
276    * and miscellaneous info.  A memory list stream is also present,
277    * pointing to the same stack memory contained in the thread list,
278    * as well as a 256-byte region around the instruction address that
279    * was executing when the exception occurred.  Stack memory is from
280    * 4 bytes below a thread's stack pointer up to the top of the
281    * memory region encompassing the stack. */
282   MD_NORMAL                            = 0x00000000,
283   MD_WITH_DATA_SEGS                    = 0x00000001,
284   MD_WITH_FULL_MEMORY                  = 0x00000002,
285   MD_WITH_HANDLE_DATA                  = 0x00000004,
286   MD_FILTER_MEMORY                     = 0x00000008,
287   MD_SCAN_MEMORY                       = 0x00000010,
288   MD_WITH_UNLOADED_MODULES             = 0x00000020,
289   MD_WITH_INDIRECTLY_REFERENCED_MEMORY = 0x00000040,
290   MD_FILTER_MODULE_PATHS               = 0x00000080,
291   MD_WITH_PROCESS_THREAD_DATA          = 0x00000100,
292   MD_WITH_PRIVATE_READ_WRITE_MEMORY    = 0x00000200,
293   MD_WITHOUT_OPTIONAL_DATA             = 0x00000400,
294   MD_WITH_FULL_MEMORY_INFO             = 0x00000800,
295   MD_WITH_THREAD_INFO                  = 0x00001000,
296   MD_WITH_CODE_SEGS                    = 0x00002000,
297   MD_WITHOUT_AUXILLIARY_SEGS           = 0x00004000,
298   MD_WITH_FULL_AUXILLIARY_STATE        = 0x00008000,
299   MD_WITH_PRIVATE_WRITE_COPY_MEMORY    = 0x00010000,
300   MD_IGNORE_INACCESSIBLE_MEMORY        = 0x00020000,
301   MD_WITH_TOKEN_INFORMATION            = 0x00040000
302 } MDType;  /* MINIDUMP_TYPE */
303 
304 
305 typedef struct {
306   uint32_t             stream_type;
307   MDLocationDescriptor location;
308 } MDRawDirectory;  /* MINIDUMP_DIRECTORY */
309 
310 /* For (MDRawDirectory).stream_type */
311 typedef enum {
312   MD_UNUSED_STREAM               =  0,
313   MD_RESERVED_STREAM_0           =  1,
314   MD_RESERVED_STREAM_1           =  2,
315   MD_THREAD_LIST_STREAM          =  3,  /* MDRawThreadList */
316   MD_MODULE_LIST_STREAM          =  4,  /* MDRawModuleList */
317   MD_MEMORY_LIST_STREAM          =  5,  /* MDRawMemoryList */
318   MD_EXCEPTION_STREAM            =  6,  /* MDRawExceptionStream */
319   MD_SYSTEM_INFO_STREAM          =  7,  /* MDRawSystemInfo */
320   MD_THREAD_EX_LIST_STREAM       =  8,
321   MD_MEMORY_64_LIST_STREAM       =  9,
322   MD_COMMENT_STREAM_A            = 10,
323   MD_COMMENT_STREAM_W            = 11,
324   MD_HANDLE_DATA_STREAM          = 12,
325   MD_FUNCTION_TABLE_STREAM       = 13,
326   MD_UNLOADED_MODULE_LIST_STREAM = 14,
327   MD_MISC_INFO_STREAM            = 15,  /* MDRawMiscInfo */
328   MD_MEMORY_INFO_LIST_STREAM     = 16,  /* MDRawMemoryInfoList */
329   MD_THREAD_INFO_LIST_STREAM     = 17,
330   MD_HANDLE_OPERATION_LIST_STREAM = 18,
331   MD_TOKEN_STREAM                = 19,
332   MD_JAVASCRIPT_DATA_STREAM      = 20,
333   MD_SYSTEM_MEMORY_INFO_STREAM   = 21,
334   MD_PROCESS_VM_COUNTERS_STREAM  = 22,
335   MD_LAST_RESERVED_STREAM        = 0x0000ffff,
336 
337   /* Breakpad extension types.  0x4767 = "Gg" */
338   MD_BREAKPAD_INFO_STREAM        = 0x47670001,  /* MDRawBreakpadInfo  */
339   MD_ASSERTION_INFO_STREAM       = 0x47670002,  /* MDRawAssertionInfo */
340   /* These are additional minidump stream values which are specific to
341    * the linux breakpad implementation. */
342   MD_LINUX_CPU_INFO              = 0x47670003,  /* /proc/cpuinfo      */
343   MD_LINUX_PROC_STATUS           = 0x47670004,  /* /proc/$x/status    */
344   MD_LINUX_LSB_RELEASE           = 0x47670005,  /* /etc/lsb-release   */
345   MD_LINUX_CMD_LINE              = 0x47670006,  /* /proc/$x/cmdline   */
346   MD_LINUX_ENVIRON               = 0x47670007,  /* /proc/$x/environ   */
347   MD_LINUX_AUXV                  = 0x47670008,  /* /proc/$x/auxv      */
348   MD_LINUX_MAPS                  = 0x47670009,  /* /proc/$x/maps      */
349   MD_LINUX_DSO_DEBUG             = 0x4767000A,  /* MDRawDebug{32,64}  */
350 
351   /* Crashpad extension types. 0x4350 = "CP"
352    * See Crashpad's minidump/minidump_extensions.h. */
353   MD_CRASHPAD_INFO_STREAM        = 0x43500001,  /* MDRawCrashpadInfo  */
354 } MDStreamType;  /* MINIDUMP_STREAM_TYPE */
355 
356 
357 typedef struct {
358   uint32_t length;     /* Length of buffer in bytes (not characters),
359                         * excluding 0-terminator */
360   uint16_t buffer[1];  /* UTF-16-encoded, 0-terminated */
361 } MDString;  /* MINIDUMP_STRING */
362 
363 static const size_t MDString_minsize = offsetof(MDString, buffer[0]);
364 
365 
366 typedef struct {
367   uint32_t             thread_id;
368   uint32_t             suspend_count;
369   uint32_t             priority_class;
370   uint32_t             priority;
371   uint64_t             teb;             /* Thread environment block */
372   MDMemoryDescriptor   stack;
373   MDLocationDescriptor thread_context;  /* MDRawContext[CPU] */
374 } MDRawThread;  /* MINIDUMP_THREAD */
375 
376 
377 typedef struct {
378   uint32_t    number_of_threads;
379   MDRawThread threads[1];
380 } MDRawThreadList;  /* MINIDUMP_THREAD_LIST */
381 
382 static const size_t MDRawThreadList_minsize = offsetof(MDRawThreadList,
383                                                        threads[0]);
384 
385 
386 typedef struct {
387   uint64_t             base_of_image;
388   uint32_t             size_of_image;
389   uint32_t             checksum;         /* 0 if unknown */
390   uint32_t             time_date_stamp;  /* time_t */
391   MDRVA                module_name_rva;  /* MDString, pathname or filename */
392   MDVSFixedFileInfo    version_info;
393 
394   /* The next field stores a CodeView record and is populated when a module's
395    * debug information resides in a PDB file.  It identifies the PDB file. */
396   MDLocationDescriptor cv_record;
397 
398   /* The next field is populated when a module's debug information resides
399    * in a DBG file.  It identifies the DBG file.  This field is effectively
400    * obsolete with modules built by recent toolchains. */
401   MDLocationDescriptor misc_record;
402 
403   /* Alignment problem: reserved0 and reserved1 are defined by the platform
404    * SDK as 64-bit quantities.  However, that results in a structure whose
405    * alignment is unpredictable on different CPUs and ABIs.  If the ABI
406    * specifies full alignment of 64-bit quantities in structures (as ppc
407    * does), there will be padding between miscRecord and reserved0.  If
408    * 64-bit quantities can be aligned on 32-bit boundaries (as on x86),
409    * this padding will not exist.  (Note that the structure up to this point
410    * contains 1 64-bit member followed by 21 32-bit members.)
411    * As a workaround, reserved0 and reserved1 are instead defined here as
412    * four 32-bit quantities.  This should be harmless, as there are
413    * currently no known uses for these fields. */
414   uint32_t             reserved0[2];
415   uint32_t             reserved1[2];
416 } MDRawModule;  /* MINIDUMP_MODULE */
417 
418 /* The inclusion of a 64-bit type in MINIDUMP_MODULE forces the struct to
419  * be tail-padded out to a multiple of 64 bits under some ABIs (such as PPC).
420  * This doesn't occur on systems that don't tail-pad in this manner.  Define
421  * this macro to be the usable size of the MDRawModule struct, and use it in
422  * place of sizeof(MDRawModule). */
423 #define MD_MODULE_SIZE 108
424 
425 
426 /* (MDRawModule).cv_record can reference MDCVInfoPDB20 or MDCVInfoPDB70.
427  * Ref.: http://www.debuginfo.com/articles/debuginfomatch.html
428  * MDCVInfoPDB70 is the expected structure type with recent toolchains. */
429 
430 typedef struct {
431   uint32_t signature;
432   uint32_t offset;     /* Offset to debug data (expect 0 in minidump) */
433 } MDCVHeader;
434 
435 typedef struct {
436   MDCVHeader cv_header;
437   uint32_t   signature;         /* time_t debug information created */
438   uint32_t   age;               /* revision of PDB file */
439   uint8_t    pdb_file_name[1];  /* Pathname or filename of PDB file */
440 } MDCVInfoPDB20;
441 
442 static const size_t MDCVInfoPDB20_minsize = offsetof(MDCVInfoPDB20,
443                                                      pdb_file_name[0]);
444 
445 #define MD_CVINFOPDB20_SIGNATURE 0x3031424e  /* cvHeader.signature = '01BN' */
446 
447 typedef struct {
448   uint32_t  cv_signature;
449   MDGUID    signature;         /* GUID, identifies PDB file */
450   uint32_t  age;               /* Identifies incremental changes to PDB file */
451   uint8_t   pdb_file_name[1];  /* Pathname or filename of PDB file,
452                                 * 0-terminated 8-bit character data (UTF-8?) */
453 } MDCVInfoPDB70;
454 
455 static const size_t MDCVInfoPDB70_minsize = offsetof(MDCVInfoPDB70,
456                                                      pdb_file_name[0]);
457 
458 #define MD_CVINFOPDB70_SIGNATURE 0x53445352  /* cvSignature = 'SDSR' */
459 
460 /*
461  * Modern ELF toolchains insert a "build id" into the ELF headers that
462  * usually contains a hash of some ELF headers + sections to uniquely
463  * identify a binary.
464  *
465  * https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Developer_Guide/compiling-build-id.html
466  * https://sourceware.org/binutils/docs-2.26/ld/Options.html#index-g_t_002d_002dbuild_002did-292
467  */
468 typedef struct {
469   uint32_t cv_signature;
470   uint8_t  build_id[1];  /* Bytes of build id from GNU_BUILD_ID ELF note.
471                           * This is variable-length, but usually 20 bytes
472                           * as the binutils ld default is a SHA-1 hash. */
473 } MDCVInfoELF;
474 
475 static const size_t MDCVInfoELF_minsize = offsetof(MDCVInfoELF,
476                                                    build_id[0]);
477 
478 #define MD_CVINFOELF_SIGNATURE 0x4270454c  /* cvSignature = 'BpEL' */
479 
480 /* In addition to the two CodeView record formats above, used for linking
481  * to external pdb files, it is possible for debugging data to be carried
482  * directly in the CodeView record itself.  These signature values will
483  * be found in the first 4 bytes of the CodeView record.  Additional values
484  * not commonly experienced in the wild are given by "Microsoft Symbol and
485  * Type Information", http://www.x86.org/ftp/manuals/tools/sym.pdf, section
486  * 7.2.  An in-depth description of the CodeView 4.1 format is given by
487  * "Undocumented Windows 2000 Secrets", Windows 2000 Debugging Support/
488  * Microsoft Symbol File Internals/CodeView Subsections,
489  * http://www.rawol.com/features/undocumented/sbs-w2k-1-windows-2000-debugging-support.pdf
490  */
491 #define MD_CVINFOCV41_SIGNATURE 0x3930424e  /* '90BN', CodeView 4.10. */
492 #define MD_CVINFOCV50_SIGNATURE 0x3131424e  /* '11BN', CodeView 5.0,
493                                              * MS C7-format (/Z7). */
494 
495 #define MD_CVINFOUNKNOWN_SIGNATURE 0xffffffff  /* An unlikely value. */
496 
497 /* (MDRawModule).miscRecord can reference MDImageDebugMisc.  The Windows
498  * structure is actually defined in WinNT.h.  This structure is effectively
499  * obsolete with modules built by recent toolchains. */
500 
501 typedef struct {
502   uint32_t  data_type;    /* IMAGE_DEBUG_TYPE_*, not defined here because
503                            * this debug record type is mostly obsolete. */
504   uint32_t  length;       /* Length of entire MDImageDebugMisc structure */
505   uint8_t   unicode;      /* True if data is multibyte */
506   uint8_t   reserved[3];
507   uint8_t   data[1];
508 } MDImageDebugMisc;  /* IMAGE_DEBUG_MISC */
509 
510 static const size_t MDImageDebugMisc_minsize = offsetof(MDImageDebugMisc,
511                                                         data[0]);
512 
513 
514 typedef struct {
515   uint32_t    number_of_modules;
516   MDRawModule modules[1];
517 } MDRawModuleList;  /* MINIDUMP_MODULE_LIST */
518 
519 static const size_t MDRawModuleList_minsize = offsetof(MDRawModuleList,
520                                                        modules[0]);
521 
522 
523 typedef struct {
524   uint32_t           number_of_memory_ranges;
525   MDMemoryDescriptor memory_ranges[1];
526 } MDRawMemoryList;  /* MINIDUMP_MEMORY_LIST */
527 
528 static const size_t MDRawMemoryList_minsize = offsetof(MDRawMemoryList,
529                                                        memory_ranges[0]);
530 
531 
532 #define MD_EXCEPTION_MAXIMUM_PARAMETERS 15
533 
534 typedef struct {
535   uint32_t  exception_code;     /* Windows: MDExceptionCodeWin,
536                                  * Mac OS X: MDExceptionMac,
537                                  * Linux: MDExceptionCodeLinux. */
538   uint32_t  exception_flags;    /* Windows: 1 if noncontinuable,
539                                    Mac OS X: MDExceptionCodeMac. */
540   uint64_t  exception_record;   /* Address (in the minidump-producing host's
541                                  * memory) of another MDException, for
542                                  * nested exceptions. */
543   uint64_t  exception_address;  /* The address that caused the exception.
544                                  * Mac OS X: exception subcode (which is
545                                  *           typically the address). */
546   uint32_t  number_parameters;  /* Number of valid elements in
547                                  * exception_information. */
548   uint32_t  __align;
549   uint64_t  exception_information[MD_EXCEPTION_MAXIMUM_PARAMETERS];
550 } MDException;  /* MINIDUMP_EXCEPTION */
551 
552 #include "minidump_exception_fuchsia.h"
553 #include "minidump_exception_linux.h"
554 #include "minidump_exception_mac.h"
555 #include "minidump_exception_ps3.h"
556 #include "minidump_exception_solaris.h"
557 #include "minidump_exception_win32.h"
558 
559 typedef struct {
560   uint32_t             thread_id;         /* Thread in which the exception
561                                            * occurred.  Corresponds to
562                                            * (MDRawThread).thread_id. */
563   uint32_t             __align;
564   MDException          exception_record;
565   MDLocationDescriptor thread_context;    /* MDRawContext[CPU] */
566 } MDRawExceptionStream;  /* MINIDUMP_EXCEPTION_STREAM */
567 
568 
569 typedef union {
570   struct {
571     uint32_t vendor_id[3];               /* cpuid 0: ebx, edx, ecx */
572     uint32_t version_information;        /* cpuid 1: eax */
573     uint32_t feature_information;        /* cpuid 1: edx */
574     uint32_t amd_extended_cpu_features;  /* cpuid 0x80000001, ebx */
575   } x86_cpu_info;
576   struct {
577     uint32_t cpuid;
578     uint32_t elf_hwcaps;    /* linux specific, 0 otherwise */
579   } arm_cpu_info;
580   struct {
581     uint64_t processor_features[2];
582   } other_cpu_info;
583 } MDCPUInformation;  /* CPU_INFORMATION */
584 
585 /* For (MDCPUInformation).arm_cpu_info.elf_hwcaps.
586  * This matches the Linux kernel definitions from <asm/hwcaps.h> */
587 typedef enum {
588   MD_CPU_ARM_ELF_HWCAP_SWP       = (1 << 0),
589   MD_CPU_ARM_ELF_HWCAP_HALF      = (1 << 1),
590   MD_CPU_ARM_ELF_HWCAP_THUMB     = (1 << 2),
591   MD_CPU_ARM_ELF_HWCAP_26BIT     = (1 << 3),
592   MD_CPU_ARM_ELF_HWCAP_FAST_MULT = (1 << 4),
593   MD_CPU_ARM_ELF_HWCAP_FPA       = (1 << 5),
594   MD_CPU_ARM_ELF_HWCAP_VFP       = (1 << 6),
595   MD_CPU_ARM_ELF_HWCAP_EDSP      = (1 << 7),
596   MD_CPU_ARM_ELF_HWCAP_JAVA      = (1 << 8),
597   MD_CPU_ARM_ELF_HWCAP_IWMMXT    = (1 << 9),
598   MD_CPU_ARM_ELF_HWCAP_CRUNCH    = (1 << 10),
599   MD_CPU_ARM_ELF_HWCAP_THUMBEE   = (1 << 11),
600   MD_CPU_ARM_ELF_HWCAP_NEON      = (1 << 12),
601   MD_CPU_ARM_ELF_HWCAP_VFPv3     = (1 << 13),
602   MD_CPU_ARM_ELF_HWCAP_VFPv3D16  = (1 << 14),
603   MD_CPU_ARM_ELF_HWCAP_TLS       = (1 << 15),
604   MD_CPU_ARM_ELF_HWCAP_VFPv4     = (1 << 16),
605   MD_CPU_ARM_ELF_HWCAP_IDIVA     = (1 << 17),
606   MD_CPU_ARM_ELF_HWCAP_IDIVT     = (1 << 18),
607 } MDCPUInformationARMElfHwCaps;
608 
609 typedef struct {
610   /* The next 3 fields and numberOfProcessors are from the SYSTEM_INFO
611    * structure as returned by GetSystemInfo */
612   uint16_t         processor_architecture;
613   uint16_t         processor_level;         /* x86: 5 = 586, 6 = 686, ... */
614                                             /* ARM: 6 = ARMv6, 7 = ARMv7 ... */
615   uint16_t         processor_revision;      /* x86: 0xMMSS, where MM=model,
616                                              *      SS=stepping */
617                                             /* ARM: 0 */
618 
619   uint8_t          number_of_processors;
620   uint8_t          product_type;            /* Windows: VER_NT_* from WinNT.h */
621 
622   /* The next 5 fields are from the OSVERSIONINFO structure as returned
623    * by GetVersionEx */
624   uint32_t         major_version;
625   uint32_t         minor_version;
626   uint32_t         build_number;
627   uint32_t         platform_id;
628   MDRVA            csd_version_rva;  /* MDString further identifying the
629                                       * host OS.
630                                       * Windows: name of the installed OS
631                                       *          service pack.
632                                       * Mac OS X: the Apple OS build number
633                                       *           (sw_vers -buildVersion).
634                                       * Linux: uname -srvmo */
635 
636   uint16_t         suite_mask;       /* Windows: VER_SUITE_* from WinNT.h */
637   uint16_t         reserved2;
638 
639   MDCPUInformation cpu;
640 } MDRawSystemInfo;  /* MINIDUMP_SYSTEM_INFO */
641 
642 /* For (MDRawSystemInfo).processor_architecture: */
643 typedef enum {
644   MD_CPU_ARCHITECTURE_X86       =  0,  /* PROCESSOR_ARCHITECTURE_INTEL */
645   MD_CPU_ARCHITECTURE_MIPS      =  1,  /* PROCESSOR_ARCHITECTURE_MIPS */
646   MD_CPU_ARCHITECTURE_ALPHA     =  2,  /* PROCESSOR_ARCHITECTURE_ALPHA */
647   MD_CPU_ARCHITECTURE_PPC       =  3,  /* PROCESSOR_ARCHITECTURE_PPC */
648   MD_CPU_ARCHITECTURE_SHX       =  4,  /* PROCESSOR_ARCHITECTURE_SHX
649                                         * (Super-H) */
650   MD_CPU_ARCHITECTURE_ARM       =  5,  /* PROCESSOR_ARCHITECTURE_ARM */
651   MD_CPU_ARCHITECTURE_IA64      =  6,  /* PROCESSOR_ARCHITECTURE_IA64 */
652   MD_CPU_ARCHITECTURE_ALPHA64   =  7,  /* PROCESSOR_ARCHITECTURE_ALPHA64 */
653   MD_CPU_ARCHITECTURE_MSIL      =  8,  /* PROCESSOR_ARCHITECTURE_MSIL
654                                         * (Microsoft Intermediate Language) */
655   MD_CPU_ARCHITECTURE_AMD64     =  9,  /* PROCESSOR_ARCHITECTURE_AMD64 */
656   MD_CPU_ARCHITECTURE_X86_WIN64 = 10,
657       /* PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 (WoW64) */
658   MD_CPU_ARCHITECTURE_ARM64     = 12,  /* PROCESSOR_ARCHITECTURE_ARM64 */
659   MD_CPU_ARCHITECTURE_SPARC     = 0x8001, /* Breakpad-defined value for SPARC */
660   MD_CPU_ARCHITECTURE_PPC64     = 0x8002, /* Breakpad-defined value for PPC64 */
661   MD_CPU_ARCHITECTURE_ARM64_OLD = 0x8003, /* Breakpad-defined value for ARM64 */
662   MD_CPU_ARCHITECTURE_MIPS64    = 0x8004, /* Breakpad-defined value for MIPS64 */
663   MD_CPU_ARCHITECTURE_UNKNOWN   = 0xffff  /* PROCESSOR_ARCHITECTURE_UNKNOWN */
664 } MDCPUArchitecture;
665 
666 /* For (MDRawSystemInfo).platform_id: */
667 typedef enum {
668   MD_OS_WIN32S        = 0,  /* VER_PLATFORM_WIN32s (Windows 3.1) */
669   MD_OS_WIN32_WINDOWS = 1,  /* VER_PLATFORM_WIN32_WINDOWS (Windows 95-98-Me) */
670   MD_OS_WIN32_NT      = 2,  /* VER_PLATFORM_WIN32_NT (Windows NT, 2000+) */
671   MD_OS_WIN32_CE      = 3,  /* VER_PLATFORM_WIN32_CE, VER_PLATFORM_WIN32_HH
672                              * (Windows CE, Windows Mobile, "Handheld") */
673 
674   /* The following values are Breakpad-defined. */
675   MD_OS_UNIX          = 0x8000,  /* Generic Unix-ish */
676   MD_OS_MAC_OS_X      = 0x8101,  /* Mac OS X/Darwin */
677   MD_OS_IOS           = 0x8102,  /* iOS */
678   MD_OS_LINUX         = 0x8201,  /* Linux */
679   MD_OS_SOLARIS       = 0x8202,  /* Solaris */
680   MD_OS_ANDROID       = 0x8203,  /* Android */
681   MD_OS_PS3           = 0x8204,  /* PS3 */
682   MD_OS_NACL          = 0x8205,  /* Native Client (NaCl) */
683   MD_OS_FUCHSIA       = 0x8206   /* Fuchsia */
684 } MDOSPlatform;
685 
686 typedef struct {
687   uint64_t base_of_image;
688   uint32_t size_of_image;
689   uint32_t checksum;
690   uint32_t time_date_stamp;
691   MDRVA module_name_rva;
692 } MDRawUnloadedModule;
693 
694 typedef struct {
695   uint32_t size_of_header;
696   uint32_t size_of_entry;
697   uint32_t number_of_entries;
698 } MDRawUnloadedModuleList;  /* MINIDUMP_UNLOADED_MODULE_LIST */
699 
700 typedef struct {
701   uint16_t year;
702   uint16_t month;
703   uint16_t day_of_week;
704   uint16_t day;
705   uint16_t hour;
706   uint16_t minute;
707   uint16_t second;
708   uint16_t milliseconds;
709 } MDSystemTime;  /* SYSTEMTIME */
710 
711 typedef struct {
712   /* Required field.  The bias is the difference, in minutes, between
713    * Coordinated Universal Time (UTC) and local time.
714    *   Formula: UTC = local time + bias */
715   int32_t bias;
716   /* A description for standard time.  For example, "EST" could indicate Eastern
717    * Standard Time.  In practice this contains the full time zone names.  This
718    * string can be empty. */
719   uint16_t standard_name[32];  /* UTF-16-encoded, 0-terminated */
720   /* A MDSystemTime structure that contains a date and local time when the
721    * transition from daylight saving time to standard time occurs on this
722    * operating system.  If the time zone does not support daylight saving time,
723    * the month member in the MDSystemTime structure is zero. */
724   MDSystemTime standard_date;
725   /* The bias value to be used during local time translations that occur during
726    * standard time. */
727   int32_t standard_bias;
728   /* A description for daylight saving time.  For example, "PDT" could indicate
729    * Pacific Daylight Time.  In practice this contains the full time zone names.
730    * This string can be empty. */
731   uint16_t daylight_name[32];  /* UTF-16-encoded, 0-terminated */
732   /* A MDSystemTime structure that contains a date and local time when the
733    * transition from standard time to daylight saving time occurs on this
734    * operating system.  If the time zone does not support daylight saving time,
735    * the month member in the MDSystemTime structure is zero.*/
736   MDSystemTime daylight_date;
737   /* The bias value to be used during local time translations that occur during
738    * daylight saving time. */
739   int32_t daylight_bias;
740 } MDTimeZoneInformation;  /* TIME_ZONE_INFORMATION */
741 
742 /* MAX_PATH from windef.h */
743 #define MD_MAX_PATH 260
744 
745 /* For MDXStateConfigFeatureMscInfo.features */
746 typedef struct {
747   uint32_t offset;
748   uint32_t size;
749 } MDXStateFeature;
750 
751 /* For MDXStateConfigFeatureMscInfo.enabled_features from winnt.h */
752 typedef enum {
753   MD_XSTATE_LEGACY_FLOATING_POINT = 0, /* XSTATE_LEGACY_FLOATING_POINT */
754   MD_XSTATE_LEGACY_SSE            = 1, /* XSTATE_LEGACY_SSE */
755   MD_XSTATE_GSSE                  = 2, /* XSTATE_GSSE */
756   MD_XSTATE_AVX                   = MD_XSTATE_GSSE, /* XSTATE_AVX */
757   MD_XSTATE_MPX_BNDREGS           = 3, /* XSTATE_MPX_BNDREGS */
758   MD_XSTATE_MPX_BNDCSR            = 4, /* XSTATE_MPX_BNDCSR */
759   MD_XSTATE_AVX512_KMASK          = 5, /* XSTATE_AVX512_KMASK */
760   MD_XSTATE_AVX512_ZMM_H          = 6, /* XSTATE_AVX512_ZMM_H */
761   MD_XSTATE_AVX512_ZMM            = 7, /* XSTATE_AVX512_ZMM */
762   MD_XSTATE_IPT                   = 8, /* XSTATE_IPT */
763   MD_XSTATE_LWP                   = 62 /* XSTATE_LWP */
764 } MDXStateFeatureFlag;
765 
766 /* MAXIMUM_XSTATE_FEATURES from winnt.h */
767 #define MD_MAXIMUM_XSTATE_FEATURES 64
768 
769 /* For MDRawMiscInfo.xstate_data */
770 typedef struct {
771   uint32_t size_of_info;
772   uint32_t context_size;
773   /* An entry in the features array is valid only if the corresponding bit in
774    * the enabled_features flag is set. */
775   uint64_t enabled_features;
776   MDXStateFeature features[MD_MAXIMUM_XSTATE_FEATURES];
777 } MDXStateConfigFeatureMscInfo;
778 
779 
780 /* The miscellaneous information stream contains a variety
781  * of small pieces of information.  A member is valid if
782  * it's within the available size and its corresponding
783  * bit is set. */
784 typedef struct {
785   uint32_t size_of_info;  /* Length of entire MDRawMiscInfo structure. */
786   uint32_t flags1;
787 
788   /* The next field is only valid if flags1 contains
789    * MD_MISCINFO_FLAGS1_PROCESS_ID. */
790   uint32_t process_id;
791 
792   /* The next 3 fields are only valid if flags1 contains
793    * MD_MISCINFO_FLAGS1_PROCESS_TIMES. */
794   uint32_t process_create_time;  /* time_t process started */
795   uint32_t process_user_time;    /* seconds of user CPU time */
796   uint32_t process_kernel_time;  /* seconds of kernel CPU time */
797 
798   /* The following fields are not present in MINIDUMP_MISC_INFO but are
799    * in MINIDUMP_MISC_INFO_2.  When this struct is populated, these values
800    * may not be set.  Use flags1 and size_of_info to determine whether these
801    * values are present.  These are only valid when flags1 contains
802    * MD_MISCINFO_FLAGS1_PROCESSOR_POWER_INFO. */
803   uint32_t processor_max_mhz;
804   uint32_t processor_current_mhz;
805   uint32_t processor_mhz_limit;
806   uint32_t processor_max_idle_state;
807   uint32_t processor_current_idle_state;
808 
809   /* The following fields are not present in MINIDUMP_MISC_INFO_2 but are
810    * in MINIDUMP_MISC_INFO_3.  When this struct is populated, these values
811    * may not be set.  Use flags1 and size_of_info to determine whether these
812    * values are present. */
813 
814   /* The following field is only valid if flags1 contains
815    * MD_MISCINFO_FLAGS1_PROCESS_INTEGRITY. */
816   uint32_t process_integrity_level;
817 
818   /* The following field is only valid if flags1 contains
819    * MD_MISCINFO_FLAGS1_PROCESS_EXECUTE_FLAGS. */
820   uint32_t process_execute_flags;
821 
822   /* The following field is only valid if flags1 contains
823    * MD_MISCINFO_FLAGS1_PROTECTED_PROCESS. */
824   uint32_t protected_process;
825 
826   /* The following 2 fields are only valid if flags1 contains
827    * MD_MISCINFO_FLAGS1_TIMEZONE. */
828   uint32_t time_zone_id;
829   MDTimeZoneInformation time_zone;
830 
831   /* The following fields are not present in MINIDUMP_MISC_INFO_3 but are
832    * in MINIDUMP_MISC_INFO_4.  When this struct is populated, these values
833    * may not be set.  Use flags1 and size_of_info to determine whether these
834    * values are present. */
835 
836   /* The following 2 fields are only valid if flags1 contains
837    * MD_MISCINFO_FLAGS1_BUILDSTRING. */
838   uint16_t build_string[MD_MAX_PATH];  /* UTF-16-encoded, 0-terminated */
839   uint16_t dbg_bld_str[40];            /* UTF-16-encoded, 0-terminated */
840 
841   /* The following fields are not present in MINIDUMP_MISC_INFO_4 but are
842    * in MINIDUMP_MISC_INFO_5.  When this struct is populated, these values
843    * may not be set.  Use flags1 and size_of_info to determine whether these
844    * values are present. */
845 
846   /* The following field has its own flags for establishing the validity of
847    * the structure's contents.*/
848   MDXStateConfigFeatureMscInfo xstate_data;
849 
850   /* The following field is only valid if flags1 contains
851    * MD_MISCINFO_FLAGS1_PROCESS_COOKIE. */
852   uint32_t process_cookie;
853 } MDRawMiscInfo;  /* MINIDUMP_MISC_INFO, MINIDUMP_MISC_INFO_2,
854                    * MINIDUMP_MISC_INFO_3, MINIDUMP_MISC_INFO_4,
855                    * MINIDUMP_MISC_INFO_5, MINIDUMP_MISC_INFO_N */
856 
857 static const size_t MD_MISCINFO_SIZE =
858     offsetof(MDRawMiscInfo, processor_max_mhz);
859 static const size_t MD_MISCINFO2_SIZE =
860     offsetof(MDRawMiscInfo, process_integrity_level);
861 static const size_t MD_MISCINFO3_SIZE =
862     offsetof(MDRawMiscInfo, build_string[0]);
863 static const size_t MD_MISCINFO4_SIZE =
864     offsetof(MDRawMiscInfo, xstate_data);
865 /* Version 5 of the MDRawMiscInfo structure is not a multiple of 8 in size and
866  * yet it contains some 8-bytes sized fields. This causes many compilers to
867  * round the structure size up to a multiple of 8 by adding padding at the end.
868  * The following hack is thus required for matching the proper on-disk size. */
869 static const size_t MD_MISCINFO5_SIZE =
870     offsetof(MDRawMiscInfo, process_cookie) + sizeof(uint32_t);
871 
872 /* For (MDRawMiscInfo).flags1.  These values indicate which fields in the
873  * MDRawMiscInfoStructure are valid. */
874 typedef enum {
875   MD_MISCINFO_FLAGS1_PROCESS_ID            = 0x00000001,
876       /* MINIDUMP_MISC1_PROCESS_ID */
877   MD_MISCINFO_FLAGS1_PROCESS_TIMES         = 0x00000002,
878       /* MINIDUMP_MISC1_PROCESS_TIMES */
879   MD_MISCINFO_FLAGS1_PROCESSOR_POWER_INFO  = 0x00000004,
880       /* MINIDUMP_MISC1_PROCESSOR_POWER_INFO */
881   MD_MISCINFO_FLAGS1_PROCESS_INTEGRITY     = 0x00000010,
882       /* MINIDUMP_MISC3_PROCESS_INTEGRITY */
883   MD_MISCINFO_FLAGS1_PROCESS_EXECUTE_FLAGS = 0x00000020,
884       /* MINIDUMP_MISC3_PROCESS_EXECUTE_FLAGS */
885   MD_MISCINFO_FLAGS1_TIMEZONE              = 0x00000040,
886       /* MINIDUMP_MISC3_TIMEZONE */
887   MD_MISCINFO_FLAGS1_PROTECTED_PROCESS     = 0x00000080,
888       /* MINIDUMP_MISC3_PROTECTED_PROCESS */
889   MD_MISCINFO_FLAGS1_BUILDSTRING           = 0x00000100,
890       /* MINIDUMP_MISC4_BUILDSTRING */
891   MD_MISCINFO_FLAGS1_PROCESS_COOKIE        = 0x00000200,
892       /* MINIDUMP_MISC5_PROCESS_COOKIE */
893 } MDMiscInfoFlags1;
894 
895 /*
896  * Around DbgHelp version 6.0, the style of new LIST structures changed
897  * from including an array of length 1 at the end of the struct to
898  * represent the variable-length data to including explicit
899  * "size of header", "size of entry" and "number of entries" fields
900  * in the header, presumably to allow backwards-compatibly-extending
901  * the structures in the future. The actual list entries follow the
902  * header data directly in this case.
903  */
904 
905 typedef struct {
906   uint32_t size_of_header;    /* sizeof(MDRawMemoryInfoList) */
907   uint32_t size_of_entry;     /* sizeof(MDRawMemoryInfo) */
908   uint64_t number_of_entries;
909 } MDRawMemoryInfoList;  /* MINIDUMP_MEMORY_INFO_LIST */
910 
911 typedef struct {
912   uint64_t  base_address;           /* Base address of a region of pages */
913   uint64_t  allocation_base;        /* Base address of a range of pages
914                                      * within this region. */
915   uint32_t  allocation_protection;  /* Memory protection when this region
916                                      * was originally allocated:
917                                      * MDMemoryProtection */
918   uint32_t  __alignment1;
919   uint64_t  region_size;
920   uint32_t  state;                  /* MDMemoryState */
921   uint32_t  protection;             /* MDMemoryProtection */
922   uint32_t  type;                   /* MDMemoryType */
923   uint32_t  __alignment2;
924 } MDRawMemoryInfo;  /* MINIDUMP_MEMORY_INFO */
925 
926 /* For (MDRawMemoryInfo).state */
927 typedef enum {
928   MD_MEMORY_STATE_COMMIT   = 0x1000,  /* physical storage has been allocated */
929   MD_MEMORY_STATE_RESERVE  = 0x2000,  /* reserved, but no physical storage */
930   MD_MEMORY_STATE_FREE     = 0x10000  /* available to be allocated */
931 } MDMemoryState;
932 
933 /* For (MDRawMemoryInfo).allocation_protection and .protection */
934 typedef enum {
935   MD_MEMORY_PROTECT_NOACCESS          = 0x01,  /* PAGE_NOACCESS */
936   MD_MEMORY_PROTECT_READONLY          = 0x02,  /* PAGE_READONLY */
937   MD_MEMORY_PROTECT_READWRITE         = 0x04,  /* PAGE_READWRITE */
938   MD_MEMORY_PROTECT_WRITECOPY         = 0x08,  /* PAGE_WRITECOPY */
939   MD_MEMORY_PROTECT_EXECUTE           = 0x10,  /* PAGE_EXECUTE */
940   MD_MEMORY_PROTECT_EXECUTE_READ      = 0x20,  /* PAGE_EXECUTE_READ */
941   MD_MEMORY_PROTECT_EXECUTE_READWRITE = 0x40,  /* PAGE_EXECUTE_READWRITE */
942   MD_MEMORY_PROTECT_EXECUTE_WRITECOPY = 0x80,  /* PAGE_EXECUTE_WRITECOPY */
943   /* These options can be combined with the previous flags. */
944   MD_MEMORY_PROTECT_GUARD             = 0x100,  /* PAGE_GUARD */
945   MD_MEMORY_PROTECT_NOCACHE           = 0x200,  /* PAGE_NOCACHE */
946   MD_MEMORY_PROTECT_WRITECOMBINE      = 0x400,  /* PAGE_WRITECOMBINE */
947 } MDMemoryProtection;
948 
949 /* Used to mask the mutually exclusive options from the combinable flags. */
950 const uint32_t MD_MEMORY_PROTECTION_ACCESS_MASK = 0xFF;
951 
952 /* For (MDRawMemoryInfo).type */
953 typedef enum {
954   MD_MEMORY_TYPE_PRIVATE = 0x20000,   /* not shared by other processes */
955   MD_MEMORY_TYPE_MAPPED  = 0x40000,   /* mapped into the view of a section */
956   MD_MEMORY_TYPE_IMAGE   = 0x1000000  /* mapped into the view of an image */
957 } MDMemoryType;
958 
959 /*
960  * Breakpad extension types
961  */
962 
963 
964 typedef struct {
965   /* validity is a bitmask with values from MDBreakpadInfoValidity, indicating
966    * which of the other fields in the structure are valid. */
967   uint32_t validity;
968 
969   /* Thread ID of the handler thread.  dump_thread_id should correspond to
970    * the thread_id of an MDRawThread in the minidump's MDRawThreadList if
971    * a dedicated thread in that list was used to produce the minidump.  If
972    * the MDRawThreadList does not contain a dedicated thread used to produce
973    * the minidump, this field should be set to 0 and the validity field
974    * must not contain MD_BREAKPAD_INFO_VALID_DUMP_THREAD_ID. */
975   uint32_t dump_thread_id;
976 
977   /* Thread ID of the thread that requested the minidump be produced.  As
978    * with dump_thread_id, requesting_thread_id should correspond to the
979    * thread_id of an MDRawThread in the minidump's MDRawThreadList.  For
980    * minidumps produced as a result of an exception, requesting_thread_id
981    * will be the same as the MDRawExceptionStream's thread_id field.  For
982    * minidumps produced "manually" at the program's request,
983    * requesting_thread_id will indicate which thread caused the dump to be
984    * written.  If the minidump was produced at the request of something
985    * other than a thread in the MDRawThreadList, this field should be set
986    * to 0 and the validity field must not contain
987    * MD_BREAKPAD_INFO_VALID_REQUESTING_THREAD_ID. */
988   uint32_t requesting_thread_id;
989 } MDRawBreakpadInfo;
990 
991 /* For (MDRawBreakpadInfo).validity: */
992 typedef enum {
993   /* When set, the dump_thread_id field is valid. */
994   MD_BREAKPAD_INFO_VALID_DUMP_THREAD_ID       = 1 << 0,
995 
996   /* When set, the requesting_thread_id field is valid. */
997   MD_BREAKPAD_INFO_VALID_REQUESTING_THREAD_ID = 1 << 1
998 } MDBreakpadInfoValidity;
999 
1000 typedef struct {
1001   /* expression, function, and file are 0-terminated UTF-16 strings.  They
1002    * may be truncated if necessary, but should always be 0-terminated when
1003    * written to a file.
1004    * Fixed-length strings are used because MiniDumpWriteDump doesn't offer
1005    * a way for user streams to point to arbitrary RVAs for strings. */
1006   uint16_t expression[128];  /* Assertion that failed... */
1007   uint16_t function[128];    /* ...within this function... */
1008   uint16_t file[128];        /* ...in this file... */
1009   uint32_t line;             /* ...at this line. */
1010   uint32_t type;
1011 } MDRawAssertionInfo;
1012 
1013 /* For (MDRawAssertionInfo).type: */
1014 typedef enum {
1015   MD_ASSERTION_INFO_TYPE_UNKNOWN = 0,
1016 
1017   /* Used for assertions that would be raised by the MSVC CRT but are
1018    * directed to an invalid parameter handler instead. */
1019   MD_ASSERTION_INFO_TYPE_INVALID_PARAMETER,
1020 
1021   /* Used for assertions that would be raised by the MSVC CRT but are
1022    * directed to a pure virtual call handler instead. */
1023   MD_ASSERTION_INFO_TYPE_PURE_VIRTUAL_CALL
1024 } MDAssertionInfoData;
1025 
1026 /* These structs are used to store the DSO debug data in Linux minidumps,
1027  * which is necessary for converting minidumps to usable coredumps.
1028  * Because of a historical accident, several fields are variably encoded
1029  * according to client word size, so tools potentially need to support both. */
1030 
1031 typedef struct {
1032   uint32_t  addr;
1033   MDRVA     name;
1034   uint32_t  ld;
1035 } MDRawLinkMap32;
1036 
1037 typedef struct {
1038   uint32_t  version;
1039   MDRVA     map;  /* array of MDRawLinkMap32 */
1040   uint32_t  dso_count;
1041   uint32_t  brk;
1042   uint32_t  ldbase;
1043   uint32_t  dynamic;
1044 } MDRawDebug32;
1045 
1046 typedef struct {
1047   uint64_t  addr;
1048   MDRVA     name;
1049   uint64_t  ld;
1050 } MDRawLinkMap64;
1051 
1052 typedef struct {
1053   uint32_t  version;
1054   MDRVA     map;  /* array of MDRawLinkMap64 */
1055   uint32_t  dso_count;
1056   uint64_t  brk;
1057   uint64_t  ldbase;
1058   uint64_t  dynamic;
1059 } MDRawDebug64;
1060 
1061 /* Crashpad extension types. See Crashpad's minidump/minidump_extensions.h. */
1062 
1063 typedef struct {
1064   MDRVA key;
1065   MDRVA value;
1066 } MDRawSimpleStringDictionaryEntry;
1067 
1068 typedef struct {
1069   uint32_t count;
1070   MDRawSimpleStringDictionaryEntry entries[0];
1071 } MDRawSimpleStringDictionary;
1072 
1073 typedef struct {
1074   uint32_t version;
1075   MDLocationDescriptor list_annotations;
1076   MDLocationDescriptor simple_annotations;  /* MDRawSimpleStringDictionary */
1077 } MDRawModuleCrashpadInfo;
1078 
1079 typedef struct {
1080   uint32_t minidump_module_list_index;
1081   MDLocationDescriptor location;  /* MDRawModuleCrashpadInfo */
1082 } MDRawModuleCrashpadInfoLink;
1083 
1084 typedef struct {
1085   uint32_t count;
1086   MDLocationDescriptor modules[0];  /* MDRawModuleCrashpadInfoLink */
1087 } MDRawModuleCrashpadInfoList;
1088 
1089 typedef struct {
1090   uint32_t version;
1091   MDGUID report_id;
1092   MDGUID client_id;
1093   MDLocationDescriptor simple_annotations;  /* MDRawSimpleStringDictionary */
1094   MDLocationDescriptor module_list;  /* MDRawModuleCrashpadInfoList */
1095 } MDRawCrashpadInfo;
1096 
1097 #if defined(_MSC_VER)
1098 #pragma warning(pop)
1099 #endif  /* _MSC_VER */
1100 
1101 
1102 #endif  /* GOOGLE_BREAKPAD_COMMON_MINIDUMP_FORMAT_H__ */
1103