2019-12-30 23:04:13 +00:00
|
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
//
|
2022-01-15 20:50:11 +00:00
|
|
|
// Copyright (c) 2020-2022 Andre Richter <andre.o.richter@gmail.com>
|
2019-12-30 23:04:13 +00:00
|
|
|
|
2020-03-28 12:23:22 +00:00
|
|
|
//! Synchronous and asynchronous exception handling.
|
2019-12-30 23:04:13 +00:00
|
|
|
|
2020-03-28 12:23:22 +00:00
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
|
#[path = "_arch/aarch64/exception.rs"]
|
|
|
|
mod arch_exception;
|
2019-12-30 23:04:13 +00:00
|
|
|
|
2020-03-28 12:23:22 +00:00
|
|
|
pub mod asynchronous;
|
2019-12-30 23:04:13 +00:00
|
|
|
|
2021-01-23 21:43:59 +00:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
// Architectural Public Reexports
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
pub use arch_exception::{current_privilege_level, handling_init};
|
|
|
|
|
2020-03-28 12:23:22 +00:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
// Public Definitions
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/// Kernel privilege levels.
|
2019-12-30 23:04:13 +00:00
|
|
|
#[allow(missing_docs)]
|
|
|
|
#[derive(PartialEq)]
|
|
|
|
pub enum PrivilegeLevel {
|
|
|
|
User,
|
|
|
|
Kernel,
|
|
|
|
Hypervisor,
|
|
|
|
Unknown,
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
// Testing
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
use test_macros::kernel_test;
|
|
|
|
|
|
|
|
/// Libkernel unit tests must execute in kernel mode.
|
|
|
|
#[kernel_test]
|
|
|
|
fn test_runner_executes_in_kernel_mode() {
|
2020-03-28 12:23:22 +00:00
|
|
|
let (level, _) = current_privilege_level();
|
2019-12-30 23:04:13 +00:00
|
|
|
|
|
|
|
assert!(level == PrivilegeLevel::Kernel)
|
|
|
|
}
|
|
|
|
}
|