FreeRTOS SMP: direct access to current TCB inside stack macros (#1270)

FreeRTOS SMP: direct access to current TCB inside stack macros
This commit is contained in:
Matth9814 2025-04-30 09:42:08 +02:00 committed by GitHub
parent d03233f209
commit 4162ca49d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 101 additions and 6 deletions

View file

@ -66,6 +66,8 @@
*/ */
#if ( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) && ( portUSING_MPU_WRAPPERS != 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. */ /* Only the current stack state is to be checked. */
#define taskCHECK_FOR_STACK_OVERFLOW() \ #define taskCHECK_FOR_STACK_OVERFLOW() \
do \ do \
@ -78,11 +80,31 @@
} \ } \
} while( 0 ) } while( 0 )
#else /* if ( configNUMBER_OF_CORES == 1 ) */
/* Only the current stack state is to be checked. */
#define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \
do \
{ \
TCB_t * 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 */ #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#if ( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) && ( portUSING_MPU_WRAPPERS != 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. */ /* Only the current stack state is to be checked. */
#define taskCHECK_FOR_STACK_OVERFLOW() \ #define taskCHECK_FOR_STACK_OVERFLOW() \
do \ do \
@ -95,11 +117,31 @@
} \ } \
} while( 0 ) } while( 0 )
#else /* if ( configNUMBER_OF_CORES == 1 ) */
/* Only the current stack state is to be checked. */
#define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \
do \
{ \
TCB_t * 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 */ #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#if ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) && ( portUSING_MPU_WRAPPERS != 1 ) ) #if ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) && ( portUSING_MPU_WRAPPERS != 1 ) )
#if ( configNUMBER_OF_CORES == 1 )
#define taskCHECK_FOR_STACK_OVERFLOW() \ #define taskCHECK_FOR_STACK_OVERFLOW() \
do \ do \
{ \ { \
@ -117,11 +159,35 @@
} \ } \
} while( 0 ) } while( 0 )
#else /* if ( configNUMBER_OF_CORES == 1 ) */
#define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \
do \
{ \
TCB_t * 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 ) */ #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#if ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) && ( portUSING_MPU_WRAPPERS != 1 ) ) #if ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) && ( portUSING_MPU_WRAPPERS != 1 ) )
#if ( configNUMBER_OF_CORES == 1 )
#define taskCHECK_FOR_STACK_OVERFLOW() \ #define taskCHECK_FOR_STACK_OVERFLOW() \
do \ do \
{ \ { \
@ -142,12 +208,41 @@
} \ } \
} while( 0 ) } while( 0 )
#else /* if ( configNUMBER_OF_CORES == 1 ) */
#define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \
do \
{ \
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, \
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 ) */ #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* Remove stack overflow macro if not being used. */ /* Remove stack overflow macro if not being used. */
#ifndef taskCHECK_FOR_STACK_OVERFLOW #ifndef taskCHECK_FOR_STACK_OVERFLOW
#if ( configNUMBER_OF_CORES == 1 )
#define taskCHECK_FOR_STACK_OVERFLOW() #define taskCHECK_FOR_STACK_OVERFLOW()
#else
#define taskCHECK_FOR_STACK_OVERFLOW( xCoreID )
#endif
#endif #endif

View file

@ -5251,7 +5251,7 @@ BaseType_t xTaskIncrementTick( void )
#endif /* configGENERATE_RUN_TIME_STATS */ #endif /* configGENERATE_RUN_TIME_STATS */
/* Check for stack overflow, if configured. */ /* 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. */ /* Before the currently running task is switched out, save its errno. */
#if ( configUSE_POSIX_ERRNO == 1 ) #if ( configUSE_POSIX_ERRNO == 1 )