Skip to main content

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 LoadFirmwareRequest: the host rejected it with a
58/// non-success status.
59#[derive(Debug, Error)]
60#[error("load firmware error: {0:?}")]
61pub struct LoadFirmwareError(pub(crate) get_protocol::LoadFirmwareStatus);
62
63/// Error while invoking a GuestStateProtectionByIdRequest
64#[derive(Debug, Error)]
65#[error("malformed response - reported len > actual len: {0} > {1}")]
66pub struct GuestStateProtectionByIdError(pub(crate) u32, pub(crate) u32);
67
68/// Error while performing save/restore operation
69#[derive(Debug, Error)]
70#[error("host rejected save/restore operation")]
71#[non_exhaustive]
72pub struct SaveRestoreOperationFailure {}
73
74/// Error while invoking an IgvmAttestRequest
75#[expect(missing_docs)] // self-explanatory fields
76#[derive(Debug, Error, MeshPayload)]
77pub enum IgvmAttestError {
78    #[error("`agent_data` size {input_size} was larger than expected {expected_size}")]
79    InvalidAgentDataSize {
80        input_size: usize,
81        expected_size: usize,
82    },
83    #[error("`report` size {input_size} was larger than expected {expected_size}")]
84    InvalidReportSize {
85        input_size: usize,
86        expected_size: usize,
87    },
88    #[error("IGVM agent returned an error")]
89    IgvmAgentGenericError,
90}
91
92pub(crate) trait TryIntoProtocolBool {
93    fn into_bool(self) -> Result<bool, InvalidProtocolBool>;
94}
95
96impl TryIntoProtocolBool for get_protocol::ProtocolBool {
97    fn into_bool(self) -> Result<bool, InvalidProtocolBool> {
98        match self.0 {
99            0 => Ok(false),
100            1 => Ok(true),
101            _ => Err(InvalidProtocolBool(self.0)),
102        }
103    }
104}