From 849f8fea5ca96d8bff36b8a30d009ba4d0fcbab2 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Wed, 9 Apr 2025 15:16:56 -0600 Subject: [PATCH] kboot: Use roundup2 instead of expanding the (old) definiution of it inline The boot loader pads efi_map_header to start the array of efi_memory_descriptor entries on the 16-byte-aligned boundary after the header. Since the header isn't naturally 16-byte aligned, we need to do this. We should have used the actual UEFI EFI_MEMORY_ATTRIBUTES_TABLE which used uint32_t's to pass all this data to the kernel (they never needed to be 64-bit quantities or size_t's even) since these entries and the total size of the table is small. However, this ship long since sailed since we've used these structures for a decade and there's little to be gained by changing them. The table header we pass to the kernel from the loader has similar names, but the seamntics of the fields are different. Sponsored by: Netflix --- stand/kboot/kboot/arch/aarch64/load_addr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stand/kboot/kboot/arch/aarch64/load_addr.c b/stand/kboot/kboot/arch/aarch64/load_addr.c index 8ea3516a5cf..9d6f23a9d34 100644 --- a/stand/kboot/kboot/arch/aarch64/load_addr.c +++ b/stand/kboot/kboot/arch/aarch64/load_addr.c @@ -36,7 +36,7 @@ foreach_efi_map_entry(struct efi_map_header *efihdr, efi_map_entry_cb cb, void * * Memory map data provided by UEFI via the GetMemoryMap * Boot Services API. */ - efisz = (sizeof(struct efi_map_header) + 0xf) & ~0xf; + efisz = roundup2(sizeof(struct efi_map_header), 16); map = (struct efi_md *)((uint8_t *)efihdr + efisz); if (efihdr->descriptor_size == 0) @@ -169,7 +169,7 @@ do_memory_from_fdt(int fd) * so early boot can copy the memory map into this space and have the * rest of the code cope. */ - efisz = (sizeof(*efihdr) + 0xf) & ~0xf; + efisz = roundup2(sizeof(*efihdr), 16); buf = malloc(sz + efisz); if (buf == NULL) return false;