nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0354-dl-provide-a-fake-grub_dl_set_persistent-for-the-emu.patch

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