summary refs log tree commit diff
path: root/x86_64
diff options
context:
space:
mode:
authorSonny Rao <sonnyrao@chromium.org>2018-03-12 18:00:21 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-03-14 11:55:56 -0700
commit8f73ccc45d0db10c7769f046fd99889cd9a8230d (patch)
tree83680a2cec106d2673288834b4d5a83582e26b03 /x86_64
parent657c1850abc49c81435db03c845a4b8b77dcf288 (diff)
downloadcrosvm-8f73ccc45d0db10c7769f046fd99889cd9a8230d.tar
crosvm-8f73ccc45d0db10c7769f046fd99889cd9a8230d.tar.gz
crosvm-8f73ccc45d0db10c7769f046fd99889cd9a8230d.tar.bz2
crosvm-8f73ccc45d0db10c7769f046fd99889cd9a8230d.tar.lz
crosvm-8f73ccc45d0db10c7769f046fd99889cd9a8230d.tar.xz
crosvm-8f73ccc45d0db10c7769f046fd99889cd9a8230d.tar.zst
crosvm-8f73ccc45d0db10c7769f046fd99889cd9a8230d.zip
x86_64: implement error trait
This is useful for describing errors that we pass up.

BUG=chromium:797868
TEST=build_tests passes on all architectures
TEST=crosvm runs on caroline

Change-Id: Ied456015e74830d3f1f465fca1151682c9148eb5
Reviewed-on: https://chromium-review.googlesource.com/961603
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'x86_64')
-rw-r--r--x86_64/src/lib.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/x86_64/src/lib.rs b/x86_64/src/lib.rs
index 473550e..3eae049 100644
--- a/x86_64/src/lib.rs
+++ b/x86_64/src/lib.rs
@@ -59,6 +59,8 @@ mod regs;
 
 use std::mem;
 use std::result;
+use std::error::{self, Error as X86Error};
+use std::fmt::{self, Display};
 use std::fs::File;
 use std::ffi::CStr;
 use std::sync::{Arc, Mutex};
@@ -106,6 +108,44 @@ pub enum Error {
     /// Invalid e820 setup params.
     E820Configuration,
 }
+
+impl error::Error for Error {
+    fn description(&self) -> &str {
+        match self {
+            &Error::ConfigureSystem => "Error configuring the system",
+            &Error::CpuSetup(_) => "Error configuring the VCPU",
+            &Error::CloneEventFd(_) => "Unable to clone an EventFd",
+            &Error::CreateEventFd(_) => "Unable to make an EventFd",
+            &Error::KernelOffsetPastEnd =>
+                "The kernel extends past the end of RAM",
+            &Error::RegisterConfiguration(_) =>
+                "Error configuring the VCPU registers",
+            &Error::FpuRegisterConfiguration(_) =>
+                "Error configuring the VCPU floating point registers",
+            &Error::RegisterIrqfd(_) => "Error registering an IrqFd",
+            &Error::SegmentRegisterConfiguration(_) =>
+                "Error configuring the VCPU segment registers",
+            &Error::LoadCmdline(_) => "Error Loading command line",
+            &Error::LoadKernel(_) => "Error Loading Kernel",
+            &Error::LocalIntConfiguration(_) =>
+                "Error configuring the VCPU local interrupt",
+            &Error::MpTableSetup(_) =>
+                "Error writing MP table to memory",
+            &Error::ZeroPageSetup =>
+                "Error writing the zero page of guest memory",
+            &Error::ZeroPagePastRamEnd =>
+                "The zero page extends past the end of guest_mem",
+            &Error::E820Configuration => "Invalid e820 setup params",
+        }
+    }
+}
+
+impl Display for Error {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "X86 Arch Error: {}", Error::description(self))
+    }
+}
+
 pub type Result<T> = result::Result<T, Error>;
 
 const BOOT_STACK_POINTER: u64 = 0x8000;