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