Planeshift
minidump_format.h
Go to the documentation of this file.
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 
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_MIPS 0x00010000 /* CONTEXT_R4000 (same value as x86?) */
101 #define MD_CONTEXT_ALPHA 0x00020000 /* CONTEXT_ALPHA */
102 
103 /* As of Windows 7 SP1, the number of flag bits has increased to
104  * include 0x40 (CONTEXT_XSTATE):
105  * http://msdn.microsoft.com/en-us/library/hh134238%28v=vs.85%29.aspx */
106 #define MD_CONTEXT_CPU_MASK 0xffffff00
107 
108 
109 /* This is a base type for MDRawContextX86 and MDRawContextPPC. This
110  * structure should never be allocated directly. The actual structure type
111  * can be determined by examining the context_flags field. */
112 typedef struct {
113  uint32_t context_flags;
115 
116 #include "minidump_cpu_amd64.h"
117 #include "minidump_cpu_arm.h"
118 #include "minidump_cpu_ppc.h"
119 #include "minidump_cpu_ppc64.h"
120 #include "minidump_cpu_sparc.h"
121 #include "minidump_cpu_x86.h"
122 
123 /*
124  * WinVer.h
125  */
126 
127 
128 typedef struct {
129  uint32_t signature;
130  uint32_t struct_version;
131  uint32_t file_version_hi;
132  uint32_t file_version_lo;
135  uint32_t file_flags_mask; /* Identifies valid bits in fileFlags */
136  uint32_t file_flags;
137  uint32_t file_os;
138  uint32_t file_type;
139  uint32_t file_subtype;
140  uint32_t file_date_hi;
141  uint32_t file_date_lo;
142 } MDVSFixedFileInfo; /* VS_FIXEDFILEINFO */
143 
144 /* For (MDVSFixedFileInfo).signature */
145 #define MD_VSFIXEDFILEINFO_SIGNATURE 0xfeef04bd
146  /* VS_FFI_SIGNATURE */
147 
148 /* For (MDVSFixedFileInfo).version */
149 #define MD_VSFIXEDFILEINFO_VERSION 0x00010000
150  /* VS_FFI_STRUCVERSION */
151 
152 /* For (MDVSFixedFileInfo).file_flags_mask and
153  * (MDVSFixedFileInfo).file_flags */
154 #define MD_VSFIXEDFILEINFO_FILE_FLAGS_DEBUG 0x00000001
155  /* VS_FF_DEBUG */
156 #define MD_VSFIXEDFILEINFO_FILE_FLAGS_PRERELEASE 0x00000002
157  /* VS_FF_PRERELEASE */
158 #define MD_VSFIXEDFILEINFO_FILE_FLAGS_PATCHED 0x00000004
159  /* VS_FF_PATCHED */
160 #define MD_VSFIXEDFILEINFO_FILE_FLAGS_PRIVATEBUILD 0x00000008
161  /* VS_FF_PRIVATEBUILD */
162 #define MD_VSFIXEDFILEINFO_FILE_FLAGS_INFOINFERRED 0x00000010
163  /* VS_FF_INFOINFERRED */
164 #define MD_VSFIXEDFILEINFO_FILE_FLAGS_SPECIALBUILD 0x00000020
165  /* VS_FF_SPECIALBUILD */
166 
167 /* For (MDVSFixedFileInfo).file_os: high 16 bits */
168 #define MD_VSFIXEDFILEINFO_FILE_OS_UNKNOWN 0 /* VOS_UNKNOWN */
169 #define MD_VSFIXEDFILEINFO_FILE_OS_DOS (1 << 16) /* VOS_DOS */
170 #define MD_VSFIXEDFILEINFO_FILE_OS_OS216 (2 << 16) /* VOS_OS216 */
171 #define MD_VSFIXEDFILEINFO_FILE_OS_OS232 (3 << 16) /* VOS_OS232 */
172 #define MD_VSFIXEDFILEINFO_FILE_OS_NT (4 << 16) /* VOS_NT */
173 #define MD_VSFIXEDFILEINFO_FILE_OS_WINCE (5 << 16) /* VOS_WINCE */
174 /* Low 16 bits */
175 #define MD_VSFIXEDFILEINFO_FILE_OS__BASE 0 /* VOS__BASE */
176 #define MD_VSFIXEDFILEINFO_FILE_OS__WINDOWS16 1 /* VOS__WINDOWS16 */
177 #define MD_VSFIXEDFILEINFO_FILE_OS__PM16 2 /* VOS__PM16 */
178 #define MD_VSFIXEDFILEINFO_FILE_OS__PM32 3 /* VOS__PM32 */
179 #define MD_VSFIXEDFILEINFO_FILE_OS__WINDOWS32 4 /* VOS__WINDOWS32 */
180 
181 /* For (MDVSFixedFileInfo).file_type */
182 #define MD_VSFIXEDFILEINFO_FILE_TYPE_UNKNOWN 0 /* VFT_UNKNOWN */
183 #define MD_VSFIXEDFILEINFO_FILE_TYPE_APP 1 /* VFT_APP */
184 #define MD_VSFIXEDFILEINFO_FILE_TYPE_DLL 2 /* VFT_DLL */
185 #define MD_VSFIXEDFILEINFO_FILE_TYPE_DRV 3 /* VFT_DLL */
186 #define MD_VSFIXEDFILEINFO_FILE_TYPE_FONT 4 /* VFT_FONT */
187 #define MD_VSFIXEDFILEINFO_FILE_TYPE_VXD 5 /* VFT_VXD */
188 #define MD_VSFIXEDFILEINFO_FILE_TYPE_STATIC_LIB 7 /* VFT_STATIC_LIB */
189 
190 /* For (MDVSFixedFileInfo).file_subtype */
191 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_UNKNOWN 0
192  /* VFT2_UNKNOWN */
193 /* with file_type = MD_VSFIXEDFILEINFO_FILETYPE_DRV */
194 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_PRINTER 1
195  /* VFT2_DRV_PRINTER */
196 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_KEYBOARD 2
197  /* VFT2_DRV_KEYBOARD */
198 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_LANGUAGE 3
199  /* VFT2_DRV_LANGUAGE */
200 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_DISPLAY 4
201  /* VFT2_DRV_DISPLAY */
202 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_MOUSE 5
203  /* VFT2_DRV_MOUSE */
204 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_NETWORK 6
205  /* VFT2_DRV_NETWORK */
206 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_SYSTEM 7
207  /* VFT2_DRV_SYSTEM */
208 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_INSTALLABLE 8
209  /* VFT2_DRV_INSTALLABLE */
210 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_SOUND 9
211  /* VFT2_DRV_SOUND */
212 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_COMM 10
213  /* VFT2_DRV_COMM */
214 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_INPUTMETHOD 11
215  /* VFT2_DRV_INPUTMETHOD */
216 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_DRV_VERSIONED_PRINTER 12
217  /* VFT2_DRV_VERSIONED_PRINTER */
218 /* with file_type = MD_VSFIXEDFILEINFO_FILETYPE_FONT */
219 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_FONT_RASTER 1
220  /* VFT2_FONT_RASTER */
221 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_FONT_VECTOR 2
222  /* VFT2_FONT_VECTOR */
223 #define MD_VSFIXEDFILEINFO_FILE_SUBTYPE_FONT_TRUETYPE 3
224  /* VFT2_FONT_TRUETYPE */
225 
226 
227 /*
228  * DbgHelp.h
229  */
230 
231 
232 /* An MDRVA is an offset into the minidump file. The beginning of the
233  * MDRawHeader is at offset 0. */
234 typedef uint32_t MDRVA; /* RVA */
235 
236 typedef struct {
237  uint32_t data_size;
239 } MDLocationDescriptor; /* MINIDUMP_LOCATION_DESCRIPTOR */
240 
241 
242 typedef struct {
243  /* The base address of the memory range on the host that produced the
244  * minidump. */
246 
248 } MDMemoryDescriptor; /* MINIDUMP_MEMORY_DESCRIPTOR */
249 
250 
251 typedef struct {
252  uint32_t signature;
253  uint32_t version;
254  uint32_t stream_count;
255  MDRVA stream_directory_rva; /* A |stream_count|-sized array of
256  * MDRawDirectory structures. */
257  uint32_t checksum; /* Can be 0. In fact, that's all that's
258  * been found in minidump files. */
259  uint32_t time_date_stamp; /* time_t */
260  uint64_t flags;
261 } MDRawHeader; /* MINIDUMP_HEADER */
262 
263 /* For (MDRawHeader).signature and (MDRawHeader).version. Note that only the
264  * low 16 bits of (MDRawHeader).version are MD_HEADER_VERSION. Per the
265  * documentation, the high 16 bits are implementation-specific. */
266 #define MD_HEADER_SIGNATURE 0x504d444d /* 'PMDM' */
267  /* MINIDUMP_SIGNATURE */
268 #define MD_HEADER_VERSION 0x0000a793 /* 42899 */
269  /* MINIDUMP_VERSION */
270 
271 /* For (MDRawHeader).flags: */
272 typedef enum {
273  /* MD_NORMAL is the standard type of minidump. It includes full
274  * streams for the thread list, module list, exception, system info,
275  * and miscellaneous info. A memory list stream is also present,
276  * pointing to the same stack memory contained in the thread list,
277  * as well as a 256-byte region around the instruction address that
278  * was executing when the exception occurred. Stack memory is from
279  * 4 bytes below a thread's stack pointer up to the top of the
280  * memory region encompassing the stack. */
281  MD_NORMAL = 0x00000000,
282  MD_WITH_DATA_SEGS = 0x00000001,
283  MD_WITH_FULL_MEMORY = 0x00000002,
284  MD_WITH_HANDLE_DATA = 0x00000004,
285  MD_FILTER_MEMORY = 0x00000008,
286  MD_SCAN_MEMORY = 0x00000010,
294  MD_WITH_THREAD_INFO = 0x00001000,
295  MD_WITH_CODE_SEGS = 0x00002000,
301 } MDType; /* MINIDUMP_TYPE */
302 
303 
304 typedef struct {
305  uint32_t stream_type;
307 } MDRawDirectory; /* MINIDUMP_DIRECTORY */
308 
309 /* For (MDRawDirectory).stream_type */
310 typedef enum {
314  MD_THREAD_LIST_STREAM = 3, /* MDRawThreadList */
315  MD_MODULE_LIST_STREAM = 4, /* MDRawModuleList */
316  MD_MEMORY_LIST_STREAM = 5, /* MDRawMemoryList */
317  MD_EXCEPTION_STREAM = 6, /* MDRawExceptionStream */
318  MD_SYSTEM_INFO_STREAM = 7, /* MDRawSystemInfo */
326  MD_MISC_INFO_STREAM = 15, /* MDRawMiscInfo */
327  MD_MEMORY_INFO_LIST_STREAM = 16, /* MDRawMemoryInfoList */
331 
332  /* Breakpad extension types. 0x4767 = "Gg" */
333  MD_BREAKPAD_INFO_STREAM = 0x47670001, /* MDRawBreakpadInfo */
334  MD_ASSERTION_INFO_STREAM = 0x47670002, /* MDRawAssertionInfo */
335  /* These are additional minidump stream values which are specific to
336  * the linux breakpad implementation. */
337  MD_LINUX_CPU_INFO = 0x47670003, /* /proc/cpuinfo */
338  MD_LINUX_PROC_STATUS = 0x47670004, /* /proc/$x/status */
339  MD_LINUX_LSB_RELEASE = 0x47670005, /* /etc/lsb-release */
340  MD_LINUX_CMD_LINE = 0x47670006, /* /proc/$x/cmdline */
341  MD_LINUX_ENVIRON = 0x47670007, /* /proc/$x/environ */
342  MD_LINUX_AUXV = 0x47670008, /* /proc/$x/auxv */
343  MD_LINUX_MAPS = 0x47670009, /* /proc/$x/maps */
344  MD_LINUX_DSO_DEBUG = 0x4767000A /* MDRawDebug */
345 } MDStreamType; /* MINIDUMP_STREAM_TYPE */
346 
347 
348 typedef struct {
349  uint32_t length; /* Length of buffer in bytes (not characters),
350  * excluding 0-terminator */
351  uint16_t buffer[1]; /* UTF-16-encoded, 0-terminated */
352 } MDString; /* MINIDUMP_STRING */
353 
354 static const size_t MDString_minsize = offsetof(MDString, buffer[0]);
355 
356 
357 typedef struct {
358  uint32_t thread_id;
359  uint32_t suspend_count;
360  uint32_t priority_class;
361  uint32_t priority;
362  uint64_t teb; /* Thread environment block */
364  MDLocationDescriptor thread_context; /* MDRawContext[CPU] */
365 } MDRawThread; /* MINIDUMP_THREAD */
366 
367 
368 typedef struct {
370  MDRawThread threads[1];
371 } MDRawThreadList; /* MINIDUMP_THREAD_LIST */
372 
373 static const size_t MDRawThreadList_minsize = offsetof(MDRawThreadList,
374  threads[0]);
375 
376 
377 typedef struct {
378  uint64_t base_of_image;
379  uint32_t size_of_image;
380  uint32_t checksum; /* 0 if unknown */
381  uint32_t time_date_stamp; /* time_t */
382  MDRVA module_name_rva; /* MDString, pathname or filename */
384 
385  /* The next field stores a CodeView record and is populated when a module's
386  * debug information resides in a PDB file. It identifies the PDB file. */
388 
389  /* The next field is populated when a module's debug information resides
390  * in a DBG file. It identifies the DBG file. This field is effectively
391  * obsolete with modules built by recent toolchains. */
393 
394  /* Alignment problem: reserved0 and reserved1 are defined by the platform
395  * SDK as 64-bit quantities. However, that results in a structure whose
396  * alignment is unpredictable on different CPUs and ABIs. If the ABI
397  * specifies full alignment of 64-bit quantities in structures (as ppc
398  * does), there will be padding between miscRecord and reserved0. If
399  * 64-bit quantities can be aligned on 32-bit boundaries (as on x86),
400  * this padding will not exist. (Note that the structure up to this point
401  * contains 1 64-bit member followed by 21 32-bit members.)
402  * As a workaround, reserved0 and reserved1 are instead defined here as
403  * four 32-bit quantities. This should be harmless, as there are
404  * currently no known uses for these fields. */
405  uint32_t reserved0[2];
406  uint32_t reserved1[2];
407 } MDRawModule; /* MINIDUMP_MODULE */
408 
409 /* The inclusion of a 64-bit type in MINIDUMP_MODULE forces the struct to
410  * be tail-padded out to a multiple of 64 bits under some ABIs (such as PPC).
411  * This doesn't occur on systems that don't tail-pad in this manner. Define
412  * this macro to be the usable size of the MDRawModule struct, and use it in
413  * place of sizeof(MDRawModule). */
414 #define MD_MODULE_SIZE 108
415 
416 
417 /* (MDRawModule).cv_record can reference MDCVInfoPDB20 or MDCVInfoPDB70.
418  * Ref.: http://www.debuginfo.com/articles/debuginfomatch.html
419  * MDCVInfoPDB70 is the expected structure type with recent toolchains. */
420 
421 typedef struct {
422  uint32_t signature;
423  uint32_t offset; /* Offset to debug data (expect 0 in minidump) */
424 } MDCVHeader;
425 
426 typedef struct {
428  uint32_t signature; /* time_t debug information created */
429  uint32_t age; /* revision of PDB file */
430  uint8_t pdb_file_name[1]; /* Pathname or filename of PDB file */
431 } MDCVInfoPDB20;
432 
433 static const size_t MDCVInfoPDB20_minsize = offsetof(MDCVInfoPDB20,
434  pdb_file_name[0]);
435 
436 #define MD_CVINFOPDB20_SIGNATURE 0x3031424e /* cvHeader.signature = '01BN' */
437 
438 typedef struct {
439  uint32_t cv_signature;
440  MDGUID signature; /* GUID, identifies PDB file */
441  uint32_t age; /* Identifies incremental changes to PDB file */
442  uint8_t pdb_file_name[1]; /* Pathname or filename of PDB file,
443  * 0-terminated 8-bit character data (UTF-8?) */
444 } MDCVInfoPDB70;
445 
446 static const size_t MDCVInfoPDB70_minsize = offsetof(MDCVInfoPDB70,
447  pdb_file_name[0]);
448 
449 #define MD_CVINFOPDB70_SIGNATURE 0x53445352 /* cvSignature = 'SDSR' */
450 
451 typedef struct {
452  uint32_t data1[2];
453  uint32_t data2;
454  uint32_t data3;
455  uint32_t data4;
456  uint32_t data5[3];
457  uint8_t extra[2];
458 } MDCVInfoELF;
459 
460 /* In addition to the two CodeView record formats above, used for linking
461  * to external pdb files, it is possible for debugging data to be carried
462  * directly in the CodeView record itself. These signature values will
463  * be found in the first 4 bytes of the CodeView record. Additional values
464  * not commonly experienced in the wild are given by "Microsoft Symbol and
465  * Type Information", http://www.x86.org/ftp/manuals/tools/sym.pdf, section
466  * 7.2. An in-depth description of the CodeView 4.1 format is given by
467  * "Undocumented Windows 2000 Secrets", Windows 2000 Debugging Support/
468  * Microsoft Symbol File Internals/CodeView Subsections,
469  * http://www.rawol.com/features/undocumented/sbs-w2k-1-windows-2000-debugging-support.pdf
470  */
471 #define MD_CVINFOCV41_SIGNATURE 0x3930424e /* '90BN', CodeView 4.10. */
472 #define MD_CVINFOCV50_SIGNATURE 0x3131424e /* '11BN', CodeView 5.0,
473  * MS C7-format (/Z7). */
474 
475 #define MD_CVINFOUNKNOWN_SIGNATURE 0xffffffff /* An unlikely value. */
476 
477 /* (MDRawModule).miscRecord can reference MDImageDebugMisc. The Windows
478  * structure is actually defined in WinNT.h. This structure is effectively
479  * obsolete with modules built by recent toolchains. */
480 
481 typedef struct {
482  uint32_t data_type; /* IMAGE_DEBUG_TYPE_*, not defined here because
483  * this debug record type is mostly obsolete. */
484  uint32_t length; /* Length of entire MDImageDebugMisc structure */
485  uint8_t unicode; /* True if data is multibyte */
486  uint8_t reserved[3];
487  uint8_t data[1];
488 } MDImageDebugMisc; /* IMAGE_DEBUG_MISC */
489 
490 static const size_t MDImageDebugMisc_minsize = offsetof(MDImageDebugMisc,
491  data[0]);
492 
493 
494 typedef struct {
496  MDRawModule modules[1];
497 } MDRawModuleList; /* MINIDUMP_MODULE_LIST */
498 
499 static const size_t MDRawModuleList_minsize = offsetof(MDRawModuleList,
500  modules[0]);
501 
502 
503 typedef struct {
505  MDMemoryDescriptor memory_ranges[1];
506 } MDRawMemoryList; /* MINIDUMP_MEMORY_LIST */
507 
508 static const size_t MDRawMemoryList_minsize = offsetof(MDRawMemoryList,
509  memory_ranges[0]);
510 
511 
512 #define MD_EXCEPTION_MAXIMUM_PARAMETERS 15
513 
514 typedef struct {
515  uint32_t exception_code; /* Windows: MDExceptionCodeWin,
516  * Mac OS X: MDExceptionMac,
517  * Linux: MDExceptionCodeLinux. */
518  uint32_t exception_flags; /* Windows: 1 if noncontinuable,
519  Mac OS X: MDExceptionCodeMac. */
520  uint64_t exception_record; /* Address (in the minidump-producing host's
521  * memory) of another MDException, for
522  * nested exceptions. */
523  uint64_t exception_address; /* The address that caused the exception.
524  * Mac OS X: exception subcode (which is
525  * typically the address). */
526  uint32_t number_parameters; /* Number of valid elements in
527  * exception_information. */
528  uint32_t __align;
529  uint64_t exception_information[MD_EXCEPTION_MAXIMUM_PARAMETERS];
530 } MDException; /* MINIDUMP_EXCEPTION */
531 
533 #include "minidump_exception_mac.h"
534 #include "minidump_exception_ps3.h"
537 
538 typedef struct {
539  uint32_t thread_id; /* Thread in which the exception
540  * occurred. Corresponds to
541  * (MDRawThread).thread_id. */
542  uint32_t __align;
544  MDLocationDescriptor thread_context; /* MDRawContext[CPU] */
545 } MDRawExceptionStream; /* MINIDUMP_EXCEPTION_STREAM */
546 
547 
548 typedef union {
549  struct {
550  uint32_t vendor_id[3]; /* cpuid 0: ebx, edx, ecx */
551  uint32_t version_information; /* cpuid 1: eax */
552  uint32_t feature_information; /* cpuid 1: edx */
553  uint32_t amd_extended_cpu_features; /* cpuid 0x80000001, ebx */
554  } x86_cpu_info;
555  struct {
556  uint32_t cpuid;
557  uint32_t elf_hwcaps; /* linux specific, 0 otherwise */
558  } arm_cpu_info;
559  struct {
560  uint64_t processor_features[2];
561  } other_cpu_info;
562 } MDCPUInformation; /* CPU_INFORMATION */
563 
564 /* For (MDCPUInformation).arm_cpu_info.elf_hwcaps.
565  * This matches the Linux kernel definitions from <asm/hwcaps.h> */
566 typedef enum {
587 
588 typedef struct {
589  /* The next 3 fields and numberOfProcessors are from the SYSTEM_INFO
590  * structure as returned by GetSystemInfo */
592  uint16_t processor_level; /* x86: 5 = 586, 6 = 686, ... */
593  /* ARM: 6 = ARMv6, 7 = ARMv7 ... */
594  uint16_t processor_revision; /* x86: 0xMMSS, where MM=model,
595  * SS=stepping */
596  /* ARM: 0 */
597 
599  uint8_t product_type; /* Windows: VER_NT_* from WinNT.h */
600 
601  /* The next 5 fields are from the OSVERSIONINFO structure as returned
602  * by GetVersionEx */
603  uint32_t major_version;
604  uint32_t minor_version;
605  uint32_t build_number;
606  uint32_t platform_id;
607  MDRVA csd_version_rva; /* MDString further identifying the
608  * host OS.
609  * Windows: name of the installed OS
610  * service pack.
611  * Mac OS X: the Apple OS build number
612  * (sw_vers -buildVersion).
613  * Linux: uname -srvmo */
614 
615  uint16_t suite_mask; /* Windows: VER_SUITE_* from WinNT.h */
616  uint16_t reserved2;
617 
619 } MDRawSystemInfo; /* MINIDUMP_SYSTEM_INFO */
620 
621 /* For (MDRawSystemInfo).processor_architecture: */
622 typedef enum {
623  MD_CPU_ARCHITECTURE_X86 = 0, /* PROCESSOR_ARCHITECTURE_INTEL */
624  MD_CPU_ARCHITECTURE_MIPS = 1, /* PROCESSOR_ARCHITECTURE_MIPS */
625  MD_CPU_ARCHITECTURE_ALPHA = 2, /* PROCESSOR_ARCHITECTURE_ALPHA */
626  MD_CPU_ARCHITECTURE_PPC = 3, /* PROCESSOR_ARCHITECTURE_PPC */
627  MD_CPU_ARCHITECTURE_SHX = 4, /* PROCESSOR_ARCHITECTURE_SHX
628  * (Super-H) */
629  MD_CPU_ARCHITECTURE_ARM = 5, /* PROCESSOR_ARCHITECTURE_ARM */
630  MD_CPU_ARCHITECTURE_IA64 = 6, /* PROCESSOR_ARCHITECTURE_IA64 */
631  MD_CPU_ARCHITECTURE_ALPHA64 = 7, /* PROCESSOR_ARCHITECTURE_ALPHA64 */
632  MD_CPU_ARCHITECTURE_MSIL = 8, /* PROCESSOR_ARCHITECTURE_MSIL
633  * (Microsoft Intermediate Language) */
634  MD_CPU_ARCHITECTURE_AMD64 = 9, /* PROCESSOR_ARCHITECTURE_AMD64 */
636  /* PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 (WoW64) */
637  MD_CPU_ARCHITECTURE_SPARC = 0x8001, /* Breakpad-defined value for SPARC */
638  MD_CPU_ARCHITECTURE_PPC64 = 0x8002, /* Breakpad-defined value for PPC64 */
639  MD_CPU_ARCHITECTURE_UNKNOWN = 0xffff /* PROCESSOR_ARCHITECTURE_UNKNOWN */
641 
642 /* For (MDRawSystemInfo).platform_id: */
643 typedef enum {
644  MD_OS_WIN32S = 0, /* VER_PLATFORM_WIN32s (Windows 3.1) */
645  MD_OS_WIN32_WINDOWS = 1, /* VER_PLATFORM_WIN32_WINDOWS (Windows 95-98-Me) */
646  MD_OS_WIN32_NT = 2, /* VER_PLATFORM_WIN32_NT (Windows NT, 2000+) */
647  MD_OS_WIN32_CE = 3, /* VER_PLATFORM_WIN32_CE, VER_PLATFORM_WIN32_HH
648  * (Windows CE, Windows Mobile, "Handheld") */
649 
650  /* The following values are Breakpad-defined. */
651  MD_OS_UNIX = 0x8000, /* Generic Unix-ish */
652  MD_OS_MAC_OS_X = 0x8101, /* Mac OS X/Darwin */
653  MD_OS_IOS = 0x8102, /* iOS */
654  MD_OS_LINUX = 0x8201, /* Linux */
655  MD_OS_SOLARIS = 0x8202, /* Solaris */
656  MD_OS_ANDROID = 0x8203, /* Android */
657  MD_OS_PS3 = 0x8204, /* PS3 */
658  MD_OS_NACL = 0x8205 /* Native Client (NaCl) */
659 } MDOSPlatform;
660 
661 typedef struct {
662  uint16_t year;
663  uint16_t month;
664  uint16_t day_of_week;
665  uint16_t day;
666  uint16_t hour;
667  uint16_t minute;
668  uint16_t second;
669  uint16_t milliseconds;
670 } MDSystemTime; /* SYSTEMTIME */
671 
672 typedef struct {
673  /* Required field. The bias is the difference, in minutes, between
674  * Coordinated Universal Time (UTC) and local time.
675  * Formula: UTC = local time + bias */
676  int32_t bias;
677  /* A description for standard time. For example, "EST" could indicate Eastern
678  * Standard Time. In practice this contains the full time zone names. This
679  * string can be empty. */
680  uint16_t standard_name[32]; /* UTF-16-encoded, 0-terminated */
681  /* A MDSystemTime structure that contains a date and local time when the
682  * transition from daylight saving time to standard time occurs on this
683  * operating system. If the time zone does not support daylight saving time,
684  * the month member in the MDSystemTime structure is zero. */
686  /* The bias value to be used during local time translations that occur during
687  * standard time. */
688  int32_t standard_bias;
689  /* A description for daylight saving time. For example, "PDT" could indicate
690  * Pacific Daylight Time. In practice this contains the full time zone names.
691  * This string can be empty. */
692  uint16_t daylight_name[32]; /* UTF-16-encoded, 0-terminated */
693  /* A MDSystemTime structure that contains a date and local time when the
694  * transition from standard time to daylight saving time occurs on this
695  * operating system. If the time zone does not support daylight saving time,
696  * the month member in the MDSystemTime structure is zero.*/
698  /* The bias value to be used during local time translations that occur during
699  * daylight saving time. */
700  int32_t daylight_bias;
701 } MDTimeZoneInformation; /* TIME_ZONE_INFORMATION */
702 
703 /* MAX_PATH from windef.h */
704 #define MD_MAX_PATH 260
705 
706 /* The miscellaneous information stream contains a variety
707  * of small pieces of information. A member is valid if
708  * it's within the available size and its corresponding
709  * bit is set. */
710 typedef struct {
711  uint32_t size_of_info; /* Length of entire MDRawMiscInfo structure. */
712  uint32_t flags1;
713 
714  /* The next field is only valid if flags1 contains
715  * MD_MISCINFO_FLAGS1_PROCESS_ID. */
716  uint32_t process_id;
717 
718  /* The next 3 fields are only valid if flags1 contains
719  * MD_MISCINFO_FLAGS1_PROCESS_TIMES. */
720  uint32_t process_create_time; /* time_t process started */
721  uint32_t process_user_time; /* seconds of user CPU time */
722  uint32_t process_kernel_time; /* seconds of kernel CPU time */
723 
724  /* The following fields are not present in MINIDUMP_MISC_INFO but are
725  * in MINIDUMP_MISC_INFO_2. When this struct is populated, these value
726  * may not be set. Use flags1 or size_of_info to determine whether these
727  * values are present. These are only valid when flags1 contains
728  * MD_MISCINFO_FLAGS1_PROCESSOR_POWER_INFO. */
734 
735  /* The following fields are not present in MINIDUMP_MISC_INFO_2 but are
736  * in MINIDUMP_MISC_INFO_3. When this struct is populated, these value
737  * may not be set. Use flags1 or size_of_info to determine whether these
738  * values are present. */
739 
740  /* The following field is only valid if flags1 contains
741  * MD_MISCINFO_FLAGS1_PROCESS_INTEGRITY. */
743 
744  /* The following field is only valid if flags1 contains
745  * MD_MISCINFO_FLAGS1_PROCESS_EXECUTE_FLAGS. */
747 
748  /* The following field is only valid if flags1 contains
749  * MD_MISCINFO_FLAGS1_PROTECTED_PROCESS. */
751 
752  /* The following 2 fields are only valid if flags1 contains
753  * MD_MISCINFO_FLAGS1_TIMEZONE. */
754  uint32_t time_zone_id;
756 
757  /* The following fields are not present in MINIDUMP_MISC_INFO_3 but are
758  * in MINIDUMP_MISC_INFO_4. When this struct is populated, these value
759  * may not be set. Use size_of_info to determine whether these values are
760  * present. */
761 
762  /* The following 2 fields are only valid if
763  * size_of_info is >= MD_MISCINFO4_SIZE */
764  uint16_t build_string[MD_MAX_PATH]; /* UTF-16-encoded, 0-terminated */
765  uint16_t dbg_bld_str[40]; /* UTF-16-encoded, 0-terminated */
766 } MDRawMiscInfo; /* MINIDUMP_MISC_INFO, MINIDUMP_MISC_INFO2,
767  * MINIDUMP_MISC_INFO3, MINIDUMP_MISC_INFO4 */
768 
769 static const size_t MD_MISCINFO_SIZE =
770  offsetof(MDRawMiscInfo, processor_max_mhz);
771 static const size_t MD_MISCINFO2_SIZE =
772  offsetof(MDRawMiscInfo, process_integrity_level);
773 static const size_t MD_MISCINFO3_SIZE =
774  offsetof(MDRawMiscInfo, build_string[0]);
775 static const size_t MD_MISCINFO4_SIZE = sizeof(MDRawMiscInfo);
776 
777 /* For (MDRawMiscInfo).flags1. These values indicate which fields in the
778  * MDRawMiscInfoStructure are valid. */
779 typedef enum {
781  /* MINIDUMP_MISC1_PROCESS_ID */
783  /* MINIDUMP_MISC1_PROCESS_TIMES */
785  /* MINIDUMP_MISC1_PROCESSOR_POWER_INFO */
787  /* MINIDUMP_MISC3_PROCESS_INTEGRITY */
789  /* MINIDUMP_MISC3_PROCESS_EXECUTE_FLAGS */
791  /* MINIDUMP_MISC3_TIMEZONE */
793  /* MINIDUMP_MISC3_PROTECTED_PROCESS */
795 
796 /*
797  * Around DbgHelp version 6.0, the style of new LIST structures changed
798  * from including an array of length 1 at the end of the struct to
799  * represent the variable-length data to including explicit
800  * "size of header", "size of entry" and "number of entries" fields
801  * in the header, presumably to allow backwards-compatibly-extending
802  * the structures in the future. The actual list entries follow the
803  * header data directly in this case.
804  */
805 
806 typedef struct {
807  uint32_t size_of_header; /* sizeof(MDRawMemoryInfoList) */
808  uint32_t size_of_entry; /* sizeof(MDRawMemoryInfo) */
810 } MDRawMemoryInfoList; /* MINIDUMP_MEMORY_INFO_LIST */
811 
812 typedef struct {
813  uint64_t base_address; /* Base address of a region of pages */
814  uint64_t allocation_base; /* Base address of a range of pages
815  * within this region. */
816  uint32_t allocation_protection; /* Memory protection when this region
817  * was originally allocated:
818  * MDMemoryProtection */
819  uint32_t __alignment1;
820  uint64_t region_size;
821  uint32_t state; /* MDMemoryState */
822  uint32_t protection; /* MDMemoryProtection */
823  uint32_t type; /* MDMemoryType */
824  uint32_t __alignment2;
825 } MDRawMemoryInfo; /* MINIDUMP_MEMORY_INFO */
826 
827 /* For (MDRawMemoryInfo).state */
828 typedef enum {
829  MD_MEMORY_STATE_COMMIT = 0x1000, /* physical storage has been allocated */
830  MD_MEMORY_STATE_RESERVE = 0x2000, /* reserved, but no physical storage */
831  MD_MEMORY_STATE_FREE = 0x10000 /* available to be allocated */
832 } MDMemoryState;
833 
834 /* For (MDRawMemoryInfo).allocation_protection and .protection */
835 typedef enum {
836  MD_MEMORY_PROTECT_NOACCESS = 0x01, /* PAGE_NOACCESS */
837  MD_MEMORY_PROTECT_READONLY = 0x02, /* PAGE_READONLY */
838  MD_MEMORY_PROTECT_READWRITE = 0x04, /* PAGE_READWRITE */
839  MD_MEMORY_PROTECT_WRITECOPY = 0x08, /* PAGE_WRITECOPY */
840  MD_MEMORY_PROTECT_EXECUTE = 0x10, /* PAGE_EXECUTE */
841  MD_MEMORY_PROTECT_EXECUTE_READ = 0x20, /* PAGE_EXECUTE_READ */
842  MD_MEMORY_PROTECT_EXECUTE_READWRITE = 0x40, /* PAGE_EXECUTE_READWRITE */
843  MD_MEMORY_PROTECT_EXECUTE_WRITECOPY = 0x80, /* PAGE_EXECUTE_WRITECOPY */
844  /* These options can be combined with the previous flags. */
845  MD_MEMORY_PROTECT_GUARD = 0x100, /* PAGE_GUARD */
846  MD_MEMORY_PROTECT_NOCACHE = 0x200, /* PAGE_NOCACHE */
847  MD_MEMORY_PROTECT_WRITECOMBINE = 0x400, /* PAGE_WRITECOMBINE */
849 
850 /* Used to mask the mutually exclusive options from the combinable flags. */
851 const uint32_t MD_MEMORY_PROTECTION_ACCESS_MASK = 0xFF;
852 
853 /* For (MDRawMemoryInfo).type */
854 typedef enum {
855  MD_MEMORY_TYPE_PRIVATE = 0x20000, /* not shared by other processes */
856  MD_MEMORY_TYPE_MAPPED = 0x40000, /* mapped into the view of a section */
857  MD_MEMORY_TYPE_IMAGE = 0x1000000 /* mapped into the view of an image */
858 } MDMemoryType;
859 
860 /*
861  * Breakpad extension types
862  */
863 
864 
865 typedef struct {
866  /* validity is a bitmask with values from MDBreakpadInfoValidity, indicating
867  * which of the other fields in the structure are valid. */
868  uint32_t validity;
869 
870  /* Thread ID of the handler thread. dump_thread_id should correspond to
871  * the thread_id of an MDRawThread in the minidump's MDRawThreadList if
872  * a dedicated thread in that list was used to produce the minidump. If
873  * the MDRawThreadList does not contain a dedicated thread used to produce
874  * the minidump, this field should be set to 0 and the validity field
875  * must not contain MD_BREAKPAD_INFO_VALID_DUMP_THREAD_ID. */
876  uint32_t dump_thread_id;
877 
878  /* Thread ID of the thread that requested the minidump be produced. As
879  * with dump_thread_id, requesting_thread_id should correspond to the
880  * thread_id of an MDRawThread in the minidump's MDRawThreadList. For
881  * minidumps produced as a result of an exception, requesting_thread_id
882  * will be the same as the MDRawExceptionStream's thread_id field. For
883  * minidumps produced "manually" at the program's request,
884  * requesting_thread_id will indicate which thread caused the dump to be
885  * written. If the minidump was produced at the request of something
886  * other than a thread in the MDRawThreadList, this field should be set
887  * to 0 and the validity field must not contain
888  * MD_BREAKPAD_INFO_VALID_REQUESTING_THREAD_ID. */
891 
892 /* For (MDRawBreakpadInfo).validity: */
893 typedef enum {
894  /* When set, the dump_thread_id field is valid. */
896 
897  /* When set, the requesting_thread_id field is valid. */
900 
901 typedef struct {
902  /* expression, function, and file are 0-terminated UTF-16 strings. They
903  * may be truncated if necessary, but should always be 0-terminated when
904  * written to a file.
905  * Fixed-length strings are used because MiniDumpWriteDump doesn't offer
906  * a way for user streams to point to arbitrary RVAs for strings. */
907  uint16_t expression[128]; /* Assertion that failed... */
908  uint16_t function[128]; /* ...within this function... */
909  uint16_t file[128]; /* ...in this file... */
910  uint32_t line; /* ...at this line. */
911  uint32_t type;
913 
914 /* For (MDRawAssertionInfo).type: */
915 typedef enum {
917 
918  /* Used for assertions that would be raised by the MSVC CRT but are
919  * directed to an invalid parameter handler instead. */
921 
922  /* Used for assertions that would be raised by the MSVC CRT but are
923  * directed to a pure virtual call handler instead. */
926 
927 /* These structs are used to store the DSO debug data in Linux minidumps,
928  * which is necessary for converting minidumps to usable coredumps. */
929 typedef struct {
930  void* addr;
932  void* ld;
933 } MDRawLinkMap;
934 
935 typedef struct {
936  uint32_t version;
938  uint32_t dso_count;
939  void* brk;
940  void* ldbase;
941  void* dynamic;
942 } MDRawDebug;
943 
944 #if defined(_MSC_VER)
945 #pragma warning(pop)
946 #endif /* _MSC_VER */
947 
948 
949 #endif /* GOOGLE_BREAKPAD_COMMON_MINIDUMP_FORMAT_H__ */
MDLocationDescriptor misc_record
MDLocationDescriptor thread_context
#define MD_MAX_PATH
uint8_t number_of_processors
uint32_t process_kernel_time
MDTimeZoneInformation time_zone
MDLocationDescriptor memory
MDCPUArchitecture
uint32_t exception_flags
uint32_t process_create_time
uint32_t data2
uint32_t minor_version
uint32_t priority
MDMemoryType
MDLocationDescriptor location
uint32_t exception_code
uint32_t checksum
uint32_t number_of_modules
MDSystemTime daylight_date
MDCPUInformation cpu
uint32_t requesting_thread_id
uint32_t signature
MDStreamType
uint32_t process_execute_flags
uint32_t feature_information
uint16_t data3
uint32_t version_information
uint32_t product_version_lo
uint64_t flags
uint32_t processor_current_idle_state
MDLocationDescriptor cv_record
uint32_t time_date_stamp
uint64_t base_of_image
uint32_t number_parameters
uint32_t size_of_info
MDCPUInformationARMElfHwCaps
uint32_t __align
static const size_t MDString_minsize
uint64_t exception_address
#define MD_EXCEPTION_MAXIMUM_PARAMETERS
static const size_t MD_MISCINFO_SIZE
uint32_t time_zone_id
uint32_t cv_signature
uint32_t product_version_hi
uint32_t number_of_threads
uint32_t number_of_memory_ranges
static const size_t MDRawThreadList_minsize
MDVSFixedFileInfo version_info
uint64_t allocation_base
MDSystemTime standard_date
uint16_t processor_revision
MDRVA module_name_rva
uint32_t thread_id
MDMiscInfoFlags1
uint32_t size_of_image
MDLocationDescriptor thread_context
static const size_t MD_MISCINFO4_SIZE
uint32_t MDRVA
static const size_t MDCVInfoPDB20_minsize
uint16_t processor_architecture
MDBreakpadInfoValidity
MDMemoryState
uint32_t signature
MDMemoryDescriptor stack
uint32_t major_version
uint32_t signature
static const size_t MD_MISCINFO2_SIZE
uint32_t stream_type
uint32_t data4
uint32_t time_date_stamp
uint32_t dso_count
uint32_t length
static const size_t MDRawMemoryList_minsize
uint32_t amd_extended_cpu_features
uint32_t checksum
uint32_t version
uint32_t process_id
uint32_t version
uint16_t day_of_week
uint32_t offset
uint32_t data1
uint64_t exception_record
uint32_t suspend_count
uint32_t processor_max_mhz
uint32_t protected_process
uint32_t processor_max_idle_state
uint32_t processor_current_mhz
uint32_t priority_class
uint16_t milliseconds
static const size_t MD_MISCINFO3_SIZE
uint32_t process_integrity_level
uint32_t processor_mhz_limit
static const size_t MDImageDebugMisc_minsize
const uint32_t MD_MEMORY_PROTECTION_ACCESS_MASK
static const size_t MDRawModuleList_minsize
MDAssertionInfoData
MDCVHeader cv_header
uint16_t processor_level
uint32_t stream_count
uint32_t data3
MDMemoryProtection
MDType
static const size_t MDCVInfoPDB70_minsize
MDException exception_record
MDOSPlatform
uint16_t data2
MDRVA stream_directory_rva
uint32_t process_user_time
uint64_t start_of_memory_range
uint32_t allocation_protection