blob: 8f346760375258b2d033fde663cdcd2ccb85e1a7 [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};
19use hyp::mmio_guard::Error as MmioError;
20
21pub type Result<T> = result::Result<T, Error>;
22
23#[derive(Clone, Debug)]
24pub enum Error {
25 /// MMIO guard failed.
26 MmioGuard(MmioError),
27 /// 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 {
36 Self::MmioGuard(e) => write!(f, "MMIO guard failed: {e}."),
37 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
45impl From<MmioError> for Error {
46 fn from(e: MmioError) -> Self {
47 Self::MmioGuard(e)
48 }
49}
50
51impl From<MapError> for Error {
52 fn from(e: MapError) -> Self {
53 Self::PageTableMapping(e)
54 }
55}