From ba6375cc6c156e9b45c5d89b89e16f952af5f99b 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 different type, and check that type at unload. Only call unload low level implementation if type is dynamic. --- src/os/shared/inc/os-shared-module.h | 16 ++++++++++++---- src/os/shared/src/osapi-module.c | 17 ++++++++++++++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/os/shared/inc/os-shared-module.h b/src/os/shared/inc/os-shared-module.h index 3c93c2345..4ce5386d4 100644 --- a/src/os/shared/inc/os-shared-module.h +++ b/src/os/shared/inc/os-shared-module.h @@ -30,12 +30,20 @@ #include +typedef enum +{ + OS_MODULE_TYPE_UNKNOWN = 0, /**< Default/unspecified (reserved value) */ + OS_MODULE_TYPE_DYNAMIC = 1, /**< Module is dynamically loaded via the OS loader */ + OS_MODULE_TYPE_STATIC = 2 /**< Module is statically linked and is a placeholder */ +} OS_module_type_t; + typedef struct { - char module_name[OS_MAX_API_NAME]; - char file_name[OS_MAX_PATH_LEN]; - uint32 flags; - cpuaddr entry_point; + char module_name[OS_MAX_API_NAME]; + char file_name[OS_MAX_PATH_LEN]; + OS_module_type_t module_type; + uint32 flags; + cpuaddr entry_point; } OS_module_internal_record_t; /* diff --git a/src/os/shared/src/osapi-module.c b/src/os/shared/src/osapi-module.c index 8b690e7d4..3f4c2af1d 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].module_type = OS_MODULE_TYPE_STATIC; + } + else { /* * If this is NOT a static module, then the module file must be loaded by normal @@ -248,6 +253,7 @@ int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *f { /* supplied filename was valid, so store a copy for future reference */ strncpy(OS_module_table[local_id].file_name, filename, OS_MAX_PATH_LEN); + OS_module_table[local_id].module_type = OS_MODULE_TYPE_DYNAMIC; /* Now call the OS-specific implementation. This reads info from the module table. */ return_code = OS_ModuleLoad_Impl(local_id, translated_path); @@ -280,9 +286,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].module_type == OS_MODULE_TYPE_DYNAMIC) + { + return_code = OS_ModuleUnload_Impl(local_id); + } /* Complete the operation via the common routine */ return_code = OS_ObjectIdFinalizeDelete(return_code, record);