From 94e9b887be87d536bd7823ed563b7649cb73ea00 Mon Sep 17 00:00:00 2001 From: Matth9814 Date: Sat, 26 Apr 2025 12:10:06 +0200 Subject: [PATCH 1/7] FreeRTOS SMP: direct access to current TCB inside stack macros --- include/stack_macros.h | 205 +++++++++++++++++++++++++++++------------ tasks.c | 2 +- 2 files changed, 149 insertions(+), 58 deletions(-) diff --git a/include/stack_macros.h b/include/stack_macros.h index 6d0117722a..e88e0dc95c 100644 --- a/include/stack_macros.h +++ b/include/stack_macros.h @@ -66,81 +66,172 @@ */ #if ( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) && ( portUSING_MPU_WRAPPERS != 1 ) ) -/* Only the current stack state is to be checked. */ - #define taskCHECK_FOR_STACK_OVERFLOW() \ - do \ - { \ - /* Is the currently saved stack pointer within the stack limit? */ \ - if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack + portSTACK_LIMIT_PADDING ) \ - { \ - char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \ - vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \ - } \ - } while( 0 ) + #if( configNUMBER_OF_CORES == 1 ) + + /* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW() \ + do \ + { \ + /* Is the currently saved stack pointer within the stack limit? */ \ + if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack + portSTACK_LIMIT_PADDING ) \ + { \ + char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \ + } \ + } while( 0 ) + + #else + + /* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ + do \ + { \ + const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ + \ + /* Is the currently saved stack pointer within the stack limit? */ \ + if( pxTCB->pxTopOfStack <= pxTCB->pxStack + portSTACK_LIMIT_PADDING ) \ + { \ + char * pcOverflowTaskName = pxTCB->pcTaskName; \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxTCB, pcOverflowTaskName ); \ + } \ + } while( 0 ) + + #endif #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ /*-----------------------------------------------------------*/ #if ( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) && ( portUSING_MPU_WRAPPERS != 1 ) ) -/* Only the current stack state is to be checked. */ - #define taskCHECK_FOR_STACK_OVERFLOW() \ - do \ - { \ - /* Is the currently saved stack pointer within the stack limit? */ \ - if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) \ - { \ - char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \ - vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \ - } \ - } while( 0 ) + #if( configNUMBER_OF_CORES == 1 ) + + /* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW() \ + do \ + { \ + /* Is the currently saved stack pointer within the stack limit? */ \ + if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) \ + { \ + char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \ + } \ + } while( 0 ) + + #else + + /* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ + do \ + { \ + const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ + \ + /* Is the currently saved stack pointer within the stack limit? */ \ + if( pxTCB->pxTopOfStack >= pxTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) \ + { \ + char * pcOverflowTaskName = pxTCB->pcTaskName; \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxTCB, pcOverflowTaskName ); \ + } \ + } while( 0 ) + + #endif #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ /*-----------------------------------------------------------*/ #if ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) && ( portUSING_MPU_WRAPPERS != 1 ) ) - #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 ) + #if( configNUMBER_OF_CORES == 1 ) + + #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 ) + + #else + + #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ + do \ + { \ + const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \ + const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5U; \ + const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ + \ + if( ( pxTCB->pxTopOfStack <= pxTCB->pxStack + portSTACK_LIMIT_PADDING ) || \ + ( pulStack[ 0 ] != ulCheckValue ) || \ + ( pulStack[ 1 ] != ulCheckValue ) || \ + ( pulStack[ 2 ] != ulCheckValue ) || \ + ( pulStack[ 3 ] != ulCheckValue ) ) \ + { \ + char * pcOverflowTaskName = pxTCB->pcTaskName; \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxTCB, pcOverflowTaskName ); \ + } \ + } while( 0 ) + + #endif #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ /*-----------------------------------------------------------*/ #if ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) && ( portUSING_MPU_WRAPPERS != 1 ) ) - #define taskCHECK_FOR_STACK_OVERFLOW() \ - do \ - { \ - int8_t * pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \ - static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ - tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ - tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ - tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ - tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ - \ - pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ - \ - 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 ); \ - } \ - } while( 0 ) + #if( configNUMBER_OF_CORES == 1 ) + + #define taskCHECK_FOR_STACK_OVERFLOW() \ + do \ + { \ + int8_t * pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \ + static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ + \ + pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ + \ + 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 ); \ + } \ + } while( 0 ) + + #else + + #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ + do \ + { \ + int8_t * pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \ + static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ + const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ + \ + pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ + \ + if( ( pxTCB->pxTopOfStack >= pxTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) || \ + ( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) ) \ + { \ + char * pcOverflowTaskName = pxTCB->pcTaskName; \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxTCB, pcOverflowTaskName ); \ + } \ + } while( 0 ) + + #endif #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ /*-----------------------------------------------------------*/ diff --git a/tasks.c b/tasks.c index 24cfb2620a..e5d2c97c95 100644 --- a/tasks.c +++ b/tasks.c @@ -5251,7 +5251,7 @@ BaseType_t xTaskIncrementTick( void ) #endif /* configGENERATE_RUN_TIME_STATS */ /* Check for stack overflow, if configured. */ - taskCHECK_FOR_STACK_OVERFLOW(); + taskCHECK_FOR_STACK_OVERFLOW( xCoreID ); /* Before the currently running task is switched out, save its errno. */ #if ( configUSE_POSIX_ERRNO == 1 ) From d569fb9f7cb6a9d492b54c998f38ed6b131ffd64 Mon Sep 17 00:00:00 2001 From: Matth9814 <125400975+Matth9814@users.noreply.github.com> Date: Sun, 27 Apr 2025 13:31:54 +0200 Subject: [PATCH 2/7] Remove access to pxCurrentTCB when configCHECK_FOR_STACK_OVERFLOW == 2 Co-authored-by: Jeff Tenney --- include/stack_macros.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/stack_macros.h b/include/stack_macros.h index e88e0dc95c..195ba17058 100644 --- a/include/stack_macros.h +++ b/include/stack_macros.h @@ -164,9 +164,9 @@ #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ do \ { \ - const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \ - const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5U; \ const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ + const uint32_t * const pulStack = ( uint32_t * ) pxTCB->pxStack; \ + const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5U; \ \ if( ( pxTCB->pxTopOfStack <= pxTCB->pxStack + portSTACK_LIMIT_PADDING ) || \ ( pulStack[ 0 ] != ulCheckValue ) || \ @@ -213,13 +213,13 @@ #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ do \ { \ - int8_t * pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \ + const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ + int8_t * pcEndOfStack = ( int8_t * ) pxTCB->pxEndOfStack; \ static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ - const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ \ pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ \ From f515c5cc99b659a0f4d318f4c9f0c7e34e51f7e9 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 29 Apr 2025 10:48:03 +0000 Subject: [PATCH 3/7] Uncrustify: triggered by comment. --- include/stack_macros.h | 296 ++++++++++++++++++++--------------------- 1 file changed, 148 insertions(+), 148 deletions(-) diff --git a/include/stack_macros.h b/include/stack_macros.h index 195ba17058..77a3ab3b77 100644 --- a/include/stack_macros.h +++ b/include/stack_macros.h @@ -66,172 +66,172 @@ */ #if ( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) && ( portUSING_MPU_WRAPPERS != 1 ) ) - #if( configNUMBER_OF_CORES == 1 ) - - /* Only the current stack state is to be checked. */ - #define taskCHECK_FOR_STACK_OVERFLOW() \ - do \ - { \ - /* Is the currently saved stack pointer within the stack limit? */ \ - if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack + portSTACK_LIMIT_PADDING ) \ - { \ - char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \ - vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \ - } \ - } while( 0 ) - - #else - - /* Only the current stack state is to be checked. */ - #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ - do \ - { \ - const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ - \ - /* Is the currently saved stack pointer within the stack limit? */ \ - if( pxTCB->pxTopOfStack <= pxTCB->pxStack + portSTACK_LIMIT_PADDING ) \ - { \ - char * pcOverflowTaskName = pxTCB->pcTaskName; \ - vApplicationStackOverflowHook( ( TaskHandle_t ) pxTCB, pcOverflowTaskName ); \ - } \ - } while( 0 ) - - #endif + #if ( configNUMBER_OF_CORES == 1 ) + +/* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW() \ + do \ + { \ + /* Is the currently saved stack pointer within the stack limit? */ \ + if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack + portSTACK_LIMIT_PADDING ) \ + { \ + char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \ + } \ + } while( 0 ) + + #else /* if ( configNUMBER_OF_CORES == 1 ) */ + +/* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ + do \ + { \ + const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ + \ + /* Is the currently saved stack pointer within the stack limit? */ \ + if( pxTCB->pxTopOfStack <= pxTCB->pxStack + portSTACK_LIMIT_PADDING ) \ + { \ + char * pcOverflowTaskName = pxTCB->pcTaskName; \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxTCB, pcOverflowTaskName ); \ + } \ + } while( 0 ) + + #endif /* if ( configNUMBER_OF_CORES == 1 ) */ #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ /*-----------------------------------------------------------*/ #if ( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) && ( portUSING_MPU_WRAPPERS != 1 ) ) - #if( configNUMBER_OF_CORES == 1 ) - - /* Only the current stack state is to be checked. */ - #define taskCHECK_FOR_STACK_OVERFLOW() \ - do \ - { \ - /* Is the currently saved stack pointer within the stack limit? */ \ - if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) \ - { \ - char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \ - vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \ - } \ - } while( 0 ) - - #else - - /* Only the current stack state is to be checked. */ - #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ - do \ - { \ - const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ - \ - /* Is the currently saved stack pointer within the stack limit? */ \ - if( pxTCB->pxTopOfStack >= pxTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) \ - { \ - char * pcOverflowTaskName = pxTCB->pcTaskName; \ - vApplicationStackOverflowHook( ( TaskHandle_t ) pxTCB, pcOverflowTaskName ); \ - } \ - } while( 0 ) - - #endif + #if ( configNUMBER_OF_CORES == 1 ) + +/* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW() \ + do \ + { \ + /* Is the currently saved stack pointer within the stack limit? */ \ + if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) \ + { \ + char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \ + } \ + } while( 0 ) + + #else /* if ( configNUMBER_OF_CORES == 1 ) */ + +/* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ + do \ + { \ + const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ + \ + /* Is the currently saved stack pointer within the stack limit? */ \ + if( pxTCB->pxTopOfStack >= pxTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) \ + { \ + char * pcOverflowTaskName = pxTCB->pcTaskName; \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxTCB, pcOverflowTaskName ); \ + } \ + } while( 0 ) + + #endif /* if ( configNUMBER_OF_CORES == 1 ) */ #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ /*-----------------------------------------------------------*/ #if ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) && ( portUSING_MPU_WRAPPERS != 1 ) ) - #if( configNUMBER_OF_CORES == 1 ) - - #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 ) - - #else - - #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ - do \ - { \ - const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ - const uint32_t * const pulStack = ( uint32_t * ) pxTCB->pxStack; \ - const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5U; \ - \ - if( ( pxTCB->pxTopOfStack <= pxTCB->pxStack + portSTACK_LIMIT_PADDING ) || \ - ( pulStack[ 0 ] != ulCheckValue ) || \ - ( pulStack[ 1 ] != ulCheckValue ) || \ - ( pulStack[ 2 ] != ulCheckValue ) || \ - ( pulStack[ 3 ] != ulCheckValue ) ) \ - { \ - char * pcOverflowTaskName = pxTCB->pcTaskName; \ - vApplicationStackOverflowHook( ( TaskHandle_t ) pxTCB, pcOverflowTaskName ); \ - } \ - } while( 0 ) - - #endif + #if ( configNUMBER_OF_CORES == 1 ) + + #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 ) + + #else /* if ( configNUMBER_OF_CORES == 1 ) */ + + #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ + do \ + { \ + const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ + const uint32_t * const pulStack = ( uint32_t * ) pxTCB->pxStack; \ + const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5U; \ + \ + if( ( pxTCB->pxTopOfStack <= pxTCB->pxStack + portSTACK_LIMIT_PADDING ) || \ + ( pulStack[ 0 ] != ulCheckValue ) || \ + ( pulStack[ 1 ] != ulCheckValue ) || \ + ( pulStack[ 2 ] != ulCheckValue ) || \ + ( pulStack[ 3 ] != ulCheckValue ) ) \ + { \ + char * pcOverflowTaskName = pxTCB->pcTaskName; \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxTCB, pcOverflowTaskName ); \ + } \ + } while( 0 ) + + #endif /* if ( configNUMBER_OF_CORES == 1 ) */ #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ /*-----------------------------------------------------------*/ #if ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) && ( portUSING_MPU_WRAPPERS != 1 ) ) - #if( configNUMBER_OF_CORES == 1 ) - - #define taskCHECK_FOR_STACK_OVERFLOW() \ - do \ - { \ - int8_t * pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \ - static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ - tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ - tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ - tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ - tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ - \ - pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ - \ - 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 ); \ - } \ - } while( 0 ) - - #else - - #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ - do \ - { \ - const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ - int8_t * pcEndOfStack = ( int8_t * ) pxTCB->pxEndOfStack; \ - static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ - tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ - tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ - tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ - tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ - \ - pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ - \ - if( ( pxTCB->pxTopOfStack >= pxTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) || \ - ( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) ) \ - { \ - char * pcOverflowTaskName = pxTCB->pcTaskName; \ - vApplicationStackOverflowHook( ( TaskHandle_t ) pxTCB, pcOverflowTaskName ); \ - } \ - } while( 0 ) - - #endif + #if ( configNUMBER_OF_CORES == 1 ) + + #define taskCHECK_FOR_STACK_OVERFLOW() \ + do \ + { \ + int8_t * pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \ + static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ + \ + pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ + \ + 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 ); \ + } \ + } while( 0 ) + + #else /* if ( configNUMBER_OF_CORES == 1 ) */ + + #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ + do \ + { \ + const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ + int8_t * pcEndOfStack = ( int8_t * ) pxTCB->pxEndOfStack; \ + static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ + \ + pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ + \ + if( ( pxTCB->pxTopOfStack >= pxTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) || \ + ( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) ) \ + { \ + char * pcOverflowTaskName = pxTCB->pcTaskName; \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxTCB, pcOverflowTaskName ); \ + } \ + } while( 0 ) + + #endif /* if ( configNUMBER_OF_CORES == 1 ) */ #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ /*-----------------------------------------------------------*/ From fa902e6f606fa3162e1db6e19abcfc3ab4b316cd Mon Sep 17 00:00:00 2001 From: Gaurav Aggarwal Date: Wed, 30 Apr 2025 06:11:22 +0000 Subject: [PATCH 4/7] Trigger CI checks Signed-off-by: Gaurav Aggarwal --- include/stack_macros.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/include/stack_macros.h b/include/stack_macros.h index 77a3ab3b77..41490a24b0 100644 --- a/include/stack_macros.h +++ b/include/stack_macros.h @@ -68,8 +68,8 @@ #if ( configNUMBER_OF_CORES == 1 ) -/* Only the current stack state is to be checked. */ - #define taskCHECK_FOR_STACK_OVERFLOW() \ + /* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW() \ do \ { \ /* Is the currently saved stack pointer within the stack limit? */ \ @@ -82,8 +82,8 @@ #else /* if ( configNUMBER_OF_CORES == 1 ) */ -/* Only the current stack state is to be checked. */ - #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ + /* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ do \ { \ const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ @@ -105,8 +105,8 @@ #if ( configNUMBER_OF_CORES == 1 ) -/* Only the current stack state is to be checked. */ - #define taskCHECK_FOR_STACK_OVERFLOW() \ + /* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW() \ do \ { \ /* Is the currently saved stack pointer within the stack limit? */ \ @@ -119,8 +119,8 @@ #else /* if ( configNUMBER_OF_CORES == 1 ) */ -/* Only the current stack state is to be checked. */ - #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ + /* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ do \ { \ const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ @@ -142,7 +142,7 @@ #if ( configNUMBER_OF_CORES == 1 ) - #define taskCHECK_FOR_STACK_OVERFLOW() \ + #define taskCHECK_FOR_STACK_OVERFLOW() \ do \ { \ const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \ @@ -161,7 +161,7 @@ #else /* if ( configNUMBER_OF_CORES == 1 ) */ - #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ + #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ do \ { \ const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ @@ -188,7 +188,7 @@ #if ( configNUMBER_OF_CORES == 1 ) - #define taskCHECK_FOR_STACK_OVERFLOW() \ + #define taskCHECK_FOR_STACK_OVERFLOW() \ do \ { \ int8_t * pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \ @@ -210,7 +210,7 @@ #else /* if ( configNUMBER_OF_CORES == 1 ) */ - #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ + #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ do \ { \ const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ From f1132d05aecfdf6e43624eba7e112c1dec84d74e Mon Sep 17 00:00:00 2001 From: Gaurav Aggarwal Date: Wed, 30 Apr 2025 06:13:44 +0000 Subject: [PATCH 5/7] Fix CI formatting check Signed-off-by: Gaurav Aggarwal --- include/stack_macros.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/include/stack_macros.h b/include/stack_macros.h index 41490a24b0..9b481241b8 100644 --- a/include/stack_macros.h +++ b/include/stack_macros.h @@ -68,8 +68,8 @@ #if ( configNUMBER_OF_CORES == 1 ) - /* Only the current stack state is to be checked. */ - #define taskCHECK_FOR_STACK_OVERFLOW() \ +/* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW() \ do \ { \ /* Is the currently saved stack pointer within the stack limit? */ \ @@ -80,10 +80,10 @@ } \ } while( 0 ) - #else /* if ( configNUMBER_OF_CORES == 1 ) */ + #else /* if ( configNUMBER_OF_CORES == 1 ) */ - /* Only the current stack state is to be checked. */ - #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ +/* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ do \ { \ const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ @@ -105,8 +105,8 @@ #if ( configNUMBER_OF_CORES == 1 ) - /* Only the current stack state is to be checked. */ - #define taskCHECK_FOR_STACK_OVERFLOW() \ +/* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW() \ do \ { \ /* Is the currently saved stack pointer within the stack limit? */ \ @@ -117,10 +117,10 @@ } \ } while( 0 ) - #else /* if ( configNUMBER_OF_CORES == 1 ) */ + #else /* if ( configNUMBER_OF_CORES == 1 ) */ - /* Only the current stack state is to be checked. */ - #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ +/* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ do \ { \ const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ @@ -142,7 +142,7 @@ #if ( configNUMBER_OF_CORES == 1 ) - #define taskCHECK_FOR_STACK_OVERFLOW() \ + #define taskCHECK_FOR_STACK_OVERFLOW() \ do \ { \ const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \ @@ -159,9 +159,9 @@ } \ } while( 0 ) - #else /* if ( configNUMBER_OF_CORES == 1 ) */ + #else /* if ( configNUMBER_OF_CORES == 1 ) */ - #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ + #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ do \ { \ const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ @@ -188,7 +188,7 @@ #if ( configNUMBER_OF_CORES == 1 ) - #define taskCHECK_FOR_STACK_OVERFLOW() \ + #define taskCHECK_FOR_STACK_OVERFLOW() \ do \ { \ int8_t * pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \ @@ -208,9 +208,9 @@ } \ } while( 0 ) - #else /* if ( configNUMBER_OF_CORES == 1 ) */ + #else /* if ( configNUMBER_OF_CORES == 1 ) */ - #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ + #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ do \ { \ const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ From 90d8db53c2bea3748b7e6e25073309f74d941341 Mon Sep 17 00:00:00 2001 From: Gaurav Aggarwal Date: Wed, 30 Apr 2025 06:38:15 +0000 Subject: [PATCH 6/7] Fix build check Signed-off-by: Gaurav Aggarwal --- include/stack_macros.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/stack_macros.h b/include/stack_macros.h index 9b481241b8..77e86cb781 100644 --- a/include/stack_macros.h +++ b/include/stack_macros.h @@ -86,7 +86,7 @@ #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ do \ { \ - const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ + TCB_t * pxTCB = pxCurrentTCBs[ xCoreID ]; \ \ /* Is the currently saved stack pointer within the stack limit? */ \ if( pxTCB->pxTopOfStack <= pxTCB->pxStack + portSTACK_LIMIT_PADDING ) \ @@ -123,7 +123,7 @@ #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ do \ { \ - const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ + TCB_t * pxTCB = pxCurrentTCBs[ xCoreID ]; \ \ /* Is the currently saved stack pointer within the stack limit? */ \ if( pxTCB->pxTopOfStack >= pxTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) \ @@ -164,7 +164,7 @@ #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ do \ { \ - const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ + TCB_t * pxTCB = pxCurrentTCBs[ xCoreID ]; \ const uint32_t * const pulStack = ( uint32_t * ) pxTCB->pxStack; \ const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5U; \ \ @@ -213,7 +213,7 @@ #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \ do \ { \ - const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \ + TCB_t * pxTCB = pxCurrentTCBs[ xCoreID ]; \ int8_t * pcEndOfStack = ( int8_t * ) pxTCB->pxEndOfStack; \ static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ From b35769711023e057a02a21c458a71918098b354c Mon Sep 17 00:00:00 2001 From: Gaurav Aggarwal Date: Wed, 30 Apr 2025 07:21:23 +0000 Subject: [PATCH 7/7] Fix tests Signed-off-by: Gaurav Aggarwal --- include/stack_macros.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/stack_macros.h b/include/stack_macros.h index 77e86cb781..8bf0720c9e 100644 --- a/include/stack_macros.h +++ b/include/stack_macros.h @@ -238,7 +238,11 @@ /* Remove stack overflow macro if not being used. */ #ifndef taskCHECK_FOR_STACK_OVERFLOW - #define taskCHECK_FOR_STACK_OVERFLOW() + #if ( configNUMBER_OF_CORES == 1 ) + #define taskCHECK_FOR_STACK_OVERFLOW() + #else + #define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) + #endif #endif