Skip to content

Commit 6dd4e99

Browse files
uefi: Replace manual Debug impls with derives
Note that this requires rust>=1.70 for deriving `Debug` on `efiapi` function pointers.
1 parent c16ff33 commit 6dd4e99

File tree

4 files changed

+9
-194
lines changed

4 files changed

+9
-194
lines changed

uefi/src/proto/console/text/output.rs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::proto::unsafe_protocol;
22
use crate::{CStr16, Result, ResultExt, Status, StatusExt};
33
use core::fmt;
4-
use core::fmt::{Debug, Formatter};
54
use uefi_raw::protocol::console::{SimpleTextOutputMode, SimpleTextOutputProtocol};
65

76
/// Interface for text-based output devices.
@@ -21,6 +20,7 @@ use uefi_raw::protocol::console::{SimpleTextOutputMode, SimpleTextOutputProtocol
2120
/// [`SystemTable::stdout`]: crate::table::SystemTable::stdout
2221
/// [`SystemTable::stderr`]: crate::table::SystemTable::stderr
2322
/// [`BootServices`]: crate::table::boot::BootServices#accessing-protocols
23+
#[derive(Debug)]
2424
#[repr(transparent)]
2525
#[unsafe_protocol(SimpleTextOutputProtocol::GUID)]
2626
pub struct Output(SimpleTextOutputProtocol);
@@ -217,38 +217,6 @@ impl fmt::Write for Output {
217217
}
218218
}
219219

220-
impl Debug for Output {
221-
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
222-
f.debug_struct("Output")
223-
.field("reset (fn ptr)", &(self.0.reset as *const u64))
224-
.field(
225-
"output_string (fn ptr)",
226-
&(self.0.output_string as *const u64),
227-
)
228-
.field("test_string (fn ptr)", &(self.0.test_string as *const u64))
229-
.field("query_mode (fn ptr)", &(self.0.query_mode as *const u64))
230-
.field("set_mode (fn ptr)", &(self.0.set_mode as *const u64))
231-
.field(
232-
"set_attribute (fn ptr)",
233-
&(self.0.set_attribute as *const u64),
234-
)
235-
.field(
236-
"clear_screen (fn ptr)",
237-
&(self.0.clear_screen as *const u64),
238-
)
239-
.field(
240-
"set_cursor_position (fn ptr)",
241-
&(self.0.set_cursor_position as *const u64),
242-
)
243-
.field(
244-
"enable_cursor (fn ptr)",
245-
&(self.0.enable_cursor as *const u64),
246-
)
247-
.field("data", &self.0.mode)
248-
.finish()
249-
}
250-
}
251-
252220
/// The text mode (resolution) of the output device.
253221
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
254222
pub struct OutputMode {

uefi/src/table/boot.rs

Lines changed: 1 addition & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::util::opt_nonnull_to_ptr;
1010
use crate::{Char16, Error, Event, Guid, Handle, Result, Status, StatusExt};
1111
use core::cell::UnsafeCell;
1212
use core::ffi::c_void;
13-
use core::fmt::{Debug, Formatter};
1413
use core::mem::{self, MaybeUninit};
1514
use core::ops::{Deref, DerefMut};
1615
use core::ptr::NonNull;
@@ -89,6 +88,7 @@ pub const PAGE_SIZE: usize = 4096;
8988
///
9089
/// [`Output`]: crate::proto::console::text::Output
9190
/// [`open_protocol`]: BootServices::open_protocol
91+
#[derive(Debug)]
9292
#[repr(transparent)]
9393
pub struct BootServices(uefi_raw::table::boot::BootServices);
9494

@@ -1390,139 +1390,6 @@ impl super::Table for BootServices {
13901390
const SIGNATURE: u64 = 0x5652_4553_544f_4f42;
13911391
}
13921392

1393-
impl Debug for BootServices {
1394-
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
1395-
#[allow(deprecated)]
1396-
f.debug_struct("BootServices")
1397-
.field("header", &self.0.header)
1398-
.field("raise_tpl (fn ptr)", &(self.0.raise_tpl as *const usize))
1399-
.field(
1400-
"restore_tpl (fn ptr)",
1401-
&(self.0.restore_tpl as *const usize),
1402-
)
1403-
.field(
1404-
"allocate_pages (fn ptr)",
1405-
&(self.0.allocate_pages as *const usize),
1406-
)
1407-
.field("free_pages (fn ptr)", &(self.0.free_pages as *const usize))
1408-
.field(
1409-
"get_memory_map (fn ptr)",
1410-
&(self.0.get_memory_map as *const usize),
1411-
)
1412-
.field(
1413-
"allocate_pool (fn ptr)",
1414-
&(self.0.allocate_pool as *const usize),
1415-
)
1416-
.field("free_pool (fn ptr)", &(self.0.free_pool as *const usize))
1417-
.field(
1418-
"create_event (fn ptr)",
1419-
&(self.0.create_event as *const usize),
1420-
)
1421-
.field("set_timer (fn ptr)", &(self.0.set_timer as *const usize))
1422-
.field(
1423-
"wait_for_event (fn ptr)",
1424-
&(self.0.wait_for_event as *const usize),
1425-
)
1426-
.field("signal_event", &(self.0.signal_event as *const usize))
1427-
.field("close_event", &(self.0.close_event as *const usize))
1428-
.field("check_event", &(self.0.check_event as *const usize))
1429-
.field(
1430-
"install_protocol_interface",
1431-
&(self.0.install_protocol_interface as *const usize),
1432-
)
1433-
.field(
1434-
"reinstall_protocol_interface",
1435-
&(self.0.reinstall_protocol_interface as *const usize),
1436-
)
1437-
.field(
1438-
"uninstall_protocol_interface",
1439-
&(self.0.uninstall_protocol_interface as *const usize),
1440-
)
1441-
.field(
1442-
"handle_protocol (fn ptr)",
1443-
&(self.0.handle_protocol as *const usize),
1444-
)
1445-
.field(
1446-
"register_protocol_notify",
1447-
&(self.0.register_protocol_notify as *const usize),
1448-
)
1449-
.field(
1450-
"locate_handle (fn ptr)",
1451-
&(self.0.locate_handle as *const usize),
1452-
)
1453-
.field(
1454-
"locate_device_path (fn ptr)",
1455-
&(self.0.locate_device_path as *const usize),
1456-
)
1457-
.field(
1458-
"install_configuration_table (fn ptr)",
1459-
&(self.0.install_configuration_table as *const usize),
1460-
)
1461-
.field("load_image (fn ptr)", &(self.0.load_image as *const usize))
1462-
.field(
1463-
"start_image (fn ptr)",
1464-
&(self.0.start_image as *const usize),
1465-
)
1466-
.field("exit", &(self.0.exit as *const usize))
1467-
.field(
1468-
"unload_image (fn ptr)",
1469-
&(self.0.unload_image as *const usize),
1470-
)
1471-
.field(
1472-
"exit_boot_services (fn ptr)",
1473-
&(self.0.exit_boot_services as *const usize),
1474-
)
1475-
.field(
1476-
"get_next_monotonic_count",
1477-
&(self.0.get_next_monotonic_count as *const usize),
1478-
)
1479-
.field("stall (fn ptr)", &(self.0.stall as *const usize))
1480-
.field(
1481-
"set_watchdog_timer (fn ptr)",
1482-
&(self.0.set_watchdog_timer as *const usize),
1483-
)
1484-
.field(
1485-
"connect_controller",
1486-
&(self.0.connect_controller as *const usize),
1487-
)
1488-
.field(
1489-
"disconnect_controller",
1490-
&(self.0.disconnect_controller as *const usize),
1491-
)
1492-
.field("open_protocol", &(self.0.open_protocol as *const usize))
1493-
.field("close_protocol", &(self.0.close_protocol as *const usize))
1494-
.field(
1495-
"open_protocol_information",
1496-
&(self.0.open_protocol_information as *const usize),
1497-
)
1498-
.field(
1499-
"protocols_per_handle",
1500-
&(self.0.protocols_per_handle as *const usize),
1501-
)
1502-
.field(
1503-
"locate_handle_buffer",
1504-
&(self.0.locate_handle_buffer as *const usize),
1505-
)
1506-
.field(
1507-
"locate_protocol (fn ptr)",
1508-
&(self.0.locate_protocol as *const usize),
1509-
)
1510-
.field(
1511-
"install_multiple_protocol_interfaces",
1512-
&(self.0.install_multiple_protocol_interfaces as *const usize),
1513-
)
1514-
.field(
1515-
"uninstall_multiple_protocol_interfaces",
1516-
&(self.0.uninstall_multiple_protocol_interfaces as *const usize),
1517-
)
1518-
.field("calculate_crc32", &(self.0.calculate_crc32 as *const usize))
1519-
.field("copy_mem (fn ptr)", &(self.0.copy_mem as *const usize))
1520-
.field("set_mem (fn ptr)", &(self.0.set_mem as *const usize))
1521-
.field("create_event_ex", &(self.0.create_event_ex as *const usize))
1522-
.finish()
1523-
}
1524-
}
1525-
15261393
/// Used as a parameter of [`BootServices::load_image`] to provide the
15271394
/// image source.
15281395
#[derive(Debug)]

uefi/src/table/runtime.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use {
3131
/// A reference to `RuntimeServices` can only be accessed by calling [`SystemTable::runtime_services`].
3232
///
3333
/// [`SystemTable::runtime_services`]: crate::table::SystemTable::runtime_services
34+
#[derive(Debug)]
3435
#[repr(C)]
3536
pub struct RuntimeServices(uefi_raw::table::runtime::RuntimeServices);
3637

@@ -295,21 +296,6 @@ impl super::Table for RuntimeServices {
295296
const SIGNATURE: u64 = 0x5652_4553_544e_5552;
296297
}
297298

298-
impl Debug for RuntimeServices {
299-
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
300-
f.debug_struct("RuntimeServices")
301-
.field("header", &self.0.header)
302-
.field("get_time", &(self.0.get_time as *const u64))
303-
.field("set_time", &(self.0.set_time as *const u64))
304-
.field(
305-
"set_virtual_address_map",
306-
&(self.0.set_virtual_address_map as *const u64),
307-
)
308-
.field("reset", &(self.0.reset_system as *const u64))
309-
.finish()
310-
}
311-
}
312-
313299
/// Date and time representation.
314300
#[derive(Copy, Clone, Eq, PartialEq)]
315301
#[repr(transparent)]
@@ -464,8 +450,8 @@ impl Time {
464450
}
465451
}
466452

467-
impl fmt::Debug for Time {
468-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
453+
impl Debug for Time {
454+
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
469455
write!(
470456
f,
471457
"{:04}-{:02}-{:02} ",
@@ -485,7 +471,7 @@ impl fmt::Debug for Time {
485471
}
486472
}
487473

488-
impl fmt::Display for Time {
474+
impl Display for Time {
489475
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
490476
write!(f, "{}", self.0)
491477
}
@@ -509,8 +495,8 @@ impl VariableKey {
509495
}
510496

511497
#[cfg(feature = "alloc")]
512-
impl fmt::Display for VariableKey {
513-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
498+
impl Display for VariableKey {
499+
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
514500
write!(f, "VariableKey {{ name: ")?;
515501

516502
match self.name() {

uefi/src/table/system.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use core::ffi::c_void;
2-
use core::fmt::{Debug, Formatter};
32
use core::marker::PhantomData;
43
use core::ptr::NonNull;
54
use core::slice;
@@ -45,6 +44,7 @@ impl SystemTableView for Runtime {}
4544
/// table will be destroyed (which conveniently invalidates all references to
4645
/// UEFI boot services in the eye of the Rust borrow checker) and a runtime view
4746
/// will be provided to replace it.
47+
#[derive(Debug)]
4848
#[repr(transparent)]
4949
pub struct SystemTable<View: SystemTableView> {
5050
table: *const uefi_raw::table::system::SystemTable,
@@ -281,12 +281,6 @@ impl SystemTable<Boot> {
281281
}
282282
}
283283

284-
impl Debug for SystemTable<Boot> {
285-
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
286-
unsafe { &*self.table }.fmt(f)
287-
}
288-
}
289-
290284
// These parts of the SystemTable struct are only visible after exit from UEFI
291285
// boot services. They provide unsafe access to the UEFI runtime services, which
292286
// which were already available before but in safe form.

0 commit comments

Comments
 (0)