Planeshift

minidump_cpu_x86.h

Go to the documentation of this file.
00001 /* Copyright (c) 2006, Google Inc.
00002  * All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are
00006  * met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  * notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above
00011  * copyright notice, this list of conditions and the following disclaimer
00012  * in the documentation and/or other materials provided with the
00013  * distribution.
00014  *     * Neither the name of Google Inc. nor the names of its
00015  * contributors may be used to endorse or promote products derived from
00016  * this software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00021  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00022  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00023  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00024  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00025  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00026  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00028  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
00029 
00030 /* minidump_format.h: A cross-platform reimplementation of minidump-related
00031  * portions of DbgHelp.h from the Windows Platform SDK.
00032  *
00033  * (This is C99 source, please don't corrupt it with C++.)
00034  *
00035  * This file contains the necessary definitions to read minidump files
00036  * produced on x86.  These files may be read on any platform provided
00037  * that the alignments of these structures on the processing system are
00038  * identical to the alignments of these structures on the producing system.
00039  * For this reason, precise-sized types are used.  The structures defined
00040  * by this file have been laid out to minimize alignment problems by ensuring
00041  * ensuring that all members are aligned on their natural boundaries.  In
00042  * In some cases, tail-padding may be significant when different ABIs specify
00043  * different tail-padding behaviors.  To avoid problems when reading or
00044  * writing affected structures, MD_*_SIZE macros are provided where needed,
00045  * containing the useful size of the structures without padding.
00046  *
00047  * Structures that are defined by Microsoft to contain a zero-length array
00048  * are instead defined here to contain an array with one element, as
00049  * zero-length arrays are forbidden by standard C and C++.  In these cases,
00050  * *_minsize constants are provided to be used in place of sizeof.  For a
00051  * cleaner interface to these sizes when using C++, see minidump_size.h.
00052  *
00053  * These structures are also sufficient to populate minidump files.
00054  *
00055  * These definitions may be extended to support handling minidump files
00056  * for other CPUs and other operating systems.
00057  *
00058  * Because precise data type sizes are crucial for this implementation to
00059  * function properly and portably in terms of interoperability with minidumps
00060  * produced by DbgHelp on Windows, a set of primitive types with known sizes
00061  * are used as the basis of each structure defined by this file.  DbgHelp
00062  * on Windows is assumed to be the reference implementation; this file
00063  * seeks to provide a cross-platform compatible implementation.  To avoid
00064  * collisions with the types and values defined and used by DbgHelp in the
00065  * event that this implementation is used on Windows, each type and value
00066  * defined here is given a new name, beginning with "MD".  Names of the
00067  * equivalent types and values in the Windows Platform SDK are given in
00068  * comments.
00069  *
00070  * Author: Mark Mentovai */
00071 
00072 #ifndef GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_X86_H__
00073 #define GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_X86_H__
00074 
00075 #define MD_FLOATINGSAVEAREA_X86_REGISTERAREA_SIZE 80
00076      /* SIZE_OF_80387_REGISTERS */
00077 
00078 typedef struct {
00079   uint32_t control_word;
00080   uint32_t status_word;
00081   uint32_t tag_word;
00082   uint32_t error_offset;
00083   uint32_t error_selector;
00084   uint32_t data_offset;
00085   uint32_t data_selector;
00086 
00087   /* register_area contains eight 80-bit (x87 "long double") quantities for
00088    * floating-point registers %st0 (%mm0) through %st7 (%mm7). */
00089   uint8_t  register_area[MD_FLOATINGSAVEAREA_X86_REGISTERAREA_SIZE];
00090   uint32_t cr0_npx_state;
00091 } MDFloatingSaveAreaX86;  /* FLOATING_SAVE_AREA */
00092 
00093 
00094 #define MD_CONTEXT_X86_EXTENDED_REGISTERS_SIZE 512
00095      /* MAXIMUM_SUPPORTED_EXTENSION */
00096 
00097 typedef struct {
00098   /* The next field determines the layout of the structure, and which parts
00099    * of it are populated */
00100   uint32_t             context_flags;
00101 
00102   /* The next 6 registers are included with MD_CONTEXT_X86_DEBUG_REGISTERS */
00103   uint32_t             dr0;
00104   uint32_t             dr1;
00105   uint32_t             dr2;
00106   uint32_t             dr3;
00107   uint32_t             dr6;
00108   uint32_t             dr7;
00109 
00110   /* The next field is included with MD_CONTEXT_X86_FLOATING_POINT */
00111   MDFloatingSaveAreaX86 float_save;
00112 
00113   /* The next 4 registers are included with MD_CONTEXT_X86_SEGMENTS */
00114   uint32_t             gs; 
00115   uint32_t             fs;
00116   uint32_t             es;
00117   uint32_t             ds;
00118   /* The next 6 registers are included with MD_CONTEXT_X86_INTEGER */
00119   uint32_t             edi;
00120   uint32_t             esi;
00121   uint32_t             ebx;
00122   uint32_t             edx;
00123   uint32_t             ecx;
00124   uint32_t             eax;
00125 
00126   /* The next 6 registers are included with MD_CONTEXT_X86_CONTROL */
00127   uint32_t             ebp;
00128   uint32_t             eip;
00129   uint32_t             cs;      /* WinNT.h says "must be sanitized" */
00130   uint32_t             eflags;  /* WinNT.h says "must be sanitized" */
00131   uint32_t             esp;
00132   uint32_t             ss;
00133 
00134   /* The next field is included with MD_CONTEXT_X86_EXTENDED_REGISTERS.
00135    * It contains vector (MMX/SSE) registers.  It it laid out in the
00136    * format used by the fxsave and fsrstor instructions, so it includes
00137    * a copy of the x87 floating-point registers as well.  See FXSAVE in
00138    * "Intel Architecture Software Developer's Manual, Volume 2." */
00139   uint8_t              extended_registers[
00140                          MD_CONTEXT_X86_EXTENDED_REGISTERS_SIZE];
00141 } MDRawContextX86;  /* CONTEXT */
00142 
00143 /* For (MDRawContextX86).context_flags.  These values indicate the type of
00144  * context stored in the structure.  The high 24 bits identify the CPU, the
00145  * low 8 bits identify the type of context saved. */
00146 #define MD_CONTEXT_X86                    0x00010000
00147      /* CONTEXT_i386, CONTEXT_i486: identifies CPU */
00148 #define MD_CONTEXT_X86_CONTROL            (MD_CONTEXT_X86 | 0x00000001)
00149      /* CONTEXT_CONTROL */
00150 #define MD_CONTEXT_X86_INTEGER            (MD_CONTEXT_X86 | 0x00000002)
00151      /* CONTEXT_INTEGER */
00152 #define MD_CONTEXT_X86_SEGMENTS           (MD_CONTEXT_X86 | 0x00000004)
00153      /* CONTEXT_SEGMENTS */
00154 #define MD_CONTEXT_X86_FLOATING_POINT     (MD_CONTEXT_X86 | 0x00000008)
00155      /* CONTEXT_FLOATING_POINT */
00156 #define MD_CONTEXT_X86_DEBUG_REGISTERS    (MD_CONTEXT_X86 | 0x00000010)
00157      /* CONTEXT_DEBUG_REGISTERS */
00158 #define MD_CONTEXT_X86_EXTENDED_REGISTERS (MD_CONTEXT_X86 | 0x00000020)
00159      /* CONTEXT_EXTENDED_REGISTERS */
00160 #define MD_CONTEXT_X86_XSTATE             (MD_CONTEXT_X86 | 0x00000040)
00161      /* CONTEXT_XSTATE */
00162 
00163 #define MD_CONTEXT_X86_FULL              (MD_CONTEXT_X86_CONTROL | \
00164                                           MD_CONTEXT_X86_INTEGER | \
00165                                           MD_CONTEXT_X86_SEGMENTS)
00166      /* CONTEXT_FULL */
00167 
00168 #define MD_CONTEXT_X86_ALL               (MD_CONTEXT_X86_FULL | \
00169                                           MD_CONTEXT_X86_FLOATING_POINT | \
00170                                           MD_CONTEXT_X86_DEBUG_REGISTERS | \
00171                                           MD_CONTEXT_X86_EXTENDED_REGISTERS)
00172      /* CONTEXT_ALL */
00173 
00174 #endif /* GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_X86_H__ */