nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0066-Use-grub_efi_.-memory-helpers-where-reasonable.patch

5593c8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
5593c8
From: Peter Jones <pjones@redhat.com>
5593c8
Date: Thu, 1 Jun 2017 10:06:38 -0400
5593c8
Subject: [PATCH] Use grub_efi_...() memory helpers where reasonable.
5593c8
5593c8
This uses grub_efi_allocate_pool(), grub_efi_free_pool(), and
5593c8
grub_efi_free_pages() instead of open-coded efi_call_N() calls, so we
5593c8
get more reasonable type checking.
5593c8
5593c8
Signed-off-by: Peter Jones <pjones@redhat.com>
5593c8
---
5593c8
 grub-core/loader/efi/chainloader.c | 24 +++++++++---------------
5593c8
 1 file changed, 9 insertions(+), 15 deletions(-)
5593c8
5593c8
diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
d3c3ab
index 3ff305b1d32..ba3d2930197 100644
5593c8
--- a/grub-core/loader/efi/chainloader.c
5593c8
+++ b/grub-core/loader/efi/chainloader.c
5593c8
@@ -65,7 +65,7 @@ grub_chainloader_unload (void)
5593c8
 
5593c8
   b = grub_efi_system_table->boot_services;
5593c8
   efi_call_1 (b->unload_image, image_handle);
5593c8
-  efi_call_2 (b->free_pages, address, pages);
5593c8
+  grub_efi_free_pages (address, pages);
5593c8
 
5593c8
   grub_free (file_path);
5593c8
   grub_free (cmdline);
5593c8
@@ -108,7 +108,7 @@ grub_chainloader_boot (void)
5593c8
     }
5593c8
 
5593c8
   if (exit_data)
5593c8
-    efi_call_1 (b->free_pool, exit_data);
5593c8
+    grub_efi_free_pool (exit_data);
5593c8
 
5593c8
   grub_loader_unset ();
5593c8
 
5593c8
@@ -523,10 +523,9 @@ grub_efi_get_media_file_path (grub_efi_device_path_t *dp)
5593c8
 static grub_efi_boolean_t
5593c8
 handle_image (void *data, grub_efi_uint32_t datasize)
5593c8
 {
5593c8
-  grub_efi_boot_services_t *b;
5593c8
   grub_efi_loaded_image_t *li, li_bak;
5593c8
   grub_efi_status_t efi_status;
5593c8
-  char *buffer = NULL;
5593c8
+  void *buffer = NULL;
5593c8
   char *buffer_aligned = NULL;
5593c8
   grub_efi_uint32_t i;
5593c8
   struct grub_pe32_section_table *section;
5593c8
@@ -537,8 +536,6 @@ handle_image (void *data, grub_efi_uint32_t datasize)
5593c8
   int found_entry_point = 0;
5593c8
   int rc;
5593c8
 
5593c8
-  b = grub_efi_system_table->boot_services;
5593c8
-
5593c8
   rc = read_header (data, datasize, &context);
5593c8
   if (rc < 0)
5593c8
     {
5593c8
@@ -578,8 +575,8 @@ handle_image (void *data, grub_efi_uint32_t datasize)
5593c8
   grub_dprintf ("chain", "image size is %08"PRIxGRUB_UINT64_T", datasize is %08x\n",
5593c8
 	       context.image_size, datasize);
5593c8
 
5593c8
-  efi_status = efi_call_3 (b->allocate_pool, GRUB_EFI_LOADER_DATA,
5593c8
-			   buffer_size, &buffer);
5593c8
+  efi_status = grub_efi_allocate_pool (GRUB_EFI_LOADER_DATA, buffer_size,
5593c8
+				       &buffer);
5593c8
 
5593c8
   if (efi_status != GRUB_EFI_SUCCESS)
5593c8
     {
5593c8
@@ -811,14 +808,14 @@ handle_image (void *data, grub_efi_uint32_t datasize)
5593c8
 
5593c8
   grub_dprintf ("chain", "entry_point returned %ld\n", efi_status);
5593c8
   grub_memcpy (li, &li_bak, sizeof (grub_efi_loaded_image_t));
5593c8
-  efi_status = efi_call_1 (b->free_pool, buffer);
5593c8
+  efi_status = grub_efi_free_pool (buffer);
5593c8
 
5593c8
   return 1;
5593c8
 
5593c8
 error_exit:
5593c8
   grub_dprintf ("chain", "error_exit: grub_errno: %d\n", grub_errno);
5593c8
   if (buffer)
5593c8
-      efi_call_1 (b->free_pool, buffer);
5593c8
+    grub_efi_free_pool (buffer);
5593c8
 
5593c8
   return 0;
5593c8
 }
5593c8
@@ -826,10 +823,7 @@ error_exit:
5593c8
 static grub_err_t
5593c8
 grub_secureboot_chainloader_unload (void)
5593c8
 {
5593c8
-  grub_efi_boot_services_t *b;
5593c8
-
5593c8
-  b = grub_efi_system_table->boot_services;
5593c8
-  efi_call_2 (b->free_pages, address, pages);
5593c8
+  grub_efi_free_pages (address, pages);
5593c8
   grub_free (file_path);
5593c8
   grub_free (cmdline);
5593c8
   cmdline = 0;
5593c8
@@ -1096,7 +1090,7 @@ fail:
5593c8
   grub_free (file_path);
5593c8
 
5593c8
   if (address)
5593c8
-    efi_call_2 (b->free_pages, address, pages);
5593c8
+    grub_efi_free_pages (address, pages);
5593c8
 
5593c8
   if (cmdline)
5593c8
     grub_free (cmdline);