Use thiserror in pVM firmware.
Test: m pvmfw
Change-Id: Ib98435fadff21754166b9187941a3e2d265082e6
diff --git a/libs/libhypervisor_backends/Android.bp b/libs/libhypervisor_backends/Android.bp
index b001b8f..27e3fe5 100644
--- a/libs/libhypervisor_backends/Android.bp
+++ b/libs/libhypervisor_backends/Android.bp
@@ -14,6 +14,7 @@
rustlibs: [
"libonce_cell_nostd",
"libsmccc",
+ "libthiserror_nostd",
"libuuid_nostd",
],
enabled: false,
diff --git a/libs/libhypervisor_backends/rules.mk b/libs/libhypervisor_backends/rules.mk
index 6fc9dea..1a48773 100644
--- a/libs/libhypervisor_backends/rules.mk
+++ b/libs/libhypervisor_backends/rules.mk
@@ -8,6 +8,7 @@
trusty/user/base/lib/liballoc-rust \
$(call FIND_CRATE,once_cell) \
$(call FIND_CRATE,smccc) \
+ $(call FIND_CRATE,thiserror) \
$(call FIND_CRATE,uuid) \
include make/library.mk
\ No newline at end of file
diff --git a/libs/libhypervisor_backends/src/hypervisor/geniezone.rs b/libs/libhypervisor_backends/src/hypervisor/geniezone.rs
index fe56528..76e010b 100644
--- a/libs/libhypervisor_backends/src/hypervisor/geniezone.rs
+++ b/libs/libhypervisor_backends/src/hypervisor/geniezone.rs
@@ -14,8 +14,6 @@
//! Wrappers around calls to the GenieZone hypervisor.
-use core::fmt::{self, Display, Formatter};
-
use super::{Hypervisor, MemSharingHypervisor, MmioGuardedHypervisor};
use crate::{mem::page_4kb_of, Error, Result};
@@ -23,6 +21,7 @@
error::{positive_or_error_64, success_or_error_64},
hvc64,
};
+use thiserror::Error;
use uuid::{uuid, Uuid};
pub(super) struct GeniezoneHypervisor;
@@ -44,15 +43,19 @@
}
/// Error from a GenieZone HVC call.
-#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+#[derive(Copy, Clone, Debug, Eq, Error, PartialEq)]
pub enum GeniezoneError {
/// The call is not supported by the implementation.
+ #[error("GenieZone call not supported")]
NotSupported,
/// The call is not required to implement.
+ #[error("GenieZone call not required")]
NotRequired,
/// One of the call parameters has a invalid value.
+ #[error("GenieZone call received invalid value")]
InvalidParameter,
/// There was an unexpected return value.
+ #[error("Unknown return value from GenieZone {0} ({0:#x})")]
Unknown(i64),
}
@@ -73,17 +76,6 @@
}
}
-impl Display for GeniezoneError {
- fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- match self {
- Self::NotSupported => write!(f, "GenieZone call not supported"),
- Self::NotRequired => write!(f, "GenieZone call not required"),
- Self::InvalidParameter => write!(f, "GenieZone call received invalid value"),
- Self::Unknown(e) => write!(f, "Unknown return value from GenieZone {} ({0:#x})", e),
- }
- }
-}
-
impl Hypervisor for GeniezoneHypervisor {
fn as_mmio_guard(&self) -> Option<&dyn MmioGuardedHypervisor> {
Some(self)
diff --git a/libs/libhypervisor_backends/src/hypervisor/kvm.rs b/libs/libhypervisor_backends/src/hypervisor/kvm.rs
index e18c1f4..233097b 100644
--- a/libs/libhypervisor_backends/src/hypervisor/kvm.rs
+++ b/libs/libhypervisor_backends/src/hypervisor/kvm.rs
@@ -14,8 +14,6 @@
//! Wrappers around calls to the KVM hypervisor.
-use core::fmt::{self, Display, Formatter};
-
use super::{DeviceAssigningHypervisor, Hypervisor, MemSharingHypervisor, MmioGuardedHypervisor};
use crate::{mem::page_4kb_of, Error, Result};
@@ -23,16 +21,20 @@
error::{positive_or_error_64, success_or_error_32, success_or_error_64},
hvc64,
};
+use thiserror::Error;
use uuid::{uuid, Uuid};
/// Error from a KVM HVC call.
-#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+#[derive(Copy, Clone, Debug, Eq, Error, PartialEq)]
pub enum KvmError {
/// The call is not supported by the implementation.
+ #[error("KVM call not supported")]
NotSupported,
/// One of the call parameters has a non-supported value.
+ #[error("KVM call received non-supported value")]
InvalidParameter,
/// There was an unexpected return value.
+ #[error("Unknown return value from KVM {0} ({0:#x})")]
Unknown(i64),
}
@@ -52,16 +54,6 @@
}
}
-impl Display for KvmError {
- fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- match self {
- Self::NotSupported => write!(f, "KVM call not supported"),
- Self::InvalidParameter => write!(f, "KVM call received non-supported value"),
- Self::Unknown(e) => write!(f, "Unknown return value from KVM {} ({0:#x})", e),
- }
- }
-}
-
const ARM_SMCCC_KVM_FUNC_HYP_MEMINFO: u32 = 0xc6000002;
const ARM_SMCCC_KVM_FUNC_MEM_SHARE: u32 = 0xc6000003;
const ARM_SMCCC_KVM_FUNC_MEM_UNSHARE: u32 = 0xc6000004;