From 6d74eb436dd43a697668b901f3e14a3dbc6418b0 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Mon, 2 Nov 2020 11:58:38 -0500 Subject: [PATCH] Fix #637, static module unload fix Mark static modules with a flag, and check that flag at unload. If flag is set, then skip unload low level implementation. --- src/os/shared/inc/os-shared-module.h | 2 ++ src/os/shared/src/osapi-module.c | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/os/shared/inc/os-shared-module.h b/src/os/shared/inc/os-shared-module.h index 3c93c2345..f65d03cc5 100644 --- a/src/os/shared/inc/os-shared-module.h +++ b/src/os/shared/inc/os-shared-module.h @@ -30,6 +30,8 @@ #include +#define OS_MODULE_FLAG_IS_STATIC 0x1 + typedef struct { char module_name[OS_MAX_API_NAME]; diff --git a/src/os/shared/src/osapi-module.c b/src/os/shared/src/osapi-module.c index 8b690e7d4..689ea996b 100644 --- a/src/os/shared/src/osapi-module.c +++ b/src/os/shared/src/osapi-module.c @@ -232,7 +232,12 @@ int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *f * returns OS_ERR_NAME_NOT_FOUND. */ return_code = OS_ModuleLoad_Static(module_name); - if (return_code != OS_SUCCESS) + if (return_code == OS_SUCCESS) + { + /* mark this as a statically loaded module */ + OS_module_table[local_id].flags |= OS_MODULE_FLAG_IS_STATIC; + } + else { /* * If this is NOT a static module, then the module file must be loaded by normal @@ -280,9 +285,14 @@ int32 OS_ModuleUnload(osal_id_t module_id) if (return_code == OS_SUCCESS) { /* - * Only call the implementation if the loader is enabled + * Only call the implementation if the file was actually loaded. + * If this is a static module, then this is just a placeholder and + * it means there was no file actually loaded. */ - return_code = OS_ModuleUnload_Impl(local_id); + if ((OS_module_table[local_id].flags & OS_MODULE_FLAG_IS_STATIC) == 0) + { + return_code = OS_ModuleUnload_Impl(local_id); + } /* Complete the operation via the common routine */ return_code = OS_ObjectIdFinalizeDelete(return_code, record);