summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-11-29 21:31:17 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-11-29 21:31:17 +0100
commitef32c71683bb2da03924fbf378150923eee22996 (patch)
tree4b507c3af086ec427142dd737e310192b081f407
parent86c61218a7da9988ffd2fa7a773fdeef8634d245 (diff)
downloadserenity-ef32c71683bb2da03924fbf378150923eee22996.zip
Kernel: Have modules export their name in a "module_name" string
This will show up in /proc/modules, and is also the name you can pass to the module_unload() syscall for unloading the module.
-rw-r--r--Kernel/Process.cpp5
-rw-r--r--Kernel/TestModule.cpp2
2 files changed, 6 insertions, 1 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index 5a8159acd3..29597f145d 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -3407,7 +3407,6 @@ int Process::sys$module_load(const char* path, size_t path_length)
HashMap<String, u8*> section_storage_by_name;
auto module = make<Module>();
- module->name = "FIXME";
elf_image->for_each_section_of_type(SHT_PROGBITS, [&](const ELFImage::Section& section) {
auto section_storage = KBuffer::copy(section.raw_data(), section.size());
@@ -3463,6 +3462,10 @@ int Process::sys$module_load(const char* path, size_t path_length)
module->module_init = (ModuleInitPtr)(text_base + symbol.value());
} else if (!strcmp(symbol.name(), "module_fini")) {
module->module_fini = (ModuleFiniPtr)(text_base + symbol.value());
+ } else if (!strcmp(symbol.name(), "module_name")) {
+ const u8* storage = section_storage_by_name.get(symbol.section().name()).value_or(nullptr);
+ if (storage)
+ module->name = String((const char*)(storage + symbol.value()));
}
return IterationDecision::Continue;
});
diff --git a/Kernel/TestModule.cpp b/Kernel/TestModule.cpp
index ab4dfa84e9..a755d963fe 100644
--- a/Kernel/TestModule.cpp
+++ b/Kernel/TestModule.cpp
@@ -1,6 +1,8 @@
#include <Kernel/kstdio.h>
#include <Kernel/Process.h>
+extern "C" const char module_name[] = "TestModule";
+
extern "C" void module_init()
{
kprintf("TestModule has booted!\n");