Skip to content

Commit abef464

Browse files
jiladahe1997jiladahe1997
authored andcommitted
Add a stack pointer bounds check when configCHECK_FOR_STACK_OVERFLOW is set to 2.
1 parent f63bc2b commit abef464

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

include/stack_macros.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,18 @@
9393
const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \
9494
const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5U; \
9595
\
96+
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
9697
if( ( pulStack[ 0 ] != ulCheckValue ) || \
9798
( pulStack[ 1 ] != ulCheckValue ) || \
9899
( pulStack[ 2 ] != ulCheckValue ) || \
99100
( pulStack[ 3 ] != ulCheckValue ) ) \
100101
{ \
101-
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
102+
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
103+
} \
104+
\
105+
/* Is the currently saved stack pointer within the stack limit? */ \
106+
if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack + portSTACK_LIMIT_PADDING ) \
107+
{ \
102108
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
103109
} \
104110
} while( 0 )
@@ -120,10 +126,16 @@
120126
\
121127
pcEndOfStack -= sizeof( ucExpectedStackBytes ); \
122128
\
129+
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
123130
/* Has the extremity of the task stack ever been written over? */ \
124131
if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
125132
{ \
126-
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
133+
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
134+
} \
135+
\
136+
/* Is the currently saved stack pointer within the stack limit? */ \
137+
if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) \
138+
{ \
127139
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
128140
} \
129141
} while( 0 )

0 commit comments

Comments
 (0)