Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 5 additions & 100 deletions include/stack_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@
*/
#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() \
#define taskCHECK_FOR_STACK_OVERFLOW() \
do \
{ \
/* Is the currently saved stack pointer within the stack limit? */ \
Expand All @@ -80,33 +78,13 @@
} \
} 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 */
/*-----------------------------------------------------------*/

#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() \
#define taskCHECK_FOR_STACK_OVERFLOW() \
do \
{ \
/* Is the currently saved stack pointer within the stack limit? */ \
Expand All @@ -117,32 +95,12 @@
} \
} 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 */
/*-----------------------------------------------------------*/

#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 \
{ \
const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \
Expand All @@ -159,36 +117,12 @@
} \
} 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 ) */
/*-----------------------------------------------------------*/

#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 \
{ \
int8_t * pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \
Expand All @@ -208,41 +142,12 @@
} \
} 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 ) */
/*-----------------------------------------------------------*/

/* Remove stack overflow macro if not being used. */
#ifndef taskCHECK_FOR_STACK_OVERFLOW
#if ( configNUMBER_OF_CORES == 1 )
#define taskCHECK_FOR_STACK_OVERFLOW()
#else
#define taskCHECK_FOR_STACK_OVERFLOW( xCoreID )
#endif
#define taskCHECK_FOR_STACK_OVERFLOW()
#endif


Expand Down
2 changes: 1 addition & 1 deletion tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -5251,7 +5251,7 @@ BaseType_t xTaskIncrementTick( void )
#endif /* configGENERATE_RUN_TIME_STATS */

/* Check for stack overflow, if configured. */
taskCHECK_FOR_STACK_OVERFLOW( xCoreID );
taskCHECK_FOR_STACK_OVERFLOW();

/* Before the currently running task is switched out, save its errno. */
#if ( configUSE_POSIX_ERRNO == 1 )
Expand Down