From 31dd1e39cbe051213e096518d6751d483f598e3c Mon Sep 17 00:00:00 2001 From: Felix van Oost Date: Thu, 19 Dec 2024 03:50:43 -0500 Subject: [PATCH 1/7] Pass core ID to critical nesting count macros (#1206) * Pass core ID to CRITICAL_NESTING_COUNT macros * Match existing data type for xCoreID * Get core ID when interrupts are disabled * Implement get core ID with interrupt disabled * Get core ID inline within vTaskSuspendAll() to resolve compiler warning * Fix formatting check Signed-off-by: Gaurav Aggarwal --------- Signed-off-by: Gaurav Aggarwal Co-authored-by: Ching-Hsin,Lee Co-authored-by: Gaurav Aggarwal Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> --- .../ThirdParty/GCC/RP2040/include/portmacro.h | 8 +- tasks.c | 142 ++++++++++-------- 2 files changed, 85 insertions(+), 65 deletions(-) diff --git a/portable/ThirdParty/GCC/RP2040/include/portmacro.h b/portable/ThirdParty/GCC/RP2040/include/portmacro.h index 14f58940c69..ed9dbade09e 100644 --- a/portable/ThirdParty/GCC/RP2040/include/portmacro.h +++ b/portable/ThirdParty/GCC/RP2040/include/portmacro.h @@ -158,10 +158,10 @@ void vYieldCore( int xCoreID ); #define portCRITICAL_NESTING_IN_TCB 0 extern UBaseType_t uxCriticalNestings[ configNUMBER_OF_CORES ]; -#define portGET_CRITICAL_NESTING_COUNT() ( uxCriticalNestings[ portGET_CORE_ID() ] ) -#define portSET_CRITICAL_NESTING_COUNT( x ) ( uxCriticalNestings[ portGET_CORE_ID() ] = ( x ) ) -#define portINCREMENT_CRITICAL_NESTING_COUNT() ( uxCriticalNestings[ portGET_CORE_ID() ]++ ) -#define portDECREMENT_CRITICAL_NESTING_COUNT() ( uxCriticalNestings[ portGET_CORE_ID() ]-- ) +#define portGET_CRITICAL_NESTING_COUNT( xCoreID ) ( uxCriticalNestings[ ( xCoreID ) ] ) +#define portSET_CRITICAL_NESTING_COUNT( xCoreID, x ) ( uxCriticalNestings[ ( xCoreID ) ] = ( x ) ) +#define portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( uxCriticalNestings[ ( xCoreID ) ]++ ) +#define portDECREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( uxCriticalNestings[ ( xCoreID ) ]-- ) /*-----------------------------------------------------------*/ diff --git a/tasks.c b/tasks.c index 22e11f0fb21..7d9c8758520 100644 --- a/tasks.c +++ b/tasks.c @@ -317,10 +317,10 @@ #define taskATTRIBUTE_IS_IDLE ( UBaseType_t ) ( 1U << 0U ) #if ( ( configNUMBER_OF_CORES > 1 ) && ( portCRITICAL_NESTING_IN_TCB == 1 ) ) - #define portGET_CRITICAL_NESTING_COUNT() ( pxCurrentTCBs[ portGET_CORE_ID() ]->uxCriticalNesting ) - #define portSET_CRITICAL_NESTING_COUNT( x ) ( pxCurrentTCBs[ portGET_CORE_ID() ]->uxCriticalNesting = ( x ) ) - #define portINCREMENT_CRITICAL_NESTING_COUNT() ( pxCurrentTCBs[ portGET_CORE_ID() ]->uxCriticalNesting++ ) - #define portDECREMENT_CRITICAL_NESTING_COUNT() ( pxCurrentTCBs[ portGET_CORE_ID() ]->uxCriticalNesting-- ) + #define portGET_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ ( xCoreID ) ]->uxCriticalNesting ) + #define portSET_CRITICAL_NESTING_COUNT( xCoreID, x ) ( pxCurrentTCBs[ ( xCoreID ) ]->uxCriticalNesting = ( x ) ) + #define portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ ( xCoreID ) ]->uxCriticalNesting++ ) + #define portDECREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ ( xCoreID ) ]->uxCriticalNesting-- ) #endif /* #if ( ( configNUMBER_OF_CORES > 1 ) && ( portCRITICAL_NESTING_IN_TCB == 1 ) ) */ #define taskBITS_PER_BYTE ( ( size_t ) 8 ) @@ -807,13 +807,14 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; { UBaseType_t uxPrevCriticalNesting; const TCB_t * pxThisTCB; + BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); /* This must only be called from within a task. */ portASSERT_IF_IN_ISR(); /* This function is always called with interrupts disabled * so this is safe. */ - pxThisTCB = pxCurrentTCBs[ portGET_CORE_ID() ]; + pxThisTCB = pxCurrentTCBs[ xCoreID ]; while( pxThisTCB->xTaskRunState == taskTASK_SCHEDULED_TO_YIELD ) { @@ -825,11 +826,11 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; * the suspension and critical nesting counts, as well as release * and reacquire the correct locks. And then, do it all over again * if our state changed again during the reacquisition. */ - uxPrevCriticalNesting = portGET_CRITICAL_NESTING_COUNT(); + uxPrevCriticalNesting = portGET_CRITICAL_NESTING_COUNT( xCoreID ); if( uxPrevCriticalNesting > 0U ) { - portSET_CRITICAL_NESTING_COUNT( 0U ); + portSET_CRITICAL_NESTING_COUNT( xCoreID, 0U ); portRELEASE_ISR_LOCK(); } else @@ -854,8 +855,9 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; portDISABLE_INTERRUPTS(); portGET_TASK_LOCK(); portGET_ISR_LOCK(); + xCoreID = ( BaseType_t ) portGET_CORE_ID(); - portSET_CRITICAL_NESTING_COUNT( uxPrevCriticalNesting ); + portSET_CRITICAL_NESTING_COUNT( xCoreID, uxPrevCriticalNesting ); if( uxPrevCriticalNesting == 0U ) { @@ -874,13 +876,14 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; BaseType_t xCurrentCoreTaskPriority; BaseType_t xLowestPriorityCore = ( BaseType_t ) -1; BaseType_t xCoreID; + const BaseType_t xCurrentCoreID = portGET_CORE_ID(); #if ( configRUN_MULTIPLE_PRIORITIES == 0 ) BaseType_t xYieldCount = 0; #endif /* #if ( configRUN_MULTIPLE_PRIORITIES == 0 ) */ /* This must be called from a critical section. */ - configASSERT( portGET_CRITICAL_NESTING_COUNT() > 0U ); + configASSERT( portGET_CRITICAL_NESTING_COUNT( xCurrentCoreID ) > 0U ); #if ( configRUN_MULTIPLE_PRIORITIES == 0 ) @@ -969,11 +972,11 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; #if ( configRUN_MULTIPLE_PRIORITIES == 0 ) /* Verify that the calling core always yields to higher priority tasks. */ - if( ( ( pxCurrentTCBs[ portGET_CORE_ID() ]->uxTaskAttributes & taskATTRIBUTE_IS_IDLE ) == 0U ) && - ( pxTCB->uxPriority > pxCurrentTCBs[ portGET_CORE_ID() ]->uxPriority ) ) + if( ( ( pxCurrentTCBs[ xCurrentCoreID ]->uxTaskAttributes & taskATTRIBUTE_IS_IDLE ) == 0U ) && + ( pxTCB->uxPriority > pxCurrentTCBs[ xCurrentCoreID ]->uxPriority ) ) { - configASSERT( ( xYieldPendings[ portGET_CORE_ID() ] == pdTRUE ) || - ( taskTASK_IS_RUNNING( pxCurrentTCBs[ portGET_CORE_ID() ] ) == pdFALSE ) ); + configASSERT( ( xYieldPendings[ xCurrentCoreID ] == pdTRUE ) || + ( taskTASK_IS_RUNNING( pxCurrentTCBs[ xCurrentCoreID ] ) == pdFALSE ) ); } #endif } @@ -3880,7 +3883,7 @@ void vTaskSuspendAll( void ) ulState = portSET_INTERRUPT_MASK(); /* This must never be called from inside a critical section. */ - configASSERT( portGET_CRITICAL_NESTING_COUNT() == 0 ); + configASSERT( portGET_CRITICAL_NESTING_COUNT( portGET_CORE_ID() ) == 0 ); /* portSOFTWARE_BARRIER() is only implemented for emulated/simulated ports that * do not otherwise exhibit real time behaviour. */ @@ -4003,8 +4006,7 @@ BaseType_t xTaskResumeAll( void ) * tasks from this list into their appropriate ready list. */ taskENTER_CRITICAL(); { - BaseType_t xCoreID; - xCoreID = ( BaseType_t ) portGET_CORE_ID(); + const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); /* If uxSchedulerSuspended is zero then this function does not match a * previous call to vTaskSuspendAll(). */ @@ -5187,7 +5189,7 @@ BaseType_t xTaskIncrementTick( void ) /* vTaskSwitchContext() must never be called from within a critical section. * This is not necessarily true for single core FreeRTOS, but it is for this * SMP port. */ - configASSERT( portGET_CRITICAL_NESTING_COUNT() == 0 ); + configASSERT( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0 ); if( uxSchedulerSuspended != ( UBaseType_t ) 0U ) { @@ -6937,16 +6939,24 @@ static void prvResetNextTaskUnblockTime( void ) */ void vTaskYieldWithinAPI( void ) { + UBaseType_t ulState; + traceENTER_vTaskYieldWithinAPI(); - if( portGET_CRITICAL_NESTING_COUNT() == 0U ) - { - portYIELD(); - } - else + ulState = portSET_INTERRUPT_MASK(); { - xYieldPendings[ portGET_CORE_ID() ] = pdTRUE; + const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); + + if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) + { + portYIELD(); + } + else + { + xYieldPendings[ xCoreID ] = pdTRUE; + } } + portCLEAR_INTERRUPT_MASK( ulState ); traceRETURN_vTaskYieldWithinAPI(); } @@ -6995,40 +7005,43 @@ static void prvResetNextTaskUnblockTime( void ) traceENTER_vTaskEnterCritical(); portDISABLE_INTERRUPTS(); - - if( xSchedulerRunning != pdFALSE ) { - if( portGET_CRITICAL_NESTING_COUNT() == 0U ) - { - portGET_TASK_LOCK(); - portGET_ISR_LOCK(); - } - - portINCREMENT_CRITICAL_NESTING_COUNT(); + const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); - /* This is not the interrupt safe version of the enter critical - * function so assert() if it is being called from an interrupt - * context. Only API functions that end in "FromISR" can be used in an - * interrupt. Only assert if the critical nesting count is 1 to - * protect against recursive calls if the assert function also uses a - * critical section. */ - if( portGET_CRITICAL_NESTING_COUNT() == 1U ) + if( xSchedulerRunning != pdFALSE ) { - portASSERT_IF_IN_ISR(); + if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) + { + portGET_TASK_LOCK(); + portGET_ISR_LOCK(); + } - if( uxSchedulerSuspended == 0U ) + portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ); + + /* This is not the interrupt safe version of the enter critical + * function so assert() if it is being called from an interrupt + * context. Only API functions that end in "FromISR" can be used in an + * interrupt. Only assert if the critical nesting count is 1 to + * protect against recursive calls if the assert function also uses a + * critical section. */ + if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 1U ) { - /* The only time there would be a problem is if this is called - * before a context switch and vTaskExitCritical() is called - * after pxCurrentTCB changes. Therefore this should not be - * used within vTaskSwitchContext(). */ - prvCheckForRunStateChange(); + portASSERT_IF_IN_ISR(); + + if( uxSchedulerSuspended == 0U ) + { + /* The only time there would be a problem is if this is called + * before a context switch and vTaskExitCritical() is called + * after pxCurrentTCB changes. Therefore this should not be + * used within vTaskSwitchContext(). */ + prvCheckForRunStateChange(); + } } } - } - else - { - mtCOVERAGE_TEST_MARKER(); + else + { + mtCOVERAGE_TEST_MARKER(); + } } traceRETURN_vTaskEnterCritical(); @@ -7043,6 +7056,7 @@ static void prvResetNextTaskUnblockTime( void ) UBaseType_t vTaskEnterCriticalFromISR( void ) { UBaseType_t uxSavedInterruptStatus = 0; + const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); traceENTER_vTaskEnterCriticalFromISR(); @@ -7050,12 +7064,12 @@ static void prvResetNextTaskUnblockTime( void ) { uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); - if( portGET_CRITICAL_NESTING_COUNT() == 0U ) + if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) { portGET_ISR_LOCK(); } - portINCREMENT_CRITICAL_NESTING_COUNT(); + portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ); } else { @@ -7119,28 +7133,30 @@ static void prvResetNextTaskUnblockTime( void ) void vTaskExitCritical( void ) { + const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); + traceENTER_vTaskExitCritical(); if( xSchedulerRunning != pdFALSE ) { /* If critical nesting count is zero then this function * does not match a previous call to vTaskEnterCritical(). */ - configASSERT( portGET_CRITICAL_NESTING_COUNT() > 0U ); + configASSERT( portGET_CRITICAL_NESTING_COUNT( xCoreID ) > 0U ); /* This function should not be called in ISR. Use vTaskExitCriticalFromISR * to exit critical section from ISR. */ portASSERT_IF_IN_ISR(); - if( portGET_CRITICAL_NESTING_COUNT() > 0U ) + if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) > 0U ) { - portDECREMENT_CRITICAL_NESTING_COUNT(); + portDECREMENT_CRITICAL_NESTING_COUNT( xCoreID ); - if( portGET_CRITICAL_NESTING_COUNT() == 0U ) + if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) { BaseType_t xYieldCurrentTask; /* Get the xYieldPending stats inside the critical section. */ - xYieldCurrentTask = xYieldPendings[ portGET_CORE_ID() ]; + xYieldCurrentTask = xYieldPendings[ xCoreID ]; portRELEASE_ISR_LOCK(); portRELEASE_TASK_LOCK(); @@ -7180,19 +7196,23 @@ static void prvResetNextTaskUnblockTime( void ) void vTaskExitCriticalFromISR( UBaseType_t uxSavedInterruptStatus ) { + BaseType_t xCoreID; + traceENTER_vTaskExitCriticalFromISR( uxSavedInterruptStatus ); if( xSchedulerRunning != pdFALSE ) { + xCoreID = ( BaseType_t ) portGET_CORE_ID(); + /* If critical nesting count is zero then this function * does not match a previous call to vTaskEnterCritical(). */ - configASSERT( portGET_CRITICAL_NESTING_COUNT() > 0U ); + configASSERT( portGET_CRITICAL_NESTING_COUNT( xCoreID ) > 0U ); - if( portGET_CRITICAL_NESTING_COUNT() > 0U ) + if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) > 0U ) { - portDECREMENT_CRITICAL_NESTING_COUNT(); + portDECREMENT_CRITICAL_NESTING_COUNT( xCoreID ); - if( portGET_CRITICAL_NESTING_COUNT() == 0U ) + if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) { portRELEASE_ISR_LOCK(); portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); From cc31510088d7f7472d57967ed0011b5303dffafa Mon Sep 17 00:00:00 2001 From: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> Date: Fri, 20 Dec 2024 00:08:52 +0530 Subject: [PATCH 2/7] Remove unused config parameters (#1211) These were reported here - https://github.com/FreeRTOS/FreeRTOS-Kernel/issues/1210. Signed-off-by: Gaurav Aggarwal --- examples/coverity/FreeRTOSConfig.h | 2 -- examples/template_configuration/FreeRTOSConfig.h | 2 -- 2 files changed, 4 deletions(-) diff --git a/examples/coverity/FreeRTOSConfig.h b/examples/coverity/FreeRTOSConfig.h index 06b0f9a289e..5feaa40de41 100644 --- a/examples/coverity/FreeRTOSConfig.h +++ b/examples/coverity/FreeRTOSConfig.h @@ -118,7 +118,6 @@ #define INCLUDE_uxTaskPriorityGet 1 #define INCLUDE_vTaskDelete 1 #define INCLUDE_vTaskSuspend 1 -#define INCLUDE_xResumeFromISR 1 #define INCLUDE_vTaskDelayUntil 1 #define INCLUDE_vTaskDelay 1 #define INCLUDE_xTaskGetSchedulerState 1 @@ -126,7 +125,6 @@ #define INCLUDE_uxTaskGetStackHighWaterMark 1 #define INCLUDE_xTaskGetIdleTaskHandle 1 #define INCLUDE_eTaskGetState 1 -#define INCLUDE_xEventGroupSetBitFromISR 1 #define INCLUDE_xTimerPendFunctionCall 1 #define INCLUDE_xTaskAbortDelay 1 #define INCLUDE_xTaskGetHandle 1 diff --git a/examples/template_configuration/FreeRTOSConfig.h b/examples/template_configuration/FreeRTOSConfig.h index 8c5e5306649..5684e3c39ea 100644 --- a/examples/template_configuration/FreeRTOSConfig.h +++ b/examples/template_configuration/FreeRTOSConfig.h @@ -650,7 +650,6 @@ #define INCLUDE_uxTaskPriorityGet 1 #define INCLUDE_vTaskDelete 1 #define INCLUDE_vTaskSuspend 1 -#define INCLUDE_xResumeFromISR 1 #define INCLUDE_vTaskDelayUntil 1 #define INCLUDE_vTaskDelay 1 #define INCLUDE_xTaskGetSchedulerState 1 @@ -658,7 +657,6 @@ #define INCLUDE_uxTaskGetStackHighWaterMark 0 #define INCLUDE_xTaskGetIdleTaskHandle 0 #define INCLUDE_eTaskGetState 0 -#define INCLUDE_xEventGroupSetBitFromISR 1 #define INCLUDE_xTimerPendFunctionCall 0 #define INCLUDE_xTaskAbortDelay 0 #define INCLUDE_xTaskGetHandle 0 From f31787d35d5614620fc6fefa6c12df2583612fcf Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty <91244425+sudeep-mohanty@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:13:04 +0530 Subject: [PATCH 3/7] fix(freertos): Limit idle task name length copy operation and ensure null-termination of the idle task name string (#1203) * fix(freertos): Limit idle task name copy operation and ensure null termination This commit: - Limits the idle task name length copy operation to prevent Out-of-bounds memory access warnings from static code analyzers. - Fixes a bug where in the idle task name could be non null-terminated string for SMP configuration. Signed-off-by: Sudeep Mohanty --- tasks.c | 51 ++++++++++++++++++--------------------------------- 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/tasks.c b/tasks.c index 7d9c8758520..f6af37bab8a 100644 --- a/tasks.c +++ b/tasks.c @@ -3524,27 +3524,28 @@ static BaseType_t prvCreateIdleTasks( void ) { BaseType_t xReturn = pdPASS; BaseType_t xCoreID; - char cIdleName[ configMAX_TASK_NAME_LEN ]; + char cIdleName[ configMAX_TASK_NAME_LEN ] = { 0 }; TaskFunction_t pxIdleTaskFunction = NULL; BaseType_t xIdleTaskNameIndex; + BaseType_t xIdleNameLen; + BaseType_t xCopyLen; - for( xIdleTaskNameIndex = ( BaseType_t ) 0; xIdleTaskNameIndex < ( BaseType_t ) configMAX_TASK_NAME_LEN; xIdleTaskNameIndex++ ) + configASSERT( ( configIDLE_TASK_NAME != NULL ) && ( configMAX_TASK_NAME_LEN > 3 ) ); + + /* The length of the idle task name is limited to the minimum of the length + * of configIDLE_TASK_NAME and configMAX_TASK_NAME_LEN - 2, keeping space + * for the core ID suffix and the null-terminator. */ + xIdleNameLen = strlen( configIDLE_TASK_NAME ); + xCopyLen = xIdleNameLen < ( configMAX_TASK_NAME_LEN - 2 ) ? xIdleNameLen : ( configMAX_TASK_NAME_LEN - 2 ); + + for( xIdleTaskNameIndex = ( BaseType_t ) 0; xIdleTaskNameIndex < xCopyLen; xIdleTaskNameIndex++ ) { cIdleName[ xIdleTaskNameIndex ] = configIDLE_TASK_NAME[ xIdleTaskNameIndex ]; - - /* Don't copy all configMAX_TASK_NAME_LEN if the string is shorter than - * configMAX_TASK_NAME_LEN characters just in case the memory after the - * string is not accessible (extremely unlikely). */ - if( cIdleName[ xIdleTaskNameIndex ] == ( char ) 0x00 ) - { - break; - } - else - { - mtCOVERAGE_TEST_MARKER(); - } } + /* Ensure null termination. */ + cIdleName[ xIdleTaskNameIndex ] = '\0'; + /* Add each idle task at the lowest priority. */ for( xCoreID = ( BaseType_t ) 0; xCoreID < ( BaseType_t ) configNUMBER_OF_CORES; xCoreID++ ) { @@ -3573,25 +3574,9 @@ static BaseType_t prvCreateIdleTasks( void ) * only one idle task. */ #if ( configNUMBER_OF_CORES > 1 ) { - /* Append the idle task number to the end of the name if there is space. */ - if( xIdleTaskNameIndex < ( BaseType_t ) configMAX_TASK_NAME_LEN ) - { - cIdleName[ xIdleTaskNameIndex ] = ( char ) ( xCoreID + '0' ); - - /* And append a null character if there is space. */ - if( ( xIdleTaskNameIndex + 1 ) < ( BaseType_t ) configMAX_TASK_NAME_LEN ) - { - cIdleName[ xIdleTaskNameIndex + 1 ] = '\0'; - } - else - { - mtCOVERAGE_TEST_MARKER(); - } - } - else - { - mtCOVERAGE_TEST_MARKER(); - } + /* Append the idle task number to the end of the name. */ + cIdleName[ xIdleTaskNameIndex ] = ( char ) ( xCoreID + '0' ); + cIdleName[ xIdleTaskNameIndex + 1 ] = '\0'; } #endif /* if ( configNUMBER_OF_CORES > 1 ) */ From f63bc2b5ccc8bd9a7804ca5c09609dc03bbbebd7 Mon Sep 17 00:00:00 2001 From: wwhheerree Date: Tue, 24 Dec 2024 19:11:44 +0800 Subject: [PATCH 4/7] Add an example of human readable table generated by vTaskListTasks() to tash.h (#1215) * Add an example of human readable table generated by vTaskListTasks() to task.h --- include/task.h | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/include/task.h b/include/task.h index 0414eb9e241..a25740e3bbd 100644 --- a/include/task.h +++ b/include/task.h @@ -2199,8 +2199,8 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; * Lists all the current tasks, along with their current state and stack * usage high water mark. * - * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or - * suspended ('S'). + * Tasks are reported as running ('X'), blocked ('B'), ready ('R'), deleted ('D') + * or suspended ('S'). * * PLEASE NOTE: * @@ -2208,8 +2208,16 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; * demo applications. Do not consider it to be part of the scheduler. * * vTaskListTasks() calls uxTaskGetSystemState(), then formats part of the - * uxTaskGetSystemState() output into a human readable table that displays task: - * names, states, priority, stack usage and task number. + * uxTaskGetSystemState() output into a human readable table that displays task + * information in the following format: + * Task Name, Task State, Task Priority, Task Stack High Watermak, Task Number. + * + * The following is a sample output: + * Task A X 2 67 2 + * Task B R 1 67 3 + * IDLE R 0 67 5 + * Tmr Svc B 6 137 6 + * * Stack usage specified as the number of unused StackType_t words stack can hold * on top of stack - not the number of bytes. * @@ -2260,8 +2268,8 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; * Lists all the current tasks, along with their current state and stack * usage high water mark. * - * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or - * suspended ('S'). + * Tasks are reported as running ('X'), blocked ('B'), ready ('R'), deleted ('D') + * or suspended ('S'). * * PLEASE NOTE: * @@ -2269,8 +2277,16 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; * demo applications. Do not consider it to be part of the scheduler. * * vTaskList() calls uxTaskGetSystemState(), then formats part of the - * uxTaskGetSystemState() output into a human readable table that displays task: - * names, states, priority, stack usage and task number. + * uxTaskGetSystemState() output into a human readable table that displays task + * information in the following format: + * Task Name, Task State, Task Priority, Task Stack High Watermak, Task Number. + * + * The following is a sample output: + * Task A X 2 67 2 + * Task B R 1 67 3 + * IDLE R 0 67 5 + * Tmr Svc B 6 137 6 + * * Stack usage specified as the number of unused StackType_t words stack can hold * on top of stack - not the number of bytes. * From f05244a8d55b23428c4a8c097d375d12a9d6e30d Mon Sep 17 00:00:00 2001 From: Felix van Oost Date: Mon, 30 Dec 2024 03:58:49 -0500 Subject: [PATCH 5/7] Pass core ID to port lock macros (#1212) Pass core ID to task/ISR lock functions --- include/FreeRTOS.h | 8 +-- portable/CCRH/F1Kx/port.c | 10 ++-- portable/CCRH/F1Kx/portmacro.h | 20 ++++---- .../ThirdParty/GCC/RP2040/include/portmacro.h | 30 ++++++------ .../ThirdParty/xClang/XCOREAI/portmacro.h | 9 ++-- portable/template/portmacro.h | 8 +-- tasks.c | 49 +++++++++++-------- 7 files changed, 71 insertions(+), 63 deletions(-) diff --git a/include/FreeRTOS.h b/include/FreeRTOS.h index 3fecbdd734e..dfccccb404b 100644 --- a/include/FreeRTOS.h +++ b/include/FreeRTOS.h @@ -445,7 +445,7 @@ #ifndef portRELEASE_TASK_LOCK #if ( configNUMBER_OF_CORES == 1 ) - #define portRELEASE_TASK_LOCK() + #define portRELEASE_TASK_LOCK( xCoreID ) #else #error portRELEASE_TASK_LOCK is required in SMP #endif @@ -455,7 +455,7 @@ #ifndef portGET_TASK_LOCK #if ( configNUMBER_OF_CORES == 1 ) - #define portGET_TASK_LOCK() + #define portGET_TASK_LOCK( xCoreID ) #else #error portGET_TASK_LOCK is required in SMP #endif @@ -465,7 +465,7 @@ #ifndef portRELEASE_ISR_LOCK #if ( configNUMBER_OF_CORES == 1 ) - #define portRELEASE_ISR_LOCK() + #define portRELEASE_ISR_LOCK( xCoreID ) #else #error portRELEASE_ISR_LOCK is required in SMP #endif @@ -475,7 +475,7 @@ #ifndef portGET_ISR_LOCK #if ( configNUMBER_OF_CORES == 1 ) - #define portGET_ISR_LOCK() + #define portGET_ISR_LOCK( xCoreID ) #else #error portGET_ISR_LOCK is required in SMP #endif diff --git a/portable/CCRH/F1Kx/port.c b/portable/CCRH/F1Kx/port.c index 0e6116527df..3a43ff418d1 100644 --- a/portable/CCRH/F1Kx/port.c +++ b/portable/CCRH/F1Kx/port.c @@ -258,8 +258,8 @@ void vPortTickISR( void ); * already had lock can acquire lock without waiting. This function could be * call from task and interrupt context, the critical section is called * as in ISR */ - void vPortRecursiveLockAcquire( BaseType_t xFromIsr ); - void vPortRecursiveLockRelease( BaseType_t xFromIsr ); + void vPortRecursiveLockAcquire( BaseType_t xCoreID, BaseType_t xFromIsr ); + void vPortRecursiveLockRelease( BaseType_t xCoreID, BaseType_t xFromIsr ); #endif /* (configNUMBER_OF_CORES > 1) */ @@ -688,10 +688,9 @@ static void prvSetupTimerInterrupt( void ) } /*-----------------------------------------------------------*/ - void vPortRecursiveLockAcquire( BaseType_t xFromIsr ) + void vPortRecursiveLockAcquire( BaseType_t xCoreID, BaseType_t xFromIsr ) { BaseType_t xSavedInterruptStatus; - BaseType_t xCoreID = xPortGET_CORE_ID(); BaseType_t xBitPosition = ( xFromIsr == pdTRUE ); xSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); @@ -705,10 +704,9 @@ static void prvSetupTimerInterrupt( void ) portCLEAR_INTERRUPT_MASK_FROM_ISR( xSavedInterruptStatus ); } - void vPortRecursiveLockRelease( BaseType_t xFromIsr ) + void vPortRecursiveLockRelease( BaseType_t xCoreID, BaseType_t xFromIsr ) { BaseType_t xSavedInterruptStatus; - BaseType_t xCoreID = xPortGET_CORE_ID(); BaseType_t xBitPosition = ( xFromIsr == pdTRUE ); xSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); diff --git a/portable/CCRH/F1Kx/portmacro.h b/portable/CCRH/F1Kx/portmacro.h index 09f9f461450..a665ad23d2a 100644 --- a/portable/CCRH/F1Kx/portmacro.h +++ b/portable/CCRH/F1Kx/portmacro.h @@ -141,18 +141,18 @@ #endif /* if ( configNUMBER_OF_CORES > 1 ) */ #if ( configNUMBER_OF_CORES == 1 ) - #define portGET_ISR_LOCK() - #define portRELEASE_ISR_LOCK() - #define portGET_TASK_LOCK() - #define portRELEASE_TASK_LOCK() + #define portGET_ISR_LOCK( xCoreID ) + #define portRELEASE_ISR_LOCK( xCoreID ) + #define portGET_TASK_LOCK( xCoreID ) + #define portRELEASE_TASK_LOCK( xCoreID ) #else - extern void vPortRecursiveLockAcquire( BaseType_t xFromIsr ); - extern void vPortRecursiveLockRelease( BaseType_t xFromIsr ); + extern void vPortRecursiveLockAcquire( BaseType_t xCoreID, BaseType_t xFromIsr ); + extern void vPortRecursiveLockRelease( BaseType_t xCoreID, BaseType_t xFromIsr ); - #define portGET_ISR_LOCK() vPortRecursiveLockAcquire( pdTRUE ) - #define portRELEASE_ISR_LOCK() vPortRecursiveLockRelease( pdTRUE ) - #define portGET_TASK_LOCK() vPortRecursiveLockAcquire( pdFALSE ) - #define portRELEASE_TASK_LOCK() vPortRecursiveLockRelease( pdFALSE ) + #define portGET_ISR_LOCK( xCoreID ) vPortRecursiveLockAcquire( ( xCoreID ), pdTRUE ) + #define portRELEASE_ISR_LOCK( xCoreID ) vPortRecursiveLockRelease( ( xCoreID ), pdTRUE ) + #define portGET_TASK_LOCK( xCoreID ) vPortRecursiveLockAcquire( ( xCoreID ), pdFALSE ) + #define portRELEASE_TASK_LOCK( xCoreID ) vPortRecursiveLockRelease( ( xCoreID ), pdFALSE ) #endif /* if ( configNUMBER_OF_CORES == 1 ) */ /*-----------------------------------------------------------*/ diff --git a/portable/ThirdParty/GCC/RP2040/include/portmacro.h b/portable/ThirdParty/GCC/RP2040/include/portmacro.h index ed9dbade09e..802470e33f7 100644 --- a/portable/ThirdParty/GCC/RP2040/include/portmacro.h +++ b/portable/ThirdParty/GCC/RP2040/include/portmacro.h @@ -210,8 +210,9 @@ __force_inline static bool spin_try_lock_unsafe(spin_lock_t *lock) { /* Note this is a single method with uxAcquire parameter since we have * static vars, the method is always called with a compile time constant for - * uxAcquire, and the compiler should dothe right thing! */ -static inline void vPortRecursiveLock( uint32_t ulLockNum, + * uxAcquire, and the compiler should do the right thing! */ +static inline void vPortRecursiveLock( BaseType_t xCoreID, + uint32_t ulLockNum, spin_lock_t * pxSpinLock, BaseType_t uxAcquire ) { @@ -219,12 +220,11 @@ static inline void vPortRecursiveLock( uint32_t ulLockNum, static volatile uint8_t ucRecursionCountByLock[ portRTOS_SPINLOCK_COUNT ]; configASSERT( ulLockNum < portRTOS_SPINLOCK_COUNT ); - uint32_t ulCoreNum = get_core_num(); if( uxAcquire ) { if (!spin_try_lock_unsafe(pxSpinLock)) { - if( ucOwnedByCore[ ulCoreNum ][ ulLockNum ] ) + if( ucOwnedByCore[ xCoreID ][ ulLockNum ] ) { configASSERT( ucRecursionCountByLock[ ulLockNum ] != 255u ); ucRecursionCountByLock[ ulLockNum ]++; @@ -234,31 +234,31 @@ static inline void vPortRecursiveLock( uint32_t ulLockNum, } configASSERT( ucRecursionCountByLock[ ulLockNum ] == 0 ); ucRecursionCountByLock[ ulLockNum ] = 1; - ucOwnedByCore[ ulCoreNum ][ ulLockNum ] = 1; + ucOwnedByCore[ xCoreID ][ ulLockNum ] = 1; } else { - configASSERT( ( ucOwnedByCore[ ulCoreNum ] [ulLockNum ] ) != 0 ); + configASSERT( ( ucOwnedByCore[ xCoreID ] [ulLockNum ] ) != 0 ); configASSERT( ucRecursionCountByLock[ ulLockNum ] != 0 ); if( !--ucRecursionCountByLock[ ulLockNum ] ) { - ucOwnedByCore[ ulCoreNum ] [ ulLockNum ] = 0; + ucOwnedByCore[ xCoreID ] [ ulLockNum ] = 0; spin_unlock_unsafe(pxSpinLock); } } } #if ( configNUMBER_OF_CORES == 1 ) - #define portGET_ISR_LOCK() - #define portRELEASE_ISR_LOCK() - #define portGET_TASK_LOCK() - #define portRELEASE_TASK_LOCK() + #define portGET_ISR_LOCK( xCoreID ) + #define portRELEASE_ISR_LOCK( xCoreID ) + #define portGET_TASK_LOCK( xCoreID ) + #define portRELEASE_TASK_LOCK( xCoreID ) #else - #define portGET_ISR_LOCK() vPortRecursiveLock( 0, spin_lock_instance( configSMP_SPINLOCK_0 ), pdTRUE ) - #define portRELEASE_ISR_LOCK() vPortRecursiveLock( 0, spin_lock_instance( configSMP_SPINLOCK_0 ), pdFALSE ) - #define portGET_TASK_LOCK() vPortRecursiveLock( 1, spin_lock_instance( configSMP_SPINLOCK_1 ), pdTRUE ) - #define portRELEASE_TASK_LOCK() vPortRecursiveLock( 1, spin_lock_instance( configSMP_SPINLOCK_1 ), pdFALSE ) + #define portGET_ISR_LOCK( xCoreID ) vPortRecursiveLock( ( xCoreID ), 0, spin_lock_instance( configSMP_SPINLOCK_0 ), pdTRUE ) + #define portRELEASE_ISR_LOCK( xCoreID ) vPortRecursiveLock( ( xCoreID ), 0, spin_lock_instance( configSMP_SPINLOCK_0 ), pdFALSE ) + #define portGET_TASK_LOCK( xCoreID ) vPortRecursiveLock( ( xCoreID ), 1, spin_lock_instance( configSMP_SPINLOCK_1 ), pdTRUE ) + #define portRELEASE_TASK_LOCK( xCoreID ) vPortRecursiveLock( ( xCoreID ), 1, spin_lock_instance( configSMP_SPINLOCK_1 ), pdFALSE ) #endif /*-----------------------------------------------------------*/ diff --git a/portable/ThirdParty/xClang/XCOREAI/portmacro.h b/portable/ThirdParty/xClang/XCOREAI/portmacro.h index 82da9531487..08813331481 100644 --- a/portable/ThirdParty/xClang/XCOREAI/portmacro.h +++ b/portable/ThirdParty/xClang/XCOREAI/portmacro.h @@ -152,10 +152,11 @@ #define portASSERT_IF_IN_ISR() configASSERT( portCHECK_IF_IN_ISR() == 0 ) - #define portGET_ISR_LOCK() rtos_lock_acquire( 0 ) - #define portRELEASE_ISR_LOCK() rtos_lock_release( 0 ) - #define portGET_TASK_LOCK() rtos_lock_acquire( 1 ) - #define portRELEASE_TASK_LOCK() rtos_lock_release( 1 ) + #define portGET_ISR_LOCK( xCoreID ) do{ ( void )( xCoreID ); rtos_lock_acquire( 0 ); } while( 0 ) + #define portRELEASE_ISR_LOCK( xCoreID ) do{ ( void )( xCoreID ); rtos_lock_release( 0 ); } while( 0 ) + #define portGET_TASK_LOCK( xCoreID ) do{ ( void )( xCoreID ); rtos_lock_acquire( 1 ); } while( 0 ) + #define portRELEASE_TASK_LOCK( xCoreID ) do{ ( void )( xCoreID ); rtos_lock_release( 1 ); } while( 0 ) + void vTaskEnterCritical( void ); void vTaskExitCritical( void ); diff --git a/portable/template/portmacro.h b/portable/template/portmacro.h index 4a4a5876c62..a426f0003cb 100644 --- a/portable/template/portmacro.h +++ b/portable/template/portmacro.h @@ -123,19 +123,19 @@ extern void vPortYield( void ); /* Acquire the TASK lock. TASK lock is a recursive lock. * It should be able to be locked by the same core multiple times. */ - #define portGET_TASK_LOCK() do {} while( 0 ) + #define portGET_TASK_LOCK( xCoreID ) do {} while( 0 ) /* Release the TASK lock. If a TASK lock is locked by the same core multiple times, * it should be released as many times as it is locked. */ - #define portRELEASE_TASK_LOCK() do {} while( 0 ) + #define portRELEASE_TASK_LOCK( xCoreID ) do {} while( 0 ) /* Acquire the ISR lock. ISR lock is a recursive lock. * It should be able to be locked by the same core multiple times. */ - #define portGET_ISR_LOCK() do {} while( 0 ) + #define portGET_ISR_LOCK( xCoreID ) do {} while( 0 ) /* Release the ISR lock. If a ISR lock is locked by the same core multiple times, \ * it should be released as many times as it is locked. */ - #define portRELEASE_ISR_LOCK() do {} while( 0 ) + #define portRELEASE_ISR_LOCK( xCoreID ) do {} while( 0 ) #endif /* if ( configNUMBER_OF_CORES > 1 ) */ diff --git a/tasks.c b/tasks.c index f6af37bab8a..d7153f680e2 100644 --- a/tasks.c +++ b/tasks.c @@ -831,7 +831,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; if( uxPrevCriticalNesting > 0U ) { portSET_CRITICAL_NESTING_COUNT( xCoreID, 0U ); - portRELEASE_ISR_LOCK(); + portRELEASE_ISR_LOCK( xCoreID ); } else { @@ -840,7 +840,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; mtCOVERAGE_TEST_MARKER(); } - portRELEASE_TASK_LOCK(); + portRELEASE_TASK_LOCK( xCoreID ); portMEMORY_BARRIER(); configASSERT( pxThisTCB->xTaskRunState == taskTASK_SCHEDULED_TO_YIELD ); @@ -853,15 +853,16 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; * its run state. */ portDISABLE_INTERRUPTS(); - portGET_TASK_LOCK(); - portGET_ISR_LOCK(); + xCoreID = ( BaseType_t ) portGET_CORE_ID(); + portGET_TASK_LOCK( xCoreID ); + portGET_ISR_LOCK( xCoreID ); portSET_CRITICAL_NESTING_COUNT( xCoreID, uxPrevCriticalNesting ); if( uxPrevCriticalNesting == 0U ) { - portRELEASE_ISR_LOCK(); + portRELEASE_ISR_LOCK( xCoreID ); } } } @@ -3854,6 +3855,7 @@ void vTaskSuspendAll( void ) #else /* #if ( configNUMBER_OF_CORES == 1 ) */ { UBaseType_t ulState; + BaseType_t xCoreID; /* This must only be called from within a task. */ portASSERT_IF_IN_ISR(); @@ -3867,14 +3869,16 @@ void vTaskSuspendAll( void ) * uxSchedulerSuspended since that will prevent context switches. */ ulState = portSET_INTERRUPT_MASK(); + xCoreID = ( BaseType_t ) portGET_CORE_ID(); + /* This must never be called from inside a critical section. */ - configASSERT( portGET_CRITICAL_NESTING_COUNT( portGET_CORE_ID() ) == 0 ); + configASSERT( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0 ); /* portSOFTWARE_BARRIER() is only implemented for emulated/simulated ports that * do not otherwise exhibit real time behaviour. */ portSOFTWARE_BARRIER(); - portGET_TASK_LOCK(); + portGET_TASK_LOCK( xCoreID ); /* uxSchedulerSuspended is increased after prvCheckForRunStateChange. The * purpose is to prevent altering the variable when fromISR APIs are readying @@ -3888,12 +3892,17 @@ void vTaskSuspendAll( void ) mtCOVERAGE_TEST_MARKER(); } - portGET_ISR_LOCK(); + /* Query the coreID again as prvCheckForRunStateChange may have + * caused the task to get scheduled on a different core. The correct + * task lock for the core is acquired in prvCheckForRunStateChange. */ + xCoreID = ( BaseType_t ) portGET_CORE_ID(); + + portGET_ISR_LOCK( xCoreID ); /* The scheduler is suspended if uxSchedulerSuspended is non-zero. An increment * is used to allow calls to vTaskSuspendAll() to nest. */ ++uxSchedulerSuspended; - portRELEASE_ISR_LOCK(); + portRELEASE_ISR_LOCK( xCoreID ); portCLEAR_INTERRUPT_MASK( ulState ); } @@ -3998,7 +4007,7 @@ BaseType_t xTaskResumeAll( void ) configASSERT( uxSchedulerSuspended != 0U ); uxSchedulerSuspended = ( UBaseType_t ) ( uxSchedulerSuspended - 1U ); - portRELEASE_TASK_LOCK(); + portRELEASE_TASK_LOCK( xCoreID ); if( uxSchedulerSuspended == ( UBaseType_t ) 0U ) { @@ -5168,8 +5177,8 @@ BaseType_t xTaskIncrementTick( void ) * and move on if another core suspended the scheduler. We should only * do that if the current core has suspended the scheduler. */ - portGET_TASK_LOCK(); /* Must always acquire the task lock first. */ - portGET_ISR_LOCK(); + portGET_TASK_LOCK( xCoreID ); /* Must always acquire the task lock first. */ + portGET_ISR_LOCK( xCoreID ); { /* vTaskSwitchContext() must never be called from within a critical section. * This is not necessarily true for single core FreeRTOS, but it is for this @@ -5250,8 +5259,8 @@ BaseType_t xTaskIncrementTick( void ) #endif } } - portRELEASE_ISR_LOCK(); - portRELEASE_TASK_LOCK(); + portRELEASE_ISR_LOCK( xCoreID ); + portRELEASE_TASK_LOCK( xCoreID ); traceRETURN_vTaskSwitchContext(); } @@ -6997,8 +7006,8 @@ static void prvResetNextTaskUnblockTime( void ) { if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) { - portGET_TASK_LOCK(); - portGET_ISR_LOCK(); + portGET_TASK_LOCK( xCoreID ); + portGET_ISR_LOCK( xCoreID ); } portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ); @@ -7051,7 +7060,7 @@ static void prvResetNextTaskUnblockTime( void ) if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) { - portGET_ISR_LOCK(); + portGET_ISR_LOCK( xCoreID ); } portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ); @@ -7143,8 +7152,8 @@ static void prvResetNextTaskUnblockTime( void ) /* Get the xYieldPending stats inside the critical section. */ xYieldCurrentTask = xYieldPendings[ xCoreID ]; - portRELEASE_ISR_LOCK(); - portRELEASE_TASK_LOCK(); + portRELEASE_ISR_LOCK( xCoreID ); + portRELEASE_TASK_LOCK( xCoreID ); portENABLE_INTERRUPTS(); /* When a task yields in a critical section it just sets @@ -7199,7 +7208,7 @@ static void prvResetNextTaskUnblockTime( void ) if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) { - portRELEASE_ISR_LOCK(); + portRELEASE_ISR_LOCK( xCoreID ); portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); } else From e55bde213348c8911205f81e89016dd4ba2ba79d Mon Sep 17 00:00:00 2001 From: Ren Mingrui <972931182@qq.com> Date: Mon, 30 Dec 2024 17:11:52 +0800 Subject: [PATCH 6/7] Add a stack pointer bounds check when configCHECK_FOR_STACK_OVERFLOW is set to 2. (#1216) Add a stack pointer bounds check when configCHECK_FOR_STACK_OVERFLOW is set to 2. --- include/stack_macros.h | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/include/stack_macros.h b/include/stack_macros.h index c1018b68a2b..a9c5764bbe0 100644 --- a/include/stack_macros.h +++ b/include/stack_macros.h @@ -88,19 +88,20 @@ #if ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) ) - #define taskCHECK_FOR_STACK_OVERFLOW() \ - do { \ - const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \ - const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5U; \ - \ - if( ( pulStack[ 0 ] != ulCheckValue ) || \ - ( pulStack[ 1 ] != ulCheckValue ) || \ - ( pulStack[ 2 ] != ulCheckValue ) || \ - ( pulStack[ 3 ] != ulCheckValue ) ) \ - { \ - char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \ - vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \ - } \ + #define taskCHECK_FOR_STACK_OVERFLOW() \ + do { \ + const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \ + const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5U; \ + \ + if( ( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack + portSTACK_LIMIT_PADDING ) || \ + ( pulStack[ 0 ] != ulCheckValue ) || \ + ( pulStack[ 1 ] != ulCheckValue ) || \ + ( pulStack[ 2 ] != ulCheckValue ) || \ + ( pulStack[ 3 ] != ulCheckValue ) ) \ + { \ + char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \ + } \ } while( 0 ) #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ @@ -120,8 +121,8 @@ \ pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ \ - /* Has the extremity of the task stack ever been written over? */ \ - if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ + if( ( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) || \ + ( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) ) \ { \ char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \ vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \ From 3a7b3082cfce01ffba07b9be1398795b8307b05a Mon Sep 17 00:00:00 2001 From: iotah Date: Mon, 6 Jan 2025 13:35:53 +0800 Subject: [PATCH 7/7] Update community supported ports submodulees (#1218) Signed-off-by: Hua Zheng Co-authored-by: Hua Zheng --- portable/ThirdParty/Community-Supported-Ports | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portable/ThirdParty/Community-Supported-Ports b/portable/ThirdParty/Community-Supported-Ports index 8b2955f6d97..3c5bfb8f2e5 160000 --- a/portable/ThirdParty/Community-Supported-Ports +++ b/portable/ThirdParty/Community-Supported-Ports @@ -1 +1 @@ -Subproject commit 8b2955f6d97bf4cd582db9f5b62d9eb1587b76d7 +Subproject commit 3c5bfb8f2e557735b5200176b4a8b25a40c68d1b