microsoft/openvmm
Publicmirrored fromhttps://github.com/microsoft/openvmmAvailable
guest_test_uefi/src/uefi/rt.rs
32lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | //! Runtime support for the UEFI application environment. |
| 5 | |
| 6 | #![cfg(target_os = "uefi")] |
| 7 | // UNSAFETY: Raw assembly needed for panic handling to abort. |
| 8 | #![expect(unsafe_code)] |
| 9 | |
| 10 | #[panic_handler] |
| 11 | fn panic_handler(panic: &core::panic::PanicInfo<'_>) -> ! { |
| 12 | use uefi::println; |
| 13 | |
| 14 | println!("{}", panic); |
| 15 | |
| 16 | // If the system table is available, use UEFI's standard shutdown mechanism |
| 17 | if uefi::table::system_table_raw().is_none() { |
| 18 | use uefi::runtime::ResetType; |
| 19 | uefi::runtime::reset(ResetType::SHUTDOWN, uefi::Status::ABORTED, None); |
| 20 | } |
| 21 | |
| 22 | println!("Could not shut down... falling back to invoking an undefined instruction"); |
| 23 | |
| 24 | // SAFETY: the undefined instruction trap handler in `guest_test_uefi` will not return |
| 25 | unsafe { |
| 26 | #[cfg(target_arch = "x86_64")] |
| 27 | core::arch::asm!("ud2"); |
| 28 | #[cfg(target_arch = "aarch64")] |
| 29 | core::arch::asm!("brk #0"); |
| 30 | core::hint::unreachable_unchecked(); |
| 31 | } |
| 32 | } |
| 33 | |