armv9: fix MTE tagged pointer handling in stack assertions

When configARMV9_MTE_HEAP or configARMV9_MTE_STACK is enabled,
pvPortMalloc and pxPortInitialiseStack return pointers with non-zero
MTE tags in the top byte. The stack depth assertion in tasks.c and
the stack overflow checks in stack_macros.h compared tagged pointers
against untagged ones, causing spurious assertion failures.

Introduce portSTRIP_ADDRESS_TAG() macro:
- Default no-op in FreeRTOS.h (zero impact on non-MTE ports)
- ARM_AARCH64_ARMV9 portmacro.h defines it to mask bits [63:56]

Apply the macro in:
- tasks.c: prvInitialiseNewTask stack depth check (both pointers)
- stack_macros.h: both stack overflow detection variants
This commit is contained in:
Richard Elberger 2026-06-17 13:54:01 -07:00
parent c23ed2d1cc
commit d4a16e4c85
3 changed files with 8 additions and 4 deletions

View file

@ -2748,6 +2748,10 @@
#define portTASK_USES_FLOATING_POINT()
#endif
#ifndef portSTRIP_ADDRESS_TAG
#define portSTRIP_ADDRESS_TAG( pxPointer ) ( pxPointer )
#endif
#ifndef portALLOCATE_SECURE_CONTEXT
#define portALLOCATE_SECURE_CONTEXT( ulSecureStackSize )
#endif

View file

@ -71,7 +71,7 @@
do \
{ \
/* Is the currently saved stack pointer within the stack limit? */ \
if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack + portSTACK_LIMIT_PADDING ) \
if( portSTRIP_ADDRESS_TAG( pxCurrentTCB->pxTopOfStack ) <= pxCurrentTCB->pxStack + portSTACK_LIMIT_PADDING ) \
{ \
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
@ -88,7 +88,7 @@
do \
{ \
/* Is the currently saved stack pointer within the stack limit? */ \
if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) \
if( portSTRIP_ADDRESS_TAG( pxCurrentTCB->pxTopOfStack ) >= pxCurrentTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) \
{ \
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \

View file

@ -2011,11 +2011,11 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
#if ( portSTACK_GROWTH < 0 )
{
configASSERT( ( ( portPOINTER_SIZE_TYPE ) ( pxTopOfStack - pxNewTCB->pxTopOfStack ) ) < ( ( portPOINTER_SIZE_TYPE ) uxStackDepth ) );
configASSERT( ( ( portPOINTER_SIZE_TYPE ) ( ( StackType_t * ) portSTRIP_ADDRESS_TAG( pxTopOfStack ) - ( StackType_t * ) portSTRIP_ADDRESS_TAG( pxNewTCB->pxTopOfStack ) ) ) < ( ( portPOINTER_SIZE_TYPE ) uxStackDepth ) );
}
#else /* portSTACK_GROWTH */
{
configASSERT( ( ( portPOINTER_SIZE_TYPE ) ( pxNewTCB->pxTopOfStack - pxTopOfStack ) ) < ( ( portPOINTER_SIZE_TYPE ) uxStackDepth ) );
configASSERT( ( ( portPOINTER_SIZE_TYPE ) ( ( StackType_t * ) portSTRIP_ADDRESS_TAG( pxNewTCB->pxTopOfStack ) - ( StackType_t * ) portSTRIP_ADDRESS_TAG( pxTopOfStack ) ) ) < ( ( portPOINTER_SIZE_TYPE ) uxStackDepth ) );
}
#endif /* portSTACK_GROWTH */
}