Skip to content

Commit f553c98

Browse files
committed
Fix #641, add flags to OS_ModuleLoad
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.
1 parent c1258ac commit f553c98

File tree

9 files changed

+102
-22
lines changed

9 files changed

+102
-22
lines changed

src/os/inc/osapi.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ extern "C"
9090
#define OS_ERR_INCORRECT_OBJ_TYPE (-36) /**< @brief Incorrect object type */
9191
#define OS_ERR_STREAM_DISCONNECTED (-37) /**< @brief Stream disconnected */
9292
#define OS_ERR_OPERATION_NOT_SUPPORTED (-38) /**< @brief Requested operation is not support on the supplied object(s) */
93-
#define OS_ERR_SYMBOL_NOT_FOUND (-39) /**< @brief Symbol Name not found */
9493

9594
/**@}*/
9695

src/os/portable/os-impl-posix-dl-symtab.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ int32 OS_GenericSymbolLookup_Impl(void *dl_handle, cpuaddr *SymbolAddress, const
8686
void *Function;
8787
int32 status;
8888

89-
status = OS_ERR_SYMBOL_NOT_FOUND;
89+
status = OS_ERROR;
9090

9191
/*
9292
* call dlerror() to clear any prior error that might have occurred.

src/os/shared/src/osapi-module.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -365,15 +365,10 @@ int32 OS_SymbolLookup(cpuaddr *SymbolAddress, const char *SymbolName)
365365
staticsym_status = OS_SymbolLookup_Static(SymbolAddress, SymbolName, NULL);
366366

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

418413
/*
419-
* NOTE:
420-
* The OS_ERR_NOT_IMPLEMENTED code should only be returned
421-
* if neither the SymbolLookup_Impl nor the static table
422-
* lookup capabilities are implemented.
423-
*
424-
* If either of these are implemented then the returned
425-
* value should reflect the one that is implemented.
414+
* Only overwrite the return code if static lookup was successful.
415+
* Otherwise keep the error code from the low level implementation.
426416
*/
427-
if (staticsym_status == OS_SUCCESS || return_code == OS_ERR_NOT_IMPLEMENTED)
417+
if (staticsym_status == OS_SUCCESS)
428418
{
429419
return_code = staticsym_status;
430420
}

src/os/vxworks/src/os-impl-symtab.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ int32 OS_GenericSymbolLookup_Impl(SYMTAB_ID SymTab, cpuaddr *SymbolAddress, cons
7575
STATUS vxStatus;
7676
SYMBOL_DESC SymDesc;
7777

78+
/*
79+
** Check parameters
80+
*/
81+
if ((SymbolAddress == NULL) || (SymbolName == NULL))
82+
{
83+
return (OS_INVALID_POINTER);
84+
}
85+
7886
/*
7987
** Lookup the entry point
8088
**

src/unit-test-coverage/shared/src/coveragetest-module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void Test_OS_ModuleLoad(void)
8383
OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED);
8484

8585
/* a dynamic module with local symbols */
86-
actual = OS_ModuleLoad(&objid, "UTS", "File2", OS_MODULE_FLAG_LOCAL_SYMBOLS);
86+
actual = OS_ModuleLoad(&objid, "UT", "File3", OS_MODULE_FLAG_LOCAL_SYMBOLS);
8787
UtAssert_True(actual == expected, "OS_ModuleLoad() (%ld) == OS_SUCCESS", (long)actual);
8888
actual = UT_GetStubCount(UT_KEY(OS_ModuleLoad_Impl));
8989
UtAssert_True(actual == 2, "OS_ModuleLoad_Impl() called (%ld) == 2", (long)actual);

src/unit-tests/osloader-test/ut_osloader_module_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void UT_os_module_load_test()
121121
{
122122
snprintf(module_name, sizeof(module_name), UT_OS_GENERIC_MODULE_NAME_TEMPLATE, i);
123123
snprintf(module_file_name, sizeof(module_file_name), UT_OS_GENERIC_MODULE_FILE_TEMPLATE, i);
124-
res = OS_ModuleLoad(&module_id, module_name, module_file_name, OS_MODULE_FLAG_GLOBAL_SYMBOLS);
124+
res = OS_ModuleLoad(&module_id, module_name, module_file_name, OS_MODULE_FLAG_LOCAL_SYMBOLS);
125125
if (res != OS_SUCCESS)
126126
{
127127
testDesc = "#4 No-free-IDs - Module Load failed";

src/unit-tests/osloader-test/ut_osloader_symtable_test.c

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ void UT_os_symbol_lookup_test()
109109
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);
110110

111111
/*-----------------------------------------------------*/
112-
testDesc = "#4 Nominal";
112+
testDesc = "#4 Nominal, Global Symbols";
113113

114114
/* Setup */
115-
res = OS_ModuleLoad(&module_id, "Mod1", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS);
115+
res = OS_ModuleLoad(&module_id, "Mod1", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_GLOBAL_SYMBOLS);
116116
if (res != OS_SUCCESS)
117117
{
118118
UT_OS_TEST_RESULT("#4 Nominal - Module Load failed", UTASSERT_CASETYPE_TSF);
@@ -122,6 +122,8 @@ void UT_os_symbol_lookup_test()
122122
res = OS_SymbolLookup(&symbol_addr, "module1");
123123
if (res == OS_SUCCESS)
124124
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
125+
else if (res == OS_ERR_NOT_IMPLEMENTED)
126+
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA);
125127
else
126128
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);
127129

@@ -133,6 +135,85 @@ void UT_os_symbol_lookup_test()
133135
return;
134136
}
135137

138+
/*--------------------------------------------------------------------------------*
139+
** Syntax: OS_ModuleSymbolLookup
140+
** Purpose: Returns the memory address of a symbol
141+
** Parameters: To-be-filled-in
142+
** Returns: OS_INVALID_POINTER if any of the pointers passed in is null
143+
** OS_ERROR if the symbol name is not found
144+
** OS_SUCCESS if succeeded
145+
**--------------------------------------------------------------------------------*/
146+
147+
void UT_os_module_symbol_lookup_test()
148+
{
149+
int32 res = 0;
150+
const char *testDesc;
151+
cpuaddr symbol_addr;
152+
osal_id_t module_id;
153+
154+
/*-----------------------------------------------------*/
155+
testDesc = "API Not implemented";
156+
157+
res = OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symbol_addr, "main");
158+
if (res == OS_ERR_NOT_IMPLEMENTED)
159+
{
160+
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA);
161+
goto UT_os_module_symbol_lookup_test_exit_tag;
162+
}
163+
164+
/*-----------------------------------------------------*/
165+
testDesc = "#1 Invalid-pointer-arg-1";
166+
167+
res = OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, 0, "main");
168+
if (res == OS_INVALID_POINTER)
169+
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
170+
else
171+
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);
172+
173+
/*-----------------------------------------------------*/
174+
testDesc = "#2 Invalid-pointer-arg-2";
175+
176+
res = OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symbol_addr, 0);
177+
if (res == OS_INVALID_POINTER)
178+
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
179+
else
180+
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);
181+
182+
/*-----------------------------------------------------*/
183+
/* Setup for remainder of tests */
184+
res = OS_ModuleLoad(&module_id, "Mod1", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS);
185+
if (res != OS_SUCCESS)
186+
{
187+
UT_OS_TEST_RESULT("Module Load failed", UTASSERT_CASETYPE_TSF);
188+
goto UT_os_module_symbol_lookup_test_exit_tag;
189+
}
190+
191+
/*-----------------------------------------------------*/
192+
testDesc = "#3 Symbol-not-found";
193+
194+
res = OS_ModuleSymbolLookup(module_id, &symbol_addr, "ThisSymbolIsNotFound");
195+
if (res == OS_ERROR)
196+
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
197+
else
198+
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);
199+
200+
/*-----------------------------------------------------*/
201+
testDesc = "#4 Nominal, Local Symbols";
202+
203+
res = OS_ModuleSymbolLookup(module_id, &symbol_addr, "module1");
204+
if (res == OS_SUCCESS)
205+
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
206+
else
207+
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);
208+
209+
/* Reset test environment */
210+
res = OS_ModuleUnload(module_id);
211+
212+
UT_os_module_symbol_lookup_test_exit_tag:
213+
return;
214+
}
215+
216+
136217
/*--------------------------------------------------------------------------------*
137218
** Syntax: OS_SymbolTableDump
138219
** Purpose: Dumps the system symbol table to the given filename

src/unit-tests/osloader-test/ut_osloader_symtable_test.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
**--------------------------------------------------------------------------------*/
5555

5656
void UT_os_symbol_lookup_test(void);
57+
void UT_os_module_symbol_lookup_test(void);
5758
void UT_os_symbol_table_dump_test(void);
5859

5960
/*--------------------------------------------------------------------------------*/

src/unit-tests/osloader-test/ut_osloader_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ void UtTest_Setup(void)
8282
UtTest_Add(UT_os_module_unload_test, NULL, NULL, "OS_ModuleUnload");
8383
UtTest_Add(UT_os_module_info_test, NULL, NULL, "OS_ModuleInfo");
8484

85+
UtTest_Add(UT_os_module_symbol_lookup_test, NULL, NULL, "OS_ModuleSymbolLookup");
8586
UtTest_Add(UT_os_symbol_lookup_test, NULL, NULL, "OS_SymbolLookup");
8687
UtTest_Add(UT_os_symbol_table_dump_test, NULL, NULL, "OS_SymbolTableDump");
8788
}

0 commit comments

Comments
 (0)