From ef32c71683bb2da03924fbf378150923eee22996 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 29 Nov 2019 21:31:17 +0100 Subject: [PATCH] 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. --- Kernel/Process.cpp | 5 ++++- Kernel/TestModule.cpp | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 5a8159acd3f..29597f145d7 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 section_storage_by_name; auto module = make(); - 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 ab4dfa84e91..a755d963fe7 100644 --- a/Kernel/TestModule.cpp +++ b/Kernel/TestModule.cpp @@ -1,6 +1,8 @@ #include #include +extern "C" const char module_name[] = "TestModule"; + extern "C" void module_init() { kprintf("TestModule has booted!\n");