Skip to content

Commit

Permalink
uefi: Replace manual Debug impls with derives
Browse files Browse the repository at this point in the history
Note that this requires rust>=1.70 for deriving `Debug` on `efiapi` function
pointers.
  • Loading branch information
nicholasbishop committed Jul 15, 2023
1 parent bc5dbc1 commit a5c2849
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 190 deletions.
34 changes: 1 addition & 33 deletions uefi/src/proto/console/text/output.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::proto::unsafe_protocol;
use crate::{CStr16, Result, ResultExt, Status, StatusExt};
use core::fmt;
use core::fmt::{Debug, Formatter};
use uefi_raw::protocol::console::{SimpleTextOutputMode, SimpleTextOutputProtocol};

/// Interface for text-based output devices.
Expand All @@ -21,6 +20,7 @@ use uefi_raw::protocol::console::{SimpleTextOutputMode, SimpleTextOutputProtocol
/// [`SystemTable::stdout`]: crate::table::SystemTable::stdout
/// [`SystemTable::stderr`]: crate::table::SystemTable::stderr
/// [`BootServices`]: crate::table::boot::BootServices#accessing-protocols
#[derive(Debug)]
#[repr(transparent)]
#[unsafe_protocol(SimpleTextOutputProtocol::GUID)]
pub struct Output(SimpleTextOutputProtocol);
Expand Down Expand Up @@ -217,38 +217,6 @@ impl fmt::Write for Output {
}
}

impl Debug for Output {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("Output")
.field("reset (fn ptr)", &(self.0.reset as *const u64))
.field(
"output_string (fn ptr)",
&(self.0.output_string as *const u64),
)
.field("test_string (fn ptr)", &(self.0.test_string as *const u64))
.field("query_mode (fn ptr)", &(self.0.query_mode as *const u64))
.field("set_mode (fn ptr)", &(self.0.set_mode as *const u64))
.field(
"set_attribute (fn ptr)",
&(self.0.set_attribute as *const u64),
)
.field(
"clear_screen (fn ptr)",
&(self.0.clear_screen as *const u64),
)
.field(
"set_cursor_position (fn ptr)",
&(self.0.set_cursor_position as *const u64),
)
.field(
"enable_cursor (fn ptr)",
&(self.0.enable_cursor as *const u64),
)
.field("data", &self.0.mode)
.finish()
}
}

/// The text mode (resolution) of the output device.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub struct OutputMode {
Expand Down
135 changes: 1 addition & 134 deletions uefi/src/table/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::proto::{Protocol, ProtocolPointer};
use crate::{Char16, Error, Event, Guid, Handle, Result, Status, StatusExt};
use core::cell::UnsafeCell;
use core::ffi::c_void;
use core::fmt::{Debug, Formatter};
use core::mem::{self, MaybeUninit};
use core::ops::{Deref, DerefMut};
use core::ptr::NonNull;
Expand Down Expand Up @@ -93,6 +92,7 @@ fn opt_nonnull_to_ptr<T>(opt: Option<NonNull<T>>) -> *mut T {
///
/// [`Output`]: crate::proto::console::text::Output
/// [`open_protocol`]: BootServices::open_protocol
#[derive(Debug)]
#[repr(transparent)]
pub struct BootServices(uefi_raw::table::boot::BootServices);

Expand Down Expand Up @@ -1414,139 +1414,6 @@ impl super::Table for BootServices {
const SIGNATURE: u64 = 0x5652_4553_544f_4f42;
}

impl Debug for BootServices {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
#[allow(deprecated)]
f.debug_struct("BootServices")
.field("header", &self.0.header)
.field("raise_tpl (fn ptr)", &(self.0.raise_tpl as *const usize))
.field(
"restore_tpl (fn ptr)",
&(self.0.restore_tpl as *const usize),
)
.field(
"allocate_pages (fn ptr)",
&(self.0.allocate_pages as *const usize),
)
.field("free_pages (fn ptr)", &(self.0.free_pages as *const usize))
.field(
"get_memory_map (fn ptr)",
&(self.0.get_memory_map as *const usize),
)
.field(
"allocate_pool (fn ptr)",
&(self.0.allocate_pool as *const usize),
)
.field("free_pool (fn ptr)", &(self.0.free_pool as *const usize))
.field(
"create_event (fn ptr)",
&(self.0.create_event as *const usize),
)
.field("set_timer (fn ptr)", &(self.0.set_timer as *const usize))
.field(
"wait_for_event (fn ptr)",
&(self.0.wait_for_event as *const usize),
)
.field("signal_event", &(self.0.signal_event as *const usize))
.field("close_event", &(self.0.close_event as *const usize))
.field("check_event", &(self.0.check_event as *const usize))
.field(
"install_protocol_interface",
&(self.0.install_protocol_interface as *const usize),
)
.field(
"reinstall_protocol_interface",
&(self.0.reinstall_protocol_interface as *const usize),
)
.field(
"uninstall_protocol_interface",
&(self.0.uninstall_protocol_interface as *const usize),
)
.field(
"handle_protocol (fn ptr)",
&(self.0.handle_protocol as *const usize),
)
.field(
"register_protocol_notify",
&(self.0.register_protocol_notify as *const usize),
)
.field(
"locate_handle (fn ptr)",
&(self.0.locate_handle as *const usize),
)
.field(
"locate_device_path (fn ptr)",
&(self.0.locate_device_path as *const usize),
)
.field(
"install_configuration_table (fn ptr)",
&(self.0.install_configuration_table as *const usize),
)
.field("load_image (fn ptr)", &(self.0.load_image as *const usize))
.field(
"start_image (fn ptr)",
&(self.0.start_image as *const usize),
)
.field("exit", &(self.0.exit as *const usize))
.field(
"unload_image (fn ptr)",
&(self.0.unload_image as *const usize),
)
.field(
"exit_boot_services (fn ptr)",
&(self.0.exit_boot_services as *const usize),
)
.field(
"get_next_monotonic_count",
&(self.0.get_next_monotonic_count as *const usize),
)
.field("stall (fn ptr)", &(self.0.stall as *const usize))
.field(
"set_watchdog_timer (fn ptr)",
&(self.0.set_watchdog_timer as *const usize),
)
.field(
"connect_controller",
&(self.0.connect_controller as *const usize),
)
.field(
"disconnect_controller",
&(self.0.disconnect_controller as *const usize),
)
.field("open_protocol", &(self.0.open_protocol as *const usize))
.field("close_protocol", &(self.0.close_protocol as *const usize))
.field(
"open_protocol_information",
&(self.0.open_protocol_information as *const usize),
)
.field(
"protocols_per_handle",
&(self.0.protocols_per_handle as *const usize),
)
.field(
"locate_handle_buffer",
&(self.0.locate_handle_buffer as *const usize),
)
.field(
"locate_protocol (fn ptr)",
&(self.0.locate_protocol as *const usize),
)
.field(
"install_multiple_protocol_interfaces",
&(self.0.install_multiple_protocol_interfaces as *const usize),
)
.field(
"uninstall_multiple_protocol_interfaces",
&(self.0.uninstall_multiple_protocol_interfaces as *const usize),
)
.field("calculate_crc32", &(self.0.calculate_crc32 as *const usize))
.field("copy_mem (fn ptr)", &(self.0.copy_mem as *const usize))
.field("set_mem (fn ptr)", &(self.0.set_mem as *const usize))
.field("create_event_ex", &(self.0.create_event_ex as *const usize))
.finish()
}
}

/// Used as a parameter of [`BootServices::load_image`] to provide the
/// image source.
#[derive(Debug)]
Expand Down
18 changes: 2 additions & 16 deletions uefi/src/table/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use super::Revision;
use crate::table::boot::MemoryDescriptor;
use crate::{CStr16, Error, Result, Status, StatusExt};
use core::fmt::{Debug, Formatter};
use core::fmt::Formatter;
use core::mem::MaybeUninit;
use core::{fmt, ptr};

Expand Down Expand Up @@ -31,6 +31,7 @@ use {
/// A reference to `RuntimeServices` can only be accessed by calling [`SystemTable::runtime_services`].
///
/// [`SystemTable::runtime_services`]: crate::table::SystemTable::runtime_services
#[derive(Debug)]
#[repr(C)]
pub struct RuntimeServices(uefi_raw::table::runtime::RuntimeServices);

Expand Down Expand Up @@ -295,21 +296,6 @@ impl super::Table for RuntimeServices {
const SIGNATURE: u64 = 0x5652_4553_544e_5552;
}

impl Debug for RuntimeServices {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("RuntimeServices")
.field("header", &self.0.header)
.field("get_time", &(self.0.get_time as *const u64))
.field("set_time", &(self.0.set_time as *const u64))
.field(
"set_virtual_address_map",
&(self.0.set_virtual_address_map as *const u64),
)
.field("reset", &(self.0.reset_system as *const u64))
.finish()
}
}

/// Date and time representation.
#[derive(Copy, Clone, Eq, PartialEq)]
#[repr(transparent)]
Expand Down
8 changes: 1 addition & 7 deletions uefi/src/table/system.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use core::ffi::c_void;
use core::fmt::{Debug, Formatter};
use core::marker::PhantomData;
use core::ptr::NonNull;
use core::slice;
Expand Down Expand Up @@ -45,6 +44,7 @@ impl SystemTableView for Runtime {}
/// table will be destroyed (which conveniently invalidates all references to
/// UEFI boot services in the eye of the Rust borrow checker) and a runtime view
/// will be provided to replace it.
#[derive(Debug)]
#[repr(transparent)]
pub struct SystemTable<View: SystemTableView> {
table: *const uefi_raw::table::system::SystemTable,
Expand Down Expand Up @@ -281,12 +281,6 @@ impl SystemTable<Boot> {
}
}

impl Debug for SystemTable<Boot> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
unsafe { &*self.table }.fmt(f)
}
}

// These parts of the SystemTable struct are only visible after exit from UEFI
// boot services. They provide unsafe access to the UEFI runtime services, which
// which were already available before but in safe form.
Expand Down

0 comments on commit a5c2849

Please sign in to comment.