guest_emulation_transport/
error.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Error-types associated with various GET client methods.
5
6use mesh::MeshPayload;
7use thiserror::Error;
8
9/// Error while issuing VMGS IO over the GET
10#[derive(Debug, Error)]
11#[error("vmgs io error: {0:?}")]
12pub struct VmgsIoError(pub(crate) get_protocol::VmgsIoStatus);
13
14/// Error while fetching Device Platform Settings
15#[expect(missing_docs)] // self-explanatory fields
16#[derive(Debug, Error)]
17pub enum DevicePlatformSettingsError {
18    #[error("unknown secure boot template type: {0:?}")]
19    UnknownSecureBootTemplateType(get_protocol::SecureBootTemplateType),
20    #[error("invalid console mode (must be 0b00..=0b11): {}", 0.0)]
21    InvalidConsoleMode(get_protocol::UefiConsoleMode),
22    #[error("invalid memory protection mode (must be 0b00..=0b11): {0}")]
23    InvalidMemoryProtectionMode(u8),
24    #[error("could not parse DPSv2 JSON")]
25    BadJson(#[source] serde_json::Error),
26    #[error("could not parse embedded VTL2 settings data")]
27    BadVtl2Settings(#[source] underhill_config::schema::ParseError),
28    #[error("invalid legacy bool representation ({0:?})")]
29    InvalidProtocolBool(#[from] InvalidProtocolBool),
30}
31
32/// Encountered GET Protocol bool with an invalid representation (not 0 or 1)
33#[derive(Debug, Error)]
34#[error("expected 0 or 1, found {0}")]
35pub struct InvalidProtocolBool(pub(crate) u8);
36
37/// Error while mapping framebuffer
38#[derive(Debug, Error)]
39#[error("map framebuffer error: {0:?}")]
40pub struct MapFramebufferError(pub(crate) get_protocol::MapFramebufferStatus);
41
42/// Error while unmapping framebuffer
43#[derive(Debug, Error)]
44#[error("unmap framebuffer error: {0:?}")]
45pub struct UnmapFramebufferError(pub(crate) get_protocol::UnmapFramebufferStatus);
46
47/// Error while performing a VPCI operation
48#[derive(Debug, Error)]
49#[error("vpci operation error: {0:?}")]
50pub struct VpciControlError(pub(crate) get_protocol::VpciDeviceControlStatus);
51
52/// Error while invoking a CreateRamGpaRangeRequest
53#[derive(Debug, Error)]
54#[error("create ram GPA range error: {0:?}")]
55pub struct CreateRamGpaRangeError(pub(crate) get_protocol::CreateRamGpaRangeStatus);
56
57/// Error while invoking a GuestStateProtectionByIdRequest
58#[derive(Debug, Error)]
59#[error("malformed response - reported len > actual len: {0} > {1}")]
60pub struct GuestStateProtectionByIdError(pub(crate) u32, pub(crate) u32);
61
62/// Error while performing save/restore operation
63#[derive(Debug, Error)]
64#[error("host rejected save/restore operation")]
65#[non_exhaustive]
66pub struct SaveRestoreOperationFailure {}
67
68/// Error while invoking an IgvmAttestRequest
69#[expect(missing_docs)] // self-explanatory fields
70#[derive(Debug, Error, MeshPayload)]
71pub enum IgvmAttestError {
72    #[error("`agent_data` size {input_size} was larger than expected {expected_size}")]
73    InvalidAgentDataSize {
74        input_size: usize,
75        expected_size: usize,
76    },
77    #[error("`report` size {input_size} was larger than expected {expected_size}")]
78    InvalidReportSize {
79        input_size: usize,
80        expected_size: usize,
81    },
82    #[error("IGVM agent returned an error")]
83    IgvmAgentGenericError,
84}
85
86pub(crate) trait TryIntoProtocolBool {
87    fn into_bool(self) -> Result<bool, InvalidProtocolBool>;
88}
89
90impl TryIntoProtocolBool for get_protocol::ProtocolBool {
91    fn into_bool(self) -> Result<bool, InvalidProtocolBool> {
92        match self.0 {
93            0 => Ok(false),
94            1 => Ok(true),
95            _ => Err(InvalidProtocolBool(self.0)),
96        }
97    }
98}