From 69d3da294031758314c4b4b5708dbf71b74b31d1 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sun, 29 Oct 2023 11:10:10 -0400 Subject: [PATCH] Use const interface pointers in protocol management functions A protocol's interface may mutate itself, but the void pointer passed to the `{install,reinstall,uninstall}_protocol_interface` functions is opaque to the firmware, so there's no need for it to be a mut pointer. Note that from a Rust safety perspective there's no difference here -- mut and const pointers are interchangeable. https://github.com/rust-osdev/uefi-rs/issues/970 --- CHANGELOG.md | 5 +++++ uefi-raw/src/table/boot.rs | 8 ++++---- uefi/src/table/boot.rs | 8 ++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 049a9e12b..bb09fac2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,11 +16,16 @@ `Logger::set_output` to enable it. - `uefi::allocator::init` now takes a `&mut SystemTable` instead of `&BootServices`. +- `BootServices::{install,reinstall,uninstall}_protocol_interface` now take + `const` interface pointers. ## uefi-macros - [Unreleased] ## uefi-raw - [Unreleased] +### Changed +- `{install,reinstall,uninstall}_protocol_interface` now take `const` interface pointers. + ## uefi-services - [Unreleased] ### Changed diff --git a/uefi-raw/src/table/boot.rs b/uefi-raw/src/table/boot.rs index 02d8a52e9..ad5b0e7f7 100644 --- a/uefi-raw/src/table/boot.rs +++ b/uefi-raw/src/table/boot.rs @@ -61,18 +61,18 @@ pub struct BootServices { handle: *mut Handle, guid: *const Guid, interface_type: InterfaceType, - interface: *mut c_void, + interface: *const c_void, ) -> Status, pub reinstall_protocol_interface: unsafe extern "efiapi" fn( handle: Handle, protocol: *const Guid, - old_interface: *mut c_void, - new_interface: *mut c_void, + old_interface: *const c_void, + new_interface: *const c_void, ) -> Status, pub uninstall_protocol_interface: unsafe extern "efiapi" fn( handle: Handle, protocol: *const Guid, - interface: *mut c_void, + interface: *const c_void, ) -> Status, pub handle_protocol: unsafe extern "efiapi" fn( handle: Handle, diff --git a/uefi/src/table/boot.rs b/uefi/src/table/boot.rs index 2fe88032f..19f6d9f73 100644 --- a/uefi/src/table/boot.rs +++ b/uefi/src/table/boot.rs @@ -559,7 +559,7 @@ impl BootServices { &self, handle: Option, protocol: &Guid, - interface: *mut c_void, + interface: *const c_void, ) -> Result { let mut handle = Handle::opt_to_ptr(handle); ((self.0.install_protocol_interface)( @@ -594,8 +594,8 @@ impl BootServices { &self, handle: Handle, protocol: &Guid, - old_interface: *mut c_void, - new_interface: *mut c_void, + old_interface: *const c_void, + new_interface: *const c_void, ) -> Result<()> { (self.0.reinstall_protocol_interface)( handle.as_ptr(), @@ -629,7 +629,7 @@ impl BootServices { &self, handle: Handle, protocol: &Guid, - interface: *mut c_void, + interface: *const c_void, ) -> Result<()> { (self.0.uninstall_protocol_interface)(handle.as_ptr(), protocol, interface).to_result() }