From e492d9c70ad387fa612c1f9a13048acb651a00fb Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Tue, 28 Mar 2023 20:14:33 +0530 Subject: [PATCH] Fixes from PR - Some comment fixes. - Make some functions unsafe. - Make helpers module private. - Rebase on master - Update r-efi to v4.2.0 Signed-off-by: Ayush Singh --- .nlsp-settings/rust_analyzer.json | 3 --- Cargo.lock | 4 ++-- library/std/Cargo.toml | 2 +- library/std/src/os/uefi/env.rs | 2 +- library/std/src/sys/uefi/helpers.rs | 4 +++- library/std/src/sys/uefi/mod.rs | 6 +++--- src/doc/rustc/src/platform-support/unknown-uefi.md | 2 +- 7 files changed, 11 insertions(+), 12 deletions(-) delete mode 100644 .nlsp-settings/rust_analyzer.json diff --git a/.nlsp-settings/rust_analyzer.json b/.nlsp-settings/rust_analyzer.json deleted file mode 100644 index eddf84afb2a3d..0000000000000 --- a/.nlsp-settings/rust_analyzer.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "rust-analyzer.cargo.target": "x86_64-unknown-uefi" -} diff --git a/Cargo.lock b/Cargo.lock index f84387f30be61..a2025e58a8d1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3008,9 +3008,9 @@ dependencies = [ [[package]] name = "r-efi" -version = "4.1.0" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e7345c622833c6745e7b027a28aa95618813dc1f3c3de396206410267dce6f3" +checksum = "575fc2d9b3da54adbdfaddf6eca48fec256d977c8630a1750b8991347d1ac911" dependencies = [ "compiler_builtins", "rustc-std-workspace-core", diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index 1908dfaa33db0..965132bdedb91 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -49,7 +49,7 @@ hermit-abi = { version = "0.3.2", features = ['rustc-dep-of-std'], public = true wasi = { version = "0.11.0", features = ['rustc-dep-of-std'], default-features = false } [target.'cfg(target_os = "uefi")'.dependencies] -r-efi = { version = "4.1.0", features = ['rustc-dep-of-std', 'efiapi']} +r-efi = { version = "4.2.0", features = ['rustc-dep-of-std']} r-efi-alloc = { version = "1.0.0", features = ['rustc-dep-of-std']} [features] diff --git a/library/std/src/os/uefi/env.rs b/library/std/src/os/uefi/env.rs index 41dc7ccdb6ade..4dd090e22c620 100644 --- a/library/std/src/os/uefi/env.rs +++ b/library/std/src/os/uefi/env.rs @@ -66,7 +66,7 @@ pub(crate) fn try_system_table() -> Option> { } /// Get the SystemHandle Pointer. -/// This function is mostly intended for places where panic is not an option +/// This function is mostly intended for places where panicking is not an option pub(crate) fn try_image_handle() -> Option> { GLOBALS.get().map(|x| x.1) } diff --git a/library/std/src/sys/uefi/helpers.rs b/library/std/src/sys/uefi/helpers.rs index 2108484a40c3d..ea1c68a90ef83 100644 --- a/library/std/src/sys/uefi/helpers.rs +++ b/library/std/src/sys/uefi/helpers.rs @@ -295,7 +295,9 @@ pub(crate) fn create_event( } } -pub(crate) fn close_event(evt: NonNull) -> io::Result<()> { +/// # SAFETY +/// - The supplied event must be valid +pub(crate) unsafe fn close_event(evt: NonNull) -> io::Result<()> { let boot_services: NonNull = boot_services().ok_or(BOOT_SERVICES_UNAVAILABLE)?.cast(); let r = unsafe { diff --git a/library/std/src/sys/uefi/mod.rs b/library/std/src/sys/uefi/mod.rs index 6fd2c5f21cb4e..27f76f04c05aa 100644 --- a/library/std/src/sys/uefi/mod.rs +++ b/library/std/src/sys/uefi/mod.rs @@ -47,7 +47,7 @@ pub mod thread_local_key; #[path = "../unsupported/time.rs"] pub mod time; -pub(crate) mod helpers; +mod helpers; #[cfg(test)] mod tests; @@ -96,7 +96,7 @@ pub(crate) unsafe fn init(argc: isize, argv: *const *const u8, _sigpipe: u8) { /// - must be called only once during runtime cleanup. pub unsafe fn cleanup() { if let Some(exit_boot_service_event) = EXIT_BOOT_SERVICE_EVENT.take() { - let _ = helpers::close_event(exit_boot_service_event); + let _ = unsafe { helpers::close_event(exit_boot_service_event) }; } } @@ -123,7 +123,7 @@ pub fn decode_error_kind(code: i32) -> crate::io::ErrorKind { pub fn abort_internal() -> ! { if let Some(exit_boot_service_event) = EXIT_BOOT_SERVICE_EVENT.take() { - let _ = helpers::close_event(exit_boot_service_event); + let _ = unsafe { helpers::close_event(exit_boot_service_event) }; } if let (Some(boot_services), Some(handle)) = diff --git a/src/doc/rustc/src/platform-support/unknown-uefi.md b/src/doc/rustc/src/platform-support/unknown-uefi.md index e2c09d67bedab..019f030eb1c10 100644 --- a/src/doc/rustc/src/platform-support/unknown-uefi.md +++ b/src/doc/rustc/src/platform-support/unknown-uefi.md @@ -300,4 +300,4 @@ pub fn main() { ### BootServices The current implementation of std make `BootServices` unavailable once `ExitBootServices` is called. Refer to [Runtime Drivers](https://edk2-docs.gitbook.io/edk-ii-uefi-driver-writer-s-guide/7_driver_entry_point/711_runtime_drivers) for more information regarding how to handle switching from using physical addresses to using virtual addresses. -Note: It should be noted that it is upto the user to drop all allocated memory before `ExitBootServices` is called. +Note: It should be noted that it is upto the user to drop all allocated memory before `ExitBootServices` is called.