From 9a8032b4791405aef22518e42c80c5b66ff2d7b8 Mon Sep 17 00:00:00 2001 From: Conrad Pankoff Date: Tue, 24 Dec 2019 11:40:26 +1100 Subject: [PATCH] Kernel: Disallow loading a module twice without explicitly unloading it This ensures that a module has the chance to run its cleanup functions before it's taken out of service. --- Kernel/Process.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 30d223fb6af..62dedc85d0e 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -3699,6 +3699,11 @@ int Process::sys$module_load(const char* path, size_t path_length) if (!module->module_init) return -EINVAL; + if (g_modules->contains(module->name)) { + dbg() << "a module with the name " << module->name << " is already loaded; please unload it first"; + return -EEXIST; + } + module->module_init(); auto name = module->name;