diff options
Diffstat (limited to 'com32/lib/sys')
-rw-r--r-- | com32/lib/sys/module/common.c | 9 | ||||
-rw-r--r-- | com32/lib/sys/module/elf_module.c | 9 | ||||
-rw-r--r-- | com32/lib/sys/module/exec.c | 12 |
3 files changed, 25 insertions, 5 deletions
diff --git a/com32/lib/sys/module/common.c b/com32/lib/sys/module/common.c index 9934a7a4..387dc1a3 100644 --- a/com32/lib/sys/module/common.c +++ b/com32/lib/sys/module/common.c @@ -316,12 +316,19 @@ int check_symbols(struct elf_module *module) { return 0; } +int module_unloadable(struct elf_module *module) { + if (!list_empty(&module->dependants)) + return 0; + + return 1; +} + // Unloads the module from the system and releases all the associated memory int module_unload(struct elf_module *module) { struct module_dep *crt_dep, *tmp; // Make sure nobody needs us - if (!list_empty(&module->dependants)) { + if (!module_unloadable(module)) { DBG_PRINT("Module is required by other modules.\n"); return -1; } diff --git a/com32/lib/sys/module/elf_module.c b/com32/lib/sys/module/elf_module.c index 2952e617..ba535f45 100644 --- a/com32/lib/sys/module/elf_module.c +++ b/com32/lib/sys/module/elf_module.c @@ -401,12 +401,21 @@ static int extract_operations(struct elf_module *module) { module->init_func = (module_init_t*)module_get_absolute( init_sym->st_value, module); + if (*(module->init_func) == NULL) { + module->init_func = NULL; + } module->exit_func = (module_exit_t*)module_get_absolute( exit_sym->st_value, module); + if (*(module->exit_func) == NULL) { + module->exit_func = NULL; + } module->main_func = (module_main_t*)module_get_absolute( main_sym->st_value, module); + if (*(module->main_func) == NULL) { + module->main_func = NULL; + } return 0; } diff --git a/com32/lib/sys/module/exec.c b/com32/lib/sys/module/exec.c index bb855efb..3cd53187 100644 --- a/com32/lib/sys/module/exec.c +++ b/com32/lib/sys/module/exec.c @@ -69,13 +69,13 @@ int load_library(const char *name) { return res; } - if (*(module->main_func) != NULL) { + if (module->main_func != NULL) { DBG_PRINT("Cannot load executable module as library.\n"); module_unload(module); return -1; } - if (*(module->init_func) != NULL) { + if (module->init_func != NULL) { res = (*(module->init_func))(); DBG_PRINT("Initialization function returned: %d\n", res); } else { @@ -97,7 +97,11 @@ int unload_library(const char *name) { if (module == NULL) return -1; - if (*(module->exit_func) != NULL) { + if (!module_unloadable(module)) { + return -1; + } + + if (module->exit_func != NULL) { (*(module->exit_func))(); } @@ -121,7 +125,7 @@ int spawnv(const char *name, const char **argv) { return res; } - if (*(module->main_func) != NULL) { + if (module->main_func != NULL) { const char **last_arg = argv; void *old_tag; while (*last_arg != NULL) |