crashpad/snapshot/win/cpu_context_win.h

70 lines
2.3 KiB
C
Raw Normal View History

// Copyright 2015 The Crashpad Authors. All rights reserved.
//
// 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_SNAPSHOT_WIN_CPU_CONTEXT_WIN_H_
#define CRASHPAD_SNAPSHOT_WIN_CPU_CONTEXT_WIN_H_
#include <windows.h>
#include "build/build_config.h"
namespace crashpad {
struct CPUContextX86;
struct CPUContextX86_64;
struct CPUContextARM64;
#if defined(ARCH_CPU_X86) || DOXYGEN
//! \brief Initializes a CPUContextX86 structure from a native context structure
//! on Windows.
void InitializeX86Context(const CONTEXT* context, CPUContextX86* out);
#endif // ARCH_CPU_X86
#if defined(ARCH_CPU_X86_64) || DOXYGEN
//! \brief Initializes a CPUContextX86 structure from a native context structure
//! on Windows.
void InitializeX86Context(const WOW64_CONTEXT* context, CPUContextX86* out);
//! \brief Initializes a CPUContextX86_64 structure from a native context
//! structure on Windows.
//! Only reads a max of sizeof(CONTEXT) so will not initialize extended values.
void InitializeX64Context(const CONTEXT* context, CPUContextX86_64* out);
Captures shadow stack registers for x64 Windows contexts Windows extended contexts must be allocated by InitializeContext2 and may not be aligned. This means we cannot simply store a struct in our thread snapshot object, but must instead store enough memory and alias our struct onto this backing memory. Note that shadow stack pointers are not yet recorded for the initial exception - this cannot be determined using LocateXStateFeature in the capturing process and will be added in a future CL by plumbing through client messages when a crashed process requests a dump. See crash/32bd2c53a252705c for an example dump with this baked into chrome, that has passed through breakpad without breaking it. Local testing shows this creates valid dumps when built into Chrome, but that the referenced memory limits may need to be increased to allow for ssp referenced memory to be included. See "MANAGING STATE USING THE XSAVE FEATURE SET" Chapter 13 in the Intel SDM[0]. Many of the offsets and sizes of the extended features are provided by cpu specific values. We can access these in Windows using the SDK, and transfer these to the saved extended context which in turn is understandable by windbg. Further information is available from AMD Ch. 18 "Shadow Stacks"[1]. [0] https://software.intel.com/content/www/us/en/develop/download/intel-64-and-ia-32-architectures-sdm-combined-volumes-1-2a-2b-2c-2d-3a-3b-3c-3d-and-4.html. [1] https://www.amd.com/system/files/TechDocs/24593.pdf Bug: 1250098 Change-Id: I4b13bcb023e9d5fba257044abfd7e251d66a9329 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3300992 Reviewed-by: Joshua Peraza <jperaza@chromium.org> Commit-Queue: Alex Gough <ajgo@chromium.org>
2022-05-16 15:38:37 -07:00
//! \brief Initializes CET fields of a CPUContextX86_64 structure from
//! an xsave location if |context| flags support cet_u values.
void InitializeX64XStateCet(const CONTEXT* context,
XSAVE_CET_U_FORMAT* cet_u,
CPUContextX86_64* out);
//! \brief Wraps GetXStateEnabledFeatures(), returns true if the specified set
//! of flags are all supported.
bool IsXStateFeatureEnabled(DWORD64 feature);
#endif // ARCH_CPU_X86_64
#if defined(ARCH_CPU_ARM64) || DOXYGEN
//! \brief Initializes a CPUContextARM64 structure from a native context
//! structure on Windows.
void InitializeARM64Context(const CONTEXT* context, CPUContextARM64* out);
#endif // ARCH_CPU_ARM64
} // namespace crashpad
#endif // CRASHPAD_SNAPSHOT_WIN_CPU_CONTEXT_WIN_H_