From 90dd76f28fdca6f3d39537a38f665ef5f1b9ef4f Mon Sep 17 00:00:00 2001 From: Ahmed Ismail Date: Thu, 22 Jan 2026 15:20:58 +0000 Subject: [PATCH] tasks: Disable stack-depth check if MPU wrappers is set This stack-depth check should not be performed for ports where portUSING_MPU_WRAPPERS is set to 1. In this case, pxTopOfStack and pxNewTCB->pxTopOfStack reside in different memory regions: pxTopOfStack is in unprivileged SRAM, while pxNewTCB->pxTopOfStack is in privileged SRAM. This is because pxPortInitialiseStack() returns the address of `ullContext` array rather than the decremented pxTopOfStack, as is done in the non-MPU case. Consequently, this check is not valid in this scenario. Signed-off-by: Ahmed Ismail --- .github/scripts/kernel_checker.py | 1 + tasks.c | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/scripts/kernel_checker.py b/.github/scripts/kernel_checker.py index 151a42ba6..55833d28b 100755 --- a/.github/scripts/kernel_checker.py +++ b/.github/scripts/kernel_checker.py @@ -120,6 +120,7 @@ KERNEL_ARM_COLLAB_FILES_PATTERNS = [ r'.*portable/.*/ARM_CM4F_MPU*', r'.*portable/.*/ARM_CR82*', r'.*include/task\.h$', + r'.*tasks\.c$', ] KERNEL_HEADER = [ diff --git a/tasks.c b/tasks.c index 9d6bf84b7..c596c475f 100644 --- a/tasks.c +++ b/tasks.c @@ -1,6 +1,7 @@ /* * FreeRTOS Kernel * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2026 Arm Limited and/or its affiliates * * SPDX-License-Identifier: MIT * @@ -2007,19 +2008,19 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxTaskCode, pvParameters ); } #endif /* portHAS_STACK_OVERFLOW_CHECKING */ + + #if ( portSTACK_GROWTH < 0 ) + { + configASSERT( ( ( portPOINTER_SIZE_TYPE ) ( pxTopOfStack - pxNewTCB->pxTopOfStack ) ) < ( ( portPOINTER_SIZE_TYPE ) uxStackDepth ) ); + } + #else /* portSTACK_GROWTH */ + { + configASSERT( ( ( portPOINTER_SIZE_TYPE ) ( pxNewTCB->pxTopOfStack - pxTopOfStack ) ) < ( ( portPOINTER_SIZE_TYPE ) uxStackDepth ) ); + } + #endif /* portSTACK_GROWTH */ } #endif /* portUSING_MPU_WRAPPERS */ - #if ( portSTACK_GROWTH < 0 ) - { - configASSERT( ( ( portPOINTER_SIZE_TYPE ) ( pxTopOfStack - pxNewTCB->pxTopOfStack ) ) < ( ( portPOINTER_SIZE_TYPE ) uxStackDepth ) ); - } - #else /* portSTACK_GROWTH */ - { - configASSERT( ( ( portPOINTER_SIZE_TYPE ) ( pxNewTCB->pxTopOfStack - pxTopOfStack ) ) < ( ( portPOINTER_SIZE_TYPE ) uxStackDepth ) ); - } - #endif - /* Initialize task state and task attributes. */ #if ( configNUMBER_OF_CORES > 1 ) {