diff --git a/src/boot/boot.c b/src/boot/boot.c index 87b0232860..129d6f8f5d 100644 --- a/src/boot/boot.c +++ b/src/boot/boot.c @@ -2469,11 +2469,7 @@ static EFI_STATUS initrd_prepare( return EFI_OUT_OF_RESOURCES; } - _cleanup_pages_ Pages pages = xmalloc_pages( - AllocateMaxAddress, - EfiLoaderData, - EFI_SIZE_TO_PAGES(size), - UINT32_MAX /* Below 4G boundary. */); + _cleanup_pages_ Pages pages = xmalloc_initrd_pages(size); uint8_t *p = PHYSICAL_ADDRESS_TO_POINTER(pages.addr); STRV_FOREACH(i, entry->initrd) { diff --git a/src/boot/stub.c b/src/boot/stub.c index 7261e942d3..c92df686c8 100644 --- a/src/boot/stub.c +++ b/src/boot/stub.c @@ -114,12 +114,9 @@ static EFI_STATUS combine_initrds( n += initrd_size; } - _cleanup_pages_ Pages pages = xmalloc_pages( - AllocateMaxAddress, - EfiLoaderData, - EFI_SIZE_TO_PAGES(n), - UINT32_MAX /* Below 4G boundary. */); + _cleanup_pages_ Pages pages = xmalloc_initrd_pages(n); uint8_t *p = PHYSICAL_ADDRESS_TO_POINTER(pages.addr); + FOREACH_ARRAY(i, initrds, n_initrds) { size_t pad; diff --git a/src/boot/util.h b/src/boot/util.h index c7634576cf..3164d520bd 100644 --- a/src/boot/util.h +++ b/src/boot/util.h @@ -99,6 +99,22 @@ static inline Pages xmalloc_pages( }; } +static inline Pages xmalloc_initrd_pages(size_t n_pages) { +#if defined(__i386__) || defined(__x86_64__) + return xmalloc_pages( + AllocateMaxAddress, + EfiLoaderData, + EFI_SIZE_TO_PAGES(n_pages), + UINT32_MAX /* Below 4G boundary. */); +#else + return xmalloc_pages( + AllocateAnyPages, + EfiLoaderData, + EFI_SIZE_TO_PAGES(n_pages), + 0 /* Ignored. */); +#endif +} + void convert_efi_path(char16_t *path); char16_t *xstr8_to_path(const char *stra); char16_t *mangle_stub_cmdline(char16_t *cmdline);