uefi-raw: fix MemoryDescriptor layout on 32-bit targets

On 64-bit, there is implicit padding. On 32-bit targets, this is missing
and makes parsing the memory map impossible. The issue was found in an
external 32-bit integration test [0].

[0] https://github.com/rust-osdev/multiboot2/pull/225
This commit is contained in:
Philipp Schuster 2026-08-17 08:44:12 +02:00
parent ef2b4bc72f
commit 6424087aa5
5 changed files with 23 additions and 0 deletions

View file

@ -3,6 +3,8 @@
## Added
## Changed
- **Breaking**: `MemoryDescriptor` now has a new member to ensure correct
padding on 32-bit targets.
## Removed

View file

@ -364,6 +364,8 @@ bitflags! {
pub struct MemoryDescriptor {
/// Type of memory occupying this range.
pub ty: MemoryType,
/// Reserved field that must be set to 0.
pub reserved: u32,
// Implicit 32-bit padding.
/// Starting physical address.
pub phys_start: PhysicalAddress,
@ -384,6 +386,7 @@ impl Default for MemoryDescriptor {
fn default() -> Self {
Self {
ty: MemoryType::RESERVED,
reserved: 0,
phys_start: 0,
virt_start: 0,
page_count: 0,

View file

@ -471,6 +471,7 @@ mod tests {
const BASE_MMAP_UNSORTED: [MemoryDescriptor; 3] = [
MemoryDescriptor {
ty: MemoryType::CONVENTIONAL,
reserved: 0,
phys_start: 0x3000,
virt_start: 0x3000,
page_count: 1,
@ -478,6 +479,7 @@ mod tests {
},
MemoryDescriptor {
ty: MemoryType::CONVENTIONAL,
reserved: 0,
phys_start: 0x2000,
virt_start: 0x2000,
page_count: 1,
@ -485,6 +487,7 @@ mod tests {
},
MemoryDescriptor {
ty: MemoryType::CONVENTIONAL,
reserved: 0,
phys_start: 0x1000,
virt_start: 0x1000,
page_count: 1,

View file

@ -133,6 +133,7 @@ mod tests_mmap_artificial {
const BASE: MemoryDescriptor = MemoryDescriptor {
ty: TY,
reserved: 0,
phys_start: 0,
virt_start: 0,
page_count: 0,
@ -170,6 +171,7 @@ mod tests_mmap_artificial {
const TY: MemoryType = MemoryType::RESERVED;
const BASE: MemoryDescriptor = MemoryDescriptor {
reserved: 0,
ty: TY,
phys_start: 0,
virt_start: 0,
@ -274,6 +276,7 @@ mod tests_mmap_real {
let expected = [
MemoryDescriptor {
ty: MemoryType::BOOT_SERVICES_CODE,
reserved: 0,
phys_start: 0x0,
virt_start: 0x0,
page_count: 0x1,
@ -284,6 +287,7 @@ mod tests_mmap_real {
},
MemoryDescriptor {
ty: MemoryType::CONVENTIONAL,
reserved: 0,
phys_start: 0x1000,
virt_start: 0x0,
page_count: 0x86,
@ -294,6 +298,7 @@ mod tests_mmap_real {
},
MemoryDescriptor {
ty: MemoryType::BOOT_SERVICES_DATA,
reserved: 0,
phys_start: 0x87000,
virt_start: 0x0,
page_count: 0x1,
@ -304,6 +309,7 @@ mod tests_mmap_real {
},
MemoryDescriptor {
ty: MemoryType::CONVENTIONAL,
reserved: 0,
phys_start: 0x88000,
virt_start: 0x0,
page_count: 0x18,
@ -314,6 +320,7 @@ mod tests_mmap_real {
},
MemoryDescriptor {
ty: MemoryType::CONVENTIONAL,
reserved: 0,
phys_start: 0x100000,
virt_start: 0x0,
page_count: 0x700,
@ -324,6 +331,7 @@ mod tests_mmap_real {
},
MemoryDescriptor {
ty: MemoryType::ACPI_NON_VOLATILE,
reserved: 0,
phys_start: 0x800000,
virt_start: 0x0,
page_count: 0x8,
@ -334,6 +342,7 @@ mod tests_mmap_real {
},
MemoryDescriptor {
ty: MemoryType::CONVENTIONAL,
reserved: 0,
phys_start: 0x808000,
virt_start: 0x0,
page_count: 0x3,
@ -344,6 +353,7 @@ mod tests_mmap_real {
},
MemoryDescriptor {
ty: MemoryType::ACPI_NON_VOLATILE,
reserved: 0,
phys_start: 0x80b000,
virt_start: 0x0,
page_count: 0x1,
@ -354,6 +364,7 @@ mod tests_mmap_real {
},
MemoryDescriptor {
ty: MemoryType::CONVENTIONAL,
reserved: 0,
phys_start: 0x80c000,
virt_start: 0x0,
page_count: 0x4,
@ -364,6 +375,7 @@ mod tests_mmap_real {
},
MemoryDescriptor {
ty: MemoryType::ACPI_NON_VOLATILE,
reserved: 0,
phys_start: 0x810000,
virt_start: 0x0,
page_count: 0xf0,

View file

@ -10,6 +10,7 @@ fn parse_boot_information_efi_mmap() {
let mut mmap_source = [
MemoryDescriptor {
ty: MemoryType::CONVENTIONAL,
reserved: 0,
phys_start: 0x3000,
virt_start: 0x3000,
page_count: 1,
@ -17,6 +18,7 @@ fn parse_boot_information_efi_mmap() {
},
MemoryDescriptor {
ty: MemoryType::CONVENTIONAL,
reserved: 0,
phys_start: 0x2000,
virt_start: 0x2000,
page_count: 1,
@ -24,6 +26,7 @@ fn parse_boot_information_efi_mmap() {
},
MemoryDescriptor {
ty: MemoryType::CONVENTIONAL,
reserved: 0,
phys_start: 0x1000,
virt_start: 0x1000,
page_count: 1,