Skip to content

Commit

Permalink
uefi: Derive Debug on many protocols
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 22, 2023
1 parent f05c6a6 commit f8b4b40
Show file tree
Hide file tree
Showing 23 changed files with 26 additions and 7 deletions.
6 changes: 0 additions & 6 deletions uefi-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ pub fn unsafe_protocol(args: TokenStream, input: TokenStream) -> TokenStream {
let (impl_generics, ty_generics, where_clause) = item_struct.generics.split_for_impl();

quote! {
// Disable this lint for now. It doesn't account for the fact that
// currently it doesn't work to `derive(Debug)` on structs that have
// `extern "efiapi" fn` fields, which most protocol structs have. The
// derive _does_ work in current nightly (1.70.0) though, so hopefully
// in a couple Rust releases we can drop this.
#[allow(missing_debug_implementations)]
#item_struct

unsafe impl #impl_generics ::uefi::Identify for #ident #ty_generics #where_clause {
Expand Down
1 change: 1 addition & 0 deletions uefi/src/proto/console/gop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub use uefi_raw::protocol::console::PixelBitmask;
///
/// The GOP can be used to set the properties of the frame buffer,
/// and also allows the app to access the in-memory buffer.
#[derive(Debug)]
#[repr(transparent)]
#[unsafe_protocol(GraphicsOutputProtocol::GUID)]
pub struct GraphicsOutput(GraphicsOutputProtocol);
Expand Down
1 change: 1 addition & 0 deletions uefi/src/proto/console/pointer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{Event, Result, Status, StatusExt};
use uefi_raw::protocol::console::SimplePointerProtocol;

/// Provides information about a pointer device.
#[derive(Debug)]
#[repr(transparent)]
#[unsafe_protocol(SimplePointerProtocol::GUID)]
pub struct Pointer(SimplePointerProtocol);
Expand Down
1 change: 1 addition & 0 deletions uefi/src/proto/console/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub use uefi_raw::protocol::console::serial::{ControlBits, Parity, StopBits};
///
/// Since UEFI drivers are implemented through polling, if you fail to regularly
/// check for input/output, some data might be lost.
#[derive(Debug)]
#[repr(transparent)]
#[unsafe_protocol(SerialIoProtocol::GUID)]
pub struct Serial(SerialIoProtocol);
Expand Down
1 change: 1 addition & 0 deletions uefi/src/proto/console/text/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use core::mem::MaybeUninit;
use uefi_raw::protocol::console::{InputKey, SimpleTextInputProtocol};

/// Interface for text-based input devices.
#[derive(Debug)]
#[repr(transparent)]
#[unsafe_protocol(SimpleTextInputProtocol::GUID)]
pub struct Input(SimpleTextInputProtocol);
Expand Down
2 changes: 2 additions & 0 deletions uefi/src/proto/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ mod exception;
/// one for any given instruction set.
///
/// NOTE: OVMF only implements this protocol interface for the virtual EBC processor
#[derive(Debug)]
#[repr(C)]
#[unsafe_protocol("2755590c-6f3c-42fa-9ea4-a3ba543cda25")]
pub struct DebugSupport {
Expand Down Expand Up @@ -174,6 +175,7 @@ pub enum ProcessorArch: u32 => {

/// The debug port protocol abstracts the underlying debug port
/// hardware, whether it is a regular Serial port or something else.
#[derive(Debug)]
#[repr(C)]
#[unsafe_protocol("eba4e8d2-3858-41ec-a281-2647ba9660d0")]
pub struct DebugPort {
Expand Down
2 changes: 1 addition & 1 deletion uefi/src/proto/device_path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ pub enum NodeConversionError {
/// [`load_image`]: crate::table::boot::BootServices::load_image
#[repr(transparent)]
#[unsafe_protocol("bc62157e-3e33-4fec-9920-2d3b36d750df")]
#[derive(Pointee)]
#[derive(Debug, Pointee)]
pub struct LoadedImageDevicePath(DevicePath);

impl ProtocolPointer for LoadedImageDevicePath {
Expand Down
2 changes: 2 additions & 0 deletions uefi/src/proto/device_path/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ impl Drop for PoolString<'_> {
///
/// This protocol provides common utility functions for converting device
/// nodes and device paths to a text representation.
#[derive(Debug)]
#[repr(C)]
#[unsafe_protocol("8b843e20-8132-4852-90cc-551a4e4a7f1c")]
pub struct DevicePathToText {
Expand Down Expand Up @@ -147,6 +148,7 @@ impl DevicePathToText {
///
/// This protocol provides common utilities for converting text to
/// device paths and device nodes.
#[derive(Debug)]
#[repr(C)]
#[unsafe_protocol("05c99a21-c70f-4ad2-8a5f-35df3343f51e")]
pub struct DevicePathFromText {
Expand Down
2 changes: 2 additions & 0 deletions uefi/src/proto/driver/component_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use core::{ptr, slice};
/// [RFC 4646]: https://www.rfc-editor.org/rfc/rfc4646
#[deprecated = "deprecated in UEFI 2.1; use ComponentName2 where possible"]
#[unsafe_protocol("107a772c-d5e1-11d4-9a46-0090273fc14d")]
#[derive(Debug)]
#[repr(C)]
pub struct ComponentName1 {
get_driver_name: unsafe extern "efiapi" fn(
Expand Down Expand Up @@ -106,6 +107,7 @@ impl ComponentName1 {
/// [ISO 639-2]: https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
/// [RFC 4646]: https://www.rfc-editor.org/rfc/rfc4646
#[unsafe_protocol("6a7a5cff-e8d9-4f70-bada-75ab3025ce14")]
#[derive(Debug)]
#[repr(C)]
pub struct ComponentName2 {
get_driver_name: unsafe extern "efiapi" fn(
Expand Down
1 change: 1 addition & 0 deletions uefi/src/proto/loaded_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use core::{mem, slice};
use uefi_raw::protocol::loaded_image::LoadedImageProtocol;

/// The LoadedImage protocol. This can be opened on any image handle using the `HandleProtocol` boot service.
#[derive(Debug)]
#[repr(transparent)]
#[unsafe_protocol(LoadedImageProtocol::GUID)]
pub struct LoadedImage(LoadedImageProtocol);
Expand Down
1 change: 1 addition & 0 deletions uefi/src/proto/media/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::proto::unsafe_protocol;
use crate::{Result, Status, StatusExt};

/// The Block I/O protocol.
#[derive(Debug)]
#[repr(C)]
#[unsafe_protocol("964e5b21-6459-11d2-8e39-00a0c969723b")]
pub struct BlockIO {
Expand Down
2 changes: 2 additions & 0 deletions uefi/src/proto/media/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use uefi_raw::protocol::disk::{DiskIo2Protocol, DiskIoProtocol};
/// protocol to a more general offset-length protocol. Firmware is
/// responsible for adding this protocol to any block I/O interface that
/// appears in the system that does not already have a disk I/O protocol.
#[derive(Debug)]
#[repr(transparent)]
#[unsafe_protocol(DiskIoProtocol::GUID)]
pub struct DiskIo(DiskIoProtocol);
Expand Down Expand Up @@ -87,6 +88,7 @@ pub struct DiskIo2Token {
///
/// This protocol provides an extension to the disk I/O protocol to enable
/// non-blocking / asynchronous byte-oriented disk operation.
#[derive(Debug)]
#[repr(transparent)]
#[unsafe_protocol(DiskIo2Protocol::GUID)]
pub struct DiskIo2(DiskIo2Protocol);
Expand Down
1 change: 1 addition & 0 deletions uefi/src/proto/media/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use core::ptr;
///
/// [`BootServices::get_image_file_system`]: crate::table::boot::BootServices::get_image_file_system
/// [`BootServices`]: crate::table::boot::BootServices#accessing-protocols
#[derive(Debug)]
#[repr(C)]
#[unsafe_protocol("964e5b22-6459-11d2-8e39-00a0c969723b")]
pub struct SimpleFileSystem {
Expand Down
1 change: 1 addition & 0 deletions uefi/src/proto/media/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ newtype_enum! {
}

/// Protocol for accessing partition information.
#[allow(missing_debug_implementations)]
#[repr(C)]
#[repr(packed)]
#[unsafe_protocol("8cf2f62c-bc9b-4821-808d-ec9ec421a1a0")]
Expand Down
1 change: 1 addition & 0 deletions uefi/src/proto/network/pxe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::{CStr8, Char8, Result, Status, StatusExt};
use super::{IpAddress, MacAddress};

/// PXE Base Code protocol
#[derive(Debug)]
#[repr(C)]
#[unsafe_protocol("03c4e603-ac28-11d3-9a2d-0090273fc14d")]
#[allow(clippy::type_complexity)]
Expand Down
1 change: 1 addition & 0 deletions uefi/src/proto/network/snp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use core::ptr::NonNull;
use uefi_macros::unsafe_protocol;

/// The Simple Network Protocol
#[derive(Debug)]
#[repr(C)]
#[unsafe_protocol("a19832b9-ac25-11d3-9a2d-0090273fc14d")]
pub struct SimpleNetwork {
Expand Down
1 change: 1 addition & 0 deletions uefi/src/proto/pi/mp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub struct CpuPhysicalLocation {
}

/// Protocol that provides services needed for multi-processor management.
#[derive(Debug)]
#[repr(C)]
#[unsafe_protocol("3fdda605-a76e-4f46-ad29-12f4531b3d08")]
pub struct MpServices {
Expand Down
1 change: 1 addition & 0 deletions uefi/src/proto/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use core::{mem, ptr};
pub use uefi_raw::protocol::rng::RngAlgorithmType;

/// Rng protocol
#[derive(Debug)]
#[repr(transparent)]
#[unsafe_protocol(uefi_raw::protocol::rng::RngProtocol::GUID)]
pub struct Rng(uefi_raw::protocol::rng::RngProtocol);
Expand Down
1 change: 1 addition & 0 deletions uefi/src/proto/security/memory_protection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use core::ops::Range;
/// Protocol for getting and setting memory protection attributes.
///
/// Corresponds to the C type `EFI_MEMORY_ATTRIBUTE_PROTOCOL`.
#[derive(Debug)]
#[repr(C)]
#[unsafe_protocol("f4560cf6-40ec-4b4a-a192-bf1d57d0b189")]
pub struct MemoryProtection {
Expand Down
1 change: 1 addition & 0 deletions uefi/src/proto/shim/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ macro_rules! shim_function {
/// application may itself be a bootloader that needs to validate
/// another EFI application before running it, and the shim lock
/// protocol exists to support that.
#[derive(Debug)]
#[repr(C)]
#[unsafe_protocol("605dab50-e046-4300-abb6-3dd810dd8b23")]
pub struct ShimLock {
Expand Down
1 change: 1 addition & 0 deletions uefi/src/proto/string/unicode_collation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use core::cmp::Ordering;
/// The Unicode Collation Protocol.
///
/// Used to perform case-insensitive comparisons of strings.
#[derive(Debug)]
#[repr(C)]
#[unsafe_protocol("a4c751fc-23ae-4c3e-92e9-4964cf63f349")]
pub struct UnicodeCollation {
Expand Down
1 change: 1 addition & 0 deletions uefi/src/proto/tcg/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ impl<'a> Iterator for EventLogIter<'a> {
/// Protocol for interacting with TPM 1.1 and 1.2 devices.
///
/// The corresponding C type is `EFI_TCG_PROTOCOL`.
#[derive(Debug)]
#[repr(C)]
#[unsafe_protocol("f541796d-a62e-4954-a775-9584f61b9cdd")]
pub struct Tcg {
Expand Down
1 change: 1 addition & 0 deletions uefi/src/proto/tcg/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ impl<'a> Iterator for EventLogIter<'a> {
/// devices, but most firmware only uses it for TPM 2.0.
///
/// The corresponding C type is `EFI_TCG2_PROTOCOL`.
#[derive(Debug)]
#[repr(C)]
#[unsafe_protocol("607f766c-7455-42be-930b-e4d76db2720f")]
pub struct Tcg {
Expand Down

0 comments on commit f8b4b40

Please sign in to comment.