Skip to content

Commit

Permalink
Fix nasa#437, add new API for obtaining exception task ID
Browse files Browse the repository at this point in the history
Deprecate the OStask_ID field within the property structure.

Replace with a new API to perform a task ID reverse-lookup
based on an abstract data object (the system task ID).
  • Loading branch information
jphickey committed Apr 30, 2020
1 parent f1ea353 commit afb70b0
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 3 deletions.
27 changes: 26 additions & 1 deletion src/os/inc/osapi-os-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ typedef struct
uint32 creator;
uint32 stack_size;
uint32 priority;
uint32 OStask_id;
#ifndef OSAL_OMIT_DEPRECATED
uint32 OStask_id; /**< @deprecated */
#endif
}OS_task_prop_t;

/** @brief OSAL queue properties */
Expand Down Expand Up @@ -480,6 +482,29 @@ int32 OS_TaskGetIdByName (uint32 *task_id, const char *task_name);
* @retval #OS_INVALID_POINTER if the task_prop pointer is NULL
*/
int32 OS_TaskGetInfo (uint32 task_id, OS_task_prop_t *task_prop);


/*-------------------------------------------------------------------------------------*/
/**
* @brief Reverse-lookup the OSAL task ID from an operating system ID
*
* This provides a method by which an external entity may find the OSAL task
* ID corresponding to a system-defined identifier (e.g. TASK_ID, pthread_t, rtems_id, etc).
*
* Normally OSAL does not expose the underlying OS-specific values to the application,
* but in some circumstances, such as exception handling, the OS may provide this information
* directly to handler outside of the normal OSAL API.
*
* @param[out] task_id The buffer where the task id output is stored
* @param[in] sysdata Pointer to the system-provided identification data
* @param[in] sysdata_size Size of the system-provided identification data
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
*/
int32 OS_TaskFindIdBySystemData(uint32 *task_id, const void *sysdata, size_t sysdata_size);


/**@}*/

/** @defgroup OSAPIMsgQueue OSAL Message Queue APIs
Expand Down
39 changes: 38 additions & 1 deletion src/os/posix/src/os-impl-tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,8 @@ uint32 OS_TaskGetId_Impl (void)
*-----------------------------------------------------------------*/
int32 OS_TaskGetInfo_Impl (uint32 task_id, OS_task_prop_t *task_prop)
{
size_t copy_sz;
#ifndef OSAL_OMIT_DEPRECATED
size_t copy_sz;

/*
* NOTE - this is not really valid, as you can't officially
Expand All @@ -783,7 +784,43 @@ int32 OS_TaskGetInfo_Impl (uint32 task_id, OS_task_prop_t *task_prop)
}

memcpy(&task_prop->OStask_id, &OS_impl_task_table[task_id].id, copy_sz);
#endif

return OS_SUCCESS;
} /* end OS_TaskGetInfo_Impl */


/*----------------------------------------------------------------
*
* Function: OS_TaskIdMatchSystemData_Impl
*
* Purpose: Implemented per internal OSAL API
* See prototype for argument/return detail
*
*-----------------------------------------------------------------*/
bool OS_TaskIdMatchSystemData_Impl(void *ref, uint32 local_id, const OS_common_record_t *obj)
{
const pthread_t *target = (const pthread_t *)ref;

return (pthread_equal(*target, OS_impl_task_table[local_id].id) != 0);
}

/*----------------------------------------------------------------
*
* Function: OS_TaskValidateSystemData_Impl
*
* Purpose: Implemented per internal OSAL API
* See prototype for argument/return detail
*
*-----------------------------------------------------------------*/
int32 OS_TaskValidateSystemData_Impl(const void *sysdata, uint32 sysdata_size)
{
if (sysdata == NULL || sysdata_size != sizeof(pthread_t))
{
return OS_INVALID_POINTER;
}
return OS_SUCCESS;
}



33 changes: 33 additions & 0 deletions src/os/rtems/src/os-impl-tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,42 @@ uint32 OS_TaskGetId_Impl (void)
*-----------------------------------------------------------------*/
int32 OS_TaskGetInfo_Impl (uint32 task_id, OS_task_prop_t *task_prop)
{
#ifndef OSAL_OMIT_DEPRECATED
task_prop->OStask_id = (uint32) OS_impl_task_table[task_id].id;
#endif
return OS_SUCCESS;

} /* end OS_TaskGetInfo_Impl */

/*----------------------------------------------------------------
*
* Function: OS_TaskValidateSystemData_Impl
*
* Purpose: Implemented per internal OSAL API
* See prototype for argument/return detail
*
*-----------------------------------------------------------------*/
int32 OS_TaskValidateSystemData_Impl(const void *sysdata, uint32 sysdata_size)
{
if (sysdata == NULL || sysdata_size != sizeof(rtems_id))
{
return OS_INVALID_POINTER;
}
return OS_SUCCESS;
}

/*----------------------------------------------------------------
*
* Function: OS_TaskIdMatchSystemData_Impl
*
* Purpose: Implemented per internal OSAL API
* See prototype for argument/return detail
*
*-----------------------------------------------------------------*/
bool OS_TaskIdMatchSystemData_Impl(void *ref, uint32 local_id, const OS_common_record_t *obj)
{
const rtems_id *target = (const rtems_id *)ref;

return (*target == OS_impl_task_table[local_id].id);
}

21 changes: 21 additions & 0 deletions src/os/shared/inc/os-shared-task.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,26 @@ int32 OS_TaskGetInfo_Impl (uint32 task_id, OS_task_prop_t *task_prop)
int32 OS_TaskRegister_Impl (uint32 global_task_id);


/*----------------------------------------------------------------
Function: OS_TaskIdMatchSystemData_Impl
Purpose: A helper "match" function to find an OSAL task ID based on system ID
Compatible with the "OS_ObjectIdFindBySearch" routine
------------------------------------------------------------------*/
bool OS_TaskIdMatchSystemData_Impl(void *ref, uint32 local_id, const OS_common_record_t *obj);

/*----------------------------------------------------------------
Function: OS_TaskValidateSystemData_Impl
Purpose: Checks that the supplied sysdata pointer and sysdata_size are
compatible/reasonable for the underlying OS.
------------------------------------------------------------------*/
int32 OS_TaskValidateSystemData_Impl(const void *sysdata, uint32 sysdata_size);


#endif /* INCLUDE_OS_SHARED_TASK_H_ */

38 changes: 38 additions & 0 deletions src/os/shared/src/osapi-task.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,3 +512,41 @@ int32 OS_TaskInstallDeleteHandler(osal_task_entry function_pointer)

return return_code;
} /* end OS_TaskInstallDeleteHandler */

/*----------------------------------------------------------------
*
* Function: OS_TaskFindIdBySystemData
*
* Purpose: Implemented per public OSAL API
* See description in API and header file for detail
*
*-----------------------------------------------------------------*/
int32 OS_TaskFindIdBySystemData(uint32 *task_id, const void *sysdata, size_t sysdata_size)
{
int32 return_code;
OS_common_record_t *record;

/* Check parameters */
if (task_id == NULL)
{
return OS_INVALID_POINTER;
}

/* The "sysdata" and "sysdata_size" must be passed to the underlying impl for validation */
return_code = OS_TaskValidateSystemData_Impl(sysdata, sysdata_size);
if (return_code != OS_SUCCESS)
{
return return_code;
}

return_code = OS_ObjectIdGetBySearch(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, OS_TaskIdMatchSystemData_Impl, (void*)sysdata, &record);
if (return_code == OS_SUCCESS)
{
*task_id = record->active_id;
OS_Unlock_Global_Impl(LOCAL_OBJID_TYPE);
}

return return_code;
} /* end OS_TaskFindIdBySystemData */


36 changes: 36 additions & 0 deletions src/os/vxworks/src/os-impl-tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ uint32 OS_TaskGetId_Impl (void)
*-----------------------------------------------------------------*/
int32 OS_TaskGetInfo_Impl (uint32 task_id, OS_task_prop_t *task_prop)
{
#ifndef OSAL_OMIT_DEPRECATED
union
{
TASK_ID vxid;
Expand All @@ -434,8 +435,43 @@ int32 OS_TaskGetInfo_Impl (uint32 task_id, OS_task_prop_t *task_prop)
*/
u.vxid = OS_impl_task_table[task_id].vxid;
task_prop->OStask_id = u.value;
#endif

return OS_SUCCESS;

} /* end OS_TaskGetInfo_Impl */

/*----------------------------------------------------------------
*
* Function: OS_TaskValidateSystemData_Impl
*
* Purpose: Implemented per internal OSAL API
* See prototype for argument/return detail
*
*-----------------------------------------------------------------*/
int32 OS_TaskValidateSystemData_Impl(const void *sysdata, uint32 sysdata_size)
{
if (sysdata == NULL || sysdata_size != sizeof(TASK_ID))
{
return OS_INVALID_POINTER;
}
return OS_SUCCESS;
}

/*----------------------------------------------------------------
*
* Function: OS_TaskIdMatchSystemData_Impl
*
* Purpose: Implemented per internal OSAL API
* See prototype for argument/return detail
*
*-----------------------------------------------------------------*/
bool OS_TaskIdMatchSystemData_Impl(void *ref, uint32 local_id, const OS_common_record_t *obj)
{
const TASK_ID *target = (const TASK_ID *)ref;

return (*target == OS_impl_task_table[local_id].vxid);
}



7 changes: 7 additions & 0 deletions src/unit-test-coverage/ut-stubs/src/osapi-task-impl-stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,10 @@ uint32 OS_TaskGetId_Impl (void)
UT_DEFAULT_STUB(OS_TaskGetInfo_Impl,(uint32 task_id, OS_task_prop_t *task_prop))
UT_DEFAULT_STUB(OS_TaskRegister_Impl,(uint32 global_task_id))

bool OS_TaskIdMatchSystemData_Impl(void *ref, uint32 local_id, const OS_common_record_t *obj)
{
return UT_DEFAULT_IMPL(OS_TaskIdMatchSystemData_Impl);
}

UT_DEFAULT_STUB(OS_TaskValidateSystemData_Impl,(const void *sysdata, uint32 sysdata_size))

1 change: 0 additions & 1 deletion src/ut-stubs/osapi-utstub-task.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ int32 OS_TaskGetInfo(uint32 task_id, OS_task_prop_t *task_prop)
{
task_prop->creator = 1;
UT_FIXUP_ID(task_prop->creator, UT_OBJTYPE_TASK);
task_prop->OStask_id = task_id & 0xFFFF;
task_prop->stack_size = 100;
task_prop->priority = 150;
strncpy(task_prop->name, "UnitTest", OS_MAX_API_NAME - 1);
Expand Down

0 comments on commit afb70b0

Please sign in to comment.