From a0f9a0b74d9ed0f4d8ecea6a13bbc9ed4da0e852 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sun, 12 Mar 2023 10:42:25 -0400 Subject: [PATCH 1/4] uefi: Drop lifetime param from Serial protocol This is better expressed with a raw pointer. --- uefi/src/proto/console/serial.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/uefi/src/proto/console/serial.rs b/uefi/src/proto/console/serial.rs index a17403d05..d6ba51f86 100644 --- a/uefi/src/proto/console/serial.rs +++ b/uefi/src/proto/console/serial.rs @@ -15,7 +15,7 @@ use bitflags::bitflags; /// check for input/output, some data might be lost. #[repr(C)] #[unsafe_protocol("bb25cf6f-f1d4-11d2-9a0c-0090273fc1fd")] -pub struct Serial<'boot> { +pub struct Serial { // Revision of this protocol, only 1.0 is currently defined. // Future versions will be backwards compatible. revision: u32, @@ -33,10 +33,10 @@ pub struct Serial<'boot> { get_control_bits: extern "efiapi" fn(&Serial, &mut ControlBits) -> Status, write: unsafe extern "efiapi" fn(&mut Serial, &mut usize, *const u8) -> Status, read: unsafe extern "efiapi" fn(&mut Serial, &mut usize, *mut u8) -> Status, - io_mode: &'boot IoMode, + io_mode: *const IoMode, } -impl<'boot> Serial<'boot> { +impl Serial { /// Reset the device. pub fn reset(&mut self) -> Result { (self.reset)(self).into() @@ -45,7 +45,7 @@ impl<'boot> Serial<'boot> { /// Returns the current I/O mode. #[must_use] pub const fn io_mode(&self) -> &IoMode { - self.io_mode + unsafe { &*self.io_mode } } /// Sets the device's new attributes. @@ -115,7 +115,7 @@ impl<'boot> Serial<'boot> { } } -impl<'boot> Write for Serial<'boot> { +impl Write for Serial { fn write_str(&mut self, s: &str) -> core::fmt::Result { self.write(s.as_bytes()).map_err(|_| core::fmt::Error) } From 57189e8d96b9611834d4b5ac62f9edb9a1569775 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sun, 12 Mar 2023 10:43:35 -0400 Subject: [PATCH 2/4] uefi: Drop lifetime param from Pointer protocol This is better expressed with a raw pointer. --- uefi/src/proto/console/pointer/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/uefi/src/proto/console/pointer/mod.rs b/uefi/src/proto/console/pointer/mod.rs index 0d0939fc9..b15549c80 100644 --- a/uefi/src/proto/console/pointer/mod.rs +++ b/uefi/src/proto/console/pointer/mod.rs @@ -7,14 +7,14 @@ use core::mem::MaybeUninit; /// Provides information about a pointer device. #[repr(C)] #[unsafe_protocol("31878c87-0b75-11d5-9a4f-0090273fc14d")] -pub struct Pointer<'boot> { +pub struct Pointer { reset: extern "efiapi" fn(this: &mut Pointer, ext_verif: bool) -> Status, get_state: extern "efiapi" fn(this: &Pointer, state: *mut PointerState) -> Status, wait_for_input: Event, - mode: &'boot PointerMode, + mode: *const PointerMode, } -impl<'boot> Pointer<'boot> { +impl Pointer { /// Resets the pointer device hardware. /// /// The `extended_verification` parameter is used to request that UEFI @@ -54,7 +54,7 @@ impl<'boot> Pointer<'boot> { /// Returns a reference to the pointer device information. #[must_use] pub const fn mode(&self) -> &PointerMode { - self.mode + unsafe { &*self.mode } } } From bbe6e0a16e6c4b537fc12464518edfa5c69a0a91 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sun, 12 Mar 2023 10:46:59 -0400 Subject: [PATCH 3/4] uefi: Drop lifetime param from GraphicsOutput protocol This is better expressed with a raw pointer. --- uefi/src/proto/console/gop.rs | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/uefi/src/proto/console/gop.rs b/uefi/src/proto/console/gop.rs index 14eacec93..1e8cc5e86 100644 --- a/uefi/src/proto/console/gop.rs +++ b/uefi/src/proto/console/gop.rs @@ -63,7 +63,7 @@ use core::ptr; /// and also allows the app to access the in-memory buffer. #[repr(C)] #[unsafe_protocol("9042a9de-23dc-4a38-96fb-7aded080516a")] -pub struct GraphicsOutput<'boot> { +pub struct GraphicsOutput { query_mode: extern "efiapi" fn( &GraphicsOutput, mode: u32, @@ -84,10 +84,10 @@ pub struct GraphicsOutput<'boot> { height: usize, stride: usize, ) -> Status, - mode: &'boot ModeData<'boot>, + mode: *const ModeData, } -impl<'boot> GraphicsOutput<'boot> { +impl GraphicsOutput { /// Returns information for an available graphics mode that the graphics /// device and the set of active video output devices supports. pub fn query_mode(&self, index: u32) -> Result { @@ -110,7 +110,7 @@ impl<'boot> GraphicsOutput<'boot> { ModeIter { gop: self, current: 0, - max: self.mode.max_mode, + max: self.mode().max_mode, } } @@ -293,17 +293,17 @@ impl<'boot> GraphicsOutput<'boot> { /// Returns the frame buffer information for the current mode. #[must_use] pub const fn current_mode_info(&self) -> ModeInfo { - *self.mode.info + *self.mode().info() } /// Access the frame buffer directly pub fn frame_buffer(&mut self) -> FrameBuffer { assert!( - self.mode.info.format != PixelFormat::BltOnly, + self.mode().info().format != PixelFormat::BltOnly, "Cannot access the framebuffer in a Blt-only mode" ); - let base = self.mode.fb_address as *mut u8; - let size = self.mode.fb_size; + let base = self.mode().fb_address as *mut u8; + let size = self.mode().fb_size; FrameBuffer { base, @@ -311,16 +311,20 @@ impl<'boot> GraphicsOutput<'boot> { _lifetime: PhantomData, } } + + const fn mode(&self) -> &ModeData { + unsafe { &*self.mode } + } } #[repr(C)] -struct ModeData<'info> { +struct ModeData { // Number of modes which the GOP supports. max_mode: u32, // Current mode. mode: u32, // Information about the current mode. - info: &'info ModeInfo, + info: *const ModeInfo, // Size of the above structure. info_sz: usize, // Physical address of the frame buffer. @@ -329,6 +333,12 @@ struct ModeData<'info> { fb_size: usize, } +impl ModeData { + const fn info(&self) -> &ModeInfo { + unsafe { &*self.info } + } +} + /// Represents the format of the pixels in a frame buffer. #[derive(Debug, Copy, Clone, Eq, PartialEq)] #[repr(u32)] @@ -436,7 +446,7 @@ impl ModeInfo { /// Iterator for [`Mode`]s of the [`GraphicsOutput`] protocol. pub struct ModeIter<'gop> { - gop: &'gop GraphicsOutput<'gop>, + gop: &'gop GraphicsOutput, current: u32, max: u32, } From b93045094c702b2727b573706ab17dd911af955f Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sun, 12 Mar 2023 10:49:06 -0400 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ebd13efb..0e89ea091 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,8 @@ - `HandleBuffer` and `ProtocolsPerHandle` now implement `Deref`. The `HandleBuffer::handles` and `ProtocolsPerHandle::protocols` methods have been deprecated. -- Removed `'boot` lifetime from the `Output` protocol. +- Removed `'boot` lifetime from the `GraphicsOutput`, `Output`, `Pointer`, and + `Serial` protocols. - The generic type `Data` of `uefi::Error` doesn't need to be `Display` to be compatible with `core::error::Error`. Note that the error Trait requires the `unstable` feature.