diff options
-rw-r--r-- | com32/elflink/elf_module.c | 7 | ||||
-rw-r--r-- | com32/elflink/test_com32.c | 24 |
2 files changed, 29 insertions, 2 deletions
diff --git a/com32/elflink/elf_module.c b/com32/elflink/elf_module.c index fedebf7f..64c7b977 100644 --- a/com32/elflink/elf_module.c +++ b/com32/elflink/elf_module.c @@ -842,8 +842,8 @@ int module_load(struct elf_module *module) { // The file image is no longer needed image_unload(module); - DBG_PRINT("MODULE %s LOADED SUCCESSFULLY (&init@0x%08X, &exit@0x%08X)\n", - module->name, module->init_func, module->exit_func); + DBG_PRINT("MODULE %s LOADED SUCCESSFULLY (init@0x%08X, exit@0x%08X)\n", + module->name, *(module->init_func), *(module->exit_func)); return 0; @@ -917,6 +917,9 @@ int module_unload(struct elf_module *module) { // Release the loaded segments or sections elf_free(module->module_addr); + + DBG_PRINT("%s MODULE %s UNLOADED\n", module->shallow ? "SHALLOW" : "", + module->name); // Release the module structure free(module); diff --git a/com32/elflink/test_com32.c b/com32/elflink/test_com32.c index b9f20bd2..8404864f 100644 --- a/com32/elflink/test_com32.c +++ b/com32/elflink/test_com32.c @@ -63,6 +63,24 @@ int modules_com32_load(char *name) { return res; } +void modules_com32_unload(char *name) { + char full_name[MODULE_NAME_SIZE]; + + strcpy(full_name, ELF_DIRECTORY); + strcat(full_name, name); + + struct elf_module *module = module_find(full_name); + + if (module != NULL) { + if (*(module->exit_func) != NULL) { + (*(module->exit_func))(); + } + module_unload(module); + } else { + printf("Cannot find module %s for unloading\n", full_name); + } +} + void print_usage() { printf("Usage: test_com32 module ...\n"); printf("Where:\n"); @@ -91,10 +109,16 @@ int main(int argc, char **argv) { // Initializing the module subsystem res = modules_com32_setup(); + // Load the modules... for (i = 0; i < argc; i++) { modules_com32_load(argv[i]); } + // ...then unload them + for (i = argc-1; i >= 0; i--) { + modules_com32_unload(argv[i]); + } + modules_com32_finalize(); return 0; |