]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* grub-core/kern/efi/mm.c: Limit allocations to 2GiB when not compiling
authorVladimir Serbinenko <phcoder@gmail.com>
Fri, 22 Nov 2013 12:03:19 +0000 (13:03 +0100)
committerVladimir Serbinenko <phcoder@gmail.com>
Fri, 22 Nov 2013 12:03:19 +0000 (13:03 +0100)
with -mcmodel=large.

ChangeLog
grub-core/kern/efi/mm.c

index f610f49458e8e028ebe05bd47d3252dc5d900e97..0c6d7f4b8d3e0d1057fa646fcddd5d4361091aef 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-11-22  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       * grub-core/kern/efi/mm.c: Limit allocations to 2GiB when not compiling
+       with -mcmodel=large.
+
 2013-11-22  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * grub-core/kern/x86_64/dl.c (grub_arch_dl_relocate_symbols): Add
index 1409b5da9487cb63e359c075da6c946b0d5fcdf4..6e9dace915e1407b687297eebc926abd2bb8928c 100644 (file)
 #define BYTES_TO_PAGES(bytes)  (((bytes) + 0xfff) >> 12)
 #define PAGES_TO_BYTES(pages)  ((pages) << 12)
 
+#if defined (__code_model_large__) || !defined (__x86_64__)
+#define MAX_USABLE_ADDRESS 0xffffffff
+#else
+#define MAX_USABLE_ADDRESS 0x7fffffff
+#endif
+
 /* The size of a memory map obtained from the firmware. This must be
    a multiplier of 4KB.  */
 #define MEMORY_MAP_SIZE        0x3000
@@ -58,7 +64,7 @@ grub_efi_allocate_pages (grub_efi_physical_address_t address,
 
 #if 1
   /* Limit the memory access to less than 4GB for 32-bit platforms.  */
-  if (address > 0xffffffff)
+  if (address > MAX_USABLE_ADDRESS)
     return 0;
 #endif
 
@@ -66,7 +72,7 @@ grub_efi_allocate_pages (grub_efi_physical_address_t address,
   if (address == 0)
     {
       type = GRUB_EFI_ALLOCATE_MAX_ADDRESS;
-      address = 0xffffffff;
+      address = MAX_USABLE_ADDRESS;
     }
   else
     type = GRUB_EFI_ALLOCATE_ADDRESS;
@@ -86,7 +92,7 @@ grub_efi_allocate_pages (grub_efi_physical_address_t address,
     {
       /* Uggh, the address 0 was allocated... This is too annoying,
         so reallocate another one.  */
-      address = 0xffffffff;
+      address = MAX_USABLE_ADDRESS;
       status = efi_call_4 (b->allocate_pages, type, GRUB_EFI_LOADER_DATA, pages, &address);
       grub_efi_free_pages (0, pages);
       if (status != GRUB_EFI_SUCCESS)
@@ -319,7 +325,7 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map,
     {
       if (desc->type == GRUB_EFI_CONVENTIONAL_MEMORY
 #if 1
-         && desc->physical_start <= 0xffffffff
+         && desc->physical_start <= MAX_USABLE_ADDRESS
 #endif
          && desc->physical_start + PAGES_TO_BYTES (desc->num_pages) > 0x100000
          && desc->num_pages != 0)
@@ -337,9 +343,9 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map,
 #if 1
          if (BYTES_TO_PAGES (filtered_desc->physical_start)
              + filtered_desc->num_pages
-             > BYTES_TO_PAGES (0x100000000LL))
+             > BYTES_TO_PAGES (MAX_USABLE_ADDRESS+1LL))
            filtered_desc->num_pages
-             = (BYTES_TO_PAGES (0x100000000LL)
+             = (BYTES_TO_PAGES (MAX_USABLE_ADDRESS+1LL)
                 - BYTES_TO_PAGES (filtered_desc->physical_start));
 #endif