uefi-raw: fix layout of HII keyboard layout types

The spec defines EFI_HII_KEYBOARD_LAYOUT and EFI_KEY_DESCRIPTOR with
1-byte packing (UEFI 2.11, 34.8.10; EDK2 declares them inside
#pragma pack(1)).
This commit is contained in:
Philipp Schuster 2026-08-23 12:19:35 +02:00
parent a402aa6f33
commit a2192b7588
No known key found for this signature in database
3 changed files with 21 additions and 3 deletions

View file

@ -8,6 +8,9 @@
- **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`.
- **Breaking**: `HiiKeyboardLayout` and `KeyDescriptor` are now packed to
match the layout mandated by the UEFI specification. Previously, all
`HiiKeyboardLayout` fields after `layout_length` were at wrong offsets.
## Removed

View file

@ -4,10 +4,11 @@
use super::{HiiHandle, HiiPackageHeader, HiiPackageListHeader, KeyDescriptor};
use crate::{Guid, Handle, Status, guid, newtype_enum};
use core::mem::offset_of;
/// EFI_HII_KEYBOARD_LAYOUT
#[derive(Debug)]
#[repr(C)]
#[repr(C, packed)]
pub struct HiiKeyboardLayout {
pub layout_length: u16,
pub guid: Guid,
@ -16,6 +17,14 @@ pub struct HiiKeyboardLayout {
pub descriptors: [KeyDescriptor; 0],
}
// Compile-time ABI check.
const _: () = {
assert!(offset_of!(HiiKeyboardLayout, guid) == 2);
assert!(offset_of!(HiiKeyboardLayout, layout_descriptor_string_offset) == 18);
assert!(offset_of!(HiiKeyboardLayout, descriptor_count) == 22);
assert!(offset_of!(HiiKeyboardLayout, descriptors) == 23);
};
newtype_enum! {
/// EFI_HII_DATABASE_NOTIFY_TYPE
pub enum HiiDatabaseNotifyType: usize => {

View file

@ -208,8 +208,8 @@ newtype_enum! {
}
/// EFI_KEY_DESCRIPTOR
#[derive(Debug)]
#[repr(C)]
#[derive(Clone, Copy, Debug)]
#[repr(C, packed)]
pub struct KeyDescriptor {
pub key: Key,
pub unicode: Char16,
@ -219,3 +219,9 @@ pub struct KeyDescriptor {
pub modifier: u16,
pub affected_attribute: u16,
}
// Compile-time ABI check.
const _: () = {
assert!(size_of::<KeyDescriptor>() == 16);
assert!(align_of::<KeyDescriptor>() == 1);
};