Skip to main content

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