Home | History | Annotate | Download | only in common
      1 /* Copyright (c) 2006, Google Inc.
      2  * All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
     29 
     30 /* minidump_format.h: A cross-platform reimplementation of minidump-related
     31  * portions of DbgHelp.h from the Windows Platform SDK.
     32  *
     33  * (This is C99 source, please don't corrupt it with C++.)
     34  *
     35  * This file contains the necessary definitions to read minidump files
     36  * produced on amd64.  These files may be read on any platform provided
     37  * that the alignments of these structures on the processing system are
     38  * identical to the alignments of these structures on the producing system.
     39  * For this reason, precise-sized types are used.  The structures defined
     40  * by this file have been laid out to minimize alignment problems by ensuring
     41  * ensuring that all members are aligned on their natural boundaries.  In
     42  * In some cases, tail-padding may be significant when different ABIs specify
     43  * different tail-padding behaviors.  To avoid problems when reading or
     44  * writing affected structures, MD_*_SIZE macros are provided where needed,
     45  * containing the useful size of the structures without padding.
     46  *
     47  * Structures that are defined by Microsoft to contain a zero-length array
     48  * are instead defined here to contain an array with one element, as
     49  * zero-length arrays are forbidden by standard C and C++.  In these cases,
     50  * *_minsize constants are provided to be used in place of sizeof.  For a
     51  * cleaner interface to these sizes when using C++, see minidump_size.h.
     52  *
     53  * These structures are also sufficient to populate minidump files.
     54  *
     55  * These definitions may be extended to support handling minidump files
     56  * for other CPUs and other operating systems.
     57  *
     58  * Because precise data type sizes are crucial for this implementation to
     59  * function properly and portably in terms of interoperability with minidumps
     60  * produced by DbgHelp on Windows, a set of primitive types with known sizes
     61  * are used as the basis of each structure defined by this file.  DbgHelp
     62  * on Windows is assumed to be the reference implementation; this file
     63  * seeks to provide a cross-platform compatible implementation.  To avoid
     64  * collisions with the types and values defined and used by DbgHelp in the
     65  * event that this implementation is used on Windows, each type and value
     66  * defined here is given a new name, beginning with "MD".  Names of the
     67  * equivalent types and values in the Windows Platform SDK are given in
     68  * comments.
     69  *
     70  * Author: Mark Mentovai
     71  * Change to split into its own file: Neal Sidhwaney */
     72 
     73 #ifndef GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_AMD64_H__
     74 #define GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_AMD64_H__
     75 
     76 
     77 /*
     78  * AMD64 support, see WINNT.H
     79  */
     80 
     81 typedef struct {
     82   uint16_t       control_word;
     83   uint16_t       status_word;
     84   uint8_t        tag_word;
     85   uint8_t        reserved1;
     86   uint16_t       error_opcode;
     87   uint32_t       error_offset;
     88   uint16_t       error_selector;
     89   uint16_t       reserved2;
     90   uint32_t       data_offset;
     91   uint16_t       data_selector;
     92   uint16_t       reserved3;
     93   uint32_t       mx_csr;
     94   uint32_t       mx_csr_mask;
     95   uint128_struct float_registers[8];
     96   uint128_struct xmm_registers[16];
     97   uint8_t        reserved4[96];
     98 } MDXmmSaveArea32AMD64;  /* XMM_SAVE_AREA32 */
     99 
    100 #define MD_CONTEXT_AMD64_VR_COUNT 26
    101 
    102 typedef struct {
    103   /*
    104    * Register parameter home addresses.
    105    */
    106   uint64_t  p1_home;
    107   uint64_t  p2_home;
    108   uint64_t  p3_home;
    109   uint64_t  p4_home;
    110   uint64_t  p5_home;
    111   uint64_t  p6_home;
    112 
    113   /* The next field determines the layout of the structure, and which parts
    114    * of it are populated */
    115   uint32_t  context_flags;
    116   uint32_t  mx_csr;
    117 
    118   /* The next register is included with MD_CONTEXT_AMD64_CONTROL */
    119   uint16_t  cs;
    120 
    121   /* The next 4 registers are included with MD_CONTEXT_AMD64_SEGMENTS */
    122   uint16_t  ds;
    123   uint16_t  es;
    124   uint16_t  fs;
    125   uint16_t  gs;
    126 
    127   /* The next 2 registers are included with MD_CONTEXT_AMD64_CONTROL */
    128   uint16_t  ss;
    129   uint32_t  eflags;
    130 
    131   /* The next 6 registers are included with MD_CONTEXT_AMD64_DEBUG_REGISTERS */
    132   uint64_t  dr0;
    133   uint64_t  dr1;
    134   uint64_t  dr2;
    135   uint64_t  dr3;
    136   uint64_t  dr6;
    137   uint64_t  dr7;
    138 
    139   /* The next 4 registers are included with MD_CONTEXT_AMD64_INTEGER */
    140   uint64_t  rax;
    141   uint64_t  rcx;
    142   uint64_t  rdx;
    143   uint64_t  rbx;
    144 
    145   /* The next register is included with MD_CONTEXT_AMD64_CONTROL */
    146   uint64_t  rsp;
    147 
    148   /* The next 11 registers are included with MD_CONTEXT_AMD64_INTEGER */
    149   uint64_t  rbp;
    150   uint64_t  rsi;
    151   uint64_t  rdi;
    152   uint64_t  r8;
    153   uint64_t  r9;
    154   uint64_t  r10;
    155   uint64_t  r11;
    156   uint64_t  r12;
    157   uint64_t  r13;
    158   uint64_t  r14;
    159   uint64_t  r15;
    160 
    161   /* The next register is included with MD_CONTEXT_AMD64_CONTROL */
    162   uint64_t  rip;
    163 
    164   /* The next set of registers are included with
    165    * MD_CONTEXT_AMD64_FLOATING_POINT
    166    */
    167   union {
    168     MDXmmSaveArea32AMD64 flt_save;
    169     struct {
    170       uint128_struct header[2];
    171       uint128_struct legacy[8];
    172       uint128_struct xmm0;
    173       uint128_struct xmm1;
    174       uint128_struct xmm2;
    175       uint128_struct xmm3;
    176       uint128_struct xmm4;
    177       uint128_struct xmm5;
    178       uint128_struct xmm6;
    179       uint128_struct xmm7;
    180       uint128_struct xmm8;
    181       uint128_struct xmm9;
    182       uint128_struct xmm10;
    183       uint128_struct xmm11;
    184       uint128_struct xmm12;
    185       uint128_struct xmm13;
    186       uint128_struct xmm14;
    187       uint128_struct xmm15;
    188     } sse_registers;
    189   };
    190 
    191   uint128_struct vector_register[MD_CONTEXT_AMD64_VR_COUNT];
    192   uint64_t       vector_control;
    193 
    194   /* The next 5 registers are included with MD_CONTEXT_AMD64_DEBUG_REGISTERS */
    195   uint64_t debug_control;
    196   uint64_t last_branch_to_rip;
    197   uint64_t last_branch_from_rip;
    198   uint64_t last_exception_to_rip;
    199   uint64_t last_exception_from_rip;
    200 
    201 } MDRawContextAMD64;  /* CONTEXT */
    202 
    203 /* For (MDRawContextAMD64).context_flags.  These values indicate the type of
    204  * context stored in the structure.  The high 24 bits identify the CPU, the
    205  * low 8 bits identify the type of context saved. */
    206 #define MD_CONTEXT_AMD64 0x00100000  /* CONTEXT_AMD64 */
    207 #define MD_CONTEXT_AMD64_CONTROL         (MD_CONTEXT_AMD64 | 0x00000001)
    208      /* CONTEXT_CONTROL */
    209 #define MD_CONTEXT_AMD64_INTEGER         (MD_CONTEXT_AMD64 | 0x00000002)
    210      /* CONTEXT_INTEGER */
    211 #define MD_CONTEXT_AMD64_SEGMENTS        (MD_CONTEXT_AMD64 | 0x00000004)
    212      /* CONTEXT_SEGMENTS */
    213 #define MD_CONTEXT_AMD64_FLOATING_POINT  (MD_CONTEXT_AMD64 | 0x00000008)
    214      /* CONTEXT_FLOATING_POINT */
    215 #define MD_CONTEXT_AMD64_DEBUG_REGISTERS (MD_CONTEXT_AMD64 | 0x00000010)
    216      /* CONTEXT_DEBUG_REGISTERS */
    217 #define MD_CONTEXT_AMD64_XSTATE          (MD_CONTEXT_AMD64 | 0x00000040)
    218      /* CONTEXT_XSTATE */
    219 
    220 /* WinNT.h refers to CONTEXT_MMX_REGISTERS but doesn't appear to define it
    221  * I think it really means CONTEXT_FLOATING_POINT.
    222  */
    223 
    224 #define MD_CONTEXT_AMD64_FULL            (MD_CONTEXT_AMD64_CONTROL | \
    225                                           MD_CONTEXT_AMD64_INTEGER | \
    226                                           MD_CONTEXT_AMD64_FLOATING_POINT)
    227      /* CONTEXT_FULL */
    228 
    229 #define MD_CONTEXT_AMD64_ALL             (MD_CONTEXT_AMD64_FULL | \
    230                                           MD_CONTEXT_AMD64_SEGMENTS | \
    231                                           MD_CONTEXT_X86_DEBUG_REGISTERS)
    232      /* CONTEXT_ALL */
    233 
    234 
    235 #endif /* GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_AMD64_H__ */
    236