microsoft/openvmm

Public

mirrored fromhttps://github.com/microsoft/openvmmAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2633a52f553a8db6cbdcc8b968eeef579e15bf38

Branches

Tags

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

Clone

HTTPS

Download ZIP

guest_test_uefi/src/uefi/rt.rs

32lines · modepreview

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

//! Runtime support for the UEFI application environment.

#![cfg(target_os = "uefi")]
// UNSAFETY: Raw assembly needed for panic handling to abort.
#![expect(unsafe_code)]

#[panic_handler]
fn panic_handler(panic: &core::panic::PanicInfo<'_>) -> ! {
    use uefi::println;

    println!("{}", panic);

    // If the system table is available, use UEFI's standard shutdown mechanism
    if uefi::table::system_table_raw().is_none() {
        use uefi::runtime::ResetType;
        uefi::runtime::reset(ResetType::SHUTDOWN, uefi::Status::ABORTED, None);
    }

    println!("Could not shut down... falling back to invoking an undefined instruction");

    // SAFETY: the undefined instruction trap handler in `guest_test_uefi` will not return
    unsafe {
        #[cfg(target_arch = "x86_64")]
        core::arch::asm!("ud2");
        #[cfg(target_arch = "aarch64")]
        core::arch::asm!("brk #0");
        core::hint::unreachable_unchecked();
    }
}