From 2e4d8994d890c1b08d47bbe828fce465a44949b6 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Mon, 22 Jul 2024 16:44:21 -0400 Subject: [PATCH] runtime: Add uefi::runtime::reset No test added for this since our test runner isn't really set up for testing multiple resets. --- uefi/src/runtime.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/uefi/src/runtime.rs b/uefi/src/runtime.rs index 17b24a919..2ee16c7de 100644 --- a/uefi/src/runtime.rs +++ b/uefi/src/runtime.rs @@ -443,3 +443,27 @@ pub fn query_capsule_capabilities(capsule_header_array: &[&CapsuleHeader]) -> Re .to_result_with_val(|| info) } } + +/// Resets the computer. +/// +/// See [`ResetType`] for details of the various reset types. +/// +/// For a normal reset the value of `status` should be +/// [`Status::SUCCESS`]. Otherwise, an error code can be used. +/// +/// The `data` arg is usually `None`. Otherwise, it must contain a UCS-2 +/// null-terminated string followed by additional binary data. For +/// [`ResetType::PLATFORM_SPECIFIC`], the binary data must be a vendor-specific +/// [`Guid`] that indicates the type of reset to perform. +/// +/// This function never returns. +pub fn reset(reset_type: ResetType, status: Status, data: Option<&[u8]>) -> ! { + let rt = runtime_services_raw_panicking(); + let rt = unsafe { rt.as_ref() }; + + let (size, data) = data + .map(|data| (data.len(), data.as_ptr())) + .unwrap_or((0, ptr::null())); + + unsafe { (rt.reset_system)(reset_type, status, size, data) } +}