diff --git a/apps/insmod.c b/apps/insmod.c index 4c3dae20..64261452 100644 --- a/apps/insmod.c +++ b/apps/insmod.c @@ -12,16 +12,13 @@ int main(int argc, char * argv[]) { if (argc < 2) { - fprintf(stderr, "Usage: %s \n", argv[0]); + fprintf(stderr, "Usage: %s [ARGS...]\n", argv[0]); return 1; } - int ret = 0; - for (int i = 1; i < argc; ++i) { - int status = sysfunc(TOARU_SYS_FUNC_INSMOD, &argv[i]); - if (status < 0) { - fprintf(stderr, "%s: %s: %s\n", argv[0], argv[i], strerror(errno)); - ret = 1; - } + int status = sysfunc(TOARU_SYS_FUNC_INSMOD, &argv[1]); + if (status != 0) { + fprintf(stderr, "%s: %s: %s\n", argv[0], argv[1], strerror(errno)); + return status; } - return ret; + return 0; } diff --git a/kernel/misc/elf64.c b/kernel/misc/elf64.c index c90c3915..7c793ec8 100644 --- a/kernel/misc/elf64.c +++ b/kernel/misc/elf64.c @@ -27,10 +27,10 @@ hashmap_t * modules_get_list(void) { return _modules_table; } -int elf_module(const char * path) { +int elf_module(char ** args) { Elf64_Header header; - fs_node_t * file = kopen(path,0); + fs_node_t * file = kopen(args[0],0); if (!file) { return -ENOENT; @@ -169,7 +169,11 @@ int elf_module(const char * path) { hashmap_set(_modules_table, moduleData->name, loadedData); - return moduleData->init(0,NULL); + /* Count arguments */ + int argc = 0; + for (char ** aa = args; *aa; ++aa) ++argc; + + return moduleData->init(argc, args); } int elf_exec(const char * path, fs_node_t * file, int argc, const char *const argv[], const char *const env[], int interp) { diff --git a/kernel/sys/syscall.c b/kernel/sys/syscall.c index 5cff5dc9..62a438c4 100644 --- a/kernel/sys/syscall.c +++ b/kernel/sys/syscall.c @@ -58,7 +58,7 @@ static long sys_sbrk(ssize_t size) { return (long)out; } -extern int elf_module(const char * path); +extern int elf_module(char ** args); static long sys_sysfunc(long fn, char ** args) { /* FIXME: Most of these should be top-level, many are hacks/broken in Misaka */ @@ -93,7 +93,8 @@ static long sys_sysfunc(long fn, char ** args) { if (!args) return -EFAULT; PTR_VALIDATE(args[0]); if (!args[0]) return -EFAULT; - return elf_module(args[0]); + for (char ** aa = args; *aa; ++aa) { PTR_VALIDATE(*aa); } + return elf_module(args); case TOARU_SYS_FUNC_SETHEAP: { /* I'm not really sure how this should be done... diff --git a/modules/test.c b/modules/test.c index 2ef31031..63f2d15f 100644 --- a/modules/test.c +++ b/modules/test.c @@ -1,9 +1,22 @@ #include #include +#include +#include static int init(int argc, char * argv[]) { - printf("Hello, modules.\n"); - *(volatile int*)0x60000000 = 42; + dprintf("Hello, modules.\n"); + dprintf("Received %d arguments.\n", argc); + + if (argc > 1 && !strcmp(argv[1], "--traceback")) { + arch_dump_traceback(); + } else if (argc > 1 && !strcmp(argv[1], "--fail")) { + return 1; + } else if (argc > 1 && !strcmp(argv[1], "--crash")) { + *(volatile int*)0x60000000 = 42; + } else if (argc > 1 && !strcmp(argv[1], "--assert")) { + assert(0 && "Intentional failure."); + } + return 0; }