Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:22

0001 //===- Minidump.h - Minidump constants and structures -----------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This header constants and data structures pertaining to the Windows Minidump
0010 // core file format.
0011 //
0012 // Reference:
0013 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms679293(v=vs.85).aspx
0014 // https://chromium.googlesource.com/breakpad/breakpad/
0015 //
0016 //===----------------------------------------------------------------------===//
0017 
0018 #ifndef LLVM_BINARYFORMAT_MINIDUMP_H
0019 #define LLVM_BINARYFORMAT_MINIDUMP_H
0020 
0021 #include "llvm/ADT/BitmaskEnum.h"
0022 #include "llvm/ADT/DenseMapInfo.h"
0023 #include "llvm/Support/Endian.h"
0024 
0025 namespace llvm {
0026 namespace minidump {
0027 
0028 LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
0029 
0030 /// The minidump header is the first part of a minidump file. It identifies the
0031 /// file as a minidump file, and gives the location of the stream directory.
0032 struct Header {
0033   static constexpr uint32_t MagicSignature = 0x504d444d; // PMDM
0034   static constexpr uint16_t MagicVersion = 0xa793;
0035 
0036   support::ulittle32_t Signature;
0037   // The high 16 bits of version field are implementation specific. The low 16
0038   // bits should be MagicVersion.
0039   support::ulittle32_t Version;
0040   support::ulittle32_t NumberOfStreams;
0041   support::ulittle32_t StreamDirectoryRVA;
0042   support::ulittle32_t Checksum;
0043   support::ulittle32_t TimeDateStamp;
0044   support::ulittle64_t Flags;
0045 };
0046 static_assert(sizeof(Header) == 32);
0047 
0048 /// The type of a minidump stream identifies its contents. Streams numbers after
0049 /// LastReserved are for application-defined data streams.
0050 enum class StreamType : uint32_t {
0051 #define HANDLE_MDMP_STREAM_TYPE(CODE, NAME) NAME = CODE,
0052 #include "llvm/BinaryFormat/MinidumpConstants.def"
0053   Unused = 0,
0054   LastReserved = 0x0000ffff,
0055 };
0056 
0057 /// Specifies the location (and size) of various objects in the minidump file.
0058 /// The location is relative to the start of the file.
0059 struct LocationDescriptor {
0060   support::ulittle32_t DataSize;
0061   support::ulittle32_t RVA;
0062 };
0063 static_assert(sizeof(LocationDescriptor) == 8);
0064 
0065 /// Describes a single memory range (both its VM address and where to find it in
0066 /// the file) of the process from which this minidump file was generated.
0067 struct MemoryDescriptor {
0068   support::ulittle64_t StartOfMemoryRange;
0069   LocationDescriptor Memory;
0070 };
0071 static_assert(sizeof(MemoryDescriptor) == 16);
0072 
0073 struct MemoryDescriptor_64 {
0074   support::ulittle64_t StartOfMemoryRange;
0075   support::ulittle64_t DataSize;
0076 };
0077 static_assert(sizeof(MemoryDescriptor_64) == 16);
0078 
0079 struct MemoryListHeader {
0080   support::ulittle32_t NumberOfMemoryRanges;
0081 };
0082 static_assert(sizeof(MemoryListHeader) == 4);
0083 
0084 struct Memory64ListHeader {
0085   support::ulittle64_t NumberOfMemoryRanges;
0086   support::ulittle64_t BaseRVA;
0087 };
0088 static_assert(sizeof(Memory64ListHeader) == 16);
0089 
0090 struct MemoryInfoListHeader {
0091   support::ulittle32_t SizeOfHeader;
0092   support::ulittle32_t SizeOfEntry;
0093   support::ulittle64_t NumberOfEntries;
0094 
0095   MemoryInfoListHeader() = default;
0096   MemoryInfoListHeader(uint32_t SizeOfHeader, uint32_t SizeOfEntry,
0097                        uint64_t NumberOfEntries)
0098       : SizeOfHeader(SizeOfHeader), SizeOfEntry(SizeOfEntry),
0099         NumberOfEntries(NumberOfEntries) {}
0100 };
0101 static_assert(sizeof(MemoryInfoListHeader) == 16);
0102 
0103 enum class MemoryProtection : uint32_t {
0104 #define HANDLE_MDMP_PROTECT(CODE, NAME, NATIVENAME) NAME = CODE,
0105 #include "llvm/BinaryFormat/MinidumpConstants.def"
0106   LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/0xffffffffu),
0107 };
0108 
0109 enum class MemoryState : uint32_t {
0110 #define HANDLE_MDMP_MEMSTATE(CODE, NAME, NATIVENAME) NAME = CODE,
0111 #include "llvm/BinaryFormat/MinidumpConstants.def"
0112   LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/0xffffffffu),
0113 };
0114 
0115 enum class MemoryType : uint32_t {
0116 #define HANDLE_MDMP_MEMTYPE(CODE, NAME, NATIVENAME) NAME = CODE,
0117 #include "llvm/BinaryFormat/MinidumpConstants.def"
0118   LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/0xffffffffu),
0119 };
0120 
0121 struct MemoryInfo {
0122   support::ulittle64_t BaseAddress;
0123   support::ulittle64_t AllocationBase;
0124   support::little_t<MemoryProtection> AllocationProtect;
0125   support::ulittle32_t Reserved0;
0126   support::ulittle64_t RegionSize;
0127   support::little_t<MemoryState> State;
0128   support::little_t<MemoryProtection> Protect;
0129   support::little_t<MemoryType> Type;
0130   support::ulittle32_t Reserved1;
0131 };
0132 static_assert(sizeof(MemoryInfo) == 48);
0133 
0134 /// Specifies the location and type of a single stream in the minidump file. The
0135 /// minidump stream directory is an array of entries of this type, with its size
0136 /// given by Header.NumberOfStreams.
0137 struct Directory {
0138   support::little_t<StreamType> Type;
0139   LocationDescriptor Location;
0140 };
0141 static_assert(sizeof(Directory) == 12);
0142 
0143 /// The processor architecture of the system that generated this minidump. Used
0144 /// in the ProcessorArch field of the SystemInfo stream.
0145 enum class ProcessorArchitecture : uint16_t {
0146 #define HANDLE_MDMP_ARCH(CODE, NAME) NAME = CODE,
0147 #include "llvm/BinaryFormat/MinidumpConstants.def"
0148 };
0149 
0150 /// The OS Platform of the system that generated this minidump. Used in the
0151 /// PlatformId field of the SystemInfo stream.
0152 enum class OSPlatform : uint32_t {
0153 #define HANDLE_MDMP_PLATFORM(CODE, NAME) NAME = CODE,
0154 #include "llvm/BinaryFormat/MinidumpConstants.def"
0155 };
0156 
0157 /// Detailed information about the processor of the system that generated this
0158 /// minidump. Its interpretation depends on the ProcessorArchitecture enum.
0159 union CPUInfo {
0160   struct X86Info {
0161     char VendorID[12];                        // cpuid 0: ebx, edx, ecx
0162     support::ulittle32_t VersionInfo;         // cpuid 1: eax
0163     support::ulittle32_t FeatureInfo;         // cpuid 1: edx
0164     support::ulittle32_t AMDExtendedFeatures; // cpuid 0x80000001, ebx
0165   } X86;
0166   struct ArmInfo {
0167     support::ulittle32_t CPUID;
0168     support::ulittle32_t ElfHWCaps; // linux specific, 0 otherwise
0169   } Arm;
0170   struct OtherInfo {
0171     uint8_t ProcessorFeatures[16];
0172   } Other;
0173 };
0174 static_assert(sizeof(CPUInfo) == 24);
0175 
0176 /// The SystemInfo stream, containing various information about the system where
0177 /// this minidump was generated.
0178 struct SystemInfo {
0179   support::little_t<ProcessorArchitecture> ProcessorArch;
0180   support::ulittle16_t ProcessorLevel;
0181   support::ulittle16_t ProcessorRevision;
0182 
0183   uint8_t NumberOfProcessors;
0184   uint8_t ProductType;
0185 
0186   support::ulittle32_t MajorVersion;
0187   support::ulittle32_t MinorVersion;
0188   support::ulittle32_t BuildNumber;
0189   support::little_t<OSPlatform> PlatformId;
0190   support::ulittle32_t CSDVersionRVA;
0191 
0192   support::ulittle16_t SuiteMask;
0193   support::ulittle16_t Reserved;
0194 
0195   CPUInfo CPU;
0196 };
0197 static_assert(sizeof(SystemInfo) == 56);
0198 
0199 struct VSFixedFileInfo {
0200   support::ulittle32_t Signature;
0201   support::ulittle32_t StructVersion;
0202   support::ulittle32_t FileVersionHigh;
0203   support::ulittle32_t FileVersionLow;
0204   support::ulittle32_t ProductVersionHigh;
0205   support::ulittle32_t ProductVersionLow;
0206   support::ulittle32_t FileFlagsMask;
0207   support::ulittle32_t FileFlags;
0208   support::ulittle32_t FileOS;
0209   support::ulittle32_t FileType;
0210   support::ulittle32_t FileSubtype;
0211   support::ulittle32_t FileDateHigh;
0212   support::ulittle32_t FileDateLow;
0213 };
0214 static_assert(sizeof(VSFixedFileInfo) == 52);
0215 
0216 inline bool operator==(const VSFixedFileInfo &LHS, const VSFixedFileInfo &RHS) {
0217   return memcmp(&LHS, &RHS, sizeof(VSFixedFileInfo)) == 0;
0218 }
0219 
0220 struct Module {
0221   support::ulittle64_t BaseOfImage;
0222   support::ulittle32_t SizeOfImage;
0223   support::ulittle32_t Checksum;
0224   support::ulittle32_t TimeDateStamp;
0225   support::ulittle32_t ModuleNameRVA;
0226   VSFixedFileInfo VersionInfo;
0227   LocationDescriptor CvRecord;
0228   LocationDescriptor MiscRecord;
0229   support::ulittle64_t Reserved0;
0230   support::ulittle64_t Reserved1;
0231 };
0232 static_assert(sizeof(Module) == 108);
0233 
0234 /// Describes a single thread in the minidump file. Part of the ThreadList
0235 /// stream.
0236 struct Thread {
0237   support::ulittle32_t ThreadId;
0238   support::ulittle32_t SuspendCount;
0239   support::ulittle32_t PriorityClass;
0240   support::ulittle32_t Priority;
0241   support::ulittle64_t EnvironmentBlock;
0242   MemoryDescriptor Stack;
0243   LocationDescriptor Context;
0244 };
0245 static_assert(sizeof(Thread) == 48);
0246 
0247 struct Exception {
0248   static constexpr size_t MaxParameters = 15;
0249   static constexpr size_t MaxParameterBytes = MaxParameters * sizeof(uint64_t);
0250   static const uint32_t LLDB_FLAG = 0x4C4C4442; // ASCII for 'LLDB'
0251 
0252   support::ulittle32_t ExceptionCode;
0253   support::ulittle32_t ExceptionFlags;
0254   support::ulittle64_t ExceptionRecord;
0255   support::ulittle64_t ExceptionAddress;
0256   support::ulittle32_t NumberParameters;
0257   support::ulittle32_t UnusedAlignment;
0258   support::ulittle64_t ExceptionInformation[MaxParameters];
0259 };
0260 static_assert(sizeof(Exception) == 152);
0261 
0262 struct ExceptionStream {
0263   support::ulittle32_t ThreadId;
0264   support::ulittle32_t UnusedAlignment;
0265   Exception ExceptionRecord;
0266   LocationDescriptor ThreadContext;
0267 };
0268 static_assert(sizeof(ExceptionStream) == 168);
0269 
0270 } // namespace minidump
0271 
0272 template <> struct DenseMapInfo<minidump::StreamType> {
0273   static minidump::StreamType getEmptyKey() { return minidump::StreamType(-1); }
0274 
0275   static minidump::StreamType getTombstoneKey() {
0276     return minidump::StreamType(-2);
0277   }
0278 
0279   static unsigned getHashValue(minidump::StreamType Val) {
0280     return DenseMapInfo<uint32_t>::getHashValue(static_cast<uint32_t>(Val));
0281   }
0282 
0283   static bool isEqual(minidump::StreamType LHS, minidump::StreamType RHS) {
0284     return LHS == RHS;
0285   }
0286 };
0287 
0288 } // namespace llvm
0289 
0290 #endif // LLVM_BINARYFORMAT_MINIDUMP_H