]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
Fix the chain load memory alloc failure in UEFI mode.
authorlongpanda <admin@ventoy.net>
Wed, 15 Jun 2022 12:50:25 +0000 (20:50 +0800)
committerlongpanda <admin@ventoy.net>
Wed, 15 Jun 2022 12:50:25 +0000 (20:50 +0800)
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_linux.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_unix.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_vhd.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_windows.c

index 410369504907ce27dbd5eb20416c3361365e7ef9..2f1faa3413f77fb250d8f8a249e2ff5707df8334 100644 (file)
@@ -38,6 +38,7 @@
 #include <grub/memory.h>
 #ifdef GRUB_MACHINE_EFI
 #include <grub/efi/efi.h>
+#include <grub/efi/memory.h>
 #endif
 #include <grub/ventoy.h>
 #include "ventoy_def.h"
@@ -135,6 +136,22 @@ int ventoy_is_efi_os(void)
     return g_efi_os;
 }
 
+void * ventoy_alloc_chain(grub_size_t size)
+{
+    void *p = NULL;
+
+    p = grub_malloc(size);
+#ifdef GRUB_MACHINE_EFI
+    if (!p)
+    {
+        p = grub_efi_allocate_any_pages(GRUB_EFI_BYTES_TO_PAGES(size));
+    }
+#endif
+
+    return p;
+}
+
+
 static int ventoy_arch_mode_init(void)
 {
     #ifdef GRUB_MACHINE_EFI
index 27209da60747fd1afe15a7ba53e9fc445cb6089b..d1163628a65d04c536d5e3388d2f594d4b5529fa 100644 (file)
@@ -1206,6 +1206,7 @@ grub_err_t ventoy_cmd_browser_dir(grub_extcmd_context_t ctxt, int argc, char **a
 grub_err_t ventoy_cmd_browser_disk(grub_extcmd_context_t ctxt, int argc, char **args);
 int ventoy_get_fs_type(const char *fs);
 int ventoy_img_name_valid(const char *filename, grub_size_t namelen);
+void * ventoy_alloc_chain(grub_size_t size);
 
 #endif /* __VENTOY_DEF_H__ */
 
index 37910c76cc2b7e1dec25bf15a7dcf03c59cd65ca..244a684ef8d4ab92d67f7b5de2beaf9ea25cb8cb 100644 (file)
@@ -1623,10 +1623,10 @@ grub_err_t ventoy_cmd_linux_chain_data(grub_extcmd_context_t ctxt, int argc, cha
         }
     }
 
-    chain = grub_malloc(size);
+    chain = ventoy_alloc_chain(size);
     if (!chain)
     {
-        grub_printf("Failed to alloc chain memory size %u\n", size);
+        grub_printf("Failed to alloc chain linux memory size %u\n", size);
         grub_file_close(file);
         return 1;
     }
index 8ff212488fb68b1799d78db78edf98d7fae65f03..005cb5eb7d3d9748996e3b6c8ba4904a85c1bbd6 100644 (file)
@@ -1185,10 +1185,10 @@ grub_err_t ventoy_cmd_unix_chain_data(grub_extcmd_context_t ctxt, int argc, char
         }
     }
 
-    chain = grub_malloc(size);
+    chain = ventoy_alloc_chain(size);
     if (!chain)
     {
-        grub_printf("Failed to alloc chain memory size %u\n", size);
+        grub_printf("Failed to alloc chain unix memory size %u\n", size);
         grub_file_close(file);
         return 1;
     }
index 7bc7d90f6b70ea0615530652358a1a40d93617b3..7aa3e8f0094a46591cf5eabc917fa937c552ebdc 100644 (file)
@@ -687,10 +687,10 @@ grub_err_t ventoy_cmd_raw_chain_data(grub_extcmd_context_t ctxt, int argc, char
         }
     }
 
-    chain = grub_malloc(size);
+    chain = ventoy_alloc_chain(size);
     if (!chain)
     {
-        grub_printf("Failed to alloc chain memory size %u\n", size);
+        grub_printf("Failed to alloc chain raw memory size %u\n", size);
         grub_file_close(file);
         return 1;
     }
index ba956080bc442dc91a44e7cb79bb89995f6f4c57..23bbc8b7e10183e8dfda37c3915994e4871ba998 100644 (file)
@@ -1896,10 +1896,10 @@ grub_err_t ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, c
         }
     }
 
-    chain = grub_malloc(size);
+    chain = ventoy_alloc_chain(size);
     if (!chain)
     {
-        grub_printf("Failed to alloc chain memory size %u\n", size);
+        grub_printf("Failed to alloc chain win1 memory size %u\n", size);
         grub_file_close(file);
         return 1;
     }
@@ -2129,10 +2129,10 @@ static grub_err_t ventoy_vlnk_wim_chain_data(grub_file_t wimfile)
         }
     }
 
-    chain = grub_malloc(size);
+    chain = ventoy_alloc_chain(size);
     if (!chain)
     {
-        grub_printf("Failed to alloc chain memory size %u\n", size);
+        grub_printf("Failed to alloc chain win2 memory size %u\n", size);
         grub_file_close(file);
         return 1;
     }
@@ -2294,10 +2294,10 @@ static grub_err_t ventoy_normal_wim_chain_data(grub_file_t wimfile)
         }
     }
 
-    chain = grub_malloc(size);
+    chain = ventoy_alloc_chain(size);
     if (!chain)
     {
-        grub_printf("Failed to alloc chain memory size %u\n", size);
+        grub_printf("Failed to alloc chain win3 memory size %u\n", size);
         grub_file_close(file);
         return 1;
     }