use alloc::string::String;
use crate::HyperCallCode;
pub type HyperCallResult<T = usize> = Result<T, HyperCallError>;
#[derive(Clone, Copy, Debug, Eq, PartialEq, thiserror::Error)]
#[error("invalid hypercall code: {0:#x}")]
pub struct InvalidHyperCallCode(
pub u32,
);
#[derive(Clone, Debug, Eq, PartialEq, thiserror::Error)]
pub enum HyperCallError {
#[error(transparent)]
InvalidCode(#[from] InvalidHyperCallCode),
#[error("hypercall {code:?} is unsupported: {detail}")]
Unsupported {
code: HyperCallCode,
detail: String,
},
#[error("hypercall {code:?} received invalid parameter {parameter}: {detail}")]
InvalidParameter {
code: HyperCallCode,
parameter: &'static str,
detail: String,
},
#[error("hypercall {code:?} cannot run in the current state: {detail}")]
InvalidState {
code: HyperCallCode,
detail: String,
},
#[error("hypercall {code:?} could not find resource {resource}: {detail}")]
ResourceNotFound {
code: HyperCallCode,
resource: String,
detail: String,
},
#[error("hypercall {code:?} resource conflict for {resource}: {detail}")]
ResourceConflict {
code: HyperCallCode,
resource: String,
detail: String,
},
#[error("hypercall {code:?} ran out of memory while {operation}")]
OutOfMemory {
code: HyperCallCode,
operation: &'static str,
},
#[error("hypercall {code:?} failed to {operation} at guest address {address:#x}: {detail}")]
GuestMemoryAccess {
code: HyperCallCode,
operation: &'static str,
address: usize,
detail: String,
},
#[error("hypercall {code:?} internal operation {operation} failed: {detail}")]
Internal {
code: HyperCallCode,
operation: &'static str,
detail: String,
},
}