1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
6 #define ELF_CLASS ELFCLASS64
8 #define ELF_CLASS ELFCLASS32
11 #define Ehdr ElfW(Ehdr)
12 #define Phdr ElfW(Phdr)
13 #define Shdr ElfW(Shdr)
14 #define Nhdr ElfW(Nhdr)
15 #define auxv_t ElfW(auxv_t)
17 #if defined(__x86_64__)
18 #define ELF_ARCH EM_X86_64
19 #elif defined(__i386__)
20 #define ELF_ARCH EM_386
21 #elif defined(__arm__)
22 #define ELF_ARCH EM_ARM
25 #define PH_HDR_CANARY 0xFFFF
28 #define NT_FILE 0x46494c45
31 class DumpWriter : IUnknown
34 LONG m_ref; // reference count
36 CrashInfo& m_crashInfo;
37 BYTE m_tempBuffer[0x4000];
40 DumpWriter(CrashInfo& crashInfo);
41 virtual ~DumpWriter();
42 bool OpenDump(const char* dumpFileName);
46 STDMETHOD(QueryInterface)(___in REFIID InterfaceId, ___out PVOID* Interface);
47 STDMETHOD_(ULONG, AddRef)();
48 STDMETHOD_(ULONG, Release)();
51 bool WriteProcessInfo();
53 size_t GetNTFileInfoSize(size_t* alignmentBytes = nullptr);
54 bool WriteNTFileInfo();
55 bool WriteThread(const ThreadInfo& thread, int fatal_signal);
56 bool WriteData(const void* buffer, size_t length);
58 const size_t GetProcessInfoSize() const { return sizeof(Nhdr) + 8 + sizeof(prpsinfo_t); }
59 const size_t GetAuxvInfoSize() const { return sizeof(Nhdr) + 8 + m_crashInfo.GetAuxvSize(); }
60 const size_t GetThreadInfoSize() const
62 return m_crashInfo.Threads().size() * ((sizeof(Nhdr) + 8 + sizeof(prstatus_t))
63 #if defined(__i386__) || defined(__x86_64__) || defined(__arm__)
64 + sizeof(Nhdr) + 8 + sizeof(user_fpregs_struct)
67 + sizeof(Nhdr) + 8 + sizeof(user_fpxregs_struct)
69 #if defined(__arm__) && defined(__VFP_FP__) && !defined(__SOFTFP__)
70 + sizeof(Nhdr) + 8 + sizeof(user_vfpregs_struct)