blob: 754e5547b033b2576d92fc8c309021151fab6d48 [file] [log] [blame]
Alice Wang9a8b39f2023-04-12 15:31:48 +00001// Copyright 2022, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! This module contains the error thrown by Rialto.
16
17use aarch64_paging::MapError;
18use core::{fmt, result};
Alice Wang90e6f162023-04-17 13:49:45 +000019use hyp::Error as HypervisorError;
Alice Wang9a8b39f2023-04-12 15:31:48 +000020
21pub type Result<T> = result::Result<T, Error>;
22
23#[derive(Clone, Debug)]
24pub enum Error {
Alice Wang90e6f162023-04-17 13:49:45 +000025 /// Hypervisor error.
26 Hypervisor(HypervisorError),
Alice Wang9a8b39f2023-04-12 15:31:48 +000027 /// Failed when attempting to map some range in the page table.
28 PageTableMapping(MapError),
29 /// Failed to initialize the logger.
30 LoggerInit,
31}
32
33impl fmt::Display for Error {
34 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
35 match self {
Alice Wang90e6f162023-04-17 13:49:45 +000036 Self::Hypervisor(e) => write!(f, "MMIO guard failed: {e}."),
Alice Wang9a8b39f2023-04-12 15:31:48 +000037 Self::PageTableMapping(e) => {
38 write!(f, "Failed when attempting to map some range in the page table: {e}.")
39 }
40 Self::LoggerInit => write!(f, "Failed to initialize the logger."),
41 }
42 }
43}
44
Alice Wang90e6f162023-04-17 13:49:45 +000045impl From<HypervisorError> for Error {
46 fn from(e: HypervisorError) -> Self {
47 Self::Hypervisor(e)
Alice Wang9a8b39f2023-04-12 15:31:48 +000048 }
49}
50
51impl From<MapError> for Error {
52 fn from(e: MapError) -> Self {
53 Self::PageTableMapping(e)
54 }
55}