Skip to content

Commit

Permalink
Merge pull request #638 from jphickey/fix-637-module-unload
Browse files Browse the repository at this point in the history
Fix #637, fix OS_ModuleUnload for static modules
  • Loading branch information
astrogeco authored Nov 10, 2020
2 parents 1a82657 + ba6375c commit f2f1f44
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
16 changes: 12 additions & 4 deletions src/os/shared/inc/os-shared-module.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@

#include <os-shared-globaldefs.h>

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;

/*
Expand Down
17 changes: 14 additions & 3 deletions src/os/shared/src/osapi-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f2f1f44

Please sign in to comment.