Skip to content

Commit

Permalink
Fix #641, add flags to OS_ModuleLoad
Browse files Browse the repository at this point in the history
Add flags to indicate symbol visibility for OS_ModuleLoad().

By default (flags=0) symbols will have global visibility,
which should be the same as existing behavior.
  • Loading branch information
jphickey committed Nov 4, 2020
1 parent c1258ac commit f553c98
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 22 deletions.
1 change: 0 additions & 1 deletion src/os/inc/osapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ extern "C"
#define OS_ERR_INCORRECT_OBJ_TYPE (-36) /**< @brief Incorrect object type */
#define OS_ERR_STREAM_DISCONNECTED (-37) /**< @brief Stream disconnected */
#define OS_ERR_OPERATION_NOT_SUPPORTED (-38) /**< @brief Requested operation is not support on the supplied object(s) */
#define OS_ERR_SYMBOL_NOT_FOUND (-39) /**< @brief Symbol Name not found */

/**@}*/

Expand Down
2 changes: 1 addition & 1 deletion src/os/portable/os-impl-posix-dl-symtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int32 OS_GenericSymbolLookup_Impl(void *dl_handle, cpuaddr *SymbolAddress, const
void *Function;
int32 status;

status = OS_ERR_SYMBOL_NOT_FOUND;
status = OS_ERROR;

/*
* call dlerror() to clear any prior error that might have occurred.
Expand Down
22 changes: 6 additions & 16 deletions src/os/shared/src/osapi-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,10 @@ int32 OS_SymbolLookup(cpuaddr *SymbolAddress, const char *SymbolName)
staticsym_status = OS_SymbolLookup_Static(SymbolAddress, SymbolName, NULL);

/*
* NOTE:
* The OS_ERR_NOT_IMPLEMENTED code should only be returned
* if neither the SymbolLookup_Impl nor the static table
* lookup capabilities are implemented.
*
* If either of these are implemented then the returned
* value should reflect the one that is implemented.
* Only overwrite the return code if static lookup was successful.
* Otherwise keep the error code from the low level implementation.
*/
if (staticsym_status == OS_SUCCESS || return_code == OS_ERR_NOT_IMPLEMENTED)
if (staticsym_status == OS_SUCCESS)
{
return_code = staticsym_status;
}
Expand Down Expand Up @@ -416,15 +411,10 @@ int32 OS_ModuleSymbolLookup(osal_id_t module_id, cpuaddr *SymbolAddress, const c
staticsym_status = OS_SymbolLookup_Static(SymbolAddress, SymbolName, record->name_entry);

/*
* NOTE:
* The OS_ERR_NOT_IMPLEMENTED code should only be returned
* if neither the SymbolLookup_Impl nor the static table
* lookup capabilities are implemented.
*
* If either of these are implemented then the returned
* value should reflect the one that is implemented.
* Only overwrite the return code if static lookup was successful.
* Otherwise keep the error code from the low level implementation.
*/
if (staticsym_status == OS_SUCCESS || return_code == OS_ERR_NOT_IMPLEMENTED)
if (staticsym_status == OS_SUCCESS)
{
return_code = staticsym_status;
}
Expand Down
8 changes: 8 additions & 0 deletions src/os/vxworks/src/os-impl-symtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ int32 OS_GenericSymbolLookup_Impl(SYMTAB_ID SymTab, cpuaddr *SymbolAddress, cons
STATUS vxStatus;
SYMBOL_DESC SymDesc;

/*
** Check parameters
*/
if ((SymbolAddress == NULL) || (SymbolName == NULL))
{
return (OS_INVALID_POINTER);
}

/*
** Lookup the entry point
**
Expand Down
2 changes: 1 addition & 1 deletion src/unit-test-coverage/shared/src/coveragetest-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void Test_OS_ModuleLoad(void)
OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED);

/* a dynamic module with local symbols */
actual = OS_ModuleLoad(&objid, "UTS", "File2", OS_MODULE_FLAG_LOCAL_SYMBOLS);
actual = OS_ModuleLoad(&objid, "UT", "File3", OS_MODULE_FLAG_LOCAL_SYMBOLS);
UtAssert_True(actual == expected, "OS_ModuleLoad() (%ld) == OS_SUCCESS", (long)actual);
actual = UT_GetStubCount(UT_KEY(OS_ModuleLoad_Impl));
UtAssert_True(actual == 2, "OS_ModuleLoad_Impl() called (%ld) == 2", (long)actual);
Expand Down
2 changes: 1 addition & 1 deletion src/unit-tests/osloader-test/ut_osloader_module_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void UT_os_module_load_test()
{
snprintf(module_name, sizeof(module_name), UT_OS_GENERIC_MODULE_NAME_TEMPLATE, i);
snprintf(module_file_name, sizeof(module_file_name), UT_OS_GENERIC_MODULE_FILE_TEMPLATE, i);
res = OS_ModuleLoad(&module_id, module_name, module_file_name, OS_MODULE_FLAG_GLOBAL_SYMBOLS);
res = OS_ModuleLoad(&module_id, module_name, module_file_name, OS_MODULE_FLAG_LOCAL_SYMBOLS);
if (res != OS_SUCCESS)
{
testDesc = "#4 No-free-IDs - Module Load failed";
Expand Down
85 changes: 83 additions & 2 deletions src/unit-tests/osloader-test/ut_osloader_symtable_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ void UT_os_symbol_lookup_test()
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);

/*-----------------------------------------------------*/
testDesc = "#4 Nominal";
testDesc = "#4 Nominal, Global Symbols";

/* Setup */
res = OS_ModuleLoad(&module_id, "Mod1", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS);
res = OS_ModuleLoad(&module_id, "Mod1", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_GLOBAL_SYMBOLS);
if (res != OS_SUCCESS)
{
UT_OS_TEST_RESULT("#4 Nominal - Module Load failed", UTASSERT_CASETYPE_TSF);
Expand All @@ -122,6 +122,8 @@ void UT_os_symbol_lookup_test()
res = OS_SymbolLookup(&symbol_addr, "module1");
if (res == OS_SUCCESS)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else if (res == OS_ERR_NOT_IMPLEMENTED)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);

Expand All @@ -133,6 +135,85 @@ void UT_os_symbol_lookup_test()
return;
}

/*--------------------------------------------------------------------------------*
** Syntax: OS_ModuleSymbolLookup
** Purpose: Returns the memory address of a symbol
** Parameters: To-be-filled-in
** Returns: OS_INVALID_POINTER if any of the pointers passed in is null
** OS_ERROR if the symbol name is not found
** OS_SUCCESS if succeeded
**--------------------------------------------------------------------------------*/

void UT_os_module_symbol_lookup_test()
{
int32 res = 0;
const char *testDesc;
cpuaddr symbol_addr;
osal_id_t module_id;

/*-----------------------------------------------------*/
testDesc = "API Not implemented";

res = OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symbol_addr, "main");
if (res == OS_ERR_NOT_IMPLEMENTED)
{
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA);
goto UT_os_module_symbol_lookup_test_exit_tag;
}

/*-----------------------------------------------------*/
testDesc = "#1 Invalid-pointer-arg-1";

res = OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, 0, "main");
if (res == OS_INVALID_POINTER)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);

/*-----------------------------------------------------*/
testDesc = "#2 Invalid-pointer-arg-2";

res = OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symbol_addr, 0);
if (res == OS_INVALID_POINTER)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);

/*-----------------------------------------------------*/
/* Setup for remainder of tests */
res = OS_ModuleLoad(&module_id, "Mod1", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS);
if (res != OS_SUCCESS)
{
UT_OS_TEST_RESULT("Module Load failed", UTASSERT_CASETYPE_TSF);
goto UT_os_module_symbol_lookup_test_exit_tag;
}

/*-----------------------------------------------------*/
testDesc = "#3 Symbol-not-found";

res = OS_ModuleSymbolLookup(module_id, &symbol_addr, "ThisSymbolIsNotFound");
if (res == OS_ERROR)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);

/*-----------------------------------------------------*/
testDesc = "#4 Nominal, Local Symbols";

res = OS_ModuleSymbolLookup(module_id, &symbol_addr, "module1");
if (res == OS_SUCCESS)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);

/* Reset test environment */
res = OS_ModuleUnload(module_id);

UT_os_module_symbol_lookup_test_exit_tag:
return;
}


/*--------------------------------------------------------------------------------*
** Syntax: OS_SymbolTableDump
** Purpose: Dumps the system symbol table to the given filename
Expand Down
1 change: 1 addition & 0 deletions src/unit-tests/osloader-test/ut_osloader_symtable_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
**--------------------------------------------------------------------------------*/

void UT_os_symbol_lookup_test(void);
void UT_os_module_symbol_lookup_test(void);
void UT_os_symbol_table_dump_test(void);

/*--------------------------------------------------------------------------------*/
Expand Down
1 change: 1 addition & 0 deletions src/unit-tests/osloader-test/ut_osloader_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void UtTest_Setup(void)
UtTest_Add(UT_os_module_unload_test, NULL, NULL, "OS_ModuleUnload");
UtTest_Add(UT_os_module_info_test, NULL, NULL, "OS_ModuleInfo");

UtTest_Add(UT_os_module_symbol_lookup_test, NULL, NULL, "OS_ModuleSymbolLookup");
UtTest_Add(UT_os_symbol_lookup_test, NULL, NULL, "OS_SymbolLookup");
UtTest_Add(UT_os_symbol_table_dump_test, NULL, NULL, "OS_SymbolTableDump");
}
Expand Down

0 comments on commit f553c98

Please sign in to comment.