46968b6
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
46968b6
From: Daniel Axtens <dja@axtens.net>
46968b6
Date: Thu, 30 Jul 2020 00:13:21 +1000
46968b6
Subject: [PATCH] dl: provide a fake grub_dl_set_persistent for the emu target
46968b6
46968b6
Trying to start grub-emu with a module that calls grub_dl_set_persistent
46968b6
will crash because grub-emu fakes modules and passes NULL to the module
46968b6
init function.
46968b6
46968b6
Provide an empty function for the emu case.
46968b6
46968b6
Fixes: ee7808e2197c (dl: Add support for persistent modules)
46968b6
Signed-off-by: Daniel Axtens <dja@axtens.net>
46968b6
---
46968b6
 include/grub/dl.h | 11 +++++++++++
46968b6
 1 file changed, 11 insertions(+)
46968b6
46968b6
diff --git a/include/grub/dl.h b/include/grub/dl.h
e622855
index 2f76e6b043..20d870f2a4 100644
46968b6
--- a/include/grub/dl.h
46968b6
+++ b/include/grub/dl.h
46968b6
@@ -245,11 +245,22 @@ grub_dl_get (const char *name)
46968b6
   return 0;
46968b6
 }
46968b6
 
46968b6
+#ifdef GRUB_MACHINE_EMU
46968b6
+/*
46968b6
+ * Under grub-emu, modules are faked and NULL is passed to GRUB_MOD_INIT.
46968b6
+ * So we fake this out to avoid a NULL deref.
46968b6
+ */
46968b6
+static inline void
46968b6
+grub_dl_set_persistent (grub_dl_t mod __attribute__((unused)))
46968b6
+{
46968b6
+}
46968b6
+#else
46968b6
 static inline void
46968b6
 grub_dl_set_persistent (grub_dl_t mod)
46968b6
 {
46968b6
   mod->persistent = 1;
46968b6
 }
46968b6
+#endif
46968b6
 
46968b6
 static inline int
46968b6
 grub_dl_is_persistent (grub_dl_t mod)