Skip to content

Commit

Permalink
Add assert check for NULL TCB handle (#1177)
Browse files Browse the repository at this point in the history
Co-authored-by: ActoryOu <[email protected]>
  • Loading branch information
kar-rahul-aws and ActoryOu authored Nov 2, 2024
1 parent a081ba8 commit 7d76dce
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -2203,6 +2203,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
/* If null is passed in here then it is the calling task that is
* being deleted. */
pxTCB = prvGetTCBFromHandle( xTaskToDelete );
configASSERT( pxTCB != NULL );

/* Remove task from the ready/delayed list. */
if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )
Expand Down Expand Up @@ -2495,7 +2496,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,

traceENTER_eTaskGetState( xTask );

configASSERT( pxTCB );
configASSERT( pxTCB != NULL );

#if ( configNUMBER_OF_CORES == 1 )
if( pxTCB == pxCurrentTCB )
Expand Down Expand Up @@ -2628,6 +2629,8 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
/* If null is passed in here then it is the priority of the task
* that called uxTaskPriorityGet() that is being queried. */
pxTCB = prvGetTCBFromHandle( xTask );
configASSERT( pxTCB != NULL );

uxReturn = pxTCB->uxPriority;
}
portBASE_TYPE_EXIT_CRITICAL();
Expand Down Expand Up @@ -2676,6 +2679,8 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
/* If null is passed in here then it is the priority of the calling
* task that is being queried. */
pxTCB = prvGetTCBFromHandle( xTask );
configASSERT( pxTCB != NULL );

uxReturn = pxTCB->uxPriority;
}
taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus );
Expand All @@ -2702,6 +2707,8 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
/* If null is passed in here then it is the base priority of the task
* that called uxTaskBasePriorityGet() that is being queried. */
pxTCB = prvGetTCBFromHandle( xTask );
configASSERT( pxTCB != NULL );

uxReturn = pxTCB->uxBasePriority;
}
portBASE_TYPE_EXIT_CRITICAL();
Expand Down Expand Up @@ -2750,6 +2757,8 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
/* If null is passed in here then it is the base priority of the calling
* task that is being queried. */
pxTCB = prvGetTCBFromHandle( xTask );
configASSERT( pxTCB != NULL );

uxReturn = pxTCB->uxBasePriority;
}
taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus );
Expand Down Expand Up @@ -2794,6 +2803,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
/* If null is passed in here then it is the priority of the calling
* task that is being changed. */
pxTCB = prvGetTCBFromHandle( xTask );
configASSERT( pxTCB != NULL );

traceTASK_PRIORITY_SET( pxTCB, uxNewPriority );

Expand Down Expand Up @@ -2988,6 +2998,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
taskENTER_CRITICAL();
{
pxTCB = prvGetTCBFromHandle( xTask );
configASSERT( pxTCB != NULL );

pxTCB->uxCoreAffinityMask = uxCoreAffinityMask;

Expand Down Expand Up @@ -3043,6 +3054,8 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
portBASE_TYPE_ENTER_CRITICAL();
{
pxTCB = prvGetTCBFromHandle( xTask );
configASSERT( pxTCB != NULL );

uxCoreAffinityMask = pxTCB->uxCoreAffinityMask;
}
portBASE_TYPE_EXIT_CRITICAL();
Expand All @@ -3066,6 +3079,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
taskENTER_CRITICAL();
{
pxTCB = prvGetTCBFromHandle( xTask );
configASSERT( pxTCB != NULL );

pxTCB->xPreemptionDisable = pdTRUE;
}
Expand All @@ -3089,6 +3103,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
taskENTER_CRITICAL();
{
pxTCB = prvGetTCBFromHandle( xTask );
configASSERT( pxTCB != NULL );

pxTCB->xPreemptionDisable = pdFALSE;

Expand Down Expand Up @@ -3122,6 +3137,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
/* If null is passed in here then it is the running task that is
* being suspended. */
pxTCB = prvGetTCBFromHandle( xTaskToSuspend );
configASSERT( pxTCB != NULL );

traceTASK_SUSPEND( pxTCB );

Expand Down Expand Up @@ -4194,7 +4210,7 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery )
/* If null is passed in here then the name of the calling task is being
* queried. */
pxTCB = prvGetTCBFromHandle( xTaskToQuery );
configASSERT( pxTCB );
configASSERT( pxTCB != NULL );

traceRETURN_pcTaskGetName( &( pxTCB->pcTaskName[ 0 ] ) );

Expand Down Expand Up @@ -4357,6 +4373,7 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery )
configASSERT( ppxTaskBuffer != NULL );

pxTCB = prvGetTCBFromHandle( xTask );
configASSERT( pxTCB != NULL );

#if ( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE == 1 )
{
Expand Down Expand Up @@ -4596,7 +4613,7 @@ BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp )

traceENTER_xTaskAbortDelay( xTask );

configASSERT( pxTCB );
configASSERT( pxTCB != NULL );

vTaskSuspendAll();
{
Expand Down Expand Up @@ -4978,6 +4995,7 @@ BaseType_t xTaskIncrementTick( void )

/* If xTask is NULL then set the calling task's hook. */
pxTCB = prvGetTCBFromHandle( xTask );
configASSERT( pxTCB != NULL );

/* Save the hook function in the TCB. A critical section is required as
* the value can be accessed from an interrupt. */
Expand Down Expand Up @@ -5007,6 +5025,7 @@ BaseType_t xTaskIncrementTick( void )

/* If xTask is NULL then set the calling task's hook. */
pxTCB = prvGetTCBFromHandle( xTask );
configASSERT( pxTCB != NULL );

/* Save the hook function in the TCB. A critical section is required as
* the value can be accessed from an interrupt. */
Expand Down Expand Up @@ -5984,6 +6003,8 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
( xIndex < ( BaseType_t ) configNUM_THREAD_LOCAL_STORAGE_POINTERS ) )
{
pxTCB = prvGetTCBFromHandle( xTaskToQuery );
configASSERT( pxTCB != NULL );

pvReturn = pxTCB->pvThreadLocalStoragePointers[ xIndex ];
}
else
Expand Down Expand Up @@ -6011,6 +6032,7 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
/* If null is passed in here then we are modifying the MPU settings of
* the calling task. */
pxTCB = prvGetTCBFromHandle( xTaskToModify );
configASSERT( pxTCB != NULL );

vPortStoreTaskMPUSettings( &( pxTCB->xMPUSettings ), pxRegions, NULL, 0 );

Expand Down Expand Up @@ -6141,6 +6163,7 @@ static void prvCheckTasksWaitingTermination( void )

/* xTask is NULL then get the state of the calling task. */
pxTCB = prvGetTCBFromHandle( xTask );
configASSERT( pxTCB != NULL );

pxTaskStatus->xHandle = pxTCB;
pxTaskStatus->pcTaskName = ( const char * ) &( pxTCB->pcTaskName[ 0 ] );
Expand Down Expand Up @@ -6357,6 +6380,7 @@ static void prvCheckTasksWaitingTermination( void )
* type. */

pxTCB = prvGetTCBFromHandle( xTask );
configASSERT( pxTCB != NULL );

#if portSTACK_GROWTH < 0
{
Expand Down Expand Up @@ -6389,6 +6413,7 @@ static void prvCheckTasksWaitingTermination( void )
traceENTER_uxTaskGetStackHighWaterMark( xTask );

pxTCB = prvGetTCBFromHandle( xTask );
configASSERT( pxTCB != NULL );

#if portSTACK_GROWTH < 0
{
Expand Down Expand Up @@ -8288,6 +8313,7 @@ TickType_t uxTaskResetEventItemValue( void )
/* If null is passed in here then it is the calling task that is having
* its notification state cleared. */
pxTCB = prvGetTCBFromHandle( xTask );
configASSERT( pxTCB != NULL );

taskENTER_CRITICAL();
{
Expand Down Expand Up @@ -8327,6 +8353,7 @@ TickType_t uxTaskResetEventItemValue( void )
/* If null is passed in here then it is the calling task that is having
* its notification state cleared. */
pxTCB = prvGetTCBFromHandle( xTask );
configASSERT( pxTCB != NULL );

taskENTER_CRITICAL();
{
Expand Down Expand Up @@ -8354,6 +8381,7 @@ TickType_t uxTaskResetEventItemValue( void )
traceENTER_ulTaskGetRunTimeCounter( xTask );

pxTCB = prvGetTCBFromHandle( xTask );
configASSERT( pxTCB != NULL );

traceRETURN_ulTaskGetRunTimeCounter( pxTCB->ulRunTimeCounter );

Expand Down Expand Up @@ -8381,6 +8409,8 @@ TickType_t uxTaskResetEventItemValue( void )
if( ulTotalTime > ( configRUN_TIME_COUNTER_TYPE ) 0 )
{
pxTCB = prvGetTCBFromHandle( xTask );
configASSERT( pxTCB != NULL );

ulReturn = pxTCB->ulRunTimeCounter / ulTotalTime;
}
else
Expand Down Expand Up @@ -8584,6 +8614,7 @@ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait,
traceENTER_xTaskGetMPUSettings( xTask );

pxTCB = prvGetTCBFromHandle( xTask );
configASSERT( pxTCB != NULL );

traceRETURN_xTaskGetMPUSettings( &( pxTCB->xMPUSettings ) );

Expand Down

0 comments on commit 7d76dce

Please sign in to comment.