From d786bb7646a4e2a43f67f819d5f129ca6391b67c Mon Sep 17 00:00:00 2001 From: John Hodge Date: Mon, 16 Sep 2013 13:18:47 +0800 Subject: [PATCH] Usermode/insmod - Added insmod program (and relevant syscall) --- KernelLand/Kernel/syscalls.c | 15 +++++++- Usermode/Applications/insmod_src/Makefile | 10 ++++++ Usermode/Applications/insmod_src/main.c | 44 +++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 Usermode/Applications/insmod_src/Makefile create mode 100644 Usermode/Applications/insmod_src/main.c diff --git a/KernelLand/Kernel/syscalls.c b/KernelLand/Kernel/syscalls.c index 85fbbf8c..96f1f854 100644 --- a/KernelLand/Kernel/syscalls.c +++ b/KernelLand/Kernel/syscalls.c @@ -203,7 +203,20 @@ void SyscallHandler(tSyscallRegs *Regs) // Path, *Entrypoint ret = Binary_Load((char*)Regs->Arg1, (Uint*)Regs->Arg2); break; - + + // -- Load a kernel module + case SYS_LOADMOD: + CHECK_STR_NONULL( (const char *)Regs->Arg1 ); + if( Threads_GetUID() != 0 ) { + MERR("Not root"); + ret = EACCES; + } + else { + LOG("Module_LoadFile(\"%s\", NULL)", (const char *)Regs->Arg1); + ret = Module_LoadFile( (const char *)Regs->Arg1, NULL ); + } + break; + // --- // Virtual Filesystem // --- diff --git a/Usermode/Applications/insmod_src/Makefile b/Usermode/Applications/insmod_src/Makefile new file mode 100644 index 00000000..0f41c356 --- /dev/null +++ b/Usermode/Applications/insmod_src/Makefile @@ -0,0 +1,10 @@ +# Project: insmod + +-include ../Makefile.cfg + +DIR = SBin +OBJ = main.o +BIN = insmod + +-include ../Makefile.tpl + diff --git a/Usermode/Applications/insmod_src/main.c b/Usermode/Applications/insmod_src/main.c new file mode 100644 index 00000000..78ad0a9b --- /dev/null +++ b/Usermode/Applications/insmod_src/main.c @@ -0,0 +1,44 @@ +/* + * Acess2 OS Userland - insmod + * - By John Hodge (thePowersGang) + * + * main.c + * - Core + */ +#include +#include +#include + +#define MODDIR "/Acess/Modules/" + +// === CODE === +void Usage(const char *progname) +{ + fprintf(stderr, "Usage: %s \n", progname); +} + + +int main(int argc, char *argv[]) +{ + if( argc != 2 ) { + Usage(argv[0]); + return 1; + } + + const char *modname = argv[1]; + + char path[strlen(MODDIR)+strlen(modname)+1]; + strcpy(path, MODDIR); + strcat(path, modname); + + int rv = _SysLoadModule(path); + if( rv ) + { + fprintf(stderr, "_SysLoadModule(\"%s\"): %s\n", path, strerror(rv)); + } + else { + printf("Loaded module '%s'\n", path); + } + + return 0; +} -- 2.20.1