From b7680650312742436c31572c6db7259ebbaee509 Mon Sep 17 00:00:00 2001 From: Alan Cudmore Date: Wed, 25 Nov 2020 12:59:27 -0500 Subject: [PATCH 01/11] Fix #608 - Add RTEMS 5.x support --- src/bsp/pc-rtems/CMakeLists.txt | 7 +++++++ src/bsp/pc-rtems/src/bsp_start.c | 14 +++++++++----- src/bsp/pc-rtems/src/pcrtems_bsp_internal.h | 9 +++++++++ src/os/rtems/inc/os-rtems.h | 14 ++++++++++++++ src/os/rtems/src/os-impl-heap.c | 4 ++-- src/os/rtems/src/os-impl-loader.c | 8 ++++---- 6 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/bsp/pc-rtems/CMakeLists.txt b/src/bsp/pc-rtems/CMakeLists.txt index 9b5a0af99..c6f6a1b29 100644 --- a/src/bsp/pc-rtems/CMakeLists.txt +++ b/src/bsp/pc-rtems/CMakeLists.txt @@ -9,6 +9,13 @@ add_library(osal_pc-rtems_impl OBJECT src/bsp_console.c ) +# This definition is needed for the gethostname call +# By defining this, it avoids the need to use the -std=gnu99 +# instead of the preferred -std=c99 GCC switch +target_compile_definitions(osal_pc-rtems_impl PUBLIC + _BSD_SOURCE +) + # This BSP only works with "rtems" OS layer. # Confirming this reduces risk of accidental misconfiguration set(OSAL_EXPECTED_OSTYPE "rtems" PARENT_SCOPE) diff --git a/src/bsp/pc-rtems/src/bsp_start.c b/src/bsp/pc-rtems/src/bsp_start.c index 2bbad651b..ce6ef503e 100644 --- a/src/bsp/pc-rtems/src/bsp_start.c +++ b/src/bsp/pc-rtems/src/bsp_start.c @@ -83,10 +83,10 @@ void OS_BSP_Setup(void) cmdlinestr = bsp_cmdline(); printf("\n\n*** RTEMS Info ***\n"); - printf("%s", _Copyright_Notice); - printf("%s\n\n", _RTEMS_version); - printf(" Stack size=%d\n", (int)Configuration.stack_space_size); - printf(" Workspace size=%d\n", (int)Configuration.work_space_size); + printf("%s", OSAL_BSP_COPYRIGHT_NOTICE); + printf("%s\n\n", rtems_get_version_string()); + printf(" Stack size=%d\n", (int)rtems_configuration_get_stack_space_size()); + printf(" Workspace size=%d\n", (int)rtems_configuration_get_work_space_size()); if (cmdlinestr != NULL) { printf(" Bootloader Command Line: %s\n", cmdlinestr); @@ -374,9 +374,13 @@ rtems_task Init(rtems_task_argument ignored) #define CONFIGURE_MAXIMUM_TIMERS (OS_MAX_TIMERS + 2) #define CONFIGURE_MAXIMUM_SEMAPHORES (OS_MAX_BIN_SEMAPHORES + OS_MAX_COUNT_SEMAPHORES + OS_MAX_MUTEXES + 16) #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES (OS_MAX_QUEUES + 4) -#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS (OS_MAX_NUM_OPEN_FILES + 8) #define CONFIGURE_MAXIMUM_DRIVERS 10 #define CONFIGURE_MAXIMUM_POSIX_KEYS 4 +#ifdef _RTEMS_5_ + #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS (OS_MAX_NUM_OPEN_FILES + 8) +#else + #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS (OS_MAX_NUM_OPEN_FILES + 8) +#endif #define CONFIGURE_RTEMS_INIT_TASKS_TABLE #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER diff --git a/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h b/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h index 8d3690596..12c04509c 100644 --- a/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h +++ b/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h @@ -40,6 +40,15 @@ #define RTEMS_MAX_USER_OPTIONS 4 #define RTEMS_MAX_CMDLINE 256 +/* + * Handle the differences between RTEMS 5 and 4.11 copyright notice + */ +#ifdef _RTEMS_5_ + #define OSAL_BSP_COPYRIGHT_NOTICE rtems_get_copyright_notice() +#else + #define OSAL_BSP_COPYRIGHT_NOTICE _Copyright_Notice +#endif + /* * The location which the general purpose file system will be mounted */ diff --git a/src/os/rtems/inc/os-rtems.h b/src/os/rtems/inc/os-rtems.h index c8cf01159..5e37bad1a 100644 --- a/src/os/rtems/inc/os-rtems.h +++ b/src/os/rtems/inc/os-rtems.h @@ -52,6 +52,20 @@ /**************************************************************************************** DEFINES ***************************************************************************************/ +/* + * Handle the data structure and API name changes between RTEMS 4.11 and RTEMS 5.1 + */ +#ifdef _RTEMS_5_ + #define OSAL_HEAP_INFO_BLOCK Heap_Information_block + #define OSAL_UNRESOLV_REC_TYPE rtems_rtl_unresolv_rec + #define OSAL_UNRESOLVED_SYMBOL rtems_rtl_unresolved_symbol + #define OSAL_UNRESOLVED_ITERATE rtems_rtl_unresolved_iterate +#else + #define OSAL_HEAP_INFO_BLOCK region_information_block + #define OSAL_UNRESOLV_REC_TYPE rtems_rtl_unresolv_rec_t + #define OSAL_UNRESOLVED_SYMBOL rtems_rtl_unresolved_name + #define OSAL_UNRESOLVED_ITERATE rtems_rtl_unresolved_interate +#endif /**************************************************************************************** TYPEDEFS diff --git a/src/os/rtems/src/os-impl-heap.c b/src/os/rtems/src/os-impl-heap.c index 17addccc0..4e67125cb 100644 --- a/src/os/rtems/src/os-impl-heap.c +++ b/src/os/rtems/src/os-impl-heap.c @@ -46,8 +46,8 @@ *-----------------------------------------------------------------*/ int32 OS_HeapGetInfo_Impl(OS_heap_prop_t *heap_prop) { - region_information_block info; - int status; + OSAL_HEAP_INFO_BLOCK info; + int status; status = malloc_info(&info); diff --git a/src/os/rtems/src/os-impl-loader.c b/src/os/rtems/src/os-impl-loader.c index 89fbbedce..3f174080c 100644 --- a/src/os/rtems/src/os-impl-loader.c +++ b/src/os/rtems/src/os-impl-loader.c @@ -73,14 +73,14 @@ int32 OS_Rtems_ModuleAPI_Impl_Init(void) * This could be fine-tuned later. * *-----------------------------------------------------------------*/ -static bool OS_rtems_rtl_check_unresolved(rtems_rtl_unresolv_rec_t *rec, void *data) +static bool OS_rtems_rtl_check_unresolved(OSAL_UNRESOLV_REC_TYPE *rec, void *data) { int32 *status = data; switch (rec->type) { - case rtems_rtl_unresolved_name: - OS_DEBUG("unresolved name: %s\n", rec->rec.name.name); + case OSAL_UNRESOLVED_SYMBOL: + OS_DEBUG("unresolved symbol: %s\n", rec->rec.name.name); *status = OS_ERROR; break; case rtems_rtl_unresolved_reloc: @@ -142,7 +142,7 @@ int32 OS_ModuleLoad_Impl(uint32 module_id, const char *translated_path) OS_DEBUG("module has has unresolved externals\n"); status = OS_SUCCESS; /* note - not final, probably overridden */ - rtems_rtl_unresolved_interate(OS_rtems_rtl_check_unresolved, &status); + OSAL_UNRESOLVED_ITERATE(OS_rtems_rtl_check_unresolved, &status); } else { From 0ecfba4585eebc41f2fc6f6287818be9ca6ab4dd Mon Sep 17 00:00:00 2001 From: Alex Campbell Date: Tue, 1 Dec 2020 10:34:57 -0500 Subject: [PATCH 02/11] fix #650 OS_chmod uses read or write access. --- src/os/portable/os-impl-posix-files.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/os/portable/os-impl-posix-files.c b/src/os/portable/os-impl-posix-files.c index ba59fcba0..9fe58401a 100644 --- a/src/os/portable/os-impl-posix-files.c +++ b/src/os/portable/os-impl-posix-files.c @@ -202,7 +202,11 @@ int32 OS_FileChmod_Impl(const char *local_path, uint32 access) fd = open(local_path, O_RDONLY, 0); if (fd < 0) { - return OS_ERROR; + fd = open(local_path, O_WRONLY, 0); + if (fd < 0) + { + return OS_ERROR; + } } /* From af7beaf8879f6571fc14260bb08b5ef48efd123d Mon Sep 17 00:00:00 2001 From: Alex Campbell Date: Tue, 1 Dec 2020 16:21:29 -0500 Subject: [PATCH 03/11] fix #631 add new functional tests for OS_chmod --- src/tests/file-api-test/file-api-test.c | 64 ++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/src/tests/file-api-test/file-api-test.c b/src/tests/file-api-test/file-api-test.c index 8bfda6ea0..9dd62f9a9 100644 --- a/src/tests/file-api-test/file-api-test.c +++ b/src/tests/file-api-test/file-api-test.c @@ -33,6 +33,7 @@ void TestMkfsMount(void); void TestCreatRemove(void); void TestOpenClose(void); +void TestChmod(void); void TestReadWriteLseek(void); void TestMkRmDirFreeBytes(void); void TestOpenReadCloseDir(void); @@ -75,6 +76,7 @@ void UtTest_Setup(void) UtTest_Add(TestMkfsMount, NULL, NULL, "TestMkfsMount"); UtTest_Add(TestCreatRemove, NULL, NULL, "TestCreatRemove"); UtTest_Add(TestOpenClose, NULL, NULL, "TestOpenClose"); + UtTest_Add(TestChmod, NULL, NULL, "TestChmod"); UtTest_Add(TestReadWriteLseek, NULL, NULL, "TestReadWriteLseek"); UtTest_Add(TestMkRmDirFreeBytes, NULL, NULL, "TestMkRmDirFreeBytes"); UtTest_Add(TestOpenReadCloseDir, NULL, NULL, "TestOpenReadCloseDir"); @@ -238,10 +240,68 @@ void TestOpenClose(void) status = OS_remove(filename); UtAssert_True(status == OS_SUCCESS, "status after remove = %d", (int)status); } + /*--------------------------------------------------------------------------------------- - * Name TestReadWriteLseek + * Name TestChmod ---------------------------------------------------------------------------------------*/ +void TestChmod(void) +{ + char filename[OS_MAX_PATH_LEN]; + int32 status; + osal_id_t fd; + + /*Make a file to test on. Start in Read only mode */ + strncpy(filename, "/drive0/Filename1", sizeof(filename) - 1); + filename[sizeof(filename) - 1] = 0; + status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_ONLY); + UtAssert_True(status >= OS_SUCCESS, "status after creat = %d", (int)status); + status = OS_close(fd); + UtAssert_True(status == OS_SUCCESS, "status after close = %d", (int)status); + + /*Testing Write Only */ + status = OS_chmod(filename, OS_WRITE_ONLY); + if(status != OS_ERR_NOT_IMPLEMENTED){ + UtAssert_True(status == OS_SUCCESS, "status after chmod = %d", (int)status); + status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_NONE, OS_WRITE_ONLY); + UtAssert_True(status >= OS_SUCCESS, "status after reopen = %d", (int)status); + status = OS_close(fd); + UtAssert_True(status == OS_SUCCESS, "status after close = %d", (int)status); + }else{ + UtPrintf("OS_chmod not implemented for write only\n"); + } + + /*Testing Read Only */ + status = OS_chmod(filename, OS_READ_ONLY); + if(status != OS_ERR_NOT_IMPLEMENTED){ + UtAssert_True(status == OS_SUCCESS, "status after chmod = %d", (int)status); + status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_NONE, OS_READ_ONLY); + UtAssert_True(status >= OS_SUCCESS, "status after reopen = %d", (int)status); + status = OS_close(fd); + UtAssert_True(status == OS_SUCCESS, "status after close = %d", (int)status); + }else{ + UtPrintf("OS_chmod not implemented for read only\n"); + } + + /*Testing Read Write */ + status = OS_chmod(filename, OS_READ_WRITE); + if(status != OS_ERR_NOT_IMPLEMENTED){ + UtAssert_True(status == OS_SUCCESS, "status after chmod = %d", (int)status); + status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_NONE, OS_READ_WRITE); + UtAssert_True(status >= OS_SUCCESS, "status after reopen = %d", (int)status); + status = OS_close(fd); + UtAssert_True(status == OS_SUCCESS, "status after close = %d", (int)status); + }else{ + UtPrintf("OS_chmod not implemented for read write\n"); + } + + /*Removing the file */ + status = OS_remove(filename); + UtAssert_True(status == OS_SUCCESS, "status after remove = %d", (int)status); +} +/*--------------------------------------------------------------------------------------- + * Name TestReadWriteLseek +---------------------------------------------------------------------------------------*/ void TestReadWriteLseek(void) { char filename[OS_MAX_PATH_LEN]; @@ -468,6 +528,7 @@ void TestMkRmDirFreeBytes(void) status = OS_fsBlocksFree("/drive0"); UtAssert_True(status == OS_ERR_NOT_IMPLEMENTED || status >= OS_SUCCESS, "Checking Free Blocks: %d", (int)status); } + /*--------------------------------------------------------------------------------------- * Name TestOpenReadCloseDir(); ---------------------------------------------------------------------------------------*/ @@ -762,6 +823,7 @@ void TestRename(void) status = OS_rmdir(newdir1); UtAssert_True(status == OS_SUCCESS, "status after rmdir 1 = %d", (int)status); } + /*--------------------------------------------------------------------------------------- * Name TestStat() ---------------------------------------------------------------------------------------*/ From 51ced9442acd3e35e48bd29b9663c13868ba1e72 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Mon, 30 Nov 2020 22:11:46 -0500 Subject: [PATCH 04/11] Fix #648, scrub array references in shared layer Introduce the OS_object_token_t type which tracks a reference to an OSAL resource. This contains all information about the original reference, including the ID, object type, lock type, and the table index. Therefore, since the token type contains all relevant info, it can be used in all places where a bare index was used. This also considerably simplifies the code, as some functions which previously output multiple objects only need to operate on tokens, and the functions which called these functions only need to instantiate a token. --- src/os/shared/inc/os-shared-globaldefs.h | 9 + src/os/shared/inc/os-shared-idmap.h | 227 +++++++- src/os/shared/inc/os-shared-time.h | 21 +- src/os/shared/src/osapi-binsem.c | 77 ++- src/os/shared/src/osapi-countsem.c | 68 +-- src/os/shared/src/osapi-dir.c | 52 +- src/os/shared/src/osapi-file.c | 175 +++--- src/os/shared/src/osapi-filesys.c | 151 ++--- src/os/shared/src/osapi-idmap.c | 548 ++++++++++++------ src/os/shared/src/osapi-module.c | 79 +-- src/os/shared/src/osapi-mutex.c | 87 +-- src/os/shared/src/osapi-printf.c | 27 +- src/os/shared/src/osapi-queue.c | 79 ++- src/os/shared/src/osapi-select.c | 12 +- src/os/shared/src/osapi-shell.c | 11 +- src/os/shared/src/osapi-sockets.c | 197 ++++--- src/os/shared/src/osapi-task.c | 162 +++--- src/os/shared/src/osapi-time.c | 150 ++--- src/os/shared/src/osapi-timebase.c | 119 ++-- src/unit-test-coverage/shared/CMakeLists.txt | 5 + .../shared/src/coveragetest-binsem.c | 18 +- .../shared/src/coveragetest-countsem.c | 18 +- .../shared/src/coveragetest-file.c | 31 +- .../shared/src/coveragetest-idmap.c | 334 ++++++----- .../shared/src/coveragetest-module.c | 19 +- .../shared/src/coveragetest-mutex.c | 18 +- .../shared/src/coveragetest-printf.c | 12 +- .../shared/src/coveragetest-queue.c | 23 +- .../shared/src/coveragetest-sockets.c | 25 +- .../shared/src/coveragetest-task.c | 30 +- .../shared/src/coveragetest-time.c | 66 ++- .../shared/src/coveragetest-timebase.c | 41 +- .../shared/src/os-shared-coverage-support.c | 113 ++++ .../shared/src/os-shared-coveragetest.h | 25 + src/ut-stubs/osapi-utstub-idmap.c | 242 +++++--- 35 files changed, 1937 insertions(+), 1334 deletions(-) create mode 100644 src/unit-test-coverage/shared/src/os-shared-coverage-support.c diff --git a/src/os/shared/inc/os-shared-globaldefs.h b/src/os/shared/inc/os-shared-globaldefs.h index 3a85a80f8..b94009722 100644 --- a/src/os/shared/inc/os-shared-globaldefs.h +++ b/src/os/shared/inc/os-shared-globaldefs.h @@ -48,6 +48,15 @@ typedef struct OS_common_record OS_common_record_t; struct OS_shared_global_vars; typedef struct OS_shared_global_vars OS_SharedGlobalVars_t; +/* + * The "OS_object_token" tracks to the type of lock currently held + * and the specific object record the requested operation should + * execute on. All operations start by obtaining a token, which must + * be released when the operation is complete. + */ +struct OS_object_token; +typedef struct OS_object_token OS_object_token_t; + /* * Wrapper for encoding of other types into a generic void* type required as argument * to callbacks and pthread entry/return values, etc. diff --git a/src/os/shared/inc/os-shared-idmap.h b/src/os/shared/inc/os-shared-idmap.h index 7b5b6b30e..1413c30a7 100644 --- a/src/os/shared/inc/os-shared-idmap.h +++ b/src/os/shared/inc/os-shared-idmap.h @@ -57,6 +57,32 @@ typedef enum OS_LOCK_MODE_REFCOUNT, /**< If operation succeeds, increment refcount and unlock global table */ } OS_lock_mode_t; +/* + * Actual (non-abstract) definition of "OS_object_token_t" + */ +struct OS_object_token +{ + OS_lock_mode_t lock_mode; + osal_objtype_t obj_type; + osal_index_t obj_idx; + osal_id_t obj_id; +}; + +/* + * Macro to retrieve an entry from an object table, based on a token + */ +#define OS_OBJECT_TABLE_GET(tbl, tok) (&tbl[OS_ObjectIndexFromToken(&(tok))]) + +/* + * Macro to clear a table entry and reset its name + */ +#define OS_OBJECT_INIT(tok, ref, namefield, nameval) \ + { \ + memset(ref, 0, sizeof(*ref)); \ + strncpy(ref->namefield, nameval, sizeof(ref->namefield) - 1); \ + OS_ObjectIdGlobalFromToken(&tok)->name_entry = ref->namefield; \ + } + /* * A function to perform arbitrary record matching. * @@ -67,6 +93,18 @@ typedef enum */ typedef bool (*OS_ObjectMatchFunc_t)(void *ref, osal_index_t local_id, const OS_common_record_t *obj); +/* + * State object associated with an object iterator + */ +typedef struct +{ + OS_common_record_t * base; + OS_ObjectMatchFunc_t match; + void * arg; + osal_index_t limit; + OS_object_token_t token; +} OS_object_iter_t; + /* * Global instantiations */ @@ -194,6 +232,91 @@ uint32 OS_GetMaxForObjectType(osal_objtype_t idtype); ------------------------------------------------------------------*/ uint32 OS_GetBaseForObjectType(osal_objtype_t idtype); +/*---------------------------------------------------------------- + Function: OS_ObjectIndexFromToken + + Purpose: Gets the index referenced by the token + + Returns: None + ------------------------------------------------------------------*/ +static inline osal_objtype_t OS_ObjectTypeFromToken(const OS_object_token_t *token) +{ + return token->obj_type; +} + +/*---------------------------------------------------------------- + Function: OS_ObjectIndexFromToken + + Purpose: Gets the index referenced by the token + + Returns: None + ------------------------------------------------------------------*/ +static inline osal_index_t OS_ObjectIndexFromToken(const OS_object_token_t *token) +{ + return token->obj_idx; +} + +/*---------------------------------------------------------------- + Function: OS_ObjectIdFromToken + + Purpose: Gets the object ID referenced by the token + + Returns: None + ------------------------------------------------------------------*/ +static inline osal_id_t OS_ObjectIdFromToken(const OS_object_token_t *token) +{ + return token->obj_id; +} + +/*---------------------------------------------------------------- + Function: OS_ObjectIdGlobalFromToken + + Purpose: Obtains the global record corresponding to the token + + Returns: Pointer to global object + ------------------------------------------------------------------*/ +OS_common_record_t *OS_ObjectIdGlobalFromToken(const OS_object_token_t *token); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdTransactionInit + + Purpose: Initiates a transaction by obtaining the global table lock + and preparing the object token value + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ObjectIdTransactionInit(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS_object_token_t *token); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdTransactionCancel + + Purpose: Cancels/Releases the lock obtained by OS_ObjectIdTransactionInit() + without making any modification to global IDs. + + Returns: None + ------------------------------------------------------------------*/ +void OS_ObjectIdTransactionCancel(OS_object_token_t *token); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdTransactionFinish + + Purpose: Releases the lock obtained by OS_ObjectIdTransactionInit() + with an optional synchronized ID update for new/deleted IDs. + + Returns: None + ------------------------------------------------------------------*/ +void OS_ObjectIdTransactionFinish(OS_object_token_t *token, osal_id_t *final_id); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdConvertToken + + Purpose: Converts a token from OS_ObjectIdTransactionInit() to the + type that was requested by the user. + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ObjectIdConvertToken(OS_object_token_t *token); + /*---------------------------------------------------------------- Function: OS_ObjectIdFindByName @@ -213,7 +336,7 @@ int32 OS_ObjectIdFindByName(osal_objtype_t idtype, const char *name, osal_id_t * Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg, - OS_common_record_t **record); + OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_ObjectIdGetByName @@ -223,8 +346,7 @@ int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ObjectIdGetByName(OS_lock_mode_t lock_mode, osal_objtype_t idtype, const char *name, - OS_common_record_t **record); +int32 OS_ObjectIdGetByName(OS_lock_mode_t lock_mode, osal_objtype_t idtype, const char *name, OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_ObjectIdGetById @@ -234,8 +356,27 @@ int32 OS_ObjectIdGetByName(OS_lock_mode_t lock_mode, osal_objtype_t idtype, cons Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ObjectIdGetById(OS_lock_mode_t lock_mode, osal_objtype_t idtype, osal_id_t id, osal_index_t *array_index, - OS_common_record_t **record); +int32 OS_ObjectIdGetById(OS_lock_mode_t lock_mode, osal_objtype_t idtype, osal_id_t id, OS_object_token_t *token); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdRelease + + Purpose: Releases (unlocks) the object token previously obtained using + OS_ObjectIdGetById() or OS_ObjectIdGetBySearch(). + + Returns: none + ------------------------------------------------------------------*/ +void OS_ObjectIdRelease(OS_object_token_t *token); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdTransferToken + + Purpose: Transfers ownership of a object token without unlocking/releasing. + The original token will become benign and the new token becomes active. + + Returns: none + ------------------------------------------------------------------*/ +void OS_ObjectIdTransferToken(OS_object_token_t *token_from, OS_object_token_t *token_to); /*---------------------------------------------------------------- Function: OS_ObjectIdAllocateNew @@ -247,8 +388,7 @@ int32 OS_ObjectIdGetById(OS_lock_mode_t lock_mode, osal_objtype_t idtype, osal_i Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ObjectIdAllocateNew(osal_objtype_t idtype, const char *name, osal_index_t *array_index, - OS_common_record_t **record); +int32 OS_ObjectIdAllocateNew(osal_objtype_t idtype, const char *name, OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_ObjectIdFinalizeNew @@ -260,7 +400,7 @@ int32 OS_ObjectIdAllocateNew(osal_objtype_t idtype, const char *name, osal_index Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_common_record_t *record, osal_id_t *outid); +int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_object_token_t *token, osal_id_t *outid); /*---------------------------------------------------------------- Function: OS_ObjectIdFinalizeDelete @@ -272,17 +412,69 @@ int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_common_record_t *record, Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ObjectIdFinalizeDelete(int32 operation_status, OS_common_record_t *record); +int32 OS_ObjectIdFinalizeDelete(int32 operation_status, OS_object_token_t *token); /*---------------------------------------------------------------- - Function: OS_ObjectIdRefcountDecr + Function: OS_ObjectIdIteratorInit - Purpose: Decrement the reference count - This releases objects obtained with OS_LOCK_MODE_REFCOUNT mode + Purpose: Initialize a generic object iterator of the given type. + Note This obtains and holds a global lock on the internal table, so + this call must be followed by a call to OS_ObjectIdIteratorDestroy() - Returns: OS_SUCCESS on success, or relevant error code + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ObjectIdIteratorInit(OS_ObjectMatchFunc_t matchfunc, void *matcharg, osal_objtype_t objtype, + OS_object_iter_t *iter); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdIterateActive + + Purpose: Initialize a object iterator of the given type that will + return only active/valid OSAL objects. + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ObjectIdIterateActive(osal_objtype_t objtype, OS_object_iter_t *iter); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdIteratorGetNext + + Purpose: Move then token to the next matching iterator entry + + Returns: true if successful, false if at last entry/end of table + ------------------------------------------------------------------*/ +bool OS_ObjectIdIteratorGetNext(OS_object_iter_t *iter); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdIteratorDestroy + + Purpose: Releases an iterator from OS_ObjectIdIteratorInit() + + Returns: None + ------------------------------------------------------------------*/ +void OS_ObjectIdIteratorDestroy(OS_object_iter_t *iter); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdIteratorRef + + Purpose: Gets the token indicating current iterator position + The returned token can be used to access the relevant entry + + Returns: None + ------------------------------------------------------------------*/ +static inline const OS_object_token_t *OS_ObjectIdIteratorRef(OS_object_iter_t *iter) +{ + return &iter->token; +} + +/*---------------------------------------------------------------- + Function: OS_ObjectIdIteratorProcessEntry + + Purpose: Calls a function using the ID of the entry from the iterator + + Returns: None ------------------------------------------------------------------*/ -int32 OS_ObjectIdRefcountDecr(OS_common_record_t *record); +int32 OS_ObjectIdIteratorProcessEntry(OS_object_iter_t *iter, int32 (*func)(osal_id_t)); /* * Internal helper functions @@ -290,10 +482,7 @@ int32 OS_ObjectIdRefcountDecr(OS_common_record_t *record); * to be exposed for unit testing. */ bool OS_ObjectNameMatch(void *ref, osal_index_t local_id, const OS_common_record_t *obj); -void OS_ObjectIdInitiateLock(OS_lock_mode_t lock_mode, osal_objtype_t idtype); -int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, osal_objtype_t idtype, osal_id_t reference_id, - OS_common_record_t *obj); -int32 OS_ObjectIdSearch(osal_objtype_t idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg, OS_common_record_t **record); -int32 OS_ObjectIdFindNext(osal_objtype_t idtype, osal_index_t *array_index, OS_common_record_t **record); +int32 OS_ObjectIdFindNextMatch(OS_ObjectMatchFunc_t MatchFunc, void *arg, OS_object_token_t *token); +int32 OS_ObjectIdFindNextFree(OS_object_token_t *token); #endif /* INCLUDE_OS_SHARED_IDMAP_H_ */ diff --git a/src/os/shared/inc/os-shared-time.h b/src/os/shared/inc/os-shared-time.h index 1fb7aa3e1..6c0ac43f9 100644 --- a/src/os/shared/inc/os-shared-time.h +++ b/src/os/shared/inc/os-shared-time.h @@ -29,21 +29,22 @@ #define INCLUDE_OS_SHARED_TIME_H_ #include +#include #define TIMECB_FLAG_DEDICATED_TIMEBASE 0x1 typedef struct { - char timer_name[OS_MAX_API_NAME]; - uint32 flags; - osal_index_t timebase_ref; - osal_index_t prev_ref; - osal_index_t next_ref; - uint32 backlog_resets; - int32 wait_time; - int32 interval_time; - OS_ArgCallback_t callback_ptr; - void * callback_arg; + char timer_name[OS_MAX_API_NAME]; + uint32 flags; + OS_object_token_t timebase_token; + osal_index_t prev_ref; + osal_index_t next_ref; + uint32 backlog_resets; + int32 wait_time; + int32 interval_time; + OS_ArgCallback_t callback_ptr; + void * callback_arg; } OS_timecb_internal_record_t; /* diff --git a/src/os/shared/src/osapi-binsem.c b/src/os/shared/src/osapi-binsem.c index 6d323faff..d46bfee21 100644 --- a/src/os/shared/src/osapi-binsem.c +++ b/src/os/shared/src/osapi-binsem.c @@ -96,9 +96,9 @@ int32 OS_BinSemAPI_Init(void) *-----------------------------------------------------------------*/ int32 OS_BinSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initial_value, uint32 options) { - OS_common_record_t *record; - int32 return_code; - osal_index_t local_id; + int32 return_code; + OS_object_token_t token; + OS_bin_sem_internal_record_t *binsem; /* Check for NULL pointers */ if (sem_id == NULL || sem_name == NULL) @@ -112,18 +112,19 @@ int32 OS_BinSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initia } /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, sem_name, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, sem_name, &token); if (return_code == OS_SUCCESS) { - /* Save all the data to our own internal table */ - strcpy(OS_bin_sem_table[local_id].obj_name, sem_name); - record->name_entry = OS_bin_sem_table[local_id].obj_name; + binsem = OS_OBJECT_TABLE_GET(OS_bin_sem_table, token); + + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, binsem, obj_name, sem_name); /* Now call the OS-specific implementation. This reads info from the table. */ - return_code = OS_BinSemCreate_Impl(local_id, sem_initial_value, options); + return_code = OS_BinSemCreate_Impl(OS_ObjectIndexFromToken(&token), sem_initial_value, options); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, sem_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, sem_id); } return return_code; @@ -140,17 +141,16 @@ int32 OS_BinSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initia *-----------------------------------------------------------------*/ int32 OS_BinSemDelete(osal_id_t sem_id) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_BinSemDelete_Impl(local_id); + return_code = OS_BinSemDelete_Impl(OS_ObjectIndexFromToken(&token)); /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, record); + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } return return_code; @@ -167,15 +167,14 @@ int32 OS_BinSemDelete(osal_id_t sem_id) *-----------------------------------------------------------------*/ int32 OS_BinSemGive(osal_id_t sem_id) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_BinSemGive_Impl(local_id); + return_code = OS_BinSemGive_Impl(OS_ObjectIndexFromToken(&token)); } return return_code; @@ -192,15 +191,14 @@ int32 OS_BinSemGive(osal_id_t sem_id) *-----------------------------------------------------------------*/ int32 OS_BinSemFlush(osal_id_t sem_id) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_BinSemFlush_Impl(local_id); + return_code = OS_BinSemFlush_Impl(OS_ObjectIndexFromToken(&token)); } return return_code; @@ -216,15 +214,14 @@ int32 OS_BinSemFlush(osal_id_t sem_id) *-----------------------------------------------------------------*/ int32 OS_BinSemTake(osal_id_t sem_id) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_BinSemTake_Impl(local_id); + return_code = OS_BinSemTake_Impl(OS_ObjectIndexFromToken(&token)); } return return_code; @@ -240,15 +237,14 @@ int32 OS_BinSemTake(osal_id_t sem_id) *-----------------------------------------------------------------*/ int32 OS_BinSemTimedWait(osal_id_t sem_id, uint32 msecs) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_BinSemTimedWait_Impl(local_id, msecs); + return_code = OS_BinSemTimedWait_Impl(OS_ObjectIndexFromToken(&token), msecs); } return return_code; @@ -287,7 +283,7 @@ int32 OS_BinSemGetIdByName(osal_id_t *sem_id, const char *sem_name) int32 OS_BinSemGetInfo(osal_id_t sem_id, OS_bin_sem_prop_t *bin_prop) { OS_common_record_t *record; - osal_index_t local_id; + OS_object_token_t token; int32 return_code; /* Check parameters */ @@ -299,13 +295,16 @@ int32 OS_BinSemGetInfo(osal_id_t sem_id, OS_bin_sem_prop_t *bin_prop) memset(bin_prop, 0, sizeof(OS_bin_sem_prop_t)); /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { + record = OS_OBJECT_TABLE_GET(OS_global_bin_sem_table, token); + strncpy(bin_prop->name, record->name_entry, OS_MAX_API_NAME - 1); bin_prop->creator = record->creator; - return_code = OS_BinSemGetInfo_Impl(local_id, bin_prop); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + return_code = OS_BinSemGetInfo_Impl(OS_ObjectIndexFromToken(&token), bin_prop); + + OS_ObjectIdRelease(&token); } return return_code; diff --git a/src/os/shared/src/osapi-countsem.c b/src/os/shared/src/osapi-countsem.c index d0e248167..a47988841 100644 --- a/src/os/shared/src/osapi-countsem.c +++ b/src/os/shared/src/osapi-countsem.c @@ -88,9 +88,9 @@ int32 OS_CountSemAPI_Init(void) *-----------------------------------------------------------------*/ int32 OS_CountSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initial_value, uint32 options) { - OS_common_record_t *record; - int32 return_code; - osal_index_t local_id; + int32 return_code; + OS_object_token_t token; + OS_count_sem_internal_record_t *countsem; /* Check for NULL pointers */ if (sem_id == NULL || sem_name == NULL) @@ -104,18 +104,19 @@ int32 OS_CountSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_init } /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, sem_name, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, sem_name, &token); if (return_code == OS_SUCCESS) { - /* Save all the data to our own internal table */ - strcpy(OS_count_sem_table[local_id].obj_name, sem_name); - record->name_entry = OS_count_sem_table[local_id].obj_name; + countsem = OS_OBJECT_TABLE_GET(OS_count_sem_table, token); + + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, countsem, obj_name, sem_name); /* Now call the OS-specific implementation. This reads info from the table. */ - return_code = OS_CountSemCreate_Impl(local_id, sem_initial_value, options); + return_code = OS_CountSemCreate_Impl(OS_ObjectIndexFromToken(&token), sem_initial_value, options); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, sem_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, sem_id); } return return_code; @@ -132,17 +133,16 @@ int32 OS_CountSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_init *-----------------------------------------------------------------*/ int32 OS_CountSemDelete(osal_id_t sem_id) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_CountSemDelete_Impl(local_id); + return_code = OS_CountSemDelete_Impl(OS_ObjectIndexFromToken(&token)); /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, record); + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } return return_code; @@ -159,15 +159,14 @@ int32 OS_CountSemDelete(osal_id_t sem_id) *-----------------------------------------------------------------*/ int32 OS_CountSemGive(osal_id_t sem_id) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_CountSemGive_Impl(local_id); + return_code = OS_CountSemGive_Impl(OS_ObjectIndexFromToken(&token)); } return return_code; @@ -184,15 +183,14 @@ int32 OS_CountSemGive(osal_id_t sem_id) *-----------------------------------------------------------------*/ int32 OS_CountSemTake(osal_id_t sem_id) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_CountSemTake_Impl(local_id); + return_code = OS_CountSemTake_Impl(OS_ObjectIndexFromToken(&token)); } return return_code; @@ -208,15 +206,14 @@ int32 OS_CountSemTake(osal_id_t sem_id) *-----------------------------------------------------------------*/ int32 OS_CountSemTimedWait(osal_id_t sem_id, uint32 msecs) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_CountSemTimedWait_Impl(local_id, msecs); + return_code = OS_CountSemTimedWait_Impl(OS_ObjectIndexFromToken(&token), msecs); } return return_code; @@ -255,7 +252,7 @@ int32 OS_CountSemGetIdByName(osal_id_t *sem_id, const char *sem_name) int32 OS_CountSemGetInfo(osal_id_t sem_id, OS_count_sem_prop_t *count_prop) { OS_common_record_t *record; - osal_index_t local_id; + OS_object_token_t token; int32 return_code; /* Check parameters */ @@ -267,14 +264,17 @@ int32 OS_CountSemGetInfo(osal_id_t sem_id, OS_count_sem_prop_t *count_prop) memset(count_prop, 0, sizeof(OS_count_sem_prop_t)); /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { + record = OS_OBJECT_TABLE_GET(OS_global_count_sem_table, token); + strncpy(count_prop->name, record->name_entry, OS_MAX_API_NAME - 1); count_prop->creator = record->creator; - return_code = OS_CountSemGetInfo_Impl(local_id, count_prop); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + return_code = OS_CountSemGetInfo_Impl(OS_ObjectIndexFromToken(&token), count_prop); + + OS_ObjectIdRelease(&token); } return return_code; diff --git a/src/os/shared/src/osapi-dir.c b/src/os/shared/src/osapi-dir.c index 5246d9a31..7f9ac053b 100644 --- a/src/os/shared/src/osapi-dir.c +++ b/src/os/shared/src/osapi-dir.c @@ -111,10 +111,10 @@ int32 OS_mkdir(const char *path, uint32 access) *-----------------------------------------------------------------*/ int32 OS_DirectoryOpen(osal_id_t *dir_id, const char *path) { - char local_path[OS_MAX_LOCAL_PATH_LEN]; - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + char local_path[OS_MAX_LOCAL_PATH_LEN]; + OS_object_token_t token; + OS_dir_internal_record_t *dir; + int32 return_code; if (dir_id == NULL || path == NULL) { @@ -125,18 +125,19 @@ int32 OS_DirectoryOpen(osal_id_t *dir_id, const char *path) if (return_code == OS_SUCCESS) { /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, NULL, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, NULL, &token); if (return_code == OS_SUCCESS) { - /* Save all the data to our own internal table */ - memset(&OS_dir_table[local_id], 0, sizeof(OS_dir_internal_record_t)); - strncpy(OS_dir_table[local_id].dir_name, path, OS_MAX_PATH_LEN - 1); + dir = OS_OBJECT_TABLE_GET(OS_dir_table, token); + + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, dir, dir_name, path); /* Now call the OS-specific implementation. */ - return_code = OS_DirOpen_Impl(local_id, local_path); + return_code = OS_DirOpen_Impl(OS_ObjectIndexFromToken(&token), local_path); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, dir_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, dir_id); } } @@ -153,18 +154,17 @@ int32 OS_DirectoryOpen(osal_id_t *dir_id, const char *path) *-----------------------------------------------------------------*/ int32 OS_DirectoryClose(osal_id_t dir_id) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Make sure the file descriptor is legit before using it */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, dir_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, dir_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_DirClose_Impl(local_id); + return_code = OS_DirClose_Impl(OS_ObjectIndexFromToken(&token)); /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, record); + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } return return_code; @@ -180,9 +180,8 @@ int32 OS_DirectoryClose(osal_id_t dir_id) *-----------------------------------------------------------------*/ int32 OS_DirectoryRead(osal_id_t dir_id, os_dirent_t *dirent) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; if (dirent == NULL) { @@ -190,7 +189,7 @@ int32 OS_DirectoryRead(osal_id_t dir_id, os_dirent_t *dirent) } /* Make sure the file descriptor is legit before using it */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, dir_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, dir_id, &token); if (return_code == OS_SUCCESS) { /* @@ -203,9 +202,9 @@ int32 OS_DirectoryRead(osal_id_t dir_id, os_dirent_t *dirent) * reads the "/" directory, the application will see the * real name (eeprom) and not the virtualized name (cf). */ - return_code = OS_DirRead_Impl(local_id, dirent); + return_code = OS_DirRead_Impl(OS_ObjectIndexFromToken(&token), dirent); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } return return_code; @@ -222,15 +221,14 @@ int32 OS_DirectoryRead(osal_id_t dir_id, os_dirent_t *dirent) *-----------------------------------------------------------------*/ int32 OS_DirectoryRewind(osal_id_t dir_id) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Make sure the file descriptor is legit before using it */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, dir_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, dir_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_DirRewind_Impl(local_id); + return_code = OS_DirRewind_Impl(OS_ObjectIndexFromToken(&token)); } return return_code; diff --git a/src/os/shared/src/osapi-file.c b/src/os/shared/src/osapi-file.c index 06cc795e8..1dc99247a 100644 --- a/src/os/shared/src/osapi-file.c +++ b/src/os/shared/src/osapi-file.c @@ -89,10 +89,10 @@ int32 OS_FileAPI_Init(void) *-----------------------------------------------------------------*/ int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 access) { - int32 return_code; - osal_index_t local_id; - OS_common_record_t *record; - char local_path[OS_MAX_LOCAL_PATH_LEN]; + int32 return_code; + char local_path[OS_MAX_LOCAL_PATH_LEN]; + OS_object_token_t token; + OS_stream_internal_record_t *stream; if (filedes == NULL) { @@ -115,19 +115,19 @@ int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 acc if (return_code == OS_SUCCESS) { /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, NULL, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, NULL, &token); if (return_code == OS_SUCCESS) { - /* Save all the data to our own internal table */ - memset(&OS_stream_table[local_id], 0, sizeof(OS_stream_internal_record_t)); - strcpy(OS_stream_table[local_id].stream_name, path); - record->name_entry = OS_stream_table[local_id].stream_name; + stream = OS_OBJECT_TABLE_GET(OS_stream_table, token); + + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, stream, stream_name, path); /* Now call the OS-specific implementation. */ - return_code = OS_FileOpen_Impl(local_id, local_path, flags, access); + return_code = OS_FileOpen_Impl(OS_ObjectIndexFromToken(&token), local_path, flags, access); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, filedes); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, filedes); } } @@ -227,18 +227,17 @@ int32 OS_open(const char *path, int32 access, uint32 mode) *-----------------------------------------------------------------*/ int32 OS_close(osal_id_t filedes) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Make sure the file descriptor is legit before using it */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, filedes, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, filedes, &token); if (return_code == OS_SUCCESS) { - return_code = OS_GenericClose_Impl(local_id); + return_code = OS_GenericClose_Impl(OS_ObjectIndexFromToken(&token)); /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, record); + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } return return_code; @@ -255,9 +254,8 @@ int32 OS_close(osal_id_t filedes) *-----------------------------------------------------------------*/ int32 OS_TimedRead(osal_id_t filedes, void *buffer, size_t nbytes, int32 timeout) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ if (buffer == NULL || nbytes == 0) @@ -265,11 +263,11 @@ int32 OS_TimedRead(osal_id_t filedes, void *buffer, size_t nbytes, int32 timeout return OS_INVALID_POINTER; } - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, filedes, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, filedes, &token); if (return_code == OS_SUCCESS) { - return_code = OS_GenericRead_Impl(local_id, buffer, nbytes, timeout); - OS_ObjectIdRefcountDecr(record); + return_code = OS_GenericRead_Impl(OS_ObjectIndexFromToken(&token), buffer, nbytes, timeout); + OS_ObjectIdRelease(&token); } return return_code; @@ -285,9 +283,8 @@ int32 OS_TimedRead(osal_id_t filedes, void *buffer, size_t nbytes, int32 timeout *-----------------------------------------------------------------*/ int32 OS_TimedWrite(osal_id_t filedes, const void *buffer, size_t nbytes, int32 timeout) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ if (buffer == NULL || nbytes == 0) @@ -295,11 +292,11 @@ int32 OS_TimedWrite(osal_id_t filedes, const void *buffer, size_t nbytes, int32 return OS_INVALID_POINTER; } - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, filedes, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, filedes, &token); if (return_code == OS_SUCCESS) { - return_code = OS_GenericWrite_Impl(local_id, buffer, nbytes, timeout); - OS_ObjectIdRefcountDecr(record); + return_code = OS_GenericWrite_Impl(OS_ObjectIndexFromToken(&token), buffer, nbytes, timeout); + OS_ObjectIdRelease(&token); } return return_code; @@ -393,16 +390,15 @@ int32 OS_stat(const char *path, os_fstat_t *filestats) *-----------------------------------------------------------------*/ int32 OS_lseek(osal_id_t filedes, int32 offset, uint32 whence) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Make sure the file descriptor is legit before using it */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, filedes, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, filedes, &token); if (return_code == OS_SUCCESS) { - return_code = OS_GenericSeek_Impl(local_id, offset, whence); - OS_ObjectIdRefcountDecr(record); + return_code = OS_GenericSeek_Impl(OS_ObjectIndexFromToken(&token), offset, whence); + OS_ObjectIdRelease(&token); } return return_code; @@ -441,10 +437,11 @@ int32 OS_remove(const char *path) *-----------------------------------------------------------------*/ int32 OS_rename(const char *old, const char *new) { - osal_index_t i; - int32 return_code; - char old_path[OS_MAX_LOCAL_PATH_LEN]; - char new_path[OS_MAX_LOCAL_PATH_LEN]; + OS_object_iter_t iter; + OS_stream_internal_record_t *stream; + int32 return_code; + char old_path[OS_MAX_LOCAL_PATH_LEN]; + char new_path[OS_MAX_LOCAL_PATH_LEN]; return_code = OS_TranslatePath(old, old_path); if (return_code == OS_SUCCESS) @@ -459,17 +456,19 @@ int32 OS_rename(const char *old, const char *new) if (return_code == OS_SUCCESS) { - OS_Lock_Global(LOCAL_OBJID_TYPE); - for (i = 0; i < OS_MAX_NUM_OPEN_FILES; i++) + OS_ObjectIdIterateActive(LOCAL_OBJID_TYPE, &iter); + + while (OS_ObjectIdIteratorGetNext(&iter)) { - if (OS_ObjectIdDefined(OS_global_stream_table[i].active_id) && - OS_stream_table[i].socket_domain == OS_SocketDomain_INVALID && - strcmp(OS_stream_table[i].stream_name, old) == 0) + stream = OS_OBJECT_TABLE_GET(OS_stream_table, iter.token); + + if (stream->socket_domain == OS_SocketDomain_INVALID && strcmp(stream->stream_name, old) == 0) { - strcpy(OS_stream_table[i].stream_name, new); + strcpy(stream->stream_name, new); } } - OS_Unlock_Global(LOCAL_OBJID_TYPE); + + OS_ObjectIdIteratorDestroy(&iter); } return return_code; @@ -583,7 +582,7 @@ int32 OS_mv(const char *src, const char *dest) int32 OS_FDGetInfo(osal_id_t filedes, OS_file_prop_t *fd_prop) { OS_common_record_t *record; - osal_index_t local_id; + OS_object_token_t token; int32 return_code; /* Check parameters */ @@ -595,13 +594,16 @@ int32 OS_FDGetInfo(osal_id_t filedes, OS_file_prop_t *fd_prop) memset(fd_prop, 0, sizeof(OS_file_prop_t)); /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, filedes, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, filedes, &token); if (return_code == OS_SUCCESS) { + record = OS_OBJECT_TABLE_GET(OS_global_stream_table, token); + strncpy(fd_prop->Path, record->name_entry, OS_MAX_PATH_LEN - 1); fd_prop->User = record->creator; fd_prop->IsValid = true; - OS_Unlock_Global(LOCAL_OBJID_TYPE); + + OS_ObjectIdRelease(&token); } return return_code; @@ -618,8 +620,9 @@ int32 OS_FDGetInfo(osal_id_t filedes, OS_file_prop_t *fd_prop) *-----------------------------------------------------------------*/ int32 OS_FileOpenCheck(const char *Filename) { - int32 return_code; - osal_index_t i; + int32 return_code; + OS_object_iter_t iter; + OS_stream_internal_record_t *stream; if (Filename == NULL) { @@ -628,20 +631,19 @@ int32 OS_FileOpenCheck(const char *Filename) return_code = OS_ERROR; - OS_Lock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdIterateActive(LOCAL_OBJID_TYPE, &iter); - for (i = 0; i < OS_MAX_NUM_OPEN_FILES; i++) + while (OS_ObjectIdIteratorGetNext(&iter)) { - if (OS_ObjectIdDefined(OS_global_stream_table[i].active_id) && - OS_stream_table[i].socket_domain == OS_SocketDomain_INVALID && - (strcmp(OS_stream_table[i].stream_name, Filename) == 0)) + stream = OS_OBJECT_TABLE_GET(OS_stream_table, iter.token); + if (stream->socket_domain == OS_SocketDomain_INVALID && (strcmp(stream->stream_name, Filename) == 0)) { return_code = OS_SUCCESS; break; } - } /* end for */ + } - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdIteratorDestroy(&iter); return return_code; } /* end OS_FileOpenCheck */ @@ -656,9 +658,10 @@ int32 OS_FileOpenCheck(const char *Filename) *-----------------------------------------------------------------*/ int32 OS_CloseFileByName(const char *Filename) { - int32 return_code; - int32 close_code; - osal_index_t i; + int32 return_code; + int32 close_code; + OS_object_iter_t iter; + OS_stream_internal_record_t *stream; if (Filename == NULL) { @@ -667,27 +670,25 @@ int32 OS_CloseFileByName(const char *Filename) return_code = OS_FS_ERR_PATH_INVALID; - OS_Lock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdIterateActive(LOCAL_OBJID_TYPE, &iter); - for (i = 0; i < OS_MAX_NUM_OPEN_FILES; i++) + while (OS_ObjectIdIteratorGetNext(&iter)) { - if (OS_ObjectIdDefined(OS_global_stream_table[i].active_id) && - OS_stream_table[i].socket_domain == OS_SocketDomain_INVALID && - (strcmp(OS_stream_table[i].stream_name, Filename) == 0)) + stream = OS_OBJECT_TABLE_GET(OS_stream_table, iter.token); + + if (stream->socket_domain == OS_SocketDomain_INVALID && (strcmp(stream->stream_name, Filename) == 0)) { - close_code = OS_GenericClose_Impl(i); - if (close_code == OS_SUCCESS) - { - OS_global_stream_table[i].active_id = OS_OBJECT_ID_UNDEFINED; - } + /* call OS_close() on the entry referred to by the iterator */ + close_code = OS_ObjectIdIteratorProcessEntry(&iter, OS_close); + if (return_code == OS_FS_ERR_PATH_INVALID || close_code != OS_SUCCESS) { return_code = close_code; } } - } /* end for */ + } - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdIteratorDestroy(&iter); return (return_code); @@ -703,31 +704,25 @@ int32 OS_CloseFileByName(const char *Filename) *-----------------------------------------------------------------*/ int32 OS_CloseAllFiles(void) { - int32 return_code; - int32 close_code; - osal_index_t i; + int32 return_code; + int32 close_code; + OS_object_iter_t iter; return_code = OS_SUCCESS; - OS_Lock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdIterateActive(LOCAL_OBJID_TYPE, &iter); - for (i = 0; i < OS_MAX_NUM_OPEN_FILES; i++) + while (OS_ObjectIdIteratorGetNext(&iter)) { - if (OS_ObjectIdDefined(OS_global_stream_table[i].active_id)) + /* call OS_close() on the entry referred to by the iterator */ + close_code = OS_ObjectIdIteratorProcessEntry(&iter, OS_close); + if (close_code != OS_SUCCESS) { - close_code = OS_GenericClose_Impl(i); - if (close_code == OS_SUCCESS) - { - OS_global_stream_table[i].active_id = OS_OBJECT_ID_UNDEFINED; - } - if (close_code != OS_SUCCESS) - { - return_code = close_code; - } + return_code = close_code; } - } /* end for */ + } - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdIteratorDestroy(&iter); return (return_code); diff --git a/src/os/shared/src/osapi-filesys.c b/src/os/shared/src/osapi-filesys.c index ed8effd21..711ef7fb5 100644 --- a/src/os/shared/src/osapi-filesys.c +++ b/src/os/shared/src/osapi-filesys.c @@ -104,10 +104,9 @@ bool OS_FileSys_FindVirtMountPoint(void *ref, osal_index_t local_id, const OS_co int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fsvolname, size_t blocksize, osal_blockcount_t numblocks, bool should_format) { - OS_common_record_t * global; OS_filesys_internal_record_t *local; int32 return_code; - osal_index_t local_id; + OS_object_token_t token; /* ** Check parameters @@ -129,14 +128,13 @@ int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fs return OS_FS_ERR_PATH_TOO_LONG; } - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, fsdevname, &local_id, &global); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, fsdevname, &token); if (return_code == OS_SUCCESS) { - local = &OS_filesys_table[local_id]; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, token); - memset(local, 0, sizeof(*local)); - global->name_entry = local->device_name; - strcpy(local->device_name, fsdevname); + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, local, device_name, fsdevname); /* populate the VolumeName and BlockSize ahead of the Impl call, * so the implementation can reference this info if necessary */ @@ -159,7 +157,7 @@ int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fs local->fstype = OS_FILESYS_TYPE_VOLATILE_DISK; } - return_code = OS_FileSysStartVolume_Impl(local_id); + return_code = OS_FileSysStartVolume_Impl(OS_ObjectIndexFromToken(&token)); if (return_code == OS_SUCCESS) { @@ -169,7 +167,7 @@ int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fs */ if (should_format) { - return_code = OS_FileSysFormatVolume_Impl(local_id); + return_code = OS_FileSysFormatVolume_Impl(OS_ObjectIndexFromToken(&token)); } if (return_code == OS_SUCCESS) @@ -178,18 +176,18 @@ int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fs } else { - /* + /* * To avoid leaving in an intermediate state, * this also stops the volume if formatting failed. * Cast to void to repress analysis warnings for * ignored return value. */ - (void)OS_FileSysStopVolume_Impl(local_id); + (void)OS_FileSysStopVolume_Impl(OS_ObjectIndexFromToken(&token)); } } /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, global, NULL); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, NULL); } return return_code; @@ -226,10 +224,9 @@ int32 OS_FileSysAPI_Init(void) *-----------------------------------------------------------------*/ int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const char *virt_path) { - OS_common_record_t * global; OS_filesys_internal_record_t *local; int32 return_code; - osal_index_t local_id; + OS_object_token_t token; const char * dev_name; /* @@ -263,14 +260,14 @@ int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const return OS_ERR_NAME_TOO_LONG; } - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, dev_name, &local_id, &global); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, dev_name, &token); if (return_code == OS_SUCCESS) { - local = &OS_filesys_table[local_id]; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, token); + + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, local, device_name, dev_name); - memset(local, 0, sizeof(*local)); - global->name_entry = local->device_name; - strncpy(local->device_name, dev_name, sizeof(local->device_name) - 1); strncpy(local->volume_name, dev_name, sizeof(local->volume_name) - 1); strncpy(local->system_mountpt, phys_path, sizeof(local->system_mountpt) - 1); strncpy(local->virtual_mountpt, virt_path, sizeof(local->virtual_mountpt) - 1); @@ -285,12 +282,12 @@ int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const * The "mount" implementation is required as it will * create the mountpoint if it does not already exist */ - return_code = OS_FileSysStartVolume_Impl(local_id); + return_code = OS_FileSysStartVolume_Impl(OS_ObjectIndexFromToken(&token)); if (return_code == OS_SUCCESS) { local->flags |= OS_FILESYS_FLAG_IS_READY; - return_code = OS_FileSysMountVolume_Impl(local_id); + return_code = OS_FileSysMountVolume_Impl(OS_ObjectIndexFromToken(&token)); } if (return_code == OS_SUCCESS) @@ -302,7 +299,7 @@ int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const } /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, global, filesys_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, filesys_id); } return return_code; @@ -348,9 +345,8 @@ int32 OS_mkfs(char *address, const char *devname, const char *volname, size_t bl *-----------------------------------------------------------------*/ int32 OS_rmfs(const char *devname) { - int32 return_code; - osal_index_t local_id; - OS_common_record_t *global; + int32 return_code; + OS_object_token_t token; if (devname == NULL) { @@ -362,11 +358,9 @@ int32 OS_rmfs(const char *devname) return OS_FS_ERR_PATH_TOO_LONG; } - return_code = OS_ObjectIdGetByName(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, devname, &global); + return_code = OS_ObjectIdGetByName(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, devname, &token); if (return_code == OS_SUCCESS) { - OS_ObjectIdToArrayIndex(LOCAL_OBJID_TYPE, global->active_id, &local_id); - /* * NOTE: It is likely that if the file system is mounted, * this call to stop the volume will fail. @@ -375,16 +369,10 @@ int32 OS_rmfs(const char *devname) * the filesystem is unmounted first, but this would break * compatibility with the existing unit tests. */ - return_code = OS_FileSysStopVolume_Impl(local_id); - - /* Free the entry in the master table now while still locked */ - if (return_code == OS_SUCCESS) - { - /* Only need to clear the ID as zero is the "unused" flag */ - global->active_id = OS_OBJECT_ID_UNDEFINED; - } + return_code = OS_FileSysStopVolume_Impl(OS_ObjectIndexFromToken(&token)); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + /* Free the entry in the master table */ + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } else { @@ -435,8 +423,7 @@ int32 OS_initfs(char *address, const char *devname, const char *volname, size_t int32 OS_mount(const char *devname, const char *mountpoint) { int32 return_code; - osal_index_t local_id; - OS_common_record_t * global; + OS_object_token_t token; OS_filesys_internal_record_t *local; /* Check parameters */ @@ -450,11 +437,10 @@ int32 OS_mount(const char *devname, const char *mountpoint) return OS_FS_ERR_PATH_TOO_LONG; } - return_code = OS_ObjectIdGetByName(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, devname, &global); + return_code = OS_ObjectIdGetByName(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, devname, &token); if (return_code == OS_SUCCESS) { - OS_ObjectIdToArrayIndex(LOCAL_OBJID_TYPE, global->active_id, &local_id); - local = &OS_filesys_table[local_id]; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, token); /* * READY flag should be set (mkfs/initfs must have been called on this FS) @@ -477,7 +463,7 @@ int32 OS_mount(const char *devname, const char *mountpoint) } else { - return_code = OS_FileSysMountVolume_Impl(local_id); + return_code = OS_FileSysMountVolume_Impl(OS_ObjectIndexFromToken(&token)); } if (return_code == OS_SUCCESS) @@ -488,7 +474,7 @@ int32 OS_mount(const char *devname, const char *mountpoint) strcpy(local->virtual_mountpt, mountpoint); } - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } if (return_code != OS_SUCCESS) @@ -511,8 +497,7 @@ int32 OS_mount(const char *devname, const char *mountpoint) int32 OS_unmount(const char *mountpoint) { int32 return_code; - osal_index_t local_id; - OS_common_record_t * global; + OS_object_token_t token; OS_filesys_internal_record_t *local; /* Check parameters */ @@ -526,13 +511,12 @@ int32 OS_unmount(const char *mountpoint) return OS_FS_ERR_PATH_TOO_LONG; } - return_code = OS_ObjectIdGetBySearch(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, OS_FileSys_FindVirtMountPoint, - (void *)mountpoint, &global); + return_code = OS_ObjectIdGetBySearch(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, OS_FileSys_FindVirtMountPoint, + (void *)mountpoint, &token); if (return_code == OS_SUCCESS) { - OS_ObjectIdToArrayIndex(LOCAL_OBJID_TYPE, global->active_id, &local_id); - local = &OS_filesys_table[local_id]; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, token); /* * FIXED flag should always be unset (these don't support mount/unmount at all) @@ -549,7 +533,7 @@ int32 OS_unmount(const char *mountpoint) } else { - return_code = OS_FileSysUnmountVolume_Impl(local_id); + return_code = OS_FileSysUnmountVolume_Impl(OS_ObjectIndexFromToken(&token)); } if (return_code == OS_SUCCESS) @@ -559,7 +543,7 @@ int32 OS_unmount(const char *mountpoint) local->flags &= ~(OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL); } - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } if (return_code != OS_SUCCESS) @@ -580,10 +564,9 @@ int32 OS_unmount(const char *mountpoint) *-----------------------------------------------------------------*/ int32 OS_fsBlocksFree(const char *name) { - int32 return_code; - OS_statvfs_t statfs; - osal_index_t local_id; - OS_common_record_t *global; + int32 return_code; + OS_statvfs_t statfs; + OS_object_token_t token; if (name == NULL) { @@ -596,15 +579,13 @@ int32 OS_fsBlocksFree(const char *name) } return_code = OS_ObjectIdGetBySearch(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, OS_FileSys_FindVirtMountPoint, - (void *)name, &global); + (void *)name, &token); if (return_code == OS_SUCCESS) { - OS_ObjectIdToArrayIndex(LOCAL_OBJID_TYPE, global->active_id, &local_id); - - return_code = OS_FileSysStatVolume_Impl(local_id, &statfs); + return_code = OS_FileSysStatVolume_Impl(OS_ObjectIndexFromToken(&token), &statfs); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); if (return_code == OS_SUCCESS) { @@ -631,10 +612,9 @@ int32 OS_fsBlocksFree(const char *name) *-----------------------------------------------------------------*/ int32 OS_fsBytesFree(const char *name, uint64 *bytes_free) { - int32 return_code; - OS_statvfs_t statfs; - osal_index_t local_id; - OS_common_record_t *global; + int32 return_code; + OS_statvfs_t statfs; + OS_object_token_t token; if (name == NULL || bytes_free == NULL) { @@ -647,15 +627,13 @@ int32 OS_fsBytesFree(const char *name, uint64 *bytes_free) } return_code = OS_ObjectIdGetBySearch(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, OS_FileSys_FindVirtMountPoint, - (void *)name, &global); + (void *)name, &token); if (return_code == OS_SUCCESS) { - OS_ObjectIdToArrayIndex(LOCAL_OBJID_TYPE, global->active_id, &local_id); + return_code = OS_FileSysStatVolume_Impl(OS_ObjectIndexFromToken(&token), &statfs); - return_code = OS_FileSysStatVolume_Impl(local_id, &statfs); - - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); if (return_code == OS_SUCCESS) { @@ -682,9 +660,8 @@ int32 OS_fsBytesFree(const char *name, uint64 *bytes_free) *-----------------------------------------------------------------*/ int32 OS_chkfs(const char *name, bool repair) { - osal_index_t local_id; - int32 return_code; - OS_common_record_t *global; + OS_object_token_t token; + int32 return_code; /* ** Check for a null pointer @@ -704,15 +681,13 @@ int32 OS_chkfs(const char *name, bool repair) /* Get a reference lock, as a filesystem check could take some time. */ return_code = OS_ObjectIdGetBySearch(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, OS_FileSys_FindVirtMountPoint, - (void *)name, &global); + (void *)name, &token); if (return_code == OS_SUCCESS) { - OS_ObjectIdToArrayIndex(LOCAL_OBJID_TYPE, global->active_id, &local_id); - - return_code = OS_FileSysCheckVolume_Impl(local_id, repair); + return_code = OS_FileSysCheckVolume_Impl(OS_ObjectIndexFromToken(&token), repair); - OS_ObjectIdRefcountDecr(global); + OS_ObjectIdRelease(&token); } return return_code; @@ -729,9 +704,8 @@ int32 OS_chkfs(const char *name, bool repair) *-----------------------------------------------------------------*/ int32 OS_FS_GetPhysDriveName(char *PhysDriveName, const char *MountPoint) { - osal_index_t local_id; + OS_object_token_t token; int32 return_code; - OS_common_record_t * global; OS_filesys_internal_record_t *local; if (MountPoint == NULL || PhysDriveName == NULL) @@ -746,12 +720,11 @@ int32 OS_FS_GetPhysDriveName(char *PhysDriveName, const char *MountPoint) /* Get a reference lock, as a filesystem check could take some time. */ return_code = OS_ObjectIdGetBySearch(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, OS_FileSys_FindVirtMountPoint, - (void *)MountPoint, &global); + (void *)MountPoint, &token); if (return_code == OS_SUCCESS) { - OS_ObjectIdToArrayIndex(LOCAL_OBJID_TYPE, global->active_id, &local_id); - local = &OS_filesys_table[local_id]; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, token); if ((local->flags & OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM) != 0) { @@ -763,7 +736,7 @@ int32 OS_FS_GetPhysDriveName(char *PhysDriveName, const char *MountPoint) return_code = OS_ERR_INCORRECT_OBJ_STATE; } - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } else { @@ -835,10 +808,9 @@ int32 OS_GetFsInfo(os_fsinfo_t *filesys_info) *-----------------------------------------------------------------*/ int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath) { - osal_index_t local_id; + OS_object_token_t token; int32 return_code; const char * name_ptr; - OS_common_record_t * global; OS_filesys_internal_record_t *local; size_t SysMountPointLen; size_t VirtPathLen; @@ -888,7 +860,7 @@ int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath) /* Get a reference lock, as a filesystem check could take some time. */ return_code = OS_ObjectIdGetBySearch(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, OS_FileSys_FindVirtMountPoint, - (void *)VirtualPath, &global); + (void *)VirtualPath, &token); if (return_code != OS_SUCCESS) { @@ -896,8 +868,7 @@ int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath) } else { - OS_ObjectIdToArrayIndex(LOCAL_OBJID_TYPE, global->active_id, &local_id); - local = &OS_filesys_table[local_id]; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, token); if ((local->flags & OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM) != 0) { @@ -913,7 +884,7 @@ int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath) return_code = OS_ERR_INCORRECT_OBJ_STATE; } - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } if (return_code == OS_SUCCESS) diff --git a/src/os/shared/src/osapi-idmap.c b/src/os/shared/src/osapi-idmap.c index 858c583cd..44fee7580 100644 --- a/src/os/shared/src/osapi-idmap.c +++ b/src/os/shared/src/osapi-idmap.c @@ -210,6 +210,22 @@ uint32 OS_GetBaseForObjectType(osal_objtype_t idtype) * (not used outside of this unit) **************************************************************/ +/*---------------------------------------------------------------- + * + * Function: OS_ObjectIdGlobalFromToken + * + * Purpose: Local helper routine, not part of OSAL API. + * Gets the global/common record associated with the token + * + * returns: pointer to record (never NULL - token MUST be valid) + * + *-----------------------------------------------------------------*/ +OS_common_record_t *OS_ObjectIdGlobalFromToken(const OS_object_token_t *token) +{ + uint32 base_idx = OS_GetBaseForObjectType(token->obj_type); + return &OS_common_table[base_idx + token->obj_idx]; +} + /*---------------------------------------------------------------- * * Function: OS_ObjectNameMatch @@ -219,7 +235,7 @@ uint32 OS_GetBaseForObjectType(osal_objtype_t idtype) * a reference value (which must be a const char* string). * * This allows OS_ObjectIdFindByName() to be implemented using the - * generic OS_ObjectIdSearch() routine. + * generic OS_ObjectIdFindNextMatch() routine. * * returns: true if match, false otherwise * @@ -231,7 +247,7 @@ bool OS_ObjectNameMatch(void *ref, osal_index_t local_id, const OS_common_record /*---------------------------------------------------------------- * - * Function: OS_ObjectIdInitiateLock + * Function: OS_ObjectIdTransactionInit * * Purpose: Local helper routine, not part of OSAL API. * Initiate the locking process for the given mode and ID type, prior @@ -240,22 +256,67 @@ bool OS_ObjectNameMatch(void *ref, osal_index_t local_id, const OS_common_record * For any lock_mode other than OS_LOCK_MODE_NONE, this acquires the * global table lock for that ID type. * - * Once the lookup operation is completed, the OS_ObjectIdConvertLock() + * Once the lookup operation is completed, the OS_ObjectIdConvertToken() * routine should be used to convert this global lock into the actual * lock type requested (lock_mode). * *-----------------------------------------------------------------*/ -void OS_ObjectIdInitiateLock(OS_lock_mode_t lock_mode, osal_objtype_t idtype) +int32 OS_ObjectIdTransactionInit(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS_object_token_t *token) { + memset(token, 0, sizeof(*token)); + + if (OS_SharedGlobalVars.Initialized == false) + { + return OS_ERROR; + } + + /* + * only "exclusive" locks allowed after shutdown request (this is mode used for delete). + * All regular ops will be blocked. + */ + if (OS_SharedGlobalVars.ShutdownFlag == OS_SHUTDOWN_MAGIC_NUMBER && lock_mode != OS_LOCK_MODE_EXCLUSIVE) + { + return OS_ERR_INCORRECT_OBJ_STATE; + } + + if (idtype >= OS_OBJECT_TYPE_USER) + { + return OS_ERR_INCORRECT_OBJ_TYPE; + } + if (lock_mode != OS_LOCK_MODE_NONE) { OS_Lock_Global(idtype); } -} /* end OS_ObjectIdInitiateLock */ + + token->lock_mode = lock_mode; + token->obj_type = idtype; + token->obj_idx = OSAL_INDEX_C(-1); + + return OS_SUCCESS; + +} /* end OS_ObjectIdTransactionInit */ + +/*---------------------------------------------------------------- + * + * Function: OS_ObjectIdTransactionInit + * + * Purpose: Local helper routine, not part of OSAL API. + * Cancels/aborts a previously initialized transaction + * + *-----------------------------------------------------------------*/ +void OS_ObjectIdTransactionCancel(OS_object_token_t *token) +{ + if (token->lock_mode != OS_LOCK_MODE_NONE) + { + OS_Unlock_Global(token->obj_type); + token->lock_mode = OS_LOCK_MODE_NONE; + } +} /*---------------------------------------------------------------- * - * Function: OS_ObjectIdConvertLock + * Function: OS_ObjectIdConvertToken * * Purpose: Local helper routine, not part of OSAL API. * @@ -291,18 +352,19 @@ void OS_ObjectIdInitiateLock(OS_lock_mode_t lock_mode, osal_objtype_t idtype) * all lock modes other than OS_LOCK_MODE_NONE. * *-----------------------------------------------------------------*/ -int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, osal_objtype_t idtype, osal_id_t reference_id, - OS_common_record_t *obj) +int32 OS_ObjectIdConvertToken(OS_object_token_t *token) { int32 return_code = OS_ERROR; uint32 exclusive_bits = 0; uint32 attempts = 0; + OS_common_record_t *obj = OS_ObjectIdGlobalFromToken(token); + while (true) { /* Validate the integrity of the ID. As the "active_id" is a single * integer, we can do this check regardless of whether global is locked or not. */ - if (!OS_ObjectIdEqual(obj->active_id, reference_id)) + if (!OS_ObjectIdEqual(obj->active_id, OS_ObjectIdFromToken(token))) { /* The ID does not match, so unlock and return error. * This basically means the ID was stale or otherwise no longer invalid */ @@ -314,7 +376,7 @@ int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, osal_objtype_t idtype, os * The REFCOUNT and EXCLUSIVE lock modes require additional * conditions on before they can be successful. */ - if (lock_mode == OS_LOCK_MODE_REFCOUNT) + if (token->lock_mode == OS_LOCK_MODE_REFCOUNT) { /* As long as no exclusive request is pending, we can increment the * refcount and good to go. */ @@ -325,7 +387,7 @@ int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, osal_objtype_t idtype, os break; } } - else if (lock_mode == OS_LOCK_MODE_EXCLUSIVE) + else if (token->lock_mode == OS_LOCK_MODE_EXCLUSIVE) { /* * Set the exclusive request flag -- this will prevent anyone else from @@ -371,9 +433,9 @@ int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, osal_objtype_t idtype, os break; } - OS_Unlock_Global(idtype); + OS_Unlock_Global(token->obj_type); OS_TaskDelay_Impl(attempts); - OS_Lock_Global(idtype); + OS_Lock_Global(token->obj_type); } /* @@ -382,7 +444,7 @@ int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, osal_objtype_t idtype, os * If lock_mode is OS_LOCK_MODE_NONE, then the table was never locked * to begin with, and therefore never needs to be unlocked. */ - if (lock_mode != OS_LOCK_MODE_NONE) + if (token->lock_mode != OS_LOCK_MODE_NONE) { /* * In case any exclusive bits were set locally, unset them now @@ -391,25 +453,23 @@ int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, osal_objtype_t idtype, os obj->flags &= ~exclusive_bits; /* - * If the operation failed, then we always unlock the global table. - * * On a successful operation, the global is unlocked if it is a REFCOUNT * style lock. For other styles (GLOBAL or EXCLUSIVE) the global lock * should be maintained and returned to the caller. */ - if (return_code != OS_SUCCESS || lock_mode == OS_LOCK_MODE_REFCOUNT) + if (return_code == OS_SUCCESS && token->lock_mode == OS_LOCK_MODE_REFCOUNT) { - OS_Unlock_Global(idtype); + OS_Unlock_Global(token->obj_type); } } return return_code; -} /* end OS_ObjectIdConvertLock */ +} /* end OS_ObjectIdConvertToken */ /*---------------------------------------------------------------- * - * Function: OS_ObjectIdSearch + * Function: OS_ObjectIdFindNextMatch * * Purpose: Local helper routine, not part of OSAL API. * Locate an existing object using the supplied Match function. @@ -421,47 +481,43 @@ int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, osal_objtype_t idtype, os * returns: OS_ERR_NAME_NOT_FOUND if not found, OS_SUCCESS if match is found * *-----------------------------------------------------------------*/ -int32 OS_ObjectIdSearch(osal_objtype_t idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg, OS_common_record_t **record) +int32 OS_ObjectIdFindNextMatch(OS_ObjectMatchFunc_t MatchFunc, void *arg, OS_object_token_t *token) { int32 return_code; uint32 obj_count; - osal_index_t local_id; - OS_common_record_t *obj; + OS_common_record_t *base; + OS_common_record_t *record; - return_code = OS_ERR_NAME_NOT_FOUND; - obj = &OS_common_table[OS_GetBaseForObjectType(idtype)]; - obj_count = OS_GetMaxForObjectType(idtype); - local_id = 0; + return_code = OS_ERR_NAME_NOT_FOUND; + base = &OS_common_table[OS_GetBaseForObjectType(token->obj_type)]; + obj_count = OS_GetMaxForObjectType(token->obj_type); + token->obj_id = OS_OBJECT_ID_UNDEFINED; while (true) { - if (obj_count == 0) + ++token->obj_idx; + + if (token->obj_idx >= obj_count) { - obj = NULL; break; } - --obj_count; - if (OS_ObjectIdDefined(obj->active_id) && MatchFunc(arg, local_id, obj)) + record = OS_OBJECT_TABLE_GET(base, *token); + + if (OS_ObjectIdDefined(record->active_id) && MatchFunc(arg, token->obj_idx, record)) { - return_code = OS_SUCCESS; + return_code = OS_SUCCESS; + token->obj_id = record->active_id; break; } - ++obj; - ++local_id; - } - - if (record != NULL) - { - *record = obj; } return return_code; -} /* end OS_ObjectIdSearch */ +} /* end OS_ObjectIdFindNextMatch */ /*---------------------------------------------------------------- * - * Function: OS_ObjectIdFindNext + * Function: OS_ObjectIdFindNextFree * * Purpose: Local helper routine, not part of OSAL API. * Find the next available Object ID of the given type @@ -476,18 +532,20 @@ int32 OS_ObjectIdSearch(osal_objtype_t idtype, OS_ObjectMatchFunc_t MatchFunc, v * * returns: OS_SUCCESS if an empty location was found. *-----------------------------------------------------------------*/ -int32 OS_ObjectIdFindNext(osal_objtype_t idtype, osal_index_t *array_index, OS_common_record_t **record) +int32 OS_ObjectIdFindNextFree(OS_object_token_t *token) { uint32 max_id; uint32 base_id; - uint32 local_id = 0; - uint32 idvalue; + uint32 local_id; + uint32 serial; uint32 i; int32 return_code; OS_common_record_t *obj = NULL; + OS_objtype_state_t *objtype_state; - base_id = OS_GetBaseForObjectType(idtype); - max_id = OS_GetMaxForObjectType(idtype); + base_id = OS_GetBaseForObjectType(token->obj_type); + max_id = OS_GetMaxForObjectType(token->obj_type); + objtype_state = &OS_objtype_state[token->obj_type]; if (max_id == 0) { @@ -496,21 +554,21 @@ int32 OS_ObjectIdFindNext(osal_objtype_t idtype, osal_index_t *array_index, OS_c * Return the "not implemented" to differentiate between * this case vs. running out of valid slots */ return_code = OS_ERR_NOT_IMPLEMENTED; - idvalue = 0; + serial = 0; } else { return_code = OS_ERR_NO_FREE_IDS; - idvalue = OS_ObjectIdToSerialNumber_Impl(OS_objtype_state[idtype].last_id_issued); + serial = OS_ObjectIdToSerialNumber_Impl(objtype_state->last_id_issued); } for (i = 0; i < max_id; ++i) { - local_id = (++idvalue) % max_id; - if (idvalue >= OS_OBJECT_INDEX_MASK) + local_id = (++serial) % max_id; + if (serial >= OS_OBJECT_INDEX_MASK) { /* reset to beginning of ID space */ - idvalue = local_id; + serial = local_id; } obj = &OS_common_table[local_id + base_id]; if (!OS_ObjectIdDefined(obj->active_id)) @@ -522,31 +580,27 @@ int32 OS_ObjectIdFindNext(osal_objtype_t idtype, osal_index_t *array_index, OS_c if (return_code == OS_SUCCESS) { - OS_ObjectIdCompose_Impl(idtype, idvalue, &obj->active_id); + token->obj_idx = OSAL_INDEX_C(local_id); + OS_ObjectIdCompose_Impl(token->obj_type, serial, &token->obj_id); /* Ensure any data in the record has been cleared */ + obj->active_id = token->obj_id; obj->name_entry = NULL; obj->creator = OS_TaskGetId(); obj->refcount = 0; - } - if (return_code != OS_SUCCESS) - { - obj = NULL; - local_id = 0; + /* preemptively update the last id issued */ + objtype_state->last_id_issued = token->obj_id; } - if (array_index != NULL) - { - *array_index = OSAL_INDEX_C(local_id); - } - if (record != NULL) + if (return_code != OS_SUCCESS) { - *record = obj; + token->obj_idx = OSAL_INDEX_C(-1); + token->obj_id = OS_OBJECT_ID_UNDEFINED; } return return_code; -} /* end OS_ObjectIdFindNext */ +} /* end OS_ObjectIdFindNextFree */ /* ********************************************************************************* @@ -694,10 +748,9 @@ void OS_Unlock_Global(osal_objtype_t idtype) * were detected while validating the ID. * *-----------------------------------------------------------------*/ -int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_common_record_t *record, osal_id_t *outid) +int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_object_token_t *token, osal_id_t *outid) { - osal_objtype_t idtype = OS_ObjectIdToType_Impl(record->active_id); - osal_id_t callback_id; + osal_id_t final_id; /* if operation was unsuccessful, then clear * the active_id field within the record, so @@ -706,72 +759,61 @@ int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_common_record_t *record, * Otherwise, ensure that the record_id to be * exported is sane (it always should be) */ - if (operation_status != OS_SUCCESS) - { - record->active_id = OS_OBJECT_ID_UNDEFINED; - } - else if (idtype == 0 || idtype >= OS_OBJECT_TYPE_USER) + if (operation_status == OS_SUCCESS) { - /* should never happen - indicates a bug. */ - operation_status = OS_ERR_INVALID_ID; - record->active_id = OS_OBJECT_ID_UNDEFINED; + final_id = token->obj_id; } else { - /* success */ - OS_objtype_state[idtype].last_id_issued = record->active_id; + final_id = OS_OBJECT_ID_UNDEFINED; } - /* snapshot the ID for callback - will be needed after unlock */ - callback_id = record->active_id; + /* Either way we must unlock the object type */ + OS_ObjectIdTransactionFinish(token, &final_id); - if (outid != NULL) + /* Give event callback to the application */ + if (operation_status == OS_SUCCESS) { - /* always write the final value to the output buffer */ - *outid = record->active_id; + OS_NotifyEvent(OS_EVENT_RESOURCE_CREATED, token->obj_id, NULL); } - /* Either way we must unlock the object type */ - OS_Unlock_Global(idtype); - - /* Give event callback to the application */ - if (OS_ObjectIdDefined(callback_id)) + if (outid != NULL) { - OS_NotifyEvent(OS_EVENT_RESOURCE_CREATED, callback_id, NULL); + /* always write the final value to the output buffer */ + *outid = final_id; } return operation_status; -} /* end OS_ObjectIdFinalizeNew */ +} /* end OS_ObjectIdFinalizeNew(, &token, ) */ /*---------------------------------------------------------------- - Function: OS_ObjectIdFinalizeDelete + Function: OS_ObjectIdFinalizeDelete(, &token) Purpose: Helper routine, not part of OSAL public API. See description in prototype ------------------------------------------------------------------*/ -int32 OS_ObjectIdFinalizeDelete(int32 operation_status, OS_common_record_t *record) +int32 OS_ObjectIdFinalizeDelete(int32 operation_status, OS_object_token_t *token) { - osal_objtype_t idtype = OS_ObjectIdToType_Impl(record->active_id); - osal_id_t callback_id; + osal_id_t final_id; /* Clear the OSAL ID if successful - this returns the record to the pool */ if (operation_status == OS_SUCCESS) { - callback_id = record->active_id; - record->active_id = OS_OBJECT_ID_UNDEFINED; + final_id = OS_OBJECT_ID_UNDEFINED; } else { - callback_id = OS_OBJECT_ID_UNDEFINED; + /* this restores the original ID */ + final_id = token->obj_id; } /* Either way we must unlock the object type */ - OS_Unlock_Global(idtype); + OS_ObjectIdTransactionFinish(token, &final_id); /* Give event callback to the application */ - if (OS_ObjectIdDefined(callback_id)) + if (operation_status == OS_SUCCESS) { - OS_NotifyEvent(OS_EVENT_RESOURCE_DELETED, callback_id, NULL); + OS_NotifyEvent(OS_EVENT_RESOURCE_DELETED, token->obj_id, NULL); } return operation_status; @@ -792,32 +834,26 @@ int32 OS_ObjectIdFinalizeDelete(int32 operation_status, OS_common_record_t *reco * *-----------------------------------------------------------------*/ int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg, - OS_common_record_t **record) + OS_object_token_t *token) { - int32 return_code; - OS_common_record_t *obj; + int32 return_code; - OS_ObjectIdInitiateLock(lock_mode, idtype); + OS_ObjectIdTransactionInit(lock_mode, idtype, token); - return_code = OS_ObjectIdSearch(idtype, MatchFunc, arg, &obj); + return_code = OS_ObjectIdFindNextMatch(MatchFunc, arg, token); if (return_code == OS_SUCCESS) { /* - * The "ConvertLock" routine will return with the global lock + * The "ConvertToken" routine will return with the global lock * in a state appropriate for returning to the caller, as indicated * by the "check_mode" parameter. */ - return_code = OS_ObjectIdConvertLock(lock_mode, idtype, obj->active_id, obj); + return_code = OS_ObjectIdConvertToken(token); } else if (lock_mode != OS_LOCK_MODE_NONE) { - OS_Unlock_Global(idtype); - } - - if (record != NULL) - { - *record = obj; + OS_ObjectIdTransactionCancel(token); } return return_code; @@ -837,10 +873,9 @@ int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS * returns: OS_ERR_NAME_NOT_FOUND if not found, OS_SUCCESS if match is found * *-----------------------------------------------------------------*/ -int32 OS_ObjectIdGetByName(OS_lock_mode_t lock_mode, osal_objtype_t idtype, const char *name, - OS_common_record_t **record) +int32 OS_ObjectIdGetByName(OS_lock_mode_t lock_mode, osal_objtype_t idtype, const char *name, OS_object_token_t *token) { - return OS_ObjectIdGetBySearch(lock_mode, idtype, OS_ObjectNameMatch, (void *)name, record); + return OS_ObjectIdGetBySearch(lock_mode, idtype, OS_ObjectNameMatch, (void *)name, token); } /* end OS_ObjectIdGetByName */ @@ -857,8 +892,8 @@ int32 OS_ObjectIdGetByName(OS_lock_mode_t lock_mode, osal_objtype_t idtype, cons *-----------------------------------------------------------------*/ int32 OS_ObjectIdFindByName(osal_objtype_t idtype, const char *name, osal_id_t *object_id) { - int32 return_code; - OS_common_record_t *global; + int32 return_code; + OS_object_token_t token; /* * As this is an internal-only function, calling it will NULL is allowed. @@ -875,11 +910,12 @@ int32 OS_ObjectIdFindByName(osal_objtype_t idtype, const char *name, osal_id_t * return OS_ERR_NAME_TOO_LONG; } - return_code = OS_ObjectIdGetByName(OS_LOCK_MODE_GLOBAL, idtype, name, &global); + return_code = OS_ObjectIdGetByName(OS_LOCK_MODE_GLOBAL, idtype, name, &token); if (return_code == OS_SUCCESS) { - *object_id = global->active_id; - OS_Unlock_Global(idtype); + *object_id = token.obj_id; + + OS_ObjectIdRelease(&token); } return return_code; @@ -902,87 +938,118 @@ int32 OS_ObjectIdFindByName(osal_objtype_t idtype, const char *name, osal_id_t * * If this returns something other than OS_SUCCESS then the global is NOT locked. * *-----------------------------------------------------------------*/ -int32 OS_ObjectIdGetById(OS_lock_mode_t lock_mode, osal_objtype_t idtype, osal_id_t id, osal_index_t *array_index, - OS_common_record_t **record) +int32 OS_ObjectIdGetById(OS_lock_mode_t lock_mode, osal_objtype_t idtype, osal_id_t id, OS_object_token_t *token) { int32 return_code; - if (OS_SharedGlobalVars.Initialized == false) + return_code = OS_ObjectIdTransactionInit(lock_mode, idtype, token); + if (return_code != OS_SUCCESS) { - return OS_ERROR; + return return_code; } - /* - * Special case to allow only OS_LOCK_MODE_EXCLUSIVE during shutdowns - * (This is the lock mode used to delete objects) - */ - if (OS_SharedGlobalVars.ShutdownFlag == OS_SHUTDOWN_MAGIC_NUMBER && lock_mode != OS_LOCK_MODE_EXCLUSIVE) + return_code = OS_ObjectIdToArrayIndex(idtype, id, &token->obj_idx); + if (return_code == OS_SUCCESS) { - return OS_ERR_INCORRECT_OBJ_STATE; + token->obj_id = id; + + /* + * The "ConvertToken" routine will return with the global lock + * in a state appropriate for returning to the caller, as indicated + * by the "check_mode" paramter. + * + * Note If this operation fails, then it always unlocks the global for + * all check_mode's other than NONE. + */ + return_code = OS_ObjectIdConvertToken(token); } - return_code = OS_ObjectIdToArrayIndex(idtype, id, array_index); if (return_code != OS_SUCCESS) { - return return_code; + OS_ObjectIdTransactionCancel(token); } - *record = &OS_common_table[*array_index + OS_GetBaseForObjectType(idtype)]; - - OS_ObjectIdInitiateLock(lock_mode, idtype); - - /* - * The "ConvertLock" routine will return with the global lock - * in a state appropriate for returning to the caller, as indicated - * by the "check_mode" paramter. - * - * Note If this operation fails, then it always unlocks the global for - * all check_mode's other than NONE. - */ - return_code = OS_ObjectIdConvertLock(lock_mode, idtype, id, *record); - return return_code; } /* end OS_ObjectIdGetById */ /*---------------------------------------------------------------- * - * Function: OS_ObjectIdRefcountDecr + * Function: OS_ObjectIdTransactionFinish * - * Purpose: Local helper routine, not part of OSAL API. - * Decrement the reference count on the resource record, which must have been - * acquired (incremented) by the caller prior to this. + * Purpose: Complete a transaction which was previously obtained via + * OS_ObjectIdGetById() or OS_ObjectIdGetBySearch(). + * + * This also updates the ID from the value in the final_id parameter, which + * is used for create/delete. * - * returns: OS_SUCCESS if decremented successfully. + * If no ID update is pending, then NULL may be passed and the ID will not + * be changed. * *-----------------------------------------------------------------*/ -int32 OS_ObjectIdRefcountDecr(OS_common_record_t *record) +void OS_ObjectIdTransactionFinish(OS_object_token_t *token, osal_id_t *final_id) { - int32 return_code; - osal_objtype_t idtype = OS_ObjectIdToType_Impl(record->active_id); + OS_common_record_t *record; - if (idtype == 0 || !OS_ObjectIdDefined(record->active_id)) + if (token->lock_mode == OS_LOCK_MODE_NONE) { - return_code = OS_ERR_INVALID_ID; + /* nothing to do */ + return; } - else + + record = OS_ObjectIdGlobalFromToken(token); + + /* re-acquire global table lock to adjust refcount */ + if (token->lock_mode == OS_LOCK_MODE_REFCOUNT) { - OS_Lock_Global(idtype); + OS_Lock_Global(token->obj_type); if (record->refcount > 0) { --record->refcount; - return_code = OS_SUCCESS; - } - else - { - return_code = OS_ERR_INCORRECT_OBJ_STATE; } + } - OS_Unlock_Global(idtype); + /* + * at this point the global mutex is always held, either + * from re-acquiring it above or it is still held from + * the original lock when using OS_LOCK_MODE_GLOBAL. + * + * If an ID update was pending (i.e. for a create/delete op) + * then do the ID update now while holding the mutex. + */ + if (final_id != NULL) + { + record->active_id = *final_id; } - return return_code; -} /* end OS_ObjectIdRefcountDecr */ + /* always unlock (this also covers OS_LOCK_MODE_GLOBAL case) */ + OS_Unlock_Global(token->obj_type); + + /* + * Setting to "NONE" indicates that this token has been + * released, and should not be released again. + */ + token->lock_mode = OS_LOCK_MODE_NONE; +} + +/*---------------------------------------------------------------- + * + * Function: OS_ObjectIdRelease + * + * Purpose: Release/Unlock a transaction token which was previously obtained via + * OS_ObjectIdGetById() or OS_ObjectIdGetBySearch(). + * + * This is used for completing normal operations other than create/delete - + * that is where the same ID exists before and after the transaction without + * change. + * + * (There is a dedicated routine for finalization of create and delete ops) + * + *-----------------------------------------------------------------*/ +void OS_ObjectIdRelease(OS_object_token_t *token) +{ + OS_ObjectIdTransactionFinish(token, NULL); +} /*---------------------------------------------------------------- * @@ -1014,30 +1081,28 @@ int32 OS_ObjectIdRefcountDecr(OS_common_record_t *record) * manipulate the global lock at all. * *-----------------------------------------------------------------*/ -int32 OS_ObjectIdAllocateNew(osal_objtype_t idtype, const char *name, osal_index_t *array_index, - OS_common_record_t **record) +int32 OS_ObjectIdAllocateNew(osal_objtype_t idtype, const char *name, OS_object_token_t *token) { int32 return_code; - if (OS_SharedGlobalVars.Initialized == false || OS_SharedGlobalVars.ShutdownFlag == OS_SHUTDOWN_MAGIC_NUMBER) + if (OS_SharedGlobalVars.ShutdownFlag == OS_SHUTDOWN_MAGIC_NUMBER) { - return OS_ERROR; + return OS_ERR_INCORRECT_OBJ_STATE; } - if (idtype >= OS_OBJECT_TYPE_USER) + return_code = OS_ObjectIdTransactionInit(OS_LOCK_MODE_EXCLUSIVE, idtype, token); + if (return_code != OS_SUCCESS) { - return OS_ERR_INCORRECT_OBJ_TYPE; + return return_code; } - OS_Lock_Global(idtype); - /* * Check if an object of the same name already exits. * If so, a new object cannot be allocated. */ if (name != NULL) { - return_code = OS_ObjectIdSearch(idtype, OS_ObjectNameMatch, (void *)name, record); + return_code = OS_ObjectIdFindNextMatch(OS_ObjectNameMatch, (void *)name, token); } else { @@ -1050,24 +1115,140 @@ int32 OS_ObjectIdAllocateNew(osal_objtype_t idtype, const char *name, osal_index } else { - return_code = OS_ObjectIdFindNext(idtype, array_index, record); + return_code = OS_ObjectIdFindNextFree(token); } if (return_code == OS_SUCCESS) { - return_code = OS_NotifyEvent(OS_EVENT_RESOURCE_ALLOCATED, (*record)->active_id, NULL); + return_code = OS_NotifyEvent(OS_EVENT_RESOURCE_ALLOCATED, token->obj_id, NULL); } /* If allocation failed for any reason, unlock the global. * otherwise the global should stay locked so remaining initialization can be done */ if (return_code != OS_SUCCESS) { - OS_Unlock_Global(idtype); + OS_ObjectIdTransactionCancel(token); } return return_code; } /* end OS_ObjectIdAllocateNew */ +/*---------------------------------------------------------------- + Function: OS_ObjectIdTransferToken + + Purpose: Transfer ownership of a token to another buffer + ------------------------------------------------------------------*/ +void OS_ObjectIdTransferToken(OS_object_token_t *token_from, OS_object_token_t *token_to) +{ + /* start with a simple copy */ + *token_to = *token_from; + + /* + * nullify the old token, such that if release/cancel + * is invoked it will have no effect (the real lock is + * now on token_to). + */ + token_from->lock_mode = OS_LOCK_MODE_NONE; +} + +/*---------------------------------------------------------------- + Function: OS_ObjectIdIteratorInit + + Purpose: Start the process of iterating through OSAL objects + ------------------------------------------------------------------*/ +int32 OS_ObjectIdIteratorInit(OS_ObjectMatchFunc_t matchfunc, void *matcharg, osal_objtype_t objtype, + OS_object_iter_t *iter) +{ + iter->match = matchfunc; + iter->arg = matcharg; + iter->limit = OS_GetMaxForObjectType(objtype); + iter->base = &OS_common_table[OS_GetBaseForObjectType(objtype)]; + + return OS_ObjectIdTransactionInit(OS_LOCK_MODE_GLOBAL, objtype, &iter->token); +} + +/*---------------------------------------------------------------- + Function: OS_ObjectFilterActive + + Purpose: Match function to iterate only active objects + ------------------------------------------------------------------*/ +bool OS_ObjectFilterActive(void *ref, osal_index_t local_id, const OS_common_record_t *obj) +{ + return OS_ObjectIdDefined(obj->active_id); +} + +/*---------------------------------------------------------------- + Function: OS_ObjectIdIterateActive + + Purpose: Start the process of iterating through OSAL objects + ------------------------------------------------------------------*/ +int32 OS_ObjectIdIterateActive(osal_objtype_t objtype, OS_object_iter_t *iter) +{ + return OS_ObjectIdIteratorInit(OS_ObjectFilterActive, NULL, objtype, iter); +} + +/*---------------------------------------------------------------- + Function: OS_ObjectIdIteratorGetNext + + Purpose: Move iterator to the next entry + ------------------------------------------------------------------*/ +bool OS_ObjectIdIteratorGetNext(OS_object_iter_t *iter) +{ + OS_common_record_t *record; + bool got_next; + + got_next = false; + iter->token.obj_id = OS_OBJECT_ID_UNDEFINED; + + do + { + ++iter->token.obj_idx; + if (iter->token.obj_idx >= iter->limit) + { + break; + } + + record = OS_OBJECT_TABLE_GET(iter->base, iter->token); + if (iter->match == NULL || iter->match(iter->arg, iter->token.obj_idx, record)) + { + iter->token.obj_id = record->active_id; + got_next = true; + } + } while (!got_next); + + return got_next; +} /* end OS_ObjectIdIteratorGetNext */ + +/*---------------------------------------------------------------- + Function: OS_ObjectIdIteratorDestroy + + Purpose: Release iterator resources + ------------------------------------------------------------------*/ +void OS_ObjectIdIteratorDestroy(OS_object_iter_t *iter) +{ + OS_ObjectIdTransactionCancel(&iter->token); +} + +/*---------------------------------------------------------------- + Function: OS_ObjectIdIteratorProcessEntry + + Purpose: Call a handler function on an iterator object ID + ------------------------------------------------------------------*/ +int32 OS_ObjectIdIteratorProcessEntry(OS_object_iter_t *iter, int32 (*func)(osal_id_t)) +{ + int32 status; + + /* + * This needs to temporarily unlock the global, + * call the handler function, then re-lock. + */ + OS_Unlock_Global(iter->token.obj_type); + status = func(iter->token.obj_id); + OS_Lock_Global(iter->token.obj_type); + + return status; +} + /* ********************************************************************************* * PUBLIC API (these functions may be called externally) @@ -1189,11 +1370,10 @@ osal_objtype_t OS_IdentifyObject(osal_id_t object_id) *-----------------------------------------------------------------*/ int32 OS_GetResourceName(osal_id_t object_id, char *buffer, size_t buffer_size) { - osal_objtype_t idtype; OS_common_record_t *record; int32 return_code; size_t name_len; - osal_index_t local_id; + OS_object_token_t token; /* sanity check the passed-in buffer and size */ if (buffer == NULL || buffer_size == 0) @@ -1208,10 +1388,11 @@ int32 OS_GetResourceName(osal_id_t object_id, char *buffer, size_t buffer_size) */ buffer[0] = 0; - idtype = OS_ObjectIdToType_Impl(object_id); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, idtype, object_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_ObjectIdToType_Impl(object_id), object_id, &token); if (return_code == OS_SUCCESS) { + record = OS_ObjectIdGlobalFromToken(&token); + if (record->name_entry != NULL) { name_len = strlen(record->name_entry); @@ -1224,7 +1405,8 @@ int32 OS_GetResourceName(osal_id_t object_id, char *buffer, size_t buffer_size) memcpy(buffer, record->name_entry, name_len); buffer[name_len] = 0; } - OS_Unlock_Global(idtype); + + OS_ObjectIdRelease(&token); } return return_code; diff --git a/src/os/shared/src/osapi-module.c b/src/os/shared/src/osapi-module.c index 2bd14899f..6510bf44c 100644 --- a/src/os/shared/src/osapi-module.c +++ b/src/os/shared/src/osapi-module.c @@ -181,11 +181,11 @@ int32 OS_ModuleAPI_Init(void) *-----------------------------------------------------------------*/ int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *filename, uint32 flags) { - char translated_path[OS_MAX_LOCAL_PATH_LEN]; - int32 return_code; - int32 filename_status; - osal_index_t local_id; - OS_common_record_t *record; + char translated_path[OS_MAX_LOCAL_PATH_LEN]; + int32 return_code; + int32 filename_status; + OS_object_token_t token; + OS_module_internal_record_t *module; /* ** Check parameters @@ -215,13 +215,15 @@ int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *f filename_status = OS_TranslatePath(filename, translated_path); /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, module_name, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, module_name, &token); if (return_code == OS_SUCCESS) { - memset(&OS_module_table[local_id], 0, sizeof(OS_module_internal_record_t)); - strncpy(OS_module_table[local_id].module_name, module_name, OS_MAX_API_NAME); - record->name_entry = OS_module_table[local_id].module_name; - OS_module_table[local_id].flags = flags; /* save user-supplied flags */ + module = OS_OBJECT_TABLE_GET(OS_module_table, token); + + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, module, module_name, module_name); + + module->flags = flags; /* save user-supplied flags */ /* * Check the statically-linked module list. @@ -237,7 +239,7 @@ int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *f if (return_code == OS_SUCCESS) { /* mark this as a statically loaded module */ - OS_module_table[local_id].module_type = OS_MODULE_TYPE_STATIC; + module->module_type = OS_MODULE_TYPE_STATIC; } else { @@ -254,16 +256,16 @@ int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *f else { /* 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; + strncpy(module->file_name, filename, OS_MAX_PATH_LEN); + module->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); + return_code = OS_ModuleLoad_Impl(OS_ObjectIndexFromToken(&token), translated_path); } } /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, module_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, module_id); } return (return_code); @@ -280,25 +282,27 @@ int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *f *-----------------------------------------------------------------*/ int32 OS_ModuleUnload(osal_id_t module_id) { - OS_common_record_t *record; - int32 return_code; - osal_index_t local_id; + OS_module_internal_record_t *module; + int32 return_code; + OS_object_token_t token; - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, module_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, module_id, &token); if (return_code == OS_SUCCESS) { + module = OS_OBJECT_TABLE_GET(OS_module_table, token); + /* * 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. */ - if (OS_module_table[local_id].module_type == OS_MODULE_TYPE_DYNAMIC) + if (module->module_type == OS_MODULE_TYPE_DYNAMIC) { - return_code = OS_ModuleUnload_Impl(local_id); + return_code = OS_ModuleUnload_Impl(OS_ObjectIndexFromToken(&token)); } /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, record); + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } return return_code; @@ -314,9 +318,10 @@ int32 OS_ModuleUnload(osal_id_t module_id) *-----------------------------------------------------------------*/ int32 OS_ModuleInfo(osal_id_t module_id, OS_module_prop_t *module_prop) { - OS_common_record_t *record; - int32 return_code; - osal_index_t local_id; + OS_common_record_t * record; + OS_module_internal_record_t *module; + int32 return_code; + OS_object_token_t token; /* Check parameters */ if (module_prop == NULL) @@ -326,15 +331,18 @@ int32 OS_ModuleInfo(osal_id_t module_id, OS_module_prop_t *module_prop) memset(module_prop, 0, sizeof(OS_module_prop_t)); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, module_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, module_id, &token); if (return_code == OS_SUCCESS) { + record = OS_OBJECT_TABLE_GET(OS_global_module_table, token); + module = OS_OBJECT_TABLE_GET(OS_module_table, token); + strncpy(module_prop->name, record->name_entry, OS_MAX_API_NAME - 1); - strncpy(module_prop->filename, OS_module_table[local_id].file_name, OS_MAX_API_NAME - 1); + strncpy(module_prop->filename, module->file_name, OS_MAX_API_NAME - 1); - return_code = OS_ModuleGetInfo_Impl(local_id, module_prop); + return_code = OS_ModuleGetInfo_Impl(OS_ObjectIndexFromToken(&token), module_prop); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } return return_code; @@ -402,7 +410,7 @@ int32 OS_ModuleSymbolLookup(osal_id_t module_id, cpuaddr *symbol_address, const int32 return_code; int32 staticsym_status; OS_common_record_t *record; - osal_index_t local_id; + OS_object_token_t token; /* ** Check parameters @@ -412,10 +420,12 @@ int32 OS_ModuleSymbolLookup(osal_id_t module_id, cpuaddr *symbol_address, const return (OS_INVALID_POINTER); } - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, module_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, module_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_ModuleSymbolLookup_Impl(local_id, symbol_address, symbol_name); + record = OS_OBJECT_TABLE_GET(OS_global_module_table, token); + + return_code = OS_ModuleSymbolLookup_Impl(OS_ObjectIndexFromToken(&token), symbol_address, symbol_name); if (return_code != OS_SUCCESS) { /* look for a static symbol that also matches this module name */ @@ -430,15 +440,14 @@ int32 OS_ModuleSymbolLookup(osal_id_t module_id, cpuaddr *symbol_address, const return_code = staticsym_status; } } - OS_Unlock_Global(LOCAL_OBJID_TYPE); + + OS_ObjectIdRelease(&token); } return (return_code); } /* end OS_ModuleSymbolLookup */ - - /*---------------------------------------------------------------- * * Function: OS_SymbolTableDump diff --git a/src/os/shared/src/osapi-mutex.c b/src/os/shared/src/osapi-mutex.c index 5e1a282ff..73c9adab1 100644 --- a/src/os/shared/src/osapi-mutex.c +++ b/src/os/shared/src/osapi-mutex.c @@ -88,9 +88,9 @@ int32 OS_MutexAPI_Init(void) *-----------------------------------------------------------------*/ int32 OS_MutSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 options) { - OS_common_record_t *record; - int32 return_code; - osal_index_t local_id; + int32 return_code; + OS_object_token_t token; + OS_mutex_internal_record_t *mutex; /* Check for NULL pointers */ if (sem_id == NULL || sem_name == NULL) @@ -104,18 +104,19 @@ int32 OS_MutSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 options) } /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, sem_name, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, sem_name, &token); if (return_code == OS_SUCCESS) { - /* Save all the data to our own internal table */ - strcpy(OS_mutex_table[local_id].obj_name, sem_name); - record->name_entry = OS_mutex_table[local_id].obj_name; + mutex = OS_OBJECT_TABLE_GET(OS_mutex_table, token); + + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, mutex, obj_name, sem_name); /* Now call the OS-specific implementation. This reads info from the table. */ - return_code = OS_MutSemCreate_Impl(local_id, options); + return_code = OS_MutSemCreate_Impl(OS_ObjectIndexFromToken(&token), options); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, sem_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, sem_id); } return return_code; @@ -132,17 +133,16 @@ int32 OS_MutSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 options) *-----------------------------------------------------------------*/ int32 OS_MutSemDelete(osal_id_t sem_id) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_MutSemDelete_Impl(local_id); + return_code = OS_MutSemDelete_Impl(OS_ObjectIndexFromToken(&token)); /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, record); + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } return return_code; @@ -159,28 +159,28 @@ int32 OS_MutSemDelete(osal_id_t sem_id) *-----------------------------------------------------------------*/ int32 OS_MutSemGive(osal_id_t sem_id) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; - osal_id_t self_task; + OS_mutex_internal_record_t *mutex; + OS_object_token_t token; + int32 return_code; + osal_id_t self_task; /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { + mutex = OS_OBJECT_TABLE_GET(OS_mutex_table, token); + self_task = OS_TaskGetId(); - if (!OS_ObjectIdEqual(OS_mutex_table[local_id].last_owner, self_task)) + if (!OS_ObjectIdEqual(mutex->last_owner, self_task)) { - OS_DEBUG("WARNING: Task %lu giving mutex %lu while owned by task %lu\n", - OS_ObjectIdToInteger(self_task), - OS_ObjectIdToInteger(sem_id), - OS_ObjectIdToInteger(OS_mutex_table[local_id].last_owner)); + OS_DEBUG("WARNING: Task %lu giving mutex %lu while owned by task %lu\n", OS_ObjectIdToInteger(self_task), + OS_ObjectIdToInteger(sem_id), OS_ObjectIdToInteger(mutex->last_owner)); } - OS_mutex_table[local_id].last_owner = OS_OBJECT_ID_UNDEFINED; + mutex->last_owner = OS_OBJECT_ID_UNDEFINED; - return_code = OS_MutSemGive_Impl(local_id); + return_code = OS_MutSemGive_Impl(OS_ObjectIndexFromToken(&token)); } return return_code; @@ -197,29 +197,30 @@ int32 OS_MutSemGive(osal_id_t sem_id) *-----------------------------------------------------------------*/ int32 OS_MutSemTake(osal_id_t sem_id) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; - osal_id_t self_task; + OS_mutex_internal_record_t *mutex; + OS_object_token_t token; + int32 return_code; + osal_id_t self_task; /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_MutSemTake_Impl(local_id); + mutex = OS_OBJECT_TABLE_GET(OS_mutex_table, token); + + return_code = OS_MutSemTake_Impl(OS_ObjectIndexFromToken(&token)); if (return_code == OS_SUCCESS) { self_task = OS_TaskGetId(); - if (OS_ObjectIdDefined(OS_mutex_table[local_id].last_owner)) + if (OS_ObjectIdDefined(mutex->last_owner)) { OS_DEBUG("WARNING: Task %lu taking mutex %lu while owned by task %lu\n", - OS_ObjectIdToInteger(self_task), - OS_ObjectIdToInteger(sem_id), - OS_ObjectIdToInteger(OS_mutex_table[local_id].last_owner)); + OS_ObjectIdToInteger(self_task), OS_ObjectIdToInteger(sem_id), + OS_ObjectIdToInteger(mutex->last_owner)); } - OS_mutex_table[local_id].last_owner = self_task; + mutex->last_owner = self_task; } } @@ -262,7 +263,7 @@ int32 OS_MutSemGetInfo(osal_id_t sem_id, OS_mut_sem_prop_t *mut_prop) { OS_common_record_t *record; int32 return_code; - osal_index_t local_id; + OS_object_token_t token; /* Check parameters */ if (mut_prop == NULL) @@ -272,15 +273,17 @@ int32 OS_MutSemGetInfo(osal_id_t sem_id, OS_mut_sem_prop_t *mut_prop) memset(mut_prop, 0, sizeof(OS_mut_sem_prop_t)); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sem_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { + record = OS_OBJECT_TABLE_GET(OS_global_mutex_table, token); + strncpy(mut_prop->name, record->name_entry, OS_MAX_API_NAME - 1); mut_prop->creator = record->creator; - return_code = OS_MutSemGetInfo_Impl(local_id, mut_prop); + return_code = OS_MutSemGetInfo_Impl(OS_ObjectIndexFromToken(&token), mut_prop); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } return return_code; diff --git a/src/os/shared/src/osapi-printf.c b/src/os/shared/src/osapi-printf.c index 0a5359656..edcc033b5 100644 --- a/src/os/shared/src/osapi-printf.c +++ b/src/os/shared/src/osapi-printf.c @@ -78,22 +78,20 @@ int32 OS_ConsoleAPI_Init(void) { OS_console_internal_record_t *console; int32 return_code; - osal_index_t local_id; - OS_common_record_t * record; + OS_object_token_t token; memset(&OS_console_table, 0, sizeof(OS_console_table)); /* * Configure a console device to be used for OS_printf() calls. */ - return_code = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_CONSOLE, OS_PRINTF_CONSOLE_NAME, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_CONSOLE, OS_PRINTF_CONSOLE_NAME, &token); if (return_code == OS_SUCCESS) { - console = &OS_console_table[local_id]; + console = OS_OBJECT_TABLE_GET(OS_console_table, token); - record->name_entry = console->device_name; - strncpy(console->device_name, OS_PRINTF_CONSOLE_NAME, sizeof(console->device_name) - 1); - console->device_name[sizeof(console->device_name) - 1] = 0; + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, console, device_name, OS_PRINTF_CONSOLE_NAME); /* * Initialize the ring buffer pointers @@ -101,10 +99,10 @@ int32 OS_ConsoleAPI_Init(void) console->BufBase = OS_printf_buffer_mem; console->BufSize = sizeof(OS_printf_buffer_mem); - return_code = OS_ConsoleCreate_Impl(local_id); + return_code = OS_ConsoleCreate_Impl(OS_ObjectIndexFromToken(&token)); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, &OS_SharedGlobalVars.PrintfConsoleId); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, &OS_SharedGlobalVars.PrintfConsoleId); /* * Printf can be enabled by default now that the buffer is configured. @@ -192,15 +190,14 @@ static int32 OS_Console_CopyOut(OS_console_internal_record_t *console, const cha int32 OS_ConsoleWrite(osal_id_t console_id, const char *Str) { int32 return_code; - OS_common_record_t * record; - osal_index_t local_id; + OS_object_token_t token; OS_console_internal_record_t *console; size_t PendingWritePos; - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_CONSOLE, console_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_CONSOLE, console_id, &token); if (return_code == OS_SUCCESS) { - console = &OS_console_table[local_id]; + console = OS_OBJECT_TABLE_GET(OS_console_table, token); /* * The entire string should be put to the ring buffer, @@ -236,9 +233,9 @@ int32 OS_ConsoleWrite(osal_id_t console_id, const char *Str) * This is done while still locked, so it can support * either a synchronous or asynchronous implementation. */ - OS_ConsoleWakeup_Impl(local_id); + OS_ConsoleWakeup_Impl(OS_ObjectIndexFromToken(&token)); - OS_Unlock_Global(OS_OBJECT_TYPE_OS_CONSOLE); + OS_ObjectIdRelease(&token); } return return_code; diff --git a/src/os/shared/src/osapi-queue.c b/src/os/shared/src/osapi-queue.c index 51833c843..0105db711 100644 --- a/src/os/shared/src/osapi-queue.c +++ b/src/os/shared/src/osapi-queue.c @@ -90,9 +90,9 @@ int32 OS_QueueAPI_Init(void) int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, osal_blockcount_t queue_depth, size_t data_size, uint32 flags) { - OS_common_record_t *record; - int32 return_code; - osal_index_t local_id; + int32 return_code; + OS_object_token_t token; + OS_queue_internal_record_t *queue; if (queue_name == NULL || queue_id == NULL) { @@ -110,20 +110,22 @@ int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, osal_blockcoun } /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, queue_name, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, queue_name, &token); if (return_code == OS_SUCCESS) { - /* Save all the data to our own internal queue table */ - strcpy(OS_queue_table[local_id].queue_name, queue_name); - record->name_entry = OS_queue_table[local_id].queue_name; - OS_queue_table[local_id].max_depth = queue_depth; - OS_queue_table[local_id].max_size = data_size; + queue = OS_OBJECT_TABLE_GET(OS_queue_table, token); + + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, queue, queue_name, queue_name); + + queue->max_depth = queue_depth; + queue->max_size = data_size; /* Now call the OS-specific implementation. This reads info from the queue table. */ - return_code = OS_QueueCreate_Impl(local_id, flags); + return_code = OS_QueueCreate_Impl(OS_ObjectIndexFromToken(&token), flags); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, queue_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, queue_id); } return return_code; @@ -140,17 +142,16 @@ int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, osal_blockcoun *-----------------------------------------------------------------*/ int32 OS_QueueDelete(osal_id_t queue_id) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, queue_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, queue_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_QueueDelete_Impl(local_id); + return_code = OS_QueueDelete_Impl(OS_ObjectIndexFromToken(&token)); /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, record); + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } return return_code; @@ -167,9 +168,9 @@ int32 OS_QueueDelete(osal_id_t queue_id) *-----------------------------------------------------------------*/ int32 OS_QueueGet(osal_id_t queue_id, void *data, size_t size, size_t *size_copied, int32 timeout) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; + OS_queue_internal_record_t *queue; /* Check Parameters */ if (data == NULL || size_copied == NULL) @@ -178,10 +179,12 @@ int32 OS_QueueGet(osal_id_t queue_id, void *data, size_t size, size_t *size_copi } else { - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, queue_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, queue_id, &token); if (return_code == OS_SUCCESS) { - if (size < OS_queue_table[local_id].max_size) + queue = OS_OBJECT_TABLE_GET(OS_queue_table, token); + + if (size < queue->max_size) { /* ** The buffer that the user is passing in is potentially too small @@ -191,7 +194,7 @@ int32 OS_QueueGet(osal_id_t queue_id, void *data, size_t size, size_t *size_copi } else { - return_code = OS_QueueGet_Impl(local_id, data, size, size_copied, timeout); + return_code = OS_QueueGet_Impl(OS_ObjectIndexFromToken(&token), data, size, size_copied, timeout); } } } @@ -209,9 +212,9 @@ int32 OS_QueueGet(osal_id_t queue_id, void *data, size_t size, size_t *size_copi *-----------------------------------------------------------------*/ int32 OS_QueuePut(osal_id_t queue_id, const void *data, size_t size, uint32 flags) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; + OS_queue_internal_record_t *queue; /* Check Parameters */ if (data == NULL) @@ -220,10 +223,22 @@ int32 OS_QueuePut(osal_id_t queue_id, const void *data, size_t size, uint32 flag } else { - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, queue_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, queue_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_QueuePut_Impl(local_id, data, size, flags); + queue = OS_OBJECT_TABLE_GET(OS_queue_table, token); + + if (size > queue->max_size) + { + /* + ** The buffer that the user is passing in is too large + */ + return_code = OS_QUEUE_INVALID_SIZE; + } + else + { + return_code = OS_QueuePut_Impl(OS_ObjectIndexFromToken(&token), data, size, flags); + } } } @@ -265,7 +280,7 @@ int32 OS_QueueGetInfo(osal_id_t queue_id, OS_queue_prop_t *queue_prop) { OS_common_record_t *record; int32 return_code; - osal_index_t local_id; + OS_object_token_t token; /* Check parameters */ if (queue_prop == NULL) @@ -275,9 +290,11 @@ int32 OS_QueueGetInfo(osal_id_t queue_id, OS_queue_prop_t *queue_prop) memset(queue_prop, 0, sizeof(OS_queue_prop_t)); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, queue_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, queue_id, &token); if (return_code == OS_SUCCESS) { + record = OS_OBJECT_TABLE_GET(OS_global_queue_table, token); + strncpy(queue_prop->name, record->name_entry, OS_MAX_API_NAME - 1); queue_prop->creator = record->creator; @@ -286,7 +303,7 @@ int32 OS_QueueGetInfo(osal_id_t queue_id, OS_queue_prop_t *queue_prop) * But this could be added in the future (i.e. current/max depth, msg size, etc) */ - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } return return_code; diff --git a/src/os/shared/src/osapi-select.c b/src/os/shared/src/osapi-select.c index f48c27a34..cb759afb5 100644 --- a/src/os/shared/src/osapi-select.c +++ b/src/os/shared/src/osapi-select.c @@ -60,18 +60,18 @@ *-----------------------------------------------------------------*/ int32 OS_SelectSingle(osal_id_t objid, uint32 *StateFlags, int32 msecs) { - int32 return_code; - osal_index_t local_id; - OS_common_record_t *record; + int32 return_code; + OS_object_token_t token; if (StateFlags == NULL) return OS_INVALID_POINTER; - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_STREAM, objid, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_STREAM, objid, &token); if (return_code == OS_SUCCESS) { - return_code = OS_SelectSingle_Impl(local_id, StateFlags, msecs); - OS_ObjectIdRefcountDecr(record); + return_code = OS_SelectSingle_Impl(OS_ObjectIndexFromToken(&token), StateFlags, msecs); + + OS_ObjectIdRelease(&token); } return return_code; diff --git a/src/os/shared/src/osapi-shell.c b/src/os/shared/src/osapi-shell.c index 50e195068..e35e103f2 100644 --- a/src/os/shared/src/osapi-shell.c +++ b/src/os/shared/src/osapi-shell.c @@ -52,9 +52,8 @@ *-----------------------------------------------------------------*/ int32 OS_ShellOutputToFile(const char *Cmd, osal_id_t filedes) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ if (Cmd == NULL) @@ -62,11 +61,11 @@ int32 OS_ShellOutputToFile(const char *Cmd, osal_id_t filedes) return OS_INVALID_POINTER; } - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_STREAM, filedes, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_STREAM, filedes, &token); if (return_code == OS_SUCCESS) { - return_code = OS_ShellOutputToFile_Impl(local_id, Cmd); - OS_ObjectIdRefcountDecr(record); + return_code = OS_ShellOutputToFile_Impl(OS_ObjectIndexFromToken(&token), Cmd); + OS_ObjectIdRelease(&token); } return return_code; diff --git a/src/os/shared/src/osapi-sockets.c b/src/os/shared/src/osapi-sockets.c index cca5aee01..de9e9022b 100644 --- a/src/os/shared/src/osapi-sockets.c +++ b/src/os/shared/src/osapi-sockets.c @@ -120,9 +120,9 @@ void OS_CreateSocketName(osal_index_t local_id, const OS_SockAddr_t *Addr, const *-----------------------------------------------------------------*/ int32 OS_SocketOpen(osal_id_t *sock_id, OS_SocketDomain_t Domain, OS_SocketType_t Type) { - OS_common_record_t *record; - int32 return_code; - osal_index_t local_id; + OS_object_token_t token; + OS_stream_internal_record_t *stream; + int32 return_code; /* Check for NULL pointers */ if (sock_id == NULL) @@ -131,19 +131,21 @@ int32 OS_SocketOpen(osal_id_t *sock_id, OS_SocketDomain_t Domain, OS_SocketType_ } /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, NULL, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, NULL, &token); if (return_code == OS_SUCCESS) { + stream = OS_OBJECT_TABLE_GET(OS_stream_table, token); + /* Save all the data to our own internal table */ - memset(&OS_stream_table[local_id], 0, sizeof(OS_stream_internal_record_t)); - OS_stream_table[local_id].socket_domain = Domain; - OS_stream_table[local_id].socket_type = Type; + memset(stream, 0, sizeof(OS_stream_internal_record_t)); + stream->socket_domain = Domain; + stream->socket_type = Type; /* Now call the OS-specific implementation. This reads info from the table. */ - return_code = OS_SocketOpen_Impl(local_id); + return_code = OS_SocketOpen_Impl(OS_ObjectIndexFromToken(&token)); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, sock_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, sock_id); } return return_code; @@ -159,9 +161,10 @@ int32 OS_SocketOpen(osal_id_t *sock_id, OS_SocketDomain_t Domain, OS_SocketType_ *-----------------------------------------------------------------*/ int32 OS_SocketBind(osal_id_t sock_id, const OS_SockAddr_t *Addr) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_common_record_t * record; + OS_stream_internal_record_t *stream; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ if (Addr == NULL) @@ -169,33 +172,35 @@ int32 OS_SocketBind(osal_id_t sock_id, const OS_SockAddr_t *Addr) return OS_INVALID_POINTER; } - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sock_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sock_id, &token); if (return_code == OS_SUCCESS) { - if (OS_stream_table[local_id].socket_domain == OS_SocketDomain_INVALID) + record = OS_OBJECT_TABLE_GET(OS_global_stream_table, token); + stream = OS_OBJECT_TABLE_GET(OS_stream_table, token); + + if (stream->socket_domain == OS_SocketDomain_INVALID) { /* Not a socket */ return_code = OS_ERR_INCORRECT_OBJ_TYPE; } - else if (record->refcount != 0 || - (OS_stream_table[local_id].stream_state & (OS_STREAM_STATE_BOUND | OS_STREAM_STATE_CONNECTED)) != 0) + else if (record->refcount != 0 || (stream->stream_state & (OS_STREAM_STATE_BOUND | OS_STREAM_STATE_CONNECTED)) != 0) { /* Socket must be neither bound nor connected */ return_code = OS_ERR_INCORRECT_OBJ_STATE; } else { - return_code = OS_SocketBind_Impl(local_id, Addr); + return_code = OS_SocketBind_Impl(OS_ObjectIndexFromToken(&token), Addr); if (return_code == OS_SUCCESS) { - OS_CreateSocketName(local_id, Addr, NULL); - record->name_entry = OS_stream_table[local_id].stream_name; - OS_stream_table[local_id].stream_state |= OS_STREAM_STATE_BOUND; + OS_CreateSocketName(OS_ObjectIndexFromToken(&token), Addr, NULL); + record->name_entry = stream->stream_name; + stream->stream_state |= OS_STREAM_STATE_BOUND; } } - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } return return_code; @@ -212,11 +217,13 @@ int32 OS_SocketBind(osal_id_t sock_id, const OS_SockAddr_t *Addr) *-----------------------------------------------------------------*/ int32 OS_SocketAccept(osal_id_t sock_id, osal_id_t *connsock_id, OS_SockAddr_t *Addr, int32 timeout) { - OS_common_record_t *record; - OS_common_record_t *connrecord; - osal_index_t local_id; - osal_index_t conn_id; - int32 return_code; + OS_common_record_t * sock_record; + OS_common_record_t * conn_record; + OS_stream_internal_record_t *sock; + OS_stream_internal_record_t *conn; + OS_object_token_t sock_token; + OS_object_token_t conn_token; + int32 return_code; /* Check Parameters */ if (Addr == NULL || connsock_id == NULL) @@ -231,19 +238,25 @@ int32 OS_SocketAccept(osal_id_t sock_id, osal_id_t *connsock_id, OS_SockAddr_t * * return_code is checked, and return_code is only * set to OS_SUCCESS when connrecord is also initialized) */ - connrecord = NULL; - conn_id = OSAL_INDEX_C(0); - - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, sock_id, &local_id, &record); + conn_record = NULL; + sock_record = NULL; + sock = NULL; + conn = NULL; + memset(&sock_token, 0, sizeof(sock_token)); + memset(&conn_token, 0, sizeof(conn_token)); + + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, sock_id, &sock_token); if (return_code == OS_SUCCESS) { - if (OS_stream_table[local_id].socket_type != OS_SocketType_STREAM) + sock_record = OS_OBJECT_TABLE_GET(OS_global_stream_table, sock_token); + sock = OS_OBJECT_TABLE_GET(OS_stream_table, sock_token); + + if (sock->socket_type != OS_SocketType_STREAM) { /* Socket must be of the STREAM variety */ return_code = OS_ERR_INCORRECT_OBJ_TYPE; } - else if ((OS_stream_table[local_id].stream_state & (OS_STREAM_STATE_BOUND | OS_STREAM_STATE_CONNECTED)) != - OS_STREAM_STATE_BOUND) + else if ((sock->stream_state & (OS_STREAM_STATE_BOUND | OS_STREAM_STATE_CONNECTED)) != OS_STREAM_STATE_BOUND) { /* Socket must be bound but not connected */ return_code = OS_ERR_INCORRECT_OBJ_STATE; @@ -251,52 +264,60 @@ int32 OS_SocketAccept(osal_id_t sock_id, osal_id_t *connsock_id, OS_SockAddr_t * else { /* Now create a unique ID for the connection */ - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, NULL, &conn_id, &connrecord); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, NULL, &conn_token); if (return_code == OS_SUCCESS) { + conn_record = OS_OBJECT_TABLE_GET(OS_global_stream_table, conn_token); + conn = OS_OBJECT_TABLE_GET(OS_stream_table, sock_token); + /* Incr the refcount to record the fact that an operation is pending on this */ - memset(&OS_stream_table[conn_id], 0, sizeof(OS_stream_internal_record_t)); - OS_stream_table[conn_id].socket_domain = OS_stream_table[local_id].socket_domain; - OS_stream_table[conn_id].socket_type = OS_stream_table[local_id].socket_type; - ++connrecord->refcount; - return_code = OS_ObjectIdFinalizeNew(return_code, connrecord, connsock_id); - } - } + memset(conn, 0, sizeof(OS_stream_internal_record_t)); - /* If failure happened here, decrement the refcount of the listening socket now */ - if (return_code != OS_SUCCESS) - { - OS_ObjectIdRefcountDecr(record); + conn->socket_domain = sock->socket_domain; + conn->socket_type = sock->socket_type; + + /* bumps up the refcount by 1 before finalizing, + * to avoid having to re-acquire (should be cleaned up) */ + ++conn_record->refcount; + + return_code = OS_ObjectIdFinalizeNew(return_code, &conn_token, connsock_id); + } } } if (return_code == OS_SUCCESS) { - OS_SocketAddrInit_Impl(Addr, OS_stream_table[local_id].socket_domain); + OS_SocketAddrInit_Impl(Addr, sock->socket_domain); /* The actual accept impl is done without global table lock, only refcount lock */ - return_code = OS_SocketAccept_Impl(local_id, conn_id, Addr, timeout); + return_code = OS_SocketAccept_Impl(OS_ObjectIndexFromToken(&sock_token), OS_ObjectIndexFromToken(&conn_token), + Addr, timeout); + } + if (conn_record != NULL) + { OS_Lock_Global(LOCAL_OBJID_TYPE); + if (return_code == OS_SUCCESS) { /* Generate an entry name based on the remote address */ - OS_CreateSocketName(conn_id, Addr, record->name_entry); - connrecord->name_entry = OS_stream_table[conn_id].stream_name; - OS_stream_table[conn_id].stream_state |= OS_STREAM_STATE_CONNECTED; + OS_CreateSocketName(OS_ObjectIndexFromToken(&conn_token), Addr, sock_record->name_entry); + conn_record->name_entry = conn->stream_name; + conn->stream_state |= OS_STREAM_STATE_CONNECTED; } else { /* Clear the connrecord */ - connrecord->active_id = OS_OBJECT_ID_UNDEFINED; + conn_record->active_id = OS_OBJECT_ID_UNDEFINED; } /* Decrement both ref counters that were increased earlier */ - --record->refcount; - --connrecord->refcount; + --conn_record->refcount; OS_Unlock_Global(LOCAL_OBJID_TYPE); } + OS_ObjectIdRelease(&sock_token); + return return_code; } /* end OS_SocketAccept */ @@ -310,9 +331,10 @@ int32 OS_SocketAccept(osal_id_t sock_id, osal_id_t *connsock_id, OS_SockAddr_t * *-----------------------------------------------------------------*/ int32 OS_SocketConnect(osal_id_t sock_id, const OS_SockAddr_t *Addr, int32 Timeout) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_stream_internal_record_t *stream; + OS_common_record_t * record; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ if (Addr == NULL) @@ -320,15 +342,17 @@ int32 OS_SocketConnect(osal_id_t sock_id, const OS_SockAddr_t *Addr, int32 Timeo return OS_INVALID_POINTER; } - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sock_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sock_id, &token); if (return_code == OS_SUCCESS) { - if (OS_stream_table[local_id].socket_domain == OS_SocketDomain_INVALID) + record = OS_OBJECT_TABLE_GET(OS_global_stream_table, token); + stream = OS_OBJECT_TABLE_GET(OS_stream_table, token); + + if (stream->socket_domain == OS_SocketDomain_INVALID) { return_code = OS_ERR_INCORRECT_OBJ_TYPE; } - else if (OS_stream_table[local_id].socket_type == OS_SocketType_STREAM && - (OS_stream_table[local_id].stream_state & OS_STREAM_STATE_CONNECTED) != 0) + else if (stream->socket_type == OS_SocketType_STREAM && (stream->stream_state & OS_STREAM_STATE_CONNECTED) != 0) { /* Stream socket must not be connected */ return_code = OS_ERR_INCORRECT_OBJ_STATE; @@ -337,18 +361,18 @@ int32 OS_SocketConnect(osal_id_t sock_id, const OS_SockAddr_t *Addr, int32 Timeo { ++record->refcount; } - OS_Unlock_Global(LOCAL_OBJID_TYPE); + + OS_ObjectIdRelease(&token); } if (return_code == OS_SUCCESS) { - return_code = OS_SocketConnect_Impl(local_id, Addr, Timeout); + return_code = OS_SocketConnect_Impl(OS_ObjectIndexFromToken(&token), Addr, Timeout); OS_Lock_Global(LOCAL_OBJID_TYPE); if (return_code == OS_SUCCESS) { - OS_stream_table[local_id].stream_state |= - OS_STREAM_STATE_CONNECTED | OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; + stream->stream_state |= OS_STREAM_STATE_CONNECTED | OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; } --record->refcount; OS_Unlock_Global(LOCAL_OBJID_TYPE); @@ -367,9 +391,9 @@ int32 OS_SocketConnect(osal_id_t sock_id, const OS_SockAddr_t *Addr, int32 Timeo *-----------------------------------------------------------------*/ int32 OS_SocketRecvFrom(osal_id_t sock_id, void *buffer, size_t buflen, OS_SockAddr_t *RemoteAddr, int32 timeout) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_stream_internal_record_t *stream; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ if (buffer == NULL || buflen == 0) @@ -377,24 +401,26 @@ int32 OS_SocketRecvFrom(osal_id_t sock_id, void *buffer, size_t buflen, OS_SockA return OS_INVALID_POINTER; } - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, sock_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, sock_id, &token); if (return_code == OS_SUCCESS) { - if (OS_stream_table[local_id].socket_type != OS_SocketType_DATAGRAM) + stream = OS_OBJECT_TABLE_GET(OS_stream_table, token); + + if (stream->socket_type != OS_SocketType_DATAGRAM) { return_code = OS_ERR_INCORRECT_OBJ_TYPE; } - else if ((OS_stream_table[local_id].stream_state & OS_STREAM_STATE_BOUND) == 0) + else if ((stream->stream_state & OS_STREAM_STATE_BOUND) == 0) { /* Socket needs to be bound first */ return_code = OS_ERR_INCORRECT_OBJ_STATE; } else { - return_code = OS_SocketRecvFrom_Impl(local_id, buffer, buflen, RemoteAddr, timeout); + return_code = OS_SocketRecvFrom_Impl(OS_ObjectIndexFromToken(&token), buffer, buflen, RemoteAddr, timeout); } - OS_ObjectIdRefcountDecr(record); + OS_ObjectIdRelease(&token); } return return_code; @@ -410,9 +436,9 @@ int32 OS_SocketRecvFrom(osal_id_t sock_id, void *buffer, size_t buflen, OS_SockA *-----------------------------------------------------------------*/ int32 OS_SocketSendTo(osal_id_t sock_id, const void *buffer, size_t buflen, const OS_SockAddr_t *RemoteAddr) { - OS_common_record_t *record; - osal_index_t local_id; - int32 return_code; + OS_stream_internal_record_t *stream; + OS_object_token_t token; + int32 return_code; /* Check Parameters */ if (buffer == NULL || buflen == 0) @@ -420,19 +446,21 @@ int32 OS_SocketSendTo(osal_id_t sock_id, const void *buffer, size_t buflen, cons return OS_INVALID_POINTER; } - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, sock_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, sock_id, &token); if (return_code == OS_SUCCESS) { - if (OS_stream_table[local_id].socket_type != OS_SocketType_DATAGRAM) + stream = OS_OBJECT_TABLE_GET(OS_stream_table, token); + + if (stream->socket_type != OS_SocketType_DATAGRAM) { return_code = OS_ERR_INCORRECT_OBJ_TYPE; } else { - return_code = OS_SocketSendTo_Impl(local_id, buffer, buflen, RemoteAddr); + return_code = OS_SocketSendTo_Impl(OS_ObjectIndexFromToken(&token), buffer, buflen, RemoteAddr); } - OS_ObjectIdRefcountDecr(record); + OS_ObjectIdRelease(&token); } return return_code; @@ -471,7 +499,7 @@ int32 OS_SocketGetIdByName(osal_id_t *sock_id, const char *sock_name) int32 OS_SocketGetInfo(osal_id_t sock_id, OS_socket_prop_t *sock_prop) { OS_common_record_t *record; - osal_index_t local_id; + OS_object_token_t token; int32 return_code; /* Check parameters */ @@ -483,13 +511,16 @@ int32 OS_SocketGetInfo(osal_id_t sock_id, OS_socket_prop_t *sock_prop) memset(sock_prop, 0, sizeof(OS_socket_prop_t)); /* Check Parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sock_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, sock_id, &token); if (return_code == OS_SUCCESS) { + record = OS_OBJECT_TABLE_GET(OS_global_stream_table, token); + strncpy(sock_prop->name, record->name_entry, OS_MAX_API_NAME - 1); sock_prop->creator = record->creator; - return_code = OS_SocketGetInfo_Impl(local_id, sock_prop); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + return_code = OS_SocketGetInfo_Impl(OS_ObjectIndexFromToken(&token), sock_prop); + + OS_ObjectIdRelease(&token); } return return_code; diff --git a/src/os/shared/src/osapi-task.c b/src/os/shared/src/osapi-task.c index 0bb3b96d0..88777744b 100644 --- a/src/os/shared/src/osapi-task.c +++ b/src/os/shared/src/osapi-task.c @@ -81,34 +81,19 @@ OS_task_internal_record_t OS_task_table[LOCAL_NUM_OBJECTS]; *-----------------------------------------------------------------*/ static int32 OS_TaskPrepare(osal_id_t task_id, osal_task_entry *entrypt) { - int32 return_code; - osal_index_t local_id; + int32 return_code; + OS_object_token_t token; + OS_task_internal_record_t *task; - return_code = OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_TASK, task_id, &local_id); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_TASK, task_id, &token); if (return_code == OS_SUCCESS) { - /* - * Take our own task table lock. - * - * This ensures that the parent thread's OS_TaskCreate() call is fully completed, - * and that nobody can call OS_TaskDelete() and possibly overwrite this data. - */ - OS_Lock_Global(OS_OBJECT_TYPE_OS_TASK); + task = OS_OBJECT_TABLE_GET(OS_task_table, token); - /* - * Verify that we still appear to own the table entry - */ - if (!OS_ObjectIdEqual(OS_global_task_table[local_id].active_id, task_id)) - { - return_code = OS_ERR_INVALID_ID; - } - else - { - return_code = OS_TaskMatch_Impl(local_id); - *entrypt = OS_task_table[local_id].entry_function_pointer; - } + return_code = OS_TaskMatch_Impl(OS_ObjectIndexFromToken(&token)); + *entrypt = task->entry_function_pointer; - OS_Unlock_Global(OS_OBJECT_TYPE_OS_TASK); + OS_ObjectIdRelease(&token); } if (return_code == OS_SUCCESS) @@ -189,9 +174,9 @@ int32 OS_TaskAPI_Init(void) int32 OS_TaskCreate(osal_id_t *task_id, const char *task_name, osal_task_entry function_pointer, osal_stackptr_t stack_pointer, size_t stack_size, osal_priority_t priority, uint32 flags) { - OS_common_record_t *record; - int32 return_code; - osal_index_t local_id; + int32 return_code; + OS_object_token_t token; + OS_task_internal_record_t *task; /* Check for NULL pointers */ if (task_name == NULL || task_id == NULL || function_pointer == NULL) @@ -214,24 +199,24 @@ int32 OS_TaskCreate(osal_id_t *task_id, const char *task_name, osal_task_entry f } /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, task_name, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, task_name, &token); if (return_code == OS_SUCCESS) { - /* Save all the data to our own internal task table */ - memset(&OS_task_table[local_id], 0, sizeof(OS_task_internal_record_t)); + task = OS_OBJECT_TABLE_GET(OS_task_table, token); - strncpy(OS_task_table[local_id].task_name, task_name, OS_MAX_API_NAME); - record->name_entry = OS_task_table[local_id].task_name; - OS_task_table[local_id].stack_size = stack_size; - OS_task_table[local_id].priority = priority; - OS_task_table[local_id].entry_function_pointer = function_pointer; - OS_task_table[local_id].stack_pointer = stack_pointer; + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, task, task_name, task_name); + + task->stack_size = stack_size; + task->priority = priority; + task->entry_function_pointer = function_pointer; + task->stack_pointer = stack_pointer; /* Now call the OS-specific implementation. This reads info from the task table. */ - return_code = OS_TaskCreate_Impl(local_id, flags); + return_code = OS_TaskCreate_Impl(OS_ObjectIndexFromToken(&token), flags); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, task_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, task_id); } return return_code; @@ -247,22 +232,24 @@ int32 OS_TaskCreate(osal_id_t *task_id, const char *task_name, osal_task_entry f *-----------------------------------------------------------------*/ int32 OS_TaskDelete(osal_id_t task_id) { - OS_common_record_t *record; - int32 return_code; - osal_index_t local_id; - osal_task_entry delete_hook; + int32 return_code; + OS_object_token_t token; + OS_task_internal_record_t *task; + osal_task_entry delete_hook; delete_hook = NULL; - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, task_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, task_id, &token); if (return_code == OS_SUCCESS) { + task = OS_OBJECT_TABLE_GET(OS_task_table, token); + /* Save the delete hook, as we do not want to call it while locked */ - delete_hook = OS_task_table[local_id].delete_hook_pointer; + delete_hook = task->delete_hook_pointer; - return_code = OS_TaskDelete_Impl(local_id); + return_code = OS_TaskDelete_Impl(OS_ObjectIndexFromToken(&token)); /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, record); + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } /* @@ -286,15 +273,14 @@ int32 OS_TaskDelete(osal_id_t task_id) *-----------------------------------------------------------------*/ void OS_TaskExit() { - OS_common_record_t *record; - osal_id_t task_id; - osal_index_t local_id; + osal_id_t task_id; + OS_object_token_t token; task_id = OS_TaskGetId_Impl(); - if (OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, task_id, &local_id, &record) == OS_SUCCESS) + if (OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, task_id, &token) == OS_SUCCESS) { /* Complete the operation via the common routine */ - OS_ObjectIdFinalizeDelete(OS_SUCCESS, record); + OS_ObjectIdFinalizeDelete(OS_SUCCESS, &token); } /* call the implementation */ @@ -327,24 +313,25 @@ int32 OS_TaskDelay(uint32 millisecond) *-----------------------------------------------------------------*/ int32 OS_TaskSetPriority(osal_id_t task_id, osal_priority_t new_priority) { - OS_common_record_t *record; - int32 return_code; - osal_index_t local_id; + int32 return_code; + OS_object_token_t token; + OS_task_internal_record_t *task; - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, task_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, task_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_TaskSetPriority_Impl(local_id, new_priority); + task = OS_OBJECT_TABLE_GET(OS_task_table, token); + + return_code = OS_TaskSetPriority_Impl(OS_ObjectIndexFromToken(&token), new_priority); if (return_code == OS_SUCCESS) { /* Use the abstracted priority, not the OS one */ /* Change the priority in the table as well */ - OS_task_table[local_id].priority = new_priority; + task->priority = new_priority; } - /* Unlock the global from OS_ObjectIdGetAndLock() */ - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } return return_code; @@ -360,14 +347,13 @@ int32 OS_TaskSetPriority(osal_id_t task_id, osal_priority_t new_priority) *-----------------------------------------------------------------*/ int32 OS_TaskRegister(void) { - OS_common_record_t *record; - osal_index_t local_id; + OS_object_token_t token; /* * Just to retain compatibility (really, only the unit test cares) * this will return NON success when called from a non-task context */ - return OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, OS_TaskGetId_Impl(), &local_id, &record); + return OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, OS_TaskGetId_Impl(), &token); } /* end OS_TaskRegister */ /*---------------------------------------------------------------- @@ -380,15 +366,14 @@ int32 OS_TaskRegister(void) *-----------------------------------------------------------------*/ osal_id_t OS_TaskGetId(void) { - OS_common_record_t *record; - osal_index_t local_id; - osal_id_t task_id; + OS_object_token_t token; + osal_id_t task_id; task_id = OS_TaskGetId_Impl(); /* Confirm the task master table entry matches the expected. * If not it means we have some stale/leftover value */ - if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, task_id, &local_id, &record) != OS_SUCCESS) + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, task_id, &token) != OS_SUCCESS) { task_id = OS_OBJECT_ID_UNDEFINED; } @@ -429,9 +414,10 @@ int32 OS_TaskGetIdByName(osal_id_t *task_id, const char *task_name) *-----------------------------------------------------------------*/ int32 OS_TaskGetInfo(osal_id_t task_id, OS_task_prop_t *task_prop) { - OS_common_record_t *record; - int32 return_code; - osal_index_t local_id; + OS_common_record_t * record; + int32 return_code; + OS_object_token_t token; + OS_task_internal_record_t *task; /* Check parameters */ if (task_prop == NULL) @@ -441,21 +427,24 @@ int32 OS_TaskGetInfo(osal_id_t task_id, OS_task_prop_t *task_prop) memset(task_prop, 0, sizeof(OS_task_prop_t)); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, task_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, task_id, &token); if (return_code == OS_SUCCESS) { + record = OS_OBJECT_TABLE_GET(OS_global_task_table, token); + task = OS_OBJECT_TABLE_GET(OS_task_table, token); + if (record->name_entry != NULL) { strncpy(task_prop->name, record->name_entry, sizeof(task_prop->name) - 1); task_prop->name[sizeof(task_prop->name) - 1] = 0; } task_prop->creator = record->creator; - task_prop->stack_size = OS_task_table[local_id].stack_size; - task_prop->priority = OS_task_table[local_id].priority; + task_prop->stack_size = task->stack_size; + task_prop->priority = task->priority; - return_code = OS_TaskGetInfo_Impl(local_id, task_prop); + return_code = OS_TaskGetInfo_Impl(OS_ObjectIndexFromToken(&token), task_prop); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } return return_code; @@ -472,21 +461,23 @@ int32 OS_TaskGetInfo(osal_id_t task_id, OS_task_prop_t *task_prop) *-----------------------------------------------------------------*/ int32 OS_TaskInstallDeleteHandler(osal_task_entry function_pointer) { - OS_common_record_t *record; - int32 return_code; - osal_index_t local_id; - osal_id_t task_id; + int32 return_code; + OS_object_token_t token; + OS_task_internal_record_t *task; + osal_id_t task_id; task_id = OS_TaskGetId_Impl(); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, task_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, task_id, &token); if (return_code == OS_SUCCESS) { + task = OS_OBJECT_TABLE_GET(OS_task_table, token); + /* ** Install the pointer */ - OS_task_table[local_id].delete_hook_pointer = function_pointer; + task->delete_hook_pointer = function_pointer; - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } return return_code; @@ -502,8 +493,8 @@ int32 OS_TaskInstallDeleteHandler(osal_task_entry function_pointer) *-----------------------------------------------------------------*/ int32 OS_TaskFindIdBySystemData(osal_id_t *task_id, const void *sysdata, size_t sysdata_size) { - int32 return_code; - OS_common_record_t *record; + int32 return_code; + OS_object_token_t token; /* Check parameters */ if (task_id == NULL) @@ -519,11 +510,12 @@ int32 OS_TaskFindIdBySystemData(osal_id_t *task_id, const void *sysdata, size_t } return_code = OS_ObjectIdGetBySearch(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, OS_TaskIdMatchSystemData_Impl, - (void *)sysdata, &record); + (void *)sysdata, &token); if (return_code == OS_SUCCESS) { - *task_id = record->active_id; - OS_Unlock_Global(LOCAL_OBJID_TYPE); + *task_id = OS_ObjectIdFromToken(&token); + + OS_ObjectIdRelease(&token); } return return_code; diff --git a/src/os/shared/src/osapi-time.c b/src/os/shared/src/osapi-time.c index b73f4b1cb..ea52e2490 100644 --- a/src/os/shared/src/osapi-time.c +++ b/src/os/shared/src/osapi-time.c @@ -90,15 +90,14 @@ int32 OS_TimerCbAPI_Init(void) static int32 OS_DoTimerAdd(osal_id_t *timer_id, const char *timer_name, osal_id_t timebase_ref_id, OS_ArgCallback_t callback_ptr, void *callback_arg, uint32 flags) { - OS_common_record_t * timebase; - OS_common_record_t * record; - OS_timecb_internal_record_t *local; - int32 return_code; - osal_objtype_t objtype; - osal_index_t local_id; - osal_index_t timebase_local_id; - osal_id_t cb_list; - osal_index_t attach_id; + int32 return_code; + osal_objtype_t objtype; + OS_object_token_t timebase_token; + OS_object_token_t timecb_token; + OS_timecb_internal_record_t * local; + OS_timebase_internal_record_t *timebase; + osal_id_t cb_list; + osal_index_t attach_id; /* ** Check Parameters @@ -141,56 +140,61 @@ static int32 OS_DoTimerAdd(osal_id_t *timer_id, const char *timer_name, osal_id_ * if we leave this routine with an error. */ return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_TIMEBASE, timebase_ref_id, - &timebase_local_id, &timebase); + &timebase_token); if (return_code != OS_SUCCESS) { return return_code; } /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TIMECB, timer_name, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TIMECB, timer_name, &timecb_token); if (return_code == OS_SUCCESS) { - /* Save all the data to our own internal timer table */ - local = &OS_timecb_table[local_id]; + local = OS_OBJECT_TABLE_GET(OS_timecb_table, timecb_token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, timebase_token); - memset(local, 0, sizeof(OS_timecb_internal_record_t)); + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(timecb_token, local, timer_name, timer_name); + + /* + * transfer ownership so the refcount obtained earlier is now + * associated with the timecb object, and will be retained until + * the object is deleted. + */ + OS_ObjectIdTransferToken(&timebase_token, &local->timebase_token); - strncpy(local->timer_name, timer_name, OS_MAX_API_NAME - 1); - record->name_entry = local->timer_name; local->callback_ptr = callback_ptr; local->callback_arg = callback_arg; - local->timebase_ref = timebase_local_id; local->flags = flags; - local->prev_ref = local_id; - local->next_ref = local_id; + local->prev_ref = OS_ObjectIndexFromToken(&timecb_token); + local->next_ref = OS_ObjectIndexFromToken(&timecb_token); /* * Now we need to add it to the time base callback ring, so take the * timebase-specific lock to prevent a tick from being processed at this moment. */ - OS_TimeBaseLock_Impl(timebase_local_id); + OS_TimeBaseLock_Impl(OS_ObjectIndexFromToken(&timebase_token)); - cb_list = OS_timebase_table[timebase_local_id].first_cb; - OS_timebase_table[timebase_local_id].first_cb = record->active_id; + cb_list = timebase->first_cb; + timebase->first_cb = OS_ObjectIdFromToken(&timecb_token); if (OS_ObjectIdDefined(cb_list)) { OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_TIMECB, cb_list, &attach_id); local->next_ref = attach_id; local->prev_ref = OS_timecb_table[attach_id].prev_ref; - OS_timecb_table[local->prev_ref].next_ref = local_id; - OS_timecb_table[local->next_ref].prev_ref = local_id; + OS_timecb_table[local->prev_ref].next_ref = OS_ObjectIndexFromToken(&timecb_token); + OS_timecb_table[local->next_ref].prev_ref = OS_ObjectIndexFromToken(&timecb_token); } - OS_TimeBaseUnlock_Impl(timebase_local_id); + OS_TimeBaseUnlock_Impl(OS_ObjectIndexFromToken(&timebase_token)); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, timer_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &timecb_token, timer_id); } else { - OS_ObjectIdRefcountDecr(timebase); + OS_ObjectIdRelease(&timebase_token); } return return_code; @@ -282,6 +286,7 @@ int32 OS_TimerCreate(osal_id_t *timer_id, const char *timer_name, uint32 *accura */ Conv.opaque_arg = NULL; Conv.timer_callback_func = callback_ptr; + return_code = OS_DoTimerAdd(timer_id, timer_name, timebase_ref_id, OS_Timer_NoArgCallback, Conv.opaque_arg, TIMECB_FLAG_DEDICATED_TIMEBASE); @@ -311,12 +316,11 @@ int32 OS_TimerCreate(osal_id_t *timer_id, const char *timer_name, uint32 *accura *-----------------------------------------------------------------*/ int32 OS_TimerSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time) { - OS_common_record_t * record; OS_timecb_internal_record_t *local; int32 return_code; osal_objtype_t objtype; - osal_index_t local_id; osal_id_t dedicated_timebase_id; + OS_object_token_t token; dedicated_timebase_id = OS_OBJECT_ID_UNDEFINED; @@ -340,25 +344,24 @@ int32 OS_TimerSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time) return OS_ERR_INCORRECT_OBJ_STATE; } - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_TIMECB, timer_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_TIMECB, timer_id, &token); if (return_code == OS_SUCCESS) { - local = &OS_timecb_table[local_id]; + local = OS_OBJECT_TABLE_GET(OS_timecb_table, token); - OS_TimeBaseLock_Impl(local->timebase_ref); + OS_TimeBaseLock_Impl(OS_ObjectIndexFromToken(&local->timebase_token)); if ((local->flags & TIMECB_FLAG_DEDICATED_TIMEBASE) != 0) { - dedicated_timebase_id = OS_global_timebase_table[local->timebase_ref].active_id; + dedicated_timebase_id = OS_ObjectIdFromToken(&local->timebase_token); } local->wait_time = (int32)start_time; local->interval_time = (int32)interval_time; - OS_TimeBaseUnlock_Impl(local->timebase_ref); + OS_TimeBaseUnlock_Impl(OS_ObjectIndexFromToken(&local->timebase_token)); - /* Unlock the global from OS_ObjectIdCheck() */ - OS_Unlock_Global(OS_OBJECT_TYPE_OS_TIMECB); + OS_ObjectIdRelease(&token); } /* @@ -391,15 +394,16 @@ int32 OS_TimerSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time) *-----------------------------------------------------------------*/ int32 OS_TimerDelete(osal_id_t timer_id) { - OS_timecb_internal_record_t *local; - OS_common_record_t * record; - OS_common_record_t * timebase = NULL; - int32 return_code; - osal_objtype_t objtype; - osal_index_t local_id; - osal_id_t dedicated_timebase_id; + OS_timecb_internal_record_t * local; + int32 return_code; + osal_objtype_t objtype; + osal_id_t dedicated_timebase_id; + OS_object_token_t token; + OS_timebase_internal_record_t *timebase_local; + OS_object_token_t timebase_token; dedicated_timebase_id = OS_OBJECT_ID_UNDEFINED; + memset(&timebase_token, 0, sizeof(timebase_token)); /* * Check our context. Not allowed to use the timer API from a timer callback. @@ -411,66 +415,64 @@ int32 OS_TimerDelete(osal_id_t timer_id) return OS_ERR_INCORRECT_OBJ_STATE; } - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_TIMECB, timer_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_TIMECB, timer_id, &token); if (return_code == OS_SUCCESS) { - local = &OS_timecb_table[local_id]; - timebase = &OS_global_timebase_table[local->timebase_ref]; + local = OS_OBJECT_TABLE_GET(OS_timecb_table, token); + timebase_local = OS_OBJECT_TABLE_GET(OS_timebase_table, local->timebase_token); - OS_TimeBaseLock_Impl(local->timebase_ref); + OS_ObjectIdTransferToken(&local->timebase_token, &timebase_token); + + OS_TimeBaseLock_Impl(OS_ObjectIndexFromToken(&local->timebase_token)); /* * If the timer uses a dedicated time base, then also delete that. */ if ((local->flags & TIMECB_FLAG_DEDICATED_TIMEBASE) != 0) { - dedicated_timebase_id = timebase->active_id; + dedicated_timebase_id = OS_ObjectIdFromToken(&local->timebase_token); } /* * Now we need to remove it from the time base callback ring */ - if (OS_ObjectIdEqual(OS_timebase_table[local->timebase_ref].first_cb, timer_id)) + if (OS_ObjectIdEqual(timebase_local->first_cb, timer_id)) { - if (local->next_ref != local_id) + if (local->next_ref != OS_ObjectIndexFromToken(&token)) { - OS_ObjectIdCompose_Impl(OS_OBJECT_TYPE_OS_TIMEBASE, local->next_ref, - &OS_timebase_table[local->timebase_ref].first_cb); + OS_ObjectIdCompose_Impl(OS_OBJECT_TYPE_OS_TIMEBASE, local->next_ref, &timebase_local->first_cb); } else { /* * consider the list empty */ - OS_timebase_table[local->timebase_ref].first_cb = OS_OBJECT_ID_UNDEFINED; + timebase_local->first_cb = OS_OBJECT_ID_UNDEFINED; } } OS_timecb_table[local->prev_ref].next_ref = local->next_ref; OS_timecb_table[local->next_ref].prev_ref = local->prev_ref; - local->next_ref = local_id; - local->prev_ref = local_id; + local->next_ref = OS_ObjectIndexFromToken(&token); + local->prev_ref = OS_ObjectIndexFromToken(&token); - OS_TimeBaseUnlock_Impl(local->timebase_ref); + OS_TimeBaseUnlock_Impl(OS_ObjectIndexFromToken(&local->timebase_token)); /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, record); + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } /* * Remove the reference count against the timebase */ + OS_ObjectIdRelease(&timebase_token); /* * If the timer uses a dedicated time base, then also delete it. */ - if (return_code == OS_SUCCESS) + if (return_code == OS_SUCCESS && OS_ObjectIdDefined(dedicated_timebase_id)) { - OS_ObjectIdRefcountDecr(timebase); - if (OS_ObjectIdDefined(dedicated_timebase_id)) - { - OS_TimeBaseDelete(dedicated_timebase_id); - } + OS_TimeBaseDelete(dedicated_timebase_id); } return return_code; @@ -519,10 +521,12 @@ int32 OS_TimerGetIdByName(osal_id_t *timer_id, const char *timer_name) *-----------------------------------------------------------------*/ int32 OS_TimerGetInfo(osal_id_t timer_id, OS_timer_prop_t *timer_prop) { - OS_common_record_t *record; - int32 return_code; - osal_index_t local_id; - osal_objtype_t objtype; + OS_common_record_t * record; + int32 return_code; + osal_objtype_t objtype; + OS_object_token_t token; + OS_timecb_internal_record_t * timecb; + OS_timebase_internal_record_t *timebase; /* Check parameters */ if (timer_prop == NULL) @@ -542,15 +546,19 @@ int32 OS_TimerGetInfo(osal_id_t timer_id, OS_timer_prop_t *timer_prop) memset(timer_prop, 0, sizeof(OS_timer_prop_t)); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_TIMECB, timer_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_TIMECB, timer_id, &token); if (return_code == OS_SUCCESS) { + record = OS_OBJECT_TABLE_GET(OS_global_timecb_table, token); + timecb = OS_OBJECT_TABLE_GET(OS_timecb_table, token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, timecb->timebase_token); + strncpy(timer_prop->name, record->name_entry, OS_MAX_API_NAME - 1); timer_prop->creator = record->creator; - timer_prop->interval_time = (uint32)OS_timecb_table[local_id].interval_time; - timer_prop->accuracy = OS_timebase_table[OS_timecb_table[local_id].timebase_ref].accuracy_usec; + timer_prop->interval_time = (uint32)timecb->interval_time; + timer_prop->accuracy = timebase->accuracy_usec; - OS_Unlock_Global(OS_OBJECT_TYPE_OS_TIMECB); + OS_ObjectIdRelease(&token); } return return_code; diff --git a/src/os/shared/src/osapi-timebase.c b/src/os/shared/src/osapi-timebase.c index 17b2a67f1..491bf4d6f 100644 --- a/src/os/shared/src/osapi-timebase.c +++ b/src/os/shared/src/osapi-timebase.c @@ -98,10 +98,10 @@ int32 OS_TimeBaseAPI_Init(void) *-----------------------------------------------------------------*/ int32 OS_TimeBaseCreate(osal_id_t *timer_id, const char *timebase_name, OS_TimerSync_t external_sync) { - OS_common_record_t *record; - int32 return_code; - osal_objtype_t objtype; - osal_index_t local_id; + int32 return_code; + osal_objtype_t objtype; + OS_object_token_t token; + OS_timebase_internal_record_t *timebase; /* * Specifying a NULL sync function means the timebase is not externally synchronized. @@ -136,29 +136,29 @@ int32 OS_TimeBaseCreate(osal_id_t *timer_id, const char *timebase_name, OS_Timer } /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ - return_code = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TIMEBASE, timebase_name, &local_id, &record); + return_code = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TIMEBASE, timebase_name, &token); if (return_code == OS_SUCCESS) { - /* Save all the data to our own internal timer table */ - memset(&OS_timebase_table[local_id], 0, sizeof(OS_timebase_internal_record_t)); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, token); + + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, timebase, timebase_name, timebase_name); - strncpy(OS_timebase_table[local_id].timebase_name, timebase_name, OS_MAX_API_NAME - 1); - record->name_entry = OS_timebase_table[local_id].timebase_name; - OS_timebase_table[local_id].external_sync = external_sync; + timebase->external_sync = external_sync; if (external_sync == NULL) { - OS_timebase_table[local_id].accuracy_usec = OS_SharedGlobalVars.MicroSecPerTick; + timebase->accuracy_usec = OS_SharedGlobalVars.MicroSecPerTick; } else { - OS_timebase_table[local_id].accuracy_usec = 0; + timebase->accuracy_usec = 0; } /* Now call the OS-specific implementation. This reads info from the timer table. */ - return_code = OS_TimeBaseCreate_Impl(local_id); + return_code = OS_TimeBaseCreate_Impl(OS_ObjectIndexFromToken(&token)); /* Check result, finalize record, and unlock global table. */ - return_code = OS_ObjectIdFinalizeNew(return_code, record, timer_id); + return_code = OS_ObjectIdFinalizeNew(return_code, &token, timer_id); } return return_code; @@ -174,10 +174,10 @@ int32 OS_TimeBaseCreate(osal_id_t *timer_id, const char *timebase_name, OS_Timer *-----------------------------------------------------------------*/ int32 OS_TimeBaseSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time) { - OS_common_record_t *record; - int32 return_code; - osal_objtype_t objtype; - osal_index_t local_id; + int32 return_code; + osal_objtype_t objtype; + OS_object_token_t token; + OS_timebase_internal_record_t *timebase; /* * Internally the implementation represents the interval as a @@ -202,24 +202,26 @@ int32 OS_TimeBaseSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time return OS_ERR_INCORRECT_OBJ_STATE; } - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_TIMEBASE, timer_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_TIMEBASE, timer_id, &token); if (return_code == OS_SUCCESS) { + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, token); + /* Need to take the time base lock to ensure that no ticks are currently being processed */ - OS_TimeBaseLock_Impl(local_id); + OS_TimeBaseLock_Impl(OS_ObjectIndexFromToken(&token)); - return_code = OS_TimeBaseSet_Impl(local_id, start_time, interval_time); + return_code = OS_TimeBaseSet_Impl(OS_ObjectIndexFromToken(&token), start_time, interval_time); if (return_code == OS_SUCCESS) { /* Save the value since we were successful */ - OS_timebase_table[local_id].nominal_start_time = start_time; - OS_timebase_table[local_id].nominal_interval_time = interval_time; + timebase->nominal_start_time = start_time; + timebase->nominal_interval_time = interval_time; } - OS_TimeBaseUnlock_Impl(local_id); + OS_TimeBaseUnlock_Impl(OS_ObjectIndexFromToken(&token)); - OS_Unlock_Global(OS_OBJECT_TYPE_OS_TIMEBASE); + OS_ObjectIdRelease(&token); } return return_code; @@ -235,10 +237,9 @@ int32 OS_TimeBaseSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time *-----------------------------------------------------------------*/ int32 OS_TimeBaseDelete(osal_id_t timer_id) { - OS_common_record_t *record; - int32 return_code; - osal_objtype_t objtype; - osal_index_t local_id; + int32 return_code; + osal_objtype_t objtype; + OS_object_token_t token; /* * Check our context. Not allowed to use the timer API from a timer callback. @@ -250,13 +251,13 @@ int32 OS_TimeBaseDelete(osal_id_t timer_id) return OS_ERR_INCORRECT_OBJ_STATE; } - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_TIMEBASE, timer_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_TIMEBASE, timer_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_TimeBaseDelete_Impl(local_id); + return_code = OS_TimeBaseDelete_Impl(OS_ObjectIndexFromToken(&token)); /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, record); + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); } return return_code; @@ -305,10 +306,11 @@ int32 OS_TimeBaseGetIdByName(osal_id_t *timer_id, const char *timebase_name) *-----------------------------------------------------------------*/ int32 OS_TimeBaseGetInfo(osal_id_t timebase_id, OS_timebase_prop_t *timebase_prop) { - OS_common_record_t *record; - int32 return_code; - osal_objtype_t objtype; - osal_index_t local_id; + OS_common_record_t * record; + int32 return_code; + osal_objtype_t objtype; + OS_object_token_t token; + OS_timebase_internal_record_t *timebase; /* Check parameters */ if (timebase_prop == NULL) @@ -328,18 +330,21 @@ int32 OS_TimeBaseGetInfo(osal_id_t timebase_id, OS_timebase_prop_t *timebase_pro memset(timebase_prop, 0, sizeof(OS_timebase_prop_t)); - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, timebase_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, timebase_id, &token); if (return_code == OS_SUCCESS) { + record = OS_OBJECT_TABLE_GET(OS_global_timebase_table, token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, token); + strncpy(timebase_prop->name, record->name_entry, OS_MAX_API_NAME - 1); timebase_prop->creator = record->creator; - timebase_prop->nominal_interval_time = OS_timebase_table[local_id].nominal_interval_time; - timebase_prop->freerun_time = OS_timebase_table[local_id].freerun_time; - timebase_prop->accuracy = OS_timebase_table[local_id].accuracy_usec; + timebase_prop->nominal_interval_time = timebase->nominal_interval_time; + timebase_prop->freerun_time = timebase->freerun_time; + timebase_prop->accuracy = timebase->accuracy_usec; - return_code = OS_TimeBaseGetInfo_Impl(local_id, timebase_prop); + return_code = OS_TimeBaseGetInfo_Impl(OS_ObjectIndexFromToken(&token), timebase_prop); - OS_Unlock_Global(LOCAL_OBJID_TYPE); + OS_ObjectIdRelease(&token); } return return_code; @@ -355,15 +360,17 @@ int32 OS_TimeBaseGetInfo(osal_id_t timebase_id, OS_timebase_prop_t *timebase_pro *-----------------------------------------------------------------*/ int32 OS_TimeBaseGetFreeRun(osal_id_t timebase_id, uint32 *freerun_val) { - OS_common_record_t *record; - int32 return_code; - osal_index_t local_id; + int32 return_code; + OS_object_token_t token; + OS_timebase_internal_record_t *timebase; /* Check parameters */ - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, timebase_id, &local_id, &record); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, timebase_id, &token); if (return_code == OS_SUCCESS) { - *freerun_val = OS_timebase_table[local_id].freerun_time; + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, token); + + *freerun_val = timebase->freerun_time; } return return_code; @@ -394,7 +401,7 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) OS_timebase_internal_record_t *timebase; OS_timecb_internal_record_t * timecb; OS_common_record_t * record; - osal_index_t local_id; + OS_object_token_t token; osal_index_t timer_id; osal_index_t curr_cb_local_id; osal_id_t curr_cb_public_id; @@ -411,17 +418,19 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) OS_TaskRegister_Impl(timebase_id); /* Grab the relevant info from the global structure */ - if (OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_TIMEBASE, timebase_id, &local_id, &record) != 0) + if (OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_TIMEBASE, timebase_id, &token) != 0) { /* Something went wrong - abort this thread */ return; } - timebase = &OS_timebase_table[local_id]; + record = OS_OBJECT_TABLE_GET(OS_global_timebase_table, token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, token); + syncfunc = timebase->external_sync; spin_cycles = 0; - OS_Unlock_Global(OS_OBJECT_TYPE_OS_TIMEBASE); + OS_ObjectIdRelease(&token); while (1) { @@ -429,7 +438,7 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) * Call the sync function - this will pend for some period of time * and return the amount of elapsed time in units of "timebase ticks" */ - tick_time = (*syncfunc)(local_id); + tick_time = (*syncfunc)(OS_ObjectIndexFromToken(&token)); /* * The returned tick_time should be nonzero. If the sync function @@ -471,7 +480,7 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) } } - OS_TimeBaseLock_Impl(local_id); + OS_TimeBaseLock_Impl(OS_ObjectIndexFromToken(&token)); /* * After waiting, check that our ID still matches @@ -479,7 +488,7 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) */ if (!OS_ObjectIdEqual(timebase_id, record->active_id)) { - OS_TimeBaseUnlock_Impl(local_id); + OS_TimeBaseUnlock_Impl(OS_ObjectIndexFromToken(&token)); break; } @@ -531,7 +540,7 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) } while (curr_cb_local_id != timer_id); } - OS_TimeBaseUnlock_Impl(local_id); + OS_TimeBaseUnlock_Impl(OS_ObjectIndexFromToken(&token)); } } /* end OS_TimeBase_CallbackThread */ diff --git a/src/unit-test-coverage/shared/CMakeLists.txt b/src/unit-test-coverage/shared/CMakeLists.txt index 582ddcf2e..9f9211880 100644 --- a/src/unit-test-coverage/shared/CMakeLists.txt +++ b/src/unit-test-coverage/shared/CMakeLists.txt @@ -26,6 +26,7 @@ set(MODULE_LIST ) set(SHARED_COVERAGE_LINK_LIST + os-shared-coverage-support ut-adaptor-shared ut_osapi_impl_stubs ut_osapi_shared_stubs @@ -33,6 +34,10 @@ set(SHARED_COVERAGE_LINK_LIST ut_libc_stubs ) +add_library(os-shared-coverage-support STATIC + src/os-shared-coverage-support.c +) + add_subdirectory(adaptors) diff --git a/src/unit-test-coverage/shared/src/coveragetest-binsem.c b/src/unit-test-coverage/shared/src/coveragetest-binsem.c index 21bc69803..2b92b9626 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-binsem.c +++ b/src/unit-test-coverage/shared/src/coveragetest-binsem.c @@ -165,18 +165,12 @@ void Test_OS_BinSemGetInfo(void) * Test Case For: * int32 OS_BinSemGetInfo (uint32 sem_id, OS_bin_sem_prop_t *bin_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_bin_sem_prop_t prop; - osal_index_t local_index = UT_INDEX_1; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - utrec.creator = UT_OBJID_OTHER; - utrec.name_entry = "ABC"; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + OS_bin_sem_prop_t prop; + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_BINSEM, UT_INDEX_1, "ABC", UT_OBJID_OTHER); + actual = OS_BinSemGetInfo(UT_OBJID_1, &prop); UtAssert_True(actual == expected, "OS_BinSemGetInfo() (%ld) == OS_SUCCESS", (long)actual); diff --git a/src/unit-test-coverage/shared/src/coveragetest-countsem.c b/src/unit-test-coverage/shared/src/coveragetest-countsem.c index f5e539f1f..6c947a12e 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-countsem.c +++ b/src/unit-test-coverage/shared/src/coveragetest-countsem.c @@ -59,9 +59,7 @@ void Test_OS_CountSemCreate(void) int32 actual = OS_CountSemCreate(&objid, "UT", 0, 0); UtAssert_True(actual == expected, "OS_CountSemCreate() (%ld) == OS_SUCCESS", (long)actual); -#ifdef jphfix OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); -#endif OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate(NULL, NULL, 0, 0), OS_INVALID_POINTER); UT_SetDefaultReturnValue(UT_KEY(OCS_strlen), 10 + OS_MAX_API_NAME); @@ -156,21 +154,13 @@ void Test_OS_CountSemGetInfo(void) int32 expected = OS_SUCCESS; int32 actual = ~OS_SUCCESS; OS_count_sem_prop_t prop; - osal_index_t local_index = UT_INDEX_1; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - utrec.creator = UT_OBJID_OTHER; - utrec.name_entry = "ABC"; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_COUNTSEM, UT_INDEX_1, "ABC", UT_OBJID_OTHER); + actual = OS_CountSemGetInfo(UT_OBJID_1, &prop); UtAssert_True(actual == expected, "OS_CountSemGetInfo() (%ld) == OS_SUCCESS", (long)actual); -#ifdef jphfix - UtAssert_True(prop.creator == 111, "prop.creator (%lu) == 111", (unsigned long)prop.creator); -#endif + OSAPI_TEST_OBJID(prop.creator, ==, UT_OBJID_OTHER); UtAssert_True(strcmp(prop.name, "ABC") == 0, "prop.name (%s) == ABC", prop.name); OSAPI_TEST_FUNCTION_RC(OS_CountSemGetInfo(UT_OBJID_1, NULL), OS_INVALID_POINTER); diff --git a/src/unit-test-coverage/shared/src/coveragetest-file.c b/src/unit-test-coverage/shared/src/coveragetest-file.c index 3cfc7ee23..4292c5497 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-file.c +++ b/src/unit-test-coverage/shared/src/coveragetest-file.c @@ -237,7 +237,7 @@ void Test_OS_rename(void) int32 expected = OS_SUCCESS; int32 actual = ~OS_SUCCESS; - OS_global_stream_table[1].active_id = UT_OBJID_1; + OS_UT_SetupIterator(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, 1); strncpy(OS_stream_table[1].stream_name, "/cf/file1", sizeof(OS_stream_table[1].stream_name)); actual = OS_rename("/cf/file1", "/cf/file2"); @@ -310,18 +310,12 @@ void Test_OS_FDGetInfo(void) * Test Case For: * int32 OS_FDGetInfo (uint32 filedes, OS_file_prop_t *fd_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_file_prop_t file_prop; - osal_index_t local_index = UT_INDEX_1; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - utrec.creator = UT_OBJID_OTHER; - utrec.name_entry = "ABC"; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + OS_file_prop_t file_prop; + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, "ABC", UT_OBJID_OTHER); + actual = OS_FDGetInfo(UT_OBJID_1, &file_prop); UtAssert_True(actual == expected, "OS_FDGetInfo() (%ld) == OS_SUCCESS", (long)actual); @@ -343,7 +337,7 @@ void Test_OS_FileOpenCheck(void) UtAssert_True(actual == expected, "OS_FileOpenCheck() (%ld) == OS_ERROR", (long)actual); - OS_global_stream_table[0].active_id = UT_OBJID_1; + OS_UT_SetupIterator(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, 1); UT_SetDefaultReturnValue(UT_KEY(OCS_strcmp), 0); expected = OS_SUCCESS; actual = OS_FileOpenCheck("/cf/file"); @@ -367,8 +361,8 @@ void Test_OS_CloseFileByName(void) UtAssert_True(actual == expected, "OS_CloseFileByName() (%ld) == OS_FS_ERR_PATH_INVALID", (long)actual); /* setup for success */ - expected = OS_SUCCESS; - OS_global_stream_table[0].active_id = UT_OBJID_1; + OS_UT_SetupIterator(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, 1); + expected = OS_SUCCESS; UT_SetDefaultReturnValue(UT_KEY(OCS_strcmp), 0); actual = OS_CloseFileByName("/cf/file"); UtAssert_True(actual == expected, "OS_CloseFileByName() (%ld) == OS_SUCCESS", (long)actual); @@ -387,9 +381,8 @@ void Test_OS_CloseAllFiles(void) int32 expected = -222; int32 actual; - OS_global_stream_table[0].active_id = UT_OBJID_1; - OS_global_stream_table[1].active_id = UT_OBJID_2; - UT_SetDeferredRetcode(UT_KEY(OS_GenericClose_Impl), 1, expected); + OS_UT_SetupIterator(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, 2); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdIteratorProcessEntry), 1, expected); actual = OS_CloseAllFiles(); UtAssert_True(actual == expected, "OS_CloseAllFiles() (%ld) == -222", (long)actual); diff --git a/src/unit-test-coverage/shared/src/coveragetest-idmap.c b/src/unit-test-coverage/shared/src/coveragetest-idmap.c index 00b537c3d..5ac362b92 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-idmap.c +++ b/src/unit-test-coverage/shared/src/coveragetest-idmap.c @@ -27,6 +27,7 @@ #include "os-shared-coveragetest.h" #include "os-shared-idmap.h" #include "os-shared-common.h" +#include "os-shared-task.h" #include @@ -101,35 +102,37 @@ void Test_OS_LockUnlockGlobal(void) OS_Unlock_Global(OS_OBJECT_TYPE_OS_BINSEM); } -void Test_OS_ObjectIdConvertLock(void) +void Test_OS_ObjectIdConvertToken(void) { /* * Test Case For: - * static int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, - * uint32 idtype, uint32 reference_id, OS_common_record_t *obj) + * int32 OS_ObjectIdConvertToken(OS_object_token_t *token) * * NOTE: These test cases just focus on code paths that are not exercised * by the other test cases in this file. */ int32 expected; int32 actual; - osal_index_t array_index; + OS_object_token_t token; OS_common_record_t *record; osal_id_t objid; - UT_idbuf_t corrupt_objid; /* get a valid (fake) OSAL ID to start with */ - OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, "ut", &array_index, &record); - objid = record->active_id; + OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, "ut", &token); + objid = token.obj_id; + + record = OS_OBJECT_TABLE_GET(OS_global_task_table, token); + record->refcount = 5; + record->active_id = objid; /* * Attempt to obtain a lock for the same record with a non-matching ID * This should return an error. */ - corrupt_objid.id = objid; - corrupt_objid.val ^= 0x10; /* flip a bit */ - actual = OS_ObjectIdConvertLock(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TASK, corrupt_objid.id, record); - expected = OS_ERR_INVALID_ID; + token.lock_mode = OS_LOCK_MODE_NONE; + token.obj_id = OS_ObjectIdFromInteger(OS_ObjectIdToInteger(token.obj_id) ^ 0x10); /* flip a bit */ + actual = OS_ObjectIdConvertToken(&token); + expected = OS_ERR_INVALID_ID; UtAssert_True(actual == expected, "OS_ObjectIdConvertLock() (%ld) == OS_ERR_INVALID_ID (%ld)", (long)actual, (long)expected); @@ -138,22 +141,62 @@ void Test_OS_ObjectIdConvertLock(void) * Use mode OS_LOCK_MODE_NONE with matching ID * This should return success. */ - actual = OS_ObjectIdConvertLock(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TASK, objid, record); - expected = OS_SUCCESS; + token.lock_mode = OS_LOCK_MODE_NONE; + token.obj_id = objid; + actual = OS_ObjectIdConvertToken(&token); + expected = OS_SUCCESS; - UtAssert_True(actual == expected, "OS_ObjectIdConvertLock() (%ld) == OS_ERR_INVALID_ID (%ld)", (long)actual, + UtAssert_True(actual == expected, "OS_ObjectIdConvertLock(NONE) (%ld) == OS_SUCCESS (%ld)", (long)actual, + (long)expected); + + /* + * Use mode OS_LOCK_MODE_GLOBAL with matching ID + * This should return success, not change refcount + */ + token.lock_mode = OS_LOCK_MODE_GLOBAL; + token.obj_id = objid; + actual = OS_ObjectIdConvertToken(&token); + expected = OS_SUCCESS; + + UtAssert_True(actual == expected, "OS_ObjectIdConvertLock(GLOBAL) (%ld) == OS_SUCCESS (%ld)", (long)actual, + (long)expected); + UtAssert_UINT32_EQ(record->refcount, 5); + + /* + * Use mode OS_LOCK_MODE_REFCOUNT with matching ID + * This should return success, increment refcount + */ + token.lock_mode = OS_LOCK_MODE_REFCOUNT; + token.obj_id = objid; + actual = OS_ObjectIdConvertToken(&token); + expected = OS_SUCCESS; + + UtAssert_True(actual == expected, "OS_ObjectIdConvertLock(REFCOUNT) (%ld) == OS_SUCCESS (%ld)", (long)actual, (long)expected); + UtAssert_UINT32_EQ(record->refcount, 6); + + /* + * Use mode OS_LOCK_MODE_EXCLUSIVE with matching ID and other refs. + * This should return OS_ERR_OBJECT_IN_USE. + */ + token.lock_mode = OS_LOCK_MODE_EXCLUSIVE; + token.obj_id = objid; + actual = OS_ObjectIdConvertToken(&token); + expected = OS_ERR_OBJECT_IN_USE; + UtAssert_True(actual == expected, "OS_ObjectIdConvertLock(EXCLUSIVE) (%ld) == OS_ERR_OBJECT_IN_USE (%ld)", + (long)actual, (long)expected); + + /* should have delayed 4 times, on the 5th try it returns error */ + UtAssert_STUB_COUNT(OS_TaskDelay_Impl, 4); /* * Use mode OS_LOCK_MODE_EXCLUSIVE with matching ID and no other refs. * This should return success. */ - record->flags = 0; record->refcount = 0; - actual = OS_ObjectIdConvertLock(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_TASK, objid, record); + actual = OS_ObjectIdConvertToken(&token); expected = OS_SUCCESS; - - UtAssert_True(actual == expected, "OS_ObjectIdConvertLock() (%ld) == OS_SUCCESS (%ld)", (long)actual, + UtAssert_True(actual == expected, "OS_ObjectIdConvertLock(EXCLUSIVE) (%ld) == OS_SUCCESS (%ld)", (long)actual, (long)expected); } @@ -167,17 +210,21 @@ void Test_OS_ObjectIdGetBySearch(void) * NOTE: These test cases just focus on code paths that are not exercised * by the other test cases in this file. */ - int32 expected; - int32 actual; - OS_common_record_t *record; + int32 expected; + int32 actual; + OS_object_token_t token; OS_global_task_table[0].active_id = UT_OBJID_OTHER; - actual = OS_ObjectIdGetBySearch(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TASK, TestAlwaysMatch, NULL, &record); + actual = OS_ObjectIdGetBySearch(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TASK, TestAlwaysMatch, NULL, &token); expected = OS_SUCCESS; - OS_global_task_table[0].active_id = OS_OBJECT_ID_UNDEFINED; UtAssert_True(actual == expected, "OS_ObjectIdGetBySearch() (%ld) == OS_SUCCESS (%ld)", (long)actual, (long)expected); + + UtAssert_Bool(OS_ObjectIdEqual(token.obj_id, UT_OBJID_OTHER), "Token Object ID"); + UtAssert_UINT32_EQ(token.obj_idx, 0); + + OS_global_task_table[0].active_id = OS_OBJECT_ID_UNDEFINED; } void Test_OS_GetMaxForObjectType(void) @@ -328,8 +375,8 @@ void Test_OS_ObjectIdGetById(void) { /* * Test Case For: - * int32 OS_ObjectIdGetById(OS_lock_mode_t check_mode, uint32 idtype, uint32 id, uint32 *array_index, - * OS_common_record_t **record); + * int32 OS_ObjectIdGetById(OS_lock_mode_t lock_mode, osal_objtype_t idtype, osal_id_t id, OS_object_token_t + * *token); * */ int32 actual = ~OS_SUCCESS; @@ -337,70 +384,66 @@ void Test_OS_ObjectIdGetById(void) osal_id_t refobjid; osal_index_t local_idx; OS_common_record_t *rptr = NULL; + OS_object_token_t token1; + OS_object_token_t token2; /* verify that the call returns ERROR when not initialized */ OS_SharedGlobalVars.Initialized = false; - actual = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, 0, OS_OBJECT_ID_UNDEFINED, &local_idx, &rptr); - expected = OS_ERROR; + actual = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, 0, OS_OBJECT_ID_UNDEFINED, &token1); + expected = OS_ERROR; UtAssert_True(actual == expected, "OS_ObjectIdGetById(uninitialized) (%ld) == OS_ERROR", (long)actual); /* set "true" for the remainder of tests */ OS_SharedGlobalVars.Initialized = true; - OS_ObjectIdCompose_Impl(OS_OBJECT_TYPE_OS_TASK, 1, &refobjid); + OS_ObjectIdCompose_Impl(OS_OBJECT_TYPE_OS_TASK, 1000, &refobjid); OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_TASK, refobjid, &local_idx); - OS_global_task_table[local_idx].active_id = refobjid; - expected = OS_SUCCESS; - actual = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_TASK, refobjid, &local_idx, &rptr); + rptr = &OS_global_task_table[local_idx]; + rptr->active_id = refobjid; + expected = OS_SUCCESS; + actual = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_TASK, refobjid, &token1); /* Verify Outputs */ UtAssert_True(actual == expected, "OS_ObjectIdGetById() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(local_idx == 1, "local_idx (%lu) == 1", (unsigned long)local_idx); - UtAssert_True(rptr != NULL, "rptr (%p) != NULL", (void *)rptr); + UtAssert_UINT32_EQ(token1.obj_idx, local_idx); UtAssert_True(rptr->refcount == 1, "refcount (%u) == 1", (unsigned int)rptr->refcount); /* attempting to get an exclusive lock should return IN_USE error */ expected = OS_ERR_OBJECT_IN_USE; - actual = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_TASK, refobjid, &local_idx, &rptr); + actual = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_TASK, refobjid, &token2); UtAssert_True(actual == expected, "OS_ObjectIdGetById() (%ld) == OS_ERR_OBJECT_IN_USE", (long)actual); + /* refcount decrement should work */ + OS_ObjectIdRelease(&token1); + UtAssert_True(rptr->refcount == 0, "refcount (%u) == 0", (unsigned int)rptr->refcount); + + /* noop if done a second time */ + OS_ObjectIdRelease(&token1); + UtAssert_True(rptr->refcount == 0, "refcount (%u) == 0", (unsigned int)rptr->refcount); + /* attempt to get non-exclusive lock during shutdown should fail */ OS_SharedGlobalVars.ShutdownFlag = OS_SHUTDOWN_MAGIC_NUMBER; expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TASK, refobjid, &local_idx, &rptr); + actual = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TASK, refobjid, &token1); UtAssert_True(actual == expected, "OS_ObjectIdGetById() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); OS_SharedGlobalVars.ShutdownFlag = 0; /* attempt to get lock for invalid type object should fail */ - expected = OS_ERR_INVALID_ID; - actual = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, 0xFFFF, refobjid, &local_idx, &rptr); - UtAssert_True(actual == expected, "OS_ObjectIdGetById() (%ld) == OS_ERR_INVALID_ID", (long)actual); + expected = OS_ERR_INCORRECT_OBJ_TYPE; + actual = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, 0xFFFF, refobjid, &token1); + UtAssert_True(actual == expected, "OS_ObjectIdGetById() (%ld) == OS_ERR_INCORRECT_OBJ_TYPE", (long)actual); OS_SharedGlobalVars.ShutdownFlag = 0; - /* refcount decrement should work */ - expected = OS_SUCCESS; - actual = OS_ObjectIdRefcountDecr(rptr); - UtAssert_True(actual == expected, "OS_ObjectIdRefcountDecr() (%ld) == OS_SUCCESS", (long)actual); - - /* decrement should fail if done a second time */ - expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_ObjectIdRefcountDecr(rptr); - UtAssert_True(actual == expected, "OS_ObjectIdRefcountDecr() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); - /* clear out state entry */ memset(&OS_global_task_table[local_idx], 0, sizeof(OS_global_task_table[local_idx])); - - expected = OS_ERR_INVALID_ID; - actual = OS_ObjectIdRefcountDecr(rptr); - UtAssert_True(actual == expected, "OS_ObjectIdRefcountDecr() (%ld) == OS_ERR_INVALID_ID", (long)actual); } -void Test_OS_ObjectIdFindNext(void) +void Test_OS_ObjectIdFindNextFree(void) { /* * Test Case For: - * int32 OS_ObjectIdFindNext(uint32 idtype, uint32 *array_index, OS_common_record_t **record); - * int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_common_record_t *record, uint32 *outid); + * int32 OS_ObjectIdFindNextFree(OS_object_token_t *token); + * int32 OS_ObjectIdFinalizeNew(int32 operation_status, &token, uint32 *outid); * * Note This test case covers both functions because they are somewhat interlinked and * they share state between them - The output of FindNext() should be passed to Finalize() @@ -409,75 +452,81 @@ void Test_OS_ObjectIdFindNext(void) int32 expected; int32 actual; + OS_object_token_t token1; + OS_object_token_t token2; OS_common_record_t *rec1; OS_common_record_t *rec2; osal_id_t id1; osal_id_t id2; - UT_idbuf_t check_id; - UT_idbuf_t saved_id; + osal_id_t saved_id; uint32 i; + memset(&token1, 0, sizeof(token1)); + token1.lock_mode = OS_LOCK_MODE_GLOBAL; + token1.obj_type = OS_OBJECT_TYPE_OS_TASK; + /* Need to first obtain a valid ID to finalize */ expected = OS_SUCCESS; - actual = OS_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, NULL, &rec1); - UtAssert_True(actual == expected, "OS_ObjectIdFindNext() (%ld) == OS_SUCCESS", (long)actual); + actual = OS_ObjectIdFindNextFree(&token1); + UtAssert_True(actual == expected, "OS_ObjectIdFindNextFree() (%ld) == OS_SUCCESS", (long)actual); /* nominal case (success) */ id1 = OS_OBJECT_ID_UNDEFINED; - actual = OS_ObjectIdFinalizeNew(OS_SUCCESS, rec1, &id1); + actual = OS_ObjectIdFinalizeNew(OS_SUCCESS, &token1, &id1); + OSAPI_TEST_OBJID(id1, ==, token1.obj_id); /* Verify Outputs */ + rec1 = OS_OBJECT_TABLE_GET(OS_global_task_table, token1); UtAssert_True(actual == expected, "OS_ObjectIdFinalizeNew() (%ld) == OS_SUCCESS", (long)actual); - OSAPI_TEST_OBJID(id1, ==, rec1->active_id); + OSAPI_TEST_OBJID(token1.obj_id, ==, rec1->active_id); /* Allocate another ID (should be different!) */ - actual = OS_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, NULL, &rec2); - UtAssert_True(actual == expected, "OS_ObjectIdFindNext() (%ld) == OS_SUCCESS", (long)actual); - OSAPI_TEST_OBJID(rec2->active_id, !=, rec1->active_id); + memset(&token2, 0, sizeof(token2)); + token2.lock_mode = OS_LOCK_MODE_GLOBAL; + token2.obj_type = OS_OBJECT_TYPE_OS_TASK; + actual = OS_ObjectIdFindNextFree(&token2); + UtAssert_True(actual == expected, "OS_ObjectIdFindNextFree() (%ld) == OS_SUCCESS", (long)actual); + rec2 = OS_OBJECT_TABLE_GET(OS_global_task_table, token2); + OSAPI_TEST_OBJID(token2.obj_id, !=, token1.obj_id); /* Failure to initialize the second one. * Verify the error code passes thru */ - expected = -1234; - saved_id.id = rec2->active_id; - id2 = OS_OBJECT_ID_UNDEFINED; - actual = OS_ObjectIdFinalizeNew(expected, rec2, &id2); + expected = -1234; + saved_id = token2.obj_id; + id2 = OS_OBJECT_ID_UNDEFINED; + actual = OS_ObjectIdFinalizeNew(expected, &token2, &id2); /* Verify Outputs */ UtAssert_True(actual == expected, "OS_ObjectIdFinalizeNew() (%ld) == %ld", (long)actual, (long)expected); OSAPI_TEST_OBJID(id2, ==, OS_OBJECT_ID_UNDEFINED); OSAPI_TEST_OBJID(rec2->active_id, ==, OS_OBJECT_ID_UNDEFINED); + OSAPI_TEST_OBJID(token2.obj_id, ==, saved_id); - /* next call should re-issue the same id because init failed */ - expected = OS_SUCCESS; - actual = OS_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, NULL, &rec2); - UtAssert_True(actual == expected, "OS_ObjectIdFindNext() (%ld) == OS_SUCCESS", (long)actual); - OSAPI_TEST_OBJID(rec2->active_id, ==, saved_id.id); - - /* test invalid case*/ - rec2->active_id = OS_OBJECT_ID_UNDEFINED; - expected = OS_ERR_INVALID_ID; - actual = OS_ObjectIdFinalizeNew(OS_SUCCESS, rec2, &id2); - UtAssert_True(actual == expected, "OS_ObjectIdFinalizeNew() (%ld) == %ld", (long)actual, (long)expected); - OSAPI_TEST_OBJID(id2, ==, OS_OBJECT_ID_UNDEFINED); - OSAPI_TEST_OBJID(rec2->active_id, ==, OS_OBJECT_ID_UNDEFINED); + /* next call should not re-issue the same id */ + memset(&token2, 0, sizeof(token2)); + token2.obj_type = OS_OBJECT_TYPE_OS_TASK; + expected = OS_SUCCESS; + actual = OS_ObjectIdFindNextFree(&token2); + UtAssert_True(actual == expected, "OS_ObjectIdFindNextFree() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_OBJID(token2.obj_id, !=, saved_id); /* * Finally - test the wrap-around function to verify that object IDs * will continue to allocate correctly after OS_OBJECT_INDEX_MASK */ - expected = OS_SUCCESS; - saved_id.id = OS_OBJECT_ID_UNDEFINED; + expected = OS_SUCCESS; + saved_id = OS_OBJECT_ID_UNDEFINED; for (i = 0; i < (OS_OBJECT_INDEX_MASK + 2); ++i) { - actual = OS_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, NULL, &rec2); - /* not usuing UtAssert_True here as it will create thousands of duplicates. */ + actual = OS_ObjectIdFindNextFree(&token2); + /* not using UtAssert_True here as it will create thousands of duplicates. */ if (expected != actual) { - UtAssert_Failed("OS_ObjectIdFindNext() failure (%ld)", (long)actual); + UtAssert_Failed("OS_ObjectIdFindNextFree() failure (%ld)", (long)actual); break; } - actual = OS_ObjectIdFinalizeNew(OS_SUCCESS, rec2, NULL); + actual = OS_ObjectIdFinalizeNew(OS_SUCCESS, &token2, NULL); if (expected != actual) { UtAssert_Failed("OS_ObjectIdFinalizeNew() failure (%ld)", (long)actual); @@ -485,79 +534,79 @@ void Test_OS_ObjectIdFindNext(void) } /* should always be different than the previous ID */ - if (OS_ObjectIdEqual(saved_id.id, rec2->active_id)) + if (OS_ObjectIdEqual(saved_id, token2.obj_id)) { - UtAssert_Failed("OS_ObjectIdFindNext() re-issued ID (%lx)", (unsigned long)saved_id.val); + UtAssert_Failed("OS_ObjectIdFindNextFree() re-issued ID (%lx)", OS_ObjectIdToInteger(token2.obj_id)); break; } /* it also should never be id1, which was previously allocated */ - check_id.id = id1; - if (OS_ObjectIdEqual(check_id.id, rec2->active_id)) + if (OS_ObjectIdEqual(token1.obj_id, token2.obj_id)) { - UtAssert_Failed("OS_ObjectIdFindNext() duplicate ID (%lx)", (unsigned long)check_id.val); + UtAssert_Failed("OS_ObjectIdFindNextFree() duplicate ID (%lx)", OS_ObjectIdToInteger(token1.obj_id)); break; } if (rec1 == rec2) { - UtAssert_Failed("OS_ObjectIdFindNext() duplicate slot (%p)", (void *)rec1); + UtAssert_Failed("OS_ObjectIdFindNextFree() duplicate slot (%p)", (void *)rec1); break; } /* Find the wrap. Once this occurs the test is successful. */ - check_id.id = rec2->active_id; - if (saved_id.val > check_id.val) + if (OS_ObjectIdToInteger(saved_id) > OS_ObjectIdToInteger(token2.obj_id)) { /* Success */ break; } /* clear the entry for re-use */ - saved_id.id = rec2->active_id; - rec2->active_id = OS_OBJECT_ID_UNDEFINED; + saved_id = token2.obj_id; + rec2 = OS_OBJECT_TABLE_GET(OS_global_task_table, token2); + memset(rec2, 0, sizeof(*rec2)); } /* verify that the wrap occurred */ - UtAssert_True(i < (OS_OBJECT_INDEX_MASK + 2), "OS_ObjectIdFindNext() wrap around occurred"); + UtAssert_True(i < (OS_OBJECT_INDEX_MASK + 2), "OS_ObjectIdFindNextFree() wrap around occurred"); } void Test_OS_ObjectIdAllocateNew(void) { /* * Test Case For: - * int32 OS_ObjectIdAllocateNew(uint32 idtype, const char *name, uint32 *array_index, OS_common_record_t **record); + * int32 OS_ObjectIdAllocateNew(osal_objtype_t idtype, const char *name, OS_object_token_t *token) * - * Most of the business logic is done by OS_ObjectIdFindNext() which is tested separately + * Most of the business logic is done by OS_ObjectIdFindNextFree() which is tested separately * This test case mainly focuses on additional error checking */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - osal_index_t idx; - OS_common_record_t *rptr = NULL; + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + OS_object_token_t token; - actual = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, "UT_alloc", &idx, &rptr); + actual = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, "UT_alloc", &token); /* Verify Outputs */ UtAssert_True(actual == expected, "OS_ObjectIdAllocate() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(rptr != NULL, "rptr (%p) != NULL", (void *)rptr); + UtAssert_UINT32_EQ(token.lock_mode, OS_LOCK_MODE_EXCLUSIVE); + UtAssert_UINT32_EQ(token.obj_type, OS_OBJECT_TYPE_OS_TASK); + UtAssert_Bool(OS_ObjectIdDefined(token.obj_id), "ObjectIdDefined(token.obj_id)"); /* Passing a NULL name also should work here (used for internal objects) */ - actual = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, NULL, &idx, &rptr); + actual = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, NULL, &token); UtAssert_True(actual == expected, "OS_ObjectIdAllocate(NULL) (%ld) == OS_SUCCESS", (long)actual); - rptr->name_entry = "UT_alloc"; - expected = OS_ERR_NAME_TAKEN; - actual = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, "UT_alloc", &idx, &rptr); + OS_global_task_table[0].name_entry = "UT_alloc"; + expected = OS_ERR_NAME_TAKEN; + actual = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, "UT_alloc", &token); UtAssert_True(actual == expected, "OS_ObjectIdAllocate() (%ld) == OS_ERR_NAME_TAKEN", (long)actual); OS_SharedGlobalVars.ShutdownFlag = OS_SHUTDOWN_MAGIC_NUMBER; - expected = OS_ERROR; - actual = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, "UT_alloc", &idx, &rptr); + expected = OS_ERR_INCORRECT_OBJ_STATE; + actual = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TASK, "UT_alloc", &token); OS_SharedGlobalVars.ShutdownFlag = 0; - UtAssert_True(actual == expected, "OS_ObjectIdAllocate() (%ld) == OS_ERR_NAME_TAKEN", (long)actual); + UtAssert_True(actual == expected, "OS_ObjectIdAllocate() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); expected = OS_ERR_INCORRECT_OBJ_TYPE; - actual = OS_ObjectIdAllocateNew(0xFFFF, "UT_alloc", &idx, &rptr); + actual = OS_ObjectIdAllocateNew(0xFFFF, "UT_alloc", &token); UtAssert_True(actual == expected, "OS_ObjectIdAllocate() (%ld) == OS_ERR_INCORRECT_OBJ_TYPE", (long)actual); } @@ -569,21 +618,20 @@ void Test_OS_ConvertToArrayIndex(void) * * */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; // OS_ConvertToArrayIndex(); - osal_index_t local_idx1; - osal_index_t local_idx2; - OS_common_record_t *rptr = NULL; + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; // OS_ConvertToArrayIndex(); + osal_id_t refobjid; + osal_index_t local_idx; /* Need a valid ID to work with */ - OS_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, &local_idx1, &rptr); - actual = OS_ConvertToArrayIndex(rptr->active_id, &local_idx2); + OS_ObjectIdCompose_Impl(OS_OBJECT_TYPE_OS_TASK, 1234, &refobjid); + actual = OS_ConvertToArrayIndex(refobjid, &local_idx); UtAssert_True(actual == expected, "OS_ConvertToArrayIndex() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(local_idx1 == local_idx2, "local_idx1 (%lu) == local_idx2 (%lu)", (unsigned long)local_idx1, - (unsigned long)local_idx2); + UtAssert_True(local_idx < OS_MAX_TASKS, "local_idx (%lu) < OS_MAX_TASKS (%lu)", (unsigned long)local_idx, + (unsigned long)OS_MAX_TASKS); expected = OS_ERR_INVALID_ID; - actual = OS_ConvertToArrayIndex(OS_OBJECT_ID_UNDEFINED, &local_idx2); + actual = OS_ConvertToArrayIndex(OS_OBJECT_ID_UNDEFINED, &local_idx); UtAssert_True(actual == expected, "OS_ConvertToArrayIndex() (%ld) == OS_ERR_INVALID_ID", (long)actual); } @@ -593,21 +641,22 @@ void Test_OS_ForEachObject(void) * Test Case For: * void OS_ForEachObject (uint32 creator_id, OS_ArgCallback_t callback_ptr, void *callback_arg); */ - osal_objtype_t objtype; - OS_common_record_t * rptr = NULL; - osal_index_t local_idx; + OS_object_token_t token; UT_idbuf_t self_id; Test_OS_ObjTypeCount_t Count; self_id.id = OS_TaskGetId(); memset(&Count, 0, sizeof(Count)); + memset(&token, 0, sizeof(token)); - objtype = OS_OBJECT_TYPE_UNDEFINED; - while (objtype < OS_OBJECT_TYPE_USER) + while (token.obj_type < OS_OBJECT_TYPE_USER) { - OS_ObjectIdFindNext(objtype, &local_idx, &rptr); - ++objtype; + if (OS_ObjectIdFindNextFree(&token) == OS_SUCCESS) + { + OS_ObjectIdGlobalFromToken(&token)->active_id = token.obj_id; + } + ++token.obj_type; } OS_ForEachObject(OS_OBJECT_ID_UNDEFINED, &ObjTypeCounter, &Count); @@ -642,8 +691,8 @@ void Test_OS_GetResourceName(void) * Test Case For: * int32 OS_GetResourceName(uint32 id, char *buffer, uint32 buffer_size) */ - osal_index_t local_idx; - OS_common_record_t *rptr = NULL; + OS_object_token_t token; + OS_common_record_t *rptr; char NameBuffer[OS_MAX_API_NAME]; int32 expected; int32 actual; @@ -652,19 +701,24 @@ void Test_OS_GetResourceName(void) * Set up for the OS_GetResourceName function to return success */ /* Need a valid ID to work with */ - OS_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, &local_idx, &rptr); + memset(&token, 0, sizeof(token)); + token.obj_type = OS_OBJECT_TYPE_OS_TASK; + OS_ObjectIdFindNextFree(&token); + rptr = OS_OBJECT_TABLE_GET(OS_global_task_table, token); rptr->name_entry = "UTTask"; - expected = OS_SUCCESS; - actual = OS_GetResourceName(rptr->active_id, NameBuffer, sizeof(NameBuffer)); + rptr->active_id = token.obj_id; + + expected = OS_SUCCESS; + actual = OS_GetResourceName(token.obj_id, NameBuffer, sizeof(NameBuffer)); UtAssert_True(actual == expected, "OS_GetResourceName() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(strcmp(NameBuffer, "UTTask") == 0, "NameBuffer (%s) == UTTask", NameBuffer); expected = OS_ERR_NAME_TOO_LONG; - actual = OS_GetResourceName(rptr->active_id, NameBuffer, OSAL_SIZE_C(2)); + actual = OS_GetResourceName(token.obj_id, NameBuffer, OSAL_SIZE_C(2)); UtAssert_True(actual == expected, "OS_GetResourceName() (%ld) == OS_ERR_NAME_TOO_LONG", (long)actual); expected = OS_INVALID_POINTER; - actual = OS_GetResourceName(rptr->active_id, NULL, OSAL_SIZE_C(0)); + actual = OS_GetResourceName(token.obj_id, NULL, OSAL_SIZE_C(0)); UtAssert_True(actual == expected, "OS_GetResourceName() (%ld) == OS_INVALID_POINTER", (long)actual); } @@ -703,12 +757,12 @@ void UtTest_Setup(void) { ADD_TEST(OS_ObjectIdInit); ADD_TEST(OS_LockUnlockGlobal); - ADD_TEST(OS_ObjectIdFindNext); + ADD_TEST(OS_ObjectIdFindNextFree); ADD_TEST(OS_ObjectIdToArrayIndex); ADD_TEST(OS_ObjectIdFindByName); ADD_TEST(OS_ObjectIdGetById); ADD_TEST(OS_ObjectIdAllocateNew); - ADD_TEST(OS_ObjectIdConvertLock); + ADD_TEST(OS_ObjectIdConvertToken); ADD_TEST(OS_ObjectIdGetBySearch); ADD_TEST(OS_ConvertToArrayIndex); ADD_TEST(OS_ForEachObject); diff --git a/src/unit-test-coverage/shared/src/coveragetest-module.c b/src/unit-test-coverage/shared/src/coveragetest-module.c index 1b69365af..1a13d9389 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-module.c +++ b/src/unit-test-coverage/shared/src/coveragetest-module.c @@ -229,20 +229,13 @@ void Test_OS_ModuleGetInfo(void) * Test Case For: * int32 OS_ModuleInfo ( uint32 module_id, OS_module_prop_t *module_prop ) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_module_prop_t module_prop; - osal_index_t local_index; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - local_index = UT_INDEX_1; - memset(&utrec, 0, sizeof(utrec)); - utrec.creator = UT_OBJID_OTHER; - utrec.name_entry = "ABC"; + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + OS_module_prop_t module_prop; + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_MODULE, UT_INDEX_1, "ABC", UT_OBJID_OTHER); strncpy(OS_module_table[1].file_name, "DEF", sizeof(OS_module_table[1].file_name)); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); + actual = OS_ModuleInfo(UT_OBJID_1, &module_prop); UtAssert_True(actual == expected, "OS_ModuleGetInfo() (%ld) == OS_SUCCESS", (long)actual); diff --git a/src/unit-test-coverage/shared/src/coveragetest-mutex.c b/src/unit-test-coverage/shared/src/coveragetest-mutex.c index 8fa79469c..b14655ecd 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-mutex.c +++ b/src/unit-test-coverage/shared/src/coveragetest-mutex.c @@ -136,18 +136,12 @@ void Test_OS_MutSemGetInfo(void) * Test Case For: * int32 OS_MutSemGetInfo (uint32 sem_id, OS_mut_sem_prop_t *mut_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_mut_sem_prop_t prop; - osal_index_t local_index = UT_INDEX_1; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - utrec.creator = UT_OBJID_OTHER; - utrec.name_entry = "ABC"; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + OS_mut_sem_prop_t prop; + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_MUTEX, UT_INDEX_1, "ABC", UT_OBJID_OTHER); + actual = OS_MutSemGetInfo(UT_OBJID_1, &prop); UtAssert_True(actual == expected, "OS_MutSemGetInfo() (%ld) == OS_SUCCESS", (long)actual); diff --git a/src/unit-test-coverage/shared/src/coveragetest-printf.c b/src/unit-test-coverage/shared/src/coveragetest-printf.c index c7f0fb9ac..44f7f7586 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-printf.c +++ b/src/unit-test-coverage/shared/src/coveragetest-printf.c @@ -38,10 +38,16 @@ void Test_OS_ConsoleAPI_Init(void) * Test Case For: * int32 OS_ConsoleAPI_Init(void) */ - uint32 CallCount = 0; - uint32 local_id = 0; + uint32 CallCount = 0; + OS_object_token_t token; + + /* make a custom token to force use of array index 0 */ + token.lock_mode = OS_LOCK_MODE_NONE; + token.obj_type = OS_OBJECT_TYPE_OS_CONSOLE; + token.obj_idx = UT_INDEX_0; + token.obj_id = UT_OBJID_1; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdAllocateNew), &local_id, sizeof(local_id), false); + UT_SetDataBuffer(UT_KEY(OS_ObjectIdAllocateNew), &token, sizeof(token), false); /* call for coverage */ OS_ConsoleAPI_Init(); diff --git a/src/unit-test-coverage/shared/src/coveragetest-queue.c b/src/unit-test-coverage/shared/src/coveragetest-queue.c index dc6ccb64d..d5efa54ac 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-queue.c +++ b/src/unit-test-coverage/shared/src/coveragetest-queue.c @@ -166,20 +166,15 @@ void Test_OS_QueueGetInfo(void) * Test Case For: * int32 OS_QueueGetInfo (uint32 queue_id, OS_queue_prop_t *queue_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_queue_prop_t queue_prop; - osal_id_t id; - osal_index_t local_index = UT_INDEX_1; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - id = UT_OBJID_OTHER; - utrec.creator = UT_OBJID_OTHER; - utrec.name_entry = "ABC"; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + OS_queue_prop_t queue_prop; + osal_id_t id; + + id = UT_OBJID_OTHER; + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_QUEUE, UT_INDEX_1, "ABC", UT_OBJID_OTHER); + actual = OS_QueueGetInfo(UT_OBJID_1, &queue_prop); UtAssert_True(actual == expected, "OS_QueueGetInfo() (%ld) == OS_SUCCESS", (long)actual); diff --git a/src/unit-test-coverage/shared/src/coveragetest-sockets.c b/src/unit-test-coverage/shared/src/coveragetest-sockets.c index 5c9156edd..d3a7feb63 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-sockets.c +++ b/src/unit-test-coverage/shared/src/coveragetest-sockets.c @@ -159,7 +159,7 @@ void Test_OS_SocketAccept(void) OS_stream_table[local_id].socket_type = OS_SocketType_STREAM; OS_stream_table[local_id].stream_state = OS_STREAM_STATE_BOUND; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_id, sizeof(local_id), false); + OS_UT_SetupTestTargetIndex(OS_OBJECT_TYPE_OS_STREAM, local_id); memset(&Addr, 0, sizeof(Addr)); actual = OS_SocketAccept(UT_OBJID_1, &connsock_id, &Addr, 0); @@ -215,7 +215,7 @@ void Test_OS_SocketConnect(void) memset(&Addr, 0, sizeof(Addr)); idbuf = UT_INDEX_1; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &idbuf, sizeof(idbuf), false); + OS_UT_SetupTestTargetIndex(OS_OBJECT_TYPE_OS_STREAM, idbuf); OS_stream_table[idbuf].socket_domain = OS_SocketDomain_INET; OS_stream_table[idbuf].socket_type = OS_SocketType_STREAM; OS_stream_table[idbuf].stream_state = 0; @@ -268,7 +268,7 @@ void Test_OS_SocketRecvFrom(void) memset(&Addr, 0, sizeof(Addr)); idbuf = UT_INDEX_1; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &idbuf, sizeof(idbuf), false); + OS_UT_SetupTestTargetIndex(OS_OBJECT_TYPE_OS_STREAM, idbuf); OS_stream_table[idbuf].socket_type = OS_SocketType_DATAGRAM; OS_stream_table[idbuf].stream_state = OS_STREAM_STATE_BOUND; actual = OS_SocketRecvFrom(UT_OBJID_1, &Buf, 1, &Addr, 0); @@ -319,7 +319,7 @@ void Test_OS_SocketSendTo(void) memset(&Addr, 0, sizeof(Addr)); idbuf = UT_INDEX_1; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &idbuf, sizeof(idbuf), false); + OS_UT_SetupTestTargetIndex(OS_OBJECT_TYPE_OS_STREAM, idbuf); OS_stream_table[idbuf].socket_type = OS_SocketType_DATAGRAM; OS_stream_table[idbuf].stream_state = OS_STREAM_STATE_BOUND; actual = OS_SocketSendTo(UT_OBJID_1, &Buf, sizeof(Buf), &Addr); @@ -381,18 +381,11 @@ void Test_OS_SocketGetInfo(void) * Test Case For: * int32 OS_SocketGetInfo (uint32 sock_id, OS_socket_prop_t *sock_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_socket_prop_t prop; - osal_index_t local_index = UT_INDEX_1; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - utrec.creator = UT_OBJID_OTHER; - utrec.name_entry = "ABC"; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + OS_socket_prop_t prop; + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, "ABC", UT_OBJID_OTHER); actual = OS_SocketGetInfo(UT_OBJID_1, &prop); UtAssert_True(actual == expected, "OS_SocketGetInfo() (%ld) == OS_SUCCESS", (long)actual); diff --git a/src/unit-test-coverage/shared/src/coveragetest-task.c b/src/unit-test-coverage/shared/src/coveragetest-task.c index 9fa88677d..1d9d20d8c 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-task.c +++ b/src/unit-test-coverage/shared/src/coveragetest-task.c @@ -56,6 +56,7 @@ void Test_OS_TaskEntryPoint(void) uint32 CallCount = 0; UT_TestHook_Count = 0; + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERROR); OS_TaskEntryPoint(UT_OBJID_1); UtAssert_True(UT_TestHook_Count == 0, "UT_TestHook_Count (%lu) == 0", (unsigned long)UT_TestHook_Count); CallCount = UT_GetStubCount(UT_KEY(OS_TaskMatch_Impl)); @@ -154,14 +155,6 @@ void Test_OS_TaskExit(void) * Test Case For: * void OS_TaskExit() */ - osal_index_t local_index = UT_INDEX_0; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - utrec.active_id = UT_OBJID_1; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); OS_TaskExit(); @@ -249,27 +242,20 @@ void Test_OS_TaskGetInfo(void) * Test Case For: * int32 OS_TaskGetInfo (uint32 task_id, OS_task_prop_t *task_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_task_prop_t task_prop; - osal_index_t local_index = UT_INDEX_1; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - utrec.creator = UT_OBJID_OTHER; - utrec.name_entry = "ABC"; + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + OS_task_prop_t task_prop; + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_TASK, UT_INDEX_1, "ABC", UT_OBJID_OTHER); OS_task_table[1].stack_size = OSAL_SIZE_C(222); OS_task_table[1].priority = OSAL_PRIORITY_C(133); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); + actual = OS_TaskGetInfo(UT_OBJID_1, &task_prop); UtAssert_True(actual == expected, "OS_TaskGetInfo() (%ld) == OS_SUCCESS", (long)actual); OSAPI_TEST_OBJID(task_prop.creator, ==, UT_OBJID_OTHER); UtAssert_True(strcmp(task_prop.name, "ABC") == 0, "task_prop.name (%s) == ABC", task_prop.name); - UtAssert_True(task_prop.stack_size == 222, "task_prop.stack_size (%lu) == 222", - (unsigned long)task_prop.stack_size); + UtAssert_True(task_prop.stack_size == 222, "task_prop.stack_size (%lu) == 222", (unsigned long)task_prop.stack_size); UtAssert_True(task_prop.priority == 133, "task_prop.priority (%lu) == 133", (unsigned long)task_prop.priority); OS_task_table[1].stack_size = OSAL_SIZE_C(0); diff --git a/src/unit-test-coverage/shared/src/coveragetest-time.c b/src/unit-test-coverage/shared/src/coveragetest-time.c index fc9fd125d..9ab947db0 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-time.c +++ b/src/unit-test-coverage/shared/src/coveragetest-time.c @@ -170,10 +170,11 @@ void Test_OS_TimerSet(void) actual = OS_TimerSet(UT_OBJID_1, 0, 1); UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_SUCCESS", (long)actual); - OS_timecb_table[2].timebase_ref = UT_INDEX_0; - OS_timecb_table[2].flags = TIMECB_FLAG_DEDICATED_TIMEBASE; - OS_global_timebase_table[0].active_id = UT_OBJID_2; - actual = OS_TimerSet(UT_OBJID_2, 0, 1); + OS_timecb_table[2].timebase_token.obj_type = OS_OBJECT_TYPE_OS_TIMEBASE; + OS_timecb_table[2].timebase_token.obj_id = UT_OBJID_2; + OS_timecb_table[2].timebase_token.obj_idx = UT_INDEX_0; + OS_timecb_table[2].flags = TIMECB_FLAG_DEDICATED_TIMEBASE; + actual = OS_TimerSet(UT_OBJID_2, 0, 1); UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_SUCCESS", (long)actual); memset(OS_timecb_table, 0, sizeof(OS_timecb_table)); @@ -194,17 +195,20 @@ void Test_OS_TimerDelete(void) * Test Case For: * int32 OS_TimerDelete(uint32 timer_id) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_TimerDelete(UT_OBJID_1); + int32 expected = OS_SUCCESS; + int32 actual = OS_TimerDelete(UT_OBJID_1); + osal_id_t timebase_id; UtAssert_True(actual == expected, "OS_TimerDelete() (%ld) == OS_SUCCESS", (long)actual); - OS_timecb_table[1].timebase_ref = UT_INDEX_0; - OS_timecb_table[2].timebase_ref = UT_INDEX_0; - OS_timecb_table[2].next_ref = UT_INDEX_1; - OS_timecb_table[1].next_ref = UT_INDEX_1; - OS_timebase_table[0].first_cb = UT_OBJID_2; - actual = OS_TimerDelete(UT_OBJID_2); + OS_timecb_table[1].timebase_token.obj_type = OS_OBJECT_TYPE_OS_TIMEBASE; + OS_timecb_table[1].timebase_token.obj_id = UT_OBJID_1; + OS_timecb_table[1].timebase_token.obj_idx = UT_INDEX_0; + OS_timecb_table[2].timebase_token = OS_timecb_table[1].timebase_token; + OS_timecb_table[2].next_ref = UT_INDEX_1; + OS_timecb_table[1].next_ref = UT_INDEX_1; + OS_timebase_table[0].first_cb = UT_OBJID_2; + actual = OS_TimerDelete(UT_OBJID_2); UtAssert_True(actual == expected, "OS_TimerDelete() (%ld) == OS_SUCCESS", (long)actual); OS_timebase_table[0].first_cb = UT_OBJID_1; @@ -213,10 +217,13 @@ void Test_OS_TimerDelete(void) /* verify deletion of the dedicated timebase objects * these are implicitly created as part of timer creation for API compatibility */ - OS_TimeBaseCreate(&OS_global_timebase_table[0].active_id, "ut", NULL); - OS_timecb_table[1].flags = TIMECB_FLAG_DEDICATED_TIMEBASE; - OS_timecb_table[1].timebase_ref = UT_INDEX_0; - actual = OS_TimerDelete(UT_OBJID_1); + OS_TimeBaseCreate(&timebase_id, "ut", NULL); + OS_UT_SetupTestTargetIndex(OS_OBJECT_TYPE_OS_TIMECB, UT_INDEX_1); + OS_timecb_table[1].flags = TIMECB_FLAG_DEDICATED_TIMEBASE; + OS_timecb_table[1].timebase_token.obj_type = OS_OBJECT_TYPE_OS_TIMEBASE; + OS_timecb_table[1].timebase_token.obj_id = timebase_id; + OS_timecb_table[1].timebase_token.obj_idx = OS_ObjectIdToInteger(timebase_id) & OS_OBJECT_INDEX_MASK; + actual = OS_TimerDelete(UT_OBJID_1); UtAssert_True(actual == expected, "OS_TimerDelete() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(UT_GetStubCount(UT_KEY(OS_TimeBaseDelete)) == 1, "OS_TimerDelete() invoked OS_TimeBaseDelete()"); @@ -266,21 +273,18 @@ void Test_OS_TimerGetInfo(void) * Test Case For: * int32 OS_TimerGetInfo (uint32 timer_id, OS_timer_prop_t *timer_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_timer_prop_t timer_prop; - osal_index_t local_index = UT_INDEX_1; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - utrec.creator = UT_OBJID_OTHER; - utrec.name_entry = "ABC"; - OS_timecb_table[1].interval_time = 2222; - OS_timecb_table[1].timebase_ref = UT_INDEX_0; - OS_timebase_table[0].accuracy_usec = 3333; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + OS_timer_prop_t timer_prop; + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_TIMECB, UT_INDEX_1, "ABC", UT_OBJID_OTHER); + + OS_timecb_table[1].interval_time = 2222; + OS_timecb_table[1].timebase_token.obj_type = OS_OBJECT_TYPE_OS_TIMEBASE; + OS_timecb_table[1].timebase_token.obj_id = UT_OBJID_1; + OS_timecb_table[1].timebase_token.obj_idx = UT_INDEX_0; + OS_timebase_table[0].accuracy_usec = 3333; + actual = OS_TimerGetInfo(UT_OBJID_1, &timer_prop); UtAssert_True(actual == expected, "OS_TimerGetInfo() (%ld) == OS_SUCCESS", (long)actual); diff --git a/src/unit-test-coverage/shared/src/coveragetest-timebase.c b/src/unit-test-coverage/shared/src/coveragetest-timebase.c index bfde8cb2e..6239ffd71 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-timebase.c +++ b/src/unit-test-coverage/shared/src/coveragetest-timebase.c @@ -189,21 +189,16 @@ void Test_OS_TimeBaseGetInfo(void) * Test Case For: * int32 OS_TimeBaseGetInfo (uint32 timebase_id, OS_timebase_prop_t *timebase_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_timebase_prop_t timebase_prop; - osal_index_t local_index = UT_INDEX_1; - OS_common_record_t utrec; - OS_common_record_t *rptr = &utrec; - - memset(&utrec, 0, sizeof(utrec)); - utrec.creator = UT_OBJID_OTHER; - utrec.name_entry = "ABC"; + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + OS_timebase_prop_t timebase_prop; + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_TIMEBASE, UT_INDEX_1, "ABC", UT_OBJID_OTHER); + OS_timebase_table[1].nominal_interval_time = 2222; OS_timebase_table[1].freerun_time = 3333; OS_timebase_table[1].accuracy_usec = 4444; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &rptr, sizeof(rptr), false); + actual = OS_TimeBaseGetInfo(UT_OBJID_1, &timebase_prop); UtAssert_True(actual == expected, "OS_TimeBaseGetInfo() (%ld) == OS_SUCCESS", (long)actual); @@ -247,13 +242,11 @@ void Test_OS_TimeBase_CallbackThread(void) * Test Case For: * void OS_TimeBase_CallbackThread(uint32 timebase_id) */ - OS_common_record_t fake_record; - OS_common_record_t *recptr = &fake_record; - osal_index_t local_index; + OS_common_record_t *recptr; - local_index = UT_INDEX_2; - memset(&fake_record, 0, sizeof(fake_record)); - fake_record.active_id = UT_OBJID_2; + recptr = &OS_global_timebase_table[2]; + memset(recptr, 0, sizeof(*recptr)); + recptr->active_id = UT_OBJID_2; OS_timebase_table[2].external_sync = UT_TimerSync; OS_timecb_table[0].wait_time = 2000; @@ -261,19 +254,17 @@ void Test_OS_TimeBase_CallbackThread(void) TimerSyncCount = 0; TimerSyncRetVal = 0; TimeCB = 0; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &recptr, sizeof(recptr), false); + OS_UT_SetupTestTargetIndex(OS_OBJECT_TYPE_OS_TIMEBASE, UT_INDEX_2); UT_SetHookFunction(UT_KEY(OS_TimeBaseLock_Impl), ClearObjectsHook, recptr); OS_TimeBase_CallbackThread(UT_OBJID_2); UtAssert_True(TimerSyncCount == 11, "TimerSyncCount (%lu) == 11", (unsigned long)TimerSyncCount); UT_ResetState(UT_KEY(OS_TimeBaseLock_Impl)); - TimerSyncCount = 0; - TimerSyncRetVal = 1000; - fake_record.active_id = UT_OBJID_2; - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &local_index, sizeof(local_index), false); - UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &recptr, sizeof(recptr), false); + TimerSyncCount = 0; + TimerSyncRetVal = 1000; + recptr->active_id = UT_OBJID_2; + OS_UT_SetupTestTargetIndex(OS_OBJECT_TYPE_OS_TIMEBASE, UT_INDEX_2); UT_SetHookFunction(UT_KEY(OS_TimeBaseLock_Impl), ClearObjectsHook, recptr); OS_TimeBase_CallbackThread(UT_OBJID_2); diff --git a/src/unit-test-coverage/shared/src/os-shared-coverage-support.c b/src/unit-test-coverage/shared/src/os-shared-coverage-support.c new file mode 100644 index 000000000..4d105dc82 --- /dev/null +++ b/src/unit-test-coverage/shared/src/os-shared-coverage-support.c @@ -0,0 +1,113 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file os-shared-coverage-support.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ +#include "os-shared-coveragetest.h" +#include "os-shared-idmap.h" +#include "os-shared-common.h" + +void OS_UT_SetupIterator(osal_objtype_t obj_type, osal_index_t first_idx, osal_index_t num_entries) +{ + OS_object_token_t tokenlist[num_entries]; + osal_index_t idx = OSAL_INDEX_C(0); + + while (idx < num_entries) + { + tokenlist[idx].lock_mode = OS_LOCK_MODE_NONE; + tokenlist[idx].obj_type = obj_type; + tokenlist[idx].obj_idx = first_idx + idx; + tokenlist[idx].obj_id = OS_ObjectIdFromInteger((obj_type << OS_OBJECT_TYPE_SHIFT) | tokenlist[idx].obj_idx); + ++idx; + } + + UT_SetDataBuffer(UT_KEY(OS_ObjectIdIteratorGetNext), tokenlist, sizeof(OS_object_token_t) * num_entries, true); +} + +void OS_UT_SetupTestTargetIndex(osal_objtype_t obj_type, osal_index_t test_idx) +{ + OS_object_token_t token; + + token.lock_mode = OS_LOCK_MODE_NONE; + token.obj_type = obj_type; + token.obj_idx = test_idx; + token.obj_id = OS_ObjectIdFromInteger((obj_type << OS_OBJECT_TYPE_SHIFT) | test_idx); + + UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &token, sizeof(OS_object_token_t), true); +} + +void OS_UT_SetupBasicInfoTest(osal_objtype_t obj_type, osal_index_t test_idx, const char *name, osal_id_t creator) +{ + OS_common_record_t *rptr; + + switch (obj_type) + { + case OS_OBJECT_TYPE_OS_TASK: + rptr = OS_global_task_table; + break; + case OS_OBJECT_TYPE_OS_QUEUE: + rptr = OS_global_queue_table; + break; + case OS_OBJECT_TYPE_OS_BINSEM: + rptr = OS_global_bin_sem_table; + break; + case OS_OBJECT_TYPE_OS_COUNTSEM: + rptr = OS_global_count_sem_table; + break; + case OS_OBJECT_TYPE_OS_MUTEX: + rptr = OS_global_mutex_table; + break; + case OS_OBJECT_TYPE_OS_CONSOLE: + rptr = OS_global_console_table; + break; + case OS_OBJECT_TYPE_OS_MODULE: + rptr = OS_global_module_table; + break; + case OS_OBJECT_TYPE_OS_FILESYS: + rptr = OS_global_filesys_table; + break; + case OS_OBJECT_TYPE_OS_TIMEBASE: + rptr = OS_global_timebase_table; + break; + case OS_OBJECT_TYPE_OS_TIMECB: + rptr = OS_global_timecb_table; + break; + case OS_OBJECT_TYPE_OS_STREAM: + rptr = OS_global_stream_table; + break; + case OS_OBJECT_TYPE_OS_DIR: + rptr = OS_global_dir_table; + break; + default: + rptr = NULL; + break; + } + + rptr += test_idx; + memset(rptr, 0, sizeof(*rptr)); + rptr->creator = UT_OBJID_OTHER; + rptr->name_entry = "ABC"; + + OS_UT_SetupTestTargetIndex(obj_type, test_idx); +} diff --git a/src/unit-test-coverage/shared/src/os-shared-coveragetest.h b/src/unit-test-coverage/shared/src/os-shared-coveragetest.h index 55397f6fb..59144c01f 100644 --- a/src/unit-test-coverage/shared/src/os-shared-coveragetest.h +++ b/src/unit-test-coverage/shared/src/os-shared-coveragetest.h @@ -78,6 +78,31 @@ typedef union #define UT_INDEX_1 OSAL_INDEX_C(1) #define UT_INDEX_2 OSAL_INDEX_C(2) +/* + * Set up an coverage test iterator of the given type. + * + * The OS_ObjectIdIteratorGetNext() stub routine will be configured + * to return the given range of IDs. + */ +void OS_UT_SetupIterator(osal_objtype_t obj_type, osal_index_t first_idx, osal_index_t num_entries); + +/* + * Set up the UT stubs for the target entry of the next test case. + * + * This configures the OS_ObjectIdGetById() stub to return a token + * that refers to the given entry index. + */ +void OS_UT_SetupTestTargetIndex(osal_objtype_t obj_type, osal_index_t test_idx); + +/* + * Set up the UT stubs for a "get info" test. + * + * This sets up a single entry in the global table with the given name and + * ID value. It also configures the OS_ObjectIdGetById() stub to return a + * token that refers to the same table entry. + */ +void OS_UT_SetupBasicInfoTest(osal_objtype_t obj_type, osal_index_t test_idx, const char *name, osal_id_t creator); + /* * Setup function prior to every test */ diff --git a/src/ut-stubs/osapi-utstub-idmap.c b/src/ut-stubs/osapi-utstub-idmap.c index 594c4812f..3526f98e5 100644 --- a/src/ut-stubs/osapi-utstub-idmap.c +++ b/src/ut-stubs/osapi-utstub-idmap.c @@ -39,6 +39,17 @@ #include "utstub-helpers.h" #include "os-shared-idmap.h" +/* + * UT Helper function to create a fake object lock token + */ +static void UT_TokenCompose(uint32 lock_mode, uint32 indx, UT_ObjType_t objtype, OS_object_token_t *token) +{ + token->lock_mode = lock_mode; + token->obj_type = objtype; + token->obj_idx = indx; + UT_ObjIdCompose(indx, objtype, &token->obj_id); +} + UT_DEFAULT_STUB(OS_ObjectIdInit, (void)) /* Lock/Unlock for global tables */ @@ -117,22 +128,44 @@ int32 OS_ObjectIdToArrayIndex(osal_objtype_t idtype, osal_id_t id, osal_index_t return Status; } +/***************************************************************************** + * + * Stub function for OS_ObjectIdGlobalFromToken() + * + *****************************************************************************/ +OS_common_record_t *OS_ObjectIdGlobalFromToken(const OS_object_token_t *token) +{ + static OS_common_record_t fake_record; + int32 status; + OS_common_record_t * recptr; + + status = UT_DEFAULT_IMPL(OS_ObjectIdGlobalFromToken); + if (status == 0 && + UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGlobalFromToken), &recptr, sizeof(recptr)) < sizeof(recptr)) + { + /* This function should never return null */ + recptr = &fake_record; + } + + return recptr; +} + /***************************************************************************** * * Stub function for OS_ObjectIdFinalize() * *****************************************************************************/ -int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_common_record_t *record, osal_id_t *outid) +int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_object_token_t *token, osal_id_t *outid) { int32 Status; Status = UT_DEFAULT_IMPL_RC(OS_ObjectIdFinalizeNew, operation_status); /* need to actually write something to the output buffer */ - if (Status == OS_SUCCESS && record != NULL && outid != NULL && + if (Status == OS_SUCCESS && token != NULL && outid != NULL && UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdFinalizeNew), outid, sizeof(*outid)) < sizeof(*outid)) { - *outid = record->active_id; + *outid = token->obj_id; } return Status; @@ -143,7 +176,7 @@ int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_common_record_t *record, * Stub function for OS_ObjectIdFinalizeDelete() * *****************************************************************************/ -int32 OS_ObjectIdFinalizeDelete(int32 operation_status, OS_common_record_t *record) +int32 OS_ObjectIdFinalizeDelete(int32 operation_status, OS_object_token_t *token) { int32 Status; @@ -158,10 +191,9 @@ int32 OS_ObjectIdFinalizeDelete(int32 operation_status, OS_common_record_t *reco * *****************************************************************************/ int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg, - OS_common_record_t **record) + OS_object_token_t *token) { - int32 Status; - static OS_common_record_t fake_record; + int32 Status; /* by default this stub should return NAME_NOT_FOUND * unless the test case has set up otherwise. To set @@ -170,12 +202,10 @@ int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS */ Status = UT_DEFAULT_IMPL(OS_ObjectIdGetBySearch); - if (Status == OS_SUCCESS && record != NULL && - UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetBySearch), record, sizeof(*record)) < sizeof(*record)) + if (Status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetBySearch), token, sizeof(*token)) < sizeof(*token)) { - memset(&fake_record, 0, sizeof(fake_record)); - UT_ObjIdCompose(1, idtype, &fake_record.active_id); - *record = &fake_record; + UT_TokenCompose(lock_mode, 1, idtype, token); } return Status; @@ -183,7 +213,7 @@ int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS /***************************************************************************** * - * Stub function for OS_ObjectIdFindByName(, &fake_record.active_id) + * Stub function for OS_ObjectIdFindByName() * *****************************************************************************/ int32 OS_ObjectIdFindByName(osal_objtype_t idtype, const char *name, osal_id_t *object_id) @@ -208,33 +238,19 @@ int32 OS_ObjectIdFindByName(osal_objtype_t idtype, const char *name, osal_id_t * /***************************************************************************** * - * Stub function for OS_ObjectIdGetByName(,object_id) + * Stub function for OS_ObjectIdGetByName() * *****************************************************************************/ -int32 OS_ObjectIdGetByName(OS_lock_mode_t lock_mode, osal_objtype_t idtype, const char *name, - OS_common_record_t **record) +int32 OS_ObjectIdGetByName(OS_lock_mode_t lock_mode, osal_objtype_t idtype, const char *name, OS_object_token_t *token) { - int32 Status; - OS_common_record_t * local_record; - static OS_common_record_t fake_record; + int32 Status; Status = UT_DEFAULT_IMPL(OS_ObjectIdGetByName); - if (Status == 0) + if (Status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetByName), token, sizeof(*token)) < sizeof(*token)) { - if (UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetByName), &local_record, sizeof(local_record)) < - sizeof(local_record)) - { - memset(&fake_record, 0, sizeof(fake_record)); - local_record = &fake_record; - UT_ObjIdCompose(1, idtype, &fake_record.active_id); - } - - /* this needs to output something valid or code will break */ - if (record != NULL) - { - *record = local_record; - } + UT_TokenCompose(lock_mode, 1, idtype, token); } return Status; @@ -242,45 +258,18 @@ int32 OS_ObjectIdGetByName(OS_lock_mode_t lock_mode, osal_objtype_t idtype, cons /***************************************************************************** * - * Stub function for OS_ObjectIdGetById(, &fake_record.active_id) + * Stub function for OS_ObjectIdGetById() * *****************************************************************************/ -int32 OS_ObjectIdGetById(OS_lock_mode_t check_mode, osal_objtype_t idtype, osal_id_t id, osal_index_t *array_index, - OS_common_record_t **record) +int32 OS_ObjectIdGetById(OS_lock_mode_t lock_mode, osal_objtype_t idtype, osal_id_t id, OS_object_token_t *token) { - int32 Status; - uint32 tempserial; - osal_index_t local_id; - UT_ObjType_t checktype; - OS_common_record_t * local_record; - static OS_common_record_t fake_record; + int32 Status; Status = UT_DEFAULT_IMPL(OS_ObjectIdGetById); - if (Status == 0) + if (Status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetById), token, sizeof(*token)) < sizeof(*token)) { - if (UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetById), &local_id, sizeof(local_id)) < sizeof(local_id)) - { - UT_ObjIdDecompose(id, &tempserial, &checktype); - local_id = OSAL_INDEX_C(tempserial); - } - - if (UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetById), &local_record, sizeof(local_record)) < sizeof(local_record)) - { - memset(&fake_record, 0, sizeof(fake_record)); - fake_record.active_id = id; - local_record = &fake_record; - } - - /* this needs to output something valid or code will break */ - if (array_index != NULL) - { - *array_index = local_id; - } - if (record != NULL) - { - *record = local_record; - } + UT_TokenCompose(lock_mode, OS_ObjectIdToInteger(id) & 0xFFFF, idtype, token); } return Status; @@ -288,16 +277,31 @@ int32 OS_ObjectIdGetById(OS_lock_mode_t check_mode, osal_objtype_t idtype, osal_ /***************************************************************************** * - * Stub function for OS_ObjectIdRefcountDecr() + * Stub function for OS_ObjectIdRelease() + * + *****************************************************************************/ +void OS_ObjectIdRelease(OS_object_token_t *token) +{ + UT_DEFAULT_IMPL(OS_ObjectIdRelease); +} + +/***************************************************************************** + * + * Stub function for OS_ObjectIdTransferToken() * *****************************************************************************/ -int32 OS_ObjectIdRefcountDecr(OS_common_record_t *record) +void OS_ObjectIdTransferToken(OS_object_token_t *token_from, OS_object_token_t *token_to) { int32 Status; - Status = UT_DEFAULT_IMPL(OS_ObjectIdRefcountDecr); + Status = UT_DEFAULT_IMPL(OS_ObjectIdTransferToken); - return Status; + if (Status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdTransferToken), token_to, sizeof(*token_to)) < sizeof(*token_to)) + { + /* just copy it if nothing specified */ + *token_to = *token_from; + } } /***************************************************************************** @@ -352,36 +356,19 @@ int32 OS_ObjectIdGetNext(osal_objtype_t idtype, uint32 *curr_index, OS_common_re /***************************************************************************** * - * Stub function for OS_ObjectIdAllocateNew(, &fake_record.active_id) + * Stub function for OS_ObjectIdAllocateNew() * *****************************************************************************/ -int32 OS_ObjectIdAllocateNew(osal_objtype_t idtype, const char *name, osal_index_t *array_index, - OS_common_record_t **record) +int32 OS_ObjectIdAllocateNew(osal_objtype_t idtype, const char *name, OS_object_token_t *token) { - int32 Status; - osal_index_t local_id; - OS_common_record_t * local_record; - static OS_common_record_t fake_record; + int32 Status; Status = UT_DEFAULT_IMPL(OS_ObjectIdAllocateNew); - if (Status == 0) + if (Status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdAllocateNew), token, sizeof(*token)) < sizeof(*token)) { - if (UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdAllocateNew), &local_id, sizeof(local_id)) < sizeof(local_id)) - { - local_id = UT_GetStubCount(UT_KEY(OS_ObjectIdAllocateNew)) & 0xFFFF; - } - - if (UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdAllocateNew), &local_record, sizeof(local_record)) < - sizeof(local_record)) - { - memset(&fake_record, 0, sizeof(fake_record)); - UT_ObjIdCompose(local_id, idtype, &fake_record.active_id); - local_record = &fake_record; - } - - *record = local_record; - *array_index = local_id; + UT_TokenCompose(OS_LOCK_MODE_GLOBAL, UT_GetStubCount(UT_KEY(OS_ObjectIdAllocateNew)), idtype, token); } return Status; @@ -523,6 +510,77 @@ void OS_ForEachObject(osal_id_t creator_id, OS_ArgCallback_t callback_ptr, void } } +int32 OS_ObjectIdIteratorInit(OS_ObjectMatchFunc_t matchfunc, void *matcharg, osal_objtype_t objtype, + OS_object_iter_t *iter) +{ + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIteratorInit), matchfunc); + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIteratorInit), matcharg); + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIteratorInit), objtype); + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIteratorInit), iter); + + int32 Status; + + Status = UT_DEFAULT_IMPL_RC(OS_ObjectIdIteratorInit, 1); + + if (Status == 1 && UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdIteratorGetNext), iter, sizeof(*iter)) < sizeof(*iter)) + { + memset(iter, 0, sizeof(*iter)); + Status = OS_SUCCESS; + } + + return Status; +} + +int32 OS_ObjectIdIterateActive(osal_objtype_t objtype, OS_object_iter_t *iter) +{ + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIterateActive), objtype); + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIterateActive), iter); + + int32 Status; + + Status = UT_DEFAULT_IMPL_RC(OS_ObjectIdIterateActive, 1); + + if (Status == 1 && UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdIterateActive), iter, sizeof(*iter)) < sizeof(*iter)) + { + memset(iter, 0, sizeof(*iter)); + Status = OS_SUCCESS; + } + + return Status; +} + +bool OS_ObjectIdIteratorGetNext(OS_object_iter_t *iter) +{ + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIteratorGetNext), iter); + + int32 Status; + + Status = UT_DEFAULT_IMPL_RC(OS_ObjectIdIteratorGetNext, -1); + + if (Status == -1) + { + /* if test case has registered something, return true, otherwise return false */ + Status = (UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdIteratorGetNext), &iter->token, sizeof(iter->token)) == + sizeof(iter->token)); + } + + return (bool)Status; +} + +void OS_ObjectIdIteratorDestroy(OS_object_iter_t *iter) +{ + UT_DEFAULT_IMPL(OS_ObjectIdIteratorDestroy); +} + +int32 OS_ObjectIdIteratorProcessEntry(OS_object_iter_t *iter, int32 (*func)(osal_id_t)) +{ + int32 Status; + + Status = UT_DEFAULT_IMPL(OS_ObjectIdIteratorProcessEntry); + + return Status; +} + /*--------------------------------------------------------------------------------------- Name: OS_IdentifyObject From f9d508d82f7c2fd12d5f69d8a00adb181e4a1a51 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 1 Dec 2020 09:09:19 -0500 Subject: [PATCH 05/11] Fix #648, rename internal fields for consistency Use a variable name that matches the type of resource being accessed, rather than just "local". In particular this is important for readability of timecb and timebase code where functions need often need to access both types of objects at the same time. This also updates filesys code to match. --- src/os/shared/src/osapi-filesys.c | 100 +++++++++++++++--------------- src/os/shared/src/osapi-time.c | 82 ++++++++++++------------ 2 files changed, 91 insertions(+), 91 deletions(-) diff --git a/src/os/shared/src/osapi-filesys.c b/src/os/shared/src/osapi-filesys.c index 711ef7fb5..d791c7d05 100644 --- a/src/os/shared/src/osapi-filesys.c +++ b/src/os/shared/src/osapi-filesys.c @@ -76,17 +76,17 @@ const char OS_FILESYS_RAMDISK_VOLNAME_PREFIX[] = "RAM"; *-----------------------------------------------------------------*/ bool OS_FileSys_FindVirtMountPoint(void *ref, osal_index_t local_id, const OS_common_record_t *obj) { - OS_filesys_internal_record_t *rec = &OS_filesys_table[local_id]; - const char * target = (const char *)ref; + OS_filesys_internal_record_t *filesys = &OS_filesys_table[local_id]; + const char * target = (const char *)ref; size_t mplen; - if ((rec->flags & OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL) == 0) + if ((filesys->flags & OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL) == 0) { return false; } - mplen = strlen(rec->virtual_mountpt); - return (mplen > 0 && strncmp(target, rec->virtual_mountpt, mplen) == 0 && + mplen = strlen(filesys->virtual_mountpt); + return (mplen > 0 && strncmp(target, filesys->virtual_mountpt, mplen) == 0 && (target[mplen] == '/' || target[mplen] == 0)); } /* end OS_FileSys_FindVirtMountPoint */ @@ -104,7 +104,7 @@ bool OS_FileSys_FindVirtMountPoint(void *ref, osal_index_t local_id, const OS_co int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fsvolname, size_t blocksize, osal_blockcount_t numblocks, bool should_format) { - OS_filesys_internal_record_t *local; + OS_filesys_internal_record_t *filesys; int32 return_code; OS_object_token_t token; @@ -123,7 +123,7 @@ int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fs } /* check names are not excessively long strings */ - if (strlen(fsdevname) >= sizeof(local->device_name) || strlen(fsvolname) >= sizeof(local->volume_name)) + if (strlen(fsdevname) >= sizeof(filesys->device_name) || strlen(fsvolname) >= sizeof(filesys->volume_name)) { return OS_FS_ERR_PATH_TOO_LONG; } @@ -131,17 +131,17 @@ int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fs return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, fsdevname, &token); if (return_code == OS_SUCCESS) { - local = OS_OBJECT_TABLE_GET(OS_filesys_table, token); + filesys = OS_OBJECT_TABLE_GET(OS_filesys_table, token); /* Reset the table entry and save the name */ - OS_OBJECT_INIT(token, local, device_name, fsdevname); + OS_OBJECT_INIT(token, filesys, device_name, fsdevname); /* populate the VolumeName and BlockSize ahead of the Impl call, * so the implementation can reference this info if necessary */ - local->blocksize = blocksize; - local->numblocks = numblocks; - local->address = address; - strcpy(local->volume_name, fsvolname); + filesys->blocksize = blocksize; + filesys->numblocks = numblocks; + filesys->address = address; + strcpy(filesys->volume_name, fsvolname); /* * Determine basic type of filesystem, if not already known @@ -150,11 +150,11 @@ int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fs * contains the string "RAM" then it is a RAM disk. Otherwise * leave the type as UNKNOWN and let the implementation decide. */ - if (local->fstype == OS_FILESYS_TYPE_UNKNOWN && - (local->address != NULL || strncmp(local->volume_name, OS_FILESYS_RAMDISK_VOLNAME_PREFIX, - sizeof(OS_FILESYS_RAMDISK_VOLNAME_PREFIX) - 1) == 0)) + if (filesys->fstype == OS_FILESYS_TYPE_UNKNOWN && + (filesys->address != NULL || strncmp(filesys->volume_name, OS_FILESYS_RAMDISK_VOLNAME_PREFIX, + sizeof(OS_FILESYS_RAMDISK_VOLNAME_PREFIX) - 1) == 0)) { - local->fstype = OS_FILESYS_TYPE_VOLATILE_DISK; + filesys->fstype = OS_FILESYS_TYPE_VOLATILE_DISK; } return_code = OS_FileSysStartVolume_Impl(OS_ObjectIndexFromToken(&token)); @@ -172,7 +172,7 @@ int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fs if (return_code == OS_SUCCESS) { - local->flags |= OS_FILESYS_FLAG_IS_READY; + filesys->flags |= OS_FILESYS_FLAG_IS_READY; } else { @@ -224,7 +224,7 @@ int32 OS_FileSysAPI_Init(void) *-----------------------------------------------------------------*/ int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const char *virt_path) { - OS_filesys_internal_record_t *local; + OS_filesys_internal_record_t *filesys; int32 return_code; OS_object_token_t token; const char * dev_name; @@ -263,20 +263,20 @@ int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, dev_name, &token); if (return_code == OS_SUCCESS) { - local = OS_OBJECT_TABLE_GET(OS_filesys_table, token); + filesys = OS_OBJECT_TABLE_GET(OS_filesys_table, token); /* Reset the table entry and save the name */ - OS_OBJECT_INIT(token, local, device_name, dev_name); + OS_OBJECT_INIT(token, filesys, device_name, dev_name); - strncpy(local->volume_name, dev_name, sizeof(local->volume_name) - 1); - strncpy(local->system_mountpt, phys_path, sizeof(local->system_mountpt) - 1); - strncpy(local->virtual_mountpt, virt_path, sizeof(local->virtual_mountpt) - 1); + strncpy(filesys->volume_name, dev_name, sizeof(filesys->volume_name) - 1); + strncpy(filesys->system_mountpt, phys_path, sizeof(filesys->system_mountpt) - 1); + strncpy(filesys->virtual_mountpt, virt_path, sizeof(filesys->virtual_mountpt) - 1); /* * mark the entry that it is a fixed disk */ - local->fstype = OS_FILESYS_TYPE_FS_BASED; - local->flags = OS_FILESYS_FLAG_IS_FIXED; + filesys->fstype = OS_FILESYS_TYPE_FS_BASED; + filesys->flags = OS_FILESYS_FLAG_IS_FIXED; /* * The "mount" implementation is required as it will @@ -286,7 +286,7 @@ int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const if (return_code == OS_SUCCESS) { - local->flags |= OS_FILESYS_FLAG_IS_READY; + filesys->flags |= OS_FILESYS_FLAG_IS_READY; return_code = OS_FileSysMountVolume_Impl(OS_ObjectIndexFromToken(&token)); } @@ -295,7 +295,7 @@ int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const /* * mark the entry that it is a fixed disk */ - local->flags |= OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; + filesys->flags |= OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; } /* Check result, finalize record, and unlock global table. */ @@ -424,7 +424,7 @@ int32 OS_mount(const char *devname, const char *mountpoint) { int32 return_code; OS_object_token_t token; - OS_filesys_internal_record_t *local; + OS_filesys_internal_record_t *filesys; /* Check parameters */ if (devname == NULL || mountpoint == NULL) @@ -432,7 +432,7 @@ int32 OS_mount(const char *devname, const char *mountpoint) return OS_INVALID_POINTER; } - if (strlen(devname) >= sizeof(local->device_name) || strlen(mountpoint) >= sizeof(local->virtual_mountpt)) + if (strlen(devname) >= sizeof(filesys->device_name) || strlen(mountpoint) >= sizeof(filesys->virtual_mountpt)) { return OS_FS_ERR_PATH_TOO_LONG; } @@ -440,7 +440,7 @@ int32 OS_mount(const char *devname, const char *mountpoint) return_code = OS_ObjectIdGetByName(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, devname, &token); if (return_code == OS_SUCCESS) { - local = OS_OBJECT_TABLE_GET(OS_filesys_table, token); + filesys = OS_OBJECT_TABLE_GET(OS_filesys_table, token); /* * READY flag should be set (mkfs/initfs must have been called on this FS) @@ -449,12 +449,12 @@ int32 OS_mount(const char *devname, const char *mountpoint) * FIXED flag _should_ always be unset (these don't support mount/unmount) * but to support abstraction this is not enforced. */ - if ((local->flags & ~OS_FILESYS_FLAG_IS_FIXED) != OS_FILESYS_FLAG_IS_READY) + if ((filesys->flags & ~OS_FILESYS_FLAG_IS_FIXED) != OS_FILESYS_FLAG_IS_READY) { /* mount() cannot be used on this file system at this time */ return_code = OS_ERR_INCORRECT_OBJ_STATE; } - else if (local->system_mountpt[0] == 0) + else if (filesys->system_mountpt[0] == 0) { /* * The system mount point should be a non-empty string. @@ -470,8 +470,8 @@ int32 OS_mount(const char *devname, const char *mountpoint) { /* mark as mounted in the local table. * For now this does both sides (system and virtual) */ - local->flags |= OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; - strcpy(local->virtual_mountpt, mountpoint); + filesys->flags |= OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; + strcpy(filesys->virtual_mountpt, mountpoint); } OS_ObjectIdRelease(&token); @@ -498,7 +498,7 @@ int32 OS_unmount(const char *mountpoint) { int32 return_code; OS_object_token_t token; - OS_filesys_internal_record_t *local; + OS_filesys_internal_record_t *filesys; /* Check parameters */ if (mountpoint == NULL) @@ -506,7 +506,7 @@ int32 OS_unmount(const char *mountpoint) return OS_INVALID_POINTER; } - if (strlen(mountpoint) >= sizeof(local->virtual_mountpt)) + if (strlen(mountpoint) >= sizeof(filesys->virtual_mountpt)) { return OS_FS_ERR_PATH_TOO_LONG; } @@ -516,7 +516,7 @@ int32 OS_unmount(const char *mountpoint) if (return_code == OS_SUCCESS) { - local = OS_OBJECT_TABLE_GET(OS_filesys_table, token); + filesys = OS_OBJECT_TABLE_GET(OS_filesys_table, token); /* * FIXED flag should always be unset (these don't support mount/unmount at all) @@ -525,7 +525,7 @@ int32 OS_unmount(const char *mountpoint) * * The FIXED flag is not enforced to support abstraction. */ - if ((local->flags & ~OS_FILESYS_FLAG_IS_FIXED) != + if ((filesys->flags & ~OS_FILESYS_FLAG_IS_FIXED) != (OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL)) { /* unmount() cannot be used on this file system at this time */ @@ -540,7 +540,7 @@ int32 OS_unmount(const char *mountpoint) { /* mark as mounted in the local table. * For now this does both sides (system and virtual) */ - local->flags &= ~(OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL); + filesys->flags &= ~(OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL); } OS_ObjectIdRelease(&token); @@ -706,7 +706,7 @@ int32 OS_FS_GetPhysDriveName(char *PhysDriveName, const char *MountPoint) { OS_object_token_t token; int32 return_code; - OS_filesys_internal_record_t *local; + OS_filesys_internal_record_t *filesys; if (MountPoint == NULL || PhysDriveName == NULL) { @@ -724,11 +724,11 @@ int32 OS_FS_GetPhysDriveName(char *PhysDriveName, const char *MountPoint) if (return_code == OS_SUCCESS) { - local = OS_OBJECT_TABLE_GET(OS_filesys_table, token); + filesys = OS_OBJECT_TABLE_GET(OS_filesys_table, token); - if ((local->flags & OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM) != 0) + if ((filesys->flags & OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM) != 0) { - strncpy(PhysDriveName, local->system_mountpt, OS_FS_PHYS_NAME_LEN - 1); + strncpy(PhysDriveName, filesys->system_mountpt, OS_FS_PHYS_NAME_LEN - 1); PhysDriveName[OS_FS_PHYS_NAME_LEN - 1] = 0; } else @@ -811,7 +811,7 @@ int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath) OS_object_token_t token; int32 return_code; const char * name_ptr; - OS_filesys_internal_record_t *local; + OS_filesys_internal_record_t *filesys; size_t SysMountPointLen; size_t VirtPathLen; size_t VirtPathBegin; @@ -868,15 +868,15 @@ int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath) } else { - local = OS_OBJECT_TABLE_GET(OS_filesys_table, token); + filesys = OS_OBJECT_TABLE_GET(OS_filesys_table, token); - if ((local->flags & OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM) != 0) + if ((filesys->flags & OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM) != 0) { - SysMountPointLen = strlen(local->system_mountpt); - VirtPathBegin = strlen(local->virtual_mountpt); + SysMountPointLen = strlen(filesys->system_mountpt); + VirtPathBegin = strlen(filesys->virtual_mountpt); if (SysMountPointLen < OS_MAX_LOCAL_PATH_LEN) { - memcpy(LocalPath, local->system_mountpt, SysMountPointLen); + memcpy(LocalPath, filesys->system_mountpt, SysMountPointLen); } } else diff --git a/src/os/shared/src/osapi-time.c b/src/os/shared/src/osapi-time.c index ea52e2490..ed79e9bca 100644 --- a/src/os/shared/src/osapi-time.c +++ b/src/os/shared/src/osapi-time.c @@ -94,7 +94,7 @@ static int32 OS_DoTimerAdd(osal_id_t *timer_id, const char *timer_name, osal_id_ osal_objtype_t objtype; OS_object_token_t timebase_token; OS_object_token_t timecb_token; - OS_timecb_internal_record_t * local; + OS_timecb_internal_record_t * timecb; OS_timebase_internal_record_t *timebase; osal_id_t cb_list; osal_index_t attach_id; @@ -150,24 +150,24 @@ static int32 OS_DoTimerAdd(osal_id_t *timer_id, const char *timer_name, osal_id_ return_code = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_TIMECB, timer_name, &timecb_token); if (return_code == OS_SUCCESS) { - local = OS_OBJECT_TABLE_GET(OS_timecb_table, timecb_token); + timecb = OS_OBJECT_TABLE_GET(OS_timecb_table, timecb_token); timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, timebase_token); /* Reset the table entry and save the name */ - OS_OBJECT_INIT(timecb_token, local, timer_name, timer_name); + OS_OBJECT_INIT(timecb_token, timecb, timer_name, timer_name); /* * transfer ownership so the refcount obtained earlier is now * associated with the timecb object, and will be retained until * the object is deleted. */ - OS_ObjectIdTransferToken(&timebase_token, &local->timebase_token); + OS_ObjectIdTransferToken(&timebase_token, &timecb->timebase_token); - local->callback_ptr = callback_ptr; - local->callback_arg = callback_arg; - local->flags = flags; - local->prev_ref = OS_ObjectIndexFromToken(&timecb_token); - local->next_ref = OS_ObjectIndexFromToken(&timecb_token); + timecb->callback_ptr = callback_ptr; + timecb->callback_arg = callback_arg; + timecb->flags = flags; + timecb->prev_ref = OS_ObjectIndexFromToken(&timecb_token); + timecb->next_ref = OS_ObjectIndexFromToken(&timecb_token); /* * Now we need to add it to the time base callback ring, so take the @@ -181,10 +181,10 @@ static int32 OS_DoTimerAdd(osal_id_t *timer_id, const char *timer_name, osal_id_ if (OS_ObjectIdDefined(cb_list)) { OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_TIMECB, cb_list, &attach_id); - local->next_ref = attach_id; - local->prev_ref = OS_timecb_table[attach_id].prev_ref; - OS_timecb_table[local->prev_ref].next_ref = OS_ObjectIndexFromToken(&timecb_token); - OS_timecb_table[local->next_ref].prev_ref = OS_ObjectIndexFromToken(&timecb_token); + timecb->next_ref = attach_id; + timecb->prev_ref = OS_timecb_table[attach_id].prev_ref; + OS_timecb_table[timecb->prev_ref].next_ref = OS_ObjectIndexFromToken(&timecb_token); + OS_timecb_table[timecb->next_ref].prev_ref = OS_ObjectIndexFromToken(&timecb_token); } OS_TimeBaseUnlock_Impl(OS_ObjectIndexFromToken(&timebase_token)); @@ -316,7 +316,7 @@ int32 OS_TimerCreate(osal_id_t *timer_id, const char *timer_name, uint32 *accura *-----------------------------------------------------------------*/ int32 OS_TimerSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time) { - OS_timecb_internal_record_t *local; + OS_timecb_internal_record_t *timecb; int32 return_code; osal_objtype_t objtype; osal_id_t dedicated_timebase_id; @@ -347,19 +347,19 @@ int32 OS_TimerSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time) return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_TIMECB, timer_id, &token); if (return_code == OS_SUCCESS) { - local = OS_OBJECT_TABLE_GET(OS_timecb_table, token); + timecb = OS_OBJECT_TABLE_GET(OS_timecb_table, token); - OS_TimeBaseLock_Impl(OS_ObjectIndexFromToken(&local->timebase_token)); + OS_TimeBaseLock_Impl(OS_ObjectIndexFromToken(&timecb->timebase_token)); - if ((local->flags & TIMECB_FLAG_DEDICATED_TIMEBASE) != 0) + if ((timecb->flags & TIMECB_FLAG_DEDICATED_TIMEBASE) != 0) { - dedicated_timebase_id = OS_ObjectIdFromToken(&local->timebase_token); + dedicated_timebase_id = OS_ObjectIdFromToken(&timecb->timebase_token); } - local->wait_time = (int32)start_time; - local->interval_time = (int32)interval_time; + timecb->wait_time = (int32)start_time; + timecb->interval_time = (int32)interval_time; - OS_TimeBaseUnlock_Impl(OS_ObjectIndexFromToken(&local->timebase_token)); + OS_TimeBaseUnlock_Impl(OS_ObjectIndexFromToken(&timecb->timebase_token)); OS_ObjectIdRelease(&token); } @@ -394,13 +394,13 @@ int32 OS_TimerSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time) *-----------------------------------------------------------------*/ int32 OS_TimerDelete(osal_id_t timer_id) { - OS_timecb_internal_record_t * local; int32 return_code; osal_objtype_t objtype; osal_id_t dedicated_timebase_id; - OS_object_token_t token; - OS_timebase_internal_record_t *timebase_local; + OS_object_token_t timecb_token; OS_object_token_t timebase_token; + OS_timebase_internal_record_t *timebase; + OS_timecb_internal_record_t * timecb; dedicated_timebase_id = OS_OBJECT_ID_UNDEFINED; memset(&timebase_token, 0, sizeof(timebase_token)); @@ -415,51 +415,51 @@ int32 OS_TimerDelete(osal_id_t timer_id) return OS_ERR_INCORRECT_OBJ_STATE; } - return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_TIMECB, timer_id, &token); + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_TIMECB, timer_id, &timecb_token); if (return_code == OS_SUCCESS) { - local = OS_OBJECT_TABLE_GET(OS_timecb_table, token); - timebase_local = OS_OBJECT_TABLE_GET(OS_timebase_table, local->timebase_token); + timecb = OS_OBJECT_TABLE_GET(OS_timecb_table, timecb_token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, timecb->timebase_token); - OS_ObjectIdTransferToken(&local->timebase_token, &timebase_token); + OS_ObjectIdTransferToken(&timecb->timebase_token, &timebase_token); - OS_TimeBaseLock_Impl(OS_ObjectIndexFromToken(&local->timebase_token)); + OS_TimeBaseLock_Impl(OS_ObjectIndexFromToken(&timecb->timebase_token)); /* * If the timer uses a dedicated time base, then also delete that. */ - if ((local->flags & TIMECB_FLAG_DEDICATED_TIMEBASE) != 0) + if ((timecb->flags & TIMECB_FLAG_DEDICATED_TIMEBASE) != 0) { - dedicated_timebase_id = OS_ObjectIdFromToken(&local->timebase_token); + dedicated_timebase_id = OS_ObjectIdFromToken(&timecb->timebase_token); } /* * Now we need to remove it from the time base callback ring */ - if (OS_ObjectIdEqual(timebase_local->first_cb, timer_id)) + if (OS_ObjectIdEqual(timebase->first_cb, timer_id)) { - if (local->next_ref != OS_ObjectIndexFromToken(&token)) + if (timecb->next_ref != OS_ObjectIndexFromToken(&timecb_token)) { - OS_ObjectIdCompose_Impl(OS_OBJECT_TYPE_OS_TIMEBASE, local->next_ref, &timebase_local->first_cb); + OS_ObjectIdCompose_Impl(OS_OBJECT_TYPE_OS_TIMEBASE, timecb->next_ref, &timebase->first_cb); } else { /* * consider the list empty */ - timebase_local->first_cb = OS_OBJECT_ID_UNDEFINED; + timebase->first_cb = OS_OBJECT_ID_UNDEFINED; } } - OS_timecb_table[local->prev_ref].next_ref = local->next_ref; - OS_timecb_table[local->next_ref].prev_ref = local->prev_ref; - local->next_ref = OS_ObjectIndexFromToken(&token); - local->prev_ref = OS_ObjectIndexFromToken(&token); + OS_timecb_table[timecb->prev_ref].next_ref = timecb->next_ref; + OS_timecb_table[timecb->next_ref].prev_ref = timecb->prev_ref; + timecb->next_ref = OS_ObjectIndexFromToken(&timecb_token); + timecb->prev_ref = OS_ObjectIndexFromToken(&timecb_token); - OS_TimeBaseUnlock_Impl(OS_ObjectIndexFromToken(&local->timebase_token)); + OS_TimeBaseUnlock_Impl(OS_ObjectIndexFromToken(&timecb->timebase_token)); /* Complete the operation via the common routine */ - return_code = OS_ObjectIdFinalizeDelete(return_code, &token); + return_code = OS_ObjectIdFinalizeDelete(return_code, &timecb_token); } /* From ffb098de6917ecc302b64dbff53d791ea498b58f Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 1 Dec 2020 21:28:58 -0500 Subject: [PATCH 06/11] Fix #648, sanitize array refs on impl layer Pass token objects to impl layers to identify the object to operate on, rather than the index. The token has extra information including the original/actual object ID - which matters if the ID might change as part of the operation (e.g. new/delete). --- src/os/portable/os-impl-bsd-select.c | 24 +-- src/os/portable/os-impl-bsd-sockets.c | 157 ++++++++++-------- src/os/portable/os-impl-console-bsp.c | 5 +- src/os/portable/os-impl-no-loader.c | 6 +- src/os/portable/os-impl-no-shell.c | 2 +- src/os/portable/os-impl-posix-dirs.c | 37 +++-- src/os/portable/os-impl-posix-dl-loader.c | 33 ++-- src/os/portable/os-impl-posix-dl-symtab.c | 10 +- src/os/portable/os-impl-posix-files.c | 16 +- src/os/portable/os-impl-posix-io.c | 59 ++++--- src/os/posix/src/os-impl-binsem.c | 42 +++-- src/os/posix/src/os-impl-console.c | 38 +++-- src/os/posix/src/os-impl-countsem.c | 53 ++++-- src/os/posix/src/os-impl-filesys.c | 27 +-- src/os/posix/src/os-impl-mutex.c | 56 ++++--- src/os/posix/src/os-impl-queues.c | 62 ++++--- src/os/posix/src/os-impl-shell.c | 17 +- src/os/posix/src/os-impl-tasks.c | 57 ++++--- src/os/posix/src/os-impl-timebase.c | 56 ++++--- src/os/rtems/inc/os-impl-io.h | 4 +- src/os/rtems/src/os-impl-binsem.c | 63 ++++--- src/os/rtems/src/os-impl-console.c | 39 +++-- src/os/rtems/src/os-impl-countsem.c | 54 +++--- src/os/rtems/src/os-impl-files.c | 2 +- src/os/rtems/src/os-impl-filesys.c | 49 ++++-- src/os/rtems/src/os-impl-loader.c | 29 ++-- src/os/rtems/src/os-impl-mutex.c | 42 +++-- src/os/rtems/src/os-impl-queues.c | 67 +++++--- src/os/rtems/src/os-impl-tasks.c | 67 +++++--- src/os/rtems/src/os-impl-timebase.c | 75 +++++---- src/os/shared/inc/os-shared-binsem.h | 14 +- src/os/shared/inc/os-shared-countsem.h | 12 +- src/os/shared/inc/os-shared-dir.h | 8 +- src/os/shared/inc/os-shared-file.h | 12 +- src/os/shared/inc/os-shared-filesys.h | 16 +- src/os/shared/inc/os-shared-idmap.h | 4 +- src/os/shared/inc/os-shared-module.h | 8 +- src/os/shared/inc/os-shared-mutex.h | 10 +- src/os/shared/inc/os-shared-printf.h | 6 +- src/os/shared/inc/os-shared-queue.h | 10 +- src/os/shared/inc/os-shared-select.h | 2 +- src/os/shared/inc/os-shared-shell.h | 2 +- src/os/shared/inc/os-shared-sockets.h | 18 +- src/os/shared/inc/os-shared-task.h | 12 +- src/os/shared/inc/os-shared-timebase.h | 12 +- src/os/shared/src/osapi-binsem.c | 14 +- src/os/shared/src/osapi-countsem.c | 12 +- src/os/shared/src/osapi-dir.c | 8 +- src/os/shared/src/osapi-file.c | 11 +- src/os/shared/src/osapi-filesys.c | 30 ++-- src/os/shared/src/osapi-idmap.c | 8 +- src/os/shared/src/osapi-module.c | 8 +- src/os/shared/src/osapi-mutex.c | 10 +- src/os/shared/src/osapi-printf.c | 4 +- src/os/shared/src/osapi-queue.c | 8 +- src/os/shared/src/osapi-select.c | 2 +- src/os/shared/src/osapi-shell.c | 2 +- src/os/shared/src/osapi-sockets.c | 25 +-- src/os/shared/src/osapi-task.c | 10 +- src/os/shared/src/osapi-time.c | 12 +- src/os/shared/src/osapi-timebase.c | 20 +-- src/os/vxworks/inc/os-vxworks.h | 2 +- src/os/vxworks/src/os-impl-binsem.c | 57 +++++-- src/os/vxworks/src/os-impl-console.c | 44 +++-- src/os/vxworks/src/os-impl-countsem.c | 49 ++++-- src/os/vxworks/src/os-impl-dirs.c | 38 +++-- src/os/vxworks/src/os-impl-filesys.c | 48 ++++-- src/os/vxworks/src/os-impl-loader.c | 38 +++-- src/os/vxworks/src/os-impl-mutex.c | 38 +++-- src/os/vxworks/src/os-impl-queues.c | 53 ++++-- src/os/vxworks/src/os-impl-shell.c | 25 +-- src/os/vxworks/src/os-impl-symtab.c | 5 +- src/os/vxworks/src/os-impl-tasks.c | 71 ++++---- src/os/vxworks/src/os-impl-timebase.c | 115 +++++++------ .../portable/src/coveragetest-bsd-select.c | 18 +- .../portable/src/coveragetest-console-bsp.c | 12 +- .../portable/src/coveragetest-posix-files.c | 15 +- .../portable/src/coveragetest-posix-io.c | 49 ++++-- .../shared/src/coveragetest-filesys.c | 33 ++-- .../shared/src/coveragetest-idmap.c | 2 +- .../shared/src/coveragetest-sockets.c | 12 +- .../shared/src/os-shared-coverage-support.c | 1 + .../ut-stubs/src/osapi-binsem-impl-stubs.c | 14 +- .../ut-stubs/src/osapi-console-impl-stubs.c | 4 +- .../ut-stubs/src/osapi-countsem-impl-stubs.c | 12 +- .../ut-stubs/src/osapi-file-impl-stubs.c | 20 +-- .../ut-stubs/src/osapi-filesys-impl-stubs.c | 14 +- .../ut-stubs/src/osapi-loader-impl-stubs.c | 8 +- .../ut-stubs/src/osapi-mutex-impl-stubs.c | 10 +- .../ut-stubs/src/osapi-network-impl-stubs.c | 18 +- .../ut-stubs/src/osapi-queue-impl-stubs.c | 10 +- .../ut-stubs/src/osapi-select-impl-stubs.c | 2 +- .../ut-stubs/src/osapi-task-impl-stubs.c | 14 +- .../ut-stubs/src/osapi-timer-impl-stubs.c | 13 +- .../src/portable-console-bsp-impl-stubs.c | 2 +- .../vxworks/adaptors/inc/ut-adaptor-tasks.h | 2 +- .../adaptors/inc/ut-adaptor-timebase.h | 2 +- .../vxworks/adaptors/src/ut-adaptor-tasks.c | 4 +- .../adaptors/src/ut-adaptor-timebase.c | 4 +- .../vxworks/src/coveragetest-binsem.c | 38 +++-- .../vxworks/src/coveragetest-console.c | 20 ++- .../vxworks/src/coveragetest-countsem.c | 28 +++- .../vxworks/src/coveragetest-dirs.c | 21 ++- .../vxworks/src/coveragetest-filesys.c | 64 ++++--- .../vxworks/src/coveragetest-loader.c | 21 ++- .../vxworks/src/coveragetest-mutex.c | 22 ++- .../vxworks/src/coveragetest-queues.c | 47 +++--- .../vxworks/src/coveragetest-shell.c | 9 +- .../vxworks/src/coveragetest-symtab.c | 11 +- .../vxworks/src/coveragetest-tasks.c | 45 +++-- .../vxworks/src/coveragetest-timebase.c | 46 +++-- .../vxworks/src/os-vxworks-coveragetest.h | 16 ++ 112 files changed, 1727 insertions(+), 1117 deletions(-) diff --git a/src/os/portable/os-impl-bsd-select.c b/src/os/portable/os-impl-bsd-select.c index 29c677f36..afe500527 100644 --- a/src/os/portable/os-impl-bsd-select.c +++ b/src/os/portable/os-impl-bsd-select.c @@ -45,6 +45,7 @@ #include #include "os-impl-select.h" #include "os-shared-select.h" +#include "os-shared-idmap.h" /**************************************************************************************** DEFINES @@ -249,17 +250,20 @@ static int32 OS_DoSelect(int maxfd, fd_set *rd_set, fd_set *wr_set, int32 msecs) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_SelectSingle_Impl(osal_index_t stream_id, uint32 *SelectFlags, int32 msecs) +int32 OS_SelectSingle_Impl(const OS_object_token_t *token, uint32 *SelectFlags, int32 msecs) { - int32 return_code; - fd_set wr_set; - fd_set rd_set; + int32 return_code; + fd_set wr_set; + fd_set rd_set; + OS_impl_file_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); /* * If called on a stream_id which does not support this * operation, return immediately and do not invoke the system call */ - if (!OS_impl_filehandle_table[stream_id].selectable) + if (!impl->selectable) { return OS_ERR_OPERATION_NOT_SUPPORTED; } @@ -270,22 +274,22 @@ int32 OS_SelectSingle_Impl(osal_index_t stream_id, uint32 *SelectFlags, int32 ms FD_ZERO(&rd_set); if (*SelectFlags & OS_STREAM_STATE_READABLE) { - FD_SET(OS_impl_filehandle_table[stream_id].fd, &rd_set); + FD_SET(impl->fd, &rd_set); } if (*SelectFlags & OS_STREAM_STATE_WRITABLE) { - FD_SET(OS_impl_filehandle_table[stream_id].fd, &wr_set); + FD_SET(impl->fd, &wr_set); } - return_code = OS_DoSelect(OS_impl_filehandle_table[stream_id].fd, &rd_set, &wr_set, msecs); + return_code = OS_DoSelect(impl->fd, &rd_set, &wr_set, msecs); if (return_code == OS_SUCCESS) { - if (!FD_ISSET(OS_impl_filehandle_table[stream_id].fd, &rd_set)) + if (!FD_ISSET(impl->fd, &rd_set)) { *SelectFlags &= ~OS_STREAM_STATE_READABLE; } - if (!FD_ISSET(OS_impl_filehandle_table[stream_id].fd, &wr_set)) + if (!FD_ISSET(impl->fd, &wr_set)) { *SelectFlags &= ~OS_STREAM_STATE_WRITABLE; } diff --git a/src/os/portable/os-impl-bsd-sockets.c b/src/os/portable/os-impl-bsd-sockets.c index 655dc0287..31ca3e911 100644 --- a/src/os/portable/os-impl-bsd-sockets.c +++ b/src/os/portable/os-impl-bsd-sockets.c @@ -57,6 +57,7 @@ #include "os-shared-file.h" #include "os-shared-select.h" #include "os-shared-sockets.h" +#include "os-shared-idmap.h" /**************************************************************************************** DEFINES @@ -84,16 +85,21 @@ typedef union * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_SocketOpen_Impl(osal_index_t sock_id) +int32 OS_SocketOpen_Impl(const OS_object_token_t *token) { - int os_domain; - int os_type; - int os_proto; - int os_flags; + int os_domain; + int os_type; + int os_proto; + int os_flags; + OS_impl_file_internal_record_t *impl; + OS_stream_internal_record_t * stream; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); + stream = OS_OBJECT_TABLE_GET(OS_stream_table, *token); os_proto = 0; - switch (OS_stream_table[sock_id].socket_type) + switch (stream->socket_type) { case OS_SocketType_DATAGRAM: os_type = SOCK_DGRAM; @@ -106,7 +112,7 @@ int32 OS_SocketOpen_Impl(osal_index_t sock_id) return OS_ERR_NOT_IMPLEMENTED; } - switch (OS_stream_table[sock_id].socket_domain) + switch (stream->socket_domain) { case OS_SocketDomain_INET: os_domain = AF_INET; @@ -120,11 +126,11 @@ int32 OS_SocketOpen_Impl(osal_index_t sock_id) return OS_ERR_NOT_IMPLEMENTED; } - switch (OS_stream_table[sock_id].socket_domain) + switch (stream->socket_domain) { case OS_SocketDomain_INET: case OS_SocketDomain_INET6: - switch (OS_stream_table[sock_id].socket_type) + switch (stream->socket_type) { case OS_SocketType_DATAGRAM: os_proto = IPPROTO_UDP; @@ -140,8 +146,8 @@ int32 OS_SocketOpen_Impl(osal_index_t sock_id) break; } - OS_impl_filehandle_table[sock_id].fd = socket(os_domain, os_type, os_proto); - if (OS_impl_filehandle_table[sock_id].fd < 0) + impl->fd = socket(os_domain, os_type, os_proto); + if (impl->fd < 0) { return OS_ERROR; } @@ -151,18 +157,18 @@ int32 OS_SocketOpen_Impl(osal_index_t sock_id) * code restarts. However if setting the option fails then it is not worth bailing out over. */ os_flags = 1; - setsockopt(OS_impl_filehandle_table[sock_id].fd, SOL_SOCKET, SO_REUSEADDR, &os_flags, sizeof(os_flags)); + setsockopt(impl->fd, SOL_SOCKET, SO_REUSEADDR, &os_flags, sizeof(os_flags)); /* * Set the standard options on the filehandle by default -- * this may set it to non-blocking mode if the implementation supports it. * any blocking would be done explicitly via the select() wrappers */ - os_flags = fcntl(OS_impl_filehandle_table[sock_id].fd, F_GETFL); + os_flags = fcntl(impl->fd, F_GETFL); os_flags |= OS_IMPL_SOCKET_FLAGS; - fcntl(OS_impl_filehandle_table[sock_id].fd, F_SETFL, os_flags); + fcntl(impl->fd, F_SETFL, os_flags); - OS_impl_filehandle_table[sock_id].selectable = ((os_flags & O_NONBLOCK) != 0); + impl->selectable = ((os_flags & O_NONBLOCK) != 0); return OS_SUCCESS; } /* end OS_SocketOpen_Impl */ @@ -175,11 +181,16 @@ int32 OS_SocketOpen_Impl(osal_index_t sock_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_SocketBind_Impl(osal_index_t sock_id, const OS_SockAddr_t *Addr) +int32 OS_SocketBind_Impl(const OS_object_token_t *token, const OS_SockAddr_t *Addr) { - int os_result; - socklen_t addrlen; - const struct sockaddr *sa; + int os_result; + socklen_t addrlen; + const struct sockaddr * sa; + OS_impl_file_internal_record_t *impl; + OS_stream_internal_record_t * stream; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); + stream = OS_OBJECT_TABLE_GET(OS_stream_table, *token); sa = (const struct sockaddr *)&Addr->AddrData; @@ -203,7 +214,7 @@ int32 OS_SocketBind_Impl(osal_index_t sock_id, const OS_SockAddr_t *Addr) return OS_ERR_BAD_ADDRESS; } - os_result = bind(OS_impl_filehandle_table[sock_id].fd, sa, addrlen); + os_result = bind(impl->fd, sa, addrlen); if (os_result < 0) { OS_DEBUG("bind: %s\n", strerror(errno)); @@ -211,9 +222,9 @@ int32 OS_SocketBind_Impl(osal_index_t sock_id, const OS_SockAddr_t *Addr) } /* Start listening on the socket (implied for stream sockets) */ - if (OS_stream_table[sock_id].socket_type == OS_SocketType_STREAM) + if (stream->socket_type == OS_SocketType_STREAM) { - os_result = listen(OS_impl_filehandle_table[sock_id].fd, 10); + os_result = listen(impl->fd, 10); if (os_result < 0) { OS_DEBUG("listen: %s\n", strerror(errno)); @@ -231,14 +242,17 @@ int32 OS_SocketBind_Impl(osal_index_t sock_id, const OS_SockAddr_t *Addr) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_SocketConnect_Impl(osal_index_t sock_id, const OS_SockAddr_t *Addr, int32 timeout) +int32 OS_SocketConnect_Impl(const OS_object_token_t *token, const OS_SockAddr_t *Addr, int32 timeout) { - int32 return_code; - int os_status; - int sockopt; - socklen_t slen; - uint32 operation; - const struct sockaddr *sa; + int32 return_code; + int os_status; + int sockopt; + socklen_t slen; + uint32 operation; + const struct sockaddr * sa; + OS_impl_file_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); sa = (const struct sockaddr *)&Addr->AddrData; switch (sa->sa_family) @@ -263,7 +277,7 @@ int32 OS_SocketConnect_Impl(osal_index_t sock_id, const OS_SockAddr_t *Addr, int else { return_code = OS_SUCCESS; - os_status = connect(OS_impl_filehandle_table[sock_id].fd, sa, slen); + os_status = connect(impl->fd, sa, slen); if (os_status < 0) { if (errno != EINPROGRESS) @@ -273,9 +287,9 @@ int32 OS_SocketConnect_Impl(osal_index_t sock_id, const OS_SockAddr_t *Addr, int else { operation = OS_STREAM_STATE_WRITABLE; - if (OS_impl_filehandle_table[sock_id].selectable) + if (impl->selectable) { - return_code = OS_SelectSingle_Impl(sock_id, &operation, timeout); + return_code = OS_SelectSingle_Impl(token, &operation, timeout); } if (return_code == OS_SUCCESS) { @@ -285,10 +299,9 @@ int32 OS_SocketConnect_Impl(osal_index_t sock_id, const OS_SockAddr_t *Addr, int } else { - sockopt = 0; - slen = sizeof(sockopt); - os_status = - getsockopt(OS_impl_filehandle_table[sock_id].fd, SOL_SOCKET, SO_ERROR, &sockopt, &slen); + sockopt = 0; + slen = sizeof(sockopt); + os_status = getsockopt(impl->fd, SOL_SOCKET, SO_ERROR, &sockopt, &slen); if (os_status < 0 || sockopt != 0) { return_code = OS_ERROR; @@ -309,17 +322,23 @@ int32 OS_SocketConnect_Impl(osal_index_t sock_id, const OS_SockAddr_t *Addr, int * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_SocketAccept_Impl(osal_index_t sock_id, osal_index_t connsock_id, OS_SockAddr_t *Addr, int32 timeout) +int32 OS_SocketAccept_Impl(const OS_object_token_t *sock_token, const OS_object_token_t *conn_token, + OS_SockAddr_t *Addr, int32 timeout) { - int32 return_code; - uint32 operation; - socklen_t addrlen; - int os_flags; + int32 return_code; + uint32 operation; + socklen_t addrlen; + int os_flags; + OS_impl_file_internal_record_t *sock_impl; + OS_impl_file_internal_record_t *conn_impl; + + sock_impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *sock_token); + conn_impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *conn_token); operation = OS_STREAM_STATE_READABLE; - if (OS_impl_filehandle_table[sock_id].selectable) + if (sock_impl->selectable) { - return_code = OS_SelectSingle_Impl(sock_id, &operation, timeout); + return_code = OS_SelectSingle_Impl(sock_token, &operation, timeout); } else { @@ -334,10 +353,9 @@ int32 OS_SocketAccept_Impl(osal_index_t sock_id, osal_index_t connsock_id, OS_So } else { - addrlen = Addr->ActualLength; - OS_impl_filehandle_table[connsock_id].fd = - accept(OS_impl_filehandle_table[sock_id].fd, (struct sockaddr *)&Addr->AddrData, &addrlen); - if (OS_impl_filehandle_table[connsock_id].fd < 0) + addrlen = Addr->ActualLength; + conn_impl->fd = accept(sock_impl->fd, (struct sockaddr *)&Addr->AddrData, &addrlen); + if (conn_impl->fd < 0) { return_code = OS_ERROR; } @@ -350,11 +368,11 @@ int32 OS_SocketAccept_Impl(osal_index_t sock_id, osal_index_t connsock_id, OS_So * this may set it to non-blocking mode if the implementation supports it. * any blocking would be done explicitly via the select() wrappers */ - os_flags = fcntl(OS_impl_filehandle_table[connsock_id].fd, F_GETFL); + os_flags = fcntl(conn_impl->fd, F_GETFL); os_flags |= OS_IMPL_SOCKET_FLAGS; - fcntl(OS_impl_filehandle_table[connsock_id].fd, F_SETFL, os_flags); + fcntl(conn_impl->fd, F_SETFL, os_flags); - OS_impl_filehandle_table[connsock_id].selectable = ((os_flags & O_NONBLOCK) != 0); + conn_impl->selectable = ((os_flags & O_NONBLOCK) != 0); } } } @@ -370,15 +388,18 @@ int32 OS_SocketAccept_Impl(osal_index_t sock_id, osal_index_t connsock_id, OS_So * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_SocketRecvFrom_Impl(osal_index_t sock_id, void *buffer, size_t buflen, OS_SockAddr_t *RemoteAddr, +int32 OS_SocketRecvFrom_Impl(const OS_object_token_t *token, void *buffer, size_t buflen, OS_SockAddr_t *RemoteAddr, int32 timeout) { - int32 return_code; - int os_result; - int waitflags; - uint32 operation; - struct sockaddr *sa; - socklen_t addrlen; + int32 return_code; + int os_result; + int waitflags; + uint32 operation; + struct sockaddr * sa; + socklen_t addrlen; + OS_impl_file_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); if (RemoteAddr == NULL) { @@ -396,10 +417,10 @@ int32 OS_SocketRecvFrom_Impl(osal_index_t sock_id, void *buffer, size_t buflen, * If "O_NONBLOCK" flag is set then use select() * Note this is the only way to get a correct timeout */ - if (OS_impl_filehandle_table[sock_id].selectable) + if (impl->selectable) { waitflags = MSG_DONTWAIT; - return_code = OS_SelectSingle_Impl(sock_id, &operation, timeout); + return_code = OS_SelectSingle_Impl(token, &operation, timeout); } else { @@ -423,7 +444,7 @@ int32 OS_SocketRecvFrom_Impl(osal_index_t sock_id, void *buffer, size_t buflen, } else { - os_result = recvfrom(OS_impl_filehandle_table[sock_id].fd, buffer, buflen, waitflags, sa, &addrlen); + os_result = recvfrom(impl->fd, buffer, buflen, waitflags, sa, &addrlen); if (os_result < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) @@ -459,11 +480,15 @@ int32 OS_SocketRecvFrom_Impl(osal_index_t sock_id, void *buffer, size_t buflen, * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_SocketSendTo_Impl(osal_index_t sock_id, const void *buffer, size_t buflen, const OS_SockAddr_t *RemoteAddr) +int32 OS_SocketSendTo_Impl(const OS_object_token_t *token, const void *buffer, size_t buflen, + const OS_SockAddr_t *RemoteAddr) { - int os_result; - socklen_t addrlen; - const struct sockaddr *sa; + int os_result; + socklen_t addrlen; + const struct sockaddr * sa; + OS_impl_file_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); sa = (const struct sockaddr *)&RemoteAddr->AddrData; switch (sa->sa_family) @@ -486,7 +511,7 @@ int32 OS_SocketSendTo_Impl(osal_index_t sock_id, const void *buffer, size_t bufl return OS_ERR_BAD_ADDRESS; } - os_result = sendto(OS_impl_filehandle_table[sock_id].fd, buffer, buflen, MSG_DONTWAIT, sa, addrlen); + os_result = sendto(impl->fd, buffer, buflen, MSG_DONTWAIT, sa, addrlen); if (os_result < 0) { OS_DEBUG("sendto: %s\n", strerror(errno)); @@ -504,7 +529,7 @@ int32 OS_SocketSendTo_Impl(osal_index_t sock_id, const void *buffer, size_t bufl * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_SocketGetInfo_Impl(osal_index_t sock_id, OS_socket_prop_t *sock_prop) +int32 OS_SocketGetInfo_Impl(const OS_object_token_t *token, OS_socket_prop_t *sock_prop) { return OS_SUCCESS; } /* end OS_SocketGetInfo_Impl */ diff --git a/src/os/portable/os-impl-console-bsp.c b/src/os/portable/os-impl-console-bsp.c index 815c423d5..fc3d8290b 100644 --- a/src/os/portable/os-impl-console-bsp.c +++ b/src/os/portable/os-impl-console-bsp.c @@ -39,6 +39,7 @@ #include "os-impl-console.h" #include "os-shared-printf.h" +#include "os-shared-idmap.h" /**************************************************************************************** CONSOLE OUTPUT @@ -52,14 +53,14 @@ * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -void OS_ConsoleOutput_Impl(osal_index_t local_id) +void OS_ConsoleOutput_Impl(const OS_object_token_t *token) { size_t StartPos; size_t EndPos; size_t WriteSize; OS_console_internal_record_t *console; - console = &OS_console_table[local_id]; + console = OS_OBJECT_TABLE_GET(OS_console_table, *token); StartPos = console->ReadPos; EndPos = console->WritePos; while (StartPos != EndPos) diff --git a/src/os/portable/os-impl-no-loader.c b/src/os/portable/os-impl-no-loader.c index 046fe3419..dbed7b8e8 100644 --- a/src/os/portable/os-impl-no-loader.c +++ b/src/os/portable/os-impl-no-loader.c @@ -38,7 +38,7 @@ * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleLoad_Impl(osal_index_t module_id, const char *translated_path) +int32 OS_ModuleLoad_Impl(const OS_object_token_t *token, const char *translated_path) { return OS_ERR_NOT_IMPLEMENTED; @@ -52,7 +52,7 @@ int32 OS_ModuleLoad_Impl(osal_index_t module_id, const char *translated_path) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleUnload_Impl(osal_index_t module_id) +int32 OS_ModuleUnload_Impl(const OS_object_token_t *token) { return OS_ERR_NOT_IMPLEMENTED; @@ -66,7 +66,7 @@ int32 OS_ModuleUnload_Impl(osal_index_t module_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleGetInfo_Impl(osal_index_t module_id, OS_module_prop_t *module_prop) +int32 OS_ModuleGetInfo_Impl(const OS_object_token_t *token, OS_module_prop_t *module_prop) { return OS_ERR_NOT_IMPLEMENTED; diff --git a/src/os/portable/os-impl-no-shell.c b/src/os/portable/os-impl-no-shell.c index 5f86dc1af..77ca23208 100644 --- a/src/os/portable/os-impl-no-shell.c +++ b/src/os/portable/os-impl-no-shell.c @@ -34,7 +34,7 @@ * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ShellOutputToFile_Impl(osal_index_t file_id, const char *Cmd) +int32 OS_ShellOutputToFile_Impl(const OS_object_token_t *token, const char *Cmd) { return OS_ERR_NOT_IMPLEMENTED; } diff --git a/src/os/portable/os-impl-posix-dirs.c b/src/os/portable/os-impl-posix-dirs.c index e840ed089..05b246f6d 100644 --- a/src/os/portable/os-impl-posix-dirs.c +++ b/src/os/portable/os-impl-posix-dirs.c @@ -49,6 +49,7 @@ #include "os-impl-dirs.h" #include "os-shared-dir.h" +#include "os-shared-idmap.h" /**************************************************************************************** DEFINES @@ -104,14 +105,19 @@ int32 OS_DirCreate_Impl(const char *local_path, uint32 access) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_DirOpen_Impl(osal_index_t local_id, const char *local_path) +int32 OS_DirOpen_Impl(const OS_object_token_t *token, const char *local_path) { - DIR *dp = opendir(local_path); + DIR * dp = opendir(local_path); + OS_impl_dir_internal_record_t *impl; + if (dp == NULL) { return OS_ERROR; } - OS_impl_dir_table[local_id].dp = dp; + + impl = OS_OBJECT_TABLE_GET(OS_impl_dir_table, *token); + impl->dp = dp; + return OS_SUCCESS; } /* end OS_DirOpen_Impl */ @@ -123,10 +129,15 @@ int32 OS_DirOpen_Impl(osal_index_t local_id, const char *local_path) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_DirClose_Impl(osal_index_t local_id) +int32 OS_DirClose_Impl(const OS_object_token_t *token) { - closedir(OS_impl_dir_table[local_id].dp); - OS_impl_dir_table[local_id].dp = NULL; + OS_impl_dir_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_dir_table, *token); + + closedir(impl->dp); + impl->dp = NULL; + return OS_SUCCESS; } /* end OS_DirClose_Impl */ @@ -138,9 +149,11 @@ int32 OS_DirClose_Impl(osal_index_t local_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_DirRead_Impl(osal_index_t local_id, os_dirent_t *dirent) +int32 OS_DirRead_Impl(const OS_object_token_t *token, os_dirent_t *dirent) { - struct dirent *de; + struct dirent * de; + OS_impl_dir_internal_record_t *impl; + impl = OS_OBJECT_TABLE_GET(OS_impl_dir_table, *token); /* NOTE - the readdir() call is non-reentrant .... * However, this is performed while the global dir table lock is taken. @@ -151,7 +164,7 @@ int32 OS_DirRead_Impl(osal_index_t local_id, os_dirent_t *dirent) */ /* cppcheck-suppress readdirCalled */ /* cppcheck-suppress nonreentrantFunctionsreaddir */ - de = readdir(OS_impl_dir_table[local_id].dp); + de = readdir(impl->dp); if (de == NULL) { return OS_ERROR; @@ -171,9 +184,11 @@ int32 OS_DirRead_Impl(osal_index_t local_id, os_dirent_t *dirent) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_DirRewind_Impl(osal_index_t local_id) +int32 OS_DirRewind_Impl(const OS_object_token_t *token) { - rewinddir(OS_impl_dir_table[local_id].dp); + OS_impl_dir_internal_record_t *impl; + impl = OS_OBJECT_TABLE_GET(OS_impl_dir_table, *token); + rewinddir(impl->dp); return OS_SUCCESS; } /* end OS_DirRewind_Impl */ diff --git a/src/os/portable/os-impl-posix-dl-loader.c b/src/os/portable/os-impl-posix-dl-loader.c index 2a8036dcc..3843d5050 100644 --- a/src/os/portable/os-impl-posix-dl-loader.c +++ b/src/os/portable/os-impl-posix-dl-loader.c @@ -48,6 +48,7 @@ #include "os-impl-loader.h" #include "os-shared-module.h" +#include "os-shared-idmap.h" /**************************************************************************************** Module Loader API @@ -61,10 +62,15 @@ * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleLoad_Impl(osal_index_t module_id, const char *translated_path) +int32 OS_ModuleLoad_Impl(const OS_object_token_t *token, const char *translated_path) { - int32 status = OS_ERROR; - int dl_mode; + int32 status = OS_ERROR; + int dl_mode; + OS_impl_module_internal_record_t *impl; + OS_module_internal_record_t * module; + + impl = OS_OBJECT_TABLE_GET(OS_impl_module_table, *token); + module = OS_OBJECT_TABLE_GET(OS_module_table, *token); /* * RTLD_NOW should instruct dlopen() to resolve all the symbols in the @@ -74,7 +80,7 @@ int32 OS_ModuleLoad_Impl(osal_index_t module_id, const char *translated_path) */ dl_mode = RTLD_NOW; - if ((OS_module_table[module_id].flags & OS_MODULE_FLAG_LOCAL_SYMBOLS) != 0) + if ((module->flags & OS_MODULE_FLAG_LOCAL_SYMBOLS) != 0) { /* * Do not add the symbols in this module to the global symbol table. @@ -95,8 +101,8 @@ int32 OS_ModuleLoad_Impl(osal_index_t module_id, const char *translated_path) } dlerror(); - OS_impl_module_table[module_id].dl_handle = dlopen(translated_path, dl_mode); - if (OS_impl_module_table[module_id].dl_handle != NULL) + impl->dl_handle = dlopen(translated_path, dl_mode); + if (impl->dl_handle != NULL) { status = OS_SUCCESS; } @@ -117,18 +123,21 @@ int32 OS_ModuleLoad_Impl(osal_index_t module_id, const char *translated_path) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleUnload_Impl(osal_index_t module_id) +int32 OS_ModuleUnload_Impl(const OS_object_token_t *token) { - int32 status = OS_ERROR; + int32 status = OS_ERROR; + OS_impl_module_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_module_table, *token); /* ** Attempt to close/unload the module */ dlerror(); - if (dlclose(OS_impl_module_table[module_id].dl_handle) == 0) + if (dlclose(impl->dl_handle) == 0) { - OS_impl_module_table[module_id].dl_handle = NULL; - status = OS_SUCCESS; + impl->dl_handle = NULL; + status = OS_SUCCESS; } else { @@ -147,7 +156,7 @@ int32 OS_ModuleUnload_Impl(osal_index_t module_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleGetInfo_Impl(osal_index_t module_id, OS_module_prop_t *module_prop) +int32 OS_ModuleGetInfo_Impl(const OS_object_token_t *token, OS_module_prop_t *module_prop) { /* * Limiting strictly to POSIX-defined API means there is no defined diff --git a/src/os/portable/os-impl-posix-dl-symtab.c b/src/os/portable/os-impl-posix-dl-symtab.c index ff78c19d5..629ba8d8e 100644 --- a/src/os/portable/os-impl-posix-dl-symtab.c +++ b/src/os/portable/os-impl-posix-dl-symtab.c @@ -47,6 +47,7 @@ #include "os-impl-loader.h" #include "os-shared-module.h" +#include "os-shared-idmap.h" /**************************************************************************************** DEFINES @@ -157,11 +158,14 @@ int32 OS_GlobalSymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleSymbolLookup_Impl(osal_index_t local_id, cpuaddr *SymbolAddress, const char *SymbolName) +int32 OS_ModuleSymbolLookup_Impl(const OS_object_token_t *token, cpuaddr *SymbolAddress, const char *SymbolName) { - int32 status; + int32 status; + OS_impl_module_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_module_table, *token); - status = OS_GenericSymbolLookup_Impl(OS_impl_module_table[local_id].dl_handle, SymbolAddress, SymbolName); + status = OS_GenericSymbolLookup_Impl(impl->dl_handle, SymbolAddress, SymbolName); return status; diff --git a/src/os/portable/os-impl-posix-files.c b/src/os/portable/os-impl-posix-files.c index ba59fcba0..d46aa2142 100644 --- a/src/os/portable/os-impl-posix-files.c +++ b/src/os/portable/os-impl-posix-files.c @@ -46,6 +46,7 @@ #include "os-impl-files.h" #include "os-shared-file.h" +#include "os-shared-idmap.h" /**************************************************************************************** DEFINES @@ -63,10 +64,13 @@ * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileOpen_Impl(osal_index_t local_id, const char *local_path, int32 flags, int32 access) +int32 OS_FileOpen_Impl(const OS_object_token_t *token, const char *local_path, int32 flags, int32 access) { - int os_perm; - int os_mode; + int os_perm; + int os_mode; + OS_impl_file_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); /* ** Check for a valid access mode @@ -100,9 +104,9 @@ int32 OS_FileOpen_Impl(osal_index_t local_id, const char *local_path, int32 flag os_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; - OS_impl_filehandle_table[local_id].fd = open(local_path, os_perm, os_mode); + impl->fd = open(local_path, os_perm, os_mode); - if (OS_impl_filehandle_table[local_id].fd < 0) + if (impl->fd < 0) { OS_DEBUG("open(%s): %s\n", local_path, strerror(errno)); return OS_ERROR; @@ -112,7 +116,7 @@ int32 OS_FileOpen_Impl(osal_index_t local_id, const char *local_path, int32 flag * If the flags included O_NONBLOCK, then * enable the "select" call on this handle. */ - OS_impl_filehandle_table[local_id].selectable = ((os_perm & O_NONBLOCK) != 0); + impl->selectable = ((os_perm & O_NONBLOCK) != 0); return OS_SUCCESS; } /* end OS_FileOpen_Impl */ diff --git a/src/os/portable/os-impl-posix-io.c b/src/os/portable/os-impl-posix-io.c index 429e931b0..cabe43541 100644 --- a/src/os/portable/os-impl-posix-io.c +++ b/src/os/portable/os-impl-posix-io.c @@ -48,6 +48,7 @@ #include "os-impl-io.h" #include "os-shared-file.h" #include "os-shared-select.h" +#include "os-shared-idmap.h" /* some OS libraries (e.g. VxWorks) do not declare the API to be const-correct * It can still use this generic implementation but the call to write() must be @@ -66,11 +67,14 @@ * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_GenericClose_Impl(osal_index_t local_id) +int32 OS_GenericClose_Impl(const OS_object_token_t *token) { - int result; + int result; + OS_impl_file_internal_record_t *impl; - result = close(OS_impl_filehandle_table[local_id].fd); + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); + + result = close(impl->fd); if (result < 0) { /* @@ -86,7 +90,7 @@ int32 OS_GenericClose_Impl(osal_index_t local_id) */ OS_DEBUG("close: %s\n", strerror(errno)); } - OS_impl_filehandle_table[local_id].fd = -1; + impl->fd = -1; return OS_SUCCESS; } /* end OS_GenericClose_Impl */ @@ -98,11 +102,14 @@ int32 OS_GenericClose_Impl(osal_index_t local_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_GenericSeek_Impl(osal_index_t local_id, int32 offset, uint32 whence) +int32 OS_GenericSeek_Impl(const OS_object_token_t *token, int32 offset, uint32 whence) { - int where; - off_t os_result; - int32 retval; + int where; + off_t os_result; + int32 retval; + OS_impl_file_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); switch (whence) { @@ -119,7 +126,7 @@ int32 OS_GenericSeek_Impl(osal_index_t local_id, int32 offset, uint32 whence) return OS_ERROR; } - os_result = lseek(OS_impl_filehandle_table[local_id].fd, (off_t)offset, where); + os_result = lseek(impl->fd, (off_t)offset, where); if (os_result == (off_t)-1) { if (errno == ESPIPE) @@ -163,11 +170,14 @@ int32 OS_GenericSeek_Impl(osal_index_t local_id, int32 offset, uint32 whence) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_GenericRead_Impl(osal_index_t local_id, void *buffer, size_t nbytes, int32 timeout) +int32 OS_GenericRead_Impl(const OS_object_token_t *token, void *buffer, size_t nbytes, int32 timeout) { - int32 return_code; - ssize_t os_result; - uint32 operation; + int32 return_code; + ssize_t os_result; + uint32 operation; + OS_impl_file_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); return_code = OS_SUCCESS; @@ -183,14 +193,14 @@ int32 OS_GenericRead_Impl(osal_index_t local_id, void *buffer, size_t nbytes, in * * Note that a timeout will not work unless selectable is true. */ - if (OS_impl_filehandle_table[local_id].selectable) + if (impl->selectable) { - return_code = OS_SelectSingle_Impl(local_id, &operation, timeout); + return_code = OS_SelectSingle_Impl(token, &operation, timeout); } if (return_code == OS_SUCCESS && (operation & OS_STREAM_STATE_READABLE) != 0) { - os_result = read(OS_impl_filehandle_table[local_id].fd, buffer, nbytes); + os_result = read(impl->fd, buffer, nbytes); if (os_result < 0) { OS_DEBUG("read: %s\n", strerror(errno)); @@ -215,11 +225,14 @@ int32 OS_GenericRead_Impl(osal_index_t local_id, void *buffer, size_t nbytes, in * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_GenericWrite_Impl(osal_index_t local_id, const void *buffer, size_t nbytes, int32 timeout) +int32 OS_GenericWrite_Impl(const OS_object_token_t *token, const void *buffer, size_t nbytes, int32 timeout) { - int32 return_code; - ssize_t os_result; - uint32 operation; + int32 return_code; + ssize_t os_result; + uint32 operation; + OS_impl_file_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); return_code = OS_SUCCESS; @@ -235,16 +248,16 @@ int32 OS_GenericWrite_Impl(osal_index_t local_id, const void *buffer, size_t nby * * Note that a timeout will not work unless selectable is true. */ - if (OS_impl_filehandle_table[local_id].selectable) + if (impl->selectable) { - return_code = OS_SelectSingle_Impl(local_id, &operation, timeout); + return_code = OS_SelectSingle_Impl(token, &operation, timeout); } if (return_code == OS_SUCCESS && (operation & OS_STREAM_STATE_WRITABLE) != 0) { /* on some system libraries for which the write() argument is not * qualified correctly, it needs to be case to a void* here */ - os_result = write(OS_impl_filehandle_table[local_id].fd, GENERIC_IO_CONST_DATA_CAST buffer, nbytes); + os_result = write(impl->fd, GENERIC_IO_CONST_DATA_CAST buffer, nbytes); if (os_result < 0) { OS_DEBUG("write: %s\n", strerror(errno)); diff --git a/src/os/posix/src/os-impl-binsem.c b/src/os/posix/src/os-impl-binsem.c index 89227a2f4..fe86c4b8a 100644 --- a/src/os/posix/src/os-impl-binsem.c +++ b/src/os/posix/src/os-impl-binsem.c @@ -32,6 +32,7 @@ ***************************************************************************************/ #include "os-posix.h" +#include "os-shared-idmap.h" #include "os-shared-binsem.h" #include "os-impl-binsem.h" @@ -118,7 +119,7 @@ int32 OS_Posix_BinSemAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemCreate_Impl(osal_index_t sem_id, uint32 initial_value, uint32 options) +int32 OS_BinSemCreate_Impl(const OS_object_token_t *token, uint32 initial_value, uint32 options) { int ret; int attr_created; @@ -141,7 +142,7 @@ int32 OS_BinSemCreate_Impl(osal_index_t sem_id, uint32 initial_value, uint32 opt attr_created = 0; mutex_created = 0; cond_created = 0; - sem = &OS_impl_bin_sem_table[sem_id]; + sem = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); memset(sem, 0, sizeof(*sem)); do @@ -240,12 +241,12 @@ int32 OS_BinSemCreate_Impl(osal_index_t sem_id, uint32 initial_value, uint32 opt * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemDelete_Impl(osal_index_t sem_id) +int32 OS_BinSemDelete_Impl(const OS_object_token_t *token) { OS_impl_binsem_internal_record_t *sem; int32 return_code; - sem = &OS_impl_bin_sem_table[sem_id]; + sem = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); if (pthread_cond_destroy(&(sem->cv)) != 0) { @@ -279,11 +280,11 @@ int32 OS_BinSemDelete_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemGive_Impl(osal_index_t sem_id) +int32 OS_BinSemGive_Impl(const OS_object_token_t *token) { OS_impl_binsem_internal_record_t *sem; - sem = &OS_impl_bin_sem_table[sem_id]; + sem = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); /* * Note there is a possibility that another thread is concurrently taking this sem, @@ -324,11 +325,11 @@ int32 OS_BinSemGive_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemFlush_Impl(osal_index_t sem_id) +int32 OS_BinSemFlush_Impl(const OS_object_token_t *token) { OS_impl_binsem_internal_record_t *sem; - sem = &OS_impl_bin_sem_table[sem_id]; + sem = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); /* Lock the mutex ( not the table! ) */ if (OS_Posix_BinSemAcquireMutex(&sem->id) != OS_SUCCESS) @@ -358,10 +359,13 @@ int32 OS_BinSemFlush_Impl(osal_index_t sem_id) becomes nonzero (via SemGive) or the semaphore gets flushed. ---------------------------------------------------------------------------------------*/ -static int32 OS_GenericBinSemTake_Impl(OS_impl_binsem_internal_record_t *sem, const struct timespec *timeout) +static int32 OS_GenericBinSemTake_Impl(const OS_object_token_t *token, const struct timespec *timeout) { - sig_atomic_t flush_count; - int32 return_code; + sig_atomic_t flush_count; + int32 return_code; + OS_impl_binsem_internal_record_t *sem; + + sem = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); /* * Note - this lock should be quickly available - should not delay here. @@ -441,9 +445,9 @@ static int32 OS_GenericBinSemTake_Impl(OS_impl_binsem_internal_record_t *sem, co * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemTake_Impl(osal_index_t sem_id) +int32 OS_BinSemTake_Impl(const OS_object_token_t *token) { - return (OS_GenericBinSemTake_Impl(&OS_impl_bin_sem_table[sem_id], NULL)); + return (OS_GenericBinSemTake_Impl(token, NULL)); } /* end OS_BinSemTake_Impl */ /*---------------------------------------------------------------- @@ -454,7 +458,7 @@ int32 OS_BinSemTake_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemTimedWait_Impl(osal_index_t sem_id, uint32 msecs) +int32 OS_BinSemTimedWait_Impl(const OS_object_token_t *token, uint32 msecs) { struct timespec ts; @@ -463,7 +467,7 @@ int32 OS_BinSemTimedWait_Impl(osal_index_t sem_id, uint32 msecs) */ OS_Posix_CompAbsDelayTime(msecs, &ts); - return (OS_GenericBinSemTake_Impl(&OS_impl_bin_sem_table[sem_id], &ts)); + return (OS_GenericBinSemTake_Impl(token, &ts)); } /* end OS_BinSemTimedWait_Impl */ /*---------------------------------------------------------------- @@ -474,9 +478,13 @@ int32 OS_BinSemTimedWait_Impl(osal_index_t sem_id, uint32 msecs) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemGetInfo_Impl(osal_index_t sem_id, OS_bin_sem_prop_t *sem_prop) +int32 OS_BinSemGetInfo_Impl(const OS_object_token_t *token, OS_bin_sem_prop_t *sem_prop) { + OS_impl_binsem_internal_record_t *sem; + + sem = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); + /* put the info into the stucture */ - sem_prop->value = OS_impl_bin_sem_table[sem_id].current_value; + sem_prop->value = sem->current_value; return OS_SUCCESS; } /* end OS_BinSemGetInfo_Impl */ diff --git a/src/os/posix/src/os-impl-console.c b/src/os/posix/src/os-impl-console.c index be6197a6f..7ba6baa63 100644 --- a/src/os/posix/src/os-impl-console.c +++ b/src/os/posix/src/os-impl-console.c @@ -32,6 +32,7 @@ #include "os-posix.h" #include "os-impl-console.h" +#include "os-shared-idmap.h" #include "os-shared-printf.h" /* @@ -59,9 +60,11 @@ OS_impl_console_internal_record_t OS_impl_console_table[OS_MAX_CONSOLES]; * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -void OS_ConsoleWakeup_Impl(osal_index_t local_id) +void OS_ConsoleWakeup_Impl(const OS_object_token_t *token) { - OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; + OS_impl_console_internal_record_t *local; + + local = OS_OBJECT_TABLE_GET(OS_impl_console_table, *token); if (local->is_async) { @@ -71,7 +74,7 @@ void OS_ConsoleWakeup_Impl(osal_index_t local_id) else { /* output directly */ - OS_ConsoleOutput_Impl(local_id); + OS_ConsoleOutput_Impl(token); } } /* end OS_ConsoleWakeup_Impl */ @@ -87,13 +90,18 @@ static void *OS_ConsoleTask_Entry(void *arg) { OS_U32ValueWrapper_t local_arg; OS_impl_console_internal_record_t *local; + OS_object_token_t token; local_arg.opaque_arg = arg; - local = &OS_impl_console_table[local_arg.idx]; - while (true) + if (OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_CONSOLE, local_arg.id, &token) == OS_SUCCESS) { - OS_ConsoleOutput_Impl(local_arg.idx); - sem_wait(&local->data_sem); + local = OS_OBJECT_TABLE_GET(OS_impl_console_table, token); + while (true) + { + OS_ConsoleOutput_Impl(&token); + sem_wait(&local->data_sem); + } + OS_ObjectIdRelease(&token); } return NULL; } /* end OS_ConsoleTask_Entry */ @@ -106,33 +114,35 @@ static void *OS_ConsoleTask_Entry(void *arg) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ConsoleCreate_Impl(osal_index_t local_id) +int32 OS_ConsoleCreate_Impl(const OS_object_token_t *token) { - OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; + OS_impl_console_internal_record_t *local; pthread_t consoletask; int32 return_code; OS_U32ValueWrapper_t local_arg = {0}; - if (local_id == 0) + local = OS_OBJECT_TABLE_GET(OS_impl_console_table, *token); + + if (token->obj_idx == 0) { return_code = OS_SUCCESS; local->is_async = OS_CONSOLE_ASYNC; if (local->is_async) { - if (sem_init(&OS_impl_console_table[local_id].data_sem, 0, 0) < 0) + if (sem_init(&local->data_sem, 0, 0) < 0) { return_code = OS_SEM_FAILURE; } else { - local_arg.idx = local_id; - return_code = OS_Posix_InternalTaskCreate_Impl(&consoletask, OS_CONSOLE_TASK_PRIORITY, 0, + local_arg.id = OS_ObjectIdFromToken(token); + return_code = OS_Posix_InternalTaskCreate_Impl(&consoletask, OS_CONSOLE_TASK_PRIORITY, 0, OS_ConsoleTask_Entry, local_arg.opaque_arg); if (return_code != OS_SUCCESS) { - sem_destroy(&OS_impl_console_table[local_id].data_sem); + sem_destroy(&local->data_sem); } } } diff --git a/src/os/posix/src/os-impl-countsem.c b/src/os/posix/src/os-impl-countsem.c index d399e0857..dac78b6ab 100644 --- a/src/os/posix/src/os-impl-countsem.c +++ b/src/os/posix/src/os-impl-countsem.c @@ -32,6 +32,7 @@ #include "os-posix.h" #include "os-impl-countsem.h" #include "os-shared-countsem.h" +#include "os-shared-idmap.h" /* * Added SEM_VALUE_MAX Define @@ -74,14 +75,18 @@ int32 OS_Posix_CountSemAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemCreate_Impl(osal_index_t sem_id, uint32 sem_initial_value, uint32 options) +int32 OS_CountSemCreate_Impl(const OS_object_token_t *token, uint32 sem_initial_value, uint32 options) { + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); + if (sem_initial_value > SEM_VALUE_MAX) { return OS_INVALID_SEM_VALUE; } - if (sem_init(&OS_impl_count_sem_table[sem_id].id, 0, sem_initial_value) < 0) + if (sem_init(&impl->id, 0, sem_initial_value) < 0) { return OS_SEM_FAILURE; } @@ -98,9 +103,13 @@ int32 OS_CountSemCreate_Impl(osal_index_t sem_id, uint32 sem_initial_value, uint * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemDelete_Impl(osal_index_t sem_id) +int32 OS_CountSemDelete_Impl(const OS_object_token_t *token) { - if (sem_destroy(&OS_impl_count_sem_table[sem_id].id) < 0) + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); + + if (sem_destroy(&impl->id) < 0) { return OS_SEM_FAILURE; } @@ -117,9 +126,13 @@ int32 OS_CountSemDelete_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemGive_Impl(osal_index_t sem_id) +int32 OS_CountSemGive_Impl(const OS_object_token_t *token) { - if (sem_post(&OS_impl_count_sem_table[sem_id].id) < 0) + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); + + if (sem_post(&impl->id) < 0) { return OS_SEM_FAILURE; } @@ -136,9 +149,13 @@ int32 OS_CountSemGive_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemTake_Impl(osal_index_t sem_id) +int32 OS_CountSemTake_Impl(const OS_object_token_t *token) { - if (sem_wait(&OS_impl_count_sem_table[sem_id].id) < 0) + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); + + if (sem_wait(&impl->id) < 0) { return OS_SEM_FAILURE; } @@ -154,17 +171,20 @@ int32 OS_CountSemTake_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemTimedWait_Impl(osal_index_t sem_id, uint32 msecs) +int32 OS_CountSemTimedWait_Impl(const OS_object_token_t *token, uint32 msecs) { - struct timespec ts; - int result; + struct timespec ts; + int result; + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); /* ** Compute an absolute time for the delay */ OS_Posix_CompAbsDelayTime(msecs, &ts); - if (sem_timedwait(&OS_impl_count_sem_table[sem_id].id, &ts) == 0) + if (sem_timedwait(&impl->id, &ts) == 0) { result = OS_SUCCESS; } @@ -189,11 +209,14 @@ int32 OS_CountSemTimedWait_Impl(osal_index_t sem_id, uint32 msecs) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemGetInfo_Impl(osal_index_t sem_id, OS_count_sem_prop_t *count_prop) +int32 OS_CountSemGetInfo_Impl(const OS_object_token_t *token, OS_count_sem_prop_t *count_prop) { - int sval; + int sval; + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); - if (sem_getvalue(&OS_impl_count_sem_table[sem_id].id, &sval) < 0) + if (sem_getvalue(&impl->id, &sval) < 0) { return OS_SEM_FAILURE; } diff --git a/src/os/posix/src/os-impl-filesys.c b/src/os/posix/src/os-impl-filesys.c index 6e71e3321..4213b39ad 100644 --- a/src/os/posix/src/os-impl-filesys.c +++ b/src/os/posix/src/os-impl-filesys.c @@ -44,6 +44,7 @@ #include "os-posix.h" #include "os-shared-filesys.h" +#include "os-shared-idmap.h" /**************************************************************************************** DEFINES @@ -82,9 +83,9 @@ int32 OS_Posix_FileSysAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysStartVolume_Impl(osal_index_t filesys_id) +int32 OS_FileSysStartVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_filesys_internal_record_t *local; struct stat stat_buf; const char * tmpdir; uint32 i; @@ -97,6 +98,8 @@ int32 OS_FileSysStartVolume_Impl(osal_index_t filesys_id) VOLATILE_DISK_LOC_MAX }; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + /* * Determine basic type of filesystem, if not already known */ @@ -184,7 +187,7 @@ int32 OS_FileSysStartVolume_Impl(osal_index_t filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysStopVolume_Impl(osal_index_t filesys_id) +int32 OS_FileSysStopVolume_Impl(const OS_object_token_t *token) { /* * This is a no-op. @@ -207,7 +210,7 @@ int32 OS_FileSysStopVolume_Impl(osal_index_t filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysFormatVolume_Impl(osal_index_t filesys_id) +int32 OS_FileSysFormatVolume_Impl(const OS_object_token_t *token) { /* * In theory, this should wipe any existing files in the ramdisk, @@ -230,11 +233,13 @@ int32 OS_FileSysFormatVolume_Impl(osal_index_t filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysMountVolume_Impl(osal_index_t filesys_id) +int32 OS_FileSysMountVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_filesys_internal_record_t *local; struct stat stat_buf; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + /* * This will do a mkdir() for the mount point if it does * not already exist. @@ -282,7 +287,7 @@ int32 OS_FileSysMountVolume_Impl(osal_index_t filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysUnmountVolume_Impl(osal_index_t filesys_id) +int32 OS_FileSysUnmountVolume_Impl(const OS_object_token_t *token) { /* * NOTE: Mounting/Unmounting on POSIX is not implemented. @@ -303,11 +308,13 @@ int32 OS_FileSysUnmountVolume_Impl(osal_index_t filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysStatVolume_Impl(osal_index_t filesys_id, OS_statvfs_t *result) +int32 OS_FileSysStatVolume_Impl(const OS_object_token_t *token, OS_statvfs_t *result) { - OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_filesys_internal_record_t *local; struct statvfs stat_buf; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + if (statvfs(local->system_mountpt, &stat_buf) != 0) { return OS_ERROR; @@ -328,7 +335,7 @@ int32 OS_FileSysStatVolume_Impl(osal_index_t filesys_id, OS_statvfs_t *result) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysCheckVolume_Impl(osal_index_t filesys_id, bool repair) +int32 OS_FileSysCheckVolume_Impl(const OS_object_token_t *token, bool repair) { return OS_ERR_NOT_IMPLEMENTED; } /* end OS_FileSysCheckVolume_Impl */ diff --git a/src/os/posix/src/os-impl-mutex.c b/src/os/posix/src/os-impl-mutex.c index 8d6de200a..5a0e43593 100644 --- a/src/os/posix/src/os-impl-mutex.c +++ b/src/os/posix/src/os-impl-mutex.c @@ -31,6 +31,7 @@ #include "os-posix.h" #include "os-shared-mutex.h" +#include "os-shared-idmap.h" #include "os-impl-mutex.h" /* Tables where the OS object information is stored */ @@ -61,10 +62,13 @@ int32 OS_Posix_MutexAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemCreate_Impl(osal_index_t sem_id, uint32 options) +int32 OS_MutSemCreate_Impl(const OS_object_token_t *token, uint32 options) { - int return_code; - pthread_mutexattr_t mutex_attr; + int return_code; + pthread_mutexattr_t mutex_attr; + OS_impl_mutex_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); /* ** initialize the attribute with default values @@ -72,8 +76,8 @@ int32 OS_MutSemCreate_Impl(osal_index_t sem_id, uint32 options) return_code = pthread_mutexattr_init(&mutex_attr); if (return_code != 0) { - OS_DEBUG("Error: Mutex could not be created. pthread_mutexattr_init failed ID = %u: %s\n", (unsigned int)sem_id, - strerror(return_code)); + OS_DEBUG("Error: Mutex could not be created. pthread_mutexattr_init failed ID = %lu: %s\n", + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), strerror(return_code)); return OS_SEM_FAILURE; } @@ -83,8 +87,8 @@ int32 OS_MutSemCreate_Impl(osal_index_t sem_id, uint32 options) return_code = pthread_mutexattr_setprotocol(&mutex_attr, PTHREAD_PRIO_INHERIT); if (return_code != 0) { - OS_DEBUG("Error: Mutex could not be created. pthread_mutexattr_setprotocol failed ID = %u: %s\n", - (unsigned int)sem_id, strerror(return_code)); + OS_DEBUG("Error: Mutex could not be created. pthread_mutexattr_setprotocol failed ID = %lu: %s\n", + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), strerror(return_code)); return OS_SEM_FAILURE; } @@ -94,8 +98,8 @@ int32 OS_MutSemCreate_Impl(osal_index_t sem_id, uint32 options) return_code = pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE); if (return_code != 0) { - OS_DEBUG("Error: Mutex could not be created. pthread_mutexattr_settype failed ID = %u: %s\n", - (unsigned int)sem_id, strerror(return_code)); + OS_DEBUG("Error: Mutex could not be created. pthread_mutexattr_settype failed ID = %lu: %s\n", + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), strerror(return_code)); return OS_SEM_FAILURE; } @@ -103,10 +107,11 @@ int32 OS_MutSemCreate_Impl(osal_index_t sem_id, uint32 options) ** create the mutex ** upon successful initialization, the state of the mutex becomes initialized and unlocked */ - return_code = pthread_mutex_init(&OS_impl_mutex_table[sem_id].id, &mutex_attr); + return_code = pthread_mutex_init(&impl->id, &mutex_attr); if (return_code != 0) { - OS_DEBUG("Error: Mutex could not be created. ID = %u: %s\n", (unsigned int)sem_id, strerror(return_code)); + OS_DEBUG("Error: Mutex could not be created. ID = %lu: %s\n", OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), + strerror(return_code)); return OS_SEM_FAILURE; } @@ -121,11 +126,14 @@ int32 OS_MutSemCreate_Impl(osal_index_t sem_id, uint32 options) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemDelete_Impl(osal_index_t sem_id) +int32 OS_MutSemDelete_Impl(const OS_object_token_t *token) { - int status; + int status; + OS_impl_mutex_internal_record_t *impl; - status = pthread_mutex_destroy(&(OS_impl_mutex_table[sem_id].id)); /* 0 = success */ + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); + + status = pthread_mutex_destroy(&(impl->id)); /* 0 = success */ if (status != 0) { @@ -144,14 +152,17 @@ int32 OS_MutSemDelete_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemGive_Impl(osal_index_t sem_id) +int32 OS_MutSemGive_Impl(const OS_object_token_t *token) { - int status; + int status; + OS_impl_mutex_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); /* ** Unlock the mutex */ - status = pthread_mutex_unlock(&(OS_impl_mutex_table[sem_id].id)); + status = pthread_mutex_unlock(&(impl->id)); if (status != 0) { return OS_SEM_FAILURE; @@ -168,14 +179,17 @@ int32 OS_MutSemGive_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemTake_Impl(osal_index_t sem_id) +int32 OS_MutSemTake_Impl(const OS_object_token_t *token) { - int status; + int status; + OS_impl_mutex_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); /* ** Lock the mutex */ - status = pthread_mutex_lock(&(OS_impl_mutex_table[sem_id].id)); + status = pthread_mutex_lock(&(impl->id)); if (status != 0) { return OS_SEM_FAILURE; @@ -192,7 +206,7 @@ int32 OS_MutSemTake_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemGetInfo_Impl(osal_index_t sem_id, OS_mut_sem_prop_t *mut_prop) +int32 OS_MutSemGetInfo_Impl(const OS_object_token_t *token, OS_mut_sem_prop_t *mut_prop) { return OS_SUCCESS; diff --git a/src/os/posix/src/os-impl-queues.c b/src/os/posix/src/os-impl-queues.c index 913d0773b..87ce7e935 100644 --- a/src/os/posix/src/os-impl-queues.c +++ b/src/os/posix/src/os-impl-queues.c @@ -81,17 +81,22 @@ int32 OS_Posix_QueueAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueCreate_Impl(osal_index_t queue_id, uint32 flags) +int32 OS_QueueCreate_Impl(const OS_object_token_t *token, uint32 flags) { - int return_code; - mqd_t queueDesc; - struct mq_attr queueAttr; - char name[OS_MAX_API_NAME * 2]; + int return_code; + mqd_t queueDesc; + struct mq_attr queueAttr; + char name[OS_MAX_API_NAME * 2]; + OS_impl_queue_internal_record_t *impl; + OS_queue_internal_record_t * queue; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); + queue = OS_OBJECT_TABLE_GET(OS_queue_table, *token); /* set queue attributes */ memset(&queueAttr, 0, sizeof(queueAttr)); - queueAttr.mq_maxmsg = OS_queue_table[queue_id].max_depth; - queueAttr.mq_msgsize = OS_queue_table[queue_id].max_size; + queueAttr.mq_maxmsg = queue->max_depth; + queueAttr.mq_msgsize = queue->max_size; /* * The "TruncateQueueDepth" indicates a soft limit to the size of a queue. @@ -107,7 +112,7 @@ int32 OS_QueueCreate_Impl(osal_index_t queue_id, uint32 flags) ** Construct the queue name: ** The name will consist of "/.queue_name" */ - snprintf(name, sizeof(name), "/%d.%s", (int)getpid(), OS_global_queue_table[queue_id].name_entry); + snprintf(name, sizeof(name), "/%d.%s", (int)getpid(), queue->queue_name); /* ** create message queue @@ -128,8 +133,8 @@ int32 OS_QueueCreate_Impl(osal_index_t queue_id, uint32 flags) } else { - OS_impl_queue_table[queue_id].id = queueDesc; - return_code = OS_SUCCESS; + impl->id = queueDesc; + return_code = OS_SUCCESS; /* * Unlink the queue right now -- @@ -159,12 +164,15 @@ int32 OS_QueueCreate_Impl(osal_index_t queue_id, uint32 flags) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueDelete_Impl(osal_index_t queue_id) +int32 OS_QueueDelete_Impl(const OS_object_token_t *token) { - int32 return_code; + int32 return_code; + OS_impl_queue_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); /* Try to delete and unlink the queue */ - if (mq_close(OS_impl_queue_table[queue_id].id) != 0) + if (mq_close(impl->id) != 0) { OS_DEBUG("OS_QueueDelete Error during mq_close(). errno = %d (%s)\n", errno, strerror(errno)); return_code = OS_ERROR; @@ -185,11 +193,14 @@ int32 OS_QueueDelete_Impl(osal_index_t queue_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueGet_Impl(osal_index_t queue_id, void *data, size_t size, size_t *size_copied, int32 timeout) +int32 OS_QueueGet_Impl(const OS_object_token_t *token, void *data, size_t size, size_t *size_copied, int32 timeout) { - int32 return_code; - ssize_t sizeCopied; - struct timespec ts; + int32 return_code; + ssize_t sizeCopied; + struct timespec ts; + OS_impl_queue_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); /* ** Read the message queue for data @@ -203,7 +214,7 @@ int32 OS_QueueGet_Impl(osal_index_t queue_id, void *data, size_t size, size_t *s */ do { - sizeCopied = mq_receive(OS_impl_queue_table[queue_id].id, data, size, NULL); + sizeCopied = mq_receive(impl->id, data, size, NULL); } while (sizeCopied < 0 && errno == EINTR); } else @@ -232,7 +243,7 @@ int32 OS_QueueGet_Impl(osal_index_t queue_id, void *data, size_t size, size_t *s */ do { - sizeCopied = mq_timedreceive(OS_impl_queue_table[queue_id].id, data, size, NULL, &ts); + sizeCopied = mq_timedreceive(impl->id, data, size, NULL, &ts); } while (timeout != OS_CHECK && sizeCopied < 0 && errno == EINTR); } /* END timeout */ @@ -281,11 +292,14 @@ int32 OS_QueueGet_Impl(osal_index_t queue_id, void *data, size_t size, size_t *s * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueuePut_Impl(osal_index_t queue_id, const void *data, size_t size, uint32 flags) +int32 OS_QueuePut_Impl(const OS_object_token_t *token, const void *data, size_t size, uint32 flags) { - int32 return_code; - int result; - struct timespec ts; + int32 return_code; + int result; + struct timespec ts; + OS_impl_queue_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); /* * NOTE - using a zero timeout here for the same reason that QueueGet does --- @@ -298,7 +312,7 @@ int32 OS_QueuePut_Impl(osal_index_t queue_id, const void *data, size_t size, uin /* send message */ do { - result = mq_timedsend(OS_impl_queue_table[queue_id].id, data, size, 1, &ts); + result = mq_timedsend(impl->id, data, size, 1, &ts); } while (result == -1 && errno == EINTR); if (result == 0) diff --git a/src/os/posix/src/os-impl-shell.c b/src/os/posix/src/os-impl-shell.c index e85654380..445ae4d38 100644 --- a/src/os/posix/src/os-impl-shell.c +++ b/src/os/posix/src/os-impl-shell.c @@ -57,12 +57,15 @@ * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ShellOutputToFile_Impl(osal_index_t file_id, const char *Cmd) +int32 OS_ShellOutputToFile_Impl(const OS_object_token_t *token, const char *Cmd) { - pid_t cpid; - uint32 local_id; - int wstat; - const char *shell = getenv("SHELL"); + pid_t cpid; + uint32 local_id; + int wstat; + const char * shell = getenv("SHELL"); + OS_impl_file_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); if (shell == NULL) { @@ -79,8 +82,8 @@ int32 OS_ShellOutputToFile_Impl(osal_index_t file_id, const char *Cmd) if (cpid == 0) { /* child process */ - dup2(OS_impl_filehandle_table[file_id].fd, STDOUT_FILENO); - dup2(OS_impl_filehandle_table[file_id].fd, STDERR_FILENO); + dup2(impl->fd, STDOUT_FILENO); + dup2(impl->fd, STDERR_FILENO); /* close all _other_ filehandles */ for (local_id = 0; local_id < OS_MAX_NUM_OPEN_FILES; ++local_id) diff --git a/src/os/posix/src/os-impl-tasks.c b/src/os/posix/src/os-impl-tasks.c index a529264ee..cb94efcc5 100644 --- a/src/os/posix/src/os-impl-tasks.c +++ b/src/os/posix/src/os-impl-tasks.c @@ -564,17 +564,21 @@ int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, osal_priority_t priority * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskCreate_Impl(osal_index_t task_id, uint32 flags) +int32 OS_TaskCreate_Impl(const OS_object_token_t *token, uint32 flags) { - OS_U32ValueWrapper_t arg; - int32 return_code; + OS_U32ValueWrapper_t arg; + int32 return_code; + OS_impl_task_internal_record_t *impl; + OS_task_internal_record_t * task; arg.opaque_arg = NULL; - arg.id = OS_global_task_table[task_id].active_id; + arg.id = OS_ObjectIdFromToken(token); + + task = OS_OBJECT_TABLE_GET(OS_task_table, *token); + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); - return_code = - OS_Posix_InternalTaskCreate_Impl(&OS_impl_task_table[task_id].id, OS_task_table[task_id].priority, - OS_task_table[task_id].stack_size, OS_PthreadTaskEntry, arg.opaque_arg); + return_code = OS_Posix_InternalTaskCreate_Impl(&impl->id, task->priority, task->stack_size, OS_PthreadTaskEntry, + arg.opaque_arg); return return_code; } /* end OS_TaskCreate_Impl */ @@ -587,9 +591,13 @@ int32 OS_TaskCreate_Impl(osal_index_t task_id, uint32 flags) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskMatch_Impl(osal_index_t task_id) +int32 OS_TaskMatch_Impl(const OS_object_token_t *token) { - if (pthread_equal(pthread_self(), OS_impl_task_table[task_id].id) == 0) + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + + if (pthread_equal(pthread_self(), impl->id) == 0) { return OS_ERROR; } @@ -605,15 +613,19 @@ int32 OS_TaskMatch_Impl(osal_index_t task_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskDelete_Impl(osal_index_t task_id) +int32 OS_TaskDelete_Impl(const OS_object_token_t *token) { + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + /* ** Try to delete the task ** If this fails, not much recourse - the only potential cause of failure ** to cancel here is that the thread ID is invalid because it already exited itself, ** and if that is true there is nothing wrong - everything is OK to continue normally. */ - pthread_cancel(OS_impl_task_table[task_id].id); + pthread_cancel(impl->id); return OS_SUCCESS; } /* end OS_TaskDelete_Impl */ @@ -678,11 +690,15 @@ int32 OS_TaskDelay_Impl(uint32 millisecond) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskSetPriority_Impl(osal_index_t task_id, osal_priority_t new_priority) +int32 OS_TaskSetPriority_Impl(const OS_object_token_t *token, osal_priority_t new_priority) { int os_priority; int ret; + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + if (POSIX_GlobalVars.EnableTaskPriorities) { /* Change OSAL priority into a priority that will work for this OS */ @@ -691,11 +707,11 @@ int32 OS_TaskSetPriority_Impl(osal_index_t task_id, osal_priority_t new_priority /* ** Set priority */ - ret = pthread_setschedprio(OS_impl_task_table[task_id].id, os_priority); + ret = pthread_setschedprio(impl->id, os_priority); if (ret != 0) { - OS_DEBUG("pthread_setschedprio: Task ID = %u, prio = %d, err = %s\n", (unsigned int)task_id, os_priority, - strerror(ret)); + OS_DEBUG("pthread_setschedprio: Task ID = %lu, prio = %d, err = %s\n", + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), os_priority, strerror(ret)); return (OS_ERROR); } } @@ -758,7 +774,7 @@ osal_id_t OS_TaskGetId_Impl(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskGetInfo_Impl(osal_index_t task_id, OS_task_prop_t *task_prop) +int32 OS_TaskGetInfo_Impl(const OS_object_token_t *token, OS_task_prop_t *task_prop) { return OS_SUCCESS; } /* end OS_TaskGetInfo_Impl */ @@ -771,11 +787,14 @@ int32 OS_TaskGetInfo_Impl(osal_index_t task_id, OS_task_prop_t *task_prop) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -bool OS_TaskIdMatchSystemData_Impl(void *ref, osal_index_t local_id, const OS_common_record_t *obj) +bool OS_TaskIdMatchSystemData_Impl(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) { - const pthread_t *target = (const pthread_t *)ref; + const pthread_t * target = (const pthread_t *)ref; + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); - return (pthread_equal(*target, OS_impl_task_table[local_id].id) != 0); + return (pthread_equal(*target, impl->id) != 0); } /*---------------------------------------------------------------- diff --git a/src/os/posix/src/os-impl-timebase.c b/src/os/posix/src/os-impl-timebase.c index a618435ac..bbd177bc4 100644 --- a/src/os/posix/src/os-impl-timebase.c +++ b/src/os/posix/src/os-impl-timebase.c @@ -108,9 +108,13 @@ static void OS_UsecToTimespec(uint32 usecs, struct timespec *time_spec) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -void OS_TimeBaseLock_Impl(osal_index_t local_id) +void OS_TimeBaseLock_Impl(const OS_object_token_t *token) { - pthread_mutex_lock(&OS_impl_timebase_table[local_id].handler_mutex); + OS_impl_timebase_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + + pthread_mutex_lock(&impl->handler_mutex); } /* end OS_TimeBaseLock_Impl */ /*---------------------------------------------------------------- @@ -121,9 +125,13 @@ void OS_TimeBaseLock_Impl(osal_index_t local_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -void OS_TimeBaseUnlock_Impl(osal_index_t local_id) +void OS_TimeBaseUnlock_Impl(const OS_object_token_t *token) { - pthread_mutex_unlock(&OS_impl_timebase_table[local_id].handler_mutex); + OS_impl_timebase_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + + pthread_mutex_unlock(&impl->handler_mutex); } /* end OS_TimeBaseUnlock_Impl */ /*---------------------------------------------------------------- @@ -286,8 +294,8 @@ int32 OS_Posix_TimeBaseAPI_Impl_Init(void) * - This is used internally for reporting accuracy, * - TicksPerSecond values over 2M will return zero */ - OS_SharedGlobalVars.MicroSecPerTick = - (1000000 + (OS_SharedGlobalVars.TicksPerSecond / 2)) / OS_SharedGlobalVars.TicksPerSecond; + OS_SharedGlobalVars.MicroSecPerTick = (1000000 + (OS_SharedGlobalVars.TicksPerSecond / 2)) / + OS_SharedGlobalVars.TicksPerSecond; } while (0); return (return_code); @@ -314,7 +322,7 @@ static void *OS_TimeBasePthreadEntry(void *arg) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseCreate_Impl(osal_index_t timer_id) +int32 OS_TimeBaseCreate_Impl(const OS_object_token_t *token) { int32 return_code; int status; @@ -323,11 +331,11 @@ int32 OS_TimeBaseCreate_Impl(osal_index_t timer_id) struct sigevent evp; struct timespec ts; OS_impl_timebase_internal_record_t *local; - OS_common_record_t * global; + OS_timebase_internal_record_t * timebase; OS_U32ValueWrapper_t arg; - local = &OS_impl_timebase_table[timer_id]; - global = &OS_global_timebase_table[timer_id]; + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, *token); /* * Spawn a dedicated time base handler thread @@ -340,7 +348,7 @@ int32 OS_TimeBaseCreate_Impl(osal_index_t timer_id) * the global table lock. */ arg.opaque_arg = NULL; - arg.id = global->active_id; + arg.id = OS_ObjectIdFromToken(token); return_code = OS_Posix_InternalTaskCreate_Impl(&local->handler_thread, OSAL_PRIORITY_C(0), 0, OS_TimeBasePthreadEntry, arg.opaque_arg); if (return_code != OS_SUCCESS) @@ -360,7 +368,7 @@ int32 OS_TimeBaseCreate_Impl(osal_index_t timer_id) * If no external sync function is provided then this will set up a POSIX * timer to locally simulate the timer tick using the CPU clock. */ - if (OS_timebase_table[timer_id].external_sync == NULL) + if (timebase->external_sync == NULL) { sigemptyset(&local->sigset); @@ -371,7 +379,7 @@ int32 OS_TimeBaseCreate_Impl(osal_index_t timer_id) */ for (idx = 0; idx < OS_MAX_TIMEBASES; ++idx) { - if (idx != timer_id && OS_ObjectIdDefined(OS_global_timebase_table[idx].active_id) && + if (OS_ObjectIdDefined(OS_global_timebase_table[idx].active_id) && OS_impl_timebase_table[idx].assigned_signal != 0) { sigaddset(&local->sigset, OS_impl_timebase_table[idx].assigned_signal); @@ -439,7 +447,7 @@ int32 OS_TimeBaseCreate_Impl(osal_index_t timer_id) * and doing it this way should still work on a system where sizeof(sival_int) < sizeof(uint32) * (as long as sizeof(sival_int) >= number of bits in OS_OBJECT_INDEX_MASK) */ - evp.sigev_value.sival_int = (int)OS_ObjectIdToSerialNumber_Impl(global->active_id); + evp.sigev_value.sival_int = (int)OS_ObjectIdToSerialNumber_Impl(OS_ObjectIdFromToken(token)); /* ** Create the timer @@ -453,7 +461,7 @@ int32 OS_TimeBaseCreate_Impl(osal_index_t timer_id) break; } - OS_timebase_table[timer_id].external_sync = OS_TimeBase_SigWaitImpl; + timebase->external_sync = OS_TimeBase_SigWaitImpl; } while (0); } @@ -480,14 +488,16 @@ int32 OS_TimeBaseCreate_Impl(osal_index_t timer_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseSet_Impl(osal_index_t timer_id, uint32 start_time, uint32 interval_time) +int32 OS_TimeBaseSet_Impl(const OS_object_token_t *token, uint32 start_time, uint32 interval_time) { OS_impl_timebase_internal_record_t *local; struct itimerspec timeout; int32 return_code; int status; + OS_timebase_internal_record_t * timebase; - local = &OS_impl_timebase_table[timer_id]; + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, *token); return_code = OS_SUCCESS; /* There is only something to do here if we are generating a simulated tick */ @@ -514,11 +524,11 @@ int32 OS_TimeBaseSet_Impl(osal_index_t timer_id, uint32 start_time, uint32 inter } else if (interval_time > 0) { - OS_timebase_table[timer_id].accuracy_usec = (uint32)((timeout.it_interval.tv_nsec + 999) / 1000); + timebase->accuracy_usec = (uint32)((timeout.it_interval.tv_nsec + 999) / 1000); } else { - OS_timebase_table[timer_id].accuracy_usec = (uint32)((timeout.it_value.tv_nsec + 999) / 1000); + timebase->accuracy_usec = (uint32)((timeout.it_value.tv_nsec + 999) / 1000); } } @@ -534,12 +544,12 @@ int32 OS_TimeBaseSet_Impl(osal_index_t timer_id, uint32 start_time, uint32 inter * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseDelete_Impl(osal_index_t timer_id) +int32 OS_TimeBaseDelete_Impl(const OS_object_token_t *token) { OS_impl_timebase_internal_record_t *local; int status; - local = &OS_impl_timebase_table[timer_id]; + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); pthread_cancel(local->handler_thread); @@ -548,7 +558,7 @@ int32 OS_TimeBaseDelete_Impl(osal_index_t timer_id) */ if (local->assigned_signal != 0) { - status = timer_delete(OS_impl_timebase_table[timer_id].host_timerid); + status = timer_delete(local->host_timerid); if (status < 0) { OS_DEBUG("Error deleting timer: %s\n", strerror(errno)); @@ -569,7 +579,7 @@ int32 OS_TimeBaseDelete_Impl(osal_index_t timer_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseGetInfo_Impl(osal_index_t timer_id, OS_timebase_prop_t *timer_prop) +int32 OS_TimeBaseGetInfo_Impl(const OS_object_token_t *token, OS_timebase_prop_t *timer_prop) { return OS_SUCCESS; diff --git a/src/os/rtems/inc/os-impl-io.h b/src/os/rtems/inc/os-impl-io.h index 9fc1893c1..78a9e3ca5 100644 --- a/src/os/rtems/inc/os-impl-io.h +++ b/src/os/rtems/inc/os-impl-io.h @@ -36,7 +36,7 @@ typedef struct { int fd; bool selectable; -} OS_Rtems_filehandle_entry_t; +} OS_impl_file_internal_record_t; /* * The global file handle table. @@ -44,6 +44,6 @@ typedef struct * This table is shared across multiple units (files, sockets, etc) and they will share * the same file handle table from the basic file I/O. */ -extern OS_Rtems_filehandle_entry_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; +extern OS_impl_file_internal_record_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; #endif /* INCLUDE_OS_IMPL_IO_H_ */ diff --git a/src/os/rtems/src/os-impl-binsem.c b/src/os/rtems/src/os-impl-binsem.c index d3a8933bf..8d15204fa 100644 --- a/src/os/rtems/src/os-impl-binsem.c +++ b/src/os/rtems/src/os-impl-binsem.c @@ -87,17 +87,20 @@ int32 OS_Rtems_BinSemAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemCreate_Impl(osal_index_t sem_id, uint32 sem_initial_value, uint32 options) +int32 OS_BinSemCreate_Impl(const OS_object_token_t *token, uint32 sem_initial_value, uint32 options) { - rtems_status_code status; - rtems_name r_name; + rtems_status_code status; + rtems_name r_name; + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); /* ** RTEMS task names are 4 byte integers. ** It is convenient to use the OSAL ID in here, as we know it is already unique ** and trying to use the real name would be less than useful (only 4 chars) */ - r_name = OS_ObjectIdToInteger(OS_global_bin_sem_table[sem_id].active_id); + r_name = OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)); /* Check to make sure the sem value is going to be either 0 or 1 */ if (sem_initial_value > 1) @@ -106,8 +109,7 @@ int32 OS_BinSemCreate_Impl(osal_index_t sem_id, uint32 sem_initial_value, uint32 } /* Create RTEMS Semaphore */ - status = rtems_semaphore_create(r_name, sem_initial_value, OSAL_BINARY_SEM_ATTRIBS, 0, - &(OS_impl_bin_sem_table[sem_id].id)); + status = rtems_semaphore_create(r_name, sem_initial_value, OSAL_BINARY_SEM_ATTRIBS, 0, &(impl->id)); /* check if Create failed */ if (status != RTEMS_SUCCESSFUL) @@ -128,11 +130,14 @@ int32 OS_BinSemCreate_Impl(osal_index_t sem_id, uint32 sem_initial_value, uint32 * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemDelete_Impl(osal_index_t sem_id) +int32 OS_BinSemDelete_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); - status = rtems_semaphore_delete(OS_impl_bin_sem_table[sem_id].id); + status = rtems_semaphore_delete(impl->id); if (status != RTEMS_SUCCESSFUL) { OS_DEBUG("Unhandled semaphore_delete error: %s\n", rtems_status_text(status)); @@ -151,11 +156,14 @@ int32 OS_BinSemDelete_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemGive_Impl(osal_index_t sem_id) +int32 OS_BinSemGive_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); - status = rtems_semaphore_release(OS_impl_bin_sem_table[sem_id].id); + status = rtems_semaphore_release(impl->id); if (status != RTEMS_SUCCESSFUL) { OS_DEBUG("Unhandled semaphore_release error: %s\n", rtems_status_text(status)); @@ -173,12 +181,15 @@ int32 OS_BinSemGive_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemFlush_Impl(osal_index_t sem_id) +int32 OS_BinSemFlush_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); /* Give Semaphore */ - status = rtems_semaphore_flush(OS_impl_bin_sem_table[sem_id].id); + status = rtems_semaphore_flush(impl->id); if (status != RTEMS_SUCCESSFUL) { OS_DEBUG("Unhandled semaphore_flush error: %s\n", rtems_status_text(status)); @@ -197,11 +208,14 @@ int32 OS_BinSemFlush_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemTake_Impl(osal_index_t sem_id) +int32 OS_BinSemTake_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); - status = rtems_semaphore_obtain(OS_impl_bin_sem_table[sem_id].id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + status = rtems_semaphore_obtain(impl->id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); /* ** If the semaphore is flushed, this function will return ** RTEMS_UNSATISFIED. If this happens, the OSAL does not want to return @@ -228,17 +242,20 @@ int32 OS_BinSemTake_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemTimedWait_Impl(osal_index_t sem_id, uint32 msecs) +int32 OS_BinSemTimedWait_Impl(const OS_object_token_t *token, uint32 msecs) { - rtems_status_code status; - int TimeInTicks; + rtems_status_code status; + int TimeInTicks; + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); if (OS_Milli2Ticks(msecs, &TimeInTicks) != OS_SUCCESS) { return OS_ERROR; } - status = rtems_semaphore_obtain(OS_impl_bin_sem_table[sem_id].id, RTEMS_WAIT, TimeInTicks); + status = rtems_semaphore_obtain(impl->id, RTEMS_WAIT, TimeInTicks); if (status == RTEMS_TIMEOUT) { @@ -264,7 +281,7 @@ int32 OS_BinSemTimedWait_Impl(osal_index_t sem_id, uint32 msecs) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemGetInfo_Impl(osal_index_t sem_id, OS_bin_sem_prop_t *bin_prop) +int32 OS_BinSemGetInfo_Impl(const OS_object_token_t *token, OS_bin_sem_prop_t *bin_prop) { /* RTEMS has no API for obtaining the current value of a semaphore */ return OS_SUCCESS; diff --git a/src/os/rtems/src/os-impl-console.c b/src/os/rtems/src/os-impl-console.c index 7bad84748..ba0f2534a 100644 --- a/src/os/rtems/src/os-impl-console.c +++ b/src/os/rtems/src/os-impl-console.c @@ -86,9 +86,11 @@ OS_impl_console_internal_record_t OS_impl_console_table[OS_MAX_CONSOLES]; * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -void OS_ConsoleWakeup_Impl(osal_index_t local_id) +void OS_ConsoleWakeup_Impl(const OS_object_token_t *token) { - OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; + OS_impl_console_internal_record_t *local; + + local = OS_OBJECT_TABLE_GET(OS_impl_console_table, *token); if (local->is_async) { @@ -98,7 +100,7 @@ void OS_ConsoleWakeup_Impl(osal_index_t local_id) else { /* output directly */ - OS_ConsoleOutput_Impl(local_id); + OS_ConsoleOutput_Impl(token); } } /* end OS_ConsoleWakeup_Impl */ @@ -111,14 +113,19 @@ void OS_ConsoleWakeup_Impl(osal_index_t local_id) *-----------------------------------------------------------------*/ static void OS_ConsoleTask_Entry(rtems_task_argument arg) { - uint32 local_id = arg; + OS_object_token_t token; OS_impl_console_internal_record_t *local; - local = &OS_impl_console_table[local_id]; - while (true) + if (OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_CONSOLE, OS_ObjectIdFromInteger(arg), &token) == + OS_SUCCESS) { - OS_ConsoleOutput_Impl(local_id); - rtems_semaphore_obtain(local->data_sem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + local = OS_OBJECT_TABLE_GET(OS_impl_console_table, token); + while (true) + { + OS_ConsoleOutput_Impl(&token); + rtems_semaphore_obtain(local->data_sem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + } + OS_ObjectIdRelease(&token); } } /* end OS_ConsoleTask_Entry */ @@ -130,15 +137,17 @@ static void OS_ConsoleTask_Entry(rtems_task_argument arg) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ConsoleCreate_Impl(osal_index_t local_id) +int32 OS_ConsoleCreate_Impl(const OS_object_token_t *token) { - OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; + OS_impl_console_internal_record_t *local; int32 return_code; rtems_name r_name; rtems_id r_task_id; rtems_status_code status; - if (local_id == 0) + local = OS_OBJECT_TABLE_GET(OS_impl_console_table, *token); + + if (OS_ObjectIndexFromToken(token) == 0) { return_code = OS_SUCCESS; local->is_async = OS_CONSOLE_ASYNC; @@ -152,7 +161,7 @@ int32 OS_ConsoleCreate_Impl(osal_index_t local_id) ** It is convenient to use the OSAL ID in here, as we know it is already unique ** and trying to use the real name would be less than useful (only 4 chars) */ - r_name = OS_ObjectIdToInteger(OS_global_console_table[local_id].active_id); + r_name = OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)); status = rtems_semaphore_create(r_name, 0, RTEMS_PRIORITY, 0, &local->data_sem); if (status != RTEMS_SUCCESSFUL) { @@ -175,9 +184,9 @@ int32 OS_ConsoleCreate_Impl(osal_index_t local_id) else { /* will place the task in 'ready for scheduling' state */ - status = rtems_task_start(r_task_id, /*rtems task id*/ - OS_ConsoleTask_Entry, /* task entry point */ - (rtems_task_argument)local_id); /* passed argument */ + status = rtems_task_start(r_task_id, /*rtems task id*/ + OS_ConsoleTask_Entry, /* task entry point */ + (rtems_task_argument)r_name); /* passed argument */ if (status != RTEMS_SUCCESSFUL) { diff --git a/src/os/rtems/src/os-impl-countsem.c b/src/os/rtems/src/os-impl-countsem.c index 11c294918..33b1719b6 100644 --- a/src/os/rtems/src/os-impl-countsem.c +++ b/src/os/rtems/src/os-impl-countsem.c @@ -84,10 +84,13 @@ int32 OS_Rtems_CountSemAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemCreate_Impl(osal_index_t sem_id, uint32 sem_initial_value, uint32 options) +int32 OS_CountSemCreate_Impl(const OS_object_token_t *token, uint32 sem_initial_value, uint32 options) { - rtems_status_code status; - rtems_name r_name; + rtems_status_code status; + rtems_name r_name; + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); /* ** Verify that the semaphore maximum value is not too high @@ -102,9 +105,8 @@ int32 OS_CountSemCreate_Impl(osal_index_t sem_id, uint32 sem_initial_value, uint ** It is convenient to use the OSAL ID in here, as we know it is already unique ** and trying to use the real name would be less than useful (only 4 chars) */ - r_name = OS_ObjectIdToInteger(OS_global_count_sem_table[sem_id].active_id); - status = rtems_semaphore_create(r_name, sem_initial_value, OSAL_COUNT_SEM_ATTRIBS, 0, - &(OS_impl_count_sem_table[sem_id].id)); + r_name = OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)); + status = rtems_semaphore_create(r_name, sem_initial_value, OSAL_COUNT_SEM_ATTRIBS, 0, &(impl->id)); /* check if Create failed */ if (status != RTEMS_SUCCESSFUL) @@ -125,11 +127,14 @@ int32 OS_CountSemCreate_Impl(osal_index_t sem_id, uint32 sem_initial_value, uint * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemDelete_Impl(osal_index_t sem_id) +int32 OS_CountSemDelete_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); - status = rtems_semaphore_delete(OS_impl_count_sem_table[sem_id].id); + status = rtems_semaphore_delete(impl->id); if (status != RTEMS_SUCCESSFUL) { OS_DEBUG("Unhandled semaphore_delete error: %s\n", rtems_status_text(status)); @@ -148,11 +153,14 @@ int32 OS_CountSemDelete_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemGive_Impl(osal_index_t sem_id) +int32 OS_CountSemGive_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); - status = rtems_semaphore_release(OS_impl_count_sem_table[sem_id].id); + status = rtems_semaphore_release(impl->id); if (status != RTEMS_SUCCESSFUL) { OS_DEBUG("Unhandled semaphore_release error: %s\n", rtems_status_text(status)); @@ -171,11 +179,14 @@ int32 OS_CountSemGive_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemTake_Impl(osal_index_t sem_id) +int32 OS_CountSemTake_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_countsem_internal_record_t *impl; - status = rtems_semaphore_obtain(OS_impl_count_sem_table[sem_id].id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); + + status = rtems_semaphore_obtain(impl->id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); if (status != RTEMS_SUCCESSFUL) { OS_DEBUG("Unhandled semaphore_obtain error: %s\n", rtems_status_text(status)); @@ -194,17 +205,20 @@ int32 OS_CountSemTake_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemTimedWait_Impl(osal_index_t sem_id, uint32 msecs) +int32 OS_CountSemTimedWait_Impl(const OS_object_token_t *token, uint32 msecs) { - rtems_status_code status; - int TimeInTicks; + rtems_status_code status; + int TimeInTicks; + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); if (OS_Milli2Ticks(msecs, &TimeInTicks) != OS_SUCCESS) { return OS_ERROR; } - status = rtems_semaphore_obtain(OS_impl_count_sem_table[sem_id].id, RTEMS_WAIT, TimeInTicks); + status = rtems_semaphore_obtain(impl->id, RTEMS_WAIT, TimeInTicks); if (status == RTEMS_TIMEOUT) { return OS_SEM_TIMEOUT; @@ -228,7 +242,7 @@ int32 OS_CountSemTimedWait_Impl(osal_index_t sem_id, uint32 msecs) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemGetInfo_Impl(osal_index_t sem_id, OS_count_sem_prop_t *count_prop) +int32 OS_CountSemGetInfo_Impl(const OS_object_token_t *token, OS_count_sem_prop_t *count_prop) { /* RTEMS does not provide an API to get the value */ return OS_SUCCESS; diff --git a/src/os/rtems/src/os-impl-files.c b/src/os/rtems/src/os-impl-files.c index d82de88fe..48e76807d 100644 --- a/src/os/rtems/src/os-impl-files.c +++ b/src/os/rtems/src/os-impl-files.c @@ -47,7 +47,7 @@ * This is shared by all OSAL entities that perform low-level I/O. */ /* The file/stream table is referenced by multiple entities, i.e. sockets, select, etc */ -OS_Rtems_filehandle_entry_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; +OS_impl_file_internal_record_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; /**************************************************************************************** IMPLEMENTATION-SPECIFIC ROUTINES diff --git a/src/os/rtems/src/os-impl-filesys.c b/src/os/rtems/src/os-impl-filesys.c index 3583303c7..4bdea8453 100644 --- a/src/os/rtems/src/os-impl-filesys.c +++ b/src/os/rtems/src/os-impl-filesys.c @@ -104,13 +104,16 @@ int32 OS_Rtems_FileSysAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysStartVolume_Impl(osal_index_t filesys_id) +int32 OS_FileSysStartVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t * local = &OS_filesys_table[filesys_id]; - OS_impl_filesys_internal_record_t *impl = &OS_impl_filesys_table[filesys_id]; + OS_filesys_internal_record_t * local; + OS_impl_filesys_internal_record_t *impl; rtems_status_code sc; int32 return_code; + impl = OS_OBJECT_TABLE_GET(OS_impl_filesys_table, *token); + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + return_code = OS_ERR_NOT_IMPLEMENTED; memset(impl, 0, sizeof(*impl)); @@ -161,7 +164,7 @@ int32 OS_FileSysStartVolume_Impl(osal_index_t filesys_id) impl->mount_fstype = RTEMS_FILESYSTEM_TYPE_RFS; impl->mount_options = RTEMS_FILESYSTEM_READ_WRITE; snprintf(impl->blockdev_name, sizeof(impl->blockdev_name), "%s%c", RAMDISK_DEVICE_BASE_NAME, - (int)filesys_id + 'a'); + (int)OS_ObjectIndexFromToken(token) + 'a'); sc = rtems_blkdev_create(impl->blockdev_name, local->blocksize, local->numblocks, ramdisk_ioctl, impl->allocated_disk); @@ -205,9 +208,11 @@ int32 OS_FileSysStartVolume_Impl(osal_index_t filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysStopVolume_Impl(osal_index_t filesys_id) +int32 OS_FileSysStopVolume_Impl(const OS_object_token_t *token) { - OS_impl_filesys_internal_record_t *impl = &OS_impl_filesys_table[filesys_id]; + OS_impl_filesys_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filesys_table, *token); /* * If this was a dynamically allocated disk, then unlink it. @@ -229,14 +234,17 @@ int32 OS_FileSysStopVolume_Impl(osal_index_t filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysFormatVolume_Impl(osal_index_t filesys_id) +int32 OS_FileSysFormatVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t * local = &OS_filesys_table[filesys_id]; - OS_impl_filesys_internal_record_t *impl = &OS_impl_filesys_table[filesys_id]; + OS_filesys_internal_record_t * local; + OS_impl_filesys_internal_record_t *impl; rtems_rfs_format_config config; int32 return_code; int sc; + impl = OS_OBJECT_TABLE_GET(OS_impl_filesys_table, *token); + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + return_code = OS_ERR_NOT_IMPLEMENTED; switch (local->fstype) @@ -291,12 +299,15 @@ int32 OS_FileSysFormatVolume_Impl(osal_index_t filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysMountVolume_Impl(osal_index_t filesys_id) +int32 OS_FileSysMountVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t * local = &OS_filesys_table[filesys_id]; - OS_impl_filesys_internal_record_t *impl = &OS_impl_filesys_table[filesys_id]; + OS_filesys_internal_record_t * local; + OS_impl_filesys_internal_record_t *impl; struct stat stat_buf; + impl = OS_OBJECT_TABLE_GET(OS_impl_filesys_table, *token); + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + /* * This will do a mkdir() for the mount point if it does * not already exist. @@ -345,9 +356,11 @@ int32 OS_FileSysMountVolume_Impl(osal_index_t filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysUnmountVolume_Impl(osal_index_t filesys_id) +int32 OS_FileSysUnmountVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_filesys_internal_record_t *local; + + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); if (local->fstype == OS_FILESYS_TYPE_VOLATILE_DISK || local->fstype == OS_FILESYS_TYPE_NORMAL_DISK) { @@ -373,12 +386,14 @@ int32 OS_FileSysUnmountVolume_Impl(osal_index_t filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysStatVolume_Impl(osal_index_t filesys_id, OS_statvfs_t *result) +int32 OS_FileSysStatVolume_Impl(const OS_object_token_t *token, OS_statvfs_t *result) { - OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_filesys_internal_record_t *local; struct statvfs stat_buf; int32 return_code; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + if (statvfs(local->system_mountpt, &stat_buf) != 0) { /* @@ -415,7 +430,7 @@ int32 OS_FileSysStatVolume_Impl(osal_index_t filesys_id, OS_statvfs_t *result) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysCheckVolume_Impl(osal_index_t filesys_id, bool repair) +int32 OS_FileSysCheckVolume_Impl(const OS_object_token_t *token, bool repair) { return OS_ERR_NOT_IMPLEMENTED; } /* end OS_FileSysCheckVolume_Impl */ diff --git a/src/os/rtems/src/os-impl-loader.c b/src/os/rtems/src/os-impl-loader.c index f3f1fb1d8..40278f27e 100644 --- a/src/os/rtems/src/os-impl-loader.c +++ b/src/os/rtems/src/os-impl-loader.c @@ -34,6 +34,7 @@ #include "os-rtems.h" #include "os-impl-loader.h" #include "os-shared-module.h" +#include "os-shared-idmap.h" /**************************************************************************************** GLOBAL DATA @@ -104,11 +105,14 @@ static bool OS_rtems_rtl_check_unresolved(rtems_rtl_unresolv_rec_t *rec, void *d * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleLoad_Impl(osal_index_t module_id, const char *translated_path) +int32 OS_ModuleLoad_Impl(const OS_object_token_t *token, const char *translated_path) { - int32 status = OS_ERROR; - int unresolved; - void *dl_handle; + int32 status = OS_ERROR; + int unresolved; + void * dl_handle; + OS_impl_module_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_module_table, *token); dlerror(); dl_handle = dlopen(translated_path, RTLD_NOW | RTLD_GLOBAL); @@ -152,7 +156,7 @@ int32 OS_ModuleLoad_Impl(osal_index_t module_id, const char *translated_path) if (status == OS_SUCCESS) { /* success: save for future use */ - OS_impl_module_table[module_id].dl_handle = dl_handle; + impl->dl_handle = dl_handle; } else if (dl_handle != NULL) { @@ -177,18 +181,21 @@ int32 OS_ModuleLoad_Impl(osal_index_t module_id, const char *translated_path) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleUnload_Impl(osal_index_t module_id) +int32 OS_ModuleUnload_Impl(const OS_object_token_t *token) { - int32 status = OS_ERROR; + int32 status = OS_ERROR; + OS_impl_module_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_module_table, *token); /* ** Attempt to close/unload the module */ dlerror(); - if (dlclose(OS_impl_module_table[module_id].dl_handle) == 0) + if (dlclose(impl->dl_handle) == 0) { - OS_impl_module_table[module_id].dl_handle = NULL; - status = OS_SUCCESS; + impl->dl_handle = NULL; + status = OS_SUCCESS; } else { @@ -207,7 +214,7 @@ int32 OS_ModuleUnload_Impl(osal_index_t module_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleGetInfo_Impl(osal_index_t module_id, OS_module_prop_t *module_prop) +int32 OS_ModuleGetInfo_Impl(const OS_object_token_t *token, OS_module_prop_t *module_prop) { /* ** RTEMS does not specify a way to get these values diff --git a/src/os/rtems/src/os-impl-mutex.c b/src/os/rtems/src/os-impl-mutex.c index c02b95665..48874bdcc 100644 --- a/src/os/rtems/src/os-impl-mutex.c +++ b/src/os/rtems/src/os-impl-mutex.c @@ -85,16 +85,19 @@ int32 OS_Rtems_MutexAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemCreate_Impl(osal_index_t sem_id, uint32 options) +int32 OS_MutSemCreate_Impl(const OS_object_token_t *token, uint32 options) { - rtems_status_code status; - rtems_name r_name; + rtems_status_code status; + rtems_name r_name; + OS_impl_mutex_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); /* ** Try to create the mutex */ - r_name = OS_ObjectIdToInteger(OS_global_mutex_table[sem_id].active_id); - status = rtems_semaphore_create(r_name, 1, OSAL_MUTEX_ATTRIBS, 0, &OS_impl_mutex_table[sem_id].id); + r_name = OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)); + status = rtems_semaphore_create(r_name, 1, OSAL_MUTEX_ATTRIBS, 0, &impl->id); if (status != RTEMS_SUCCESSFUL) { @@ -114,11 +117,14 @@ int32 OS_MutSemCreate_Impl(osal_index_t sem_id, uint32 options) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemDelete_Impl(osal_index_t sem_id) +int32 OS_MutSemDelete_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_mutex_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); - status = rtems_semaphore_delete(OS_impl_mutex_table[sem_id].id); + status = rtems_semaphore_delete(impl->id); if (status != RTEMS_SUCCESSFUL) { /* clean up? */ @@ -138,12 +144,15 @@ int32 OS_MutSemDelete_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemGive_Impl(osal_index_t sem_id) +int32 OS_MutSemGive_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_mutex_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); /* Give the mutex */ - status = rtems_semaphore_release(OS_impl_mutex_table[sem_id].id); + status = rtems_semaphore_release(impl->id); if (status != RTEMS_SUCCESSFUL) { @@ -163,11 +172,14 @@ int32 OS_MutSemGive_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemTake_Impl(osal_index_t sem_id) +int32 OS_MutSemTake_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_mutex_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); - status = rtems_semaphore_obtain(OS_impl_mutex_table[sem_id].id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + status = rtems_semaphore_obtain(impl->id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); if (status != RTEMS_SUCCESSFUL) { @@ -187,7 +199,7 @@ int32 OS_MutSemTake_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemGetInfo_Impl(osal_index_t sem_id, OS_mut_sem_prop_t *mut_prop) +int32 OS_MutSemGetInfo_Impl(const OS_object_token_t *token, OS_mut_sem_prop_t *mut_prop) { /* RTEMS provides no additional info */ return OS_SUCCESS; diff --git a/src/os/rtems/src/os-impl-queues.c b/src/os/rtems/src/os-impl-queues.c index f94385f5c..58e978ceb 100644 --- a/src/os/rtems/src/os-impl-queues.c +++ b/src/os/rtems/src/os-impl-queues.c @@ -78,17 +78,22 @@ int32 OS_Rtems_QueueAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueCreate_Impl(osal_index_t queue_id, uint32 flags) +int32 OS_QueueCreate_Impl(const OS_object_token_t *token, uint32 flags) { - rtems_status_code status; - rtems_name r_name; + rtems_status_code status; + rtems_name r_name; + OS_impl_queue_internal_record_t *impl; + OS_queue_internal_record_t * queue; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); + queue = OS_OBJECT_TABLE_GET(OS_queue_table, *token); /* ** RTEMS task names are 4 byte integers. ** It is convenient to use the OSAL queue ID in here, as we know it is already unique ** and trying to use the real queue name would be less than useful (only 4 chars) */ - r_name = OS_ObjectIdToInteger(OS_global_queue_table[queue_id].active_id); + r_name = OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)); /* ** Create the message queue. @@ -96,12 +101,11 @@ int32 OS_QueueCreate_Impl(osal_index_t queue_id, uint32 flags) ** (RTEMS_FIFO or RTEMS_PRIORITY) is irrelevant since only one task waits ** on each queue. */ - status = rtems_message_queue_create( - r_name, /* 32-bit RTEMS object name; not used */ - OS_queue_table[queue_id].max_depth, /* maximum number of messages in queue (queue depth) */ - OS_queue_table[queue_id].max_size, /* maximum size in bytes of a message */ - RTEMS_FIFO | RTEMS_LOCAL, /* attributes (default) */ - &(OS_impl_queue_table[queue_id].id) /* object ID returned for queue */ + status = rtems_message_queue_create(r_name, /* 32-bit RTEMS object name; not used */ + queue->max_depth, /* maximum number of messages in queue (queue depth) */ + queue->max_size, /* maximum size in bytes of a message */ + RTEMS_FIFO | RTEMS_LOCAL, /* attributes (default) */ + &(impl->id) /* object ID returned for queue */ ); /* @@ -125,12 +129,15 @@ int32 OS_QueueCreate_Impl(osal_index_t queue_id, uint32 flags) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueDelete_Impl(osal_index_t queue_id) +int32 OS_QueueDelete_Impl(const OS_object_token_t *token) { - rtems_status_code status; + rtems_status_code status; + OS_impl_queue_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); /* Try to delete the queue */ - status = rtems_message_queue_delete(OS_impl_queue_table[queue_id].id); + status = rtems_message_queue_delete(impl->id); if (status != RTEMS_SUCCESSFUL) { OS_DEBUG("Unhandled queue_delete error: %s\n", rtems_status_text(status)); @@ -149,17 +156,20 @@ int32 OS_QueueDelete_Impl(osal_index_t queue_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueGet_Impl(osal_index_t queue_id, void *data, uint32 size, uint32 *size_copied, int32 timeout) +int32 OS_QueueGet_Impl(const OS_object_token_t *token, void *data, uint32 size, uint32 *size_copied, int32 timeout) { - int32 return_code; - rtems_status_code status; - rtems_interval ticks; - int tick_count; - rtems_option option_set; - size_t rtems_size; - rtems_id rtems_queue_id; + int32 return_code; + rtems_status_code status; + rtems_interval ticks; + int tick_count; + rtems_option option_set; + size_t rtems_size; + rtems_id rtems_queue_id; + OS_impl_queue_internal_record_t *impl; - rtems_queue_id = OS_impl_queue_table[queue_id].id; + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); + + rtems_queue_id = impl->id; /* Get Message From Message Queue */ if (timeout == OS_PEND) @@ -243,12 +253,15 @@ int32 OS_QueueGet_Impl(osal_index_t queue_id, void *data, uint32 size, uint32 *s * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueuePut_Impl(osal_index_t queue_id, const void *data, uint32 size, uint32 flags) +int32 OS_QueuePut_Impl(const OS_object_token_t *token, const void *data, uint32 size, uint32 flags) { - rtems_status_code status; - rtems_id rtems_queue_id; + rtems_status_code status; + rtems_id rtems_queue_id; + OS_impl_queue_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); - rtems_queue_id = OS_impl_queue_table[queue_id].id; + rtems_queue_id = impl->id; /* Write the buffer pointer to the queue. If an error occurred, report it ** with the corresponding SB status code. @@ -287,7 +300,7 @@ int32 OS_QueuePut_Impl(osal_index_t queue_id, const void *data, uint32 size, uin * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueGetInfo_Impl(osal_index_t queue_id, OS_queue_prop_t *queue_prop) +int32 OS_QueueGetInfo_Impl(const OS_object_token_t *token, OS_queue_prop_t *queue_prop) { /* No extra info for queues in the OS implementation */ return OS_SUCCESS; diff --git a/src/os/rtems/src/os-impl-tasks.c b/src/os/rtems/src/os-impl-tasks.c index cc278e422..a9db8a73b 100644 --- a/src/os/rtems/src/os-impl-tasks.c +++ b/src/os/rtems/src/os-impl-tasks.c @@ -90,19 +90,24 @@ int32 OS_Rtems_TaskAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskCreate_Impl(osal_index_t task_id, uint32 flags) +int32 OS_TaskCreate_Impl(const OS_object_token_t *token, uint32 flags) { - rtems_status_code status; - rtems_name r_name; - rtems_mode r_mode; - rtems_attribute r_attributes; + rtems_status_code status; + rtems_name r_name; + rtems_mode r_mode; + rtems_attribute r_attributes; + OS_impl_task_internal_record_t *impl; + OS_task_internal_record_t * task; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + task = OS_OBJECT_TABLE_GET(OS_task_table, *token); /* ** RTEMS task names are 4 byte integers. ** It is convenient to use the OSAL task ID in here, as we know it is already unique ** and trying to use the real task name would be less than useful (only 4 chars) */ - r_name = OS_ObjectIdToInteger(OS_global_task_table[task_id].active_id); + r_name = OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)); r_mode = RTEMS_PREEMPT | RTEMS_NO_ASR | RTEMS_NO_TIMESLICE | RTEMS_INTERRUPT_LEVEL(0); /* @@ -115,8 +120,7 @@ int32 OS_TaskCreate_Impl(osal_index_t task_id, uint32 flags) r_attributes |= RTEMS_FLOATING_POINT; } - status = rtems_task_create(r_name, OS_task_table[task_id].priority, OS_task_table[task_id].stack_size, r_mode, - r_attributes, &OS_impl_task_table[task_id].id); + status = rtems_task_create(r_name, task->priority, task->stack_size, r_mode, r_attributes, &impl->id); /* check if task_create failed */ if (status != RTEMS_SUCCESSFUL) @@ -127,15 +131,14 @@ int32 OS_TaskCreate_Impl(osal_index_t task_id, uint32 flags) } /* will place the task in 'ready for scheduling' state */ - status = rtems_task_start( - OS_impl_task_table[task_id].id, /*rtems task id*/ - (rtems_task_entry)OS_RtemsEntry, /* task entry point */ - (rtems_task_argument)OS_ObjectIdToInteger(OS_global_task_table[task_id].active_id)); /* passed argument */ + status = rtems_task_start(impl->id, /*rtems task id*/ + (rtems_task_entry)OS_RtemsEntry, /* task entry point */ + (rtems_task_argument)r_name); /* passed argument */ if (status != RTEMS_SUCCESSFUL) { OS_printf("rtems_task_start failed: %s\n", rtems_status_text(status)); - rtems_task_delete(OS_impl_task_table[task_id].id); + rtems_task_delete(impl->id); return OS_ERROR; } @@ -151,8 +154,12 @@ int32 OS_TaskCreate_Impl(osal_index_t task_id, uint32 flags) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskDelete_Impl(osal_index_t task_id) +int32 OS_TaskDelete_Impl(const OS_object_token_t *token) { + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + /* ** Try to delete the task ** If this fails, not much recourse - the only potential cause of failure @@ -160,7 +167,7 @@ int32 OS_TaskDelete_Impl(osal_index_t task_id) ** and if that is true there is nothing wrong - everything is OK to continue normally. */ - rtems_task_delete(OS_impl_task_table[task_id].id); + rtems_task_delete(impl->id); return OS_SUCCESS; } /* end OS_TaskDelete_Impl */ @@ -221,13 +228,16 @@ int32 OS_TaskDelay_Impl(uint32 milli_second) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskSetPriority_Impl(osal_index_t task_id, osal_priority_t new_priority) +int32 OS_TaskSetPriority_Impl(const OS_object_token_t *token, osal_priority_t new_priority) { - rtems_task_priority old_pri; - rtems_status_code status; + rtems_task_priority old_pri; + rtems_status_code status; + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); /* Set RTEMS Task Priority */ - status = rtems_task_set_priority(OS_impl_task_table[task_id].id, new_priority, &old_pri); + status = rtems_task_set_priority(impl->id, new_priority, &old_pri); if (status != RTEMS_SUCCESSFUL) { OS_DEBUG("Unhandled task_set_priority error: %s\n", rtems_status_text(status)); @@ -246,12 +256,16 @@ int32 OS_TaskSetPriority_Impl(osal_index_t task_id, osal_priority_t new_priority * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskMatch_Impl(osal_index_t task_id) +int32 OS_TaskMatch_Impl(const OS_object_token_t *token) { + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + /* ** Get RTEMS Task Id */ - if (rtems_task_self() != OS_impl_task_table[task_id].id) + if (rtems_task_self() != impl->id) { return (OS_ERROR); } @@ -329,7 +343,7 @@ osal_id_t OS_TaskGetId_Impl(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskGetInfo_Impl(osal_index_t task_id, OS_task_prop_t *task_prop) +int32 OS_TaskGetInfo_Impl(const OS_object_token_t *token, OS_task_prop_t *task_prop) { return OS_SUCCESS; @@ -360,9 +374,12 @@ int32 OS_TaskValidateSystemData_Impl(const void *sysdata, uint32 sysdata_size) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -bool OS_TaskIdMatchSystemData_Impl(void *ref, osal_index_t local_id, const OS_common_record_t *obj) +bool OS_TaskIdMatchSystemData_Impl(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) { - const rtems_id *target = (const rtems_id *)ref; + const rtems_id * target = (const rtems_id *)ref; + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); - return (*target == OS_impl_task_table[local_id].id); + return (*target == impl->id); } diff --git a/src/os/rtems/src/os-impl-timebase.c b/src/os/rtems/src/os-impl-timebase.c index c5c74370c..c4c72a349 100644 --- a/src/os/rtems/src/os-impl-timebase.c +++ b/src/os/rtems/src/os-impl-timebase.c @@ -89,9 +89,13 @@ OS_impl_timebase_internal_record_t OS_impl_timebase_table[OS_MAX_TIMEBASES]; * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -void OS_TimeBaseLock_Impl(osal_index_t local_id) +void OS_TimeBaseLock_Impl(const OS_object_token_t *token) { - rtems_semaphore_obtain(OS_impl_timebase_table[local_id].handler_mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + OS_impl_timebase_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + + rtems_semaphore_obtain(impl->handler_mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT); } /* end OS_TimeBaseLock_Impl */ /*---------------------------------------------------------------- @@ -102,9 +106,13 @@ void OS_TimeBaseLock_Impl(osal_index_t local_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -void OS_TimeBaseUnlock_Impl(osal_index_t local_id) +void OS_TimeBaseUnlock_Impl(const OS_object_token_t *token) { - rtems_semaphore_release(OS_impl_timebase_table[local_id].handler_mutex); + OS_impl_timebase_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + + rtems_semaphore_release(impl->handler_mutex); } /* end OS_TimeBaseUnlock_Impl */ /*---------------------------------------------------------------- @@ -119,14 +127,14 @@ void OS_TimeBaseUnlock_Impl(osal_index_t local_id) static rtems_timer_service_routine OS_TimeBase_ISR(rtems_id rtems_timer_id, void *arg) { OS_U32ValueWrapper_t user_data; - osal_index_t local_id; + OS_object_token_t token; OS_impl_timebase_internal_record_t *local; user_data.opaque_arg = arg; - OS_ConvertToArrayIndex(user_data.id, &local_id); - local = &OS_impl_timebase_table[local_id]; - if (OS_ObjectIdEqual(OS_global_timebase_table[local_id].active_id, user_data.id)) + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMEBASE, user_data.id, &token) == OS_SUCCESS) { + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, token); + /* * Reset the timer, but only if an interval was selected */ @@ -219,8 +227,8 @@ int32 OS_Rtems_TimeBaseAPI_Impl_Init(void) * This really should be an exact/whole number result; otherwise this * will round to the nearest nanosecond. */ - RTEMS_GlobalVars.ClockAccuracyNsec = - (1000000000 + (OS_SharedGlobalVars.TicksPerSecond / 2)) / OS_SharedGlobalVars.TicksPerSecond; + RTEMS_GlobalVars.ClockAccuracyNsec = (1000000000 + (OS_SharedGlobalVars.TicksPerSecond / 2)) / + OS_SharedGlobalVars.TicksPerSecond; /* * Finally compute the Microseconds per tick @@ -280,22 +288,22 @@ void OS_UsecsToTicks(uint32 usecs, rtems_interval *ticks) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseCreate_Impl(osal_index_t timer_id) +int32 OS_TimeBaseCreate_Impl(const OS_object_token_t *token) { int32 return_code; rtems_status_code rtems_sc; OS_impl_timebase_internal_record_t *local; - OS_common_record_t * global; rtems_name r_name; + OS_timebase_internal_record_t * timebase; return_code = OS_SUCCESS; - local = &OS_impl_timebase_table[timer_id]; - global = &OS_global_timebase_table[timer_id]; + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, *token); /* * The RTEMS classic name for dependent resources */ - r_name = OS_ObjectIdToInteger(global->active_id); + r_name = OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)); /* * Set up the necessary OS constructs @@ -306,17 +314,17 @@ int32 OS_TimeBaseCreate_Impl(osal_index_t timer_id) * If no external sync function is provided then this will set up an RTEMS * timer to locally simulate the timer tick using the CPU clock. */ - local->simulate_flag = (OS_timebase_table[timer_id].external_sync == NULL); + local->simulate_flag = (timebase->external_sync == NULL); if (local->simulate_flag) { - OS_timebase_table[timer_id].external_sync = OS_TimeBase_WaitImpl; + timebase->external_sync = OS_TimeBase_WaitImpl; /* * The tick_sem is a simple semaphore posted by the ISR and taken by the * timebase helper task (created later). */ - rtems_sc = - rtems_semaphore_create(r_name, 0, RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_PRIORITY, 0, &local->tick_sem); + rtems_sc = rtems_semaphore_create(r_name, 0, RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_PRIORITY, 0, + &local->tick_sem); if (rtems_sc != RTEMS_SUCCESSFUL) { OS_DEBUG("Error: Tick Sem could not be created: %d\n", (int)rtems_sc); @@ -376,10 +384,9 @@ int32 OS_TimeBaseCreate_Impl(osal_index_t timer_id) else { /* will place the task in 'ready for scheduling' state */ - rtems_sc = - rtems_task_start(local->handler_task, /*rtems task id*/ - (rtems_task_entry)OS_TimeBase_CallbackThread, /* task entry point */ - (rtems_task_argument)OS_ObjectIdToInteger(global->active_id)); /* passed argument */ + rtems_sc = rtems_task_start(local->handler_task, /*rtems task id*/ + (rtems_task_entry)OS_TimeBase_CallbackThread, /* task entry point */ + (rtems_task_argument)r_name); /* passed argument */ if (rtems_sc != RTEMS_SUCCESSFUL) { @@ -410,15 +417,17 @@ int32 OS_TimeBaseCreate_Impl(osal_index_t timer_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseSet_Impl(osal_index_t timer_id, uint32 start_time, uint32 interval_time) +int32 OS_TimeBaseSet_Impl(const OS_object_token_t *token, uint32 start_time, uint32 interval_time) { OS_U32ValueWrapper_t user_data; OS_impl_timebase_internal_record_t *local; int32 return_code; int status; rtems_interval start_ticks; + OS_timebase_internal_record_t * timebase; - local = &OS_impl_timebase_table[timer_id]; + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, *token); return_code = OS_SUCCESS; /* There is only something to do here if we are generating a simulated tick */ @@ -458,7 +467,7 @@ int32 OS_TimeBaseSet_Impl(osal_index_t timer_id, uint32 start_time, uint32 inter OS_UsecsToTicks(start_time, &start_ticks); user_data.opaque_arg = NULL; - user_data.id = OS_global_timebase_table[timer_id].active_id; + user_data.id = OS_ObjectIdFromToken(token); status = rtems_timer_fire_after(local->rtems_timer_id, start_ticks, OS_TimeBase_ISR, user_data.opaque_arg); if (status != RTEMS_SUCCESSFUL) @@ -475,23 +484,23 @@ int32 OS_TimeBaseSet_Impl(osal_index_t timer_id, uint32 start_time, uint32 inter if (local->configured_start_time != start_time) { OS_DEBUG("WARNING: timer %lu start_time requested=%luus, configured=%luus\n", - (unsigned long)timer_id, (unsigned long)start_time, + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), (unsigned long)start_time, (unsigned long)local->configured_start_time); } if (local->configured_interval_time != interval_time) { OS_DEBUG("WARNING: timer %lu interval_time requested=%luus, configured=%luus\n", - (unsigned long)timer_id, (unsigned long)interval_time, + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), (unsigned long)interval_time, (unsigned long)local->configured_interval_time); } if (local->interval_ticks > 0) { - OS_timebase_table[timer_id].accuracy_usec = local->configured_interval_time; + timebase->accuracy_usec = local->configured_interval_time; } else { - OS_timebase_table[timer_id].accuracy_usec = local->configured_start_time; + timebase->accuracy_usec = local->configured_start_time; } } } @@ -512,13 +521,13 @@ int32 OS_TimeBaseSet_Impl(osal_index_t timer_id, uint32 start_time, uint32 inter * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseDelete_Impl(osal_index_t timer_id) +int32 OS_TimeBaseDelete_Impl(const OS_object_token_t *token) { rtems_status_code rtems_sc; OS_impl_timebase_internal_record_t *local; int32 return_code; - local = &OS_impl_timebase_table[timer_id]; + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); return_code = OS_SUCCESS; /* @@ -576,7 +585,7 @@ int32 OS_TimeBaseDelete_Impl(osal_index_t timer_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseGetInfo_Impl(osal_index_t timer_id, OS_timebase_prop_t *timer_prop) +int32 OS_TimeBaseGetInfo_Impl(const OS_object_token_t *token, OS_timebase_prop_t *timer_prop) { return OS_SUCCESS; diff --git a/src/os/shared/inc/os-shared-binsem.h b/src/os/shared/inc/os-shared-binsem.h index f9b743f62..13070731f 100644 --- a/src/os/shared/inc/os-shared-binsem.h +++ b/src/os/shared/inc/os-shared-binsem.h @@ -62,7 +62,7 @@ int32 OS_BinSemAPI_Init(void); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_BinSemCreate_Impl(osal_index_t sem_id, uint32 sem_initial_value, uint32 options); +int32 OS_BinSemCreate_Impl(const OS_object_token_t *token, uint32 sem_initial_value, uint32 options); /*---------------------------------------------------------------- Function: OS_BinSemFlush_Impl @@ -72,7 +72,7 @@ int32 OS_BinSemCreate_Impl(osal_index_t sem_id, uint32 sem_initial_value, uint32 Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_BinSemFlush_Impl(osal_index_t sem_id); +int32 OS_BinSemFlush_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_BinSemGive_Impl @@ -81,7 +81,7 @@ int32 OS_BinSemFlush_Impl(osal_index_t sem_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_BinSemGive_Impl(osal_index_t sem_id); +int32 OS_BinSemGive_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_BinSemTake_Impl @@ -91,7 +91,7 @@ int32 OS_BinSemGive_Impl(osal_index_t sem_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_BinSemTake_Impl(osal_index_t sem_id); +int32 OS_BinSemTake_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_BinSemTimedWait_Impl @@ -101,7 +101,7 @@ int32 OS_BinSemTake_Impl(osal_index_t sem_id); Returns: OS_SUCCESS on success, or relevant error code OS_SEM_TIMEOUT must be returned if the time limit was reached ------------------------------------------------------------------*/ -int32 OS_BinSemTimedWait_Impl(osal_index_t sem_id, uint32 msecs); +int32 OS_BinSemTimedWait_Impl(const OS_object_token_t *token, uint32 msecs); /*---------------------------------------------------------------- Function: OS_BinSemDelete_Impl @@ -110,7 +110,7 @@ int32 OS_BinSemTimedWait_Impl(osal_index_t sem_id, uint32 msecs); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_BinSemDelete_Impl(osal_index_t sem_id); +int32 OS_BinSemDelete_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_BinSemGetInfo_Impl @@ -119,6 +119,6 @@ int32 OS_BinSemDelete_Impl(osal_index_t sem_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_BinSemGetInfo_Impl(osal_index_t sem_id, OS_bin_sem_prop_t *bin_prop); +int32 OS_BinSemGetInfo_Impl(const OS_object_token_t *token, OS_bin_sem_prop_t *bin_prop); #endif /* INCLUDE_OS_SHARED_BINSEM_H_ */ diff --git a/src/os/shared/inc/os-shared-countsem.h b/src/os/shared/inc/os-shared-countsem.h index fc4715d62..08966db51 100644 --- a/src/os/shared/inc/os-shared-countsem.h +++ b/src/os/shared/inc/os-shared-countsem.h @@ -62,7 +62,7 @@ int32 OS_CountSemAPI_Init(void); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_CountSemCreate_Impl(osal_index_t sem_id, uint32 sem_initial_value, uint32 options); +int32 OS_CountSemCreate_Impl(const OS_object_token_t *token, uint32 sem_initial_value, uint32 options); /*---------------------------------------------------------------- Function: OS_CountSemGive_Impl @@ -71,7 +71,7 @@ int32 OS_CountSemCreate_Impl(osal_index_t sem_id, uint32 sem_initial_value, uint Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_CountSemGive_Impl(osal_index_t sem_id); +int32 OS_CountSemGive_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_CountSemTake_Impl @@ -81,7 +81,7 @@ int32 OS_CountSemGive_Impl(osal_index_t sem_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_CountSemTake_Impl(osal_index_t sem_id); +int32 OS_CountSemTake_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_CountSemTimedWait_Impl @@ -91,7 +91,7 @@ int32 OS_CountSemTake_Impl(osal_index_t sem_id); Returns: OS_SUCCESS on success, or relevant error code OS_SEM_TIMEOUT must be returned if the time limit was reached ------------------------------------------------------------------*/ -int32 OS_CountSemTimedWait_Impl(osal_index_t sem_id, uint32 msecs); +int32 OS_CountSemTimedWait_Impl(const OS_object_token_t *token, uint32 msecs); /*---------------------------------------------------------------- Function: OS_CountSemDelete_Impl @@ -100,7 +100,7 @@ int32 OS_CountSemTimedWait_Impl(osal_index_t sem_id, uint32 msecs); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_CountSemDelete_Impl(osal_index_t sem_id); +int32 OS_CountSemDelete_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_CountSemGetInfo_Impl @@ -109,6 +109,6 @@ int32 OS_CountSemDelete_Impl(osal_index_t sem_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_CountSemGetInfo_Impl(osal_index_t sem_id, OS_count_sem_prop_t *count_prop); +int32 OS_CountSemGetInfo_Impl(const OS_object_token_t *token, OS_count_sem_prop_t *count_prop); #endif /* INCLUDE_OS_SHARED_COUNTSEM_H_ */ diff --git a/src/os/shared/inc/os-shared-dir.h b/src/os/shared/inc/os-shared-dir.h index e52d682ad..638fac1ad 100644 --- a/src/os/shared/inc/os-shared-dir.h +++ b/src/os/shared/inc/os-shared-dir.h @@ -72,7 +72,7 @@ int32 OS_DirCreate_Impl(const char *local_path, uint32 access); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_DirOpen_Impl(osal_index_t local_id, const char *local_path); +int32 OS_DirOpen_Impl(const OS_object_token_t *token, const char *local_path); /*---------------------------------------------------------------- Function: OS_DirClose_Impl @@ -81,7 +81,7 @@ int32 OS_DirOpen_Impl(osal_index_t local_id, const char *local_path); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_DirClose_Impl(osal_index_t local_id); +int32 OS_DirClose_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_DirRead_Impl @@ -90,7 +90,7 @@ int32 OS_DirClose_Impl(osal_index_t local_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_DirRead_Impl(osal_index_t local_id, os_dirent_t *dirent); +int32 OS_DirRead_Impl(const OS_object_token_t *token, os_dirent_t *dirent); /*---------------------------------------------------------------- Function: OS_DirRewind_Impl @@ -99,7 +99,7 @@ int32 OS_DirRead_Impl(osal_index_t local_id, os_dirent_t *dirent); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_DirRewind_Impl(osal_index_t local_id); +int32 OS_DirRewind_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_DirRemove_Impl diff --git a/src/os/shared/inc/os-shared-file.h b/src/os/shared/inc/os-shared-file.h index 547bde042..32058fa1a 100644 --- a/src/os/shared/inc/os-shared-file.h +++ b/src/os/shared/inc/os-shared-file.h @@ -78,7 +78,7 @@ int32 OS_FileAPI_Init(void); Returns: File position (non-negative) on success, or relevant error code (negative) ------------------------------------------------------------------*/ -int32 OS_GenericSeek_Impl(osal_index_t local_id, int32 offset, uint32 whence); +int32 OS_GenericSeek_Impl(const OS_object_token_t *token, int32 offset, uint32 whence); /*---------------------------------------------------------------- Function: OS_GenericRead_Impl @@ -88,7 +88,7 @@ int32 OS_GenericSeek_Impl(osal_index_t local_id, int32 offset, uint32 whence); Returns: Number of bytes read (non-negative) on success, or relevant error code (negative) ------------------------------------------------------------------*/ -int32 OS_GenericRead_Impl(osal_index_t local_id, void *buffer, size_t nbytes, int32 timeout); +int32 OS_GenericRead_Impl(const OS_object_token_t *token, void *buffer, size_t nbytes, int32 timeout); /*---------------------------------------------------------------- Function: OS_GenericWrite_Impl @@ -98,7 +98,7 @@ int32 OS_GenericRead_Impl(osal_index_t local_id, void *buffer, size_t nbytes, in Returns: Number of bytes written (non-negative) on success, or relevant error code (negative) ------------------------------------------------------------------*/ -int32 OS_GenericWrite_Impl(osal_index_t local_id, const void *buffer, size_t nbytes, int32 timeout); +int32 OS_GenericWrite_Impl(const OS_object_token_t *token, const void *buffer, size_t nbytes, int32 timeout); /*---------------------------------------------------------------- Function: OS_GenericClose_Impl @@ -108,7 +108,7 @@ int32 OS_GenericWrite_Impl(osal_index_t local_id, const void *buffer, size_t nby Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_GenericClose_Impl(osal_index_t local_id); +int32 OS_GenericClose_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_FileOpen_Impl @@ -118,7 +118,7 @@ int32 OS_GenericClose_Impl(osal_index_t local_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_FileOpen_Impl(osal_index_t local_id, const char *local_path, int32 flags, int32 access); +int32 OS_FileOpen_Impl(const OS_object_token_t *token, const char *local_path, int32 flags, int32 access); /*---------------------------------------------------------------- Function: OS_ShellOutputToFile_Impl @@ -127,7 +127,7 @@ int32 OS_FileOpen_Impl(osal_index_t local_id, const char *local_path, int32 flag Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ShellOutputToFile_Impl(osal_index_t stream_id, const char *Cmd); +int32 OS_ShellOutputToFile_Impl(const OS_object_token_t *token, const char *Cmd); /**************************************************************************************** Filename-based Operations diff --git a/src/os/shared/inc/os-shared-filesys.h b/src/os/shared/inc/os-shared-filesys.h index 110a23697..bba3ec767 100644 --- a/src/os/shared/inc/os-shared-filesys.h +++ b/src/os/shared/inc/os-shared-filesys.h @@ -140,7 +140,7 @@ int32 OS_FileSysAPI_Init(void); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_FileSysStartVolume_Impl(osal_index_t filesys_id); +int32 OS_FileSysStartVolume_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_FileSysStopVolume_Impl @@ -149,7 +149,7 @@ int32 OS_FileSysStartVolume_Impl(osal_index_t filesys_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_FileSysStopVolume_Impl(osal_index_t filesys_id); +int32 OS_FileSysStopVolume_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_FileSysFormatVolume_Impl @@ -158,7 +158,7 @@ int32 OS_FileSysStopVolume_Impl(osal_index_t filesys_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_FileSysFormatVolume_Impl(osal_index_t filesys_id); +int32 OS_FileSysFormatVolume_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_FileSysCheckVolume_Impl @@ -167,7 +167,7 @@ int32 OS_FileSysFormatVolume_Impl(osal_index_t filesys_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_FileSysCheckVolume_Impl(osal_index_t filesys_id, bool repair); +int32 OS_FileSysCheckVolume_Impl(const OS_object_token_t *token, bool repair); /*---------------------------------------------------------------- Function: OS_FileSysStatVolume_Impl @@ -176,7 +176,7 @@ int32 OS_FileSysCheckVolume_Impl(osal_index_t filesys_id, bool repair); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_FileSysStatVolume_Impl(osal_index_t filesys_id, OS_statvfs_t *result); +int32 OS_FileSysStatVolume_Impl(const OS_object_token_t *token, OS_statvfs_t *result); /*---------------------------------------------------------------- Function: OS_FileSysMountVolume_Impl @@ -185,7 +185,7 @@ int32 OS_FileSysStatVolume_Impl(osal_index_t filesys_id, OS_statvfs_t *result); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_FileSysMountVolume_Impl(osal_index_t filesys_id); +int32 OS_FileSysMountVolume_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_FileSysUnmountVolume_Impl @@ -194,7 +194,7 @@ int32 OS_FileSysMountVolume_Impl(osal_index_t filesys_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_FileSysUnmountVolume_Impl(osal_index_t filesys_id); +int32 OS_FileSysUnmountVolume_Impl(const OS_object_token_t *token); /* * Internal helper functions @@ -202,7 +202,7 @@ int32 OS_FileSysUnmountVolume_Impl(osal_index_t filesys_id); * Not normally invoked outside this unit, except for unit testing */ -bool OS_FileSys_FindVirtMountPoint(void *ref, osal_index_t local_id, const OS_common_record_t *obj); +bool OS_FileSys_FindVirtMountPoint(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj); int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fsvolname, size_t blocksize, osal_blockcount_t numblocks, bool should_format); diff --git a/src/os/shared/inc/os-shared-idmap.h b/src/os/shared/inc/os-shared-idmap.h index 1413c30a7..a63d2eea6 100644 --- a/src/os/shared/inc/os-shared-idmap.h +++ b/src/os/shared/inc/os-shared-idmap.h @@ -91,7 +91,7 @@ struct OS_object_token * * Returns true if the id/obj matches the reference, false otherwise. */ -typedef bool (*OS_ObjectMatchFunc_t)(void *ref, osal_index_t local_id, const OS_common_record_t *obj); +typedef bool (*OS_ObjectMatchFunc_t)(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj); /* * State object associated with an object iterator @@ -481,7 +481,7 @@ int32 OS_ObjectIdIteratorProcessEntry(OS_object_iter_t *iter, int32 (*func)(osal * These are not normally called outside this unit, but need * to be exposed for unit testing. */ -bool OS_ObjectNameMatch(void *ref, osal_index_t local_id, const OS_common_record_t *obj); +bool OS_ObjectNameMatch(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj); int32 OS_ObjectIdFindNextMatch(OS_ObjectMatchFunc_t MatchFunc, void *arg, OS_object_token_t *token); int32 OS_ObjectIdFindNextFree(OS_object_token_t *token); diff --git a/src/os/shared/inc/os-shared-module.h b/src/os/shared/inc/os-shared-module.h index 4f9284264..6f651b648 100644 --- a/src/os/shared/inc/os-shared-module.h +++ b/src/os/shared/inc/os-shared-module.h @@ -72,7 +72,7 @@ int32 OS_ModuleAPI_Init(void); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ModuleLoad_Impl(osal_index_t module_id, const char *translated_path); +int32 OS_ModuleLoad_Impl(const OS_object_token_t *token, const char *translated_path); /*---------------------------------------------------------------- @@ -82,7 +82,7 @@ int32 OS_ModuleLoad_Impl(osal_index_t module_id, const char *translated_path); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ModuleUnload_Impl(osal_index_t module_id); +int32 OS_ModuleUnload_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_ModuleGetInfo_Impl @@ -91,7 +91,7 @@ int32 OS_ModuleUnload_Impl(osal_index_t module_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ModuleGetInfo_Impl(osal_index_t module_id, OS_module_prop_t *module_prop); +int32 OS_ModuleGetInfo_Impl(const OS_object_token_t *token, OS_module_prop_t *module_prop); /*---------------------------------------------------------------- Function: OS_GlobalSymbolLookup_Impl @@ -111,7 +111,7 @@ int32 OS_GlobalSymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ModuleSymbolLookup_Impl(osal_index_t local_id, cpuaddr *SymbolAddress, const char *SymbolName); +int32 OS_ModuleSymbolLookup_Impl(const OS_object_token_t *token, cpuaddr *SymbolAddress, const char *SymbolName); /*---------------------------------------------------------------- Function: OS_SymbolTableDump_Impl diff --git a/src/os/shared/inc/os-shared-mutex.h b/src/os/shared/inc/os-shared-mutex.h index 576540228..b7703aa66 100644 --- a/src/os/shared/inc/os-shared-mutex.h +++ b/src/os/shared/inc/os-shared-mutex.h @@ -58,7 +58,7 @@ int32 OS_MutexAPI_Init(void); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_MutSemCreate_Impl(osal_index_t sem_id, uint32 options); +int32 OS_MutSemCreate_Impl(const OS_object_token_t *token, uint32 options); /*---------------------------------------------------------------- Function: OS_MutSemGive_Impl @@ -67,7 +67,7 @@ int32 OS_MutSemCreate_Impl(osal_index_t sem_id, uint32 options); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_MutSemGive_Impl(osal_index_t sem_id); +int32 OS_MutSemGive_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_MutSemTake_Impl @@ -76,7 +76,7 @@ int32 OS_MutSemGive_Impl(osal_index_t sem_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_MutSemTake_Impl(osal_index_t sem_id); +int32 OS_MutSemTake_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_MutSemDelete_Impl @@ -85,7 +85,7 @@ int32 OS_MutSemTake_Impl(osal_index_t sem_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_MutSemDelete_Impl(osal_index_t sem_id); +int32 OS_MutSemDelete_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_MutSemGetInfo_Impl @@ -94,6 +94,6 @@ int32 OS_MutSemDelete_Impl(osal_index_t sem_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_MutSemGetInfo_Impl(osal_index_t sem_id, OS_mut_sem_prop_t *mut_prop); +int32 OS_MutSemGetInfo_Impl(const OS_object_token_t *token, OS_mut_sem_prop_t *mut_prop); #endif /* INCLUDE_OS_SHARED_MUTEX_H_ */ diff --git a/src/os/shared/inc/os-shared-printf.h b/src/os/shared/inc/os-shared-printf.h index 165dd3dec..6bc2b6b48 100644 --- a/src/os/shared/inc/os-shared-printf.h +++ b/src/os/shared/inc/os-shared-printf.h @@ -73,7 +73,7 @@ int32 OS_ConsoleAPI_Init(void); Purpose: Prepare a console device for use For Async devices, this sets up the background writer task ------------------------------------------------------------------*/ -int32 OS_ConsoleCreate_Impl(osal_index_t local_id); +int32 OS_ConsoleCreate_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_ConsoleOutput_Impl @@ -85,7 +85,7 @@ int32 OS_ConsoleCreate_Impl(osal_index_t local_id); The data is already formatted, this just writes the characters. ------------------------------------------------------------------*/ -void OS_ConsoleOutput_Impl(osal_index_t local_id); +void OS_ConsoleOutput_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_ConsoleOutput_Impl @@ -100,6 +100,6 @@ void OS_ConsoleOutput_Impl(osal_index_t local_id); service, this should wakeup the actual console servicing thread. ------------------------------------------------------------------*/ -void OS_ConsoleWakeup_Impl(osal_index_t local_id); +void OS_ConsoleWakeup_Impl(const OS_object_token_t *token); #endif /* INCLUDE_OS_SHARED_PRINTF_H_ */ diff --git a/src/os/shared/inc/os-shared-queue.h b/src/os/shared/inc/os-shared-queue.h index 752c61f89..03b5c309d 100644 --- a/src/os/shared/inc/os-shared-queue.h +++ b/src/os/shared/inc/os-shared-queue.h @@ -63,7 +63,7 @@ int32 OS_QueueAPI_Init(void); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_QueueCreate_Impl(osal_index_t queue_id, uint32 flags); +int32 OS_QueueCreate_Impl(const OS_object_token_t *token, uint32 flags); /*---------------------------------------------------------------- Function: OS_QueueDelete_Impl @@ -72,7 +72,7 @@ int32 OS_QueueCreate_Impl(osal_index_t queue_id, uint32 flags); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_QueueDelete_Impl(osal_index_t queue_id); +int32 OS_QueueDelete_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_QueueGet_Impl @@ -85,7 +85,7 @@ int32 OS_QueueDelete_Impl(osal_index_t queue_id); OS_QUEUE_EMPTY must be returned if the queue is empty when polled (OS_CHECK) OS_QUEUE_INVALID_SIZE must be returned if the supplied buffer is too small ------------------------------------------------------------------*/ -int32 OS_QueueGet_Impl(osal_index_t queue_id, void *data, size_t size, size_t *size_copied, int32 timeout); +int32 OS_QueueGet_Impl(const OS_object_token_t *token, void *data, size_t size, size_t *size_copied, int32 timeout); /*---------------------------------------------------------------- Function: OS_QueuePut_Impl @@ -95,7 +95,7 @@ int32 OS_QueueGet_Impl(osal_index_t queue_id, void *data, size_t size, size_t *s Returns: OS_SUCCESS on success, or relevant error code OS_QUEUE_FULL must be returned if the queue is full. ------------------------------------------------------------------*/ -int32 OS_QueuePut_Impl(osal_index_t queue_id, const void *data, size_t size, uint32 flags); +int32 OS_QueuePut_Impl(const OS_object_token_t *token, const void *data, size_t size, uint32 flags); /*---------------------------------------------------------------- Function: OS_QueueGetInfo_Impl @@ -104,6 +104,6 @@ int32 OS_QueuePut_Impl(osal_index_t queue_id, const void *data, size_t size, uin Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_QueueGetInfo_Impl(osal_index_t queue_id, OS_queue_prop_t *queue_prop); +int32 OS_QueueGetInfo_Impl(const OS_object_token_t *token, OS_queue_prop_t *queue_prop); #endif /* INCLUDE_OS_SHARED_QUEUE_H_ */ diff --git a/src/os/shared/inc/os-shared-select.h b/src/os/shared/inc/os-shared-select.h index a1d7e9c85..66cf33f3c 100644 --- a/src/os/shared/inc/os-shared-select.h +++ b/src/os/shared/inc/os-shared-select.h @@ -50,7 +50,7 @@ Returns: OS_SUCCESS on success, or relevant error code OS_ERR_OPERATION_NOT_SUPPORTED if the specified file handle does not support select ------------------------------------------------------------------*/ -int32 OS_SelectSingle_Impl(osal_index_t stream_id, uint32 *SelectFlags, int32 msecs); +int32 OS_SelectSingle_Impl(const OS_object_token_t *token, uint32 *SelectFlags, int32 msecs); /*---------------------------------------------------------------- diff --git a/src/os/shared/inc/os-shared-shell.h b/src/os/shared/inc/os-shared-shell.h index a26044648..1b896ee8f 100644 --- a/src/os/shared/inc/os-shared-shell.h +++ b/src/os/shared/inc/os-shared-shell.h @@ -41,6 +41,6 @@ Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_ShellOutputToFile_Impl(osal_index_t stream_id, const char *Cmd); +int32 OS_ShellOutputToFile_Impl(const OS_object_token_t *token, const char *Cmd); #endif /* INCLUDE_OS_SHARED_SHELL_H_ */ diff --git a/src/os/shared/inc/os-shared-sockets.h b/src/os/shared/inc/os-shared-sockets.h index 8bd9fcfb6..12a9cc7b9 100644 --- a/src/os/shared/inc/os-shared-sockets.h +++ b/src/os/shared/inc/os-shared-sockets.h @@ -50,7 +50,7 @@ int32 OS_SocketAPI_Init(void); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_SocketOpen_Impl(osal_index_t sock_id); +int32 OS_SocketOpen_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_SocketBind_Impl @@ -59,7 +59,7 @@ int32 OS_SocketOpen_Impl(osal_index_t sock_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_SocketBind_Impl(osal_index_t sock_id, const OS_SockAddr_t *Addr); +int32 OS_SocketBind_Impl(const OS_object_token_t *token, const OS_SockAddr_t *Addr); /*---------------------------------------------------------------- Function: OS_SocketAccept_Impl @@ -70,7 +70,8 @@ int32 OS_SocketBind_Impl(osal_index_t sock_id, const OS_SockAddr_t *Addr); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_SocketAccept_Impl(osal_index_t sock_id, osal_index_t connsock_id, OS_SockAddr_t *Addr, int32 timeout); +int32 OS_SocketAccept_Impl(const OS_object_token_t *sock_token, const OS_object_token_t *conn_token, + OS_SockAddr_t *Addr, int32 timeout); /*---------------------------------------------------------------- Function: OS_SocketConnect_Impl @@ -80,7 +81,7 @@ int32 OS_SocketAccept_Impl(osal_index_t sock_id, osal_index_t connsock_id, OS_So Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_SocketConnect_Impl(osal_index_t sock_id, const OS_SockAddr_t *Addr, int32 timeout); +int32 OS_SocketConnect_Impl(const OS_object_token_t *token, const OS_SockAddr_t *Addr, int32 timeout); /*---------------------------------------------------------------- Function: OS_SocketRecvFrom_Impl @@ -93,7 +94,7 @@ int32 OS_SocketConnect_Impl(osal_index_t sock_id, const OS_SockAddr_t *Addr, int Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_SocketRecvFrom_Impl(osal_index_t sock_id, void *buffer, size_t buflen, OS_SockAddr_t *RemoteAddr, +int32 OS_SocketRecvFrom_Impl(const OS_object_token_t *token, void *buffer, size_t buflen, OS_SockAddr_t *RemoteAddr, int32 timeout); /*---------------------------------------------------------------- @@ -105,7 +106,8 @@ int32 OS_SocketRecvFrom_Impl(osal_index_t sock_id, void *buffer, size_t buflen, Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_SocketSendTo_Impl(osal_index_t sock_id, const void *buffer, size_t buflen, const OS_SockAddr_t *RemoteAddr); +int32 OS_SocketSendTo_Impl(const OS_object_token_t *token, const void *buffer, size_t buflen, + const OS_SockAddr_t *RemoteAddr); /*---------------------------------------------------------------- @@ -115,7 +117,7 @@ int32 OS_SocketSendTo_Impl(osal_index_t sock_id, const void *buffer, size_t bufl Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_SocketGetInfo_Impl(osal_index_t sock_id, OS_socket_prop_t *sock_prop); +int32 OS_SocketGetInfo_Impl(const OS_object_token_t *token, OS_socket_prop_t *sock_prop); /*---------------------------------------------------------------- @@ -175,6 +177,6 @@ int32 OS_SocketAddrSetPort_Impl(OS_SockAddr_t *Addr, uint16 PortNum); * Internal helper functions * Not normally called outside the local unit, except during unit test */ -void OS_CreateSocketName(osal_index_t local_id, const OS_SockAddr_t *Addr, const char *parent_name); +void OS_CreateSocketName(const OS_object_token_t *token, const OS_SockAddr_t *Addr, const char *parent_name); #endif /* INCLUDE_OS_SHARED_SOCKETS_H_ */ diff --git a/src/os/shared/inc/os-shared-task.h b/src/os/shared/inc/os-shared-task.h index 74ba5386a..03fc11fe7 100644 --- a/src/os/shared/inc/os-shared-task.h +++ b/src/os/shared/inc/os-shared-task.h @@ -81,7 +81,7 @@ void OS_TaskEntryPoint(osal_id_t global_task_id); Returns: OS_SUCCESS on match, any other code on non-match ------------------------------------------------------------------*/ -int32 OS_TaskMatch_Impl(osal_index_t task_id); +int32 OS_TaskMatch_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- @@ -92,7 +92,7 @@ int32 OS_TaskMatch_Impl(osal_index_t task_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_TaskCreate_Impl(osal_index_t task_id, uint32 flags); +int32 OS_TaskCreate_Impl(const OS_object_token_t *token, uint32 flags); /*---------------------------------------------------------------- Function: OS_TaskDelete_Impl @@ -101,7 +101,7 @@ int32 OS_TaskCreate_Impl(osal_index_t task_id, uint32 flags); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_TaskDelete_Impl(osal_index_t task_id); +int32 OS_TaskDelete_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_TaskExit_Impl @@ -128,7 +128,7 @@ int32 OS_TaskDelay_Impl(uint32 millisecond); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_TaskSetPriority_Impl(osal_index_t task_id, osal_priority_t new_priority); +int32 OS_TaskSetPriority_Impl(const OS_object_token_t *token, osal_priority_t new_priority); /*---------------------------------------------------------------- Function: OS_TaskGetId_Impl @@ -146,7 +146,7 @@ osal_id_t OS_TaskGetId_Impl(void); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_TaskGetInfo_Impl(osal_index_t task_id, OS_task_prop_t *task_prop); +int32 OS_TaskGetInfo_Impl(const OS_object_token_t *token, OS_task_prop_t *task_prop); /*---------------------------------------------------------------- @@ -169,7 +169,7 @@ int32 OS_TaskRegister_Impl(osal_id_t global_task_id); Compatible with the "OS_ObjectIdFindBySearch" routine ------------------------------------------------------------------*/ -bool OS_TaskIdMatchSystemData_Impl(void *ref, osal_index_t local_id, const OS_common_record_t *obj); +bool OS_TaskIdMatchSystemData_Impl(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj); /*---------------------------------------------------------------- diff --git a/src/os/shared/inc/os-shared-timebase.h b/src/os/shared/inc/os-shared-timebase.h index 9b8c9fe57..3e06d4f18 100644 --- a/src/os/shared/inc/os-shared-timebase.h +++ b/src/os/shared/inc/os-shared-timebase.h @@ -73,7 +73,7 @@ int32 OS_TimeBaseAPI_Init(void); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_TimeBaseCreate_Impl(osal_index_t timebase_id); +int32 OS_TimeBaseCreate_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_TimeBaseSet_Impl @@ -82,7 +82,7 @@ int32 OS_TimeBaseCreate_Impl(osal_index_t timebase_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_TimeBaseSet_Impl(osal_index_t timebase_id, uint32 start_time, uint32 interval_time); +int32 OS_TimeBaseSet_Impl(const OS_object_token_t *token, uint32 start_time, uint32 interval_time); /*---------------------------------------------------------------- Function: OS_TimeBaseDelete_Impl @@ -91,7 +91,7 @@ int32 OS_TimeBaseSet_Impl(osal_index_t timebase_id, uint32 start_time, uint32 in Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_TimeBaseDelete_Impl(osal_index_t timebase_id); +int32 OS_TimeBaseDelete_Impl(const OS_object_token_t *token); /**************************************************************************************** INTERNAL FUNCTIONS @@ -103,7 +103,7 @@ int32 OS_TimeBaseDelete_Impl(osal_index_t timebase_id); Purpose: Get exclusive access to the given timebase Add/remove of application callbacks is prevented ------------------------------------------------------------------*/ -void OS_TimeBaseLock_Impl(osal_index_t timebase_id); +void OS_TimeBaseLock_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_TimeBaseLock_Impl @@ -111,7 +111,7 @@ void OS_TimeBaseLock_Impl(osal_index_t timebase_id); Purpose: Release exclusive access to the given timebase Add/remove of application callbacks is allowed ------------------------------------------------------------------*/ -void OS_TimeBaseUnlock_Impl(osal_index_t timebase_id); +void OS_TimeBaseUnlock_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- Function: OS_TimeBaseGetInfo_Impl @@ -120,7 +120,7 @@ void OS_TimeBaseUnlock_Impl(osal_index_t timebase_id); Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_TimeBaseGetInfo_Impl(osal_index_t timer_id, OS_timebase_prop_t *timer_prop); +int32 OS_TimeBaseGetInfo_Impl(const OS_object_token_t *token, OS_timebase_prop_t *timer_prop); /*---------------------------------------------------------------- Function: OS_TimeBase_CallbackThread diff --git a/src/os/shared/src/osapi-binsem.c b/src/os/shared/src/osapi-binsem.c index d46bfee21..8fbe7ec20 100644 --- a/src/os/shared/src/osapi-binsem.c +++ b/src/os/shared/src/osapi-binsem.c @@ -121,7 +121,7 @@ int32 OS_BinSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initia OS_OBJECT_INIT(token, binsem, obj_name, sem_name); /* Now call the OS-specific implementation. This reads info from the table. */ - return_code = OS_BinSemCreate_Impl(OS_ObjectIndexFromToken(&token), sem_initial_value, options); + return_code = OS_BinSemCreate_Impl(&token, sem_initial_value, options); /* Check result, finalize record, and unlock global table. */ return_code = OS_ObjectIdFinalizeNew(return_code, &token, sem_id); @@ -147,7 +147,7 @@ int32 OS_BinSemDelete(osal_id_t sem_id) return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_BinSemDelete_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_BinSemDelete_Impl(&token); /* Complete the operation via the common routine */ return_code = OS_ObjectIdFinalizeDelete(return_code, &token); @@ -174,7 +174,7 @@ int32 OS_BinSemGive(osal_id_t sem_id) return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_BinSemGive_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_BinSemGive_Impl(&token); } return return_code; @@ -198,7 +198,7 @@ int32 OS_BinSemFlush(osal_id_t sem_id) return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_BinSemFlush_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_BinSemFlush_Impl(&token); } return return_code; @@ -221,7 +221,7 @@ int32 OS_BinSemTake(osal_id_t sem_id) return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_BinSemTake_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_BinSemTake_Impl(&token); } return return_code; @@ -244,7 +244,7 @@ int32 OS_BinSemTimedWait(osal_id_t sem_id, uint32 msecs) return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_BinSemTimedWait_Impl(OS_ObjectIndexFromToken(&token), msecs); + return_code = OS_BinSemTimedWait_Impl(&token, msecs); } return return_code; @@ -302,7 +302,7 @@ int32 OS_BinSemGetInfo(osal_id_t sem_id, OS_bin_sem_prop_t *bin_prop) strncpy(bin_prop->name, record->name_entry, OS_MAX_API_NAME - 1); bin_prop->creator = record->creator; - return_code = OS_BinSemGetInfo_Impl(OS_ObjectIndexFromToken(&token), bin_prop); + return_code = OS_BinSemGetInfo_Impl(&token, bin_prop); OS_ObjectIdRelease(&token); } diff --git a/src/os/shared/src/osapi-countsem.c b/src/os/shared/src/osapi-countsem.c index a47988841..a73f55843 100644 --- a/src/os/shared/src/osapi-countsem.c +++ b/src/os/shared/src/osapi-countsem.c @@ -113,7 +113,7 @@ int32 OS_CountSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_init OS_OBJECT_INIT(token, countsem, obj_name, sem_name); /* Now call the OS-specific implementation. This reads info from the table. */ - return_code = OS_CountSemCreate_Impl(OS_ObjectIndexFromToken(&token), sem_initial_value, options); + return_code = OS_CountSemCreate_Impl(&token, sem_initial_value, options); /* Check result, finalize record, and unlock global table. */ return_code = OS_ObjectIdFinalizeNew(return_code, &token, sem_id); @@ -139,7 +139,7 @@ int32 OS_CountSemDelete(osal_id_t sem_id) return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_CountSemDelete_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_CountSemDelete_Impl(&token); /* Complete the operation via the common routine */ return_code = OS_ObjectIdFinalizeDelete(return_code, &token); @@ -166,7 +166,7 @@ int32 OS_CountSemGive(osal_id_t sem_id) return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_CountSemGive_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_CountSemGive_Impl(&token); } return return_code; @@ -190,7 +190,7 @@ int32 OS_CountSemTake(osal_id_t sem_id) return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_CountSemTake_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_CountSemTake_Impl(&token); } return return_code; @@ -213,7 +213,7 @@ int32 OS_CountSemTimedWait(osal_id_t sem_id, uint32 msecs) return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_CountSemTimedWait_Impl(OS_ObjectIndexFromToken(&token), msecs); + return_code = OS_CountSemTimedWait_Impl(&token, msecs); } return return_code; @@ -272,7 +272,7 @@ int32 OS_CountSemGetInfo(osal_id_t sem_id, OS_count_sem_prop_t *count_prop) strncpy(count_prop->name, record->name_entry, OS_MAX_API_NAME - 1); count_prop->creator = record->creator; - return_code = OS_CountSemGetInfo_Impl(OS_ObjectIndexFromToken(&token), count_prop); + return_code = OS_CountSemGetInfo_Impl(&token, count_prop); OS_ObjectIdRelease(&token); } diff --git a/src/os/shared/src/osapi-dir.c b/src/os/shared/src/osapi-dir.c index 7f9ac053b..0c82b98a6 100644 --- a/src/os/shared/src/osapi-dir.c +++ b/src/os/shared/src/osapi-dir.c @@ -134,7 +134,7 @@ int32 OS_DirectoryOpen(osal_id_t *dir_id, const char *path) OS_OBJECT_INIT(token, dir, dir_name, path); /* Now call the OS-specific implementation. */ - return_code = OS_DirOpen_Impl(OS_ObjectIndexFromToken(&token), local_path); + return_code = OS_DirOpen_Impl(&token, local_path); /* Check result, finalize record, and unlock global table. */ return_code = OS_ObjectIdFinalizeNew(return_code, &token, dir_id); @@ -161,7 +161,7 @@ int32 OS_DirectoryClose(osal_id_t dir_id) return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, dir_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_DirClose_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_DirClose_Impl(&token); /* Complete the operation via the common routine */ return_code = OS_ObjectIdFinalizeDelete(return_code, &token); @@ -202,7 +202,7 @@ int32 OS_DirectoryRead(osal_id_t dir_id, os_dirent_t *dirent) * reads the "/" directory, the application will see the * real name (eeprom) and not the virtualized name (cf). */ - return_code = OS_DirRead_Impl(OS_ObjectIndexFromToken(&token), dirent); + return_code = OS_DirRead_Impl(&token, dirent); OS_ObjectIdRelease(&token); } @@ -228,7 +228,7 @@ int32 OS_DirectoryRewind(osal_id_t dir_id) return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, dir_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_DirRewind_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_DirRewind_Impl(&token); } return return_code; diff --git a/src/os/shared/src/osapi-file.c b/src/os/shared/src/osapi-file.c index 1dc99247a..2b045375b 100644 --- a/src/os/shared/src/osapi-file.c +++ b/src/os/shared/src/osapi-file.c @@ -124,7 +124,7 @@ int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 acc OS_OBJECT_INIT(token, stream, stream_name, path); /* Now call the OS-specific implementation. */ - return_code = OS_FileOpen_Impl(OS_ObjectIndexFromToken(&token), local_path, flags, access); + return_code = OS_FileOpen_Impl(&token, local_path, flags, access); /* Check result, finalize record, and unlock global table. */ return_code = OS_ObjectIdFinalizeNew(return_code, &token, filedes); @@ -234,7 +234,7 @@ int32 OS_close(osal_id_t filedes) return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, filedes, &token); if (return_code == OS_SUCCESS) { - return_code = OS_GenericClose_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_GenericClose_Impl(&token); /* Complete the operation via the common routine */ return_code = OS_ObjectIdFinalizeDelete(return_code, &token); @@ -266,7 +266,8 @@ int32 OS_TimedRead(osal_id_t filedes, void *buffer, size_t nbytes, int32 timeout return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, filedes, &token); if (return_code == OS_SUCCESS) { - return_code = OS_GenericRead_Impl(OS_ObjectIndexFromToken(&token), buffer, nbytes, timeout); + return_code = OS_GenericRead_Impl(&token, buffer, nbytes, timeout); + OS_ObjectIdRelease(&token); } @@ -295,7 +296,7 @@ int32 OS_TimedWrite(osal_id_t filedes, const void *buffer, size_t nbytes, int32 return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, filedes, &token); if (return_code == OS_SUCCESS) { - return_code = OS_GenericWrite_Impl(OS_ObjectIndexFromToken(&token), buffer, nbytes, timeout); + return_code = OS_GenericWrite_Impl(&token, buffer, nbytes, timeout); OS_ObjectIdRelease(&token); } @@ -397,7 +398,7 @@ int32 OS_lseek(osal_id_t filedes, int32 offset, uint32 whence) return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, filedes, &token); if (return_code == OS_SUCCESS) { - return_code = OS_GenericSeek_Impl(OS_ObjectIndexFromToken(&token), offset, whence); + return_code = OS_GenericSeek_Impl(&token, offset, whence); OS_ObjectIdRelease(&token); } diff --git a/src/os/shared/src/osapi-filesys.c b/src/os/shared/src/osapi-filesys.c index d791c7d05..3c51d646e 100644 --- a/src/os/shared/src/osapi-filesys.c +++ b/src/os/shared/src/osapi-filesys.c @@ -74,12 +74,14 @@ const char OS_FILESYS_RAMDISK_VOLNAME_PREFIX[] = "RAM"; * Returns: true if the entry matches, false if it does not match * *-----------------------------------------------------------------*/ -bool OS_FileSys_FindVirtMountPoint(void *ref, osal_index_t local_id, const OS_common_record_t *obj) +bool OS_FileSys_FindVirtMountPoint(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) { - OS_filesys_internal_record_t *filesys = &OS_filesys_table[local_id]; - const char * target = (const char *)ref; + OS_filesys_internal_record_t *filesys; + const char * target = (const char *)ref; size_t mplen; + filesys = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + if ((filesys->flags & OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL) == 0) { return false; @@ -157,7 +159,7 @@ int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fs filesys->fstype = OS_FILESYS_TYPE_VOLATILE_DISK; } - return_code = OS_FileSysStartVolume_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_FileSysStartVolume_Impl(&token); if (return_code == OS_SUCCESS) { @@ -167,7 +169,7 @@ int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fs */ if (should_format) { - return_code = OS_FileSysFormatVolume_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_FileSysFormatVolume_Impl(&token); } if (return_code == OS_SUCCESS) @@ -182,7 +184,7 @@ int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fs * Cast to void to repress analysis warnings for * ignored return value. */ - (void)OS_FileSysStopVolume_Impl(OS_ObjectIndexFromToken(&token)); + (void)OS_FileSysStopVolume_Impl(&token); } } @@ -282,12 +284,12 @@ int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const * The "mount" implementation is required as it will * create the mountpoint if it does not already exist */ - return_code = OS_FileSysStartVolume_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_FileSysStartVolume_Impl(&token); if (return_code == OS_SUCCESS) { filesys->flags |= OS_FILESYS_FLAG_IS_READY; - return_code = OS_FileSysMountVolume_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_FileSysMountVolume_Impl(&token); } if (return_code == OS_SUCCESS) @@ -369,7 +371,7 @@ int32 OS_rmfs(const char *devname) * the filesystem is unmounted first, but this would break * compatibility with the existing unit tests. */ - return_code = OS_FileSysStopVolume_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_FileSysStopVolume_Impl(&token); /* Free the entry in the master table */ return_code = OS_ObjectIdFinalizeDelete(return_code, &token); @@ -463,7 +465,7 @@ int32 OS_mount(const char *devname, const char *mountpoint) } else { - return_code = OS_FileSysMountVolume_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_FileSysMountVolume_Impl(&token); } if (return_code == OS_SUCCESS) @@ -533,7 +535,7 @@ int32 OS_unmount(const char *mountpoint) } else { - return_code = OS_FileSysUnmountVolume_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_FileSysUnmountVolume_Impl(&token); } if (return_code == OS_SUCCESS) @@ -583,7 +585,7 @@ int32 OS_fsBlocksFree(const char *name) if (return_code == OS_SUCCESS) { - return_code = OS_FileSysStatVolume_Impl(OS_ObjectIndexFromToken(&token), &statfs); + return_code = OS_FileSysStatVolume_Impl(&token, &statfs); OS_ObjectIdRelease(&token); @@ -631,7 +633,7 @@ int32 OS_fsBytesFree(const char *name, uint64 *bytes_free) if (return_code == OS_SUCCESS) { - return_code = OS_FileSysStatVolume_Impl(OS_ObjectIndexFromToken(&token), &statfs); + return_code = OS_FileSysStatVolume_Impl(&token, &statfs); OS_ObjectIdRelease(&token); @@ -685,7 +687,7 @@ int32 OS_chkfs(const char *name, bool repair) if (return_code == OS_SUCCESS) { - return_code = OS_FileSysCheckVolume_Impl(OS_ObjectIndexFromToken(&token), repair); + return_code = OS_FileSysCheckVolume_Impl(&token, repair); OS_ObjectIdRelease(&token); } diff --git a/src/os/shared/src/osapi-idmap.c b/src/os/shared/src/osapi-idmap.c index 44fee7580..0ccaf16f0 100644 --- a/src/os/shared/src/osapi-idmap.c +++ b/src/os/shared/src/osapi-idmap.c @@ -240,7 +240,7 @@ OS_common_record_t *OS_ObjectIdGlobalFromToken(const OS_object_token_t *token) * returns: true if match, false otherwise * *-----------------------------------------------------------------*/ -bool OS_ObjectNameMatch(void *ref, osal_index_t local_id, const OS_common_record_t *obj) +bool OS_ObjectNameMatch(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) { return (obj->name_entry != NULL && strcmp((const char *)ref, obj->name_entry) == 0); } /* end OS_ObjectNameMatch */ @@ -504,7 +504,7 @@ int32 OS_ObjectIdFindNextMatch(OS_ObjectMatchFunc_t MatchFunc, void *arg, OS_obj record = OS_OBJECT_TABLE_GET(base, *token); - if (OS_ObjectIdDefined(record->active_id) && MatchFunc(arg, token->obj_idx, record)) + if (OS_ObjectIdDefined(record->active_id) && MatchFunc(arg, token, record)) { return_code = OS_SUCCESS; token->obj_id = record->active_id; @@ -1172,7 +1172,7 @@ int32 OS_ObjectIdIteratorInit(OS_ObjectMatchFunc_t matchfunc, void *matcharg, os Purpose: Match function to iterate only active objects ------------------------------------------------------------------*/ -bool OS_ObjectFilterActive(void *ref, osal_index_t local_id, const OS_common_record_t *obj) +bool OS_ObjectFilterActive(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) { return OS_ObjectIdDefined(obj->active_id); } @@ -1209,7 +1209,7 @@ bool OS_ObjectIdIteratorGetNext(OS_object_iter_t *iter) } record = OS_OBJECT_TABLE_GET(iter->base, iter->token); - if (iter->match == NULL || iter->match(iter->arg, iter->token.obj_idx, record)) + if (iter->match == NULL || iter->match(iter->arg, &iter->token, record)) { iter->token.obj_id = record->active_id; got_next = true; diff --git a/src/os/shared/src/osapi-module.c b/src/os/shared/src/osapi-module.c index 6510bf44c..ad42b5fd0 100644 --- a/src/os/shared/src/osapi-module.c +++ b/src/os/shared/src/osapi-module.c @@ -260,7 +260,7 @@ int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *f module->module_type = OS_MODULE_TYPE_DYNAMIC; /* Now call the OS-specific implementation. This reads info from the module table. */ - return_code = OS_ModuleLoad_Impl(OS_ObjectIndexFromToken(&token), translated_path); + return_code = OS_ModuleLoad_Impl(&token, translated_path); } } @@ -298,7 +298,7 @@ int32 OS_ModuleUnload(osal_id_t module_id) */ if (module->module_type == OS_MODULE_TYPE_DYNAMIC) { - return_code = OS_ModuleUnload_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_ModuleUnload_Impl(&token); } /* Complete the operation via the common routine */ @@ -340,7 +340,7 @@ int32 OS_ModuleInfo(osal_id_t module_id, OS_module_prop_t *module_prop) strncpy(module_prop->name, record->name_entry, OS_MAX_API_NAME - 1); strncpy(module_prop->filename, module->file_name, OS_MAX_API_NAME - 1); - return_code = OS_ModuleGetInfo_Impl(OS_ObjectIndexFromToken(&token), module_prop); + return_code = OS_ModuleGetInfo_Impl(&token, module_prop); OS_ObjectIdRelease(&token); } @@ -425,7 +425,7 @@ int32 OS_ModuleSymbolLookup(osal_id_t module_id, cpuaddr *symbol_address, const { record = OS_OBJECT_TABLE_GET(OS_global_module_table, token); - return_code = OS_ModuleSymbolLookup_Impl(OS_ObjectIndexFromToken(&token), symbol_address, symbol_name); + return_code = OS_ModuleSymbolLookup_Impl(&token, symbol_address, symbol_name); if (return_code != OS_SUCCESS) { /* look for a static symbol that also matches this module name */ diff --git a/src/os/shared/src/osapi-mutex.c b/src/os/shared/src/osapi-mutex.c index 73c9adab1..e861ff667 100644 --- a/src/os/shared/src/osapi-mutex.c +++ b/src/os/shared/src/osapi-mutex.c @@ -113,7 +113,7 @@ int32 OS_MutSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 options) OS_OBJECT_INIT(token, mutex, obj_name, sem_name); /* Now call the OS-specific implementation. This reads info from the table. */ - return_code = OS_MutSemCreate_Impl(OS_ObjectIndexFromToken(&token), options); + return_code = OS_MutSemCreate_Impl(&token, options); /* Check result, finalize record, and unlock global table. */ return_code = OS_ObjectIdFinalizeNew(return_code, &token, sem_id); @@ -139,7 +139,7 @@ int32 OS_MutSemDelete(osal_id_t sem_id) return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, sem_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_MutSemDelete_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_MutSemDelete_Impl(&token); /* Complete the operation via the common routine */ return_code = OS_ObjectIdFinalizeDelete(return_code, &token); @@ -180,7 +180,7 @@ int32 OS_MutSemGive(osal_id_t sem_id) mutex->last_owner = OS_OBJECT_ID_UNDEFINED; - return_code = OS_MutSemGive_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_MutSemGive_Impl(&token); } return return_code; @@ -208,7 +208,7 @@ int32 OS_MutSemTake(osal_id_t sem_id) { mutex = OS_OBJECT_TABLE_GET(OS_mutex_table, token); - return_code = OS_MutSemTake_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_MutSemTake_Impl(&token); if (return_code == OS_SUCCESS) { self_task = OS_TaskGetId(); @@ -281,7 +281,7 @@ int32 OS_MutSemGetInfo(osal_id_t sem_id, OS_mut_sem_prop_t *mut_prop) strncpy(mut_prop->name, record->name_entry, OS_MAX_API_NAME - 1); mut_prop->creator = record->creator; - return_code = OS_MutSemGetInfo_Impl(OS_ObjectIndexFromToken(&token), mut_prop); + return_code = OS_MutSemGetInfo_Impl(&token, mut_prop); OS_ObjectIdRelease(&token); } diff --git a/src/os/shared/src/osapi-printf.c b/src/os/shared/src/osapi-printf.c index edcc033b5..780476a72 100644 --- a/src/os/shared/src/osapi-printf.c +++ b/src/os/shared/src/osapi-printf.c @@ -99,7 +99,7 @@ int32 OS_ConsoleAPI_Init(void) console->BufBase = OS_printf_buffer_mem; console->BufSize = sizeof(OS_printf_buffer_mem); - return_code = OS_ConsoleCreate_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_ConsoleCreate_Impl(&token); /* Check result, finalize record, and unlock global table. */ return_code = OS_ObjectIdFinalizeNew(return_code, &token, &OS_SharedGlobalVars.PrintfConsoleId); @@ -233,7 +233,7 @@ int32 OS_ConsoleWrite(osal_id_t console_id, const char *Str) * This is done while still locked, so it can support * either a synchronous or asynchronous implementation. */ - OS_ConsoleWakeup_Impl(OS_ObjectIndexFromToken(&token)); + OS_ConsoleWakeup_Impl(&token); OS_ObjectIdRelease(&token); } diff --git a/src/os/shared/src/osapi-queue.c b/src/os/shared/src/osapi-queue.c index 0105db711..509680df7 100644 --- a/src/os/shared/src/osapi-queue.c +++ b/src/os/shared/src/osapi-queue.c @@ -122,7 +122,7 @@ int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, osal_blockcoun queue->max_size = data_size; /* Now call the OS-specific implementation. This reads info from the queue table. */ - return_code = OS_QueueCreate_Impl(OS_ObjectIndexFromToken(&token), flags); + return_code = OS_QueueCreate_Impl(&token, flags); /* Check result, finalize record, and unlock global table. */ return_code = OS_ObjectIdFinalizeNew(return_code, &token, queue_id); @@ -148,7 +148,7 @@ int32 OS_QueueDelete(osal_id_t queue_id) return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, queue_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_QueueDelete_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_QueueDelete_Impl(&token); /* Complete the operation via the common routine */ return_code = OS_ObjectIdFinalizeDelete(return_code, &token); @@ -194,7 +194,7 @@ int32 OS_QueueGet(osal_id_t queue_id, void *data, size_t size, size_t *size_copi } else { - return_code = OS_QueueGet_Impl(OS_ObjectIndexFromToken(&token), data, size, size_copied, timeout); + return_code = OS_QueueGet_Impl(&token, data, size, size_copied, timeout); } } } @@ -237,7 +237,7 @@ int32 OS_QueuePut(osal_id_t queue_id, const void *data, size_t size, uint32 flag } else { - return_code = OS_QueuePut_Impl(OS_ObjectIndexFromToken(&token), data, size, flags); + return_code = OS_QueuePut_Impl(&token, data, size, flags); } } } diff --git a/src/os/shared/src/osapi-select.c b/src/os/shared/src/osapi-select.c index cb759afb5..cecad98c0 100644 --- a/src/os/shared/src/osapi-select.c +++ b/src/os/shared/src/osapi-select.c @@ -69,7 +69,7 @@ int32 OS_SelectSingle(osal_id_t objid, uint32 *StateFlags, int32 msecs) return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_STREAM, objid, &token); if (return_code == OS_SUCCESS) { - return_code = OS_SelectSingle_Impl(OS_ObjectIndexFromToken(&token), StateFlags, msecs); + return_code = OS_SelectSingle_Impl(&token, StateFlags, msecs); OS_ObjectIdRelease(&token); } diff --git a/src/os/shared/src/osapi-shell.c b/src/os/shared/src/osapi-shell.c index e35e103f2..62e182fcc 100644 --- a/src/os/shared/src/osapi-shell.c +++ b/src/os/shared/src/osapi-shell.c @@ -64,7 +64,7 @@ int32 OS_ShellOutputToFile(const char *Cmd, osal_id_t filedes) return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_STREAM, filedes, &token); if (return_code == OS_SUCCESS) { - return_code = OS_ShellOutputToFile_Impl(OS_ObjectIndexFromToken(&token), Cmd); + return_code = OS_ShellOutputToFile_Impl(&token, Cmd); OS_ObjectIdRelease(&token); } diff --git a/src/os/shared/src/osapi-sockets.c b/src/os/shared/src/osapi-sockets.c index de9e9022b..99c2968ee 100644 --- a/src/os/shared/src/osapi-sockets.c +++ b/src/os/shared/src/osapi-sockets.c @@ -84,11 +84,13 @@ int32 OS_SocketAPI_Init(void) * Purpose: Local helper routine, not part of OSAL API. * *-----------------------------------------------------------------*/ -void OS_CreateSocketName(osal_index_t local_id, const OS_SockAddr_t *Addr, const char *parent_name) +void OS_CreateSocketName(const OS_object_token_t *token, const OS_SockAddr_t *Addr, const char *parent_name) { size_t len; uint16 port; - OS_stream_internal_record_t *sock = &OS_stream_table[local_id]; + OS_stream_internal_record_t *sock; + + sock = OS_OBJECT_TABLE_GET(OS_stream_table, *token); if (OS_SocketAddrToString_Impl(sock->stream_name, OS_MAX_API_NAME, Addr) != OS_SUCCESS) { @@ -142,7 +144,7 @@ int32 OS_SocketOpen(osal_id_t *sock_id, OS_SocketDomain_t Domain, OS_SocketType_ stream->socket_type = Type; /* Now call the OS-specific implementation. This reads info from the table. */ - return_code = OS_SocketOpen_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_SocketOpen_Impl(&token); /* Check result, finalize record, and unlock global table. */ return_code = OS_ObjectIdFinalizeNew(return_code, &token, sock_id); @@ -190,11 +192,11 @@ int32 OS_SocketBind(osal_id_t sock_id, const OS_SockAddr_t *Addr) } else { - return_code = OS_SocketBind_Impl(OS_ObjectIndexFromToken(&token), Addr); + return_code = OS_SocketBind_Impl(&token, Addr); if (return_code == OS_SUCCESS) { - OS_CreateSocketName(OS_ObjectIndexFromToken(&token), Addr, NULL); + OS_CreateSocketName(&token, Addr, NULL); record->name_entry = stream->stream_name; stream->stream_state |= OS_STREAM_STATE_BOUND; } @@ -290,8 +292,7 @@ int32 OS_SocketAccept(osal_id_t sock_id, osal_id_t *connsock_id, OS_SockAddr_t * OS_SocketAddrInit_Impl(Addr, sock->socket_domain); /* The actual accept impl is done without global table lock, only refcount lock */ - return_code = OS_SocketAccept_Impl(OS_ObjectIndexFromToken(&sock_token), OS_ObjectIndexFromToken(&conn_token), - Addr, timeout); + return_code = OS_SocketAccept_Impl(&sock_token, &conn_token, Addr, timeout); } if (conn_record != NULL) @@ -301,7 +302,7 @@ int32 OS_SocketAccept(osal_id_t sock_id, osal_id_t *connsock_id, OS_SockAddr_t * if (return_code == OS_SUCCESS) { /* Generate an entry name based on the remote address */ - OS_CreateSocketName(OS_ObjectIndexFromToken(&conn_token), Addr, sock_record->name_entry); + OS_CreateSocketName(&conn_token, Addr, sock_record->name_entry); conn_record->name_entry = conn->stream_name; conn->stream_state |= OS_STREAM_STATE_CONNECTED; } @@ -367,7 +368,7 @@ int32 OS_SocketConnect(osal_id_t sock_id, const OS_SockAddr_t *Addr, int32 Timeo if (return_code == OS_SUCCESS) { - return_code = OS_SocketConnect_Impl(OS_ObjectIndexFromToken(&token), Addr, Timeout); + return_code = OS_SocketConnect_Impl(&token, Addr, Timeout); OS_Lock_Global(LOCAL_OBJID_TYPE); if (return_code == OS_SUCCESS) @@ -417,7 +418,7 @@ int32 OS_SocketRecvFrom(osal_id_t sock_id, void *buffer, size_t buflen, OS_SockA } else { - return_code = OS_SocketRecvFrom_Impl(OS_ObjectIndexFromToken(&token), buffer, buflen, RemoteAddr, timeout); + return_code = OS_SocketRecvFrom_Impl(&token, buffer, buflen, RemoteAddr, timeout); } OS_ObjectIdRelease(&token); @@ -457,7 +458,7 @@ int32 OS_SocketSendTo(osal_id_t sock_id, const void *buffer, size_t buflen, cons } else { - return_code = OS_SocketSendTo_Impl(OS_ObjectIndexFromToken(&token), buffer, buflen, RemoteAddr); + return_code = OS_SocketSendTo_Impl(&token, buffer, buflen, RemoteAddr); } OS_ObjectIdRelease(&token); @@ -518,7 +519,7 @@ int32 OS_SocketGetInfo(osal_id_t sock_id, OS_socket_prop_t *sock_prop) strncpy(sock_prop->name, record->name_entry, OS_MAX_API_NAME - 1); sock_prop->creator = record->creator; - return_code = OS_SocketGetInfo_Impl(OS_ObjectIndexFromToken(&token), sock_prop); + return_code = OS_SocketGetInfo_Impl(&token, sock_prop); OS_ObjectIdRelease(&token); } diff --git a/src/os/shared/src/osapi-task.c b/src/os/shared/src/osapi-task.c index 88777744b..54738a855 100644 --- a/src/os/shared/src/osapi-task.c +++ b/src/os/shared/src/osapi-task.c @@ -90,7 +90,7 @@ static int32 OS_TaskPrepare(osal_id_t task_id, osal_task_entry *entrypt) { task = OS_OBJECT_TABLE_GET(OS_task_table, token); - return_code = OS_TaskMatch_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_TaskMatch_Impl(&token); *entrypt = task->entry_function_pointer; OS_ObjectIdRelease(&token); @@ -213,7 +213,7 @@ int32 OS_TaskCreate(osal_id_t *task_id, const char *task_name, osal_task_entry f task->stack_pointer = stack_pointer; /* Now call the OS-specific implementation. This reads info from the task table. */ - return_code = OS_TaskCreate_Impl(OS_ObjectIndexFromToken(&token), flags); + return_code = OS_TaskCreate_Impl(&token, flags); /* Check result, finalize record, and unlock global table. */ return_code = OS_ObjectIdFinalizeNew(return_code, &token, task_id); @@ -246,7 +246,7 @@ int32 OS_TaskDelete(osal_id_t task_id) /* Save the delete hook, as we do not want to call it while locked */ delete_hook = task->delete_hook_pointer; - return_code = OS_TaskDelete_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_TaskDelete_Impl(&token); /* Complete the operation via the common routine */ return_code = OS_ObjectIdFinalizeDelete(return_code, &token); @@ -322,7 +322,7 @@ int32 OS_TaskSetPriority(osal_id_t task_id, osal_priority_t new_priority) { task = OS_OBJECT_TABLE_GET(OS_task_table, token); - return_code = OS_TaskSetPriority_Impl(OS_ObjectIndexFromToken(&token), new_priority); + return_code = OS_TaskSetPriority_Impl(&token, new_priority); if (return_code == OS_SUCCESS) { @@ -442,7 +442,7 @@ int32 OS_TaskGetInfo(osal_id_t task_id, OS_task_prop_t *task_prop) task_prop->stack_size = task->stack_size; task_prop->priority = task->priority; - return_code = OS_TaskGetInfo_Impl(OS_ObjectIndexFromToken(&token), task_prop); + return_code = OS_TaskGetInfo_Impl(&token, task_prop); OS_ObjectIdRelease(&token); } diff --git a/src/os/shared/src/osapi-time.c b/src/os/shared/src/osapi-time.c index ed79e9bca..6c78ea160 100644 --- a/src/os/shared/src/osapi-time.c +++ b/src/os/shared/src/osapi-time.c @@ -173,7 +173,7 @@ static int32 OS_DoTimerAdd(osal_id_t *timer_id, const char *timer_name, osal_id_ * Now we need to add it to the time base callback ring, so take the * timebase-specific lock to prevent a tick from being processed at this moment. */ - OS_TimeBaseLock_Impl(OS_ObjectIndexFromToken(&timebase_token)); + OS_TimeBaseLock_Impl(&timebase_token); cb_list = timebase->first_cb; timebase->first_cb = OS_ObjectIdFromToken(&timecb_token); @@ -187,7 +187,7 @@ static int32 OS_DoTimerAdd(osal_id_t *timer_id, const char *timer_name, osal_id_ OS_timecb_table[timecb->next_ref].prev_ref = OS_ObjectIndexFromToken(&timecb_token); } - OS_TimeBaseUnlock_Impl(OS_ObjectIndexFromToken(&timebase_token)); + OS_TimeBaseUnlock_Impl(&timebase_token); /* Check result, finalize record, and unlock global table. */ return_code = OS_ObjectIdFinalizeNew(return_code, &timecb_token, timer_id); @@ -349,7 +349,7 @@ int32 OS_TimerSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time) { timecb = OS_OBJECT_TABLE_GET(OS_timecb_table, token); - OS_TimeBaseLock_Impl(OS_ObjectIndexFromToken(&timecb->timebase_token)); + OS_TimeBaseLock_Impl(&timecb->timebase_token); if ((timecb->flags & TIMECB_FLAG_DEDICATED_TIMEBASE) != 0) { @@ -359,7 +359,7 @@ int32 OS_TimerSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time) timecb->wait_time = (int32)start_time; timecb->interval_time = (int32)interval_time; - OS_TimeBaseUnlock_Impl(OS_ObjectIndexFromToken(&timecb->timebase_token)); + OS_TimeBaseUnlock_Impl(&timecb->timebase_token); OS_ObjectIdRelease(&token); } @@ -423,7 +423,7 @@ int32 OS_TimerDelete(osal_id_t timer_id) OS_ObjectIdTransferToken(&timecb->timebase_token, &timebase_token); - OS_TimeBaseLock_Impl(OS_ObjectIndexFromToken(&timecb->timebase_token)); + OS_TimeBaseLock_Impl(&timecb->timebase_token); /* * If the timer uses a dedicated time base, then also delete that. @@ -456,7 +456,7 @@ int32 OS_TimerDelete(osal_id_t timer_id) timecb->next_ref = OS_ObjectIndexFromToken(&timecb_token); timecb->prev_ref = OS_ObjectIndexFromToken(&timecb_token); - OS_TimeBaseUnlock_Impl(OS_ObjectIndexFromToken(&timecb->timebase_token)); + OS_TimeBaseUnlock_Impl(&timecb->timebase_token); /* Complete the operation via the common routine */ return_code = OS_ObjectIdFinalizeDelete(return_code, &timecb_token); diff --git a/src/os/shared/src/osapi-timebase.c b/src/os/shared/src/osapi-timebase.c index 491bf4d6f..62e935a95 100644 --- a/src/os/shared/src/osapi-timebase.c +++ b/src/os/shared/src/osapi-timebase.c @@ -155,7 +155,7 @@ int32 OS_TimeBaseCreate(osal_id_t *timer_id, const char *timebase_name, OS_Timer } /* Now call the OS-specific implementation. This reads info from the timer table. */ - return_code = OS_TimeBaseCreate_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_TimeBaseCreate_Impl(&token); /* Check result, finalize record, and unlock global table. */ return_code = OS_ObjectIdFinalizeNew(return_code, &token, timer_id); @@ -208,9 +208,9 @@ int32 OS_TimeBaseSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, token); /* Need to take the time base lock to ensure that no ticks are currently being processed */ - OS_TimeBaseLock_Impl(OS_ObjectIndexFromToken(&token)); + OS_TimeBaseLock_Impl(&token); - return_code = OS_TimeBaseSet_Impl(OS_ObjectIndexFromToken(&token), start_time, interval_time); + return_code = OS_TimeBaseSet_Impl(&token, start_time, interval_time); if (return_code == OS_SUCCESS) { @@ -219,7 +219,7 @@ int32 OS_TimeBaseSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time timebase->nominal_interval_time = interval_time; } - OS_TimeBaseUnlock_Impl(OS_ObjectIndexFromToken(&token)); + OS_TimeBaseUnlock_Impl(&token); OS_ObjectIdRelease(&token); } @@ -254,7 +254,7 @@ int32 OS_TimeBaseDelete(osal_id_t timer_id) return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_TIMEBASE, timer_id, &token); if (return_code == OS_SUCCESS) { - return_code = OS_TimeBaseDelete_Impl(OS_ObjectIndexFromToken(&token)); + return_code = OS_TimeBaseDelete_Impl(&token); /* Complete the operation via the common routine */ return_code = OS_ObjectIdFinalizeDelete(return_code, &token); @@ -342,7 +342,7 @@ int32 OS_TimeBaseGetInfo(osal_id_t timebase_id, OS_timebase_prop_t *timebase_pro timebase_prop->freerun_time = timebase->freerun_time; timebase_prop->accuracy = timebase->accuracy_usec; - return_code = OS_TimeBaseGetInfo_Impl(OS_ObjectIndexFromToken(&token), timebase_prop); + return_code = OS_TimeBaseGetInfo_Impl(&token, timebase_prop); OS_ObjectIdRelease(&token); } @@ -438,7 +438,7 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) * Call the sync function - this will pend for some period of time * and return the amount of elapsed time in units of "timebase ticks" */ - tick_time = (*syncfunc)(OS_ObjectIndexFromToken(&token)); + tick_time = (*syncfunc)(timebase_id); /* * The returned tick_time should be nonzero. If the sync function @@ -480,7 +480,7 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) } } - OS_TimeBaseLock_Impl(OS_ObjectIndexFromToken(&token)); + OS_TimeBaseLock_Impl(&token); /* * After waiting, check that our ID still matches @@ -488,7 +488,7 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) */ if (!OS_ObjectIdEqual(timebase_id, record->active_id)) { - OS_TimeBaseUnlock_Impl(OS_ObjectIndexFromToken(&token)); + OS_TimeBaseUnlock_Impl(&token); break; } @@ -540,7 +540,7 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) } while (curr_cb_local_id != timer_id); } - OS_TimeBaseUnlock_Impl(OS_ObjectIndexFromToken(&token)); + OS_TimeBaseUnlock_Impl(&token); } } /* end OS_TimeBase_CallbackThread */ diff --git a/src/os/vxworks/inc/os-vxworks.h b/src/os/vxworks/inc/os-vxworks.h index 997a12aaa..88bbe1826 100644 --- a/src/os/vxworks/inc/os-vxworks.h +++ b/src/os/vxworks/inc/os-vxworks.h @@ -94,7 +94,7 @@ int OS_VxWorks_ConsoleTask_Entry(int arg); uint32 OS_VxWorks_SigWait(osal_index_t local_id); int OS_VxWorks_TimeBaseTask(int arg); -void OS_VxWorks_RegisterTimer(osal_index_t local_id); +void OS_VxWorks_RegisterTimer(osal_id_t obj_id); void OS_VxWorks_UsecToTimespec(uint32 usecs, struct timespec *time_spec); int32 OS_VxWorks_GenericSemTake(SEM_ID vxid, int sys_ticks); diff --git a/src/os/vxworks/src/os-impl-binsem.c b/src/os/vxworks/src/os-impl-binsem.c index 0f90efd2b..4c9a1acd4 100644 --- a/src/os/vxworks/src/os-impl-binsem.c +++ b/src/os/vxworks/src/os-impl-binsem.c @@ -33,6 +33,7 @@ #include "os-impl-binsem.h" #include "os-shared-binsem.h" #include "os-shared-timebase.h" +#include "os-shared-idmap.h" /**************************************************************************************** DEFINES @@ -70,13 +71,16 @@ int32 OS_VxWorks_BinSemAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemCreate_Impl(osal_index_t sem_id, uint32 sem_initial_value, uint32 options) +int32 OS_BinSemCreate_Impl(const OS_object_token_t *token, uint32 sem_initial_value, uint32 options) { - SEM_ID tmp_sem_id; + SEM_ID tmp_sem_id; + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); /* Initialize VxWorks Semaphore. * The memory for this sem is statically allocated. */ - tmp_sem_id = semBInitialize(OS_impl_bin_sem_table[sem_id].bmem, SEM_Q_PRIORITY, sem_initial_value); + tmp_sem_id = semBInitialize(impl->bmem, SEM_Q_PRIORITY, sem_initial_value); /* check if semBInitialize failed */ if (tmp_sem_id == (SEM_ID)0) @@ -85,7 +89,7 @@ int32 OS_BinSemCreate_Impl(osal_index_t sem_id, uint32 sem_initial_value, uint32 return OS_SEM_FAILURE; } - OS_impl_bin_sem_table[sem_id].vxid = tmp_sem_id; + impl->vxid = tmp_sem_id; return OS_SUCCESS; } /* end OS_BinSemCreate_Impl */ @@ -98,12 +102,16 @@ int32 OS_BinSemCreate_Impl(osal_index_t sem_id, uint32 sem_initial_value, uint32 * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemDelete_Impl(osal_index_t sem_id) +int32 OS_BinSemDelete_Impl(const OS_object_token_t *token) { + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); + /* * As the memory for the sem is statically allocated, delete is a no-op. */ - OS_impl_bin_sem_table[sem_id].vxid = 0; + impl->vxid = 0; return OS_SUCCESS; } /* end OS_BinSemDelete_Impl */ @@ -116,10 +124,14 @@ int32 OS_BinSemDelete_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemGive_Impl(osal_index_t sem_id) +int32 OS_BinSemGive_Impl(const OS_object_token_t *token) { + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); + /* Use common routine */ - return OS_VxWorks_GenericSemGive(OS_impl_bin_sem_table[sem_id].vxid); + return OS_VxWorks_GenericSemGive(impl->vxid); } /* end OS_BinSemGive_Impl */ /*---------------------------------------------------------------- @@ -130,10 +142,14 @@ int32 OS_BinSemGive_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemFlush_Impl(osal_index_t sem_id) +int32 OS_BinSemFlush_Impl(const OS_object_token_t *token) { + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); + /* Flush VxWorks Semaphore */ - if (semFlush(OS_impl_bin_sem_table[sem_id].vxid) != OK) + if (semFlush(impl->vxid) != OK) { OS_DEBUG("semFlush() - vxWorks errno %d\n", errno); return OS_SEM_FAILURE; @@ -150,10 +166,14 @@ int32 OS_BinSemFlush_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemTake_Impl(osal_index_t sem_id) +int32 OS_BinSemTake_Impl(const OS_object_token_t *token) { + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); + /* Use common routine */ - return OS_VxWorks_GenericSemTake(OS_impl_bin_sem_table[sem_id].vxid, WAIT_FOREVER); + return OS_VxWorks_GenericSemTake(impl->vxid, WAIT_FOREVER); } /* end OS_BinSemTake_Impl */ @@ -165,16 +185,19 @@ int32 OS_BinSemTake_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemTimedWait_Impl(osal_index_t sem_id, uint32 msecs) +int32 OS_BinSemTimedWait_Impl(const OS_object_token_t *token, uint32 msecs) { - int ticks; - int32 status; + int ticks; + int32 status; + OS_impl_binsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_bin_sem_table, *token); status = OS_Milli2Ticks(msecs, &ticks); if (status == OS_SUCCESS) { - status = OS_VxWorks_GenericSemTake(OS_impl_bin_sem_table[sem_id].vxid, ticks); + status = OS_VxWorks_GenericSemTake(impl->vxid, ticks); } return status; @@ -188,7 +211,7 @@ int32 OS_BinSemTimedWait_Impl(osal_index_t sem_id, uint32 msecs) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_BinSemGetInfo_Impl(osal_index_t sem_id, OS_bin_sem_prop_t *bin_prop) +int32 OS_BinSemGetInfo_Impl(const OS_object_token_t *token, OS_bin_sem_prop_t *bin_prop) { /* VxWorks has no API for obtaining the current value of a semaphore */ return OS_SUCCESS; diff --git a/src/os/vxworks/src/os-impl-console.c b/src/os/vxworks/src/os-impl-console.c index 7accef4bb..0a8bbe886 100644 --- a/src/os/vxworks/src/os-impl-console.c +++ b/src/os/vxworks/src/os-impl-console.c @@ -32,6 +32,7 @@ #include "os-impl-console.h" #include "os-shared-printf.h" +#include "os-shared-idmap.h" /**************************************************************************************** DEFINES @@ -66,9 +67,11 @@ OS_impl_console_internal_record_t OS_impl_console_table[OS_MAX_CONSOLES]; * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -void OS_ConsoleWakeup_Impl(osal_index_t local_id) +void OS_ConsoleWakeup_Impl(const OS_object_token_t *token) { - OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; + OS_impl_console_internal_record_t *local; + + local = OS_OBJECT_TABLE_GET(OS_impl_console_table, *token); if (local->is_async) { @@ -81,7 +84,7 @@ void OS_ConsoleWakeup_Impl(osal_index_t local_id) else { /* output directly */ - OS_ConsoleOutput_Impl(local_id); + OS_ConsoleOutput_Impl(token); } } /* end OS_ConsoleWakeup_Impl */ @@ -94,18 +97,23 @@ void OS_ConsoleWakeup_Impl(osal_index_t local_id) *-----------------------------------------------------------------*/ int OS_VxWorks_ConsoleTask_Entry(int arg) { - osal_index_t local_id = OSAL_INDEX_C(arg); OS_impl_console_internal_record_t *local; + OS_object_token_t token; - local = &OS_impl_console_table[local_id]; - while (true) + if (OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_CONSOLE, OS_ObjectIdFromInteger(arg), &token) == + OS_SUCCESS) { - OS_ConsoleOutput_Impl(local_id); - if (semTake(local->datasem, WAIT_FOREVER) == ERROR) + local = OS_OBJECT_TABLE_GET(OS_impl_console_table, token); + while (true) { - OS_DEBUG("semTake() - vxWorks errno %d\n", errno); - break; + OS_ConsoleOutput_Impl(&token); + if (semTake(local->datasem, WAIT_FOREVER) == ERROR) + { + OS_DEBUG("semTake() - vxWorks errno %d\n", errno); + break; + } } + OS_ObjectIdRelease(&token); } return OK; @@ -119,12 +127,16 @@ int OS_VxWorks_ConsoleTask_Entry(int arg) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ConsoleCreate_Impl(osal_index_t local_id) +int32 OS_ConsoleCreate_Impl(const OS_object_token_t *token) { - OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; + OS_impl_console_internal_record_t *local; int32 return_code; + OS_console_internal_record_t * console; + + local = OS_OBJECT_TABLE_GET(OS_impl_console_table, *token); + console = OS_OBJECT_TABLE_GET(OS_console_table, *token); - if (local_id == 0) + if (OS_ObjectIndexFromToken(token) == 0) { return_code = OS_SUCCESS; local->is_async = OS_CONSOLE_ASYNC; @@ -145,9 +157,9 @@ int32 OS_ConsoleCreate_Impl(osal_index_t local_id) } /* spawn the async output helper task */ - local->taskid = taskSpawn(OS_console_table[local_id].device_name, OS_CONSOLE_TASK_PRIORITY, 0, - OS_CONSOLE_TASK_STACKSIZE, (FUNCPTR)OS_VxWorks_ConsoleTask_Entry, local_id, 0, 0, - 0, 0, 0, 0, 0, 0, 0); + local->taskid = taskSpawn(console->device_name, OS_CONSOLE_TASK_PRIORITY, 0, OS_CONSOLE_TASK_STACKSIZE, + (FUNCPTR)OS_VxWorks_ConsoleTask_Entry, + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), 0, 0, 0, 0, 0, 0, 0, 0, 0); if (local->taskid == (TASK_ID)ERROR) { diff --git a/src/os/vxworks/src/os-impl-countsem.c b/src/os/vxworks/src/os-impl-countsem.c index 41cff591d..3f4ef65e7 100644 --- a/src/os/vxworks/src/os-impl-countsem.c +++ b/src/os/vxworks/src/os-impl-countsem.c @@ -32,6 +32,7 @@ #include "os-impl-countsem.h" #include "os-shared-countsem.h" #include "os-shared-timebase.h" +#include "os-shared-idmap.h" /**************************************************************************************** DEFINES @@ -69,13 +70,16 @@ int32 OS_VxWorks_CountSemAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemCreate_Impl(osal_index_t sem_id, uint32 sem_initial_value, uint32 options) +int32 OS_CountSemCreate_Impl(const OS_object_token_t *token, uint32 sem_initial_value, uint32 options) { - SEM_ID tmp_sem_id; + SEM_ID tmp_sem_id; + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); /* Initialize VxWorks Semaphore. * The memory for this sem is statically allocated. */ - tmp_sem_id = semCInitialize(OS_impl_count_sem_table[sem_id].cmem, SEM_Q_PRIORITY, sem_initial_value); + tmp_sem_id = semCInitialize(impl->cmem, SEM_Q_PRIORITY, sem_initial_value); /* check if semCInitialize failed */ if (tmp_sem_id == (SEM_ID)0) @@ -84,7 +88,7 @@ int32 OS_CountSemCreate_Impl(osal_index_t sem_id, uint32 sem_initial_value, uint return OS_SEM_FAILURE; } - OS_impl_count_sem_table[sem_id].vxid = tmp_sem_id; + impl->vxid = tmp_sem_id; return OS_SUCCESS; } /* end OS_CountSemCreate_Impl */ @@ -97,12 +101,16 @@ int32 OS_CountSemCreate_Impl(osal_index_t sem_id, uint32 sem_initial_value, uint * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemDelete_Impl(osal_index_t sem_id) +int32 OS_CountSemDelete_Impl(const OS_object_token_t *token) { + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); + /* * As the memory for the sem is statically allocated, delete is a no-op. */ - OS_impl_count_sem_table[sem_id].vxid = 0; + impl->vxid = 0; return OS_SUCCESS; } /* end OS_CountSemDelete_Impl */ @@ -115,10 +123,14 @@ int32 OS_CountSemDelete_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemGive_Impl(osal_index_t sem_id) +int32 OS_CountSemGive_Impl(const OS_object_token_t *token) { + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); + /* Give VxWorks Semaphore */ - return OS_VxWorks_GenericSemGive(OS_impl_count_sem_table[sem_id].vxid); + return OS_VxWorks_GenericSemGive(impl->vxid); } /* end OS_CountSemGive_Impl */ /*---------------------------------------------------------------- @@ -129,9 +141,13 @@ int32 OS_CountSemGive_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemTake_Impl(osal_index_t sem_id) +int32 OS_CountSemTake_Impl(const OS_object_token_t *token) { - return OS_VxWorks_GenericSemTake(OS_impl_count_sem_table[sem_id].vxid, WAIT_FOREVER); + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); + + return OS_VxWorks_GenericSemTake(impl->vxid, WAIT_FOREVER); } /* end OS_CountSemTake_Impl */ /*---------------------------------------------------------------- @@ -142,16 +158,19 @@ int32 OS_CountSemTake_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemTimedWait_Impl(osal_index_t sem_id, uint32 msecs) +int32 OS_CountSemTimedWait_Impl(const OS_object_token_t *token, uint32 msecs) { - int ticks; - int32 status; + int ticks; + int32 status; + OS_impl_countsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_count_sem_table, *token); status = OS_Milli2Ticks(msecs, &ticks); if (status == OS_SUCCESS) { - status = OS_VxWorks_GenericSemTake(OS_impl_count_sem_table[sem_id].vxid, ticks); + status = OS_VxWorks_GenericSemTake(impl->vxid, ticks); } return status; @@ -165,7 +184,7 @@ int32 OS_CountSemTimedWait_Impl(osal_index_t sem_id, uint32 msecs) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_CountSemGetInfo_Impl(osal_index_t sem_id, OS_count_sem_prop_t *count_prop) +int32 OS_CountSemGetInfo_Impl(const OS_object_token_t *token, OS_count_sem_prop_t *count_prop) { /* VxWorks does not provide an API to get the value */ return OS_SUCCESS; diff --git a/src/os/vxworks/src/os-impl-dirs.c b/src/os/vxworks/src/os-impl-dirs.c index 513b8b878..e20da3b87 100644 --- a/src/os/vxworks/src/os-impl-dirs.c +++ b/src/os/vxworks/src/os-impl-dirs.c @@ -32,6 +32,7 @@ #include "os-vxworks.h" #include "os-impl-dirs.h" #include "os-shared-dir.h" +#include "os-shared-idmap.h" /* * The directory handle table. @@ -83,10 +84,14 @@ int32 OS_DirCreate_Impl(const char *local_path, uint32 access) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_DirOpen_Impl(osal_index_t local_id, const char *local_path) +int32 OS_DirOpen_Impl(const OS_object_token_t *token, const char *local_path) { - OS_impl_dir_table[local_id].dp = opendir(local_path); - if (OS_impl_dir_table[local_id].dp == NULL) + OS_impl_dir_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_dir_table, *token); + + impl->dp = opendir(local_path); + if (impl->dp == NULL) { return OS_ERROR; } @@ -101,10 +106,14 @@ int32 OS_DirOpen_Impl(osal_index_t local_id, const char *local_path) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_DirClose_Impl(osal_index_t local_id) +int32 OS_DirClose_Impl(const OS_object_token_t *token) { - closedir(OS_impl_dir_table[local_id].dp); - OS_impl_dir_table[local_id].dp = NULL; + OS_impl_dir_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_dir_table, *token); + + closedir(impl->dp); + impl->dp = NULL; return OS_SUCCESS; } /* end OS_DirClose_Impl */ @@ -116,9 +125,12 @@ int32 OS_DirClose_Impl(osal_index_t local_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_DirRead_Impl(osal_index_t local_id, os_dirent_t *dirent) +int32 OS_DirRead_Impl(const OS_object_token_t *token, os_dirent_t *dirent) { - struct dirent *de; + struct dirent * de; + OS_impl_dir_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_dir_table, *token); /* NOTE - the readdir() call is non-reentrant .... * However, this is performed while the global dir table lock is taken. @@ -129,7 +141,7 @@ int32 OS_DirRead_Impl(osal_index_t local_id, os_dirent_t *dirent) */ /* cppcheck-suppress readdirCalled */ /* cppcheck-suppress nonreentrantFunctionsreaddir */ - de = readdir(OS_impl_dir_table[local_id].dp); + de = readdir(impl->dp); if (de == NULL) { return OS_ERROR; @@ -149,9 +161,13 @@ int32 OS_DirRead_Impl(osal_index_t local_id, os_dirent_t *dirent) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_DirRewind_Impl(osal_index_t local_id) +int32 OS_DirRewind_Impl(const OS_object_token_t *token) { - rewinddir(OS_impl_dir_table[local_id].dp); + OS_impl_dir_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_dir_table, *token); + + rewinddir(impl->dp); return OS_SUCCESS; } /* end OS_DirRewind_Impl */ diff --git a/src/os/vxworks/src/os-impl-filesys.c b/src/os/vxworks/src/os-impl-filesys.c index 2876348e4..5a7080c6e 100644 --- a/src/os/vxworks/src/os-impl-filesys.c +++ b/src/os/vxworks/src/os-impl-filesys.c @@ -76,12 +76,15 @@ OS_impl_filesys_internal_record_t OS_impl_filesys_table[OS_MAX_FILE_SYSTEMS]; * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysStartVolume_Impl(osal_index_t filesys_id) +int32 OS_FileSysStartVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t * local = &OS_filesys_table[filesys_id]; - OS_impl_filesys_internal_record_t *impl = &OS_impl_filesys_table[filesys_id]; + OS_filesys_internal_record_t * local; + OS_impl_filesys_internal_record_t *impl; int32 return_code; + impl = OS_OBJECT_TABLE_GET(OS_impl_filesys_table, *token); + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + memset(impl, 0, sizeof(*impl)); return_code = OS_ERR_NOT_IMPLEMENTED; switch (local->fstype) @@ -192,10 +195,13 @@ int32 OS_FileSysStartVolume_Impl(osal_index_t filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysStopVolume_Impl(osal_index_t filesys_id) +int32 OS_FileSysStopVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t * local = &OS_filesys_table[filesys_id]; - OS_impl_filesys_internal_record_t *impl = &OS_impl_filesys_table[filesys_id]; + OS_filesys_internal_record_t * local; + OS_impl_filesys_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filesys_table, *token); + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); switch (local->fstype) { @@ -231,12 +237,14 @@ int32 OS_FileSysStopVolume_Impl(osal_index_t filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysFormatVolume_Impl(osal_index_t filesys_id) +int32 OS_FileSysFormatVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_filesys_internal_record_t *local; int32 return_code = OS_ERR_NOT_IMPLEMENTED; int status; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + switch (local->fstype) { case OS_FILESYS_TYPE_FS_BASED: @@ -282,12 +290,14 @@ int32 OS_FileSysFormatVolume_Impl(osal_index_t filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysMountVolume_Impl(osal_index_t filesys_id) +int32 OS_FileSysMountVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_filesys_internal_record_t *local; int32 status; int fd; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + /* * Calling open() on the physical device path * mounts the device. @@ -315,12 +325,14 @@ int32 OS_FileSysMountVolume_Impl(osal_index_t filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysUnmountVolume_Impl(osal_index_t filesys_id) +int32 OS_FileSysUnmountVolume_Impl(const OS_object_token_t *token) { - OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_filesys_internal_record_t *local; int32 status; int fd; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + /* ** vxWorks uses an ioctl to unmount */ @@ -355,12 +367,14 @@ int32 OS_FileSysUnmountVolume_Impl(osal_index_t filesys_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysStatVolume_Impl(osal_index_t filesys_id, OS_statvfs_t *result) +int32 OS_FileSysStatVolume_Impl(const OS_object_token_t *token, OS_statvfs_t *result) { - OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_filesys_internal_record_t *local; struct statfs stat_buf; int return_code; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + if (statfs(local->system_mountpt, &stat_buf) != 0) { return_code = OS_ERROR; @@ -386,13 +400,15 @@ int32 OS_FileSysStatVolume_Impl(osal_index_t filesys_id, OS_statvfs_t *result) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_FileSysCheckVolume_Impl(osal_index_t filesys_id, bool repair) +int32 OS_FileSysCheckVolume_Impl(const OS_object_token_t *token, bool repair) { - OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_filesys_internal_record_t *local; STATUS chk_status; int flags; int fd; + local = OS_OBJECT_TABLE_GET(OS_filesys_table, *token); + fd = open(local->system_mountpt, O_RDONLY, 0); if (fd < 0) { diff --git a/src/os/vxworks/src/os-impl-loader.c b/src/os/vxworks/src/os-impl-loader.c index ba9a607c2..49e693be4 100644 --- a/src/os/vxworks/src/os-impl-loader.c +++ b/src/os/vxworks/src/os-impl-loader.c @@ -32,6 +32,7 @@ #include "os-vxworks.h" #include "os-impl-loader.h" #include "os-shared-module.h" +#include "os-shared-idmap.h" #include #include @@ -71,11 +72,14 @@ int32 OS_VxWorks_ModuleAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleLoad_Impl(osal_index_t local_id, const char *translated_path) +int32 OS_ModuleLoad_Impl(const OS_object_token_t *token, const char *translated_path) { - int32 return_code; - int fd; - MODULE_ID vxModuleId; + int32 return_code; + int fd; + MODULE_ID vxModuleId; + OS_impl_module_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_module_table, *token); /* ** File is ready to load @@ -104,8 +108,8 @@ int32 OS_ModuleLoad_Impl(osal_index_t local_id, const char *translated_path) } else { - OS_impl_module_table[local_id].moduleID = vxModuleId; - return_code = OS_SUCCESS; + impl->moduleID = vxModuleId; + return_code = OS_SUCCESS; } /* @@ -126,14 +130,17 @@ int32 OS_ModuleLoad_Impl(osal_index_t local_id, const char *translated_path) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleUnload_Impl(osal_index_t local_id) +int32 OS_ModuleUnload_Impl(const OS_object_token_t *token) { - STATUS vxStatus; + STATUS vxStatus; + OS_impl_module_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_module_table, *token); /* ** Attempt to close/unload the module */ - vxStatus = unldByModuleId(OS_impl_module_table[local_id].moduleID, 0); + vxStatus = unldByModuleId(impl->moduleID, 0); if (vxStatus == ERROR) { OS_DEBUG("OSAL: Error, Cannot Close/Unload application file: %d\n", vxStatus); @@ -152,17 +159,20 @@ int32 OS_ModuleUnload_Impl(osal_index_t local_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleGetInfo_Impl(osal_index_t local_id, OS_module_prop_t *module_prop) +int32 OS_ModuleGetInfo_Impl(const OS_object_token_t *token, OS_module_prop_t *module_prop) { - MODULE_INFO vxModuleInfo; - STATUS vxStatus; + MODULE_INFO vxModuleInfo; + STATUS vxStatus; + OS_impl_module_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_module_table, *token); - module_prop->host_module_id = (cpuaddr)OS_impl_module_table[local_id].moduleID; + module_prop->host_module_id = (cpuaddr)impl->moduleID; /* ** Get the module info from vxWorks */ - vxStatus = moduleInfoGet(OS_impl_module_table[local_id].moduleID, &vxModuleInfo); + vxStatus = moduleInfoGet(impl->moduleID, &vxModuleInfo); if (vxStatus == ERROR) { OS_DEBUG("OSAL: OS_ModuleInfoGet Error from vxWorks: %d\n", vxStatus); diff --git a/src/os/vxworks/src/os-impl-mutex.c b/src/os/vxworks/src/os-impl-mutex.c index 72e09afe5..d044e5bed 100644 --- a/src/os/vxworks/src/os-impl-mutex.c +++ b/src/os/vxworks/src/os-impl-mutex.c @@ -32,6 +32,7 @@ #include "os-impl-mutex.h" #include "os-shared-mutex.h" +#include "os-shared-idmap.h" #include @@ -67,13 +68,16 @@ int32 OS_VxWorks_MutexAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemCreate_Impl(osal_index_t sem_id, uint32 options) +int32 OS_MutSemCreate_Impl(const OS_object_token_t *token, uint32 options) { - SEM_ID tmp_sem_id; + SEM_ID tmp_sem_id; + OS_impl_mutsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); /* Initialize VxWorks Semaphore. * The memory for this sem is statically allocated. */ - tmp_sem_id = semMInitialize(OS_impl_mutex_table[sem_id].mmem, SEM_Q_PRIORITY | SEM_INVERSION_SAFE); + tmp_sem_id = semMInitialize(impl->mmem, SEM_Q_PRIORITY | SEM_INVERSION_SAFE); if (tmp_sem_id == (SEM_ID)0) { @@ -81,7 +85,7 @@ int32 OS_MutSemCreate_Impl(osal_index_t sem_id, uint32 options) return OS_SEM_FAILURE; } - OS_impl_mutex_table[sem_id].vxid = tmp_sem_id; + impl->vxid = tmp_sem_id; return OS_SUCCESS; } /* end OS_MutSemCreate_Impl */ @@ -93,12 +97,16 @@ int32 OS_MutSemCreate_Impl(osal_index_t sem_id, uint32 options) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemDelete_Impl(osal_index_t sem_id) +int32 OS_MutSemDelete_Impl(const OS_object_token_t *token) { + OS_impl_mutsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); + /* * As the memory for the sem is statically allocated, delete is a no-op. */ - OS_impl_mutex_table[sem_id].vxid = 0; + impl->vxid = 0; return OS_SUCCESS; } /* end OS_MutSemDelete_Impl */ @@ -111,10 +119,14 @@ int32 OS_MutSemDelete_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemGive_Impl(osal_index_t sem_id) +int32 OS_MutSemGive_Impl(const OS_object_token_t *token) { + OS_impl_mutsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); + /* Give VxWorks Semaphore */ - return OS_VxWorks_GenericSemGive(OS_impl_mutex_table[sem_id].vxid); + return OS_VxWorks_GenericSemGive(impl->vxid); } /* end OS_MutSemGive_Impl */ /*---------------------------------------------------------------- @@ -125,10 +137,14 @@ int32 OS_MutSemGive_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemTake_Impl(osal_index_t sem_id) +int32 OS_MutSemTake_Impl(const OS_object_token_t *token) { + OS_impl_mutsem_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_mutex_table, *token); + /* Take VxWorks Semaphore */ - return OS_VxWorks_GenericSemTake(OS_impl_mutex_table[sem_id].vxid, WAIT_FOREVER); + return OS_VxWorks_GenericSemTake(impl->vxid, WAIT_FOREVER); } /* end OS_MutSemTake_Impl */ /*---------------------------------------------------------------- @@ -139,7 +155,7 @@ int32 OS_MutSemTake_Impl(osal_index_t sem_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemGetInfo_Impl(osal_index_t sem_id, OS_mut_sem_prop_t *mut_prop) +int32 OS_MutSemGetInfo_Impl(const OS_object_token_t *token, OS_mut_sem_prop_t *mut_prop) { /* VxWorks provides no additional info */ return OS_SUCCESS; diff --git a/src/os/vxworks/src/os-impl-queues.c b/src/os/vxworks/src/os-impl-queues.c index bbc95b175..99e8a3002 100644 --- a/src/os/vxworks/src/os-impl-queues.c +++ b/src/os/vxworks/src/os-impl-queues.c @@ -32,6 +32,7 @@ #include "os-impl-queues.h" #include "os-shared-queue.h" #include "os-shared-timebase.h" +#include "os-shared-idmap.h" /**************************************************************************************** GLOBAL DATA @@ -63,11 +64,19 @@ int32 OS_VxWorks_QueueAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueCreate_Impl(osal_index_t queue_id, uint32 flags) +int32 OS_QueueCreate_Impl(const OS_object_token_t *token, uint32 flags) { - MSG_Q_ID tmp_msgq_id; - int queue_depth = OS_queue_table[queue_id].max_depth; /* maximum number of messages in queue (queue depth) */ - int data_size = OS_queue_table[queue_id].max_size; /* maximum size in bytes of a message */ + MSG_Q_ID tmp_msgq_id; + int queue_depth; + int data_size; + OS_impl_queue_internal_record_t *impl; + OS_queue_internal_record_t * queue; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); + queue = OS_OBJECT_TABLE_GET(OS_queue_table, *token); + + queue_depth = queue->max_depth; /* maximum number of messages in queue (queue depth) */ + data_size = queue->max_size; /* maximum size in bytes of a message */ /* Create VxWorks Message Queue */ tmp_msgq_id = msgQCreate(queue_depth, data_size, MSG_Q_FIFO); @@ -79,7 +88,7 @@ int32 OS_QueueCreate_Impl(osal_index_t queue_id, uint32 flags) return OS_ERROR; } - OS_impl_queue_table[queue_id].vxid = tmp_msgq_id; + impl->vxid = tmp_msgq_id; return OS_SUCCESS; } /* end OS_QueueCreate_Impl */ @@ -92,16 +101,20 @@ int32 OS_QueueCreate_Impl(osal_index_t queue_id, uint32 flags) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueDelete_Impl(osal_index_t queue_id) +int32 OS_QueueDelete_Impl(const OS_object_token_t *token) { + OS_impl_queue_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); + /* Try to delete the queue */ - if (msgQDelete(OS_impl_queue_table[queue_id].vxid) != OK) + if (msgQDelete(impl->vxid) != OK) { OS_DEBUG("msgQDelete() - vxWorks errno %d\n", errno); return OS_ERROR; } - OS_impl_queue_table[queue_id].vxid = 0; + impl->vxid = 0; return OS_SUCCESS; } /* end OS_QueueDelete_Impl */ @@ -114,11 +127,14 @@ int32 OS_QueueDelete_Impl(osal_index_t queue_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueGet_Impl(osal_index_t queue_id, void *data, size_t size, size_t *size_copied, int32 timeout) +int32 OS_QueueGet_Impl(const OS_object_token_t *token, void *data, size_t size, size_t *size_copied, int32 timeout) { - int32 return_code; - STATUS status; - int ticks; + int32 return_code; + STATUS status; + int ticks; + OS_impl_queue_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); /* Get Message From Message Queue */ if (timeout == OS_PEND) @@ -138,7 +154,7 @@ int32 OS_QueueGet_Impl(osal_index_t queue_id, void *data, size_t size, size_t *s } } - status = msgQReceive(OS_impl_queue_table[queue_id].vxid, data, size, ticks); + status = msgQReceive(impl->vxid, data, size, ticks); if (status == ERROR) { @@ -174,11 +190,14 @@ int32 OS_QueueGet_Impl(osal_index_t queue_id, void *data, size_t size, size_t *s * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueuePut_Impl(osal_index_t queue_id, const void *data, size_t size, uint32 flags) +int32 OS_QueuePut_Impl(const OS_object_token_t *token, const void *data, size_t size, uint32 flags) { - int32 return_code; + int32 return_code; + OS_impl_queue_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_queue_table, *token); - if (msgQSend(OS_impl_queue_table[queue_id].vxid, (void *)data, size, NO_WAIT, MSG_PRI_NORMAL) == OK) + if (msgQSend(impl->vxid, (void *)data, size, NO_WAIT, MSG_PRI_NORMAL) == OK) { return_code = OS_SUCCESS; } @@ -204,7 +223,7 @@ int32 OS_QueuePut_Impl(osal_index_t queue_id, const void *data, size_t size, uin * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_QueueGetInfo_Impl(osal_index_t queue_id, OS_queue_prop_t *queue_prop) +int32 OS_QueueGetInfo_Impl(const OS_object_token_t *token, OS_queue_prop_t *queue_prop) { /* No extra info for queues in the OS implementation */ return OS_SUCCESS; diff --git a/src/os/vxworks/src/os-impl-shell.c b/src/os/vxworks/src/os-impl-shell.c index 2b942a41d..7fc9f3342 100644 --- a/src/os/vxworks/src/os-impl-shell.c +++ b/src/os/vxworks/src/os-impl-shell.c @@ -33,6 +33,7 @@ #include "os-impl-io.h" #include "os-shared-shell.h" #include "os-shared-file.h" +#include "os-shared-idmap.h" #include #include @@ -52,13 +53,15 @@ * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ShellOutputToFile_Impl(osal_index_t file_id, const char *Cmd) +int32 OS_ShellOutputToFile_Impl(const OS_object_token_t *token, const char *Cmd) { - int32 ReturnCode = OS_ERROR; - int32 Result; - osal_id_t fdCmd; - osal_index_t cmdidx; - char * shellName; + int32 ReturnCode = OS_ERROR; + int32 Result; + osal_id_t fdCmd; + char * shellName; + OS_impl_file_internal_record_t *out_impl; + OS_impl_file_internal_record_t *cmd_impl; + OS_object_token_t cmd_token; /* Create a file to write the command to (or write over the old one) */ Result = @@ -69,16 +72,18 @@ int32 OS_ShellOutputToFile_Impl(osal_index_t file_id, const char *Cmd) return Result; } - if (OS_ConvertToArrayIndex(fdCmd, &cmdidx) == OS_SUCCESS) + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_STREAM, fdCmd, &cmd_token) == OS_SUCCESS) { + out_impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); + cmd_impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, cmd_token); + /* copy the command to the file, and then seek back to the beginning of the file */ OS_write(fdCmd, Cmd, strlen(Cmd)); OS_lseek(fdCmd, 0, OS_SEEK_SET); /* Create a shell task the will run the command in the file, push output to OS_fd */ - Result = - shellGenericInit("INTERPRETER=Cmd", 0, NULL, &shellName, false, false, OS_impl_filehandle_table[cmdidx].fd, - OS_impl_filehandle_table[file_id].fd, OS_impl_filehandle_table[file_id].fd); + Result = shellGenericInit("INTERPRETER=Cmd", 0, NULL, &shellName, false, false, + cmd_impl->fd, out_impl->fd, out_impl->fd); } if (Result == OK) diff --git a/src/os/vxworks/src/os-impl-symtab.c b/src/os/vxworks/src/os-impl-symtab.c index be689df95..5dc9f94ee 100644 --- a/src/os/vxworks/src/os-impl-symtab.c +++ b/src/os/vxworks/src/os-impl-symtab.c @@ -119,7 +119,6 @@ int32 OS_GlobalSymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) return OS_GenericSymbolLookup_Impl(sysSymTbl, SymbolAddress, SymbolName); } /* end OS_GlobalSymbolLookup_Impl */ - /*---------------------------------------------------------------- * * Function: OS_ModuleSymbolLookup_Impl @@ -128,7 +127,7 @@ int32 OS_GlobalSymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleSymbolLookup_Impl(osal_index_t local_id, cpuaddr *SymbolAddress, const char *SymbolName) +int32 OS_ModuleSymbolLookup_Impl(const OS_object_token_t *token, cpuaddr *SymbolAddress, const char *SymbolName) { /* * NOTE: this is currently exactly the same as OS_GlobalSymbolLookup_Impl(). @@ -140,8 +139,6 @@ int32 OS_ModuleSymbolLookup_Impl(osal_index_t local_id, cpuaddr *SymbolAddress, return OS_GenericSymbolLookup_Impl(sysSymTbl, SymbolAddress, SymbolName); } /* end OS_ModuleSymbolLookup_Impl */ - - /*---------------------------------------------------------------- * * Function: OS_SymTableIterator_Impl diff --git a/src/os/vxworks/src/os-impl-tasks.c b/src/os/vxworks/src/os-impl-tasks.c index 83afb2922..ccb0e5a76 100644 --- a/src/os/vxworks/src/os-impl-tasks.c +++ b/src/os/vxworks/src/os-impl-tasks.c @@ -83,11 +83,7 @@ OS_impl_task_internal_record_t OS_impl_task_table[OS_MAX_TASKS]; ---------------------------------------------------------------------------------------*/ int OS_VxWorks_TaskEntry(int arg) { - VxWorks_ID_Buffer_t id; - - id.arg = arg; - - OS_TaskEntryPoint(id.id); + OS_TaskEntryPoint(OS_ObjectIdFromInteger(arg)); return 0; } /* end OS_VxWorksEntry */ @@ -117,7 +113,7 @@ int32 OS_VxWorks_TaskAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskCreate_Impl(osal_index_t task_id, uint32 flags) +int32 OS_TaskCreate_Impl(const OS_object_token_t *token, uint32 flags) { STATUS status; int vxflags; @@ -126,9 +122,10 @@ int32 OS_TaskCreate_Impl(osal_index_t task_id, uint32 flags) unsigned long userstackbase; unsigned long actualstackbase; OS_impl_task_internal_record_t *lrec; - VxWorks_ID_Buffer_t id; + OS_task_internal_record_t * task; - lrec = &OS_impl_task_table[task_id]; + lrec = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + task = OS_OBJECT_TABLE_GET(OS_task_table, *token); /* Create VxWorks Task */ @@ -145,9 +142,9 @@ int32 OS_TaskCreate_Impl(osal_index_t task_id, uint32 flags) * Get priority/stack specs from main struct * priority should be a direct passthru */ - vxpri = OS_task_table[task_id].priority; - actualsz = OS_task_table[task_id].stack_size; - userstackbase = (unsigned long)OS_task_table[task_id].stack_pointer; + vxpri = task->priority; + actualsz = task->stack_size; + userstackbase = (unsigned long)task->stack_pointer; /* * NOTE: Using taskInit() here rather than taskSpawn() allows us @@ -237,14 +234,13 @@ int32 OS_TaskCreate_Impl(osal_index_t task_id, uint32 flags) actualstackbase += actualsz; /* move to last byte of stack block */ #endif - id.id = OS_global_task_table[task_id].active_id; - status = taskInit(&lrec->tcb, /* address of new task's TCB */ - (char *)OS_global_task_table[task_id].name_entry, vxpri, /* priority of new task */ - vxflags, /* task option word */ - (char *)actualstackbase, /* base of new task's stack */ - actualsz, /* size (bytes) of stack needed */ - (FUNCPTR)OS_VxWorks_TaskEntry, /* entry point of new task */ - id.arg, /* 1st arg is ID */ + status = taskInit(&lrec->tcb, /* address of new task's TCB */ + (char *)task->task_name, vxpri, /* priority of new task */ + vxflags, /* task option word */ + (char *)actualstackbase, /* base of new task's stack */ + actualsz, /* size (bytes) of stack needed */ + (FUNCPTR)OS_VxWorks_TaskEntry, /* entry point of new task */ + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), /* 1st arg is ID */ 0, 0, 0, 0, 0, 0, 0, 0, 0); if (status != OK) @@ -268,21 +264,25 @@ int32 OS_TaskCreate_Impl(osal_index_t task_id, uint32 flags) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskDelete_Impl(osal_index_t task_id) +int32 OS_TaskDelete_Impl(const OS_object_token_t *token) { + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + /* ** Try to delete the task ** If this fails, not much recourse - the only potential cause of failure ** to cancel here is that the thread ID is invalid because it already exited itself, ** and if that is true there is nothing wrong - everything is OK to continue normally. */ - if (taskDelete(OS_impl_task_table[task_id].vxid) != OK) + if (taskDelete(impl->vxid) != OK) { OS_DEBUG("taskDelete() - vxWorks errno %d\n", errno); return OS_ERROR; } - OS_impl_task_table[task_id].vxid = 0; + impl->vxid = 0; return OS_SUCCESS; } /* end OS_TaskDelete_Impl */ @@ -336,10 +336,14 @@ int32 OS_TaskDelay_Impl(uint32 milli_second) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskSetPriority_Impl(osal_index_t task_id, osal_priority_t new_priority) +int32 OS_TaskSetPriority_Impl(const OS_object_token_t *token, osal_priority_t new_priority) { + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + /* Set VxWorks Task Priority */ - if (taskPrioritySet(OS_impl_task_table[task_id].vxid, new_priority) != OK) + if (taskPrioritySet(impl->vxid, new_priority) != OK) { return OS_ERROR; } @@ -356,12 +360,16 @@ int32 OS_TaskSetPriority_Impl(osal_index_t task_id, osal_priority_t new_priority * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskMatch_Impl(osal_index_t task_id) +int32 OS_TaskMatch_Impl(const OS_object_token_t *token) { + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); + /* ** Get VxWorks Task Id */ - if (taskIdSelf() != OS_impl_task_table[task_id].vxid) + if (taskIdSelf() != impl->vxid) { return (OS_ERROR); } @@ -420,7 +428,7 @@ osal_id_t OS_TaskGetId_Impl(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TaskGetInfo_Impl(osal_index_t task_id, OS_task_prop_t *task_prop) +int32 OS_TaskGetInfo_Impl(const OS_object_token_t *token, OS_task_prop_t *task_prop) { return OS_SUCCESS; @@ -451,9 +459,12 @@ int32 OS_TaskValidateSystemData_Impl(const void *sysdata, size_t sysdata_size) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -bool OS_TaskIdMatchSystemData_Impl(void *ref, osal_index_t local_id, const OS_common_record_t *obj) +bool OS_TaskIdMatchSystemData_Impl(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) { - const TASK_ID *target = (const TASK_ID *)ref; + const TASK_ID * target = (const TASK_ID *)ref; + OS_impl_task_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_task_table, *token); - return (*target == OS_impl_task_table[local_id].vxid); + return (*target == impl->vxid); } diff --git a/src/os/vxworks/src/os-impl-timebase.c b/src/os/vxworks/src/os-impl-timebase.c index 8b75c100d..04b90513e 100644 --- a/src/os/vxworks/src/os-impl-timebase.c +++ b/src/os/vxworks/src/os-impl-timebase.c @@ -93,9 +93,13 @@ static uint32 OS_ClockAccuracyNsec; * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -void OS_TimeBaseLock_Impl(osal_index_t local_id) +void OS_TimeBaseLock_Impl(const OS_object_token_t *token) { - semTake(OS_impl_timebase_table[local_id].handler_mutex, WAIT_FOREVER); + OS_impl_timebase_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + + semTake(impl->handler_mutex, WAIT_FOREVER); } /* end OS_TimeBaseLock_Impl */ /*---------------------------------------------------------------- @@ -106,9 +110,13 @@ void OS_TimeBaseLock_Impl(osal_index_t local_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -void OS_TimeBaseUnlock_Impl(osal_index_t local_id) +void OS_TimeBaseUnlock_Impl(const OS_object_token_t *token) { - semGive(OS_impl_timebase_table[local_id].handler_mutex); + OS_impl_timebase_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + + semGive(impl->handler_mutex); } /* end OS_TimeBaseUnlock_Impl */ /*---------------------------------------------------------------- @@ -204,38 +212,42 @@ uint32 OS_VxWorks_SigWait(osal_index_t local_id) * Purpose: Local helper routine, not part of OSAL API. * *-----------------------------------------------------------------*/ -void OS_VxWorks_RegisterTimer(osal_index_t local_id) +void OS_VxWorks_RegisterTimer(osal_id_t obj_id) { OS_impl_timebase_internal_record_t *local; + OS_object_token_t token; struct sigevent evp; int status; - local = &OS_impl_timebase_table[local_id]; + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMEBASE, obj_id, &token) == OS_SUCCESS) + { + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, token); - memset(&evp, 0, sizeof(evp)); - evp.sigev_notify = SIGEV_SIGNAL; - evp.sigev_signo = local->assigned_signal; + memset(&evp, 0, sizeof(evp)); + evp.sigev_notify = SIGEV_SIGNAL; + evp.sigev_signo = local->assigned_signal; - /* - ** Create the timer - ** - ** The result is not returned from this function, because - ** this is a different task context from the original creator. - ** - ** The registration status is returned through the OS_impl_timebase_table entry, - ** which is checked by the creator before returning. - ** - ** If set to ERROR, then this task will be subsequently deleted. - */ - status = timer_create(OS_PREFERRED_CLOCK, &evp, &local->host_timerid); - if (status < 0) - { - OS_DEBUG("timer_create() failed: errno=%d\n", errno); - local->timer_state = OS_TimerRegState_ERROR; - } - else - { - local->timer_state = OS_TimerRegState_SUCCESS; + /* + ** Create the timer + ** + ** The result is not returned from this function, because + ** this is a different task context from the original creator. + ** + ** The registration status is returned through the OS_impl_timebase_table entry, + ** which is checked by the creator before returning. + ** + ** If set to ERROR, then this task will be subsequently deleted. + */ + status = timer_create(OS_PREFERRED_CLOCK, &evp, &local->host_timerid); + if (status < 0) + { + OS_DEBUG("timer_create() failed: errno=%d\n", errno); + local->timer_state = OS_TimerRegState_ERROR; + } + else + { + local->timer_state = OS_TimerRegState_SUCCESS; + } } } /* end OS_VxWorks_RegisterTimer */ @@ -253,14 +265,10 @@ void OS_VxWorks_RegisterTimer(osal_index_t local_id) int OS_VxWorks_TimeBaseTask(int arg) { VxWorks_ID_Buffer_t id; - osal_index_t local_id; id.arg = arg; - if (OS_ConvertToArrayIndex(id.id, &local_id) == OS_SUCCESS) - { - OS_VxWorks_RegisterTimer(local_id); - OS_TimeBase_CallbackThread(id.id); - } + OS_VxWorks_RegisterTimer(id.id); + OS_TimeBase_CallbackThread(id.id); return 0; } /* end OS_VxWorks_TimeBaseTask */ @@ -323,7 +331,7 @@ int32 OS_VxWorks_TimeBaseAPI_Impl_Init(void) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseCreate_Impl(osal_index_t timer_id) +int32 OS_TimeBaseCreate_Impl(const OS_object_token_t *token) { /* * The tick_sem is a simple semaphore posted by the ISR and taken by the @@ -331,7 +339,7 @@ int32 OS_TimeBaseCreate_Impl(osal_index_t timer_id) */ int32 return_code; OS_impl_timebase_internal_record_t *local; - OS_common_record_t * global; + OS_timebase_internal_record_t * timebase; int signo; sigset_t inuse; osal_index_t idx; @@ -339,8 +347,9 @@ int32 OS_TimeBaseCreate_Impl(osal_index_t timer_id) VxWorks_ID_Buffer_t idbuf; return_code = OS_SUCCESS; - local = &OS_impl_timebase_table[timer_id]; - global = &OS_global_timebase_table[timer_id]; + + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, *token); sigemptyset(&local->timer_sigset); local->assigned_signal = 0; @@ -359,7 +368,7 @@ int32 OS_TimeBaseCreate_Impl(osal_index_t timer_id) * If no external sync function is provided then this will set up a VxWorks * timer to locally simulate the timer tick using the CPU clock. */ - if (OS_timebase_table[timer_id].external_sync == NULL) + if (timebase->external_sync == NULL) { /* * find an RT signal that is not used by another time base object. @@ -411,7 +420,7 @@ int32 OS_TimeBaseCreate_Impl(osal_index_t timer_id) /* * Use local sigwait() wrapper as a sync function for the local task. */ - OS_timebase_table[timer_id].external_sync = OS_VxWorks_SigWait; + timebase->external_sync = OS_VxWorks_SigWait; } } @@ -444,9 +453,9 @@ int32 OS_TimeBaseCreate_Impl(osal_index_t timer_id) */ if (return_code == OS_SUCCESS) { - idbuf.id = global->active_id; - local->handler_task = taskSpawn((char *)global->name_entry, OSAL_TIMEBASE_TASK_PRIORITY, /* priority */ - OSAL_TIMEBASE_TASK_OPTION_WORD, /* task option word */ + idbuf.id = OS_ObjectIdFromToken(token); + local->handler_task = taskSpawn(timebase->timebase_name, OSAL_TIMEBASE_TASK_PRIORITY, /* priority */ + OSAL_TIMEBASE_TASK_OPTION_WORD, /* task option word */ OSAL_TIMEBASE_TASK_STACK_SIZE, /* size (bytes) of stack needed */ (FUNCPTR)OS_VxWorks_TimeBaseTask, idbuf.arg, /* 1st arg is ID */ 0, 0, 0, 0, 0, 0, 0, 0, 0); @@ -501,14 +510,14 @@ int32 OS_TimeBaseCreate_Impl(osal_index_t timer_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseSet_Impl(osal_index_t timer_id, uint32 start_time, uint32 interval_time) +int32 OS_TimeBaseSet_Impl(const OS_object_token_t *token, uint32 start_time, uint32 interval_time) { OS_impl_timebase_internal_record_t *local; struct itimerspec timeout; int32 return_code; int status; - local = &OS_impl_timebase_table[timer_id]; + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); /* There is only something to do here if we are generating a simulated tick */ if (local->assigned_signal <= 0) @@ -550,19 +559,19 @@ int32 OS_TimeBaseSet_Impl(osal_index_t timer_id, uint32 start_time, uint32 inter if (status == OK) { local->configured_start_time = (timeout.it_value.tv_sec * 1000000) + (timeout.it_value.tv_nsec / 1000); - local->configured_interval_time = - (timeout.it_interval.tv_sec * 1000000) + (timeout.it_interval.tv_nsec / 1000); + local->configured_interval_time = (timeout.it_interval.tv_sec * 1000000) + + (timeout.it_interval.tv_nsec / 1000); if (local->configured_start_time != start_time) { OS_DEBUG("WARNING: timer %lu start_time requested=%luus, configured=%luus\n", - (unsigned long)timer_id, (unsigned long)start_time, + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), (unsigned long)start_time, (unsigned long)local->configured_start_time); } if (local->configured_interval_time != interval_time) { OS_DEBUG("WARNING: timer %lu interval_time requested=%luus, configured=%luus\n", - (unsigned long)timer_id, (unsigned long)interval_time, + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), (unsigned long)interval_time, (unsigned long)local->configured_interval_time); } } @@ -589,12 +598,12 @@ int32 OS_TimeBaseSet_Impl(osal_index_t timer_id, uint32 start_time, uint32 inter * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseDelete_Impl(osal_index_t timer_id) +int32 OS_TimeBaseDelete_Impl(const OS_object_token_t *token) { OS_impl_timebase_internal_record_t *local; int32 return_code; - local = &OS_impl_timebase_table[timer_id]; + local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, *token); return_code = OS_SUCCESS; /* An assigned_signal value indicates the OS timer needs deletion too */ @@ -623,7 +632,7 @@ int32 OS_TimeBaseDelete_Impl(osal_index_t timer_id) * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_TimeBaseGetInfo_Impl(osal_index_t timer_id, OS_timebase_prop_t *timer_prop) +int32 OS_TimeBaseGetInfo_Impl(const OS_object_token_t *token, OS_timebase_prop_t *timer_prop) { return OS_SUCCESS; diff --git a/src/unit-test-coverage/portable/src/coveragetest-bsd-select.c b/src/unit-test-coverage/portable/src/coveragetest-bsd-select.c index b86fe134a..fd2f7951c 100644 --- a/src/unit-test-coverage/portable/src/coveragetest-bsd-select.c +++ b/src/unit-test-coverage/portable/src/coveragetest-bsd-select.c @@ -26,6 +26,7 @@ #include "os-portable-coveragetest.h" #include "ut-adaptor-portable-posix-io.h" #include "os-shared-select.h" +#include "os-shared-idmap.h" #include @@ -35,20 +36,21 @@ void Test_OS_SelectSingle_Impl(void) * int32 OS_SelectSingle_Impl(uint32 stream_id, uint32 *SelectFlags, int32 msecs) */ uint32 SelectFlags; - osal_index_t StreamID; + OS_object_token_t token; struct OCS_timespec nowtime; struct OCS_timespec latertime; - StreamID = UT_INDEX_0; + memset(&token, 0, sizeof(token)); + UT_PortablePosixIOTest_Set_Selectable(UT_INDEX_0, false); SelectFlags = OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; - OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (StreamID, &SelectFlags, 0), OS_ERR_OPERATION_NOT_SUPPORTED); + OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (&token, &SelectFlags, 0), OS_ERR_OPERATION_NOT_SUPPORTED); UT_PortablePosixIOTest_Set_Selectable(UT_INDEX_0, true); - OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (StreamID, &SelectFlags, 0), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (&token, &SelectFlags, 0), OS_SUCCESS); SelectFlags = OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; - OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (StreamID, &SelectFlags, -1), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (&token, &SelectFlags, -1), OS_SUCCESS); SelectFlags = 0; - OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (StreamID, &SelectFlags, 0), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (&token, &SelectFlags, 0), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_select), 0); SelectFlags = OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; @@ -58,7 +60,7 @@ void Test_OS_SelectSingle_Impl(void) latertime.tv_nsec = 0; UT_SetDataBuffer(UT_KEY(OCS_clock_gettime), &nowtime, sizeof(nowtime), false); UT_SetDataBuffer(UT_KEY(OCS_clock_gettime), &latertime, sizeof(latertime), false); - OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (StreamID, &SelectFlags, 999), OS_ERROR_TIMEOUT); + OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (&token, &SelectFlags, 999), OS_ERROR_TIMEOUT); UT_SetDefaultReturnValue(UT_KEY(OCS_select), -1); SelectFlags = OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; @@ -68,7 +70,7 @@ void Test_OS_SelectSingle_Impl(void) latertime.tv_nsec = 600000000; UT_SetDataBuffer(UT_KEY(OCS_clock_gettime), &nowtime, sizeof(nowtime), false); UT_SetDataBuffer(UT_KEY(OCS_clock_gettime), &latertime, sizeof(latertime), false); - OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (StreamID, &SelectFlags, 2100), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (&token, &SelectFlags, 2100), OS_ERROR); } /* end OS_SelectSingle_Impl */ void Test_OS_SelectMultiple_Impl(void) diff --git a/src/unit-test-coverage/portable/src/coveragetest-console-bsp.c b/src/unit-test-coverage/portable/src/coveragetest-console-bsp.c index fc38f97a0..51727f590 100644 --- a/src/unit-test-coverage/portable/src/coveragetest-console-bsp.c +++ b/src/unit-test-coverage/portable/src/coveragetest-console-bsp.c @@ -27,6 +27,7 @@ #include "os-portable-coveragetest.h" #include "os-shared-printf.h" +#include "os-shared-idmap.h" #include #include @@ -37,8 +38,11 @@ const char TEST_BUF_INITIALIZER[1 + TEST_BUFFER_LEN] = "abcdefghijklmnop"; void Test_OS_ConsoleOutput_Impl(void) { - char TestConsoleBspBuffer[TEST_BUFFER_LEN]; - char TestOutputBuffer[32]; + char TestConsoleBspBuffer[TEST_BUFFER_LEN]; + char TestOutputBuffer[32]; + OS_object_token_t token; + + memset(&token, 0, sizeof(token)); memcpy(TestConsoleBspBuffer, TEST_BUF_INITIALIZER, sizeof(TestConsoleBspBuffer)); memset(TestOutputBuffer, 0, sizeof(TestOutputBuffer)); @@ -49,11 +53,11 @@ void Test_OS_ConsoleOutput_Impl(void) UT_SetDataBuffer(UT_KEY(OCS_OS_BSP_ConsoleOutput_Impl), TestOutputBuffer, sizeof(TestOutputBuffer), false); OS_console_table[0].WritePos = 4; - OS_ConsoleOutput_Impl(0); + OS_ConsoleOutput_Impl(&token); UtAssert_True(strcmp(TestOutputBuffer, "abcd") == 0, "TestOutputBuffer (%s) == abcd", TestOutputBuffer); OS_console_table[0].WritePos = 2; - OS_ConsoleOutput_Impl(0); + OS_ConsoleOutput_Impl(&token); UtAssert_True(strcmp(TestOutputBuffer, "abcdefghijklmnopab") == 0, "TestOutputBuffer (%s) == abcdefghijklmnopab", TestOutputBuffer); } diff --git a/src/unit-test-coverage/portable/src/coveragetest-posix-files.c b/src/unit-test-coverage/portable/src/coveragetest-posix-files.c index 372914b28..f6bb0788e 100644 --- a/src/unit-test-coverage/portable/src/coveragetest-posix-files.c +++ b/src/unit-test-coverage/portable/src/coveragetest-posix-files.c @@ -28,6 +28,7 @@ #include "ut-adaptor-portable-posix-files.h" #include "os-shared-file.h" +#include "os-shared-idmap.h" #include #include @@ -41,14 +42,18 @@ void Test_OS_FileOpen_Impl(void) * Test Case For: * int32 OS_FileOpen_Impl(uint32 local_id, const char *local_path, int32 flags, int32 access) */ - OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (UT_INDEX_0, "local", OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY), OS_SUCCESS); - OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (UT_INDEX_0, "local", 0, OS_READ_ONLY), OS_SUCCESS); - OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (UT_INDEX_0, "local", OS_FILE_FLAG_CREATE, OS_READ_WRITE), OS_SUCCESS); - OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (UT_INDEX_0, "local", 0, -1234), OS_ERROR); + OS_object_token_t token; + + memset(&token, 0, sizeof(token)); + + OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (&token, "local", OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (&token, "local", 0, OS_READ_ONLY), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (&token, "local", OS_FILE_FLAG_CREATE, OS_READ_WRITE), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (&token, "local", 0, -1234), OS_ERROR); /* failure mode */ UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1); - OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (UT_INDEX_0, "local", 0, OS_READ_ONLY), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (&token, "local", 0, OS_READ_ONLY), OS_ERROR); } void Test_OS_FileStat_Impl(void) diff --git a/src/unit-test-coverage/portable/src/coveragetest-posix-io.c b/src/unit-test-coverage/portable/src/coveragetest-posix-io.c index b272d9792..f3c7ea87b 100644 --- a/src/unit-test-coverage/portable/src/coveragetest-posix-io.c +++ b/src/unit-test-coverage/portable/src/coveragetest-posix-io.c @@ -43,14 +43,18 @@ void Test_OS_GenericClose_Impl(void) * Test Case For: * int32 OS_GenericClose_Impl(uint32 local_id) */ - OSAPI_TEST_FUNCTION_RC(OS_GenericClose_Impl, (UT_INDEX_0), OS_SUCCESS); + OS_object_token_t token; + + memset(&token, 0, sizeof(token)); + + OSAPI_TEST_FUNCTION_RC(OS_GenericClose_Impl, (&token), OS_SUCCESS); /* * Test path where underlying close() fails. * Should still return success. */ UT_SetDefaultReturnValue(UT_KEY(OCS_close), -1); - OSAPI_TEST_FUNCTION_RC(OS_GenericClose_Impl, (UT_INDEX_0), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_GenericClose_Impl, (&token), OS_SUCCESS); } void Test_OS_GenericSeek_Impl(void) @@ -59,25 +63,28 @@ void Test_OS_GenericSeek_Impl(void) * Test Case For: * int32 OS_GenericSeek_Impl (uint32 local_id, int32 offset, uint32 whence) */ + OS_object_token_t token; + + memset(&token, 0, sizeof(token)); /* note on success this wrapper returns the result of lseek(), not OS_SUCCESS */ UT_SetDefaultReturnValue(UT_KEY(OCS_lseek), 111); - OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (UT_INDEX_0, 0, OS_SEEK_CUR), 111); + OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (&token, 0, OS_SEEK_CUR), 111); UT_SetDefaultReturnValue(UT_KEY(OCS_lseek), 222); - OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (UT_INDEX_0, 0, OS_SEEK_SET), 222); + OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (&token, 0, OS_SEEK_SET), 222); UT_SetDefaultReturnValue(UT_KEY(OCS_lseek), 333); - OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (UT_INDEX_0, 0, OS_SEEK_END), 333); + OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (&token, 0, OS_SEEK_END), 333); /* bad whence */ - OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (UT_INDEX_0, 0, 1234), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (&token, 0, 1234), OS_ERROR); /* generic failure of lseek() */ UT_SetDefaultReturnValue(UT_KEY(OCS_lseek), -1); - OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (UT_INDEX_0, 0, OS_SEEK_END), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (&token, 0, OS_SEEK_END), OS_ERROR); /* The seek implementation also checks for this specific pipe errno */ OCS_errno = OCS_ESPIPE; - OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (UT_INDEX_0, 0, OS_SEEK_END), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (&token, 0, OS_SEEK_END), OS_ERR_NOT_IMPLEMENTED); } void Test_OS_GenericRead_Impl(void) @@ -86,24 +93,27 @@ void Test_OS_GenericRead_Impl(void) * Test Case For: * int32 OS_GenericRead_Impl (uint32 local_id, void *buffer, uint32 nbytes, int32 timeout) */ - char SrcData[] = "ABCDEFGHIJK"; - char DestData[sizeof(SrcData)] = {0}; + char SrcData[] = "ABCDEFGHIJK"; + char DestData[sizeof(SrcData)] = {0}; + OS_object_token_t token; + + memset(&token, 0, sizeof(token)); UT_SetDataBuffer(UT_KEY(OCS_read), SrcData, sizeof(SrcData), false); UT_PortablePosixIOTest_Set_Selectable(UT_INDEX_0, false); - OSAPI_TEST_FUNCTION_RC(OS_GenericRead_Impl, (UT_INDEX_0, DestData, sizeof(DestData), 0), sizeof(DestData)); + OSAPI_TEST_FUNCTION_RC(OS_GenericRead_Impl, (&token, DestData, sizeof(DestData), 0), sizeof(DestData)); UtAssert_MemCmp(SrcData, DestData, sizeof(SrcData), "read() data Valid"); /* test invocation of select() in nonblocking mode */ UT_ResetState(UT_KEY(OCS_read)); UT_SetDataBuffer(UT_KEY(OCS_read), SrcData, sizeof(SrcData), false); UT_PortablePosixIOTest_Set_Selectable(UT_INDEX_0, true); - OSAPI_TEST_FUNCTION_RC(OS_GenericRead_Impl, (UT_INDEX_0, DestData, sizeof(DestData), 0), sizeof(DestData)); + OSAPI_TEST_FUNCTION_RC(OS_GenericRead_Impl, (&token, DestData, sizeof(DestData), 0), sizeof(DestData)); UtAssert_True(UT_GetStubCount(UT_KEY(OS_SelectSingle_Impl)) == 1, "OS_SelectSingle() called"); /* read() failure */ UT_SetDefaultReturnValue(UT_KEY(OCS_read), -1); - OSAPI_TEST_FUNCTION_RC(OS_GenericRead_Impl, (UT_INDEX_0, DestData, sizeof(DestData), 0), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_GenericRead_Impl, (&token, DestData, sizeof(DestData), 0), OS_ERROR); } void Test_OS_GenericWrite_Impl(void) @@ -112,24 +122,27 @@ void Test_OS_GenericWrite_Impl(void) * Test Case For: * int32 OS_GenericWrite_Impl(uint32 local_id, const void *buffer, uint32 nbytes, int32 timeout) */ - char SrcData[] = "ABCDEFGHIJKL"; - char DestData[sizeof(SrcData)] = {0}; + char SrcData[] = "ABCDEFGHIJKL"; + char DestData[sizeof(SrcData)] = {0}; + OS_object_token_t token; + + memset(&token, 0, sizeof(token)); UT_SetDataBuffer(UT_KEY(OCS_write), DestData, sizeof(DestData), false); UT_PortablePosixIOTest_Set_Selectable(UT_INDEX_0, false); - OSAPI_TEST_FUNCTION_RC(OS_GenericWrite_Impl, (UT_INDEX_0, SrcData, sizeof(SrcData), 0), sizeof(SrcData)); + OSAPI_TEST_FUNCTION_RC(OS_GenericWrite_Impl, (&token, SrcData, sizeof(SrcData), 0), sizeof(SrcData)); UtAssert_MemCmp(SrcData, DestData, sizeof(SrcData), "write() data valid"); /* test invocation of select() in nonblocking mode */ UT_ResetState(UT_KEY(OCS_write)); UT_SetDataBuffer(UT_KEY(OCS_write), DestData, sizeof(DestData), false); UT_PortablePosixIOTest_Set_Selectable(UT_INDEX_0, true); - OSAPI_TEST_FUNCTION_RC(OS_GenericWrite_Impl, (UT_INDEX_0, SrcData, sizeof(SrcData), 0), sizeof(SrcData)); + OSAPI_TEST_FUNCTION_RC(OS_GenericWrite_Impl, (&token, SrcData, sizeof(SrcData), 0), sizeof(SrcData)); UtAssert_True(UT_GetStubCount(UT_KEY(OS_SelectSingle_Impl)) == 1, "OS_SelectSingle() called"); /* write() failure */ UT_SetDefaultReturnValue(UT_KEY(OCS_write), -1); - OSAPI_TEST_FUNCTION_RC(OS_GenericWrite_Impl, (UT_INDEX_0, DestData, sizeof(DestData), 0), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_GenericWrite_Impl, (&token, DestData, sizeof(DestData), 0), OS_ERROR); } /* ------------------- End of test cases --------------------------------------*/ diff --git a/src/unit-test-coverage/shared/src/coveragetest-filesys.c b/src/unit-test-coverage/shared/src/coveragetest-filesys.c index 8fd9dc218..6aaceacff 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-filesys.c +++ b/src/unit-test-coverage/shared/src/coveragetest-filesys.c @@ -237,8 +237,8 @@ void Test_OS_unmount(void) UtAssert_True(actual == expected, "OS_mount() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); /* set up so record is in the right state for mounting */ - OS_filesys_table[1].flags = - OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; + OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | + OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; expected = OS_SUCCESS; actual = OS_unmount("/ram0"); UtAssert_True(actual == expected, "OS_unmount(nominal) (%ld) == OS_SUCCESS", (long)actual); @@ -267,8 +267,8 @@ void Test_OS_fsBlocksFree(void) statval.blocks_free = OSAL_BLOCKCOUNT_C(1111); statval.total_blocks = OSAL_BLOCKCOUNT_C(2222); UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume_Impl), &statval, sizeof(statval), false); - OS_filesys_table[1].flags = - OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; + OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | + OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; actual = OS_fsBlocksFree("/cf"); UtAssert_True(actual == expected, "OS_fsBlocksFree() (%ld) == 1111", (long)actual); @@ -304,8 +304,8 @@ void Test_OS_fsBytesFree(void) statval.blocks_free = OSAL_BLOCKCOUNT_C(1111); statval.total_blocks = OSAL_BLOCKCOUNT_C(2222); UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume_Impl), &statval, sizeof(statval), false); - OS_filesys_table[1].flags = - OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; + OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | + OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; actual = OS_fsBytesFree("/cf", &bytes_free); @@ -381,8 +381,8 @@ void Test_OS_FS_GetPhysDriveName(void) actual = OS_FS_GetPhysDriveName(NameBuf, "none"); UtAssert_True(actual == expected, "OS_FS_GetPhysDriveName() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); - OS_filesys_table[1].flags = - OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; + OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | + OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; expected = OS_SUCCESS; actual = OS_FS_GetPhysDriveName(NameBuf, "none"); UtAssert_True(actual == expected, "OS_FS_GetPhysDriveName() (%ld) == OS_SUCCESS", (long)actual); @@ -436,8 +436,8 @@ void Test_OS_TranslatePath(void) int32 actual = ~OS_SUCCESS; /* Set up the local record for success */ - OS_filesys_table[1].flags = - OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; + OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | + OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; strcpy(OS_filesys_table[1].virtual_mountpt, "/cf"); strcpy(OS_filesys_table[1].system_mountpt, "/mnt/cf"); @@ -507,12 +507,17 @@ void Test_OS_FileSys_FindVirtMountPoint(void) bool result; OS_common_record_t refobj; const char refstr[] = "/ut"; + OS_object_token_t token; + + memset(&token, 0, sizeof(token)); + token.obj_idx = UT_INDEX_1; + token.obj_type = OS_OBJECT_TYPE_OS_FILESYS; memset(&refobj, 0, sizeof(refobj)); OS_filesys_table[1].flags = 0; OS_filesys_table[1].virtual_mountpt[0] = 0; - result = OS_FileSys_FindVirtMountPoint((void *)refstr, 1, &refobj); + result = OS_FileSys_FindVirtMountPoint((void *)refstr, &token, &refobj); UtAssert_True(!result, "OS_FileSys_FindVirtMountPoint(%s) (unmounted) == false", refstr); OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; @@ -520,17 +525,17 @@ void Test_OS_FileSys_FindVirtMountPoint(void) /* Verify cases where one is a substring of the other - * these should also return false */ strncpy(OS_filesys_table[1].virtual_mountpt, "/ut11", sizeof(OS_filesys_table[1].virtual_mountpt)); - result = OS_FileSys_FindVirtMountPoint((void *)refstr, 1, &refobj); + result = OS_FileSys_FindVirtMountPoint((void *)refstr, &token, &refobj); UtAssert_True(!result, "OS_FileSys_FindVirtMountPoint(%s) (mountpt=%s) == false", refstr, OS_filesys_table[1].virtual_mountpt); strncpy(OS_filesys_table[1].virtual_mountpt, "/u", sizeof(OS_filesys_table[1].virtual_mountpt)); - result = OS_FileSys_FindVirtMountPoint((void *)refstr, 1, &refobj); + result = OS_FileSys_FindVirtMountPoint((void *)refstr, &token, &refobj); UtAssert_True(!result, "OS_FileSys_FindVirtMountPoint(%s) (mountpt=%s) == false", refstr, OS_filesys_table[1].virtual_mountpt); strncpy(OS_filesys_table[1].virtual_mountpt, "/ut", sizeof(OS_filesys_table[1].virtual_mountpt)); - result = OS_FileSys_FindVirtMountPoint((void *)refstr, 1, &refobj); + result = OS_FileSys_FindVirtMountPoint((void *)refstr, &token, &refobj); UtAssert_True(result, "OS_FileSys_FindVirtMountPoint(%s) (nominal) == true", refstr); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-idmap.c b/src/unit-test-coverage/shared/src/coveragetest-idmap.c index 5ac362b92..b5bd75288 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-idmap.c +++ b/src/unit-test-coverage/shared/src/coveragetest-idmap.c @@ -40,7 +40,7 @@ typedef struct } Test_OS_ObjTypeCount_t; /* a match function that always matches */ -static bool TestAlwaysMatch(void *ref, osal_index_t local_id, const OS_common_record_t *obj) +static bool TestAlwaysMatch(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) { return true; } diff --git a/src/unit-test-coverage/shared/src/coveragetest-sockets.c b/src/unit-test-coverage/shared/src/coveragetest-sockets.c index d3a7feb63..938032578 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-sockets.c +++ b/src/unit-test-coverage/shared/src/coveragetest-sockets.c @@ -58,10 +58,18 @@ void Test_OS_CreateSocketName(void) * * This focuses on coverage paths, as this function does not return a value */ - OS_SockAddr_t testaddr; + OS_SockAddr_t testaddr; + OS_object_token_t token; + + OS_stream_table[0].stream_name[0] = 'x'; + + token.lock_mode = OS_LOCK_MODE_NONE; + token.obj_idx = UT_INDEX_0; + token.obj_id = UT_OBJID_1; + token.obj_type = OS_OBJECT_TYPE_OS_STREAM; UT_SetDefaultReturnValue(UT_KEY(OS_SocketAddrToString_Impl), OS_ERROR); - OS_CreateSocketName(0, &testaddr, "ut"); + OS_CreateSocketName(&token, &testaddr, "ut"); /* * The function should have called snprintf() to create the name diff --git a/src/unit-test-coverage/shared/src/os-shared-coverage-support.c b/src/unit-test-coverage/shared/src/os-shared-coverage-support.c index 4d105dc82..a857abb8a 100644 --- a/src/unit-test-coverage/shared/src/os-shared-coverage-support.c +++ b/src/unit-test-coverage/shared/src/os-shared-coverage-support.c @@ -55,6 +55,7 @@ void OS_UT_SetupTestTargetIndex(osal_objtype_t obj_type, osal_index_t test_idx) token.obj_id = OS_ObjectIdFromInteger((obj_type << OS_OBJECT_TYPE_SHIFT) | test_idx); UT_SetDataBuffer(UT_KEY(OS_ObjectIdGetById), &token, sizeof(OS_object_token_t), true); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_SUCCESS); } void OS_UT_SetupBasicInfoTest(osal_objtype_t obj_type, osal_index_t test_idx, const char *name, osal_id_t creator) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-binsem-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-binsem-impl-stubs.c index d1b8bfede..cee315962 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-binsem-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-binsem-impl-stubs.c @@ -38,10 +38,10 @@ ** Semaphore API */ -UT_DEFAULT_STUB(OS_BinSemCreate_Impl, (osal_index_t sem_id, uint32 sem_initial_value, uint32 options)) -UT_DEFAULT_STUB(OS_BinSemFlush_Impl, (osal_index_t sem_id)) -UT_DEFAULT_STUB(OS_BinSemGive_Impl, (osal_index_t sem_id)) -UT_DEFAULT_STUB(OS_BinSemTake_Impl, (osal_index_t sem_id)) -UT_DEFAULT_STUB(OS_BinSemTimedWait_Impl, (osal_index_t sem_id, uint32 msecs)) -UT_DEFAULT_STUB(OS_BinSemDelete_Impl, (osal_index_t sem_id)) -UT_DEFAULT_STUB(OS_BinSemGetInfo_Impl, (osal_index_t sem_id, OS_bin_sem_prop_t *bin_prop)) +UT_DEFAULT_STUB(OS_BinSemCreate_Impl, (const OS_object_token_t *token, uint32 sem_initial_value, uint32 options)) +UT_DEFAULT_STUB(OS_BinSemFlush_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_BinSemGive_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_BinSemTake_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_BinSemTimedWait_Impl, (const OS_object_token_t *token, uint32 msecs)) +UT_DEFAULT_STUB(OS_BinSemDelete_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_BinSemGetInfo_Impl, (const OS_object_token_t *token, OS_bin_sem_prop_t *bin_prop)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-console-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-console-impl-stubs.c index ec77389bb..99dc96511 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-console-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-console-impl-stubs.c @@ -37,11 +37,11 @@ /* ** Console output API (printf) */ -void OS_ConsoleWakeup_Impl(osal_index_t local_id) +void OS_ConsoleWakeup_Impl(const OS_object_token_t *token) { UT_DEFAULT_IMPL(OS_ConsoleWakeup_Impl); } -int32 OS_ConsoleCreate_Impl(osal_index_t local_id) +int32 OS_ConsoleCreate_Impl(const OS_object_token_t *token) { return UT_DEFAULT_IMPL(OS_ConsoleCreate_Impl); } diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-countsem-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-countsem-impl-stubs.c index c48a8168b..d6dcf2a54 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-countsem-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-countsem-impl-stubs.c @@ -38,9 +38,9 @@ ** Semaphore API */ -UT_DEFAULT_STUB(OS_CountSemCreate_Impl, (osal_index_t sem_id, uint32 sem_initial_value, uint32 options)) -UT_DEFAULT_STUB(OS_CountSemGive_Impl, (osal_index_t sem_id)) -UT_DEFAULT_STUB(OS_CountSemTake_Impl, (osal_index_t sem_id)) -UT_DEFAULT_STUB(OS_CountSemTimedWait_Impl, (osal_index_t sem_id, uint32 msecs)) -UT_DEFAULT_STUB(OS_CountSemDelete_Impl, (osal_index_t sem_id)) -UT_DEFAULT_STUB(OS_CountSemGetInfo_Impl, (osal_index_t sem_id, OS_count_sem_prop_t *count_prop)) +UT_DEFAULT_STUB(OS_CountSemCreate_Impl, (const OS_object_token_t *token, uint32 sem_initial_value, uint32 options)) +UT_DEFAULT_STUB(OS_CountSemGive_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_CountSemTake_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_CountSemTimedWait_Impl, (const OS_object_token_t *token, uint32 msecs)) +UT_DEFAULT_STUB(OS_CountSemDelete_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_CountSemGetInfo_Impl, (const OS_object_token_t *token, OS_count_sem_prop_t *count_prop)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-file-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-file-impl-stubs.c index ae3b5ac87..e5f0d52f5 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-file-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-file-impl-stubs.c @@ -39,27 +39,27 @@ * File API abstraction layer */ -UT_DEFAULT_STUB(OS_FileOpen_Impl, (osal_index_t file_id, const char *local_path, int32 flags, int32 access)) +UT_DEFAULT_STUB(OS_FileOpen_Impl, (const OS_object_token_t *token, const char *local_path, int32 flags, int32 access)) UT_DEFAULT_STUB(OS_FileStat_Impl, (const char *local_path, os_fstat_t *filestat)) UT_DEFAULT_STUB(OS_FileRemove_Impl, (const char *local_path)) UT_DEFAULT_STUB(OS_FileRename_Impl, (const char *old_path, const char *new_path)) UT_DEFAULT_STUB(OS_FileChmod_Impl, (const char *local_path, uint32 access)) -UT_DEFAULT_STUB(OS_ShellOutputToFile_Impl, (osal_index_t file_id, const char *Cmd)) +UT_DEFAULT_STUB(OS_ShellOutputToFile_Impl, (const OS_object_token_t *token, const char *Cmd)) /* * Directory API abstraction layer */ UT_DEFAULT_STUB(OS_DirCreate_Impl, (const char *local_path, uint32 access)) -UT_DEFAULT_STUB(OS_DirOpen_Impl, (osal_index_t dir_id, const char *local_path)) -UT_DEFAULT_STUB(OS_DirClose_Impl, (osal_index_t dir_id)) -UT_DEFAULT_STUB(OS_DirRead_Impl, (osal_index_t dir_id, os_dirent_t *dirent)) -UT_DEFAULT_STUB(OS_DirRewind_Impl, (osal_index_t dir_id)) +UT_DEFAULT_STUB(OS_DirOpen_Impl, (const OS_object_token_t *token, const char *local_path)) +UT_DEFAULT_STUB(OS_DirClose_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_DirRead_Impl, (const OS_object_token_t *token, os_dirent_t *dirent)) +UT_DEFAULT_STUB(OS_DirRewind_Impl, (const OS_object_token_t *token)) UT_DEFAULT_STUB(OS_DirRemove_Impl, (const char *local_path)) /* * Stream abstraction layer (applies to sockets and files) */ -int32 OS_GenericRead_Impl(osal_index_t local_id, void *buffer, size_t nbytes, int32 timeout) +int32 OS_GenericRead_Impl(const OS_object_token_t *token, void *buffer, size_t nbytes, int32 timeout) { int32 Status = UT_DEFAULT_IMPL(OS_GenericRead_Impl); @@ -71,7 +71,7 @@ int32 OS_GenericRead_Impl(osal_index_t local_id, void *buffer, size_t nbytes, in return Status; } -int32 OS_GenericWrite_Impl(osal_index_t local_id, const void *buffer, size_t nbytes, int32 timeout) +int32 OS_GenericWrite_Impl(const OS_object_token_t *token, const void *buffer, size_t nbytes, int32 timeout) { int32 Status = UT_DEFAULT_IMPL(OS_GenericWrite_Impl); @@ -83,5 +83,5 @@ int32 OS_GenericWrite_Impl(osal_index_t local_id, const void *buffer, size_t nby return Status; } -UT_DEFAULT_STUB(OS_GenericSeek_Impl, (osal_index_t file_id, int32 offset, uint32 whence)) -UT_DEFAULT_STUB(OS_GenericClose_Impl, (osal_index_t file_id)) +UT_DEFAULT_STUB(OS_GenericSeek_Impl, (const OS_object_token_t *token, int32 offset, uint32 whence)) +UT_DEFAULT_STUB(OS_GenericClose_Impl, (const OS_object_token_t *token)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-filesys-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-filesys-impl-stubs.c index e3f5d1037..0dd5577e0 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-filesys-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-filesys-impl-stubs.c @@ -36,14 +36,14 @@ /* * File system abstraction layer */ -UT_DEFAULT_STUB(OS_FileSysStartVolume_Impl, (osal_index_t filesys_id)) -UT_DEFAULT_STUB(OS_FileSysStopVolume_Impl, (osal_index_t filesys_id)) -UT_DEFAULT_STUB(OS_FileSysFormatVolume_Impl, (osal_index_t filesys_id)) -UT_DEFAULT_STUB(OS_FileSysCheckVolume_Impl, (osal_index_t filesys_id, bool repair)) -UT_DEFAULT_STUB(OS_FileSysMountVolume_Impl, (osal_index_t filesys_id)) -UT_DEFAULT_STUB(OS_FileSysUnmountVolume_Impl, (osal_index_t filesys_id)) +UT_DEFAULT_STUB(OS_FileSysStartVolume_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_FileSysStopVolume_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_FileSysFormatVolume_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_FileSysCheckVolume_Impl, (const OS_object_token_t *token, bool repair)) +UT_DEFAULT_STUB(OS_FileSysMountVolume_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_FileSysUnmountVolume_Impl, (const OS_object_token_t *token)) -int32 OS_FileSysStatVolume_Impl(osal_index_t filesys_id, OS_statvfs_t *result) +int32 OS_FileSysStatVolume_Impl(const OS_object_token_t *token, OS_statvfs_t *result) { int32 Status = UT_DEFAULT_IMPL(OS_FileSysStatVolume_Impl); diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-loader-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-loader-impl-stubs.c index c92e8ce31..7c2b2ccc5 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-loader-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-loader-impl-stubs.c @@ -36,9 +36,9 @@ /* * Module Loader API */ -UT_DEFAULT_STUB(OS_ModuleLoad_Impl, (osal_index_t module_id, const char *translated_path)) -UT_DEFAULT_STUB(OS_ModuleUnload_Impl, (osal_index_t module_id)) -UT_DEFAULT_STUB(OS_ModuleGetInfo_Impl, (osal_index_t module_id, OS_module_prop_t *module_prop)) +UT_DEFAULT_STUB(OS_ModuleLoad_Impl, (const OS_object_token_t *token, const char *translated_path)) +UT_DEFAULT_STUB(OS_ModuleUnload_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_ModuleGetInfo_Impl, (const OS_object_token_t *token, OS_module_prop_t *module_prop)) UT_DEFAULT_STUB(OS_GlobalSymbolLookup_Impl, (cpuaddr * SymbolAddress, const char *SymbolName)) -UT_DEFAULT_STUB(OS_ModuleSymbolLookup_Impl, (osal_index_t module_id, cpuaddr *SymbolAddress, const char *SymbolName)) +UT_DEFAULT_STUB(OS_ModuleSymbolLookup_Impl, (const OS_object_token_t *token, cpuaddr *SymbolAddress, const char *SymbolName)) UT_DEFAULT_STUB(OS_SymbolTableDump_Impl, (const char *filename, size_t size_limit)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-mutex-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-mutex-impl-stubs.c index 6bbe47829..f106785f4 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-mutex-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-mutex-impl-stubs.c @@ -38,8 +38,8 @@ ** Mutex API */ -UT_DEFAULT_STUB(OS_MutSemCreate_Impl, (osal_index_t sem_id, uint32 options)) -UT_DEFAULT_STUB(OS_MutSemGive_Impl, (osal_index_t sem_id)) -UT_DEFAULT_STUB(OS_MutSemTake_Impl, (osal_index_t sem_id)) -UT_DEFAULT_STUB(OS_MutSemDelete_Impl, (osal_index_t sem_id)) -UT_DEFAULT_STUB(OS_MutSemGetInfo_Impl, (osal_index_t sem_id, OS_mut_sem_prop_t *mut_prop)) +UT_DEFAULT_STUB(OS_MutSemCreate_Impl, (const OS_object_token_t *token, uint32 options)) +UT_DEFAULT_STUB(OS_MutSemGive_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_MutSemTake_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_MutSemDelete_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_MutSemGetInfo_Impl, (const OS_object_token_t *token, OS_mut_sem_prop_t *mut_prop)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-network-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-network-impl-stubs.c index 32cb5e40c..f797457e7 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-network-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-network-impl-stubs.c @@ -37,17 +37,17 @@ /* * Sockets API abstraction layer */ -UT_DEFAULT_STUB(OS_SocketOpen_Impl, (osal_index_t sock_id)) -UT_DEFAULT_STUB(OS_SocketClose_Impl, (osal_index_t sock_id)) -UT_DEFAULT_STUB(OS_SocketBind_Impl, (osal_index_t sock_id, const OS_SockAddr_t *Addr)) -UT_DEFAULT_STUB(OS_SocketAccept_Impl, - (osal_index_t sock_id, osal_index_t connsock_id, OS_SockAddr_t *Addr, int32 timeout)) -UT_DEFAULT_STUB(OS_SocketConnect_Impl, (osal_index_t sock_id, const OS_SockAddr_t *Addr, int32 timeout)) +UT_DEFAULT_STUB(OS_SocketOpen_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_SocketClose_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_SocketBind_Impl, (const OS_object_token_t *token, const OS_SockAddr_t *Addr)) +UT_DEFAULT_STUB(OS_SocketAccept_Impl, (const OS_object_token_t *sock_token, const OS_object_token_t *conn_token, + OS_SockAddr_t *Addr, int32 timeout)) +UT_DEFAULT_STUB(OS_SocketConnect_Impl, (const OS_object_token_t *token, const OS_SockAddr_t *Addr, int32 timeout)) UT_DEFAULT_STUB(OS_SocketRecvFrom_Impl, - (osal_index_t sock_id, void *buffer, size_t buflen, OS_SockAddr_t *RemoteAddr, int32 timeout)) + (const OS_object_token_t *token, void *buffer, size_t buflen, OS_SockAddr_t *RemoteAddr, int32 timeout)) UT_DEFAULT_STUB(OS_SocketSendTo_Impl, - (osal_index_t sock_id, const void *buffer, size_t buflen, const OS_SockAddr_t *RemoteAddr)) -UT_DEFAULT_STUB(OS_SocketGetInfo_Impl, (osal_index_t sock_id, OS_socket_prop_t *sock_prop)) + (const OS_object_token_t *token, const void *buffer, size_t buflen, const OS_SockAddr_t *RemoteAddr)) +UT_DEFAULT_STUB(OS_SocketGetInfo_Impl, (const OS_object_token_t *token, OS_socket_prop_t *sock_prop)) UT_DEFAULT_STUB(OS_SocketAddrInit_Impl, (OS_SockAddr_t * Addr, OS_SocketDomain_t Domain)) UT_DEFAULT_STUB(OS_SocketAddrToString_Impl, (char *buffer, size_t buflen, const OS_SockAddr_t *Addr)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-queue-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-queue-impl-stubs.c index 222204017..d3eea368a 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-queue-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-queue-impl-stubs.c @@ -38,8 +38,8 @@ ** Message Queue API */ -UT_DEFAULT_STUB(OS_QueueCreate_Impl, (osal_index_t queue_id, uint32 flags)) -UT_DEFAULT_STUB(OS_QueueDelete_Impl, (osal_index_t queue_id)) -UT_DEFAULT_STUB(OS_QueueGet_Impl, (osal_index_t queue_id, void *data, size_t size, size_t *size_copied, int32 timeout)) -UT_DEFAULT_STUB(OS_QueuePut_Impl, (osal_index_t queue_id, const void *data, size_t size, uint32 flags)) -UT_DEFAULT_STUB(OS_QueueGetInfo_Impl, (osal_index_t queue_id, OS_queue_prop_t *queue_prop)) +UT_DEFAULT_STUB(OS_QueueCreate_Impl, (const OS_object_token_t *token, uint32 flags)) +UT_DEFAULT_STUB(OS_QueueDelete_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_QueueGet_Impl, (const OS_object_token_t *token, void *data, size_t size, size_t *size_copied, int32 timeout)) +UT_DEFAULT_STUB(OS_QueuePut_Impl, (const OS_object_token_t *token, const void *data, size_t size, uint32 flags)) +UT_DEFAULT_STUB(OS_QueueGetInfo_Impl, (const OS_object_token_t *token, OS_queue_prop_t *queue_prop)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-select-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-select-impl-stubs.c index 1e3d84f25..4f4b720d6 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-select-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-select-impl-stubs.c @@ -33,5 +33,5 @@ #include "utstubs.h" #include "os-shared-select.h" -UT_DEFAULT_STUB(OS_SelectSingle_Impl, (osal_index_t stream_id, uint32 *SelectFlags, int32 msecs)) +UT_DEFAULT_STUB(OS_SelectSingle_Impl, (const OS_object_token_t *token, uint32 *SelectFlags, int32 msecs)) UT_DEFAULT_STUB(OS_SelectMultiple_Impl, (OS_FdSet * ReadSet, OS_FdSet *WriteSet, int32 msecs)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-task-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-task-impl-stubs.c index 56ad1c2ff..fdf9844c4 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-task-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-task-impl-stubs.c @@ -37,22 +37,22 @@ /* ** Task API */ -UT_DEFAULT_STUB(OS_TaskMatch_Impl, (osal_index_t task_id)) -UT_DEFAULT_STUB(OS_TaskCreate_Impl, (osal_index_t task_id, uint32 flags)) -UT_DEFAULT_STUB(OS_TaskDelete_Impl, (osal_index_t task_id)) +UT_DEFAULT_STUB(OS_TaskMatch_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_TaskCreate_Impl, (const OS_object_token_t *token, uint32 flags)) +UT_DEFAULT_STUB(OS_TaskDelete_Impl, (const OS_object_token_t *token)) void OS_TaskExit_Impl(void) { UT_DEFAULT_IMPL(OS_TaskExit_Impl); } UT_DEFAULT_STUB(OS_TaskDelay_Impl, (uint32 millisecond)) -UT_DEFAULT_STUB(OS_TaskSetPriority_Impl, (osal_index_t task_id, osal_priority_t new_priority)) +UT_DEFAULT_STUB(OS_TaskSetPriority_Impl, (const OS_object_token_t *token, osal_priority_t new_priority)) osal_id_t OS_TaskGetId_Impl(void) { int32 status; osal_id_t id; - status = UT_DEFAULT_IMPL(OS_TaskGetId_Impl); + status = UT_DEFAULT_IMPL_RC(OS_TaskGetId_Impl, 1); /* convert the int32 status value to an osal_id_t - * (this assumes the types are compatible) */ @@ -60,10 +60,10 @@ osal_id_t OS_TaskGetId_Impl(void) return id; } -UT_DEFAULT_STUB(OS_TaskGetInfo_Impl, (osal_index_t task_id, OS_task_prop_t *task_prop)) +UT_DEFAULT_STUB(OS_TaskGetInfo_Impl, (const OS_object_token_t *token, OS_task_prop_t *task_prop)) UT_DEFAULT_STUB(OS_TaskRegister_Impl, (osal_id_t global_task_id)) -bool OS_TaskIdMatchSystemData_Impl(void *ref, osal_index_t local_id, const OS_common_record_t *obj) +bool OS_TaskIdMatchSystemData_Impl(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) { return UT_DEFAULT_IMPL(OS_TaskIdMatchSystemData_Impl); } diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-timer-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-timer-impl-stubs.c index 29bb94214..f04c150ca 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-timer-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-timer-impl-stubs.c @@ -37,22 +37,21 @@ /* ** OS Time/Tick related API */ -UT_DEFAULT_STUB(OS_TimeBaseCreate_Impl, (osal_index_t timer_id)) -UT_DEFAULT_STUB(OS_TimeBaseSet_Impl, (osal_index_t timer_id, uint32 start_time, uint32 interval_time)) -UT_DEFAULT_STUB(OS_TimeBaseDelete_Impl, (osal_index_t timer_id)) -void OS_TimeBaseLock_Impl(osal_index_t timebase_id) +UT_DEFAULT_STUB(OS_TimeBaseCreate_Impl, (const OS_object_token_t *token)) +UT_DEFAULT_STUB(OS_TimeBaseSet_Impl, (const OS_object_token_t *token, uint32 start_time, uint32 interval_time)) +UT_DEFAULT_STUB(OS_TimeBaseDelete_Impl, (const OS_object_token_t *token)) +void OS_TimeBaseLock_Impl(const OS_object_token_t *token) { UT_DEFAULT_IMPL(OS_TimeBaseLock_Impl); } -void OS_TimeBaseUnlock_Impl(osal_index_t timebase_id) +void OS_TimeBaseUnlock_Impl(const OS_object_token_t *token) { UT_DEFAULT_IMPL(OS_TimeBaseUnlock_Impl); } -UT_DEFAULT_STUB(OS_TimeBaseGetInfo_Impl, (osal_index_t timer_id, OS_timebase_prop_t *timer_prop)) +UT_DEFAULT_STUB(OS_TimeBaseGetInfo_Impl, (const OS_object_token_t *token, OS_timebase_prop_t *timer_prop)) -UT_DEFAULT_STUB(OS_TimeBaseRegister_Impl, (osal_index_t timebase_id)) /* * Clock API low-level handlers */ diff --git a/src/unit-test-coverage/ut-stubs/src/portable-console-bsp-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/portable-console-bsp-impl-stubs.c index c4fdbee58..60fab614f 100644 --- a/src/unit-test-coverage/ut-stubs/src/portable-console-bsp-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/portable-console-bsp-impl-stubs.c @@ -37,7 +37,7 @@ /* ** Console output API (printf) */ -void OS_ConsoleOutput_Impl(osal_index_t local_id) +void OS_ConsoleOutput_Impl(const OS_object_token_t *token) { UT_DEFAULT_IMPL(OS_ConsoleOutput_Impl); } diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-tasks.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-tasks.h index e63fc68a6..b0a4bbb67 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-tasks.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-tasks.h @@ -45,7 +45,7 @@ extern size_t const UT_Ref_OS_impl_task_table_SIZE; int32 UT_Call_OS_VxWorks_TaskAPI_Impl_Init(void); void UT_TaskTest_SetImplTaskId(osal_index_t local_id, OCS_TASK_ID TaskId); -int UT_TaskTest_CallEntryPoint(int arg); +int UT_TaskTest_CallEntryPoint(osal_id_t arg); OCS_WIND_TCB *UT_TaskTest_GetTaskTcb(osal_index_t local_id); #endif /* INCLUDE_UT_ADAPTOR_TASKS_H_ */ diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-timebase.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-timebase.h index 6bb020cfd..af148e2f1 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-timebase.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-timebase.h @@ -49,7 +49,7 @@ int32 UT_TimeBaseTest_CallSigWaitFunc(osal_index_t local_id); int UT_TimeBaseTest_CallHelperTaskFunc(int arg); /* Invokes the static OS_VxWorks_RegisterTimer() function with given argument */ -void UT_TimeBaseTest_CallRegisterTimer(osal_index_t local_id); +void UT_TimeBaseTest_CallRegisterTimer(osal_id_t obj_id); /* Hook functions which set the timer registration state */ void UT_TimeBaseTest_SetTimeBaseRegState(osal_index_t local_id, bool is_success); diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-tasks.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-tasks.c index 2b2d19edf..f256dbaa9 100644 --- a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-tasks.c +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-tasks.c @@ -50,9 +50,9 @@ void UT_TaskTest_SetImplTaskId(osal_index_t local_id, OCS_TASK_ID TaskId) * in order for the UT to invoke it there must be a non-static * way to get access to it. */ -int UT_TaskTest_CallEntryPoint(int arg) +int UT_TaskTest_CallEntryPoint(osal_id_t arg) { - return OS_VxWorks_TaskEntry(arg); + return OS_VxWorks_TaskEntry(OS_ObjectIdToInteger(arg)); } OCS_WIND_TCB *UT_TaskTest_GetTaskTcb(osal_index_t local_id) diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-timebase.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-timebase.c index 0ec0b7a2b..f7814058a 100644 --- a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-timebase.c +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-timebase.c @@ -50,9 +50,9 @@ int UT_TimeBaseTest_CallHelperTaskFunc(int arg) return OS_VxWorks_TimeBaseTask(arg); } -void UT_TimeBaseTest_CallRegisterTimer(osal_index_t local_id) +void UT_TimeBaseTest_CallRegisterTimer(osal_id_t obj_id) { - OS_VxWorks_RegisterTimer(local_id); + OS_VxWorks_RegisterTimer(obj_id); } bool UT_TimeBaseTest_CheckTimeBaseRegisteredState(osal_index_t local_id) diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-binsem.c b/src/unit-test-coverage/vxworks/src/coveragetest-binsem.c index 906b4187b..41e19cf25 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-binsem.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-binsem.c @@ -50,10 +50,12 @@ void Test_OS_BinSemCreate_Impl(void) * Test Case For: * int32 OS_BinSemCreate_Impl (uint32 sem_id, uint32 initial_value, uint32 options) */ - OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate_Impl(UT_INDEX_0, 0, 0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate_Impl(&token, 0, 0), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_semBInitialize), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate_Impl(UT_INDEX_0, 0, 0), OS_SEM_FAILURE); + OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate_Impl(&token, 0, 0), OS_SEM_FAILURE); } void Test_OS_BinSemDelete_Impl(void) @@ -62,7 +64,9 @@ void Test_OS_BinSemDelete_Impl(void) * Test Case For: * int32 OS_BinSemDelete_Impl (uint32 sem_id) */ - OSAPI_TEST_FUNCTION_RC(OS_BinSemDelete_Impl(UT_INDEX_0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_BinSemDelete_Impl(&token), OS_SUCCESS); } void Test_OS_BinSemGive_Impl(void) @@ -71,10 +75,12 @@ void Test_OS_BinSemGive_Impl(void) * Test Case For: * int32 OS_BinSemGive_Impl ( uint32 sem_id ) */ - OSAPI_TEST_FUNCTION_RC(OS_BinSemGive_Impl(UT_INDEX_0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_BinSemGive_Impl(&token), OS_SUCCESS); UT_SetDefaultReturnValue(UT_StubKey_GenericSemGive, OS_SEM_FAILURE); - OSAPI_TEST_FUNCTION_RC(OS_BinSemGive_Impl(UT_INDEX_0), OS_SEM_FAILURE); + OSAPI_TEST_FUNCTION_RC(OS_BinSemGive_Impl(&token), OS_SEM_FAILURE); } void Test_OS_BinSemFlush_Impl(void) @@ -83,10 +89,12 @@ void Test_OS_BinSemFlush_Impl(void) * Test Case For: * int32 OS_BinSemFlush_Impl (uint32 sem_id) */ - OSAPI_TEST_FUNCTION_RC(OS_BinSemFlush_Impl(UT_INDEX_0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_BinSemFlush_Impl(&token), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_semFlush), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_BinSemFlush_Impl(UT_INDEX_0), OS_SEM_FAILURE); + OSAPI_TEST_FUNCTION_RC(OS_BinSemFlush_Impl(&token), OS_SEM_FAILURE); } void Test_OS_BinSemTake_Impl(void) @@ -95,7 +103,9 @@ void Test_OS_BinSemTake_Impl(void) * Test Case For: * int32 OS_BinSemTake_Impl ( uint32 sem_id ) */ - OSAPI_TEST_FUNCTION_RC(OS_BinSemTake_Impl(UT_INDEX_0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_BinSemTake_Impl(&token), OS_SUCCESS); } void Test_OS_BinSemTimedWait_Impl(void) @@ -104,13 +114,15 @@ void Test_OS_BinSemTimedWait_Impl(void) * Test Case For: * int32 OS_BinSemTimedWait_Impl ( uint32 sem_id, uint32 msecs ) */ - OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait_Impl(UT_INDEX_0, 100), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait_Impl(&token, 100), OS_SUCCESS); UT_SetDefaultReturnValue(UT_StubKey_GenericSemTake, OS_SEM_FAILURE); - OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait_Impl(UT_INDEX_0, 100), OS_SEM_FAILURE); + OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait_Impl(&token, 100), OS_SEM_FAILURE); UT_SetDefaultReturnValue(UT_KEY(OS_Milli2Ticks), OS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait_Impl(UT_INDEX_0, 100), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait_Impl(&token, 100), OS_ERROR); } void Test_OS_BinSemGetInfo_Impl(void) @@ -120,8 +132,10 @@ void Test_OS_BinSemGetInfo_Impl(void) * int32 OS_BinSemGetInfo_Impl (uint32 sem_id, OS_bin_sem_prop_t *sem_prop) */ OS_bin_sem_prop_t sem_prop; + OS_object_token_t token = UT_TOKEN_0; + memset(&sem_prop, 0xEE, sizeof(sem_prop)); - OSAPI_TEST_FUNCTION_RC(OS_BinSemGetInfo_Impl(UT_INDEX_0, &sem_prop), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_BinSemGetInfo_Impl(&token, &sem_prop), OS_SUCCESS); } /* ------------------- End of test cases --------------------------------------*/ diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-console.c b/src/unit-test-coverage/vxworks/src/coveragetest-console.c index f3a358f32..0f0f437fa 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-console.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-console.c @@ -41,35 +41,41 @@ void Test_OS_ConsoleWakeup_Impl(void) * Test Case For: * void OS_ConsoleWakeup_Impl(const char *string) */ + OS_object_token_t token = UT_TOKEN_0; /* no return code - check for coverage */ UT_ConsoleTest_SetConsoleAsync(0, true); - OS_ConsoleWakeup_Impl(0); + OS_ConsoleWakeup_Impl(&token); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_semGive)) == 1, "semGive() called in async mode"); UT_SetDefaultReturnValue(UT_KEY(OCS_semGive), -1); - OS_ConsoleWakeup_Impl(0); + OS_ConsoleWakeup_Impl(&token); UT_ConsoleTest_SetConsoleAsync(0, false); OS_console_table[0].WritePos = 1; - OS_ConsoleWakeup_Impl(0); + OS_ConsoleWakeup_Impl(&token); UtAssert_True(UT_GetStubCount(UT_KEY(OS_ConsoleOutput_Impl)) == 1, "OS_ConsoleOutput_Impl() called in sync mode"); } void Test_OS_ConsoleCreate_Impl(void) { - OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(0), OS_SUCCESS); + OS_object_token_t token; + + memset(&token, 0, sizeof(token)); + + OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(&token), OS_SUCCESS); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskSpawn)) == 1, "taskSpawn() called"); UT_SetDefaultReturnValue(UT_KEY(OCS_semCInitialize), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(0), OS_SEM_FAILURE); + OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(&token), OS_SEM_FAILURE); UT_ClearForceFail(UT_KEY(OCS_semCInitialize)); UT_SetDefaultReturnValue(UT_KEY(OCS_taskSpawn), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(0), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(&token), OS_ERROR); UT_ClearForceFail(UT_KEY(OCS_taskSpawn)); - OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(OS_MAX_CONSOLES + 1), OS_ERR_NOT_IMPLEMENTED); + token.obj_idx = OS_MAX_CONSOLES + 1; + OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(&token), OS_ERR_NOT_IMPLEMENTED); /* Also call the actual console task, to get coverage on it. * This task has an infinite loop, which only exits if semTake fails */ diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-countsem.c b/src/unit-test-coverage/vxworks/src/coveragetest-countsem.c index daa20093a..e09a9ee78 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-countsem.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-countsem.c @@ -46,10 +46,12 @@ void Test_OS_CountSemCreate_Impl(void) * Test Case For: * int32 OS_CountSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 options) */ - OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate_Impl(UT_INDEX_0, 0, 0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate_Impl(&token, 0, 0), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_semCInitialize), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate_Impl(UT_INDEX_0, 0, 0), OS_SEM_FAILURE); + OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate_Impl(&token, 0, 0), OS_SEM_FAILURE); } void Test_OS_CountSemDelete_Impl(void) @@ -58,7 +60,9 @@ void Test_OS_CountSemDelete_Impl(void) * Test Case For: * int32 OS_CountSemDelete_Impl (uint32 sem_id) */ - OSAPI_TEST_FUNCTION_RC(OS_CountSemDelete_Impl(UT_INDEX_0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_CountSemDelete_Impl(&token), OS_SUCCESS); } void Test_OS_CountSemGive_Impl(void) @@ -67,7 +71,9 @@ void Test_OS_CountSemGive_Impl(void) * Test Case For: * int32 OS_CountSemGive_Impl ( uint32 sem_id ) */ - OSAPI_TEST_FUNCTION_RC(OS_CountSemGive_Impl(UT_INDEX_0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_CountSemGive_Impl(&token), OS_SUCCESS); } void Test_OS_CountSemTake_Impl(void) @@ -76,7 +82,9 @@ void Test_OS_CountSemTake_Impl(void) * Test Case For: * int32 OS_CountSemTake_Impl ( uint32 sem_id ) */ - OSAPI_TEST_FUNCTION_RC(OS_CountSemTake_Impl(UT_INDEX_0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_CountSemTake_Impl(&token), OS_SUCCESS); } void Test_OS_CountSemTimedWait_Impl(void) @@ -85,10 +93,12 @@ void Test_OS_CountSemTimedWait_Impl(void) * Test Case For: * int32 OS_CountSemTimedWait_Impl ( uint32 sem_id, uint32 msecs ) */ - OSAPI_TEST_FUNCTION_RC(OS_CountSemTimedWait_Impl(UT_INDEX_0, 100), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_CountSemTimedWait_Impl(&token, 100), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OS_Milli2Ticks), OS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_CountSemTimedWait_Impl(UT_INDEX_0, 100), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_CountSemTimedWait_Impl(&token, 100), OS_ERROR); } void Test_OS_CountSemGetInfo_Impl(void) @@ -98,8 +108,10 @@ void Test_OS_CountSemGetInfo_Impl(void) * int32 OS_CountSemGetInfo_Impl (uint32 sem_id, OS_count_sem_prop_t *count_prop) */ OS_count_sem_prop_t count_prop; + OS_object_token_t token = UT_TOKEN_0; + memset(&count_prop, 0xEE, sizeof(count_prop)); - OSAPI_TEST_FUNCTION_RC(OS_CountSemGetInfo_Impl(UT_INDEX_0, &count_prop), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_CountSemGetInfo_Impl(&token, &count_prop), OS_SUCCESS); } /* ------------------- End of test cases --------------------------------------*/ diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-dirs.c b/src/unit-test-coverage/vxworks/src/coveragetest-dirs.c index f31a0bbe2..8818db37e 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-dirs.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-dirs.c @@ -63,9 +63,11 @@ void Test_OS_DirOpen_Impl(void) * Test Case For: * int32 OS_DirOpen_Impl(uint32 local_id, const char *local_path) */ - OSAPI_TEST_FUNCTION_RC(OS_DirOpen_Impl(UT_INDEX_0, "dir"), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_DirOpen_Impl(&token, "dir"), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_opendir), -1); - OSAPI_TEST_FUNCTION_RC(OS_DirOpen_Impl(UT_INDEX_0, "dir"), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_DirOpen_Impl(&token, "dir"), OS_ERROR); } void Test_OS_DirClose_Impl(void) @@ -74,7 +76,9 @@ void Test_OS_DirClose_Impl(void) * Test Case For: * int32 OS_DirClose_Impl(uint32 local_id) */ - OSAPI_TEST_FUNCTION_RC(OS_DirClose_Impl(UT_INDEX_0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_DirClose_Impl(&token), OS_SUCCESS); } void Test_OS_DirRead_Impl(void) @@ -83,12 +87,13 @@ void Test_OS_DirRead_Impl(void) * Test Case For: * int32 OS_DirRead_Impl(uint32 local_id, os_dirent_t *dirent) */ - os_dirent_t dirent_buff; + os_dirent_t dirent_buff; + OS_object_token_t token = UT_TOKEN_0; - OSAPI_TEST_FUNCTION_RC(OS_DirRead_Impl(UT_INDEX_0, &dirent_buff), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_DirRead_Impl(&token, &dirent_buff), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_readdir), -1); - OSAPI_TEST_FUNCTION_RC(OS_DirRead_Impl(UT_INDEX_0, &dirent_buff), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_DirRead_Impl(&token, &dirent_buff), OS_ERROR); } void Test_OS_DirRewind_Impl(void) @@ -97,7 +102,9 @@ void Test_OS_DirRewind_Impl(void) * Test Case For: * int32 OS_DirRewind_Impl(uint32 local_id) */ - OSAPI_TEST_FUNCTION_RC(OS_DirRewind_Impl(UT_INDEX_0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_DirRewind_Impl(&token), OS_SUCCESS); } void Test_OS_DirRemove_Impl(void) diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-filesys.c b/src/unit-test-coverage/vxworks/src/coveragetest-filesys.c index f10632e2b..52c2c69cf 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-filesys.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-filesys.c @@ -45,19 +45,23 @@ void Test_OS_FileSysStartVolume_Impl(void) * Test Case For: * int32 OS_FileSysStartVolume_Impl (uint32 filesys_id) */ - int32 expected; + int32 expected; + OS_object_token_t token; + + token = UT_TOKEN_0; /* Emulate an UNKNOWN entry */ OS_filesys_table[0].fstype = OS_FILESYS_TYPE_UNKNOWN; - OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(0), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(&token), OS_ERR_NOT_IMPLEMENTED); /* Emulate an FS_BASED entry */ OS_filesys_table[0].fstype = OS_FILESYS_TYPE_FS_BASED; - OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(0), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(&token), OS_SUCCESS); /* Emulate a VOLATILE_DISK entry (ramdisk) */ OS_filesys_table[1].fstype = OS_FILESYS_TYPE_VOLATILE_DISK; - OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(1), OS_SUCCESS); + token.obj_idx = UT_INDEX_1; + OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(&token), OS_SUCCESS); /* Emulate a NORMAL_DISK entry (ATA) */ OS_filesys_table[2].fstype = OS_FILESYS_TYPE_NORMAL_DISK; @@ -67,15 +71,17 @@ void Test_OS_FileSysStartVolume_Impl(void) #else expected = OS_ERR_NOT_IMPLEMENTED; #endif - OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(2), expected); + token = UT_TOKEN_2; + OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(&token), expected); /* Failure to create XBD layer */ UT_SetDefaultReturnValue(UT_KEY(OCS_xbdBlkDevCreateSync), -1); - OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(1), OS_FS_ERR_DRIVE_NOT_CREATED); + token = UT_TOKEN_1; + OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(&token), OS_FS_ERR_DRIVE_NOT_CREATED); /* Failure to create low level block dev */ UT_SetDefaultReturnValue(UT_KEY(OCS_ramDevCreate), -1); - OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(1), OS_FS_ERR_DRIVE_NOT_CREATED); + OSAPI_TEST_FUNCTION_RC(OS_FileSysStartVolume_Impl(&token), OS_FS_ERR_DRIVE_NOT_CREATED); } void Test_OS_FileSysStopVolume_Impl(void) @@ -83,12 +89,15 @@ void Test_OS_FileSysStopVolume_Impl(void) /* Test Case For: * int32 OS_FileSysStopVolume_Impl (uint32 filesys_id) */ - OSAPI_TEST_FUNCTION_RC(OS_FileSysStopVolume_Impl(0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_FileSysStopVolume_Impl(&token), OS_SUCCESS); /* Failure to delete XBD layer */ OS_filesys_table[1].fstype = OS_FILESYS_TYPE_VOLATILE_DISK; UT_FileSysTest_SetupFileSysEntry(1, NULL, 1, 4); - OSAPI_TEST_FUNCTION_RC(OS_FileSysStopVolume_Impl(1), OS_SUCCESS); + token = UT_TOKEN_1; + OSAPI_TEST_FUNCTION_RC(OS_FileSysStopVolume_Impl(&token), OS_SUCCESS); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_xbdBlkDevDelete)) == 1, "xbdBlkDevDelete() called"); } @@ -97,21 +106,22 @@ void Test_OS_FileSysFormatVolume_Impl(void) /* Test Case For: * int32 OS_FileSysFormatVolume_Impl (uint32 filesys_id) */ + OS_object_token_t token = UT_TOKEN_0; /* test unimplemented fs type */ OS_filesys_table[0].fstype = OS_FILESYS_TYPE_UNKNOWN; - OSAPI_TEST_FUNCTION_RC(OS_FileSysFormatVolume_Impl(0), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_FileSysFormatVolume_Impl(&token), OS_ERR_NOT_IMPLEMENTED); /* fs-based should be noop */ OS_filesys_table[0].fstype = OS_FILESYS_TYPE_FS_BASED; - OSAPI_TEST_FUNCTION_RC(OS_FileSysFormatVolume_Impl(0), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileSysFormatVolume_Impl(&token), OS_SUCCESS); OS_filesys_table[0].fstype = OS_FILESYS_TYPE_VOLATILE_DISK; - OSAPI_TEST_FUNCTION_RC(OS_FileSysFormatVolume_Impl(0), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileSysFormatVolume_Impl(&token), OS_SUCCESS); /* Failure of the dosFsVolFormat() call */ UT_SetDefaultReturnValue(UT_KEY(OCS_dosFsVolFormat), -1); - OSAPI_TEST_FUNCTION_RC(OS_FileSysFormatVolume_Impl(0), OS_FS_ERR_DRIVE_NOT_CREATED); + OSAPI_TEST_FUNCTION_RC(OS_FileSysFormatVolume_Impl(&token), OS_FS_ERR_DRIVE_NOT_CREATED); } void Test_OS_FileSysMountVolume_Impl(void) @@ -119,11 +129,12 @@ void Test_OS_FileSysMountVolume_Impl(void) /* Test Case For: * int32 OS_FileSysMountVolume_Impl (uint32 filesys_id) */ + OS_object_token_t token = UT_TOKEN_0; - OSAPI_TEST_FUNCTION_RC(OS_FileSysMountVolume_Impl(0), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileSysMountVolume_Impl(&token), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1); - OSAPI_TEST_FUNCTION_RC(OS_FileSysMountVolume_Impl(0), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_FileSysMountVolume_Impl(&token), OS_ERROR); UT_ClearForceFail(UT_KEY(OCS_open)); } @@ -132,15 +143,16 @@ void Test_OS_FileSysUnmountVolume_Impl(void) /* Test Case For: * int32 OS_FileSysUnmountVolume_Impl (uint32 filesys_id) */ + OS_object_token_t token = UT_TOKEN_0; - OSAPI_TEST_FUNCTION_RC(OS_FileSysUnmountVolume_Impl(0), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileSysUnmountVolume_Impl(&token), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1); - OSAPI_TEST_FUNCTION_RC(OS_FileSysUnmountVolume_Impl(0), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_FileSysUnmountVolume_Impl(&token), OS_ERROR); UT_ClearForceFail(UT_KEY(OCS_open)); UT_SetDefaultReturnValue(UT_KEY(OCS_ioctl), -1); - OSAPI_TEST_FUNCTION_RC(OS_FileSysUnmountVolume_Impl(0), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_FileSysUnmountVolume_Impl(&token), OS_ERROR); UT_ClearForceFail(UT_KEY(OCS_ioctl)); } @@ -150,11 +162,13 @@ void Test_OS_FileSysStatVolume_Impl(void) * Test Case For: * int32 OS_FileSysStatVolume_Impl (uint32 filesys_id, OS_statvfs_t *result) */ - OS_statvfs_t stat; - OSAPI_TEST_FUNCTION_RC(OS_FileSysStatVolume_Impl(0, &stat), OS_SUCCESS); + OS_statvfs_t stat; + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_FileSysStatVolume_Impl(&token, &stat), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_statvfs), -1); - OSAPI_TEST_FUNCTION_RC(OS_FileSysStatVolume_Impl(0, &stat), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_FileSysStatVolume_Impl(&token, &stat), OS_ERROR); } void Test_OS_FileSysCheckVolume_Impl(void) @@ -163,14 +177,16 @@ void Test_OS_FileSysCheckVolume_Impl(void) * Test Case For: * int32 OS_FileSysCheckVolume_Impl (uint32 filesys_id, bool repair) */ - OSAPI_TEST_FUNCTION_RC(OS_FileSysCheckVolume_Impl(0, true), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_FileSysCheckVolume_Impl(&token, true), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1); - OSAPI_TEST_FUNCTION_RC(OS_FileSysCheckVolume_Impl(0, false), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_FileSysCheckVolume_Impl(&token, false), OS_ERROR); UT_ClearForceFail(UT_KEY(OCS_open)); UT_SetDefaultReturnValue(UT_KEY(OCS_ioctl), -1); - OSAPI_TEST_FUNCTION_RC(OS_FileSysCheckVolume_Impl(0, false), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_FileSysCheckVolume_Impl(&token, false), OS_ERROR); } /* ------------------- End of test cases --------------------------------------*/ diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-loader.c b/src/unit-test-coverage/vxworks/src/coveragetest-loader.c index 5c718df1c..21fcb7858 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-loader.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-loader.c @@ -50,12 +50,14 @@ void Test_OS_ModuleLoad_Impl(void) /* Test Case For: * int32 OS_ModuleLoad_Impl ( uint32 module_id, char *translated_path ) */ - OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(UT_INDEX_0, "local"), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(&token, "local"), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1); - OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(UT_INDEX_0, "local"), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(&token, "local"), OS_ERROR); UT_ClearForceFail(UT_KEY(OCS_open)); UT_SetDefaultReturnValue(UT_KEY(OCS_loadModule), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(UT_INDEX_0, "local"), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(&token, "local"), OS_ERROR); UT_ClearForceFail(UT_KEY(OCS_loadModule)); } @@ -64,9 +66,11 @@ void Test_OS_ModuleUnload_Impl(void) /* Test Case For: * int32 OS_ModuleUnload_Impl ( uint32 module_id ) */ - OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl(UT_INDEX_0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl(&token), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_unldByModuleId), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl(UT_INDEX_0), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl(&token), OS_ERROR); UT_ClearForceFail(UT_KEY(OCS_unldByModuleId)); } @@ -75,10 +79,11 @@ void Test_OS_ModuleGetInfo_Impl(void) /* Test Case For: * int32 OS_ModuleGetInfo_Impl ( uint32 module_id, OS_module_prop_t *module_prop ) */ - OS_module_prop_t module_prop; + OS_module_prop_t module_prop; + OS_object_token_t token = UT_TOKEN_0; memset(&module_prop, 0, sizeof(module_prop)); - OSAPI_TEST_FUNCTION_RC(OS_ModuleGetInfo_Impl(UT_INDEX_0, &module_prop), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_ModuleGetInfo_Impl(&token, &module_prop), OS_SUCCESS); UtAssert_True(module_prop.addr.valid, "addresses in output valid"); /* @@ -87,7 +92,7 @@ void Test_OS_ModuleGetInfo_Impl(void) */ memset(&module_prop, 0, sizeof(module_prop)); UT_SetDefaultReturnValue(UT_KEY(OCS_moduleInfoGet), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_ModuleGetInfo_Impl(UT_INDEX_0, &module_prop), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_ModuleGetInfo_Impl(&token, &module_prop), OS_SUCCESS); UT_ClearForceFail(UT_KEY(OCS_moduleInfoGet)); UtAssert_True(!module_prop.addr.valid, "addresses in output not valid"); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-mutex.c b/src/unit-test-coverage/vxworks/src/coveragetest-mutex.c index 2320fb3a1..c606a95fb 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-mutex.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-mutex.c @@ -43,10 +43,12 @@ void Test_OS_MutSemCreate_Impl(void) * Test Case For: * int32 OS_MutSemCreate_Impl (uint32 sem_id, uint32 options) */ - OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate_Impl(UT_INDEX_0, 0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate_Impl(&token, 0), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_semMInitialize), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate_Impl(UT_INDEX_0, 0), OS_SEM_FAILURE); + OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate_Impl(&token, 0), OS_SEM_FAILURE); } void Test_OS_MutSemDelete_Impl(void) @@ -55,7 +57,9 @@ void Test_OS_MutSemDelete_Impl(void) * Test Case For: * int32 OS_MutSemDelete_Impl (uint32 sem_id) */ - OSAPI_TEST_FUNCTION_RC(OS_MutSemDelete_Impl(UT_INDEX_0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_MutSemDelete_Impl(&token), OS_SUCCESS); } void Test_OS_MutSemGive_Impl(void) @@ -64,7 +68,9 @@ void Test_OS_MutSemGive_Impl(void) * Test Case For: * int32 OS_MutSemGive_Impl ( uint32 sem_id ) */ - OSAPI_TEST_FUNCTION_RC(OS_MutSemGive_Impl(UT_INDEX_0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_MutSemGive_Impl(&token), OS_SUCCESS); } void Test_OS_MutSemTake_Impl(void) @@ -73,7 +79,9 @@ void Test_OS_MutSemTake_Impl(void) * Test Case For: * int32 OS_MutSemTake_Impl ( uint32 sem_id ) */ - OSAPI_TEST_FUNCTION_RC(OS_MutSemTake_Impl(UT_INDEX_0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_MutSemTake_Impl(&token), OS_SUCCESS); } void Test_OS_MutSemGetInfo_Impl(void) @@ -83,8 +91,10 @@ void Test_OS_MutSemGetInfo_Impl(void) * int32 OS_MutSemGetInfo_Impl (uint32 sem_id, OS_mut_sem_prop_t *mut_prop) */ OS_mut_sem_prop_t mut_prop; + OS_object_token_t token = UT_TOKEN_0; + memset(&mut_prop, 0xEE, sizeof(mut_prop)); - OSAPI_TEST_FUNCTION_RC(OS_MutSemGetInfo_Impl(UT_INDEX_0, &mut_prop), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_MutSemGetInfo_Impl(&token, &mut_prop), OS_SUCCESS); } /* ------------------- End of test cases --------------------------------------*/ diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-queues.c b/src/unit-test-coverage/vxworks/src/coveragetest-queues.c index a752c4e25..f8f67afd4 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-queues.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-queues.c @@ -47,10 +47,12 @@ void Test_OS_QueueCreate_Impl(void) * Test Case For: * int32 OS_QueueCreate_Impl (uint32 queue_id, uint32 flags) */ - OSAPI_TEST_FUNCTION_RC(OS_QueueCreate_Impl(UT_INDEX_0, 0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_QueueCreate_Impl(&token, 0), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_msgQCreate), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_QueueCreate_Impl(UT_INDEX_0, 0), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueueCreate_Impl(&token, 0), OS_ERROR); } void Test_OS_QueueDelete_Impl(void) @@ -59,10 +61,12 @@ void Test_OS_QueueDelete_Impl(void) * Test Case For: * int32 OS_QueueDelete_Impl (uint32 queue_id) */ - OSAPI_TEST_FUNCTION_RC(OS_QueueDelete_Impl(UT_INDEX_0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_QueueDelete_Impl(&token), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_msgQDelete), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_QueueDelete_Impl(UT_INDEX_0), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueueDelete_Impl(&token), OS_ERROR); } void Test_OS_QueueGet_Impl(void) @@ -71,23 +75,24 @@ void Test_OS_QueueGet_Impl(void) * Test Case For: * int32 OS_QueueGet_Impl (uint32 queue_id, void *data, uint32 size, uint32 *size_copied, int32 timeout) */ - char Data[16]; - size_t ActSz; + char Data[16]; + size_t ActSz; + OS_object_token_t token = UT_TOKEN_0; - OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(UT_INDEX_0, &Data, sizeof(Data), &ActSz, OS_PEND), OS_SUCCESS); - OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(UT_INDEX_0, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_SUCCESS); - OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(UT_INDEX_0, &Data, sizeof(Data), &ActSz, 100), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(&token, &Data, sizeof(Data), &ActSz, OS_PEND), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(&token, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(&token, &Data, sizeof(Data), &ActSz, 100), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OS_Milli2Ticks), OS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(UT_INDEX_0, &Data, sizeof(Data), &ActSz, 100), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(&token, &Data, sizeof(Data), &ActSz, 100), OS_ERROR); UT_SetDefaultReturnValue(UT_KEY(OCS_msgQReceive), OCS_ERROR); OCS_errno = OCS_S_objLib_OBJ_TIMEOUT; - OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(UT_INDEX_0, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_QUEUE_TIMEOUT); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(&token, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_QUEUE_TIMEOUT); OCS_errno = OCS_S_objLib_OBJ_UNAVAILABLE; - OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(UT_INDEX_0, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_QUEUE_EMPTY); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(&token, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_QUEUE_EMPTY); OCS_errno = 0; - OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(UT_INDEX_0, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(&token, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_ERROR); } void Test_OS_QueuePut_Impl(void) @@ -96,14 +101,16 @@ void Test_OS_QueuePut_Impl(void) * Test Case For: * int32 OS_QueuePut_Impl (uint32 queue_id, const void *data, uint32 size, uint32 flags) */ - char Data[16] = "Test"; - OSAPI_TEST_FUNCTION_RC(OS_QueuePut_Impl(UT_INDEX_0, Data, sizeof(Data), 0), OS_SUCCESS); + char Data[16] = "Test"; + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_QueuePut_Impl(&token, Data, sizeof(Data), 0), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_msgQSend), OCS_ERROR); OCS_errno = OCS_S_objLib_OBJ_UNAVAILABLE; - OSAPI_TEST_FUNCTION_RC(OS_QueuePut_Impl(UT_INDEX_0, Data, sizeof(Data), 0), OS_QUEUE_FULL); + OSAPI_TEST_FUNCTION_RC(OS_QueuePut_Impl(&token, Data, sizeof(Data), 0), OS_QUEUE_FULL); OCS_errno = 0; - OSAPI_TEST_FUNCTION_RC(OS_QueuePut_Impl(UT_INDEX_0, Data, sizeof(Data), 0), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueuePut_Impl(&token, Data, sizeof(Data), 0), OS_ERROR); } void Test_OS_QueueGetInfo_Impl(void) @@ -112,9 +119,11 @@ void Test_OS_QueueGetInfo_Impl(void) * Test Case For: * int32 OS_QueueGetInfo_Impl (uint32 queue_id, OS_queue_prop_t *queue_prop) */ - OS_queue_prop_t queue_prop; + OS_queue_prop_t queue_prop; + OS_object_token_t token = UT_TOKEN_0; + memset(&queue_prop, 0xEE, sizeof(queue_prop)); - OSAPI_TEST_FUNCTION_RC(OS_QueueGetInfo_Impl(UT_INDEX_0, &queue_prop), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_QueueGetInfo_Impl(&token, &queue_prop), OS_SUCCESS); } /* ------------------- End of test cases --------------------------------------*/ diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-shell.c b/src/unit-test-coverage/vxworks/src/coveragetest-shell.c index b9f547159..2195ff349 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-shell.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-shell.c @@ -37,8 +37,9 @@ void Test_OS_ShellOutputToFile_Impl(void) * Test Case For: * int32 OS_ShellOutputToFile_Impl(uint32 file_id, const char *Cmd) */ - int32 expected = OS_SUCCESS; - int32 actual; + int32 expected = OS_SUCCESS; + int32 actual; + OS_object_token_t token = UT_TOKEN_0; /* * The ShellOutputToFile will loop until the @@ -47,7 +48,7 @@ void Test_OS_ShellOutputToFile_Impl(void) */ UT_SetDeferredRetcode(UT_KEY(OCS_taskNameToId), 2, -1); - actual = OS_ShellOutputToFile_Impl(UT_INDEX_0, "TestCmd"); + actual = OS_ShellOutputToFile_Impl(&token, "TestCmd"); UtAssert_True(actual == expected, "OS_ShellOutputToFile_Impl() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_shellGenericInit)) == 1, "shellGenericInit() called"); @@ -55,7 +56,7 @@ void Test_OS_ShellOutputToFile_Impl(void) /* failure to open the output file */ UT_SetDefaultReturnValue(UT_KEY(OS_OpenCreate), OS_ERROR); expected = OS_ERROR; - actual = OS_ShellOutputToFile_Impl(UT_INDEX_0, "TestCmd"); + actual = OS_ShellOutputToFile_Impl(&token, "TestCmd"); UtAssert_True(actual == expected, "OS_ShellOutputToFile_Impl() (%ld) == OS_ERROR", (long)actual); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c b/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c index c7fddf233..9f7d9b9db 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c @@ -44,7 +44,6 @@ void Test_OS_GlobalSymbolLookup_Impl(void) OSAPI_TEST_FUNCTION_RC(OS_GlobalSymbolLookup_Impl(NULL, NULL), OS_INVALID_POINTER); UT_SetDefaultReturnValue(UT_KEY(OCS_symFind), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_GlobalSymbolLookup_Impl(&SymAddr, "symname"), OS_ERROR); - } void Test_OS_ModuleSymbolLookup_Impl(void) @@ -52,11 +51,13 @@ void Test_OS_ModuleSymbolLookup_Impl(void) /* Test Case For: * int32 OS_ModuleSymbolLookup_Impl( uint32 local_id, cpuaddr *SymbolAddress, const char *SymbolName ) */ - cpuaddr SymAddr; + cpuaddr SymAddr; + OS_object_token_t token = UT_TOKEN_0; - OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup_Impl(UT_INDEX_0, &SymAddr, "symname"), OS_SUCCESS); - OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup_Impl(UT_INDEX_0, NULL, NULL), OS_INVALID_POINTER); - UT_SetDefaultReturnValue(UT_KEY(OCS_symFind), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup_Impl(UT_INDEX_0, &SymAddr, "symname"), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup_Impl(&token, &SymAddr, "symname"), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup_Impl(&token, NULL, NULL), OS_INVALID_POINTER); + UT_SetDefaultReturnValue(UT_KEY(OCS_symFind), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup_Impl(&token, &SymAddr, "symname"), OS_ERROR); } void Test_OS_SymTableIterator_Impl(void) diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c b/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c index 1705b5fc9..7f27a328d 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c @@ -54,7 +54,7 @@ void Test_OS_VxWorksEntry(void) * Test Case For: * static int OS_VxWorksEntry(int arg) */ - OSAPI_TEST_FUNCTION_RC(UT_TaskTest_CallEntryPoint(0), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(UT_TaskTest_CallEntryPoint(OS_OBJECT_ID_UNDEFINED), OS_SUCCESS); UtAssert_True(UT_GetStubCount(UT_KEY(OS_TaskEntryPoint)) == 1, "OS_TaskEntryPoint() called"); } @@ -64,6 +64,8 @@ void Test_OS_TaskCreate_Impl(void) * Test Case For: * int32 OS_TaskCreate_Impl (uint32 task_id, uint32 flags) */ + OS_object_token_t token = UT_TOKEN_0; + UT_SetDataBuffer(UT_KEY(OCS_malloc), TestHeap, sizeof(TestHeap), false); UT_SetDataBuffer(UT_KEY(OCS_free), TestHeap, sizeof(TestHeap), false); @@ -71,10 +73,10 @@ void Test_OS_TaskCreate_Impl(void) * The first call checks the failure path and ensures that a malloc failure gets handled */ OS_task_table[0].stack_size = 250; UT_SetDefaultReturnValue(UT_KEY(OCS_malloc), OS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(UT_INDEX_0, 0), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(&token, 0), OS_ERROR); UT_ClearForceFail(UT_KEY(OCS_malloc)); - OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(UT_INDEX_0, OS_FP_ENABLED), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(&token, OS_FP_ENABLED), OS_SUCCESS); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_malloc)) == 2, "malloc() called"); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_free)) == 0, "free() not called"); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskInit)) == 1, "taskInit() called"); @@ -82,7 +84,7 @@ void Test_OS_TaskCreate_Impl(void) /* create again with smaller stack - this should re-use existing buffer */ OS_task_table[0].stack_size = 100; - OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(UT_INDEX_0, OS_FP_ENABLED), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(&token, OS_FP_ENABLED), OS_SUCCESS); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_malloc)) == 2, "malloc() not called"); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_free)) == 0, "free() not called"); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskInit)) == 2, "taskInit() called"); @@ -90,7 +92,7 @@ void Test_OS_TaskCreate_Impl(void) /* create again with larger stack - this should free existing and malloc() new buffer */ OS_task_table[0].stack_size = 400; - OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(UT_INDEX_0, OS_FP_ENABLED), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(&token, OS_FP_ENABLED), OS_SUCCESS); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_malloc)) == 3, "malloc() called"); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_free)) == 1, "free() called"); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskInit)) == 3, "taskInit() called"); @@ -98,7 +100,7 @@ void Test_OS_TaskCreate_Impl(void) /* other failure modes */ UT_SetDefaultReturnValue(UT_KEY(OCS_taskInit), -1); - OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(UT_INDEX_0, 0), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(&token, 0), OS_ERROR); } void Test_OS_TaskMatch_Impl(void) @@ -107,10 +109,12 @@ void Test_OS_TaskMatch_Impl(void) * Test Case For: * int32 OS_TaskMatch_Impl(uint32 task_id) */ + OS_object_token_t token = UT_TOKEN_0; + UT_TaskTest_SetImplTaskId(UT_INDEX_0, OCS_taskIdSelf()); - OSAPI_TEST_FUNCTION_RC(OS_TaskMatch_Impl(UT_INDEX_0), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_TaskMatch_Impl(&token), OS_SUCCESS); UT_TaskTest_SetImplTaskId(UT_INDEX_0, (OCS_TASK_ID)0); - OSAPI_TEST_FUNCTION_RC(OS_TaskMatch_Impl(UT_INDEX_0), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TaskMatch_Impl(&token), OS_ERROR); } void Test_OS_TaskDelete_Impl(void) @@ -119,11 +123,13 @@ void Test_OS_TaskDelete_Impl(void) * Test Case For: * int32 OS_TaskDelete_Impl (uint32 task_id) */ - OSAPI_TEST_FUNCTION_RC(OS_TaskDelete_Impl(UT_INDEX_0), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_TaskDelete_Impl(&token), OS_SUCCESS); /* failure mode */ UT_SetDefaultReturnValue(UT_KEY(OCS_taskDelete), -1); - OSAPI_TEST_FUNCTION_RC(OS_TaskDelete_Impl(UT_INDEX_0), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TaskDelete_Impl(&token), OS_ERROR); } void Test_OS_TaskExit_Impl(void) @@ -157,10 +163,12 @@ void Test_OS_TaskSetPriority_Impl(void) * Test Case For: * int32 OS_TaskSetPriority_Impl (uint32 task_id, uint32 new_priority) */ - OSAPI_TEST_FUNCTION_RC(OS_TaskSetPriority_Impl(UT_INDEX_0, OSAL_PRIORITY_C(100)), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_TaskSetPriority_Impl(&token, OSAL_PRIORITY_C(100)), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_taskPrioritySet), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_TaskSetPriority_Impl(UT_INDEX_0, OSAL_PRIORITY_C(100)), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TaskSetPriority_Impl(&token, OSAL_PRIORITY_C(100)), OS_ERROR); } void Test_OS_TaskRegister_Impl(void) @@ -196,9 +204,11 @@ void Test_OS_TaskGetInfo_Impl(void) * Test Case For: * int32 OS_TaskGetInfo_Impl (uint32 task_id, OS_task_prop_t *task_prop) */ - OS_task_prop_t task_prop; + OS_task_prop_t task_prop; + OS_object_token_t token = UT_TOKEN_0; + memset(&task_prop, 0xEE, sizeof(task_prop)); - OSAPI_TEST_FUNCTION_RC(OS_TaskGetInfo_Impl(UT_INDEX_0, &task_prop), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_TaskGetInfo_Impl(&token, &task_prop), OS_SUCCESS); } void Test_OS_TaskValidateSystemData_Impl(void) @@ -222,15 +232,16 @@ void Test_OS_TaskIdMatchSystemData_Impl(void) * Test Case For: * bool OS_TaskIdMatchSystemData_Impl(void *ref, uint32 local_id, const OS_common_record_t *obj) */ - OCS_TASK_ID test_sys_id; + OCS_TASK_ID test_sys_id; + OS_object_token_t token = UT_TOKEN_0; memset(&test_sys_id, 'x', sizeof(test_sys_id)); UT_TaskTest_SetImplTaskId(UT_INDEX_0, test_sys_id); - OSAPI_TEST_FUNCTION_RC(OS_TaskIdMatchSystemData_Impl(&test_sys_id, UT_INDEX_0, NULL), true); + OSAPI_TEST_FUNCTION_RC(OS_TaskIdMatchSystemData_Impl(&test_sys_id, &token, NULL), true); memset(&test_sys_id, 'y', sizeof(test_sys_id)); - OSAPI_TEST_FUNCTION_RC(OS_TaskIdMatchSystemData_Impl(&test_sys_id, UT_INDEX_0, NULL), false); + OSAPI_TEST_FUNCTION_RC(OS_TaskIdMatchSystemData_Impl(&test_sys_id, &token, NULL), false); } /* ------------------- End of test cases --------------------------------------*/ diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c b/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c index d001875bd..82098fe2c 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c @@ -50,7 +50,8 @@ void Test_OS_TimeBaseLock_Impl(void) /* Test Case For: * void OS_TimeBaseLock_Impl(uint32 local_id) */ - OS_TimeBaseLock_Impl(UT_INDEX_0); + OS_object_token_t token = UT_TOKEN_0; + OS_TimeBaseLock_Impl(&token); } void Test_OS_TimeBaseUnlock_Impl(void) @@ -58,7 +59,8 @@ void Test_OS_TimeBaseUnlock_Impl(void) /* Test Case For: * void OS_TimeBaseUnlock_Impl(uint32 local_id) */ - OS_TimeBaseUnlock_Impl(UT_INDEX_0); + OS_object_token_t token = UT_TOKEN_0; + OS_TimeBaseUnlock_Impl(&token); } static int32 UT_TimeBaseTest_TimeBaseRegHook(void *UserObj, int32 StubRetcode, uint32 CallCount, @@ -99,7 +101,8 @@ void Test_OS_TimeBaseCreate_Impl(void) /* Test Case For: * int32 OS_TimeBaseCreate_Impl(uint32 timer_id) */ - osal_id_t id; + osal_id_t id; + OS_object_token_t token = UT_TOKEN_0; /* * Test paths though the signal number assignment. @@ -111,17 +114,17 @@ void Test_OS_TimeBaseCreate_Impl(void) OS_global_timebase_table[1].active_id = id; UT_TimeBaseTest_Setup(UT_INDEX_1, OCS_SIGRTMIN, false); UT_SetDefaultReturnValue(UT_KEY(OCS_sigismember), true); - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(UT_INDEX_0), OS_TIMER_ERR_UNAVAILABLE); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(&token), OS_TIMER_ERR_UNAVAILABLE); UT_ResetState(UT_KEY(OCS_sigismember)); /* fail to initialize the sem */ UT_SetDefaultReturnValue(UT_KEY(OCS_semMInitialize), -1); - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(UT_INDEX_0), OS_TIMER_ERR_INTERNAL); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(&token), OS_TIMER_ERR_INTERNAL); UT_ClearForceFail(UT_KEY(OCS_semMInitialize)); /* fail to spawn the task */ UT_SetDefaultReturnValue(UT_KEY(OCS_taskSpawn), -1); - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(UT_INDEX_0), OS_TIMER_ERR_INTERNAL); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(&token), OS_TIMER_ERR_INTERNAL); UT_ClearForceFail(UT_KEY(OCS_taskSpawn)); /* @@ -129,7 +132,7 @@ void Test_OS_TimeBaseCreate_Impl(void) * this mimics the situation where the reg global is never * set past OS_TimerRegState_INIT */ - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(UT_INDEX_0), OS_TIMER_ERR_INTERNAL); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(&token), OS_TIMER_ERR_INTERNAL); /* * Do Nominal/success case now. @@ -137,7 +140,7 @@ void Test_OS_TimeBaseCreate_Impl(void) * mimic registration success */ UT_SetHookFunction(UT_KEY(OCS_taskSpawn), UT_TimeBaseTest_TimeBaseRegHook, NULL); - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(UT_INDEX_0), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(&token), OS_SUCCESS); /* * For coverage, call the OS_VxWorks_TimeBaseTask() function. @@ -147,13 +150,13 @@ void Test_OS_TimeBaseCreate_Impl(void) /* * Check outputs of OS_VxWorks_RegisterTimer() function. */ - UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_0); - UT_TimeBaseTest_CallRegisterTimer(UT_INDEX_0); + UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_1); + UT_TimeBaseTest_CallRegisterTimer(OS_OBJECT_ID_UNDEFINED); UtAssert_True(UT_TimeBaseTest_CheckTimeBaseRegisteredState(UT_INDEX_0), "timer successfully registered"); - UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_0); + UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_1); UT_SetDefaultReturnValue(UT_KEY(OCS_timer_create), -1); - UT_TimeBaseTest_CallRegisterTimer(UT_INDEX_0); + UT_TimeBaseTest_CallRegisterTimer(OS_OBJECT_ID_UNDEFINED); UtAssert_True(UT_TimeBaseTest_CheckTimeBaseErrorState(UT_INDEX_0), "timer registration failure state"); } @@ -166,6 +169,7 @@ void Test_OS_VxWorks_SigWait(void) int signo = OCS_SIGRTMIN; struct OCS_itimerspec config_value; osal_id_t id; + OS_object_token_t token = UT_TOKEN_0; memset(&id, 0x02, sizeof(id)); OS_global_timebase_table[0].active_id = id; @@ -176,7 +180,7 @@ void Test_OS_VxWorks_SigWait(void) UT_SetDataBuffer(UT_KEY(OCS_timer_settime), &config_value, sizeof(config_value), false); UT_SetDataBuffer(UT_KEY(OCS_timer_gettime), &config_value, sizeof(config_value), false); UT_TimeBaseTest_Setup(UT_INDEX_0, signo, true); - OS_TimeBaseSet_Impl(UT_INDEX_0, 1111111, 2222222); + OS_TimeBaseSet_Impl(&token, 1111111, 2222222); UT_SetDataBuffer(UT_KEY(OCS_sigwait), &signo, sizeof(signo), false); OSAPI_TEST_FUNCTION_RC(UT_TimeBaseTest_CallSigWaitFunc(UT_INDEX_0), 1111111); @@ -195,13 +199,15 @@ void Test_OS_TimeBaseSet_Impl(void) /* Test Case For: * int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time) */ - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(UT_INDEX_0, 1, 1), OS_ERR_NOT_IMPLEMENTED); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(&token, 1, 1), OS_ERR_NOT_IMPLEMENTED); UT_TimeBaseTest_Setup(UT_INDEX_0, OCS_SIGRTMIN, false); - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(UT_INDEX_0, 1, 1), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(&token, 1, 1), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_timer_settime), -1); - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(UT_INDEX_0, 1, 1), OS_TIMER_ERR_INVALID_ARGS); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(&token, 1, 1), OS_TIMER_ERR_INVALID_ARGS); } void Test_OS_TimeBaseDelete_Impl(void) @@ -209,8 +215,10 @@ void Test_OS_TimeBaseDelete_Impl(void) /* Test Case For: * int32 OS_TimeBaseDelete_Impl(uint32 timer_id) */ + OS_object_token_t token = UT_TOKEN_0; + UT_TimeBaseTest_Setup(UT_INDEX_0, OCS_SIGRTMIN, false); - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseDelete_Impl(UT_INDEX_0), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseDelete_Impl(&token), OS_SUCCESS); } void Test_OS_TimeBaseGetInfo_Impl(void) @@ -219,7 +227,9 @@ void Test_OS_TimeBaseGetInfo_Impl(void) * int32 OS_TimeBaseGetInfo_Impl (uint32 timer_id, OS_timebase_prop_t *timer_prop) */ OS_timebase_prop_t timer_prop; - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseGetInfo_Impl(UT_INDEX_0, &timer_prop), OS_SUCCESS); + OS_object_token_t token = UT_TOKEN_0; + + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseGetInfo_Impl(&token, &timer_prop), OS_SUCCESS); } /* ------------------- End of test cases --------------------------------------*/ diff --git a/src/unit-test-coverage/vxworks/src/os-vxworks-coveragetest.h b/src/unit-test-coverage/vxworks/src/os-vxworks-coveragetest.h index 989f27da7..629929372 100644 --- a/src/unit-test-coverage/vxworks/src/os-vxworks-coveragetest.h +++ b/src/unit-test-coverage/vxworks/src/os-vxworks-coveragetest.h @@ -47,6 +47,22 @@ #define UT_INDEX_1 OSAL_INDEX_C(1) #define UT_INDEX_2 OSAL_INDEX_C(2) +#define UT_TOKEN_0 \ + (OS_object_token_t) \ + { \ + .obj_id = (osal_id_t) {0x10000}, .obj_idx = 0 \ + } +#define UT_TOKEN_1 \ + (OS_object_token_t) \ + { \ + .obj_id = (osal_id_t) {0x10001}, .obj_idx = 1 \ + } +#define UT_TOKEN_2 \ + (OS_object_token_t) \ + { \ + .obj_id = (osal_id_t) {0x10002}, .obj_idx = 2 \ + } + /* Osapi_Test_Setup * * Purpose: From cbead8e54ebdb3106396d6e2c182988e3511b622 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 1 Dec 2020 10:51:00 -0500 Subject: [PATCH 07/11] Fix #649, use full object ID in timecb list For the linked list of timer callbacks, use the full object ID value rather than just the index. This ensures consistency in the list and also makes it easier to manage. --- src/os/shared/inc/os-shared-time.h | 4 +- src/os/shared/src/osapi-time.c | 61 +++++++++++-------- src/os/shared/src/osapi-timebase.c | 19 +++--- .../timer-add-api-test/timer-add-api-test.c | 2 +- .../shared/src/coveragetest-time.c | 4 +- .../shared/src/coveragetest-timebase.c | 9 ++- 6 files changed, 57 insertions(+), 42 deletions(-) diff --git a/src/os/shared/inc/os-shared-time.h b/src/os/shared/inc/os-shared-time.h index 6c0ac43f9..456991f8c 100644 --- a/src/os/shared/inc/os-shared-time.h +++ b/src/os/shared/inc/os-shared-time.h @@ -38,8 +38,8 @@ typedef struct char timer_name[OS_MAX_API_NAME]; uint32 flags; OS_object_token_t timebase_token; - osal_index_t prev_ref; - osal_index_t next_ref; + osal_id_t prev_cb; + osal_id_t next_cb; uint32 backlog_resets; int32 wait_time; int32 interval_time; diff --git a/src/os/shared/src/osapi-time.c b/src/os/shared/src/osapi-time.c index 6c78ea160..6df1fdab0 100644 --- a/src/os/shared/src/osapi-time.c +++ b/src/os/shared/src/osapi-time.c @@ -94,10 +94,10 @@ static int32 OS_DoTimerAdd(osal_id_t *timer_id, const char *timer_name, osal_id_ osal_objtype_t objtype; OS_object_token_t timebase_token; OS_object_token_t timecb_token; + OS_object_token_t listcb_token; OS_timecb_internal_record_t * timecb; + OS_timecb_internal_record_t * list_timecb; OS_timebase_internal_record_t *timebase; - osal_id_t cb_list; - osal_index_t attach_id; /* ** Check Parameters @@ -166,8 +166,8 @@ static int32 OS_DoTimerAdd(osal_id_t *timer_id, const char *timer_name, osal_id_ timecb->callback_ptr = callback_ptr; timecb->callback_arg = callback_arg; timecb->flags = flags; - timecb->prev_ref = OS_ObjectIndexFromToken(&timecb_token); - timecb->next_ref = OS_ObjectIndexFromToken(&timecb_token); + timecb->prev_cb = OS_ObjectIdFromToken(&timecb_token); + timecb->next_cb = OS_ObjectIdFromToken(&timecb_token); /* * Now we need to add it to the time base callback ring, so take the @@ -175,18 +175,23 @@ static int32 OS_DoTimerAdd(osal_id_t *timer_id, const char *timer_name, osal_id_ */ OS_TimeBaseLock_Impl(&timebase_token); - cb_list = timebase->first_cb; - timebase->first_cb = OS_ObjectIdFromToken(&timecb_token); - - if (OS_ObjectIdDefined(cb_list)) + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMECB, timebase->first_cb, &listcb_token) == OS_SUCCESS) { - OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_TIMECB, cb_list, &attach_id); - timecb->next_ref = attach_id; - timecb->prev_ref = OS_timecb_table[attach_id].prev_ref; - OS_timecb_table[timecb->prev_ref].next_ref = OS_ObjectIndexFromToken(&timecb_token); - OS_timecb_table[timecb->next_ref].prev_ref = OS_ObjectIndexFromToken(&timecb_token); + list_timecb = OS_OBJECT_TABLE_GET(OS_timecb_table, listcb_token); + + timecb->next_cb = OS_ObjectIdFromToken(&listcb_token); + timecb->prev_cb = list_timecb->prev_cb; + + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMECB, timecb->prev_cb, &listcb_token) == OS_SUCCESS) + { + list_timecb->prev_cb = OS_ObjectIdFromToken(&timecb_token); + list_timecb = OS_OBJECT_TABLE_GET(OS_timecb_table, listcb_token); + list_timecb->next_cb = OS_ObjectIdFromToken(&timecb_token); + } } + timebase->first_cb = OS_ObjectIdFromToken(&timecb_token); + OS_TimeBaseUnlock_Impl(&timebase_token); /* Check result, finalize record, and unlock global table. */ @@ -399,8 +404,10 @@ int32 OS_TimerDelete(osal_id_t timer_id) osal_id_t dedicated_timebase_id; OS_object_token_t timecb_token; OS_object_token_t timebase_token; + OS_object_token_t listcb_token; OS_timebase_internal_record_t *timebase; OS_timecb_internal_record_t * timecb; + OS_timecb_internal_record_t * list_timecb; dedicated_timebase_id = OS_OBJECT_ID_UNDEFINED; memset(&timebase_token, 0, sizeof(timebase_token)); @@ -436,25 +443,31 @@ int32 OS_TimerDelete(osal_id_t timer_id) /* * Now we need to remove it from the time base callback ring */ - if (OS_ObjectIdEqual(timebase->first_cb, timer_id)) + if (OS_ObjectIdEqual(timebase->first_cb, OS_ObjectIdFromToken(&timecb_token))) { - if (timecb->next_ref != OS_ObjectIndexFromToken(&timecb_token)) + if (OS_ObjectIdEqual(OS_ObjectIdFromToken(&timecb_token), timecb->next_cb)) { - OS_ObjectIdCompose_Impl(OS_OBJECT_TYPE_OS_TIMEBASE, timecb->next_ref, &timebase->first_cb); + timebase->first_cb = OS_OBJECT_ID_UNDEFINED; } else { - /* - * consider the list empty - */ - timebase->first_cb = OS_OBJECT_ID_UNDEFINED; + timebase->first_cb = timecb->next_cb; } } - OS_timecb_table[timecb->prev_ref].next_ref = timecb->next_ref; - OS_timecb_table[timecb->next_ref].prev_ref = timecb->prev_ref; - timecb->next_ref = OS_ObjectIndexFromToken(&timecb_token); - timecb->prev_ref = OS_ObjectIndexFromToken(&timecb_token); + if(OS_ObjectIdGetById(OS_LOCK_MODE_NONE,OS_OBJECT_TYPE_OS_TIMECB,timecb->prev_cb,&listcb_token) == OS_SUCCESS) + { + list_timecb = OS_OBJECT_TABLE_GET(OS_timecb_table, listcb_token); + list_timecb->next_cb = timecb->next_cb; + } + if(OS_ObjectIdGetById(OS_LOCK_MODE_NONE,OS_OBJECT_TYPE_OS_TIMECB,timecb->next_cb,&listcb_token) == OS_SUCCESS) + { + list_timecb = OS_OBJECT_TABLE_GET(OS_timecb_table, listcb_token); + list_timecb->prev_cb = timecb->prev_cb; + } + + timecb->next_cb = OS_ObjectIdFromToken(&timecb_token); + timecb->prev_cb = OS_ObjectIdFromToken(&timecb_token); OS_TimeBaseUnlock_Impl(&timecb->timebase_token); diff --git a/src/os/shared/src/osapi-timebase.c b/src/os/shared/src/osapi-timebase.c index 62e935a95..8eb4ad6f4 100644 --- a/src/os/shared/src/osapi-timebase.c +++ b/src/os/shared/src/osapi-timebase.c @@ -402,9 +402,7 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) OS_timecb_internal_record_t * timecb; OS_common_record_t * record; OS_object_token_t token; - osal_index_t timer_id; - osal_index_t curr_cb_local_id; - osal_id_t curr_cb_public_id; + OS_object_token_t cb_token; uint32 tick_time; uint32 spin_cycles; int32 saved_wait_time; @@ -493,14 +491,12 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) } timebase->freerun_time += tick_time; - if (OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_TIMECB, timebase->first_cb, &timer_id) == 0) + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMECB, timebase->first_cb, &cb_token) == 0) { - curr_cb_local_id = timer_id; do { - curr_cb_public_id = OS_global_timecb_table[curr_cb_local_id].active_id; - timecb = &OS_timecb_table[curr_cb_local_id]; - saved_wait_time = timecb->wait_time; + timecb = OS_OBJECT_TABLE_GET(OS_timecb_table, cb_token); + saved_wait_time = timecb->wait_time; timecb->wait_time -= tick_time; while (timecb->wait_time <= 0) { @@ -525,7 +521,7 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) */ if (saved_wait_time > 0 && timecb->callback_ptr != NULL) { - (*timecb->callback_ptr)(curr_cb_public_id, timecb->callback_arg); + (*timecb->callback_ptr)(OS_ObjectIdFromToken(&cb_token), timecb->callback_arg); } /* @@ -536,8 +532,9 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) break; } } - curr_cb_local_id = timecb->next_ref; - } while (curr_cb_local_id != timer_id); + + } while (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMECB, timecb->next_cb, &cb_token) == OS_SUCCESS && + !OS_ObjectIdEqual(OS_ObjectIdFromToken(&cb_token), timebase->first_cb)); } OS_TimeBaseUnlock_Impl(&token); diff --git a/src/tests/timer-add-api-test/timer-add-api-test.c b/src/tests/timer-add-api-test/timer-add-api-test.c index 608eacdca..c33d53bbe 100644 --- a/src/tests/timer-add-api-test/timer-add-api-test.c +++ b/src/tests/timer-add-api-test/timer-add-api-test.c @@ -130,7 +130,7 @@ void TestTimerAddApi(void) OS_GetLocalTime(&EndTime); - for (i = 0; i < NUMBER_OF_TIMERS; i++) + for (i = NUMBER_OF_TIMERS-1; i >= 0; --i) { TimerStatus[i] = OS_TimerDelete(TimerID[i]); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-time.c b/src/unit-test-coverage/shared/src/coveragetest-time.c index 9ab947db0..840638d10 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-time.c +++ b/src/unit-test-coverage/shared/src/coveragetest-time.c @@ -205,8 +205,8 @@ void Test_OS_TimerDelete(void) OS_timecb_table[1].timebase_token.obj_id = UT_OBJID_1; OS_timecb_table[1].timebase_token.obj_idx = UT_INDEX_0; OS_timecb_table[2].timebase_token = OS_timecb_table[1].timebase_token; - OS_timecb_table[2].next_ref = UT_INDEX_1; - OS_timecb_table[1].next_ref = UT_INDEX_1; + OS_timecb_table[2].next_cb = UT_OBJID_1; + OS_timecb_table[1].next_cb = UT_OBJID_1; OS_timebase_table[0].first_cb = UT_OBJID_2; actual = OS_TimerDelete(UT_OBJID_2); UtAssert_True(actual == expected, "OS_TimerDelete() (%ld) == OS_SUCCESS", (long)actual); diff --git a/src/unit-test-coverage/shared/src/coveragetest-timebase.c b/src/unit-test-coverage/shared/src/coveragetest-timebase.c index 6239ffd71..aea8714e4 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-timebase.c +++ b/src/unit-test-coverage/shared/src/coveragetest-timebase.c @@ -243,14 +243,19 @@ void Test_OS_TimeBase_CallbackThread(void) * void OS_TimeBase_CallbackThread(uint32 timebase_id) */ OS_common_record_t *recptr; + OS_object_token_t timecb_token; recptr = &OS_global_timebase_table[2]; memset(recptr, 0, sizeof(*recptr)); recptr->active_id = UT_OBJID_2; + OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMECB, UT_OBJID_1, &timecb_token); OS_timebase_table[2].external_sync = UT_TimerSync; - OS_timecb_table[0].wait_time = 2000; - OS_timecb_table[0].callback_ptr = UT_TimeCB; + OS_timebase_table[2].first_cb = timecb_token.obj_id; + OS_timecb_table[1].prev_cb = timecb_token.obj_id; + OS_timecb_table[1].next_cb = timecb_token.obj_id; + OS_timecb_table[1].wait_time = 2000; + OS_timecb_table[1].callback_ptr = UT_TimeCB; TimerSyncCount = 0; TimerSyncRetVal = 0; TimeCB = 0; From ba3bc0175bd4c4329a5ba4e1b41ffa6cae2a38bf Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 1 Dec 2020 16:56:43 -0500 Subject: [PATCH 08/11] Fix #664, change type of sync callback argument to osal_id_t ID is preferable to an array index because direct table access should not be done outside OSAL itself. --- src/os/inc/osapi-os-timer.h | 4 +- src/os/posix/src/os-impl-timebase.c | 65 ++++++++++--------- src/os/rtems/src/os-impl-timebase.c | 50 +++++++------- src/os/vxworks/inc/os-vxworks.h | 2 +- src/os/vxworks/src/os-impl-timebase.c | 26 ++++---- .../time-base-api-test/time-base-api-test.c | 2 +- .../shared/src/coveragetest-timebase.c | 2 +- .../adaptors/inc/ut-adaptor-timebase.h | 2 +- .../adaptors/src/ut-adaptor-timebase.c | 4 +- .../vxworks/src/coveragetest-timebase.c | 6 +- 10 files changed, 87 insertions(+), 76 deletions(-) diff --git a/src/os/inc/osapi-os-timer.h b/src/os/inc/osapi-os-timer.h index e9b7ef3c6..1dff895e1 100644 --- a/src/os/inc/osapi-os-timer.h +++ b/src/os/inc/osapi-os-timer.h @@ -33,8 +33,8 @@ /* ** Typedefs */ -typedef void (*OS_TimerCallback_t)(osal_id_t timer_id); /**< @brief Timer callback */ -typedef uint32 (*OS_TimerSync_t)(osal_index_t timer_id); /**< @brief Timer sync */ +typedef void (*OS_TimerCallback_t)(osal_id_t timer_id); /**< @brief Timer callback */ +typedef uint32 (*OS_TimerSync_t)(osal_id_t timer_id); /**< @brief Timer sync */ /** @brief Timer properties */ typedef struct diff --git a/src/os/posix/src/os-impl-timebase.c b/src/os/posix/src/os-impl-timebase.c index bbd177bc4..517411cda 100644 --- a/src/os/posix/src/os-impl-timebase.c +++ b/src/os/posix/src/os-impl-timebase.c @@ -141,42 +141,49 @@ void OS_TimeBaseUnlock_Impl(const OS_object_token_t *token) * Purpose: Local helper routine, not part of OSAL API. * *-----------------------------------------------------------------*/ -static uint32 OS_TimeBase_SigWaitImpl(osal_index_t timer_id) +static uint32 OS_TimeBase_SigWaitImpl(osal_id_t obj_id) { int ret; - OS_impl_timebase_internal_record_t *local; + OS_object_token_t token; + OS_impl_timebase_internal_record_t *impl; + OS_timebase_internal_record_t * timebase; uint32 interval_time; int sig; - local = &OS_impl_timebase_table[timer_id]; - - ret = sigwait(&local->sigset, &sig); + interval_time = 0; - if (ret != 0) - { - /* - * the sigwait call failed. - * returning 0 will cause the process to repeat. - */ - interval_time = 0; - } - else if (local->reset_flag == 0) + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMEBASE, obj_id, &token) == OS_SUCCESS) { - /* - * Normal steady-state behavior. - * interval_time reflects the configured interval time. - */ - interval_time = OS_timebase_table[timer_id].nominal_interval_time; - } - else - { - /* - * Reset/First interval behavior. - * timer_set() was invoked since the previous interval occurred (if any). - * interval_time reflects the configured start time. - */ - interval_time = OS_timebase_table[timer_id].nominal_start_time; - local->reset_flag = 0; + impl = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, token); + + ret = sigwait(&impl->sigset, &sig); + + if (ret != 0) + { + /* + * the sigwait call failed. + * returning 0 will cause the process to repeat. + */ + } + else if (impl->reset_flag == 0) + { + /* + * Normal steady-state behavior. + * interval_time reflects the configured interval time. + */ + interval_time = timebase->nominal_interval_time; + } + else + { + /* + * Reset/First interval behavior. + * timer_set() was invoked since the previous interval occurred (if any). + * interval_time reflects the configured start time. + */ + interval_time = timebase->nominal_start_time; + impl->reset_flag = 0; + } } return interval_time; diff --git a/src/os/rtems/src/os-impl-timebase.c b/src/os/rtems/src/os-impl-timebase.c index c4c72a349..1ccf7beeb 100644 --- a/src/os/rtems/src/os-impl-timebase.c +++ b/src/os/rtems/src/os-impl-timebase.c @@ -162,33 +162,39 @@ static rtems_timer_service_routine OS_TimeBase_ISR(rtems_id rtems_timer_id, void * Pends on the semaphore for the next timer tick * *-----------------------------------------------------------------*/ -static uint32 OS_TimeBase_WaitImpl(osal_index_t local_id) +static uint32 OS_TimeBase_WaitImpl(osal_id_t timebase_id) { - OS_impl_timebase_internal_record_t *local; + OS_object_token_t token; + OS_impl_timebase_internal_record_t *impl; uint32 tick_time; - local = &OS_impl_timebase_table[local_id]; - - /* - * Pend for the tick arrival - */ - rtems_semaphore_obtain(local->tick_sem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + tick_time = 0; - /* - * Determine how long this tick was. - * Note that there are plenty of ways this become wrong if the timer - * is reset right around the time a tick comes in. However, it is - * impossible to guarantee the behavior of a reset if the timer is running. - * (This is not an expected use-case anyway; the timer should be set and forget) - */ - if (local->reset_flag == 0) + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMEBASE, timebase_id, &token) == OS_SUCCESS) { - tick_time = local->configured_interval_time; - } - else - { - tick_time = local->configured_start_time; - local->reset_flag = 0; + impl = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, token); + + /* + * Pend for the tick arrival + */ + rtems_semaphore_obtain(impl->tick_sem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + + /* + * Determine how long this tick was. + * Note that there are plenty of ways this become wrong if the timer + * is reset right around the time a tick comes in. However, it is + * impossible to guarantee the behavior of a reset if the timer is running. + * (This is not an expected use-case anyway; the timer should be set and forget) + */ + if (impl->reset_flag == 0) + { + tick_time = impl->configured_interval_time; + } + else + { + tick_time = impl->configured_start_time; + impl->reset_flag = 0; + } } return tick_time; diff --git a/src/os/vxworks/inc/os-vxworks.h b/src/os/vxworks/inc/os-vxworks.h index 88bbe1826..7090b1c00 100644 --- a/src/os/vxworks/inc/os-vxworks.h +++ b/src/os/vxworks/inc/os-vxworks.h @@ -92,7 +92,7 @@ int32 OS_VxWorks_DirAPI_Impl_Init(void); int OS_VxWorks_TaskEntry(int arg); int OS_VxWorks_ConsoleTask_Entry(int arg); -uint32 OS_VxWorks_SigWait(osal_index_t local_id); +uint32 OS_VxWorks_SigWait(osal_id_t timebase_id); int OS_VxWorks_TimeBaseTask(int arg); void OS_VxWorks_RegisterTimer(osal_id_t obj_id); void OS_VxWorks_UsecToTimespec(uint32 usecs, struct timespec *time_spec); diff --git a/src/os/vxworks/src/os-impl-timebase.c b/src/os/vxworks/src/os-impl-timebase.c index 04b90513e..a7bfebba5 100644 --- a/src/os/vxworks/src/os-impl-timebase.c +++ b/src/os/vxworks/src/os-impl-timebase.c @@ -148,26 +148,24 @@ void OS_VxWorks_UsecToTimespec(uint32 usecs, struct timespec *time_spec) * Blocks the calling task until the timer tick arrives * *-----------------------------------------------------------------*/ -uint32 OS_VxWorks_SigWait(osal_index_t local_id) +uint32 OS_VxWorks_SigWait(osal_id_t timebase_id) { - OS_impl_timebase_internal_record_t *local; - OS_common_record_t * global; - osal_id_t active_id; + OS_object_token_t token; + OS_impl_timebase_internal_record_t *impl; uint32 tick_time; int signo; int ret; - local = &OS_impl_timebase_table[local_id]; - global = &OS_global_timebase_table[local_id]; - active_id = global->active_id; tick_time = 0; - if (OS_ObjectIdDefined(active_id) && local->assigned_signal > 0) + if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMEBASE, timebase_id, &token) == OS_SUCCESS) { + impl = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, token); + /* * Pend for the tick arrival */ - ret = sigwait(&local->timer_sigset, &signo); + ret = sigwait(&impl->timer_sigset, &signo); /* * The sigwait() can be interrupted.... @@ -187,17 +185,17 @@ uint32 OS_VxWorks_SigWait(osal_index_t local_id) * conditions. Samples from before/after a reconfig * are generally not comparable. */ - if (ret == OK && signo == local->assigned_signal && OS_ObjectIdEqual(global->active_id, active_id)) + if (ret == OK && signo == impl->assigned_signal) { - if (local->reset_flag) + if (impl->reset_flag) { /* first interval after reset, use start time */ - tick_time = local->configured_start_time; - local->reset_flag = false; + tick_time = impl->configured_start_time; + impl->reset_flag = false; } else { - tick_time = local->configured_interval_time; + tick_time = impl->configured_interval_time; } } } diff --git a/src/tests/time-base-api-test/time-base-api-test.c b/src/tests/time-base-api-test/time-base-api-test.c index 4a589a845..94bc69a9b 100644 --- a/src/tests/time-base-api-test/time-base-api-test.c +++ b/src/tests/time-base-api-test/time-base-api-test.c @@ -35,7 +35,7 @@ #include "uttest.h" #include "utbsp.h" -static uint32 UT_TimerSync(osal_index_t timer_id) +static uint32 UT_TimerSync(osal_id_t timer_id) { OS_TaskDelay(1); return 1; diff --git a/src/unit-test-coverage/shared/src/coveragetest-timebase.c b/src/unit-test-coverage/shared/src/coveragetest-timebase.c index aea8714e4..4edf634bf 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-timebase.c +++ b/src/unit-test-coverage/shared/src/coveragetest-timebase.c @@ -38,7 +38,7 @@ static uint32 TimerSyncCount = 0; static uint32 TimerSyncRetVal = 0; static uint32 TimeCB = 0; -static uint32 UT_TimerSync(osal_index_t timer_id) +static uint32 UT_TimerSync(osal_id_t timer_id) { ++TimerSyncCount; return TimerSyncRetVal; diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-timebase.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-timebase.h index af148e2f1..515cb534c 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-timebase.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-timebase.h @@ -43,7 +43,7 @@ void UT_TimeBaseTest_Setup(osal_index_t local_id, int signo, bool reset_flag); * Invokes OS_VxWorks_SigWait() with the given arguments. * This is normally a static function but exposed via a non-static wrapper for UT purposes. */ -int32 UT_TimeBaseTest_CallSigWaitFunc(osal_index_t local_id); +int32 UT_TimeBaseTest_CallSigWaitFunc(osal_id_t timebase_id); /* Invokes the static OS_VxWorks_TimeBaseTask() function with given argument */ int UT_TimeBaseTest_CallHelperTaskFunc(int arg); diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-timebase.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-timebase.c index f7814058a..e1eb97c8f 100644 --- a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-timebase.c +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-timebase.c @@ -40,9 +40,9 @@ int32 UT_Call_OS_VxWorks_TimeBaseAPI_Impl_Init(void) return OS_VxWorks_TimeBaseAPI_Impl_Init(); } -int32 UT_TimeBaseTest_CallSigWaitFunc(osal_index_t local_id) +int32 UT_TimeBaseTest_CallSigWaitFunc(osal_id_t timebase_id) { - return OS_VxWorks_SigWait(local_id); + return OS_VxWorks_SigWait(timebase_id); } int UT_TimeBaseTest_CallHelperTaskFunc(int arg) diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c b/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c index 82098fe2c..2690966e4 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c @@ -183,11 +183,11 @@ void Test_OS_VxWorks_SigWait(void) OS_TimeBaseSet_Impl(&token, 1111111, 2222222); UT_SetDataBuffer(UT_KEY(OCS_sigwait), &signo, sizeof(signo), false); - OSAPI_TEST_FUNCTION_RC(UT_TimeBaseTest_CallSigWaitFunc(UT_INDEX_0), 1111111); + OSAPI_TEST_FUNCTION_RC(UT_TimeBaseTest_CallSigWaitFunc(OS_OBJECT_ID_UNDEFINED), 1111111); UT_SetDataBuffer(UT_KEY(OCS_sigwait), &signo, sizeof(signo), false); - OSAPI_TEST_FUNCTION_RC(UT_TimeBaseTest_CallSigWaitFunc(UT_INDEX_0), 2222222); + OSAPI_TEST_FUNCTION_RC(UT_TimeBaseTest_CallSigWaitFunc(OS_OBJECT_ID_UNDEFINED), 2222222); UT_SetDataBuffer(UT_KEY(OCS_sigwait), &signo, sizeof(signo), false); - OSAPI_TEST_FUNCTION_RC(UT_TimeBaseTest_CallSigWaitFunc(UT_INDEX_0), 2222222); + OSAPI_TEST_FUNCTION_RC(UT_TimeBaseTest_CallSigWaitFunc(OS_OBJECT_ID_UNDEFINED), 2222222); UT_TimeBaseTest_Setup(UT_INDEX_0, 0, false); OS_global_timebase_table[0].active_id = OS_OBJECT_ID_UNDEFINED; From 4a4a98bbf856b8501f3bb81efceeaa84903d1fe5 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Tue, 8 Dec 2020 14:33:11 -0500 Subject: [PATCH 09/11] Fix #290, Remove obsolete printf tests --- src/unit-tests/osprintf-test/CMakeLists.txt | 28 -- src/unit-tests/osprintf-test/ut_osprintf.c | 326 ------------- src/unit-tests/osprintf-test/ut_osprintf.h | 111 ----- src/unit-tests/osprintf-test/ut_osprintf_c.c | 82 ---- src/unit-tests/osprintf-test/ut_osprintf_d.c | 174 ------- src/unit-tests/osprintf-test/ut_osprintf_f.c | 96 ---- src/unit-tests/osprintf-test/ut_osprintf_i.c | 174 ------- src/unit-tests/osprintf-test/ut_osprintf_ld.c | 181 ------- src/unit-tests/osprintf-test/ut_osprintf_lf.c | 98 ---- src/unit-tests/osprintf-test/ut_osprintf_li.c | 181 ------- src/unit-tests/osprintf-test/ut_osprintf_lu.c | 91 ---- src/unit-tests/osprintf-test/ut_osprintf_lx.c | 90 ---- .../osprintf-test/ut_osprintf_lx_uc.c | 90 ---- .../osprintf-test/ut_osprintf_misc.c | 179 ------- .../osprintf-test/ut_osprintf_offset.c | 454 ------------------ .../osprintf-test/ut_osprintf_offset.h | 76 --- .../osprintf-test/ut_osprintf_offset_dummy.c | 87 ---- src/unit-tests/osprintf-test/ut_osprintf_p.c | 84 ---- .../osprintf-test/ut_osprintf_printf.c | 49 -- src/unit-tests/osprintf-test/ut_osprintf_s.c | 84 ---- src/unit-tests/osprintf-test/ut_osprintf_u.c | 85 ---- src/unit-tests/osprintf-test/ut_osprintf_x.c | 90 ---- .../osprintf-test/ut_osprintf_x_uc.c | 90 ---- 23 files changed, 3000 deletions(-) delete mode 100644 src/unit-tests/osprintf-test/CMakeLists.txt delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf.c delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf.h delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf_c.c delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf_d.c delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf_f.c delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf_i.c delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf_ld.c delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf_lf.c delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf_li.c delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf_lu.c delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf_lx.c delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf_lx_uc.c delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf_misc.c delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf_offset.c delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf_offset.h delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf_offset_dummy.c delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf_p.c delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf_printf.c delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf_s.c delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf_u.c delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf_x.c delete mode 100644 src/unit-tests/osprintf-test/ut_osprintf_x_uc.c diff --git a/src/unit-tests/osprintf-test/CMakeLists.txt b/src/unit-tests/osprintf-test/CMakeLists.txt deleted file mode 100644 index 86abb7f0f..000000000 --- a/src/unit-tests/osprintf-test/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -# CMake snippet for OSAL printf test - -set(TEST_MODULE_FILES - ut_osprintf.c - ut_osprintf_c.c - ut_osprintf_d.c - ut_osprintf_f.c - ut_osprintf_i.c - ut_osprintf_ld.c - ut_osprintf_lf.c - ut_osprintf_li.c - ut_osprintf_lu.c - ut_osprintf_lx.c - ut_osprintf_lx_uc.c - ut_osprintf_misc.c - ut_osprintf_offset.c - ut_osprintf_offset_dummy.c - ut_osprintf_p.c - ut_osprintf_printf.c - ut_osprintf_s.c - ut_osprintf_u.c - ut_osprintf_x.c - ut_osprintf_x_uc.c -) - -add_stubs(TEST_STUBS os) -add_osal_ut_exe(osal_osprintf_UT ${TEST_MODULE_FILES} ${TEST_STUBS}) - diff --git a/src/unit-tests/osprintf-test/ut_osprintf.c b/src/unit-tests/osprintf-test/ut_osprintf.c deleted file mode 100644 index f6da52c2b..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf.c +++ /dev/null @@ -1,326 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * ut_osprintf.c - * - * Created on: May 20, 2013 - * Author: Kevin McCluney - */ - -/* -** Includes -*/ -#include "ut_osprintf.h" -#ifdef UT_DO_OFFSET -#include "ut_osprintf_offset.h" -#endif - -#ifndef OSP_ARINC653 -#include - -FILE *UT_logfile; -#endif - -/* -** Global variables -*/ -unsigned OS_printf_enabled = 1; -int ut_passed; -int ut_failed; -char cMsg[UT_MAX_MESSAGE_LENGTH]; -char cNum[UT_MAX_MESSAGE_LENGTH]; -char strg_buf[BUF_LEN]; -char trunc_buf[BUF_LEN]; -char fill_strg[BUF_LEN]; - -/* -** Functions -*/ -#ifdef OSP_ARINC653 -int os_printf_main() -#else -int main() -#endif -{ - int i; - -#ifndef OSP_ARINC653 - UT_logfile = fopen("ut_osal_osprintf_log.txt", "w"); -#endif - -#ifdef OS_USE_EMBEDDED_PRINTF - UT_Text("Using replacement printf functions\n\n"); -#else - UT_Text("Using standard printf functions\n\n"); -#endif - - for (i = 0; i < BUF_LEN; i++) - { - fill_strg[i] = '*'; - } - - ut_passed = 0; - ut_failed = 0; - - /* Test sprintf and snprintf for each format */ - UT_osprintf_d(); - UT_osprintf_i(); - UT_osprintf_u(); - UT_osprintf_x(); - UT_osprintf_X(); - UT_osprintf_p(); - UT_osprintf_c(); - UT_osprintf_s(); - UT_osprintf_ld(); - UT_osprintf_li(); - UT_osprintf_lu(); - UT_osprintf_lx(); - UT_osprintf_lX(); - -#ifndef UT_NO_FLOAT - UT_osprintf_f(); - UT_osprintf_lf(); - UT_osprintf_misc(); -#endif - -#ifdef OS_USE_EMBEDDED_PRINTF - UT_osprintf_printf(); -#endif - - UT_ReportFailures(); - -#ifdef UT_DO_OFFSET - /* Calculate argument offsets for cFE variadic functions */ - UT_osprintf_CalcOffsets(); -#endif - -#ifndef OSP_ARINC653 - /* Ensure everything gets written */ - fflush(stdout); - fclose(UT_logfile); -#endif - - return 0; -} - -/* -** Initialize string buffer to all asterisks -*/ -void init_test(void) -{ - memcpy(strg_buf, fill_strg, BUF_LEN); -} - -/* -** Compare expected string output to actual string output; return -** pass/fail result -*/ -int check_test(char *expected, char *actual) -{ - int result = UT_PASS; - - if (memcmp(expected, actual, strlen(expected) + 1)) - { - strcpy(cMsg, " Mismatch: exp = ["); - strcat(cMsg, expected); - strcat(cMsg, "], act = ["); - strcat(cMsg, actual); - strcat(cMsg, "]\n"); - UT_Text(cMsg); - result = UT_FAIL; - } - - return result; -} - -/* -** Output text -*/ -void UT_Text(char *out_text) -{ -#ifdef OSP_ARINC653 - TUTF_print(out_text); - TUTF_print("\n"); -#else - fprintf(UT_logfile, "%s", out_text); - fflush(UT_logfile); -#endif -} - -/* -** Output result of a test -*/ -void UT_Report(int test, char *fun_name, char *info, char *test_num, char *test_seq) -{ - if (test == UT_PASS) - { -#ifdef UT_SHOW_PASS - strcpy(cMsg, "PASSED ["); - strcat(cMsg, fun_name); - strcat(cMsg, "."); - strcat(cMsg, test_num); - strcat(cMsg, "."); - strcat(cMsg, test_seq); - strcat(cMsg, "] "); - strcat(cMsg, info); - strcat(cMsg, "\n-----\n"); - UT_Text(cMsg); -#endif - ut_passed++; - } - else - { - strcpy(cMsg, "FAILED ["); - strcat(cMsg, fun_name); - strcat(cMsg, "."); - strcat(cMsg, test_num); - strcat(cMsg, "."); - strcat(cMsg, test_seq); - strcat(cMsg, "] "); - strcat(cMsg, info); - strcat(cMsg, "\n-----\n"); - UT_Text(cMsg); - ut_failed++; - } -} - -/* -** Convert an integer to its character representation -*/ -void UT_itoa(int value, char *string, int radix, int out_len) -{ - char revertedStr[50]; - int revertedLength = 0; - unsigned int length = 0; - unsigned int neg = 0; - unsigned int digit_value = 0; - unsigned int uvalue; - - if ((radix == 10) && (value < 0)) - { - neg = 1; - uvalue = -value; - } - else - { - uvalue = (unsigned int)value; - } - - revertedLength = 0; - - while (uvalue >= radix) - { - digit_value = uvalue % radix; - - if (digit_value >= 10) - { - revertedStr[revertedLength] = digit_value - 10 + 'a'; - } - else - { - revertedStr[revertedLength] = digit_value + '0'; - } - - uvalue /= radix; - revertedLength++; - } - - if (uvalue >= 10) - { - revertedStr[revertedLength] = uvalue - 10 + 'a'; - } - else - { - revertedStr[revertedLength] = uvalue + '0'; - } - - if (neg == 1) - { - string[length] = '-'; - length++; - } - - if (revertedLength < out_len - 1) - { - while (revertedLength < out_len - 1) - { - revertedLength++; - revertedStr[revertedLength] = '0'; - } - } - - while (revertedLength >= 0) - { - string[length] = revertedStr[revertedLength]; - revertedLength--; - length++; - } - - string[length] = '\0'; -} - -/* -** Output summary of test results (# of passed & failed tests) -*/ -void UT_ReportFailures(void) -{ - char cNum[10]; - - strcpy(cMsg, "\nosprintf PASSED "); - UT_itoa(ut_passed, cNum, 10, 0); - strcat(cMsg, cNum); - strcat(cMsg, " tests.\n"); - strcat(cMsg, "osprintf FAILED "); - UT_itoa(ut_failed, cNum, 10, 0); - strcat(cMsg, cNum); - strcat(cMsg, " tests.\n"); - UT_Text(cMsg); - -#ifndef OSP_ARINC653 - printf("\nosprintf PASSED %d tests.\nosprintf FAILED %d tests.\n\n", ut_passed, ut_failed); -#endif -} - -#ifdef OSP_ARINC653 -/* -** Stub function for OS_MutSemCreate() -*/ -int32 OS_MutSemCreate(uint32 *mutex_id, const char *mutex_name, uint32 options) -{ - return 0; -} - -/* -** Stub function for OS_MutSemGive() -*/ -int32 OS_MutSemGive(uint32 mutex_id) -{ - return 0; -} - -/* -** Stub function for OS_MutSemTake() -*/ -int32 OS_MutSemTake(uint32 mutex_id) -{ - return 0; -} -#endif diff --git a/src/unit-tests/osprintf-test/ut_osprintf.h b/src/unit-tests/osprintf-test/ut_osprintf.h deleted file mode 100644 index 1a691fd79..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * ut_osprintf.h - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#ifndef UT_OSPRINTF_H_ -#define UT_OSPRINTF_H_ - -/* -** Includes -*/ -#include -#include - -/* printf Replacement Unit Test Compiler Flags - - Define UT_SHOW_PASS in order to display passing tests; if undefined then - only the failed tests are displayed. In either case the total number of - tests passes and failed are displayed - - Define UT_NO_FLOAT to skip the tests for floating point printf's; - undefine to include these tests - - Define UT_DO_OFFSET when compiling on the GHS target to perform tests to - determine variable parameter offset values for the cFE variadic functions - - Define OSP_GHS to compile on the GHS platform - osprintf Compiler Flags - - Define OS_USE_EMBEDDED_PRINTF to test the replacement printf functions; - undefine it to test the standard printf functions - - Define OSP_ARINC653 if using embedded (replacement) printf functions - and compiling on the GHS target using cFE modified for ARINC653 -*/ - -#ifdef OS_USE_EMBEDDED_PRINTF -#include "osprintf.h" -#ifndef OSP_GHS -int putchar(int); -#endif -#else -#include -#endif - -#ifdef OSP_ARINC653 -#include "common_types.h" -#endif - -/* -** Macro Definitions -*/ -#define BUF_LEN 200 -#define UT_MAX_MESSAGE_LENGTH 300 -#define UT_TRUE 1 -#define UT_FALSE 0 -#define UT_PASS 0 -#define UT_FAIL 1 - -/* -** Function prototypes -*/ -void init_test(void); -int check_test(char *expected, char *actual); - -void UT_osprintf_d(void); -void UT_osprintf_i(void); -void UT_osprintf_u(void); -void UT_osprintf_x(void); -void UT_osprintf_X(void); -void UT_osprintf_p(void); -void UT_osprintf_c(void); -void UT_osprintf_s(void); -void UT_osprintf_ld(void); -void UT_osprintf_li(void); -void UT_osprintf_lu(void); -void UT_osprintf_lx(void); -void UT_osprintf_lX(void); - -#ifndef UT_NO_FLOAT -void UT_osprintf_f(void); -void UT_osprintf_lf(void); -void UT_osprintf_misc(void); -#endif - -#ifdef OS_USE_EMBEDDED_PRINTF -void UT_osprintf_printf(void); -#endif - -void UT_Text(char *out_text); -void UT_Report(int test, char *fun_name, char *info, char *test_num, char *test_seq); -void UT_itoa(int value, char *string, int radix, int out_len); -void UT_ReportFailures(void); - -#endif /* UT_OSPRINTF_H_ */ diff --git a/src/unit-tests/osprintf-test/ut_osprintf_c.c b/src/unit-tests/osprintf-test/ut_osprintf_c.c deleted file mode 100644 index 28990c2e4..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_c.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_c.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %c format - *****************************************************************************/ -void UT_osprintf_c(void) -{ - char *test_fmt = "c"; /* Test format character(s) */ - int i; - - struct - { - char *test_num; /* Test identifier; sequential numbers */ - char test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char *format; /* Format string */ - char *expected; /* Expected result */ - char *description; /* Test description */ - } osp_tests[] = { - {"01", 'k', 1, "%c", "k", "%c"}, - {"02", 'w', 5, "$$$%c$$$", "$$$w$$$", "%c embedded"}, - {"03", '?', 19, "%20c", " ?", "%c with minimum field size"}, - {"04", 'Q', 2, "%.10c", "Q", "%c with maximum field size"}, - {"05", '>', 5, "%7.9c", " >", "%c with minimum and maximum field size"}, - {"06", '#', 17, "%-20c", "# ", "%c with left-justify"}, - {"07", 'H', 2, "%+c", "H", "%c with sign"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_d.c b/src/unit-tests/osprintf-test/ut_osprintf_d.c deleted file mode 100644 index ef33168d6..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_d.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_d.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %d format - *****************************************************************************/ -void UT_osprintf_d(void) -{ - char *test_fmt = "d"; /* Test format character(s) */ - int i; - - struct - { - char *test_num; /* Test identifier; sequential numbers */ - int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char *format; /* Format string */ - char *expected; /* Expected result */ - char *description; /* Test description */ - } osp_tests[] = { - {"01", 98765, 5, "%d", "98765", "%d only"}, - {"02", 46372, 8, "$$$%d$$$", "$$$46372$$$", "%d embedded, positive value"}, - {"03", 98765, 5, "% d", " 98765", "%d with space for sign, positive value"}, - {"04", 91827, 6, "%8d", " 91827", "%d with minimum field size > number of digits, positive value"}, - {"05", 91827, 4, "%4d", "91827", "%d with minimum field size < number of digits, positive value"}, - {"06", 33225, 8, "%.10d", "0000033225", "%d with precision field size > number of digits, positive value"}, - {"07", 33225, 5, "%.3d", "33225", "%d with precision field size < number of digits, positive value"}, - {"08", 12345, 8, "%9.7d", " 0012345", - "%d with minimum field size > precision field size > number of digits, positive value"}, - {"09", 12345, 6, "%9.3d", " 12345", - "%d with minimum field size > number of digits > precision field size, positive value"}, - {"10", 12345, 3, "%4.2d", "12345", - "%d with number of digits > minimum field size > precision field size, positive value"}, - {"11", 12345, 7, "%7.9d", "000012345", - "%d with precision field size > minimum field size > number of digits, positive value"}, - {"12", 12345, 8, "%3.9d", "000012345", - "%d with precision field size > number of digits > minimum field size, positive value"}, - {"13", 12345, 4, "%2.4d", "12345", - "%d with number of digits > precision field size > minimum field size, positive value"}, - {"14", 98765, 17, "%-.20d", "00000000000000098765", - "%d with left-justify and precision field size > number of digits, positive value"}, - {"15", 98765, 5, "%-.3d", "98765", - "%d with left-justify and precision field size < number of digits, positive value"}, - {"16", 98765, 4, "%+d", "+98765", "%d with sign, positive value"}, - {"17", 46372, 9, "$$$%+d$$$", "$$$+46372$$$", "%d sign and embedded, positive value"}, - {"18", 91827, 8, "%+8d", " +91827", "%d with sign and minimum field size > number of digits, positive value"}, - {"19", 91827, 5, "%+4d", "+91827", "%d with sign and minimum field size < number of digits, positive value"}, - {"20", 33225, 10, "%+.10d", "+0000033225", - "%d with sign and precision field size > number of digits, positive value"}, - {"21", 33225, 4, "%+.3d", "+33225", "%d with sign and precision field size < number of digits, positive value"}, - {"22", 12345, 6, "%+9.7d", " +0012345", - "%d with sign and minimum field size > precision field size > number of digits, positive value"}, - {"23", 12345, 7, "%+9.3d", " +12345", - "%d with sign and minimum field size > number of digits > precision field size, positive value"}, - {"24", 12345, 2, "%+4.2d", "+12345", - "%d with sign and number of digits > minimum field size > precision field size, positive value"}, - {"25", 12345, 6, "%+7.9d", "+000012345", - "%d with sign and precision field size > minimum field size > number of digits, positive value"}, - {"26", 12345, 8, "%+3.9d", "+000012345", - "%d with sign and precision field size > number of digits > minimum field size, positive value"}, - {"27", 12345, 5, "%+2.4d", "+12345", - "%d with sign and number of digits > precision field size > minimum field size, positive value"}, - {"28", 98765, 16, "%+-.20d", "+00000000000000098765", - "%d with sign and left-justify and precision field size > number of digits, positive value"}, - {"29", 98765, 5, "%+-.3d", "+98765", - "%d with sign and left-justify and precision field size < number of digits, positive value"}, - {"30", 98765, 3, "%+d", "+98765", "%d with sign, positive value"}, - {"31", -98765, 2, "%d", "-98765", "%d, negative value"}, - {"32", -46372, 8, "$$$%d$$$", "$$$-46372$$$", "%d embedded, negative value"}, - {"33", -98765, 5, "% d", "-98765", "%d with space for sign, negative value"}, - {"34", -91827, 9, "%10d", " -91827", "%d with minimum field size > number of digits, negative value"}, - {"35", -91827, 5, "%4d", "-91827", "%d with minimum field size < number of digits, negative value"}, - {"36", -33225, 7, "%.10d", "-0000033225", "%d with precision field size > number of digits, negative value"}, - {"37", -33225, 4, "%.3d", "-33225", "%d with precision field size < number of digits, negative value"}, - {"38", -12345, 8, "%9.7d", " -0012345", - "%d with minimum field size > precision field size > number of digits, negative value"}, - {"39", -12345, 9, "%9.3d", " -12345", - "%d with minimum field size > number of digits > precision field size, negative value"}, - {"40", -12345, 5, "%4.2d", "-12345", - "%d with number of digits > minimum field size > precision field size, negative value"}, - {"41", -12345, 7, "%7.9d", "-000012345", - "%d with precision field size > minimum field size > number of digits, negative value"}, - {"42", -12345, 8, "%3.9d", "-000012345", - "%d with precision field size > number of digits > minimum field size, negative value"}, - {"43", -12345, 5, "%2.4d", "-12345", - "%d with number of digits > precision field size > minimum field size, negative value"}, - {"44", -98765, 20, "%-.20d", "-00000000000000098765", - "%d with left-justify and precision field size > number of digits, negative value"}, - {"45", -98765, 5, "%-.3d", "-98765", - "%d with left-justify and precision field size < number of digits, negative value"}, - {"46", -98765, 6, "%+d", "-98765", "%d with sign, negative value"}, - {"47", -46372, 8, "$$$%+d$$$", "$$$-46372$$$", "%d sign and embedded, negative value"}, - {"48", -91827, 7, "%+8d", " -91827", "%d with sign and minimum field size > number of digits, negative value"}, - {"49", -91827, 5, "%+4d", "-91827", "%d with sign and minimum field size < number of digits, negative value"}, - {"50", -33225, 9, "%+.10d", "-0000033225", - "%d with sign and precision field size > number of digits, negative value"}, - {"51", -33225, 5, "%+.3d", "-33225", - "%d with sign and precision field size < number of digits, negative value"}, - {"52", -12345, 6, "%+9.7d", " -0012345", - "%d with sign and minimum field size > precision field size > number of digits, negative value"}, - {"53", -12345, 7, "%+9.3d", " -12345", - "%d with sign and minimum field size > number of digits > precision field size, negative value"}, - {"54", -12345, 5, "%+4.2d", "-12345", - "%d with sign and number of digits > minimum field size > precision field size, negative value"}, - {"55", -12345, 8, "%+7.9d", "-000012345", - "%d with sign and precision field size > minimum field size > number of digits, negative value"}, - {"56", -12345, 7, "%+3.9d", "-000012345", - "%d with sign and precision field size > number of digits > minimum field size, negative value"}, - {"57", -12345, 6, "%+2.4d", "-12345", - "%d with sign and number of digits > precision field size > minimum field size, negative value"}, - {"58", -98765, 13, "%+-.20d", "-00000000000000098765", - "%d with sign and left-justify and precision field size > number of digits, negative value"}, - {"59", -98765, 4, "%+-.3d", "-98765", - "%d with sign and left-justify and precision field size < number of digits, negative value"}, - {"60", -98765, 5, "%+d", "-98765", "%d with sign, negative value"}, - {"61", 0, 6, "%d", "0", "%d, zero value"}, - {"62", 162534, 5, "%08d", "00162534", "%d with zero padding, positive value"}, - {"63", -162534, 6, "%08d", "-0162534", "%d with zero padding, negative value"}, - {"64", 0, 6, "%04d", "0000", "%d, with zero padding, zero value"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_f.c b/src/unit-tests/osprintf-test/ut_osprintf_f.c deleted file mode 100644 index 08ca59d6f..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_f.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_f.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %f format - *****************************************************************************/ -void UT_osprintf_f(void) -{ - char *test_fmt = "f"; /* Test format character(s) */ - int i; - - struct - { - char *test_num; /* Test identifier; sequential numbers */ - float test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char *format; /* Format string */ - char *expected; /* Expected result */ - char *description; /* Test description */ - } osp_tests[] = { - {"01", 5.230, 6, "%f", "5.230000", "%f, positive value"}, - {"02", 2.1056, 9, "$$$%f$$$", "$$$2.105600$$$", "%f embedded, positive value"}, - {"03", 91827.3, 4, "%3f", "91827.296875", "%f with maximum field size, positive value"}, - {"04", 5.82345, 5, "%.3f", "5.823", "%f with minimum field size, positive value"}, - {"05", 12.6789, 8, "%9.5f", " 12.67890", "%f with minimum and maximum field size, positive value"}, - {"06", 65.5678, 13, "%-20.5f", "65.56780 ", "%f with left-justify, positive value"}, - {"07", 2.7944, 8, "%+f", "+2.794400", "%f with sign, positive value"}, - {"08", -0.6712237, 7, "%f", "-0.671224", "%f, negative value"}, - {"09", -7.1109, 8, "$$$%f$$$", "$$$-7.110900$$$", "%f embedded, negative value"}, - {"10", -918.987, 6, "%3f", "-918.987000", "%f with maximum field size, negative value"}, - {"11", -3.1415, 3, "%.2f", "-3.14", "%f with precision, negative value"}, - {"12", -1.23456, 6, "%9.7f", "-1.2345600", "%f with precision and maximum field size, negative value"}, - {"13", -65.65, 5, "%-8.3f", "-65.650 ", "%f with left-justify, negative value"}, - {"14", 0.0, 4, "%f", "0.000000", "%f, zero value"}, - {"15", 4.0, 6, "%7.0f", " 4", "%f, no fraction, positive value"}, - {"16", -56.0, 6, "%6.0f", " -56", "%f, no fraction, negative value"}, - {"17", 4887.12, 5, "%010.3f", "004887.120", "%f with zero padding, positive value"}, - {"18", -4887.12, 5, "%010.3f", "-04887.120", "%f with zero padding, negative value"}, - {"19", 0.0, 6, "%06.2f", "000.00", "%f, with zero padding, zero value"}, - {"20", 4.0, 6, "%07.0f", "0000004", "%f, zero padding, no fraction, positive value"}, - {"21", -56.0, 6, "%06.0f", "-00056", "%f, zero padding, no fraction, negative value"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_i.c b/src/unit-tests/osprintf-test/ut_osprintf_i.c deleted file mode 100644 index 83ed728ca..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_i.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_i.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %i format - *****************************************************************************/ -void UT_osprintf_i(void) -{ - char *test_fmt = "i"; /* Test format character(s) */ - int i; - - struct - { - char *test_num; /* Test identifier; sequential numbers */ - int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char *format; /* Format string */ - char *expected; /* Expected result */ - char *description; /* Test description */ - } osp_tests[] = { - {"01", 98765, 5, "%i", "98765", "%i, positive value"}, - {"02", 46372, 9, "$$$%i$$$", "$$$46372$$$", "%i embedded, positive value"}, - {"03", 98765, 5, "% i", " 98765", "%i with space for sign, positive value"}, - {"04", 91827, 7, "%8i", " 91827", "%i with minimum field size > number of digits, positive value"}, - {"05", 91827, 2, "%4i", "91827", "%i with minimum field size < number of digits, positive value"}, - {"06", 33225, 7, "%.10i", "0000033225", "%i with precision field size > number of digits, positive value"}, - {"07", 33225, 3, "%.3i", "33225", "%i with precision field size < number of digits, positive value"}, - {"08", 12345, 5, "%9.7i", " 0012345", - "%i with minimum field size > precision field size > number of digits, positive value"}, - {"09", 12345, 5, "%9.3i", " 12345", - "%i with minimum field size > number of digits > precision field size, positive value"}, - {"10", 12345, 5, "%4.2i", "12345", - "%i with number of digits > minimum field size > precision field size, positive value"}, - {"11", 12345, 8, "%7.9i", "000012345", - "%i with precision field size > minimum field size > number of digits, positive value"}, - {"12", 12345, 7, "%3.9i", "000012345", - "%i with precision field size > number of digits > minimum field size, positive value"}, - {"13", 12345, 4, "%2.4i", "12345", - "%i with number of digits > precision field size > minimum field size, positive value"}, - {"14", 98765, 5, "%-.20i", "00000000000000098765", - "%i with left-justify and precision field size > number of digits, positive value"}, - {"15", 98765, 5, "%-.3i", "98765", - "%i with left-justify and precision field size < number of digits, positive value"}, - {"16", 98765, 5, "%+i", "+98765", "%i with sign, positive value"}, - {"17", 46372, 5, "$$$%+d$$$", "$$$+46372$$$", "%i sign and embedded, positive value"}, - {"18", 91827, 6, "%+8i", " +91827", "%i with sign and minimum field size > number of digits, positive value"}, - {"19", 91827, 4, "%+4i", "+91827", "%i with sign and minimum field size < number of digits, positive value"}, - {"20", 33225, 8, "%+.10i", "+0000033225", - "%i with sign and precision field size > number of digits, positive value"}, - {"21", 33225, 5, "%+.3i", "+33225", "%i with sign and precision field size < number of digits, positive value"}, - {"22", 12345, 5, "%+9.7i", " +0012345", - "%i with sign and minimum field size > precision field size > number of digits, positive value"}, - {"23", 12345, 5, "%+9.3i", " +12345", - "%i with sign and minimum field size > number of digits > precision field size, positive value"}, - {"24", 12345, 5, "%+4.2i", "+12345", - "%i with sign and number of digits > minimum field size > precision field size, positive value"}, - {"25", 12345, 8, "%+7.9i", "+000012345", - "%i with sign and precision field size > minimum field size > number of digits, positive value"}, - {"26", 12345, 7, "%+3.9i", "+000012345", - "%i with sign and precision field size > number of digits > minimum field size, positive value"}, - {"27", 12345, 5, "%+2.4i", "+12345", - "%i with sign and number of digits > precision field size > minimum field size, positive value"}, - {"28", 98765, 16, "%+-.20i", "+00000000000000098765", - "%i with sign and left-justify and precision field size > number of digits, positive value"}, - {"29", 98765, 5, "%+-.3i", "+98765", - "%i with sign and left-justify and precision field size < number of digits, positive value"}, - {"30", 98765, 4, "%+i", "+98765", "%i with sign, positive value"}, - {"31", -98765, 6, "%i", "-98765", "%i, negative value"}, - {"32", -46372, 6, "$$$%i$$$", "$$$-46372$$$", "%i embedded, negative value"}, - {"33", -98765, 5, "% i", "-98765", "%i with space for sign, negative value"}, - {"34", -91827, 9, "%10i", " -91827", "%i with minimum field size > number of digits, negative value"}, - {"35", -91827, 6, "%4i", "-91827", "%i with minimum field size < number of digits, negative value"}, - {"36", -33225, 9, "%.10i", "-0000033225", "%i with precision field size > number of digits, negative value"}, - {"37", -33225, 5, "%.3i", "-33225", "%i with precision field size < number of digits, negative value"}, - {"38", -12345, 8, "%9.7i", " -0012345", - "%i with minimum field size > precision field size > number of digits, negative value"}, - {"39", -12345, 7, "%9.3i", " -12345", - "%i with minimum field size > number of digits > precision field size, negative value"}, - {"40", -12345, 6, "%4.2i", "-12345", - "%i with number of digits > minimum field size > precision field size, negative value"}, - {"41", -12345, 7, "%7.9i", "-000012345", - "%i with precision field size > minimum field size > number of digits, negative value"}, - {"42", -12345, 8, "%3.9i", "-000012345", - "%i with precision field size > number of digits > minimum field size, negative value"}, - {"43", -12345, 5, "%2.4i", "-12345", - "%i with number of digits > precision field size > minimum field size, negative value"}, - {"44", -98765, 18, "%-.20i", "-00000000000000098765", - "%i with left-justify and precision field size > number of digits, negative value"}, - {"45", -98765, 5, "%-.3i", "-98765", - "%i with left-justify and precision field size < number of digits, negative value"}, - {"46", -98765, 6, "%+i", "-98765", "%i with sign, negative value"}, - {"47", -46372, 7, "$$$%+d$$$", "$$$-46372$$$", "%i sign and embedded, negative value"}, - {"48", -91827, 5, "%+8i", " -91827", "%i with sign and minimum field size > number of digits, negative value"}, - {"49", -91827, 5, "%+4i", "-91827", "%i with sign and minimum field size < number of digits, negative value"}, - {"50", -33225, 7, "%+.10i", "-0000033225", - "%i with sign and precision field size > number of digits, negative value"}, - {"51", -33225, 5, "%+.3i", "-33225", - "%i with sign and precision field size < number of digits, negative value"}, - {"52", -12345, 7, "%+9.7i", " -0012345", - "%i with sign and minimum field size > precision field size > number of digits, negative value"}, - {"53", -12345, 8, "%+9.3i", " -12345", - "%i with sign and minimum field size > number of digits > precision field size, negative value"}, - {"54", -12345, 4, "%+4.2i", "-12345", - "%i with sign and number of digits > minimum field size > precision field size, negative value"}, - {"55", -12345, 8, "%+7.9i", "-000012345", - "%i with sign and precision field size > minimum field size > number of digits, negative value"}, - {"56", -12345, 7, "%+3.9i", "-000012345", - "%i with sign and precision field size > number of digits > minimum field size, negative value"}, - {"57", -12345, 5, "%+2.4i", "-12345", - "%i with sign and number of digits > precision field size > minimum field size, negative value"}, - {"58", -98765, 19, "%+-.20i", "-00000000000000098765", - "%i with sign and left-justify and precision field size > number of digits, negative value"}, - {"59", -98765, 6, "%+-.3i", "-98765", - "%i with sign and left-justify and precision field size < number of digits, negative value"}, - {"60", -98765, 5, "%+i", "-98765", "%i with sign, negative value"}, - {"61", 0, 6, "%i", "0", "%i, zero value"}, - {"62", 162534, 5, "%08i", "00162534", "%i with zero padding, positive value"}, - {"63", -162534, 6, "%08i", "-0162534", "%i with zero padding, negative value"}, - {"64", 0, 6, "%04i", "0000", "%i, with zero padding, zero value"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_ld.c b/src/unit-tests/osprintf-test/ut_osprintf_ld.c deleted file mode 100644 index 9236fa157..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_ld.c +++ /dev/null @@ -1,181 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_ld.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %ld format - *****************************************************************************/ -void UT_osprintf_ld(void) -{ - char *test_fmt = "ld"; /* Test format character(s) */ - int i; - - struct - { - char * test_num; /* Test identifier; sequential numbers */ - long int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char * format; /* Format string */ - char * expected; /* Expected result */ - char * description; /* Test description */ - } osp_tests[] = { - {"01", 12798765, 5, "%ld", "12798765", "%ld, positive value"}, - {"02", 43246372, 9, "$$$%ld$$$", "$$$43246372$$$", "%ld embedded, positive value"}, - {"03", 63198765, 9, "% ld", " 63198765", "%ld with space for sign, positive value"}, - {"04", 77691827, 8, "%11ld", " 77691827", "%ld with minimum field size > number of digits, positive value"}, - {"05", 54691827, 5, "%4ld", "54691827", "%ld with minimum field size < number of digits, positive value"}, - {"06", 77833225, 7, "%.10ld", "0077833225", "%ld with precision field size > number of digits, positive value"}, - {"07", 99933225, 6, "%.3ld", "99933225", "%ld with precision field size < number of digits, positive value"}, - {"08", 12345789, 8, "%12.10ld", " 0012345789", - "%ld with minimum field size > precision field size > number of digits, positive value"}, - {"09", 12345987, 7, "%12.3ld", " 12345987", - "%ld with minimum field size > number of digits > precision field size, positive value"}, - {"10", 12345444, 8, "%4.2ld", "12345444", - "%ld with number of digits > minimum field size > precision field size, positive value"}, - {"11", 12345321, 10, "%10.12ld", "000012345321", - "%ld with precision field size > minimum field size > number of digits, positive value"}, - {"12", 12333345, 9, "%6.12ld", "000012333345", - "%ld with precision field size > number of digits > minimum field size, positive value"}, - {"13", 12345777, 8, "%2.4ld", "12345777", - "%ld with number of digits > precision field size > minimum field size, positive value"}, - {"14", 98765321, 15, "%-.20ld", "00000000000098765321", - "%ld with left-justify and precision field size > number of digits, positive value"}, - {"15", 98765111, 8, "%-.3ld", "98765111", - "%ld with left-justify and precision field size < number of digits, positive value"}, - {"16", 98765222, 8, "%+ld", "+98765222", "%ld with sign, positive value"}, - {"17", 46372333, 7, "$$$%+ld$$$", "$$$+46372333$$$", "%ld sign and embedded, positive value"}, - {"18", 91827444, 6, "%+11ld", " +91827444", - "%ld with sign and minimum field size > number of digits, positive value"}, - {"19", 91827555, 5, "%+4ld", "+91827555", - "%ld with sign and minimum field size < number of digits, positive value"}, - {"20", 33225666, 7, "%+.13ld", "+0000033225666", - "%ld with sign and precision field size > number of digits, positive value"}, - {"21", 33225777, 8, "%+.3ld", "+33225777", - "%ld with sign and precision field size < number of digits, positive value"}, - {"22", 12345888, 9, "%+12.10ld", " +0012345888", - "%ld with sign and minimum field size > precision field size > number of digits, positive value"}, - {"23", 12345999, 10, "%+12.3ld", " +12345999", - "%ld with sign and minimum field size > number of digits > precision field size, positive value"}, - {"24", 12345000, 8, "%+4.2ld", "+12345000", - "%ld with sign and number of digits > minimum field size > precision field size, positive value"}, - {"25", 12345121, 9, "%+10.12ld", "+000012345121", - "%ld with sign and precision field size > minimum field size > number of digits, positive value"}, - {"26", 12345232, 8, "%+6.12ld", "+000012345232", - "%ld with sign and precision field size > number of digits > minimum field size, positive value"}, - {"27", 12345343, 6, "%+2.4ld", "+12345343", - "%ld with sign and number of digits > precision field size > minimum field size, positive value"}, - {"28", 98765454, 19, "%+-.20ld", "+00000000000098765454", - "%ld with sign and left-justify and precision field size > number of digits, positive value"}, - {"29", 98765565, 7, "%+-.3ld", "+98765565", - "%ld with sign and left-justify and precision field size < number of digits, positive value"}, - {"30", 98765676, 8, "%+ld", "+98765676", "%ld with sign, positive value"}, - {"31", -98765787, 9, "%ld", "-98765787", "%ld, negative value"}, - {"32", -46372898, 10, "$$$%ld$$$", "$$$-46372898$$$", "%ld embedded, negative value"}, - {"33", -98765909, 9, "% ld", "-98765909", "%ld with space for sign, negative value"}, - {"34", -91827121, 8, "%13ld", " -91827121", - "%ld with minimum field size > number of digits, negative value"}, - {"35", -91827232, 5, "%4ld", "-91827232", "%ld with minimum field size < number of digits, negative value"}, - {"36", -33225343, 8, "%.13ld", "-0000033225343", - "%ld with precision field size > number of digits, negative value"}, - {"37", -33225454, 6, "%.3ld", "-33225454", "%ld with precision field size < number of digits, negative value"}, - {"38", -12345565, 7, "%12.10ld", " -0012345565", - "%ld with minimum field size > precision field size > number of digits, negative value"}, - {"39", -12345676, 8, "%12.4ld", " -12345676", - "%ld with minimum field size > number of digits > precision field size, negative value"}, - {"40", -12345787, 9, "%4.2ld", "-12345787", - "%ld with number of digits > minimum field size > precision field size, negative value"}, - {"41", -12345898, 11, "%7.12ld", "-000012345898", - "%ld with precision field size > minimum field size > number of digits, negative value"}, - {"42", -12345909, 10, "%3.12ld", "-000012345909", - "%ld with precision field size > number of digits > minimum field size, negative value"}, - {"43", -12345101, 9, "%2.4ld", "-12345101", - "%ld with number of digits > precision field size > minimum field size, negative value"}, - {"44", -98765292, 10, "%-.20ld", "-00000000000098765292", - "%ld with left-justify and precision field size > number of digits, negative value"}, - {"45", -98765383, 8, "%-.3ld", "-98765383", - "%ld with left-justify and precision field size < number of digits, negative value"}, - {"46", -98765474, 9, "%+ld", "-98765474", "%ld with sign, negative value"}, - {"47", -46372565, 8, "$$$%+ld$$$", "$$$-46372565$$$", "%ld sign and embedded, negative value"}, - {"48", -91827112, 7, "%+11ld", " -91827112", - "%ld with sign and minimum field size > number of digits, negative value"}, - {"49", -91827223, 6, "%+4ld", "-91827223", - "%ld with sign and minimum field size < number of digits, negative value"}, - {"50", -33225334, 11, "%+.13ld", "-0000033225334", - "%ld with sign and precision field size > number of digits, negative value"}, - {"51", -33225445, 9, "%+.3ld", "-33225445", - "%ld with sign and precision field size < number of digits, negative value"}, - {"52", -12345556, 11, "%+12.10ld", " -0012345556", - "%ld with sign and minimum field size > precision field size > number of digits, negative value"}, - {"53", -12345667, 10, "%+12.3ld", " -12345667", - "%ld with sign and minimum field size > number of digits > precision field size, negative value"}, - {"54", -12345778, 9, "%+4.2ld", "-12345778", - "%ld with sign and number of digits > minimum field size > precision field size, negative value"}, - {"55", -12345889, 10, "%+7.12ld", "-000012345889", - "%ld with sign and precision field size > minimum field size > number of digits, negative value"}, - {"56", -12345990, 9, "%+3.12ld", "-000012345990", - "%ld with sign and precision field size > number of digits > minimum field size, negative value"}, - {"57", -12345221, 8, "%+2.4ld", "-12345221", - "%ld with sign and number of digits > precision field size > minimum field size, negative value"}, - {"58", -98765332, 7, "%+-.20ld", "-00000000000098765332", - "%ld with sign and left-justify and precision field size > number of digits, negative value"}, - {"59", -98765443, 6, "%+-.3ld", "-98765443", - "%ld with sign and left-justify and precision field size < number of digits, negative value"}, - {"60", -98765554, 5, "%+ld", "-98765554", "%ld with sign, negative value"}, - {"61", 0, 6, "%ld", "0", "%ld, zero value"}, - {"62", 16253409, 5, "%010ld", "0016253409", "%ld with zero padding, positive value"}, - {"63", -16253409, 6, "%010ld", "-016253409", "%ld with zero padding, negative value"}, - {"64", 0, 6, "%012ld", "000000000000", "%ld, with zero padding, zero value"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_lf.c b/src/unit-tests/osprintf-test/ut_osprintf_lf.c deleted file mode 100644 index bba38dcd2..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_lf.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_lf.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %lf format - *****************************************************************************/ -void UT_osprintf_lf(void) -{ - char *test_fmt = "lf"; /* Test format character(s) */ - int i; - - struct - { - char * test_num; /* Test identifier; sequential numbers */ - double test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char * format; /* Format string */ - char * expected; /* Expected result */ - char * description; /* Test description */ - } osp_tests[] = { - {"01", 9876543.125, 14, "%lf", "9876543.125000", "%lf, positive value"}, - {"02", 4637210.36, 12, "$$$%lf$$$", "$$$4637210.360000$$$", "%lf embedded, positive value"}, - {"03", 9182755.2756, 9, "%3lf", "9182755.275600", "%lf with maximum field size, positive value"}, - {"04", 12554.08, 5, "%.7lf", "12554.0800000", "%lf with precision, positive value"}, - {"05", 123456.2311, 11, "%9.7lf", "123456.2311000", - "%lf with precision and maximum field size, positive value"}, - {"06", 9876543.6765, 15, "%-20lf", "9876543.676500 ", "%lf with left-justify, positive value"}, - {"07", 9876543.001, 13, "%+lf", "+9876543.001000", "%lf with sign, positive value"}, - {"08", -9876543.1987, 12, "%lf", "-9876543.198700", "%lf, negative value"}, - {"09", -4637210.871, 14, "$$$%lf$$$", "$$$-4637210.871000$$$", "%lf embedded, negative value"}, - {"10", -9182755.22222, 15, "%3lf", "-9182755.222220", "%lf with maximum field size, negative value"}, - {"11", -3355.6109, 11, "%.5lf", "-3355.61090", "%lf with precision, negative value"}, - {"12", -123456.7, 14, "%15.4lf", " -123456.7000", - "%lf with precision and maximum field size, negative value"}, - {"13", -9876543.64388, 17, "%-20lf", "-9876543.643880 ", "%lf with left-justify, negative value"}, - {"14", 0.0, 4, "%lf", "0.000000", "%lf, zero value"}, - {"15", 123456789.0, 6, "%10.0lf", " 123456789", "%lf, no fraction, positive value"}, - {"16", -987654321.0, 6, "%12.0lf", " -987654321", "%lf, no fraction, negative value"}, - {"17", 34887.1255667, 5, "%020.4lf", "000000000034887.1256", "%lf with zero padding, positive value"}, - {"18", -34887.1255667, 5, "%020.4lf", "-00000000034887.1256", "%lf with zero padding, negative value"}, - {"19", 0.0, 6, "%09.4lf", "0000.0000", "%lf, with zero padding, zero value"}, - {"20", 467812.3, 6, "%9.0lf", " 467812", "%lf, no fraction, positive value"}, - {"21", -544446.0, 6, "%8.0lf", " -544446", "%lf, no fraction, negative value"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_li.c b/src/unit-tests/osprintf-test/ut_osprintf_li.c deleted file mode 100644 index b366e3966..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_li.c +++ /dev/null @@ -1,181 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_li.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %li format - *****************************************************************************/ -void UT_osprintf_li(void) -{ - char *test_fmt = "li"; /* Test format character(s) */ - int i; - - struct - { - char * test_num; /* Test identifier; sequential numbers */ - long int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char * format; /* Format string */ - char * expected; /* Expected result */ - char * description; /* Test description */ - } osp_tests[] = { - {"01", 12798765, 7, "%li", "12798765", "%li, positive value"}, - {"02", 43246372, 9, "$$$%li$$$", "$$$43246372$$$", "%li embedded, positive value"}, - {"03", 63198765, 8, "% li", " 63198765", "%li with space for sign, positive value"}, - {"04", 77691827, 7, "%11li", " 77691827", "%li with minimum field size > number of digits, positive value"}, - {"05", 54691827, 5, "%4li", "54691827", "%li with minimum field size < number of digits, positive value"}, - {"06", 77833225, 8, "%.10li", "0077833225", "%li with precision field size > number of digits, positive value"}, - {"07", 99933225, 5, "%.3li", "99933225", "%li with precision field size < number of digits, positive value"}, - {"08", 12345789, 10, "%12.10li", " 0012345789", - "%li with minimum field size > precision field size > number of digits, positive value"}, - {"09", 12345987, 12, "%12.3li", " 12345987", - "%li with minimum field size > number of digits > precision field size, positive value"}, - {"10", 12345444, 8, "%4.2li", "12345444", - "%li with number of digits > minimum field size > precision field size, positive value"}, - {"11", 12345321, 11, "%10.12li", "000012345321", - "%li with precision field size > minimum field size > number of digits, positive value"}, - {"12", 12333345, 7, "%6.12li", "000012333345", - "%li with precision field size > number of digits > minimum field size, positive value"}, - {"13", 12345777, 5, "%2.4li", "12345777", - "%li with number of digits > precision field size > minimum field size, positive value"}, - {"14", 98765321, 19, "%-.20li", "00000000000098765321", - "%li with left-justify and precision field size > number of digits, positive value"}, - {"15", 98765111, 7, "%-.3li", "98765111", - "%li with left-justify and precision field size < number of digits, positive value"}, - {"16", 98765222, 10, "%+li", "+98765222", "%li with sign, positive value"}, - {"17", 46372333, 9, "$$$%+li$$$", "$$$+46372333$$$", "%li sign and embedded, positive value"}, - {"18", 91827444, 8, "%+11li", " +91827444", - "%li with sign and minimum field size > number of digits, positive value"}, - {"19", 91827555, 7, "%+4li", "+91827555", - "%li with sign and minimum field size < number of digits, positive value"}, - {"20", 33225666, 2, "%+.13li", "+0000033225666", - "%li with sign and precision field size > number of digits, positive value"}, - {"21", 33225777, 5, "%+.3li", "+33225777", - "%li with sign and precision field size < number of digits, positive value"}, - {"22", 12345888, 9, "%+12.10li", " +0012345888", - "%li with sign and minimum field size > precision field size > number of digits, positive value"}, - {"23", 12345999, 8, "%+12.3li", " +12345999", - "%li with sign and minimum field size > number of digits > precision field size, positive value"}, - {"24", 12345000, 9, "%+4.2li", "+12345000", - "%li with sign and number of digits > minimum field size > precision field size, positive value"}, - {"25", 12345121, 11, "%+10.12li", "+000012345121", - "%li with sign and precision field size > minimum field size > number of digits, positive value"}, - {"26", 12345232, 10, "%+6.12li", "+000012345232", - "%li with sign and precision field size > number of digits > minimum field size, positive value"}, - {"27", 12345343, 7, "%+2.4li", "+12345343", - "%li with sign and number of digits > precision field size > minimum field size, positive value"}, - {"28", 98765454, 15, "%+-.20li", "+00000000000098765454", - "%li with sign and left-justify and precision field size > number of digits, positive value"}, - {"29", 98765565, 8, "%+-.3li", "+98765565", - "%li with sign and left-justify and precision field size < number of digits, positive value"}, - {"30", 98765676, 7, "%+li", "+98765676", "%li with sign, positive value"}, - {"31", -98765787, 6, "%li", "-98765787", "%li, negative value"}, - {"32", -46372898, 15, "$$$%li$$$", "$$$-46372898$$$", "%li embedded, negative value"}, - {"33", -98765909, 9, "% li", "-98765909", "%li with space for sign, negative value"}, - {"34", -91827121, 11, "%13li", " -91827121", - "%li with minimum field size > number of digits, negative value"}, - {"35", -91827232, 5, "%4li", "-91827232", "%li with minimum field size < number of digits, negative value"}, - {"36", -33225343, 8, "%.13li", "-0000033225343", - "%li with precision field size > number of digits, negative value"}, - {"37", -33225454, 7, "%.3li", "-33225454", "%li with precision field size < number of digits, negative value"}, - {"38", -12345565, 9, "%12.10li", " -0012345565", - "%li with minimum field size > precision field size > number of digits, negative value"}, - {"39", -12345676, 8, "%12.4li", " -12345676", - "%li with minimum field size > number of digits > precision field size, negative value"}, - {"40", -12345787, 4, "%4.2li", "-12345787", - "%li with number of digits > minimum field size > precision field size, negative value"}, - {"41", -12345898, 10, "%7.12li", "-000012345898", - "%li with precision field size > minimum field size > number of digits, negative value"}, - {"42", -12345909, 9, "%3.12li", "-000012345909", - "%li with precision field size > number of digits > minimum field size, negative value"}, - {"43", -12345101, 7, "%2.4li", "-12345101", - "%li with number of digits > precision field size > minimum field size, negative value"}, - {"44", -98765292, 18, "%-.20li", "-00000000000098765292", - "%li with left-justify and precision field size > number of digits, negative value"}, - {"45", -98765383, 7, "%-.3li", "-98765383", - "%li with left-justify and precision field size < number of digits, negative value"}, - {"46", -98765474, 8, "%+li", "-98765474", "%li with sign, negative value"}, - {"47", -46372565, 10, "$$$%+li$$$", "$$$-46372565$$$", "%li sign and embedded, negative value"}, - {"48", -91827112, 9, "%+11li", " -91827112", - "%li with sign and minimum field size > number of digits, negative value"}, - {"49", -91827223, 5, "%+4li", "-91827223", - "%li with sign and minimum field size < number of digits, negative value"}, - {"50", -33225334, 11, "%+.13li", "-0000033225334", - "%li with sign and precision field size > number of digits, negative value"}, - {"51", -33225445, 8, "%+.3li", "-33225445", - "%li with sign and precision field size < number of digits, negative value"}, - {"52", -12345556, 12, "%+12.10li", " -0012345556", - "%li with sign and minimum field size > precision field size > number of digits, negative value"}, - {"53", -12345667, 10, "%+12.3li", " -12345667", - "%li with sign and minimum field size > number of digits > precision field size, negative value"}, - {"54", -12345778, 6, "%+4.2li", "-12345778", - "%li with sign and number of digits > minimum field size > precision field size, negative value"}, - {"55", -12345889, 9, "%+7.12li", "-000012345889", - "%li with sign and precision field size > minimum field size > number of digits, negative value"}, - {"56", -12345990, 11, "%+3.12li", "-000012345990", - "%li with sign and precision field size > number of digits > minimum field size, negative value"}, - {"57", -12345221, 7, "%+2.4li", "-12345221", - "%li with sign and number of digits > precision field size > minimum field size, negative value"}, - {"58", -98765332, 15, "%+-.20li", "-00000000000098765332", - "%li with sign and left-justify and precision field size > number of digits, negative value"}, - {"59", -98765443, 7, "%+-.3li", "-98765443", - "%li with sign and left-justify and precision field size < number of digits, negative value"}, - {"60", -98765554, 5, "%+li", "-98765554", "%li with sign, negative value"}, - {"61", 0, 6, "%li", "0", "%li, zero value"}, - {"62", 16253409, 5, "%010li", "0016253409", "%li with zero padding, positive value"}, - {"63", -16253409, 6, "%010li", "-016253409", "%li with zero padding, negative value"}, - {"64", 0, 6, "%012li", "000000000000", "%li, with zero padding, zero value"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_lu.c b/src/unit-tests/osprintf-test/ut_osprintf_lu.c deleted file mode 100644 index 182c55620..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_lu.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_lu.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %lu format - *****************************************************************************/ -void UT_osprintf_lu(void) -{ - char *test_fmt = "lu"; /* Test format character(s) */ - int i; - -#ifdef OSP_ARINC653 -#pragma ghs nowarning 68 -#endif - struct - { - char * test_num; /* Test identifier; sequential numbers */ - unsigned long int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char * format; /* Format string */ - char * expected; /* Expected result */ - char * description; /* Test description */ - } osp_tests[] = { - {"01", 9876543, 6, "%lu", "9876543", "%lu, negative value"}, - {"02", 4637210, 12, "$$$%lu$$$", "$$$4637210$$$", "%lu embedded"}, - {"03", 9182755, 6, "%3lu", "9182755", "%lu with maximum field size"}, - {"04", 3322554, 10, "%.10lu", "0003322554", "%lu with minimum field size"}, - {"05", 123456, 8, "%9.7lu", " 0123456", "%lu with minimum and maximum field size"}, - {"06", 9876543, 16, "%-.20lu", "00000000000009876543", "%lu with left-justify"}, - {"07", 9876543, 5, "%+lu", "9876543", "%lu with sign"}, - {"08", -9876543, 8, "%lu", "4285090753", "%lu, negative value"}, - {"09", 0, 6, "%lu", "0", "%lu, zero value"}, - {"10", 162534098, 5, "%011lu", "00162534098", "%lu with zero padding"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; -#ifdef OSP_ARINC653 -#pragma ghs endnowarning -#endif - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_lx.c b/src/unit-tests/osprintf-test/ut_osprintf_lx.c deleted file mode 100644 index 72678d73c..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_lx.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_lx.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %x format - *****************************************************************************/ -void UT_osprintf_lx(void) -{ - char *test_fmt = "lx"; /* Test format character(s) */ - int i; - -#ifdef OSP_ARINC653 -#pragma ghs nowarning 68 -#endif - struct - { - char * test_num; /* Test identifier; sequential numbers */ - unsigned long int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char * format; /* Format string */ - char * expected; /* Expected result */ - char * description; /* Test description */ - } osp_tests[] = { - {"01", 0x9a8b7c6d, 5, "%lx", "9a8b7c6d", "%lx"}, - {"02", 0xdd46ee21, 12, "$$$%lx$$$", "$$$dd46ee21$$$", "%lx embedded"}, - {"03", 0x9ccc8275, 7, "%3lx", "9ccc8275", "%lx with minimum field size < number of digits"}, - {"04", 0xbee33225, 10, "%.10lx", "00bee33225", "%lx with precision field size"}, - {"05", 0x123fdb, 7, "%9.7lx", " 0123fdb", "%lx with minimum and precision field size"}, - {"06", 0xabc6543f, 19, "%-.20lx", "000000000000abc6543f", "%lx with left-justify"}, - {"07", -9876543, 7, "%lx", "ff694bc1", "%lx, negative value"}, - {"08", 0x12b45, 5, "%8lx", " 12b45", "%lx with minimum field size > number of digits"}, - {"09", 0x12b45, 6, "%08lx", "00012b45", "%lx with minimum field size > number of digits and leading zeroes"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; -#ifdef OSP_ARINC653 -#pragma ghs endnowarning -#endif - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_lx_uc.c b/src/unit-tests/osprintf-test/ut_osprintf_lx_uc.c deleted file mode 100644 index ab98a17a4..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_lx_uc.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_lX.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %lX format - *****************************************************************************/ -void UT_osprintf_lX(void) -{ - char *test_fmt = "lx"; /* Test format character(s) */ - int i; - -#ifdef OSP_ARINC653 -#pragma ghs nowarning 68 -#endif - struct - { - char * test_num; /* Test identifier; sequential numbers */ - unsigned long int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char * format; /* Format string */ - char * expected; /* Expected result */ - char * description; /* Test description */ - } osp_tests[] = { - {"01", 0x9a8b7c6d, 8, "%lX", "9A8B7C6D", "%lX"}, - {"02", 0xdd46ee21, 8, "$$$%lX$$$", "$$$DD46EE21$$$", "%lX embedded"}, - {"03", 0x9ccc8275, 7, "%3lX", "9CCC8275", "%lX with minimum field size < number of digits"}, - {"04", 0xbee33225, 10, "%.10lX", "00BEE33225", "%lX with precision field size"}, - {"05", 0x123fdb, 7, "%9.7lX", " 0123FDB", "%lX with minimum and precision field size"}, - {"06", 0xabc6543f, 16, "%-.20lX", "000000000000ABC6543F", "%lX with left-justify"}, - {"07", -9876543, 5, "%lX", "FF694BC1", "%lX, negative value"}, - {"08", 0x12b45, 3, "%8lX", " 12B45", "%lX with minimum field size > number of digits"}, - {"09", 0x12b45, 2, "%08lX", "00012B45", "%lX with minimum field size > number of digits and leading zeroes"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; -#ifdef OSP_ARINC653 -#pragma ghs endnowarning -#endif - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_misc.c b/src/unit-tests/osprintf-test/ut_osprintf_misc.c deleted file mode 100644 index a191f1c79..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_misc.c +++ /dev/null @@ -1,179 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_misc.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; - -/***************************************************************************** - * Test miscellaneous formats & combinations - *****************************************************************************/ -void UT_osprintf_misc(void) -{ - int test_int; - long test_long; - unsigned test_unsigned; - unsigned test_hex; - char * test_num = "misc"; - int return_value; - -#ifndef UT_NO_FLOAT - float test_float; - double test_double; - char test_char; -#endif - - /* Test representing percent character using %% */ - init_test(); - sprintf(strg_buf, "Show percent character .%%."); - UT_Report(check_test("Show percent character .%.", strg_buf), "SPRINTF", "Represent percent character using %%", - test_num, "01"); - - /* Test representing percent character using %%, truncated */ - init_test(); - snprintf(strg_buf, 11, "Show percent character .%%."); - UT_Report(check_test("Show perce", strg_buf), "SNPRINTF", "Represent percent character using %%, truncated", - test_num, "01"); - - /* Test format string ending with percent character */ - init_test(); - sprintf(strg_buf, "End with percent character %"); - UT_Report(check_test("End with percent character ", strg_buf), "SPRINTF", "End with percent character", test_num, - "02"); - - /* Test representing percent character using %%, truncated */ - init_test(); - snprintf(strg_buf, 11, "End with percent character %"); - UT_Report(check_test("End with p", strg_buf), "SNPRINTF", "End with percent character, truncated", test_num, "02"); - - /* Test null format string */ - init_test(); - sprintf(strg_buf, ""); - UT_Report(check_test("", strg_buf), "SPRINTF", "Null format string", test_num, "03"); - - /* Test representing percent character using %%, truncated */ - init_test(); - snprintf(strg_buf, 5, ""); - UT_Report(check_test("", strg_buf), "SNPRINTF", "Null format string", test_num, "03"); - - /* Test too many decimals in format width/precision modifier */ - init_test(); - return_value = sprintf(strg_buf, "Too many decimals"); - UT_Report(return_value < 0, "SPRINTF", "Invalid format string", test_num, "04"); - - /* Test too many decimals in format width/precision modifier, truncated */ - init_test(); - return_value = snprintf(strg_buf, 23, "Too many decimals"); - UT_Report(return_value < 0, "SNPRINTF", "Invalid format string", test_num, "04"); - - /* Test multiple parameters */ - init_test(); - test_int = 121; - test_long = -9876222; - test_unsigned = 5432; - test_hex = 72635; - sprintf(strg_buf, "Multiple parameters %d:%d, %d:%d, %d:%d, %d:%d", 1, test_int, 2, test_long, 3, test_unsigned, 4, - test_hex); - UT_Report(check_test("Multiple parameters 1:121, 2:-9876222, " - "3:5432, 4:72635", - strg_buf), - "SPRINTF", "Multiple parameters", test_num, "05"); - - /* Test multiple parameters, truncated */ - init_test(); - test_int = 121; - test_long = -9876222; - test_unsigned = 5432; - test_hex = 72635; - snprintf(strg_buf, 52, "Multiple parameters %d:%d, %d:%d, %d:%d, %d:%d", 1, test_int, 2, test_long, 3, - test_unsigned, 4, test_hex); - UT_Report(check_test("Multiple parameters 1:121, 2:-9876222, " - "3:5432, 4:72", - strg_buf), - "SNPRINTF", "Multiple parameters", test_num, "05"); - -#ifndef UT_NO_FLOAT - /* Test combination of types */ - init_test(); - test_int = -123; - test_long = 9876543; - test_unsigned = 4321; - test_hex = 0xa1b2; - test_float = -2.3456; - test_double = 6543.123456; - test_char = '$'; - sprintf(strg_buf, - "int = %d long = %ld uns = %u hex = 0x%x flt = %f " - "dbl = %lf chr = %c", - test_int, test_long, test_unsigned, test_hex, test_float, test_double, test_char); - UT_Report(check_test("int = -123 long = 9876543 uns = 4321 hex = " - "0xa1b2 flt = -2.345600 dbl = 6543.123456 " - "chr = $", - strg_buf), - "SPRINTF", "Combination of types", test_num, "06"); - - /* Test combination of types, truncated */ - init_test(); - test_int = -123; - test_long = 9876543; - test_unsigned = 4321; - test_hex = 0xa1b2; - test_float = -2.3456; - test_double = 6543.123456; - test_char = '$'; - snprintf(strg_buf, 16, - "int = %d long = %ld uns = %u hex = 0x%x flt = %f " - "dbl = %lf chr = %c", - test_int, test_long, test_unsigned, test_hex, test_float, test_double, test_char); - UT_Report(check_test("int = -123 lon", strg_buf), "SNPRINTF", "Combination of types, truncated", test_num, "06"); - - /* Test combination of types 2 */ - init_test(); - test_int = -123; - test_long = 9876543; - test_unsigned = 4321; - test_hex = 0xa1b2; - test_float = -2.3456; - test_double = 6543.123456; - test_char = '$'; - sprintf(strg_buf, "flt = %f dbl = %lf flt = %f", test_float, test_double, test_float); - UT_Report(check_test("flt = -2.345600 dbl = 6543.123456 flt = -2.345600", strg_buf), "SPRINTF", - "Combination of types 2", test_num, "07"); - - /* Test combination of types 2, truncated */ - init_test(); - test_int = -123; - test_long = 9876543; - test_unsigned = 4321; - test_hex = 0xa1b2; - test_float = -2.3456; - test_double = 6543.123456; - test_char = '$'; - snprintf(strg_buf, 10, "flt = %f dbl = %lf flt = %f", test_float, test_double, test_float); - UT_Report(check_test("flt = -2.", strg_buf), "SNPRINTF", "Combination of types 2", test_num, "07"); -#endif -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_offset.c b/src/unit-tests/osprintf-test/ut_osprintf_offset.c deleted file mode 100644 index f9874edb9..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_offset.c +++ /dev/null @@ -1,454 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* Calculate offset, breakpoint, and skip values for the cFE and cFE unit - * test variadic functions. Note that some "dummy" function calls from - * the original function are needed in order for the correct offset, - * breakpoint, and skip values to be calculated. The ordering of these - * dummy functions must match that in the actual function - */ -#ifdef UT_DO_OFFSET - -#include "ut_osprintf.h" -#include "ut_osprintf_offset.h" - -extern char cMsg[]; -extern char cNum[]; - -extern int OS_printf_break; -extern int OS_printf_skip; -extern int OS_printf_enabled; - -unsigned long testPattern[12][10] = {{0x12ab34cd, 0x19999991, 0x18888881, 0x17777771, 0x16666661, 0x15555551, - 0x14444441, 0x13333331, 0x12222221, 0x11111111}, - {0x23bc45de, 0x29999992, 0x28888882, 0x27777772, 0x26666662, 0x25555552, - 0x24444442, 0x23333332, 0x22222222, 0x21111112}, - {0x34cd56ef, 0x39999993, 0x38888883, 0x37777773, 0x36666663, 0x35555553, - 0x34444443, 0x33333333, 0x32222223, 0x31111113}, - {0x45ab67cd, 0x49999994, 0x48888884, 0x47777774, 0x46666664, 0x45555554, - 0x44444444, 0x43333334, 0x42222224, 0x41111114}, - {0x56bc78de, 0x59999995, 0x58888885, 0x57777775, 0x56666665, 0x55555555, - 0x54444445, 0x53333335, 0x52222225, 0x51111115}, - {0x67cd78ef, 0x69999996, 0x68888886, 0x67777776, 0x66666666, 0x65555556, - 0x64444446, 0x63333336, 0x62222226, 0x61111116}, - {0x78ab9acd, 0x79999997, 0x78888887, 0x77777777, 0x76666667, 0x75555557, - 0x74444447, 0x73333337, 0x72222227, 0x71111117}, - {0x89bcabde, 0x89999998, 0x88888888, 0x87777778, 0x86666668, 0x85555558, - 0x84444448, 0x83333338, 0x82222228, 0x81111118}, - {0x9acdbcef, 0x99999999, 0x98888889, 0x97777779, 0x96666669, 0x95555559, - 0x94444449, 0x93333339, 0x92222229, 0x91111119}, - {0xababcdcd, 0xa999999a, 0xa888888a, 0xa777777a, 0xa666666a, 0xa555555a, - 0xa444444a, 0xa333333a, 0xa222222a, 0xa111111a}, - {0xbcbcdede, 0xb999999b, 0xb888888b, 0xb777777b, 0xb666666b, 0xb555555b, - 0xb444444b, 0xb333333b, 0xb222222b, 0xb111111b}, - {0xcdcdefef, 0xc999999c, 0xc888888c, 0xc777777c, 0xc666666c, 0xc555555c, - 0xc444444c, 0xc333333c, 0xc222222c, 0xc111111c}}; - -void UT_osprintf_CalcOffsets(void) -{ - CFE_TIME_SysTime_t Time = {0, 0}; - - /* Determine variadic offsets */ - CalcOffset_CFE_ES_WriteToSysLog("CFE_ES_WriteToSysLog test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", - testPattern[0][0], testPattern[0][1], testPattern[0][2], testPattern[0][3], - testPattern[0][4], testPattern[0][5], testPattern[0][6], testPattern[0][7], - testPattern[0][8], testPattern[0][9]); - CalcOffset_EVS_SendEvent(111, 222, "EVS_SendEvent test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", testPattern[1][0], - testPattern[1][1], testPattern[1][2], testPattern[1][3], testPattern[1][4], - testPattern[1][5], testPattern[1][6], testPattern[1][7], testPattern[1][8], - testPattern[1][9]); - CalcOffset_CFE_EVS_SendEvent(333, 444, "CFE_EVS_SendEvent test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", - testPattern[2][0], testPattern[2][1], testPattern[2][2], testPattern[2][3], - testPattern[2][4], testPattern[2][5], testPattern[2][6], testPattern[2][7], - testPattern[2][8], testPattern[2][9]); - CalcOffset_CFE_EVS_SendEventWithAppID( - 555, 666, 7, "CFE_EVS_SendEventWithAppID test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", testPattern[3][0], - testPattern[3][1], testPattern[3][2], testPattern[3][3], testPattern[3][4], testPattern[3][5], - testPattern[3][6], testPattern[3][7], testPattern[3][8], testPattern[3][9]); - CalcOffset_CFE_EVS_SendTimedEvent( - Time, 888, 999, "CFE_EVS_SendTimedEvent test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", testPattern[4][0], - testPattern[4][1], testPattern[4][2], testPattern[4][3], testPattern[4][4], testPattern[4][5], - testPattern[4][6], testPattern[4][7], testPattern[4][8], testPattern[4][9]); - CalcOffset_OS_printf("OS_printf test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", testPattern[5][0], testPattern[5][1], - testPattern[5][2], testPattern[5][3], testPattern[5][4], testPattern[5][5], testPattern[5][6], - testPattern[5][7], testPattern[5][8], testPattern[5][9]); - CalcOffset_OS_sprintf(cMsg, "OS_sprintf test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", testPattern[6][0], - testPattern[6][1], testPattern[6][2], testPattern[6][3], testPattern[6][4], testPattern[6][5], - testPattern[6][6], testPattern[6][7], testPattern[6][8], testPattern[6][9]); - CalcOffset_OS_snprintf(cMsg, 100, "OS_snprintf test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", testPattern[7][0], - testPattern[7][1], testPattern[7][2], testPattern[7][3], testPattern[7][4], - testPattern[7][5], testPattern[7][6], testPattern[7][7], testPattern[7][8], - testPattern[7][9]); - CalcOffset_OS_printf_stub("OS_printf stub test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", testPattern[8][0], - testPattern[8][1], testPattern[8][2], testPattern[8][3], testPattern[8][4], - testPattern[8][5], testPattern[8][6], testPattern[8][7], testPattern[8][8], - testPattern[8][9]); - CalcOffset_CFE_ES_WriteToSysLog_stub("CFE_ES_WriteToSysLog stub test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", - testPattern[9][0], testPattern[9][1], testPattern[9][2], testPattern[9][3], - testPattern[9][4], testPattern[9][5], testPattern[9][6], testPattern[9][7], - testPattern[9][8], testPattern[9][9]); - CalcOffset_CFE_EVS_SendEvent_stub(333, 444, "CFE_EVS_SendEvent stub test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", - testPattern[10][0], testPattern[10][1], testPattern[10][2], testPattern[10][3], - testPattern[10][4], testPattern[10][5], testPattern[10][6], testPattern[10][7], - testPattern[10][8], testPattern[10][9]); - CalcOffset_CFE_EVS_SendEventWithAppID_stub( - 555, 666, 5, "CFE_EVS_SendEventWithAppID stub test %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", testPattern[11][0], - testPattern[11][1], testPattern[11][2], testPattern[11][3], testPattern[11][4], testPattern[11][5], - testPattern[11][6], testPattern[11][7], testPattern[11][8], testPattern[11][9]); -} - -void UT_ShowHex(unsigned char *ptr, int numBytes) -{ - int i, j; - unsigned char *bytePtr = (unsigned char *)ptr; - char hMsg[3000]; - - strcpy(hMsg, "args = "); - - for (i = 0, j = 1; i < numBytes; i++, j++) - { - UT_itoa(*bytePtr, cNum, 16, 2); - strcat(hMsg, cNum); - strcat(hMsg, " "); - bytePtr++; - - if (j == 4) - { - strcat(hMsg, "\n "); - j = 0; - } - } - - UT_Text(hMsg); -} - -/* Determine the offset, breakpoint, and skip values for a variadic function */ -void UT_CheckArgumentOffset(va_list ptr, int tpIndex) -{ - int i = 0; - int offset = -1; - int breakpoint = 0; - int skip = 0; - int max_allowed_offset = 20; - int max_allowed_skip = 100; - int num_parms = 10; - unsigned char *bytePtr = (unsigned char *)ptr; - unsigned char *testPtr = (void *)&testPattern[tpIndex][0]; - - /* - UT_ShowHex(ptr, 440); - */ - - while (offset < max_allowed_offset && i < sizeof(unsigned long)) - { - offset++; - - for (i = 0; i < sizeof(unsigned long); i++) - { - if (*(bytePtr + (offset * sizeof(va_list)) + i) != *(testPtr + i)) - { - break; - } - } - } - - if (offset == max_allowed_offset) - { - UT_Text(" Offset could not be determined\n"); - } - else - { - sprintf(cMsg, " Offset = %d\n", offset); - UT_Text(cMsg); - i = sizeof(unsigned long); - - /* Find breakpoint value */ - while (offset < max_allowed_offset + num_parms && i == sizeof(unsigned long)) - { - offset++; - breakpoint++; - testPtr += sizeof(unsigned long); - - for (i = 0; i < sizeof(unsigned long); i++) - { - if (*(bytePtr + (offset * sizeof(va_list)) + i) != *(testPtr + i)) - { - break; - } - } - } - - if (breakpoint == num_parms) - { - UT_Text(" No breakpoint found\n"); - } - else - { - sprintf(cMsg, " Breakpoint = %d\n", breakpoint); - UT_Text(cMsg); - - /* Find skip value */ - while (offset < max_allowed_offset + num_parms + max_allowed_skip && i < sizeof(unsigned long)) - { - offset++; - skip++; - - for (i = 0; i < sizeof(unsigned long); i++) - { - if (*(bytePtr + (offset * sizeof(va_list)) + i) != *(testPtr + i)) - { - break; - } - } - } - - if (skip == max_allowed_skip) - { - UT_Text(" Skip could not be determined\n"); - } - else - { - sprintf(cMsg, " Skip = %d\n", skip); - UT_Text(cMsg); - } - } - } -} - -/* Mimic actual CFE_ES_WriteToSysLog() */ -int32 CalcOffset_CFE_ES_WriteToSysLog(const char *SpecStringPtr, ...) -{ - char TmpString[CFE_ES_MAX_SYSLOG_MSG_SIZE]; - char MsgWithoutTime[CFE_EVS_MAX_MESSAGE_LENGTH]; - CFE_TIME_SysTime_t time = {0, 0}; - va_list Ptr; - - va_start(Ptr, SpecStringPtr, 0, 0, 0); - OS_vsnprintfDummy(MsgWithoutTime, 1, SpecStringPtr, Ptr); - CFE_TIME_PrintDummy(TmpString, time); - strcatDummy(TmpString, " "); - strncatDummy(TmpString, MsgWithoutTime, 1); - OS_printfDummy("%s", TmpString); - strlenDummy(TmpString); - strncpyDummy(TmpString, TmpString, 1); - strncpyDummy(TmpString, "\0", 1); - OS_printfDummy("Warning: Last System Log Message Truncated.\n"); - strlenDummy(TmpString); - strncpyDummy(TmpString, TmpString, 1); - - UT_Text("\nCFE_ES_WriteToSysLog Argument Calculation:\n"); - UT_CheckArgumentOffset(Ptr, 0); - va_end(Ptr); - return 0; -} - -/* Mimic actual EVS_SendEvent() */ -int32 CalcOffset_EVS_SendEvent(uint16 EventID, uint16 EventType, const char *Spec, ...) -{ - CFE_EVS_Packet_t EVS_Packet; - CFE_TIME_SysTime_t Time = {0, 0}; - va_list Ptr; - - EVS_IsFilteredDummy(0, EventID, EventType); - CFE_SB_InitMsgDummy(&EVS_Packet, 1, sizeof(CFE_EVS_Packet_t), 1); - va_start(Ptr, Spec, 0, 0, 0); - OS_vsnprintfDummy(EVS_Packet.Message, 1, Spec, Ptr); - CFE_TIME_GetTimeDummy(); - EVS_SendPacketDummy(0, Time, &EVS_Packet); - - UT_Text("\nEVS_SendEvent Argument Calculation:\n"); - UT_CheckArgumentOffset(Ptr, 1); - va_end(Ptr); - return 0; -} - -/* Mimic actual CFE_EVS_SendEvent() */ -int32 CalcOffset_CFE_EVS_SendEvent(uint16 EventID, uint16 EventType, const char *Spec, ...) -{ - CFE_EVS_Packet_t EVS_Packet; - uint32 AppID = 0; - CFE_TIME_SysTime_t Time = {0, 0}; - va_list Ptr; - - EVS_GetAppIDDummy(&AppID); - EVS_NotRegisteredDummy(AppID); - EVS_IsFilteredDummy(AppID, EventID, EventType); - CFE_SB_InitMsgDummy(&EVS_Packet, 1, sizeof(CFE_EVS_Packet_t), 1); - va_start(Ptr, Spec, 0, 0, 0); - OS_vsnprintfDummy(EVS_Packet.Message, 1, Spec, Ptr); - CFE_TIME_GetTimeDummy(); - EVS_SendPacketDummy(AppID, Time, &EVS_Packet); - - UT_Text("\nCFE_EVS_SendEvent Argument Calculation:\n"); - UT_CheckArgumentOffset(Ptr, 2); - va_end(Ptr); - return 0; -} - -/* Mimic actual CFE_EVS_SendEventWithAppID() */ -/* THIS IS RETURNING THE WRONG SKIP VALUE!!! (off by -2) */ -int32 CalcOffset_CFE_EVS_SendEventWithAppID(uint16 EventID, uint16 EventType, uint32 AppID, const char *Spec, ...) -{ - CFE_EVS_Packet_t EVS_Packet; - CFE_TIME_SysTime_t Time = {0, 0}; - va_list Ptr; - - EVS_NotRegisteredDummy(AppID); - EVS_IsFilteredDummy(AppID, EventID, EventType); - CFE_SB_InitMsgDummy(&EVS_Packet, 1, sizeof(CFE_EVS_Packet_t), 1); - va_start(Ptr, Spec, 0, 0, 0); - OS_vsnprintfDummy(EVS_Packet.Message, 1, Spec, Ptr); - CFE_TIME_GetTimeDummy(); - EVS_SendPacketDummy(AppID, Time, &EVS_Packet); - - UT_Text("\nCFE_EVS_SendEventWithAppID Argument Calculation:\n"); - UT_CheckArgumentOffset(Ptr, 3); - va_end(Ptr); - return 0; -} - -/* Mimic actual CFE_EVS_SendTimedEvent() */ -int32 CalcOffset_CFE_EVS_SendTimedEvent(CFE_TIME_SysTime_t Time, uint16 EventID, uint16 EventType, const char *Spec, - ...) -{ - CFE_EVS_Packet_t EVS_Packet; - uint32 AppID = 0; - va_list Ptr; - - EVS_GetAppIDDummy(&AppID); - EVS_NotRegisteredDummy(AppID); - EVS_IsFilteredDummy(AppID, EventID, EventType); - CFE_SB_InitMsgDummy(&EVS_Packet, 0, sizeof(CFE_EVS_Packet_t), 0); - va_start(Ptr, Spec, 0, 0, 0); - OS_vsnprintfDummy(EVS_Packet.Message, 0, Spec, Ptr); - EVS_SendPacketDummy(AppID, Time, &EVS_Packet); - - UT_Text("\nCFE_EVS_SendTimedEvent Argument Calculation:\n"); - UT_CheckArgumentOffset(Ptr, 4); - va_end(Ptr); - return 0; -} - -/* Mimic actual OS_printf() */ -void CalcOffset_OS_printf(const char *format, ...) -{ - va_list varg; - - va_start(varg, format, 0, 0, 0); - OS_vsnprintfDummy(0, -1, format, varg) - - UT_Text("\nOS_printf Argument Calculation:\n"); - UT_CheckArgumentOffset(varg, 5); - va_end(varg); -} - -/* Mimic actual and stub OS_sprintf() */ -int CalcOffset_OS_sprintf(char *out, const char *format, ...) -{ - va_list varg; - int length; - - va_start(varg, format, 0, 0, 0); - length = OS_vsnprintfDummy(out, -1, format, varg); - - UT_Text("\nOS_sprintf Argument Calculation:\n"); - UT_CheckArgumentOffset(varg, 6); - va_end(varg); - return (length); -} - -/* Mimic actual and stub OS_snprintf() */ -int CalcOffset_OS_snprintf(char *out, unsigned max_len, const char *format, ...) -{ - va_list varg; - int length; - - va_start(varg, format, 0, 0, 0); - length = OS_vsnprintfDummy(out, (int)max_len - 1, format, varg); - - UT_Text("\nOS_snprintf Argument Calculation:\n"); - UT_CheckArgumentOffset(varg, 7); - va_end(varg); - return (length); -} - -/* Mimic stub OS_printf() */ -void CalcOffset_OS_printf_stub(const char *string, ...) -{ - char tmpString[CFE_ES_MAX_SYSLOG_MSG_SIZE * 2]; - va_list ptr; - - va_start(ptr, string, 0, 0, 0); - OS_vsnprintfDummy(tmpString, CFE_ES_MAX_SYSLOG_MSG_SIZE * 2, string, ptr); - - UT_Text("\nOS_printf Stub Argument Calculation:\n"); - UT_CheckArgumentOffset(ptr, 8); - va_end(ptr); -} - -int32 CalcOffset_CFE_ES_WriteToSysLog_stub(const char *pSpecString, ...) -{ - char tmpString[CFE_ES_MAX_SYSLOG_MSG_SIZE]; - va_list ap; - - va_start(ap, pSpecString, 0, 0, 0); - OS_vsnprintfDummy(tmpString, CFE_ES_MAX_SYSLOG_MSG_SIZE, pSpecString, ap); - - UT_Text("\nCFE_ES_WriteToSysLog Stub Argument Calculation:\n"); - UT_CheckArgumentOffset(ap, 9); - va_end(ap); - return 0; -} - -/* Mimic stub CFE_EVS_SendEvent() */ -int32 CalcOffset_CFE_EVS_SendEvent_stub(uint16 EventID, uint16 EventType, const char *Spec, ...) -{ - char BigBuf[CFE_EVS_MAX_MESSAGE_LENGTH]; - va_list Ptr; - - va_start(Ptr, Spec, 0, 0, 0); - OS_vsnprintfDummy(BigBuf, CFE_EVS_MAX_MESSAGE_LENGTH, Spec, Ptr); - UT_AddEventToHistoryDummy(EventID); - - UT_Text("\nCFE_EVS_SendEvent Stub Argument Calculation:\n"); - UT_CheckArgumentOffset(Ptr, 10); - va_end(Ptr); - return 0; -} - -/* Mimic stub CFE_EVS_SendEventWithAppID() */ -int32 CalcOffset_CFE_EVS_SendEventWithAppID_stub(uint16 EventID, uint16 EventType, uint32 AppID, const char *Spec, ...) -{ - char BigBuf[CFE_EVS_MAX_MESSAGE_LENGTH]; - va_list Ptr; - - va_start(Ptr, Spec, 0, 0, 0); - OS_vsnprintfDummy(BigBuf, CFE_EVS_MAX_MESSAGE_LENGTH, Spec, Ptr); - UT_AddEventToHistoryDummy(EventID); - OS_snprintfDummy(cMsg, UT_MAX_MESSAGE_LENGTH, " CFE_EVS_SendEvent from app %lu: %u, %u - %s", AppID, EventID, - EventType, BigBuf); - - UT_Text("\nCFE_EVS_SendEventWithAppID Stub Argument Calculation:\n"); - UT_CheckArgumentOffset(Ptr, 11); - va_end(Ptr); - return 0; -} - -#endif diff --git a/src/unit-tests/osprintf-test/ut_osprintf_offset.h b/src/unit-tests/osprintf-test/ut_osprintf_offset.h deleted file mode 100644 index f86c4c2cf..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_offset.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * ut_osprintf_offset.h - * - * Variadic argument offset calculation - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ -#ifdef UT_DO_OFFSET - -#ifndef UT_OSPRINTF_OFFSET_H_ -#define UT_OSPRINTF_OFFSET_H_ - -#include "common_types.h" -#include "osapi.h" -#include "cfe_es.h" -#include "cfe_sb.h" -#include "cfe_evs_task.h" -#include "cfe_time.h" -#include "cfe_mission_cfg.h" -#include "osprintf.h" - -void UT_ShowHex(unsigned char *, int); -void UT_CheckArgumentOffset(va_list, int); -void UT_osprintf_CalcOffsets(void); -int32 CalcOffset_CFE_ES_WriteToSysLog(const char *, ...); -int32 CalcOffset_EVS_SendEvent(uint16, uint16, const char *, ...); -int32 CalcOffset_CFE_EVS_SendEvent(uint16, uint16, const char *, ...); -int32 CalcOffset_CFE_EVS_SendEventWithAppID(uint16, uint16, uint32, const char *, ...); -int32 CalcOffset_CFE_EVS_SendTimedEvent(CFE_TIME_SysTime_t, uint16, uint16, const char *, ...); -void CalcOffset_OS_printf(const char *, ...); -int CalcOffset_OS_sprintf(char *, const char *, ...); -int CalcOffset_OS_snprintf(char *, unsigned, const char *, ...); -void CalcOffset_OS_printf_stub(const char *, ...); -int32 CalcOffset_CFE_ES_WriteToSysLog_stub(const char *, ...); -int32 CalcOffset_CFE_EVS_SendEvent_stub(uint16, uint16, const char *, ...); -int32 CalcOffset_CFE_EVS_SendEventWithAppID_stub(uint16, uint16, uint32, const char *, ...); -void CFE_TIME_PrintDummy(char *, CFE_TIME_SysTime_t); -unsigned char EVS_IsFilteredDummy(uint32, uint16, uint16); -void CFE_SB_InitMsgDummy(void *, uint16, uint16, unsigned char); -CFE_TIME_SysTime_t CFE_TIME_GetTimeDummy(void); -void EVS_SendPacketDummy(uint32, CFE_TIME_SysTime_t, CFE_EVS_Packet_t *); -long int EVS_GetAppIDDummy(uint32 *); -long int EVS_NotRegisteredDummy(uint32); -int OS_vsnprintfDummy(char *, int, const char *, ...); -void OS_printfDummy(const char *, ...); -int OS_snprintfDummy(char *, unsigned, const char *, ...); -char * strcatDummy(char *, const char *); -char * strncatDummy(char *, const char *, int); -char * strncpyDummy(char *, const char *, int); -int strlenDummy(const char *); -void UT_AddEventToHistoryDummy(uint16 EventID); - -#endif /* UT_OSPRINTF_OFFSET_H_ */ - -#endif diff --git a/src/unit-tests/osprintf-test/ut_osprintf_offset_dummy.c b/src/unit-tests/osprintf-test/ut_osprintf_offset_dummy.c deleted file mode 100644 index d462d49a1..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_offset_dummy.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifdef UT_DO_OFFSET - -#include "ut_osprintf.h" -#include "ut_osprintf_offset.h" - -void CFE_TIME_PrintDummy(char *PrintBuffer, CFE_TIME_SysTime_t TimeToPrint) {} - -unsigned char EVS_IsFilteredDummy(uint32 AppID, uint16 EventID, uint16 EventType) -{ - return 0; -} - -void CFE_SB_InitMsgDummy(void *MsgPtr, uint16 MsgId, uint16 Length, unsigned char Clear) {} - -CFE_TIME_SysTime_t CFE_TIME_GetTimeDummy(void) -{ - CFE_TIME_SysTime_t Time = {0, 0}; - - return Time; -} - -void EVS_SendPacketDummy(uint32 AppID, CFE_TIME_SysTime_t Time, CFE_EVS_Packet_t *EVS_PktPtr) {} - -long int EVS_GetAppIDDummy(uint32 *AppIdPtr) -{ - return 0; -} - -long int EVS_NotRegisteredDummy(uint32 AppID) -{ - return 0; -} - -int OS_vsnprintfDummy(char *out_buffer, int max_len, const char *format, ...) -{ - return 0; -} - -void OS_printfDummy(const char *format, ...) {} - -int OS_snprintfDummy(char *out_buffer, unsigned max_len, const char *format, ...) -{ - return 0; -} - -char *strcatDummy(char *out, const char *in) -{ - return out; -} - -char *strncatDummy(char *out, const char *in, int len) -{ - return out; -} - -char *strncpyDummy(char *out, const char *in, int len) -{ - return out; -} - -int strlenDummy(const char *in) -{ - return 0; -} - -void UT_AddEventToHistoryDummy(uint16 EventID) {} -#endif diff --git a/src/unit-tests/osprintf-test/ut_osprintf_p.c b/src/unit-tests/osprintf-test/ut_osprintf_p.c deleted file mode 100644 index 4d5ce8ec9..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_p.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_p.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %p format - *****************************************************************************/ -void UT_osprintf_p(void) -{ - char *test_fmt = "p"; /* Test format character(s) */ - int i; - - struct - { - char * test_num; /* Test identifier; sequential numbers */ - long int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char * format; /* Format string */ - char * expected; /* Expected result */ - char * description; /* Test description */ - } osp_tests[] = { - {"01", 98765, 5, "%p", "0x181cd", "%p"}, - {"02", 46372, 10, "$$$%p$$$", "$$$0xb524$$$", "%p embedded"}, - {"03", 91827, 5, "%3p", "0x166b3", "%p with minimum field size"}, - {"04", 33225, 11, "%.10p", "0x00000081c9", "%p with precision field size"}, - {"05", 12345, 9, "%9.7p", "0x0003039", "%p with minimum and precision field size"}, - {"06", 98765, 19, "%-.20p", "0x000000000000000181cd", "%p with left-justify"}, - {"07", -98765, 8, "%p", "0xfffe7e33", "%p, negative value"}, - {"08", 4108, 4, "%8p", " 0x100c", "%p with minimum field size > number of digits"}, - {"09", 55220, 6, "%010p", "0x0000d7b4", "%p with minimum field size > number of digits and leading zeroes"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, (void *)osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, (void *)osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_printf.c b/src/unit-tests/osprintf-test/ut_osprintf_printf.c deleted file mode 100644 index 182261db2..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_printf.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_printf.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#ifdef OS_USE_EMBEDDED_PRINTF - -#include "ut_osprintf.h" - -extern unsigned OS_printf_enabled; - -/***************************************************************************** - * Tests of embedded printf to get complete osprintf.c code coverage - *****************************************************************************/ -void UT_osprintf_printf(void) -{ - /* Perform printf enabled test */ - OS_printf("%s", "printf_test_string\n"); - UT_Report(UT_PASS, "PRINTF", "Output to console", "%s", "01"); - - /* Perform printf disabled test */ - OS_printf_enabled = 0; - OS_printf("%s", "printf_test_string_disabled\n"); - UT_Report(UT_PASS, "PRINTF", "Output to console disabled", "%s", "02"); - OS_printf_enabled = 1; -} -#endif diff --git a/src/unit-tests/osprintf-test/ut_osprintf_s.c b/src/unit-tests/osprintf-test/ut_osprintf_s.c deleted file mode 100644 index 9ee055b4d..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_s.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_s.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %s format - *****************************************************************************/ -void UT_osprintf_s(void) -{ - char *test_fmt = "s"; /* Test format character(s) */ - int i; - - struct - { - char *test_num; /* Test identifier; sequential numbers */ - char test_val[30]; /* Test value */ - int max_len; /* Maximum output string length */ - char *format; /* Format string */ - char *expected; /* Expected result */ - char *description; /* Test description */ - } osp_tests[] = { - {"01", "123456789abcd", 7, "%s", "123456789abcd", "%s"}, - {"02", "123456789abcd", 7, "$$$%s$$$", "$$$123456789abcd$$$", "%s embedded"}, - {"03", "123456789abcd", 11, "%20s", " 123456789abcd", "%s with minimum field size"}, - {"04", "123456789abcd", 8, "%.10s", "123456789a", "%s with maximum field size"}, - {"05", "123456789abcd", 7, "%5.7s", "1234567", "%s with minimum and maximum field size"}, - {"06", "123456789abcd", 10, "%-20s", "123456789abcd ", "%s with left-justify"}, - {"07", "3456789abcd", 7, "%+s", "3456789abcd", "%s with sign"}, - {"08", "", 3, "%s", "", "%s with null string"}, - {"09", "123456789abcd", 11, "%020s", " 123456789abcd", "%s with minimum field size, ignore zero padding"}, - {"", "", 0, "", "", ""} /* End with a null format to terminate list */ - }; - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_u.c b/src/unit-tests/osprintf-test/ut_osprintf_u.c deleted file mode 100644 index ff9bcafd8..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_u.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_u.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %u format - *****************************************************************************/ -void UT_osprintf_u(void) -{ - char *test_fmt = "u"; /* Test format character(s) */ - int i; - - struct - { - char *test_num; /* Test identifier; sequential numbers */ - int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char *format; /* Format string */ - char *expected; /* Expected result */ - char *description; /* Test description */ - } osp_tests[] = { - {"01", 98765, 5, "%u", "98765", "%u"}, - {"02", 46372, 10, "$$$%u$$$", "$$$46372$$$", "%u embedded"}, - {"03", 91827, 5, "%3u", "91827", "%u with maximum field size"}, - {"04", 33225, 8, "%.10u", "0000033225", "%u with minimum field size"}, - {"05", 12345, 7, "%9.7u", " 0012345", "%u with minimum and maximum field size"}, - {"06", 98765, 18, "%-.20u", "00000000000000098765", "%u with left-justify"}, - {"07", 98765, 5, "%+u", "98765", "%u with sign"}, - {"08", -98765, 8, "%u", "4294868531", "%u, negative value"}, - {"09", 0, 6, "%u", "0", "%u, zero value"}, - {"10", 162534, 5, "%08u", "00162534", "%u with zero padding"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_x.c b/src/unit-tests/osprintf-test/ut_osprintf_x.c deleted file mode 100644 index aebc3d671..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_x.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_x.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %x format - *****************************************************************************/ -void UT_osprintf_x(void) -{ - char *test_fmt = "x"; /* Test format character(s) */ - int i; - -#ifdef OSP_ARINC653 -#pragma ghs nowarning 68 -#endif - struct - { - char * test_num; /* Test identifier; sequential numbers */ - unsigned int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char * format; /* Format string */ - char * expected; /* Expected result */ - char * description; /* Test description */ - } osp_tests[] = { - {"01", 0xa8b7, 3, "%x", "a8b7", "%x"}, - {"02", 0xff123, 10, "$$$%x$$$", "$$$ff123$$$", "%x embedded"}, - {"03", 0xd1827, 5, "%3x", "d1827", "%x with minimum field size < number of digits"}, - {"04", 0x3c225, 9, "%.10x", "000003c225", "%x with precision field size"}, - {"05", 0x12b45, 9, "%9.7x", " 0012b45", "%x with minimum and precision field size"}, - {"06", 0xe8a60, 19, "%-.20x", "000000000000000e8a60", "%x with left-justify"}, - {"07", -16, 7, "%x", "fffffff0", "%x, negative value"}, - {"08", 0x12b45, 3, "%8x", " 12b45", "%x with minimum field size > number of digits"}, - {"09", 0x12b45, 5, "%08x", "00012b45", "%x with minimum field size > number of digits and leading zeroes"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; -#ifdef OSP_ARINC653 -#pragma ghs endnowarning -#endif - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} diff --git a/src/unit-tests/osprintf-test/ut_osprintf_x_uc.c b/src/unit-tests/osprintf-test/ut_osprintf_x_uc.c deleted file mode 100644 index ceac0202a..000000000 --- a/src/unit-tests/osprintf-test/ut_osprintf_x_uc.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * UT_osprintf_X.c - * - * Created on: May 22, 2013 - * Author: Kevin McCluney - */ - -#include "ut_osprintf.h" - -extern char strg_buf[]; -extern char trunc_buf[]; - -/***************************************************************************** - * Test %X format - *****************************************************************************/ -void UT_osprintf_X(void) -{ - char *test_fmt = "x"; /* Test format character(s) */ - int i; - -#ifdef OSP_ARINC653 -#pragma ghs nowarning 68 -#endif - struct - { - char * test_num; /* Test identifier; sequential numbers */ - unsigned int test_val; /* Test value */ - int max_len; /* Maximum output string length */ - char * format; /* Format string */ - char * expected; /* Expected result */ - char * description; /* Test description */ - } osp_tests[] = { - {"01", 0xa8b7, 3, "%X", "A8B7", "%X"}, - {"02", 0xff123, 10, "$$$%X$$$", "$$$FF123$$$", "%X embedded"}, - {"03", 0xd1827, 5, "%3X", "D1827", "%X with minimum field size < number of digits"}, - {"04", 0x3c225, 9, "%.10X", "000003C225", "%X with precision field size"}, - {"05", 0x12b45, 7, "%9.7X", " 0012B45", "%X with minimum and precision field size"}, - {"06", 0xe8a60, 19, "%-.20X", "000000000000000E8A60", "%X with left-justify"}, - {"07", -16, 7, "%X", "FFFFFFF0", "%X, negative value"}, - {"08", 0x12b45, 4, "%8X", " 12B45", "%X with minimum field size > number of digits"}, - {"09", 0x12b45, 5, "%08X", "00012B45", "%X with minimum field size > number of digits and leading zeroes"}, - {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ - }; -#ifdef OSP_ARINC653 -#pragma ghs endnowarning -#endif - - for (i = 0; osp_tests[i].format[0] != '\0'; i++) - { - /* Perform sprintf test */ - init_test(); - sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - - /* Truncate expected string in preparation for snprintf test */ - strcpy(trunc_buf, osp_tests[i].expected); - - if (strlen(trunc_buf) >= osp_tests[i].max_len) - { - trunc_buf[osp_tests[i].max_len - 1] = '\0'; - } - - /* Perform snprintf test */ - init_test(); - snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); - UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, - osp_tests[i].test_num); - } -} From 9d523b67e5cccb10aa9b437a7c0d2932f5576fb8 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Wed, 9 Dec 2020 10:42:55 -0500 Subject: [PATCH 10/11] Fix #120, Exit console loop on shutdown --- src/os/posix/src/os-impl-console.c | 5 ++++- src/os/rtems/src/os-impl-console.c | 5 ++++- src/os/vxworks/src/os-impl-console.c | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/os/posix/src/os-impl-console.c b/src/os/posix/src/os-impl-console.c index 7ba6baa63..74881962e 100644 --- a/src/os/posix/src/os-impl-console.c +++ b/src/os/posix/src/os-impl-console.c @@ -34,6 +34,7 @@ #include "os-shared-idmap.h" #include "os-shared-printf.h" +#include "os-shared-common.h" /* * By default the console output is always asynchronous @@ -96,7 +97,9 @@ static void *OS_ConsoleTask_Entry(void *arg) if (OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_CONSOLE, local_arg.id, &token) == OS_SUCCESS) { local = OS_OBJECT_TABLE_GET(OS_impl_console_table, token); - while (true) + + /* Loop forever (unless shutdown is set) */ + while (OS_SharedGlobalVars.ShutdownFlag != OS_SHUTDOWN_MAGIC_NUMBER) { OS_ConsoleOutput_Impl(&token); sem_wait(&local->data_sem); diff --git a/src/os/rtems/src/os-impl-console.c b/src/os/rtems/src/os-impl-console.c index ba0f2534a..7aa2622e3 100644 --- a/src/os/rtems/src/os-impl-console.c +++ b/src/os/rtems/src/os-impl-console.c @@ -38,6 +38,7 @@ #include "os-rtems.h" #include "os-shared-printf.h" #include "os-shared-idmap.h" +#include "os-shared-common.h" /**************************************************************************************** DEFINES @@ -120,7 +121,9 @@ static void OS_ConsoleTask_Entry(rtems_task_argument arg) OS_SUCCESS) { local = OS_OBJECT_TABLE_GET(OS_impl_console_table, token); - while (true) + + /* Loop forever (unless shutdown is set) */ + while (OS_SharedGlobalVars.ShutdownFlag != OS_SHUTDOWN_MAGIC_NUMBER) { OS_ConsoleOutput_Impl(&token); rtems_semaphore_obtain(local->data_sem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); diff --git a/src/os/vxworks/src/os-impl-console.c b/src/os/vxworks/src/os-impl-console.c index 0a8bbe886..f5d44dc69 100644 --- a/src/os/vxworks/src/os-impl-console.c +++ b/src/os/vxworks/src/os-impl-console.c @@ -33,6 +33,7 @@ #include "os-shared-printf.h" #include "os-shared-idmap.h" +#include "os-shared-common.h" /**************************************************************************************** DEFINES @@ -104,7 +105,9 @@ int OS_VxWorks_ConsoleTask_Entry(int arg) OS_SUCCESS) { local = OS_OBJECT_TABLE_GET(OS_impl_console_table, token); - while (true) + + /* Loop forever (unless shutdown is set) */ + while (OS_SharedGlobalVars.ShutdownFlag != OS_SHUTDOWN_MAGIC_NUMBER) { OS_ConsoleOutput_Impl(&token); if (semTake(local->datasem, WAIT_FOREVER) == ERROR) From 52124890af1b156363d4d4260826cc22ecf38f9f Mon Sep 17 00:00:00 2001 From: Gerardo E Cruz-Ortiz <59618057+astrogeco@users.noreply.github.com> Date: Wed, 9 Dec 2020 14:51:38 -0500 Subject: [PATCH 11/11] Bump to v5.1.0-rc1+dev109 --- README.md | 10 ++++++++++ src/os/inc/osapi-version.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8be71b9c4..bd682fb32 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,16 @@ The autogenerated OSAL user's guide can be viewed at + + ### Development Build: 5.1.0-rc1+dev91 - Rename `UT_SetForceFail` to `UT_SetDefaultReturnValue` since some functions that retain more than 1 value are not necessarily failing diff --git a/src/os/inc/osapi-version.h b/src/os/inc/osapi-version.h index 66d55dab0..885439130 100644 --- a/src/os/inc/osapi-version.h +++ b/src/os/inc/osapi-version.h @@ -30,7 +30,7 @@ /* * Development Build Macro Definitions */ -#define OS_BUILD_NUMBER 91 +#define OS_BUILD_NUMBER 109 #define OS_BUILD_BASELINE "v5.1.0-rc1" /*