Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #637, fix OS_ModuleUnload for static modules #638

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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