chromium/third_party/crashpad/crashpad/minidump/minidump_context.h

// Copyright 2014 The Crashpad Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef CRASHPAD_MINIDUMP_MINIDUMP_CONTEXT_H_
#define CRASHPAD_MINIDUMP_MINIDUMP_CONTEXT_H_

#include <stdint.h>

#include "base/compiler_specific.h"
#include "snapshot/cpu_context.h"
#include "util/numeric/int128.h"

namespace crashpad {

//! \brief Architecture-independent flags for `context_flags` fields in Minidump
//!    context structures.
//
// https://zachsaw.blogspot.com/2010/11/wow64-bug-getthreadcontext-may-return.html#c5639760895973344002
enum MinidumpContextFlags : uint32_t {};

//! \brief 32-bit x86-specifc flags for MinidumpContextX86::context_flags.
enum MinidumpContextX86Flags : uint32_t {};

//! \brief A 32-bit x86 CPU context (register state) carried in a minidump file.
//!
//! This is analogous to the `CONTEXT` structure on Windows when targeting
//! 32-bit x86, and the `WOW64_CONTEXT` structure when targeting an x86-family
//! CPU, either 32- or 64-bit. This structure is used instead of `CONTEXT` or
//! `WOW64_CONTEXT` to make it available when targeting other architectures.
//!
//! \note This structure doesn’t carry `dr4` or `dr5`, which are obsolete and
//!     normally alias `dr6` and `dr7`, respectively. See Intel Software
//!     Developer’s Manual, Volume 3B: System Programming, Part 2 (253669-052),
//!     17.2.2 “Debug Registers DR4 and DR5”.
struct MinidumpContextX86 {};

//! \brief x86_64-specific flags for MinidumpContextAMD64::context_flags.
enum MinidumpContextAMD64Flags : uint32_t {};

//! \brief An x86_64 (AMD64) CPU context (register state) carried in a minidump
//!     file.
//!
//! This is analogous to the `CONTEXT` structure on Windows when targeting
//! x86_64. This structure is used instead of `CONTEXT` to make it available
//! when targeting other architectures.
//!
//! \note This structure doesn’t carry `dr4` or `dr5`, which are obsolete and
//!     normally alias `dr6` and `dr7`, respectively. See Intel Software
//!     Developer’s Manual, Volume 3B: System Programming, Part 2 (253669-052),
//!     17.2.2 “Debug Registers DR4 and DR5”.
struct alignas(16) MinidumpContextAMD64 {};

//! \brief 32-bit ARM-specifc flags for MinidumpContextARM::context_flags.
enum MinidumpContextARMFlags : uint32_t {};

//! \brief A 32-bit ARM CPU context (register state) carried in a minidump file.
struct MinidumpContextARM {};

//! \brief CONTEXT_CHUNK
struct MinidumpContextChunk {};

//! \brief CONTEXT_EX
struct MinidumpContextExHeader {};

//! \brief XSAVE_AREA_HEADER
struct MinidumpXSaveAreaHeader {};

//! \brief Offset of first xsave feature in the full extended context.
//!
//! This is used to calculate the final size of the extended context, and
//! can be validated by calling InitializeContext2 with one XSTATE feature,
//! and LocateXStateFeature to determine the first offset.
//! Also see "MANAGING STATE USING THE XSAVE FEATURE SET", Ch. 13, Intel SDM.
constexpr uint32_t kMinidumpAMD64XSaveOffset =;

//! \brief Offset of first xsave feature within the extended context area.
//!
//! 0x240 is the size of the legacy area (512) + the xsave header(64 bytes)
//! Intel SDM 13.4.1. This is not where the item is in the extended compacted
//! context, but is the offset recorded in the minidump. It needs to be correct
//! there. See https://windows-internals.com/cet-on-windows/ for some discussion
//! "CONTEXT_XSTATE: Extended processor state chunk. The state is stored in the
//! same format the XSAVE operation stores it with exception of the first 512
//! bytes, i.e. starting from XSAVE_AREA_HEADER." This may vary by cpuid.
constexpr uint32_t kXSaveAreaFirstOffset =;

//! \brief XSAVE_CET_U_FORMAT
struct MinidumpAMD64XSaveFormatCetU {};

//! \brief 64-bit ARM-specifc flags for MinidumpContextARM64::context_flags.
enum MinidumpContextARM64Flags : uint32_t {};

//! \brief A 64-bit ARM CPU context (register state) carried in a minidump file.
struct MinidumpContextARM64 {};

//! \brief 32bit MIPS-specifc flags for MinidumpContextMIPS::context_flags.
//! Based on minidump_cpu_mips.h from breakpad
enum MinidumpContextMIPSFlags : uint32_t {};

//! \brief A 32bit MIPS CPU context (register state) carried in a minidump file.
struct MinidumpContextMIPS {};

//! \brief 64bit MIPS-specifc flags for MinidumpContextMIPS64::context_flags.
//! Based on minidump_cpu_mips.h from breakpad
enum MinidumpContextMIPS64Flags : uint32_t {};

//! \brief A 32bit MIPS CPU context (register state) carried in a minidump file.
struct MinidumpContextMIPS64 {};

//! \brief 64-bit RISCV-specific flags for
//! MinidumpContextRISCV64::context_flags.
enum MinidumpContextRISCV64Flags : uint32_t {};

//! \brief A 64-bit RISC-V CPU context (register state) carried in a minidump
//! file.
//!
//! This structure is versioned. Increment |kVersion| when changing this
//! structure.
struct MinidumpContextRISCV64 {};

}  // namespace crashpad

#endif  // CRASHPAD_MINIDUMP_MINIDUMP_CONTEXT_H_