forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kernel: Implement very simple kernel module loading
It's now possible to load a .o file into the kernel via a syscall. The kernel will perform all the necessary ELF relocations, and then call the "module_init" symbol in the loaded module.
- Loading branch information
1 parent
c10a5ac
commit 6b150c7
Showing
11 changed files
with
198 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include <AK/String.h> | ||
#include <AK/Vector.h> | ||
#include <Kernel/KBuffer.h> | ||
|
||
struct Module { | ||
String name; | ||
Vector<KBuffer> sections; | ||
}; | ||
|
||
typedef void* (*ModuleInitPtr)(); | ||
typedef void* (*ModuleFiniPtr)(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <Kernel/kstdio.h> | ||
|
||
extern "C" void outside_func(); | ||
|
||
extern "C" void module_init() | ||
{ | ||
kprintf("TestModule has booted!\n"); | ||
|
||
for (int i = 0; i < 99; ++i) { | ||
kprintf("i is now %d\n", i); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <Kernel/Syscall.h> | ||
#include <errno.h> | ||
#include <serenity.h> | ||
|
||
extern "C" { | ||
|
||
int module_load(const char* path, size_t path_length) | ||
{ | ||
int rc = syscall(SC_module_load, path, path_length); | ||
__RETURN_WITH_ERRNO(rc, rc, -1); | ||
} | ||
|
||
int module_unload(const char* name, size_t name_length) | ||
{ | ||
int rc = syscall(SC_module_unload, name, name_length); | ||
__RETURN_WITH_ERRNO(rc, rc, -1); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <serenity.h> | ||
#include <string.h> | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
(void)argc; | ||
(void)argv; | ||
const char* path = "/TestModule.o"; | ||
int rc = module_load(path, strlen(path)); | ||
if (rc < 0) { | ||
perror("module_load"); | ||
return 1; | ||
} | ||
return 0; | ||
} |