Blame SOURCES/0237-linux.c-Ensure-that-initrd-is-page-aligned.patch

6b3c76
From f38d60a9c4bf9b695f40376d16b14da11456f59b Mon Sep 17 00:00:00 2001
a85e8e
From: Vladimir Serbinenko <phcoder@gmail.com>
a85e8e
Date: Thu, 7 May 2015 16:23:39 +0200
6b3c76
Subject: [PATCH 237/261] linux.c: Ensure that initrd is page-aligned.
a85e8e
a85e8e
---
a85e8e
 grub-core/loader/i386/linux.c | 11 +++++------
a85e8e
 1 file changed, 5 insertions(+), 6 deletions(-)
a85e8e
a85e8e
diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
6b3c76
index 53f74ae06..764cde203 100644
a85e8e
--- a/grub-core/loader/i386/linux.c
a85e8e
+++ b/grub-core/loader/i386/linux.c
a85e8e
@@ -70,7 +70,6 @@ static grub_addr_t prot_mode_target;
a85e8e
 static void *initrd_mem;
a85e8e
 static grub_addr_t initrd_mem_target;
a85e8e
 static grub_size_t prot_init_space;
a85e8e
-static grub_uint32_t initrd_pages;
a85e8e
 static struct grub_relocator *relocator = NULL;
a85e8e
 static void *efi_mmap_buf;
a85e8e
 static grub_size_t maximal_cmdline_size;
a85e8e
@@ -1055,7 +1054,7 @@ static grub_err_t
a85e8e
 grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
a85e8e
 		 int argc, char *argv[])
a85e8e
 {
a85e8e
-  grub_size_t size = 0;
a85e8e
+  grub_size_t size = 0, aligned_size = 0;
a85e8e
   grub_addr_t addr_min, addr_max;
a85e8e
   grub_addr_t addr;
a85e8e
   grub_err_t err;
a85e8e
@@ -1077,8 +1076,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
a85e8e
     goto fail;
a85e8e
 
a85e8e
   size = grub_get_initrd_size (&initrd_ctx);
a85e8e
-
a85e8e
-  initrd_pages = (page_align (size) >> 12);
a85e8e
+  aligned_size = ALIGN_UP (size, 4096);
a85e8e
 
a85e8e
   /* Get the highest address available for the initrd.  */
a85e8e
   if (grub_le_to_cpu16 (linux_params.version) >= 0x0203)
a85e8e
@@ -1106,7 +1104,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
a85e8e
   addr_min = (grub_addr_t) prot_mode_target + prot_init_space;
a85e8e
 
a85e8e
   /* Put the initrd as high as possible, 4KiB aligned.  */
a85e8e
-  addr = (addr_max - size) & ~0xFFF;
a85e8e
+  addr = (addr_max - aligned_size) & ~0xFFF;
a85e8e
 
a85e8e
   if (addr < addr_min)
a85e8e
     {
a85e8e
@@ -1117,7 +1115,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
a85e8e
   {
a85e8e
     grub_relocator_chunk_t ch;
a85e8e
     err = grub_relocator_alloc_chunk_align (relocator, &ch,
a85e8e
-					    addr_min, addr, size, 0x1000,
a85e8e
+					    addr_min, addr, aligned_size,
a85e8e
+					    0x1000,
a85e8e
 					    GRUB_RELOCATOR_PREFERENCE_HIGH,
a85e8e
 					    1);
a85e8e
     if (err)
6b3c76
-- 
6b3c76
2.13.5
6b3c76