microsoft/mu_feature_ffa

Public

mirrored from https://github.com/microsoft/mu_feature_ffaAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.1.7

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

FfaFeaturePkg/SecurePartitions/MsSecurePartitionRust/src/baremetal/panic.rs

58lines · modeblame

aa115865kuqin1210 months ago1//! A panic handler that infinitely waits.
2use core::panic::PanicInfo;
3
4use aarch64_cpu::asm;
5use log::error;
6
7/// Stop immediately if called a second time.
8///
9/// # Note
10///
11/// Using atomics here relieves us from needing to use `unsafe` for the static variable.
12///
13/// On `AArch64`, which is the only implemented architecture at the time of writing this,
14/// [`AtomicBool::load`] and [`AtomicBool::store`] are lowered to ordinary load and store
15/// instructions. They are therefore safe to use even with MMU + caching deactivated.
16///
17/// [`AtomicBool::load`]: core::sync::atomic::AtomicBool::load
18/// [`AtomicBool::store`]: core::sync::atomic::AtomicBool::store
19fn panic_prevent_reenter() {
20use core::sync::atomic::{AtomicBool, Ordering};
21
22static PANIC_IN_PROGRESS: AtomicBool = AtomicBool::new(false);
23
24if !PANIC_IN_PROGRESS.load(Ordering::Relaxed) {
25PANIC_IN_PROGRESS.store(true, Ordering::Relaxed);
26
27return;
28}
29
30loop {
31asm::wfe()
32}
33}
34
35#[panic_handler]
36fn panic(info: &PanicInfo) -> ! {
37// Protect against panic infinite loops if any of the following code panics itself.
38panic_prevent_reenter();
39
40let (location, line, column) = match info.location() {
41Some(loc) => (loc.file(), loc.line(), loc.column()),
42_ => ("???", 0, 0),
43};
44
45error!(
46"Kernel panic!\n\n\
47Panic location:\n File '{}', line {}, column {}\n\n\
48{}",
49location,
50line,
51column,
52info.message(),
53);
54
55loop {
56asm::wfe()
57}
58}