From ba8eadde6be1a411e838d0914277bdc3f317cda1 Mon Sep 17 00:00:00 2001 From: Daniel Axtens Date: Tue, 10 Jun 2025 21:20:38 +0530 Subject: [PATCH] dl: Provide a fake grub_dl_set_persistent() and grub_dl_is_persistent() for the emu target Trying to start grub-emu with a module that calls grub_dl_set_persistent() and grub_dl_is_persistent() will crash because grub-emu fakes modules and passes NULL to the module init function. Provide an empty function for the emu case. Fixes: ee7808e2197c (dl: Add support for persistent modules) Signed-off-by: Daniel Axtens Signed-off-by: Sudhakar Kuppusamy Reviewed-by: Stefan Berger Reviewed-by: Avnish Chouhan Reviewed-by: Daniel Kiper --- include/grub/dl.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/include/grub/dl.h b/include/grub/dl.h index 84509c5c1..b8135c8f3 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -242,6 +242,25 @@ grub_dl_get (const char *name) return 0; } +#ifdef GRUB_MACHINE_EMU +/* + * Under grub-emu, modules are faked and NULL is passed to GRUB_MOD_INIT. + * So we fake this out to avoid a NULL deref. + */ +static inline void +grub_dl_set_persistent (grub_dl_t mod __attribute__((unused))) +{ +} + +/* + * Under grub-emu, modules are faked and NULL is passed to GRUB_MOD_INIT. + * So we fake this out to avoid a NULL deref. + */ +static inline int +grub_dl_is_persistent (grub_dl_t mod __attribute__((unused))) +{ +} +#else static inline void grub_dl_set_persistent (grub_dl_t mod) { @@ -253,7 +272,7 @@ grub_dl_is_persistent (grub_dl_t mod) { return mod->persistent; } - +#endif #endif grub_err_t grub_dl_register_symbol (const char *name, void *addr,