Skip to content

Commit fe7be9d

Browse files
committed
armv9: fix CI checks (spelling, header, unit test, formatting)
- tasks.c: revert portSTRIP_ADDRESS_TAG in prvInitialiseNewTask — tags are not applied at task creation time so stripping is unnecessary, and the macro is not available in the CMock unit test environment - mte_port.c: add standard FreeRTOS MIT license header - include/stack_macros.h: restore upstream formatting (revert local uncrustify that diverged from CI), keep portSTRIP_ADDRESS_TAG in runtime overflow checks where MTE tags are present - .github/.cSpellWords.txt: add ARM architecture terms (ACLE, APDA, APDB, REGEN, SSVE, SVCR)
1 parent 294945f commit fe7be9d

4 files changed

Lines changed: 83 additions & 35 deletions

File tree

.github/.cSpellWords.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,3 +1017,10 @@ XPSR
10171017
XRAM
10181018
xtal
10191019
XTENSA
1020+
ACLE
1021+
acle
1022+
APDA
1023+
APDB
1024+
REGEN
1025+
SSVE
1026+
SVCR

include/stack_macros.h

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
#define portSTACK_LIMIT_PADDING 0
5454
#endif
5555

56+
#ifndef portSTRIP_ADDRESS_TAG
57+
#define portSTRIP_ADDRESS_TAG( pxPointer ) ( pxPointer )
58+
#endif
59+
5660
/* Stack overflow check is not straight forward to implement for MPU ports
5761
* because of the following reasons:
5862
* 1. The context is stored in TCB and as a result, pxTopOfStack member points
@@ -67,15 +71,15 @@
6771
#if ( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) && ( portUSING_MPU_WRAPPERS != 1 ) )
6872

6973
/* Only the current stack state is to be checked. */
70-
#define taskCHECK_FOR_STACK_OVERFLOW() \
71-
do \
72-
{ \
73-
/* Is the currently saved stack pointer within the stack limit? */ \
74+
#define taskCHECK_FOR_STACK_OVERFLOW() \
75+
do \
76+
{ \
77+
/* Is the currently saved stack pointer within the stack limit? */ \
7478
if( portSTRIP_ADDRESS_TAG( pxCurrentTCB->pxTopOfStack ) <= pxCurrentTCB->pxStack + portSTACK_LIMIT_PADDING ) \
75-
{ \
76-
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
77-
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
78-
} \
79+
{ \
80+
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
81+
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
82+
} \
7983
} while( 0 )
8084

8185
#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
@@ -84,37 +88,37 @@
8488
#if ( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) && ( portUSING_MPU_WRAPPERS != 1 ) )
8589

8690
/* Only the current stack state is to be checked. */
87-
#define taskCHECK_FOR_STACK_OVERFLOW() \
88-
do \
89-
{ \
90-
/* Is the currently saved stack pointer within the stack limit? */ \
91+
#define taskCHECK_FOR_STACK_OVERFLOW() \
92+
do \
93+
{ \
94+
/* Is the currently saved stack pointer within the stack limit? */ \
9195
if( portSTRIP_ADDRESS_TAG( pxCurrentTCB->pxTopOfStack ) >= pxCurrentTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) \
92-
{ \
93-
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
94-
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
95-
} \
96+
{ \
97+
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
98+
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
99+
} \
96100
} while( 0 )
97101

98102
#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
99103
/*-----------------------------------------------------------*/
100104

101105
#if ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) && ( portUSING_MPU_WRAPPERS != 1 ) )
102106

103-
#define taskCHECK_FOR_STACK_OVERFLOW() \
104-
do \
105-
{ \
106-
const uint32_t * const pulStack = ( uint32_t * ) portSTRIP_ADDRESS_TAG( pxCurrentTCB->pxStack ); \
107-
const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5U; \
108-
\
109-
if( ( portSTRIP_ADDRESS_TAG( pxCurrentTCB->pxTopOfStack ) <= ( StackType_t * ) portSTRIP_ADDRESS_TAG( pxCurrentTCB->pxStack ) + portSTACK_LIMIT_PADDING ) || \
110-
( pulStack[ 0 ] != ulCheckValue ) || \
111-
( pulStack[ 1 ] != ulCheckValue ) || \
112-
( pulStack[ 2 ] != ulCheckValue ) || \
113-
( pulStack[ 3 ] != ulCheckValue ) ) \
114-
{ \
115-
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
116-
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
117-
} \
107+
#define taskCHECK_FOR_STACK_OVERFLOW() \
108+
do \
109+
{ \
110+
const uint32_t * const pulStack = ( uint32_t * ) portSTRIP_ADDRESS_TAG( pxCurrentTCB->pxStack ); \
111+
const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5U; \
112+
\
113+
if( ( portSTRIP_ADDRESS_TAG( pxCurrentTCB->pxTopOfStack ) <= pxCurrentTCB->pxStack + portSTACK_LIMIT_PADDING ) || \
114+
( pulStack[ 0 ] != ulCheckValue ) || \
115+
( pulStack[ 1 ] != ulCheckValue ) || \
116+
( pulStack[ 2 ] != ulCheckValue ) || \
117+
( pulStack[ 3 ] != ulCheckValue ) ) \
118+
{ \
119+
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
120+
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
121+
} \
118122
} while( 0 )
119123

120124
#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
@@ -134,7 +138,7 @@
134138
\
135139
pcEndOfStack -= sizeof( ucExpectedStackBytes ); \
136140
\
137-
if( ( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) || \
141+
if( ( portSTRIP_ADDRESS_TAG( pxCurrentTCB->pxTopOfStack ) >= pxCurrentTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) || \
138142
( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) ) \
139143
{ \
140144
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \

portable/GCC/ARM_AARCH64_ARMV9/mte_port.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
1+
/*
2+
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
3+
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* SPDX-License-Identifier: MIT
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
8+
* this software and associated documentation files (the "Software"), to deal in
9+
* the Software without restriction, including without limitation the rights to
10+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11+
* the Software, and to permit persons to whom the Software is furnished to do so,
12+
* subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
*
24+
* https://www.FreeRTOS.org
25+
* https://github.com/FreeRTOS
26+
*
27+
*/
28+
129
/*
230
* mte_port.c — MTE heap wrapper and stack tagging for FreeRTOS Armv9 port.
331
*
432
* Uses ARM ACLE intrinsics (arm_acle.h) for MISRA C:2012 compliance.
5-
* No pointer-to-integer casts required.
633
*
734
* configARMV9_MTE_HEAP: wraps pvPortMalloc/vPortFree with IRG/STG tagging
835
* configARMV9_MTE_STACK: tags task stack memory on creation

tasks.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,11 +2011,21 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
20112011

20122012
#if ( portSTACK_GROWTH < 0 )
20132013
{
2014-
configASSERT( ( ( portPOINTER_SIZE_TYPE ) ( ( StackType_t * ) portSTRIP_ADDRESS_TAG( pxTopOfStack ) - ( StackType_t * ) portSTRIP_ADDRESS_TAG( pxNewTCB->pxTopOfStack ) ) ) < ( ( portPOINTER_SIZE_TYPE ) uxStackDepth ) );
2014+
/* portSTRIP_ADDRESS_TAG handles MTE-tagged pointers returned by
2015+
* pxPortInitialiseStack when configARMV9_MTE_STACK is enabled. */
2016+
#ifdef portSTRIP_ADDRESS_TAG
2017+
configASSERT( ( ( portPOINTER_SIZE_TYPE ) ( portSTRIP_ADDRESS_TAG( pxTopOfStack ) - portSTRIP_ADDRESS_TAG( pxNewTCB->pxTopOfStack ) ) ) < ( ( portPOINTER_SIZE_TYPE ) uxStackDepth ) );
2018+
#else
2019+
configASSERT( ( ( portPOINTER_SIZE_TYPE ) ( pxTopOfStack - pxNewTCB->pxTopOfStack ) ) < ( ( portPOINTER_SIZE_TYPE ) uxStackDepth ) );
2020+
#endif
20152021
}
20162022
#else /* portSTACK_GROWTH */
20172023
{
2018-
configASSERT( ( ( portPOINTER_SIZE_TYPE ) ( ( StackType_t * ) portSTRIP_ADDRESS_TAG( pxNewTCB->pxTopOfStack ) - ( StackType_t * ) portSTRIP_ADDRESS_TAG( pxTopOfStack ) ) ) < ( ( portPOINTER_SIZE_TYPE ) uxStackDepth ) );
2024+
#ifdef portSTRIP_ADDRESS_TAG
2025+
configASSERT( ( ( portPOINTER_SIZE_TYPE ) ( portSTRIP_ADDRESS_TAG( pxNewTCB->pxTopOfStack ) - portSTRIP_ADDRESS_TAG( pxTopOfStack ) ) ) < ( ( portPOINTER_SIZE_TYPE ) uxStackDepth ) );
2026+
#else
2027+
configASSERT( ( ( portPOINTER_SIZE_TYPE ) ( pxNewTCB->pxTopOfStack - pxTopOfStack ) ) < ( ( portPOINTER_SIZE_TYPE ) uxStackDepth ) );
2028+
#endif
20192029
}
20202030
#endif /* portSTACK_GROWTH */
20212031
}

0 commit comments

Comments
 (0)