PageRenderTime 76ms CodeModel.GetById 16ms app.highlight 52ms RepoModel.GetById 1ms app.codeStats 0ms

/thirdparty/breakpad/google_breakpad/common/minidump_format.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 794 lines | 399 code | 121 blank | 274 comment | 0 complexity | 567f323ffd137a096a04c1cd74cec5d2 MD5 | raw 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
 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
 81typedef struct {
 82  u_int32_t data1;
 83  u_int16_t data2;
 84  u_int16_t data3;
 85  u_int8_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. */
112typedef struct {
113  u_int32_t context_flags;
114} MDRawContextBase;
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
128typedef struct {
129  u_int32_t signature;
130  u_int32_t struct_version;
131  u_int32_t file_version_hi;
132  u_int32_t file_version_lo;
133  u_int32_t product_version_hi;
134  u_int32_t product_version_lo;
135  u_int32_t file_flags_mask;    /* Identifies valid bits in fileFlags */
136  u_int32_t file_flags;
137  u_int32_t file_os;
138  u_int32_t file_type;
139  u_int32_t file_subtype;
140  u_int32_t file_date_hi;
141  u_int32_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. */
234typedef u_int32_t MDRVA;  /* RVA */
235
236typedef struct {
237  u_int32_t data_size;
238  MDRVA     rva;
239} MDLocationDescriptor;  /* MINIDUMP_LOCATION_DESCRIPTOR */
240
241
242typedef struct {
243  /* The base address of the memory range on the host that produced the
244   * minidump. */
245  u_int64_t            start_of_memory_range;
246
247  MDLocationDescriptor memory;
248} MDMemoryDescriptor;  /* MINIDUMP_MEMORY_DESCRIPTOR */
249
250
251typedef struct {
252  u_int32_t signature;
253  u_int32_t version;
254  u_int32_t stream_count;
255  MDRVA     stream_directory_rva;  /* A |stream_count|-sized array of
256                                    * MDRawDirectory structures. */
257  u_int32_t checksum;              /* Can be 0.  In fact, that's all that's
258                                    * been found in minidump files. */
259  u_int32_t time_date_stamp;       /* time_t */
260  u_int64_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: */
272typedef 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,
287  MD_WITH_UNLOADED_MODULES             = 0x00000020,
288  MD_WITH_INDIRECTLY_REFERENCED_MEMORY = 0x00000040,
289  MD_FILTER_MODULE_PATHS               = 0x00000080,
290  MD_WITH_PROCESS_THREAD_DATA          = 0x00000100,
291  MD_WITH_PRIVATE_READ_WRITE_MEMORY    = 0x00000200,
292  MD_WITHOUT_OPTIONAL_DATA             = 0x00000400,
293  MD_WITH_FULL_MEMORY_INFO             = 0x00000800,
294  MD_WITH_THREAD_INFO                  = 0x00001000,
295  MD_WITH_CODE_SEGS                    = 0x00002000,
296  MD_WITHOUT_AUXILLIARY_SEGS           = 0x00004000,
297  MD_WITH_FULL_AUXILLIARY_STATE        = 0x00008000,
298  MD_WITH_PRIVATE_WRITE_COPY_MEMORY    = 0x00010000,
299  MD_IGNORE_INACCESSIBLE_MEMORY        = 0x00020000,
300  MD_WITH_TOKEN_INFORMATION            = 0x00040000
301} MDType;  /* MINIDUMP_TYPE */
302
303
304typedef struct {
305  u_int32_t            stream_type;
306  MDLocationDescriptor location;
307} MDRawDirectory;  /* MINIDUMP_DIRECTORY */
308
309/* For (MDRawDirectory).stream_type */
310typedef enum {
311  MD_UNUSED_STREAM               =  0,
312  MD_RESERVED_STREAM_0           =  1,
313  MD_RESERVED_STREAM_1           =  2,
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 */
319  MD_THREAD_EX_LIST_STREAM       =  8,
320  MD_MEMORY_64_LIST_STREAM       =  9,
321  MD_COMMENT_STREAM_A            = 10,
322  MD_COMMENT_STREAM_W            = 11,
323  MD_HANDLE_DATA_STREAM          = 12,
324  MD_FUNCTION_TABLE_STREAM       = 13,
325  MD_UNLOADED_MODULE_LIST_STREAM = 14,
326  MD_MISC_INFO_STREAM            = 15,  /* MDRawMiscInfo */
327  MD_MEMORY_INFO_LIST_STREAM     = 16,  /* MDRawMemoryInfoList */
328  MD_THREAD_INFO_LIST_STREAM     = 17,
329  MD_HANDLE_OPERATION_LIST_STREAM = 18,
330  MD_LAST_RESERVED_STREAM        = 0x0000ffff,
331
332  /* Breakpad extension types.  0x4767 = "Gg" */
333  MD_BREAKPAD_INFO_STREAM        = 0x47670001,  /* MDRawBreakpadInfo */
334  MD_ASSERTION_INFO_STREAM       = 0x47670002   /* MDRawAssertionInfo */
335} MDStreamType;  /* MINIDUMP_STREAM_TYPE */
336
337
338typedef struct {
339  u_int32_t length;     /* Length of buffer in bytes (not characters),
340                         * excluding 0-terminator */
341  u_int16_t buffer[1];  /* UTF-16-encoded, 0-terminated */
342} MDString;  /* MINIDUMP_STRING */
343
344static const size_t MDString_minsize = offsetof(MDString, buffer[0]);
345
346
347typedef struct {
348  u_int32_t            thread_id;
349  u_int32_t            suspend_count;
350  u_int32_t            priority_class;
351  u_int32_t            priority;
352  u_int64_t            teb;             /* Thread environment block */
353  MDMemoryDescriptor   stack;
354  MDLocationDescriptor thread_context;  /* MDRawContext[CPU] */
355} MDRawThread;  /* MINIDUMP_THREAD */
356
357
358typedef struct {
359  u_int32_t   number_of_threads;
360  MDRawThread threads[1];
361} MDRawThreadList;  /* MINIDUMP_THREAD_LIST */
362
363static const size_t MDRawThreadList_minsize = offsetof(MDRawThreadList,
364                                                       threads[0]);
365
366
367typedef struct {
368  u_int64_t            base_of_image;
369  u_int32_t            size_of_image;
370  u_int32_t            checksum;         /* 0 if unknown */
371  u_int32_t            time_date_stamp;  /* time_t */
372  MDRVA                module_name_rva;  /* MDString, pathname or filename */
373  MDVSFixedFileInfo    version_info;
374
375  /* The next field stores a CodeView record and is populated when a module's
376   * debug information resides in a PDB file.  It identifies the PDB file. */
377  MDLocationDescriptor cv_record;
378
379  /* The next field is populated when a module's debug information resides
380   * in a DBG file.  It identifies the DBG file.  This field is effectively
381   * obsolete with modules built by recent toolchains. */
382  MDLocationDescriptor misc_record;
383
384  /* Alignment problem: reserved0 and reserved1 are defined by the platform
385   * SDK as 64-bit quantities.  However, that results in a structure whose
386   * alignment is unpredictable on different CPUs and ABIs.  If the ABI
387   * specifies full alignment of 64-bit quantities in structures (as ppc
388   * does), there will be padding between miscRecord and reserved0.  If
389   * 64-bit quantities can be aligned on 32-bit boundaries (as on x86),
390   * this padding will not exist.  (Note that the structure up to this point
391   * contains 1 64-bit member followed by 21 32-bit members.)
392   * As a workaround, reserved0 and reserved1 are instead defined here as
393   * four 32-bit quantities.  This should be harmless, as there are
394   * currently no known uses for these fields. */
395  u_int32_t            reserved0[2];
396  u_int32_t            reserved1[2];
397} MDRawModule;  /* MINIDUMP_MODULE */
398
399/* The inclusion of a 64-bit type in MINIDUMP_MODULE forces the struct to
400 * be tail-padded out to a multiple of 64 bits under some ABIs (such as PPC).
401 * This doesn't occur on systems that don't tail-pad in this manner.  Define
402 * this macro to be the usable size of the MDRawModule struct, and use it in
403 * place of sizeof(MDRawModule). */
404#define MD_MODULE_SIZE 108
405
406
407/* (MDRawModule).cv_record can reference MDCVInfoPDB20 or MDCVInfoPDB70.
408 * Ref.: http://www.debuginfo.com/articles/debuginfomatch.html
409 * MDCVInfoPDB70 is the expected structure type with recent toolchains. */
410
411typedef struct {
412  u_int32_t signature;
413  u_int32_t offset;     /* Offset to debug data (expect 0 in minidump) */
414} MDCVHeader;
415
416typedef struct {
417  MDCVHeader cv_header;
418  u_int32_t  signature;         /* time_t debug information created */
419  u_int32_t  age;               /* revision of PDB file */
420  u_int8_t   pdb_file_name[1];  /* Pathname or filename of PDB file */
421} MDCVInfoPDB20;
422
423static const size_t MDCVInfoPDB20_minsize = offsetof(MDCVInfoPDB20,
424                                                     pdb_file_name[0]);
425
426#define MD_CVINFOPDB20_SIGNATURE 0x3031424e  /* cvHeader.signature = '01BN' */
427
428typedef struct {
429  u_int32_t cv_signature;
430  MDGUID    signature;         /* GUID, identifies PDB file */
431  u_int32_t age;               /* Identifies incremental changes to PDB file */
432  u_int8_t  pdb_file_name[1];  /* Pathname or filename of PDB file,
433                                * 0-terminated 8-bit character data (UTF-8?) */
434} MDCVInfoPDB70;
435
436static const size_t MDCVInfoPDB70_minsize = offsetof(MDCVInfoPDB70,
437                                                     pdb_file_name[0]);
438
439#define MD_CVINFOPDB70_SIGNATURE 0x53445352  /* cvSignature = 'SDSR' */
440
441typedef struct {
442  u_int32_t data1[2];
443  u_int32_t data2;
444  u_int32_t data3;
445  u_int32_t data4;
446  u_int32_t data5[3];
447  u_int8_t extra[2];
448} MDCVInfoELF;
449
450/* In addition to the two CodeView record formats above, used for linking
451 * to external pdb files, it is possible for debugging data to be carried
452 * directly in the CodeView record itself.  These signature values will
453 * be found in the first 4 bytes of the CodeView record.  Additional values
454 * not commonly experienced in the wild are given by "Microsoft Symbol and
455 * Type Information", http://www.x86.org/ftp/manuals/tools/sym.pdf, section
456 * 7.2.  An in-depth description of the CodeView 4.1 format is given by
457 * "Undocumented Windows 2000 Secrets", Windows 2000 Debugging Support/
458 * Microsoft Symbol File Internals/CodeView Subsections,
459 * http://www.rawol.com/features/undocumented/sbs-w2k-1-windows-2000-debugging-support.pdf
460 */
461#define MD_CVINFOCV41_SIGNATURE 0x3930424e  /* '90BN', CodeView 4.10. */
462#define MD_CVINFOCV50_SIGNATURE 0x3131424e  /* '11BN', CodeView 5.0,
463                                             * MS C7-format (/Z7). */
464
465#define MD_CVINFOUNKNOWN_SIGNATURE 0xffffffff  /* An unlikely value. */
466
467/* (MDRawModule).miscRecord can reference MDImageDebugMisc.  The Windows
468 * structure is actually defined in WinNT.h.  This structure is effectively
469 * obsolete with modules built by recent toolchains. */
470
471typedef struct {
472  u_int32_t data_type;    /* IMAGE_DEBUG_TYPE_*, not defined here because
473                           * this debug record type is mostly obsolete. */
474  u_int32_t length;       /* Length of entire MDImageDebugMisc structure */
475  u_int8_t  unicode;      /* True if data is multibyte */
476  u_int8_t  reserved[3];
477  u_int8_t  data[1];
478} MDImageDebugMisc;  /* IMAGE_DEBUG_MISC */
479
480static const size_t MDImageDebugMisc_minsize = offsetof(MDImageDebugMisc,
481                                                        data[0]);
482
483
484typedef struct {
485  u_int32_t   number_of_modules;
486  MDRawModule modules[1];
487} MDRawModuleList;  /* MINIDUMP_MODULE_LIST */
488
489static const size_t MDRawModuleList_minsize = offsetof(MDRawModuleList,
490                                                       modules[0]);
491
492
493typedef struct {
494  u_int32_t          number_of_memory_ranges;
495  MDMemoryDescriptor memory_ranges[1];
496} MDRawMemoryList;  /* MINIDUMP_MEMORY_LIST */
497
498static const size_t MDRawMemoryList_minsize = offsetof(MDRawMemoryList,
499                                                       memory_ranges[0]);
500
501
502#define MD_EXCEPTION_MAXIMUM_PARAMETERS 15
503
504typedef struct {
505  u_int32_t exception_code;     /* Windows: MDExceptionCodeWin,
506                                 * Mac OS X: MDExceptionMac,
507                                 * Linux: MDExceptionCodeLinux. */
508  u_int32_t exception_flags;    /* Windows: 1 if noncontinuable,
509                                   Mac OS X: MDExceptionCodeMac. */
510  u_int64_t exception_record;   /* Address (in the minidump-producing host's
511                                 * memory) of another MDException, for
512                                 * nested exceptions. */
513  u_int64_t exception_address;  /* The address that caused the exception.
514                                 * Mac OS X: exception subcode (which is
515                                 *           typically the address). */
516  u_int32_t number_parameters;  /* Number of valid elements in
517                                 * exception_information. */
518  u_int32_t __align;
519  u_int64_t exception_information[MD_EXCEPTION_MAXIMUM_PARAMETERS];
520} MDException;  /* MINIDUMP_EXCEPTION */
521
522#include "minidump_exception_win32.h"
523#include "minidump_exception_mac.h"
524#include "minidump_exception_linux.h"
525#include "minidump_exception_solaris.h"
526
527typedef struct {
528  u_int32_t            thread_id;         /* Thread in which the exception
529                                           * occurred.  Corresponds to
530                                           * (MDRawThread).thread_id. */
531  u_int32_t            __align;
532  MDException          exception_record;
533  MDLocationDescriptor thread_context;    /* MDRawContext[CPU] */
534} MDRawExceptionStream;  /* MINIDUMP_EXCEPTION_STREAM */
535
536
537typedef union {
538  struct {
539    u_int32_t vendor_id[3];               /* cpuid 0: ebx, edx, ecx */
540    u_int32_t version_information;        /* cpuid 1: eax */
541    u_int32_t feature_information;        /* cpuid 1: edx */
542    u_int32_t amd_extended_cpu_features;  /* cpuid 0x80000001, ebx */
543  } x86_cpu_info;
544  struct {
545    u_int64_t processor_features[2];
546  } other_cpu_info;
547} MDCPUInformation;  /* CPU_INFORMATION */
548
549
550typedef struct {
551  /* The next 3 fields and numberOfProcessors are from the SYSTEM_INFO
552   * structure as returned by GetSystemInfo */
553  u_int16_t        processor_architecture;
554  u_int16_t        processor_level;         /* x86: 5 = 586, 6 = 686, ... */
555  u_int16_t        processor_revision;      /* x86: 0xMMSS, where MM=model,
556                                             *      SS=stepping */
557
558  u_int8_t         number_of_processors;
559  u_int8_t         product_type;            /* Windows: VER_NT_* from WinNT.h */
560
561  /* The next 5 fields are from the OSVERSIONINFO structure as returned
562   * by GetVersionEx */
563  u_int32_t        major_version;
564  u_int32_t        minor_version;
565  u_int32_t        build_number;
566  u_int32_t        platform_id;
567  MDRVA            csd_version_rva;  /* MDString further identifying the
568                                      * host OS.
569                                      * Windows: name of the installed OS
570                                      *          service pack.
571                                      * Mac OS X: the Apple OS build number
572                                      *           (sw_vers -buildVersion).
573                                      * Linux: uname -srvmo */
574
575  u_int16_t        suite_mask;       /* Windows: VER_SUITE_* from WinNT.h */
576  u_int16_t        reserved2;
577
578  MDCPUInformation cpu;
579} MDRawSystemInfo;  /* MINIDUMP_SYSTEM_INFO */
580
581/* For (MDRawSystemInfo).processor_architecture: */
582typedef enum {
583  MD_CPU_ARCHITECTURE_X86       =  0,  /* PROCESSOR_ARCHITECTURE_INTEL */
584  MD_CPU_ARCHITECTURE_MIPS      =  1,  /* PROCESSOR_ARCHITECTURE_MIPS */
585  MD_CPU_ARCHITECTURE_ALPHA     =  2,  /* PROCESSOR_ARCHITECTURE_ALPHA */
586  MD_CPU_ARCHITECTURE_PPC       =  3,  /* PROCESSOR_ARCHITECTURE_PPC */
587  MD_CPU_ARCHITECTURE_SHX       =  4,  /* PROCESSOR_ARCHITECTURE_SHX
588                                        * (Super-H) */
589  MD_CPU_ARCHITECTURE_ARM       =  5,  /* PROCESSOR_ARCHITECTURE_ARM */
590  MD_CPU_ARCHITECTURE_IA64      =  6,  /* PROCESSOR_ARCHITECTURE_IA64 */
591  MD_CPU_ARCHITECTURE_ALPHA64   =  7,  /* PROCESSOR_ARCHITECTURE_ALPHA64 */
592  MD_CPU_ARCHITECTURE_MSIL      =  8,  /* PROCESSOR_ARCHITECTURE_MSIL
593                                        * (Microsoft Intermediate Language) */
594  MD_CPU_ARCHITECTURE_AMD64     =  9,  /* PROCESSOR_ARCHITECTURE_AMD64 */
595  MD_CPU_ARCHITECTURE_X86_WIN64 = 10,
596      /* PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 (WoW64) */
597  MD_CPU_ARCHITECTURE_SPARC     = 0x8001, /* Breakpad-defined value for SPARC */
598  MD_CPU_ARCHITECTURE_UNKNOWN   = 0xffff  /* PROCESSOR_ARCHITECTURE_UNKNOWN */
599} MDCPUArchitecture;
600
601/* For (MDRawSystemInfo).platform_id: */
602typedef enum {
603  MD_OS_WIN32S        = 0,  /* VER_PLATFORM_WIN32s (Windows 3.1) */
604  MD_OS_WIN32_WINDOWS = 1,  /* VER_PLATFORM_WIN32_WINDOWS (Windows 95-98-Me) */
605  MD_OS_WIN32_NT      = 2,  /* VER_PLATFORM_WIN32_NT (Windows NT, 2000+) */
606  MD_OS_WIN32_CE      = 3,  /* VER_PLATFORM_WIN32_CE, VER_PLATFORM_WIN32_HH
607                             * (Windows CE, Windows Mobile, "Handheld") */
608
609  /* The following values are Breakpad-defined. */
610  MD_OS_UNIX          = 0x8000,  /* Generic Unix-ish */
611  MD_OS_MAC_OS_X      = 0x8101,  /* Mac OS X/Darwin */
612  MD_OS_IOS           = 0x8102,  /* iOS */
613  MD_OS_LINUX         = 0x8201,  /* Linux */
614  MD_OS_SOLARIS       = 0x8202   /* Solaris */
615} MDOSPlatform;
616
617
618typedef struct {
619  u_int32_t size_of_info;  /* Length of entire MDRawMiscInfo structure. */
620  u_int32_t flags1;
621
622  /* The next field is only valid if flags1 contains
623   * MD_MISCINFO_FLAGS1_PROCESS_ID. */
624  u_int32_t process_id;
625
626  /* The next 3 fields are only valid if flags1 contains
627   * MD_MISCINFO_FLAGS1_PROCESS_TIMES. */
628  u_int32_t process_create_time;  /* time_t process started */
629  u_int32_t process_user_time;    /* seconds of user CPU time */
630  u_int32_t process_kernel_time;  /* seconds of kernel CPU time */
631
632  /* The following fields are not present in MINIDUMP_MISC_INFO but are
633   * in MINIDUMP_MISC_INFO_2.  When this struct is populated, these values
634   * may not be set.  Use flags1 or sizeOfInfo to determine whether these
635   * values are present.  These are only valid when flags1 contains
636   * MD_MISCINFO_FLAGS1_PROCESSOR_POWER_INFO. */
637  u_int32_t processor_max_mhz;
638  u_int32_t processor_current_mhz;
639  u_int32_t processor_mhz_limit;
640  u_int32_t processor_max_idle_state;
641  u_int32_t processor_current_idle_state;
642} MDRawMiscInfo;  /* MINIDUMP_MISC_INFO, MINIDUMP_MISC_INFO2 */
643
644#define MD_MISCINFO_SIZE 24
645#define MD_MISCINFO2_SIZE 44
646
647/* For (MDRawMiscInfo).flags1.  These values indicate which fields in the
648 * MDRawMiscInfoStructure are valid. */
649typedef enum {
650  MD_MISCINFO_FLAGS1_PROCESS_ID           = 0x00000001,
651      /* MINIDUMP_MISC1_PROCESS_ID */
652  MD_MISCINFO_FLAGS1_PROCESS_TIMES        = 0x00000002,
653      /* MINIDUMP_MISC1_PROCESS_TIMES */
654  MD_MISCINFO_FLAGS1_PROCESSOR_POWER_INFO = 0x00000004
655      /* MINIDUMP_MISC1_PROCESSOR_POWER_INFO */
656} MDMiscInfoFlags1;
657
658/* 
659 * Around DbgHelp version 6.0, the style of new LIST structures changed
660 * from including an array of length 1 at the end of the struct to
661 * represent the variable-length data to including explicit
662 * "size of header", "size of entry" and "number of entries" fields
663 * in the header, presumably to allow backwards-compatibly-extending
664 * the structures in the future. The actual list entries follow the
665 * header data directly in this case.
666 */
667
668typedef struct {
669  u_int32_t size_of_header;    /* sizeof(MDRawMemoryInfoList) */
670  u_int32_t size_of_entry;     /* sizeof(MDRawMemoryInfo) */
671  u_int64_t number_of_entries;
672} MDRawMemoryInfoList;  /* MINIDUMP_MEMORY_INFO_LIST */
673
674typedef struct {
675  u_int64_t base_address;           /* Base address of a region of pages */
676  u_int64_t allocation_base;        /* Base address of a range of pages
677                                     * within this region. */
678  u_int32_t allocation_protection;  /* Memory protection when this region
679                                     * was originally allocated:
680                                     * MDMemoryProtection */
681  u_int32_t __alignment1;
682  u_int64_t region_size;
683  u_int32_t state;                  /* MDMemoryState */
684  u_int32_t protection;             /* MDMemoryProtection */
685  u_int32_t type;                   /* MDMemoryType */
686  u_int32_t __alignment2;
687} MDRawMemoryInfo;  /* MINIDUMP_MEMORY_INFO */
688
689/* For (MDRawMemoryInfo).state */
690typedef enum {
691  MD_MEMORY_STATE_COMMIT   = 0x1000,  /* physical storage has been allocated */
692  MD_MEMORY_STATE_RESERVE  = 0x2000,  /* reserved, but no physical storage */
693  MD_MEMORY_STATE_FREE     = 0x10000  /* available to be allocated */
694} MDMemoryState;
695
696/* For (MDRawMemoryInfo).allocation_protection and .protection */
697typedef enum {
698  MD_MEMORY_PROTECT_NOACCESS          = 0x01,  /* PAGE_NOACCESS */
699  MD_MEMORY_PROTECT_READONLY          = 0x02,  /* PAGE_READONLY */
700  MD_MEMORY_PROTECT_READWRITE         = 0x04,  /* PAGE_READWRITE */
701  MD_MEMORY_PROTECT_WRITECOPY         = 0x08,  /* PAGE_WRITECOPY */
702  MD_MEMORY_PROTECT_EXECUTE           = 0x10,  /* PAGE_EXECUTE */
703  MD_MEMORY_PROTECT_EXECUTE_READ      = 0x20,  /* PAGE_EXECUTE_READ */
704  MD_MEMORY_PROTECT_EXECUTE_READWRITE = 0x40,  /* PAGE_EXECUTE_READWRITE */
705  MD_MEMORY_PROTECT_EXECUTE_WRITECOPY = 0x80,  /* PAGE_EXECUTE_WRITECOPY */
706  /* These options can be combined with the previous flags. */
707  MD_MEMORY_PROTECT_GUARD             = 0x100,  /* PAGE_GUARD */
708  MD_MEMORY_PROTECT_NOCACHE           = 0x200,  /* PAGE_NOCACHE */
709  MD_MEMORY_PROTECT_WRITECOMBINE      = 0x400,  /* PAGE_WRITECOMBINE */
710} MDMemoryProtection;
711
712/* Used to mask the mutually exclusive options from the combinable flags. */
713const u_int32_t MD_MEMORY_PROTECTION_ACCESS_MASK = 0xFF;
714
715/* For (MDRawMemoryInfo).type */
716typedef enum {
717  MD_MEMORY_TYPE_PRIVATE = 0x20000,   /* not shared by other processes */
718  MD_MEMORY_TYPE_MAPPED  = 0x40000,   /* mapped into the view of a section */
719  MD_MEMORY_TYPE_IMAGE   = 0x1000000  /* mapped into the view of an image */
720} MDMemoryType;
721
722/*
723 * Breakpad extension types
724 */
725
726
727typedef struct {
728  /* validity is a bitmask with values from MDBreakpadInfoValidity, indicating
729   * which of the other fields in the structure are valid. */
730  u_int32_t validity;
731
732  /* Thread ID of the handler thread.  dump_thread_id should correspond to
733   * the thread_id of an MDRawThread in the minidump's MDRawThreadList if
734   * a dedicated thread in that list was used to produce the minidump.  If
735   * the MDRawThreadList does not contain a dedicated thread used to produce
736   * the minidump, this field should be set to 0 and the validity field
737   * must not contain MD_BREAKPAD_INFO_VALID_DUMP_THREAD_ID. */
738  u_int32_t dump_thread_id;
739
740  /* Thread ID of the thread that requested the minidump be produced.  As
741   * with dump_thread_id, requesting_thread_id should correspond to the
742   * thread_id of an MDRawThread in the minidump's MDRawThreadList.  For
743   * minidumps produced as a result of an exception, requesting_thread_id
744   * will be the same as the MDRawExceptionStream's thread_id field.  For
745   * minidumps produced "manually" at the program's request,
746   * requesting_thread_id will indicate which thread caused the dump to be
747   * written.  If the minidump was produced at the request of something
748   * other than a thread in the MDRawThreadList, this field should be set
749   * to 0 and the validity field must not contain
750   * MD_BREAKPAD_INFO_VALID_REQUESTING_THREAD_ID. */
751  u_int32_t requesting_thread_id;
752} MDRawBreakpadInfo;
753
754/* For (MDRawBreakpadInfo).validity: */
755typedef enum {
756  /* When set, the dump_thread_id field is valid. */
757  MD_BREAKPAD_INFO_VALID_DUMP_THREAD_ID       = 1 << 0,
758
759  /* When set, the requesting_thread_id field is valid. */
760  MD_BREAKPAD_INFO_VALID_REQUESTING_THREAD_ID = 1 << 1
761} MDBreakpadInfoValidity;
762
763typedef struct {
764  /* expression, function, and file are 0-terminated UTF-16 strings.  They
765   * may be truncated if necessary, but should always be 0-terminated when
766   * written to a file.
767   * Fixed-length strings are used because MiniDumpWriteDump doesn't offer
768   * a way for user streams to point to arbitrary RVAs for strings. */
769  u_int16_t expression[128];  /* Assertion that failed... */
770  u_int16_t function[128];    /* ...within this function... */
771  u_int16_t file[128];        /* ...in this file... */
772  u_int32_t line;             /* ...at this line. */
773  u_int32_t type;
774} MDRawAssertionInfo;
775
776/* For (MDRawAssertionInfo).type: */
777typedef enum {
778  MD_ASSERTION_INFO_TYPE_UNKNOWN = 0,
779
780  /* Used for assertions that would be raised by the MSVC CRT but are
781   * directed to an invalid parameter handler instead. */
782  MD_ASSERTION_INFO_TYPE_INVALID_PARAMETER,
783
784  /* Used for assertions that would be raised by the MSVC CRT but are
785   * directed to a pure virtual call handler instead. */
786  MD_ASSERTION_INFO_TYPE_PURE_VIRTUAL_CALL
787} MDAssertionInfoData;
788
789#if defined(_MSC_VER)
790#pragma warning(pop)
791#endif  /* _MSC_VER */
792
793
794#endif  /* GOOGLE_BREAKPAD_COMMON_MINIDUMP_FORMAT_H__ */