diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c index fc20c6563..6bbce3128 100644 --- a/grub-core/commands/minicmd.c +++ b/grub-core/commands/minicmd.c @@ -137,6 +137,9 @@ grub_mini_cmd_rmmod (struct grub_command *cmd __attribute__ ((unused)), if (! mod) return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such module"); + if (grub_dl_is_persistent (mod)) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "cannot unload persistent module"); + if (grub_dl_unref (mod) <= 0) grub_dl_unload (mod); diff --git a/include/grub/dl.h b/include/grub/dl.h index 2bca56ce0..fee27a14c 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -175,6 +175,7 @@ struct grub_dl { char *name; int ref_count; + int persistent; grub_dl_dep_t dep; grub_dl_segment_t segment; Elf_Sym *symtab; @@ -240,6 +241,18 @@ grub_dl_get (const char *name) return 0; } +static inline void +grub_dl_set_persistent (grub_dl_t mod) +{ + mod->persistent = 1; +} + +static inline int +grub_dl_is_persistent (grub_dl_t mod) +{ + return mod->persistent; +} + #endif grub_err_t grub_dl_register_symbol (const char *name, void *addr,