From 5f4ff9867577eeb60067df05a446f6e384327b7c Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 25 Jun 2021 10:59:07 -0400 Subject: [PATCH] Fix #1084, root task ID on RTEMS Ensures that OS_GetTaskId_Impl() returns OS_OBJECT_ID_UNDEFINED if called from the root task - as this does not have an OSAL task ID. --- src/os/rtems/src/os-impl-tasks.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/os/rtems/src/os-impl-tasks.c b/src/os/rtems/src/os-impl-tasks.c index f1fa62b4b..675ac50a5 100644 --- a/src/os/rtems/src/os-impl-tasks.c +++ b/src/os/rtems/src/os-impl-tasks.c @@ -336,11 +336,20 @@ osal_id_t OS_TaskGetId_Impl(void) task_self = rtems_task_self(); /* When the task was created the OSAL ID was used as the "classic name", - * which gives us an easy way to map it back again */ + * which gives us an easy way to map it back again. However, if this + * API is invoked from a non-OSAL task (i.e. the "root" task) then it is + * possible that rtems_object_get_classic_name() succeeds but the result + * is not actually an OSAL task ID. */ status = rtems_object_get_classic_name(task_self, &self_name); if (status == RTEMS_SUCCESSFUL) { global_task_id = OS_ObjectIdFromInteger(self_name); + + if (OS_ObjectIdToType_Impl(global_task_id) != OS_OBJECT_TYPE_OS_TASK) + { + /* not an OSAL task */ + global_task_id = OS_OBJECT_ID_UNDEFINED; + } } else {