mirror of
https://github.com/rust-osdev/uefi-rs
synced 2026-08-26 18:26:05 -04:00
uefi-raw: pack USB descriptor structs
The USB 2.0 specification defines all standard descriptors with 1-byte
packing, and EDK2 declares EFI_USB_*_DESCRIPTOR inside #pragma pack(1)
accordingly [0]. With natural repr(C) layout, ConfigDescriptor was 10
bytes (spec: 9) and EndpointDescriptor 8 bytes (spec: 7) due to the
u16 member; DeviceRequest and DeviceDescriptor deviated in alignment
only.
[0]: 7735ed4f8e/MdePkg/Include/IndustryStandard/Usb.h (L85)
This commit is contained in:
parent
ef8641b510
commit
a402aa6f33
2 changed files with 33 additions and 5 deletions
|
|
@ -5,6 +5,9 @@
|
|||
## Changed
|
||||
- **Breaking**: `MemoryDescriptor` now has a new member to ensure correct
|
||||
layout on all non-UEFI 32-bit targets.
|
||||
- **Breaking**: The USB descriptor types in `protocol::usb` are now packed to
|
||||
match their layout in the USB specification. `ConfigDescriptor` and
|
||||
`EndpointDescriptor` previously had a too-large `size_of`.
|
||||
|
||||
## Removed
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ newtype_enum! {
|
|||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[repr(C)]
|
||||
#[repr(C, packed)]
|
||||
pub struct DeviceRequest {
|
||||
pub request_type: u8,
|
||||
pub request: u8,
|
||||
|
|
@ -27,6 +27,11 @@ pub struct DeviceRequest {
|
|||
pub length: u16,
|
||||
}
|
||||
|
||||
// Compile-time ABI check.
|
||||
const _: () = {
|
||||
assert!(size_of::<DeviceRequest>() == 8);
|
||||
};
|
||||
|
||||
bitflags! {
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
#[repr(transparent)]
|
||||
|
|
@ -55,7 +60,7 @@ pub type AsyncUsbTransferCallback = unsafe extern "efiapi" fn(
|
|||
) -> Status;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[repr(C)]
|
||||
#[repr(C, packed)]
|
||||
pub struct DeviceDescriptor {
|
||||
pub length: u8,
|
||||
pub descriptor_type: u8,
|
||||
|
|
@ -73,8 +78,13 @@ pub struct DeviceDescriptor {
|
|||
pub num_configurations: u8,
|
||||
}
|
||||
|
||||
// Compile-time ABI check.
|
||||
const _: () = {
|
||||
assert!(size_of::<DeviceDescriptor>() == 18);
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[repr(C)]
|
||||
#[repr(C, packed)]
|
||||
pub struct ConfigDescriptor {
|
||||
pub length: u8,
|
||||
pub descriptor_type: u8,
|
||||
|
|
@ -86,8 +96,13 @@ pub struct ConfigDescriptor {
|
|||
pub max_power: u8,
|
||||
}
|
||||
|
||||
// Compile-time ABI check.
|
||||
const _: () = {
|
||||
assert!(size_of::<ConfigDescriptor>() == 9);
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[repr(C)]
|
||||
#[repr(C, packed)]
|
||||
pub struct InterfaceDescriptor {
|
||||
pub length: u8,
|
||||
pub descriptor_type: u8,
|
||||
|
|
@ -100,8 +115,13 @@ pub struct InterfaceDescriptor {
|
|||
pub interface: u8,
|
||||
}
|
||||
|
||||
// Compile-time ABI check.
|
||||
const _: () = {
|
||||
assert!(size_of::<InterfaceDescriptor>() == 9);
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[repr(C)]
|
||||
#[repr(C, packed)]
|
||||
pub struct EndpointDescriptor {
|
||||
pub length: u8,
|
||||
pub descriptor_type: u8,
|
||||
|
|
@ -110,3 +130,8 @@ pub struct EndpointDescriptor {
|
|||
pub max_packet_size: u16,
|
||||
pub interval: u8,
|
||||
}
|
||||
|
||||
// Compile-time ABI check.
|
||||
const _: () = {
|
||||
assert!(size_of::<EndpointDescriptor>() == 7);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue