]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
dl: Provide a fake grub_dl_set_persistent() and grub_dl_is_persistent() for the emu...
authorDaniel Axtens <dja@axtens.net>
Tue, 10 Jun 2025 15:50:38 +0000 (21:20 +0530)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 26 Jun 2025 15:19:25 +0000 (17:19 +0200)
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 <dja@axtens.net>
Signed-off-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
include/grub/dl.h

index 84509c5c1acbbeae630fc143533e009c272e0cea..b8135c8f3dabaf879c9d50bd134630895ec5ee95 100644 (file)
@@ -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,