get_protocol/
crash.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! This module defines the crash dump protocol.
5
6use bitfield_struct::bitfield;
7use guid::Guid;
8use zerocopy::FromBytes;
9use zerocopy::Immutable;
10use zerocopy::IntoBytes;
11use zerocopy::KnownLayout;
12use zerocopy::Unaligned;
13
14pub const CRASHDUMP_GUID: Guid = guid::guid!("427b03e7-4ceb-4286-b5fc-486f4a1dd439");
15
16/// Capabilities supported by the host crash dump services
17#[bitfield(u64)]
18#[derive(IntoBytes, FromBytes, Immutable, KnownLayout, PartialEq, Eq)]
19pub struct Capabilities {
20    pub windows_config_v1: bool,
21    pub linux_config_v1: bool,
22    #[bits(62)]
23    pub reserved: u64,
24}
25
26open_enum::open_enum! {
27    /// Dump types
28    #[derive(IntoBytes, FromBytes, Immutable, KnownLayout)]
29    pub enum DumpType: u32 {
30        NONE = 0x00000000,
31        ELF = 0x00000001,
32        KDUMP = 0x00000002,
33    }
34}
35
36/// Crash dump configuration.
37#[derive(Debug, Copy, Clone, PartialEq, Eq, IntoBytes, FromBytes, Immutable, KnownLayout)]
38#[repr(C, packed)]
39pub struct ConfigV1 {
40    pub max_dump_size: u64,
41    pub dump_type: DumpType,
42}
43
44/// Dump completion information
45#[derive(Debug, Copy, Clone, PartialEq, Eq, IntoBytes, FromBytes, Immutable, KnownLayout)]
46#[repr(C, packed)]
47pub struct CompletionInfoV1 {
48    pub major_version: u32,
49    pub minor_version: u32,
50    pub version_banner: [u8; 256],
51    pub vtl: u8,
52}
53
54//
55// Protocol messages are packaged in request/response packets
56// The format of these packets is defined below.
57//
58
59open_enum::open_enum! {
60    /// Message types
61    #[derive(IntoBytes, FromBytes, Immutable, KnownLayout)]
62    pub enum MessageType : u64 {
63        INVALID = 0, // The default invalid type
64
65        // Request Types
66        REQUEST_GET_CAPABILITIES_V1 = 0x00000001,
67        REQUEST_GET_WINDOWS_DUMP_CONFIG_V1 = 0x00000002,
68        REQUEST_WINDOWS_DUMP_START_V1 = 0x00000003,
69        REQUEST_WINDOWS_DUMP_WRITE_V1 = 0x00000004,
70        REQUEST_WINDOWS_DUMP_COMPLETE_V1 = 0x00000005,
71        REQUEST_GET_NIX_DUMP_CONFIG_V1 = 0x00000102,
72        REQUEST_NIX_DUMP_START_V1 = 0x00000103,
73        REQUEST_NIX_DUMP_WRITE_V1 = 0x00000104,
74        REQUEST_NIX_DUMP_COMPLETE_V1 = 0x00000105,
75
76        // Response Types
77        RESPONSE_GET_CAPABILITIES_V1 = 0x00010001,
78        RESPONSE_GET_WINDOWS_DUMP_CONFIG_V1 = 0x00010002,
79        RESPONSE_WINDOWS_DUMP_START_V1 = 0x00010003,
80        RESPONSE_WINDOWS_DUMP_WRITE_V1 = 0x00010004,
81        RESPONSE_WINDOWS_DUMP_COMPLETE_V1 = 0x00010005,
82        RESPONSE_GET_NIX_DUMP_CONFIG_V1 = 0x00010102,
83        RESPONSE_NIX_DUMP_START_V1 = 0x00010103,
84        RESPONSE_NIX_DUMP_WRITE_V1 = 0x00010104,
85        RESPONSE_NIX_DUMP_COMPLETE_V1 = 0x00010105,
86    }
87}
88
89/// Common message header for all requests and responses.
90#[derive(Debug, Copy, Clone, PartialEq, Eq, IntoBytes, FromBytes, Immutable, KnownLayout)]
91#[repr(C, packed)]
92pub struct Header {
93    /// Correlates messages across guest/host
94    pub activity_id: Guid,
95    pub message_type: MessageType,
96}
97
98/// Complete message payload for ResponseGetCapabilities_v1
99#[derive(Debug, Copy, Clone, PartialEq, Eq, IntoBytes, FromBytes, Immutable, KnownLayout)]
100#[repr(C, packed)]
101pub struct DumpCapabilitiesRequestV1 {
102    pub header: Header,
103}
104
105/// Complete message payload for ResponseGetCapabilities_v1
106#[derive(Debug, Copy, Clone, PartialEq, Eq, IntoBytes, FromBytes, Immutable, KnownLayout)]
107#[repr(C, packed)]
108pub struct DumpCapabilitiesResponseV1 {
109    pub header: Header,
110    pub capabilities: Capabilities,
111}
112
113/// Complete message payload for RequestGetNixDumpConfig_v1
114#[derive(Debug, Copy, Clone, PartialEq, Eq, IntoBytes, FromBytes, Immutable, KnownLayout)]
115#[repr(C, packed)]
116pub struct DumpConfigRequestV1 {
117    pub header: Header,
118}
119
120/// Complete message payload for ResponseGetNixDumpConfig_v1
121#[derive(Debug, Copy, Clone, PartialEq, Eq, IntoBytes, FromBytes, Immutable, KnownLayout)]
122#[repr(C, packed)]
123pub struct DumpConfigResponseV1 {
124    pub header: Header,
125    pub config: ConfigV1,
126}
127
128/// Complete message payload for RequestGetNixDumpConfig_v1
129#[derive(Debug, Copy, Clone, PartialEq, Eq, IntoBytes, FromBytes, Immutable, KnownLayout)]
130#[repr(C, packed)]
131pub struct DumpStartRequestV1 {
132    pub header: Header,
133}
134
135/// Complete message payload for ResponseGetNixDumpConfig_v1
136#[derive(Debug, Copy, Clone, PartialEq, Eq, IntoBytes, FromBytes, Immutable, KnownLayout)]
137#[repr(C, packed)]
138pub struct DumpStartResponseV1 {
139    pub header: Header,
140    /// HRESULT return by the host vdev.
141    pub status: i32,
142}
143
144/// Complete message payload for RequestNixDumpWrite_v1
145/// Data follows in a separate message with no headers.
146#[derive(
147    Debug, Copy, Clone, PartialEq, Eq, IntoBytes, FromBytes, Immutable, KnownLayout, Unaligned,
148)]
149#[repr(C, packed)]
150pub struct DumpWriteRequestV1 {
151    pub header: Header,
152    pub offset: u64,
153    pub size: u32,
154}
155
156/// Response to a RequestNixDumpWrite_v1
157/// A response is only sent if an error has occurred.
158#[derive(Debug, Copy, Clone, PartialEq, Eq, IntoBytes, FromBytes, Immutable, KnownLayout)]
159#[repr(C, packed)]
160pub struct DumpWriteResponseV1 {
161    pub header: Header,
162    /// HRESULT returned by the host vdev.
163    pub status: i32,
164}
165
166/// Completes a Nix crash dump
167#[derive(Debug, Copy, Clone, PartialEq, Eq, IntoBytes, FromBytes, Immutable, KnownLayout)]
168#[repr(C, packed)]
169pub struct DumpCompleteRequestV1 {
170    pub header: Header,
171    pub info: CompletionInfoV1,
172}