From: longpanda Date: Wed, 15 Jun 2022 12:50:25 +0000 (+0800) Subject: Fix the chain load memory alloc failure in UEFI mode. X-Git-Tag: v1.0.77~6 X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/Ventoy.git/commitdiff_plain/0f3d48b3d92e1ed3d71efe34e2c8025477e91ed3?ds=inline Fix the chain load memory alloc failure in UEFI mode. --- diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c index 4103695..2f1faa3 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c @@ -38,6 +38,7 @@ #include #ifdef GRUB_MACHINE_EFI #include +#include #endif #include #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 diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h index 27209da..d116362 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h @@ -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__ */ diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_linux.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_linux.c index 37910c7..244a684 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_linux.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_linux.c @@ -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; } diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_unix.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_unix.c index 8ff2124..005cb5e 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_unix.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_unix.c @@ -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; } diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_vhd.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_vhd.c index 7bc7d90..7aa3e8f 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_vhd.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_vhd.c @@ -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; } diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_windows.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_windows.c index ba95608..23bbc8b 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_windows.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_windows.c @@ -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; }