diff --git a/kernel/misc/debug_shell.c b/kernel/misc/debug_shell.c index 1112425d..3f04715e 100644 --- a/kernel/misc/debug_shell.c +++ b/kernel/misc/debug_shell.c @@ -623,6 +623,11 @@ static int shell_mod(fs_node_t * tty, int argc, char * argv[]) { fs_printf(tty, "Okay, going to load a module!\n"); module_defs * mod_info = module_load(argv[1]); + if (!mod_info) { + fs_printf(tty, "Something went wrong, failed to load module: %s\n", argv[1]); + return 1; + } + fs_printf(tty, "Loaded %s!\n", mod_info->name); return 0; diff --git a/kernel/sys/module.c b/kernel/sys/module.c index c9ba637c..33b14714 100644 --- a/kernel/sys/module.c +++ b/kernel/sys/module.c @@ -102,7 +102,9 @@ void * module_load(char * filename) { char * name = (char *)((uintptr_t)symstrtab + table->st_name); if (table->st_shndx == 0) { if (!hashmap_get(symboltable, name)) { - debug_print(WARNING, "Unresolved symbol in module: %s", name); + debug_print(ERROR, "Unresolved symbol in module: %s", name); + debug_print(ERROR, "Did you forget to load a dependency?"); + goto mod_load_error; } } else { Elf32_Shdr * s = NULL; diff --git a/modules/test.c b/modules/test.c index b97b80f0..50257b8e 100644 --- a/modules/test.c +++ b/modules/test.c @@ -8,13 +8,12 @@ extern char * special_thing; char test_module_string[] = "I am a char[] in the module."; char * test_module_string_ptr = "I am a char * in the module."; -static int a_function(void) { - debug_print(WARNING, ("I am a static function in the module.")); +int a_function(void) { + debug_print(WARNING, ("I am an exported function in the module.")); return 42; } -int b_function(void) { - debug_print(NOTICE, "I am a global function in a module!"); +static int hello(void) { debug_print(NOTICE, special_thing); a_function(); debug_print(NOTICE, test_module_string); @@ -33,10 +32,10 @@ int b_function(void) { return 25; } -int goodbye(void) { +static int goodbye(void) { debug_print(NOTICE, "Goodbye!"); return 0; } -MODULE_DEF(test, b_function, goodbye); +MODULE_DEF(test, hello, goodbye); diff --git a/modules/testb.c b/modules/testb.c new file mode 100644 index 00000000..b7a539ad --- /dev/null +++ b/modules/testb.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include + +extern int a_function(void); + +static int hello(void) { + debug_print(NOTICE, "Calling a_function from other module."); + a_function(); + return 0; +} + +static int goodbye(void) { + debug_print(NOTICE, "Goodbye!"); + return 0; +} + +MODULE_DEF(testb, hello, goodbye); +