|
|
bbc6a89 |
From 4bc909bf89f5b4ff86c9e4e609d4fe0c11a66b0c Mon Sep 17 00:00:00 2001
|
|
|
bbc6a89 |
From: Vladimir Serbinenko <phcoder@gmail.com>
|
|
|
bbc6a89 |
Date: Mon, 7 Aug 2017 18:33:29 +0200
|
|
|
6f1e3d5 |
Subject: [PATCH 057/198] Remove grub_efi_allocate_pages.
|
|
|
bbc6a89 |
|
|
|
bbc6a89 |
grub_efi_allocate_pages Essentially does 2 unrelated things:
|
|
|
bbc6a89 |
* Allocate at fixed address.
|
|
|
bbc6a89 |
* Allocate at any address.
|
|
|
bbc6a89 |
|
|
|
bbc6a89 |
To switch between 2 different functions it uses address == 0 as magic
|
|
|
bbc6a89 |
value which is wrong as 0 is a perfectly valid fixed adress to allocate at.
|
|
|
bbc6a89 |
---
|
|
|
bbc6a89 |
grub-core/kern/arm/efi/misc.c | 4 ++--
|
|
|
bbc6a89 |
grub-core/kern/efi/mm.c | 30 ++++++++++++++----------------
|
|
|
bbc6a89 |
grub-core/loader/arm64/fdt.c | 2 +-
|
|
|
bbc6a89 |
grub-core/loader/arm64/linux.c | 7 +++----
|
|
|
bbc6a89 |
grub-core/loader/arm64/xen_boot.c | 7 +++----
|
|
|
bbc6a89 |
grub-core/loader/ia64/efi/linux.c | 10 +++++-----
|
|
|
bbc6a89 |
include/grub/autoefi.h | 2 +-
|
|
|
bbc6a89 |
include/grub/efi/efi.h | 4 +++-
|
|
|
bbc6a89 |
8 files changed, 32 insertions(+), 34 deletions(-)
|
|
|
bbc6a89 |
|
|
|
bbc6a89 |
diff --git a/grub-core/kern/arm/efi/misc.c b/grub-core/kern/arm/efi/misc.c
|
|
|
bbc6a89 |
index 7cd41842a..c95e8299d 100644
|
|
|
bbc6a89 |
--- a/grub-core/kern/arm/efi/misc.c
|
|
|
bbc6a89 |
+++ b/grub-core/kern/arm/efi/misc.c
|
|
|
bbc6a89 |
@@ -146,7 +146,7 @@ grub_efi_allocate_loader_memory (grub_uint32_t min_offset, grub_uint32_t size)
|
|
|
bbc6a89 |
continue;
|
|
|
bbc6a89 |
grub_dprintf("mm", "%s: let's allocate some (0x%x) pages @ 0x%08x...\n",
|
|
|
bbc6a89 |
__FUNCTION__, (size >> PAGE_SHIFT), (grub_addr_t) start);
|
|
|
bbc6a89 |
- mem = grub_efi_allocate_pages (start, (size >> PAGE_SHIFT) + 1);
|
|
|
bbc6a89 |
+ mem = grub_efi_allocate_fixed (start, (size >> PAGE_SHIFT) + 1);
|
|
|
bbc6a89 |
grub_dprintf("mm", "%s: retval=0x%08x\n",
|
|
|
bbc6a89 |
__FUNCTION__, (grub_addr_t) mem);
|
|
|
bbc6a89 |
if (! mem)
|
|
|
bbc6a89 |
@@ -189,7 +189,7 @@ grub_efi_prepare_platform (void)
|
|
|
bbc6a89 |
mmap_size = find_mmap_size ();
|
|
|
bbc6a89 |
if (! mmap_size)
|
|
|
bbc6a89 |
return GRUB_ERR_OUT_OF_MEMORY;
|
|
|
bbc6a89 |
- mmap_buf = grub_efi_allocate_pages (0, page_align (mmap_size) >> 12);
|
|
|
bbc6a89 |
+ mmap_buf = grub_efi_allocate_any_pages (page_align (mmap_size) >> 12);
|
|
|
bbc6a89 |
if (! mmap_buf)
|
|
|
bbc6a89 |
return GRUB_ERR_OUT_OF_MEMORY;
|
|
|
bbc6a89 |
|
|
|
bbc6a89 |
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
|
|
|
bbc6a89 |
index d88bc5e43..b97b05fe8 100644
|
|
|
bbc6a89 |
--- a/grub-core/kern/efi/mm.c
|
|
|
bbc6a89 |
+++ b/grub-core/kern/efi/mm.c
|
|
|
bbc6a89 |
@@ -83,20 +83,19 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
|
|
|
bbc6a89 |
}
|
|
|
bbc6a89 |
|
|
|
bbc6a89 |
void *
|
|
|
bbc6a89 |
-grub_efi_allocate_pages (grub_efi_physical_address_t address,
|
|
|
bbc6a89 |
- grub_efi_uintn_t pages)
|
|
|
bbc6a89 |
+grub_efi_allocate_any_pages (grub_efi_uintn_t pages)
|
|
|
bbc6a89 |
{
|
|
|
bbc6a89 |
- grub_efi_allocate_type_t alloctype;
|
|
|
bbc6a89 |
-
|
|
|
bbc6a89 |
- if (address == 0)
|
|
|
bbc6a89 |
- {
|
|
|
bbc6a89 |
- alloctype = GRUB_EFI_ALLOCATE_MAX_ADDRESS;
|
|
|
bbc6a89 |
- address = GRUB_EFI_MAX_USABLE_ADDRESS;
|
|
|
bbc6a89 |
- }
|
|
|
bbc6a89 |
- else
|
|
|
bbc6a89 |
- alloctype = GRUB_EFI_ALLOCATE_ADDRESS;
|
|
|
bbc6a89 |
+ return grub_efi_allocate_pages_real (GRUB_EFI_MAX_USABLE_ADDRESS,
|
|
|
bbc6a89 |
+ pages, GRUB_EFI_ALLOCATE_MAX_ADDRESS,
|
|
|
bbc6a89 |
+ GRUB_EFI_LOADER_DATA);
|
|
|
bbc6a89 |
+}
|
|
|
bbc6a89 |
|
|
|
bbc6a89 |
- return grub_efi_allocate_pages_real (address, pages, alloctype,
|
|
|
bbc6a89 |
+void *
|
|
|
bbc6a89 |
+grub_efi_allocate_fixed (grub_efi_physical_address_t address,
|
|
|
bbc6a89 |
+ grub_efi_uintn_t pages)
|
|
|
bbc6a89 |
+{
|
|
|
bbc6a89 |
+ return grub_efi_allocate_pages_real (address, pages,
|
|
|
bbc6a89 |
+ GRUB_EFI_ALLOCATE_ADDRESS,
|
|
|
bbc6a89 |
GRUB_EFI_LOADER_DATA);
|
|
|
bbc6a89 |
}
|
|
|
bbc6a89 |
|
|
|
bbc6a89 |
@@ -404,7 +403,7 @@ add_memory_regions (grub_efi_memory_descriptor_t *memory_map,
|
|
|
bbc6a89 |
pages = required_pages;
|
|
|
bbc6a89 |
}
|
|
|
bbc6a89 |
|
|
|
bbc6a89 |
- addr = grub_efi_allocate_pages (start, pages);
|
|
|
bbc6a89 |
+ addr = grub_efi_allocate_fixed (start, pages);
|
|
|
bbc6a89 |
if (! addr)
|
|
|
bbc6a89 |
grub_fatal ("cannot allocate conventional memory %p with %u pages",
|
|
|
bbc6a89 |
(void *) ((grub_addr_t) start),
|
|
|
bbc6a89 |
@@ -456,8 +455,7 @@ grub_efi_mm_init (void)
|
|
|
bbc6a89 |
int mm_status;
|
|
|
bbc6a89 |
|
|
|
bbc6a89 |
/* Prepare a memory region to store two memory maps. */
|
|
|
bbc6a89 |
- memory_map = grub_efi_allocate_pages (0,
|
|
|
bbc6a89 |
- 2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
|
|
|
bbc6a89 |
+ memory_map = grub_efi_allocate_any_pages (2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
|
|
|
bbc6a89 |
if (! memory_map)
|
|
|
bbc6a89 |
grub_fatal ("cannot allocate memory");
|
|
|
bbc6a89 |
|
|
|
bbc6a89 |
@@ -475,7 +473,7 @@ grub_efi_mm_init (void)
|
|
|
bbc6a89 |
/* Freeing/allocating operations may increase memory map size. */
|
|
|
bbc6a89 |
map_size += desc_size * 32;
|
|
|
bbc6a89 |
|
|
|
bbc6a89 |
- memory_map = grub_efi_allocate_pages (0, 2 * BYTES_TO_PAGES (map_size));
|
|
|
bbc6a89 |
+ memory_map = grub_efi_allocate_any_pages (2 * BYTES_TO_PAGES (map_size));
|
|
|
bbc6a89 |
if (! memory_map)
|
|
|
bbc6a89 |
grub_fatal ("cannot allocate memory");
|
|
|
bbc6a89 |
|
|
|
bbc6a89 |
diff --git a/grub-core/loader/arm64/fdt.c b/grub-core/loader/arm64/fdt.c
|
|
|
bbc6a89 |
index db49cf649..368001696 100644
|
|
|
bbc6a89 |
--- a/grub-core/loader/arm64/fdt.c
|
|
|
bbc6a89 |
+++ b/grub-core/loader/arm64/fdt.c
|
|
|
bbc6a89 |
@@ -50,7 +50,7 @@ grub_fdt_load (grub_size_t additional_size)
|
|
|
bbc6a89 |
size += additional_size;
|
|
|
bbc6a89 |
|
|
|
bbc6a89 |
grub_dprintf ("linux", "allocating %ld bytes for fdt\n", size);
|
|
|
bbc6a89 |
- fdt = grub_efi_allocate_pages (0, GRUB_EFI_BYTES_TO_PAGES (size));
|
|
|
bbc6a89 |
+ fdt = grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (size));
|
|
|
bbc6a89 |
if (!fdt)
|
|
|
bbc6a89 |
return NULL;
|
|
|
bbc6a89 |
|
|
|
bbc6a89 |
diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
|
|
|
bbc6a89 |
index 9519d2e4d..ee3fcaa86 100644
|
|
|
bbc6a89 |
--- a/grub-core/loader/arm64/linux.c
|
|
|
bbc6a89 |
+++ b/grub-core/loader/arm64/linux.c
|
|
|
bbc6a89 |
@@ -148,8 +148,7 @@ grub_arm64_uefi_boot_image (grub_addr_t addr, grub_size_t size, char *args)
|
|
|
bbc6a89 |
loaded_image->load_options_size = len =
|
|
|
bbc6a89 |
(grub_strlen (args) + 1) * sizeof (grub_efi_char16_t);
|
|
|
bbc6a89 |
loaded_image->load_options =
|
|
|
bbc6a89 |
- grub_efi_allocate_pages (0,
|
|
|
bbc6a89 |
- GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
|
|
|
bbc6a89 |
+ grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
|
|
|
bbc6a89 |
if (!loaded_image->load_options)
|
|
|
bbc6a89 |
return grub_errno;
|
|
|
bbc6a89 |
|
|
|
bbc6a89 |
@@ -223,7 +222,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
|
|
bbc6a89 |
grub_dprintf ("linux", "Loading initrd\n");
|
|
|
bbc6a89 |
|
|
|
bbc6a89 |
initrd_pages = (GRUB_EFI_BYTES_TO_PAGES (initrd_size));
|
|
|
bbc6a89 |
- initrd_mem = grub_efi_allocate_pages (0, initrd_pages);
|
|
|
bbc6a89 |
+ initrd_mem = grub_efi_allocate_any_pages (initrd_pages);
|
|
|
bbc6a89 |
if (!initrd_mem)
|
|
|
bbc6a89 |
{
|
|
|
bbc6a89 |
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
|
|
|
bbc6a89 |
@@ -277,7 +276,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
|
|
bbc6a89 |
grub_loader_unset();
|
|
|
bbc6a89 |
|
|
|
bbc6a89 |
grub_dprintf ("linux", "kernel file size: %lld\n", (long long) kernel_size);
|
|
|
bbc6a89 |
- kernel_addr = grub_efi_allocate_pages (0, GRUB_EFI_BYTES_TO_PAGES (kernel_size));
|
|
|
bbc6a89 |
+ kernel_addr = grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (kernel_size));
|
|
|
bbc6a89 |
grub_dprintf ("linux", "kernel numpages: %lld\n",
|
|
|
bbc6a89 |
(long long) GRUB_EFI_BYTES_TO_PAGES (kernel_size));
|
|
|
bbc6a89 |
if (!kernel_addr)
|
|
|
bbc6a89 |
diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c
|
|
|
bbc6a89 |
index 27ede46ca..6c145a771 100644
|
|
|
bbc6a89 |
--- a/grub-core/loader/arm64/xen_boot.c
|
|
|
bbc6a89 |
+++ b/grub-core/loader/arm64/xen_boot.c
|
|
|
bbc6a89 |
@@ -324,10 +324,9 @@ xen_boot_binary_load (struct xen_boot_binary *binary, grub_file_t file,
|
|
|
bbc6a89 |
grub_dprintf ("xen_loader", "Xen_boot file size: 0x%lx\n", binary->size);
|
|
|
bbc6a89 |
|
|
|
bbc6a89 |
binary->start
|
|
|
bbc6a89 |
- = (grub_addr_t) grub_efi_allocate_pages (0,
|
|
|
bbc6a89 |
- GRUB_EFI_BYTES_TO_PAGES
|
|
|
bbc6a89 |
- (binary->size +
|
|
|
bbc6a89 |
- binary->align));
|
|
|
bbc6a89 |
+ = (grub_addr_t) grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES
|
|
|
bbc6a89 |
+ (binary->size +
|
|
|
bbc6a89 |
+ binary->align));
|
|
|
bbc6a89 |
if (!binary->start)
|
|
|
bbc6a89 |
{
|
|
|
bbc6a89 |
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
|
|
|
bbc6a89 |
diff --git a/grub-core/loader/ia64/efi/linux.c b/grub-core/loader/ia64/efi/linux.c
|
|
|
bbc6a89 |
index efaa42ccd..750330d45 100644
|
|
|
bbc6a89 |
--- a/grub-core/loader/ia64/efi/linux.c
|
|
|
bbc6a89 |
+++ b/grub-core/loader/ia64/efi/linux.c
|
|
|
bbc6a89 |
@@ -252,7 +252,7 @@ allocate_pages (grub_uint64_t align, grub_uint64_t size_pages,
|
|
|
bbc6a89 |
aligned_start += align;
|
|
|
bbc6a89 |
if (aligned_start + size > end)
|
|
|
bbc6a89 |
continue;
|
|
|
bbc6a89 |
- mem = grub_efi_allocate_pages (aligned_start, size_pages);
|
|
|
bbc6a89 |
+ mem = grub_efi_allocate_fixed (aligned_start, size_pages);
|
|
|
bbc6a89 |
if (! mem)
|
|
|
bbc6a89 |
{
|
|
|
bbc6a89 |
grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate memory");
|
|
|
bbc6a89 |
@@ -326,7 +326,7 @@ grub_linux_boot (void)
|
|
|
bbc6a89 |
mmap_size = find_mmap_size ();
|
|
|
bbc6a89 |
if (! mmap_size)
|
|
|
bbc6a89 |
return grub_errno;
|
|
|
bbc6a89 |
- mmap_buf = grub_efi_allocate_pages (0, page_align (mmap_size) >> 12);
|
|
|
bbc6a89 |
+ mmap_buf = grub_efi_allocate_any_pages (page_align (mmap_size) >> 12);
|
|
|
bbc6a89 |
if (! mmap_buf)
|
|
|
bbc6a89 |
return grub_error (GRUB_ERR_IO, "cannot allocate memory map");
|
|
|
bbc6a89 |
err = grub_efi_finish_boot_services (&mmap_size, mmap_buf, &map_key,
|
|
|
bbc6a89 |
@@ -422,7 +422,7 @@ grub_load_elf64 (grub_file_t file, void *buffer, const char *filename)
|
|
|
bbc6a89 |
relocate = grub_env_get ("linux_relocate");
|
|
|
bbc6a89 |
if (!relocate || grub_strcmp (relocate, "force") != 0)
|
|
|
bbc6a89 |
{
|
|
|
bbc6a89 |
- kernel_mem = grub_efi_allocate_pages (low_addr, kernel_pages);
|
|
|
bbc6a89 |
+ kernel_mem = grub_efi_allocate_fixed (low_addr, kernel_pages);
|
|
|
bbc6a89 |
reloc_offset = 0;
|
|
|
bbc6a89 |
}
|
|
|
bbc6a89 |
/* Try to relocate. */
|
|
|
bbc6a89 |
@@ -524,7 +524,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
|
|
bbc6a89 |
len += grub_strlen (argv[i]) + 1;
|
|
|
bbc6a89 |
len += sizeof (struct ia64_boot_param) + 512; /* Room for extensions. */
|
|
|
bbc6a89 |
boot_param_pages = page_align (len) >> 12;
|
|
|
bbc6a89 |
- boot_param = grub_efi_allocate_pages (0, boot_param_pages);
|
|
|
bbc6a89 |
+ boot_param = grub_efi_allocate_any_pages (boot_param_pages);
|
|
|
bbc6a89 |
if (boot_param == 0)
|
|
|
bbc6a89 |
{
|
|
|
bbc6a89 |
grub_error (GRUB_ERR_OUT_OF_MEMORY,
|
|
|
bbc6a89 |
@@ -589,7 +589,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
|
|
bbc6a89 |
grub_dprintf ("linux", "Loading initrd\n");
|
|
|
bbc6a89 |
|
|
|
bbc6a89 |
initrd_pages = (page_align (initrd_size) >> 12);
|
|
|
bbc6a89 |
- initrd_mem = grub_efi_allocate_pages (0, initrd_pages);
|
|
|
bbc6a89 |
+ initrd_mem = grub_efi_allocate_any_pages (initrd_pages);
|
|
|
bbc6a89 |
if (! initrd_mem)
|
|
|
bbc6a89 |
{
|
|
|
bbc6a89 |
grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate pages");
|
|
|
bbc6a89 |
diff --git a/include/grub/autoefi.h b/include/grub/autoefi.h
|
|
|
bbc6a89 |
index b75591176..b7a252e07 100644
|
|
|
bbc6a89 |
--- a/include/grub/autoefi.h
|
|
|
bbc6a89 |
+++ b/include/grub/autoefi.h
|
|
|
bbc6a89 |
@@ -55,7 +55,7 @@ static inline grub_err_t grub_autoefi_prepare (void)
|
|
|
bbc6a89 |
# define SYSTEM_TABLE_PTR GRUB_EFIEMU_SYSTEM_TABLE_PTR
|
|
|
bbc6a89 |
# define SIZEOF_OF_UINTN GRUB_EFIEMU_SIZEOF_OF_UINTN
|
|
|
bbc6a89 |
# define SYSTEM_TABLE GRUB_EFIEMU_SYSTEM_TABLE
|
|
|
bbc6a89 |
-# define grub_efi_allocate_pages(x,y) (x)
|
|
|
bbc6a89 |
+# define grub_efi_allocate_fixed(x,y) (x)
|
|
|
bbc6a89 |
# define grub_efi_free_pages(x,y) GRUB_EFI_SUCCESS
|
|
|
bbc6a89 |
# define grub_autoefi_finish_boot_services grub_efiemu_finish_boot_services
|
|
|
bbc6a89 |
# define EFI_PRESENT 1
|
|
|
bbc6a89 |
diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
|
|
|
bbc6a89 |
index b4cbebf38..3fa082816 100644
|
|
|
bbc6a89 |
--- a/include/grub/efi/efi.h
|
|
|
bbc6a89 |
+++ b/include/grub/efi/efi.h
|
|
|
bbc6a89 |
@@ -43,8 +43,10 @@ EXPORT_FUNC(grub_efi_allocate_pages_real) (grub_efi_physical_address_t address,
|
|
|
bbc6a89 |
grub_efi_allocate_type_t alloctype,
|
|
|
bbc6a89 |
grub_efi_memory_type_t memtype);
|
|
|
bbc6a89 |
void *
|
|
|
bbc6a89 |
-EXPORT_FUNC(grub_efi_allocate_pages) (grub_efi_physical_address_t address,
|
|
|
bbc6a89 |
+EXPORT_FUNC(grub_efi_allocate_fixed) (grub_efi_physical_address_t address,
|
|
|
bbc6a89 |
grub_efi_uintn_t pages);
|
|
|
bbc6a89 |
+void *
|
|
|
bbc6a89 |
+EXPORT_FUNC(grub_efi_allocate_any_pages) (grub_efi_uintn_t pages);
|
|
|
bbc6a89 |
void EXPORT_FUNC(grub_efi_free_pages) (grub_efi_physical_address_t address,
|
|
|
bbc6a89 |
grub_efi_uintn_t pages);
|
|
|
bbc6a89 |
int
|
|
|
bbc6a89 |
--
|
|
|
da63b36 |
2.14.3
|
|
|
bbc6a89 |
|