Skip to content

Commit 99a5a5f

Browse files
committed
Fix free secure context for Cortex-M23 ports
Update the branching condition to correctly free secure context when there is one. Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
1 parent 06ea727 commit 99a5a5f

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

portable/ARMv8M/non_secure/portable/GCC/ARM_CM23/portasm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ void vPortFreeSecureContext( uint32_t * pulTCB ) /* __attribute__ (( naked )) PR
449449
" ldr r2, [r0] \n"/* The first item in the TCB is the top of the stack. */
450450
" ldr r1, [r2] \n"/* The first item on the stack is the task's xSecureContext. */
451451
" cmp r1, #0 \n"/* Raise svc if task's xSecureContext is not NULL. */
452-
" beq free_secure_context \n"
452+
" bne free_secure_context \n"/* Branch if r1 != 0. */
453453
" bx lr \n"/* There is no secure context (xSecureContext is NULL). */
454454
" free_secure_context: \n"
455455
" svc %0 \n"/* Secure context is freed in the supervisor call. */

portable/ARMv8M/non_secure/portable/IAR/ARM_CM23/portasm.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ vPortFreeSecureContext:
381381
ldr r2, [r0] /* The first item in the TCB is the top of the stack. */
382382
ldr r1, [r2] /* The first item on the stack is the task's xSecureContext. */
383383
cmp r1, #0 /* Raise svc if task's xSecureContext is not NULL. */
384-
beq free_secure_context
384+
bne free_secure_context /* Branch if r1 != 0. */
385385
bx lr /* There is no secure context (xSecureContext is NULL). */
386386
free_secure_context:
387387
svc 1 /* Secure context is freed in the supervisor call. portSVC_FREE_SECURE_CONTEXT = 1. */

portable/GCC/ARM_CM23/non_secure/portasm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ void vPortFreeSecureContext( uint32_t * pulTCB ) /* __attribute__ (( naked )) PR
449449
" ldr r2, [r0] \n"/* The first item in the TCB is the top of the stack. */
450450
" ldr r1, [r2] \n"/* The first item on the stack is the task's xSecureContext. */
451451
" cmp r1, #0 \n"/* Raise svc if task's xSecureContext is not NULL. */
452-
" beq free_secure_context \n"
452+
" bne free_secure_context \n"/* Branch if r1 != 0. */
453453
" bx lr \n"/* There is no secure context (xSecureContext is NULL). */
454454
" free_secure_context: \n"
455455
" svc %0 \n"/* Secure context is freed in the supervisor call. */

portable/IAR/ARM_CM23/non_secure/portasm.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ vPortFreeSecureContext:
381381
ldr r2, [r0] /* The first item in the TCB is the top of the stack. */
382382
ldr r1, [r2] /* The first item on the stack is the task's xSecureContext. */
383383
cmp r1, #0 /* Raise svc if task's xSecureContext is not NULL. */
384-
beq free_secure_context
384+
bne free_secure_context /* Branch if r1 != 0. */
385385
bx lr /* There is no secure context (xSecureContext is NULL). */
386386
free_secure_context:
387387
svc 1 /* Secure context is freed in the supervisor call. portSVC_FREE_SECURE_CONTEXT = 1. */

tasks.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,6 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
12191219
{
12201220
--uxCurrentNumberOfTasks;
12211221
traceTASK_DELETE( pxTCB );
1222-
prvDeleteTCB( pxTCB );
12231222

12241223
/* Reset the next expected unblock time in case it referred to
12251224
* the task that has just been deleted. */
@@ -1228,6 +1227,14 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
12281227
}
12291228
taskEXIT_CRITICAL();
12301229

1230+
/* If the task is not deleting itself, call prvDeleteTCB from outside of
1231+
* critical section. If a task deletes itself, prvDeleteTCB is called
1232+
* from prvCheckTasksWaitingTermination which is called from Idle task. */
1233+
if( pxTCB != pxCurrentTCB )
1234+
{
1235+
prvDeleteTCB( pxTCB );
1236+
}
1237+
12311238
/* Force a reschedule if it is the currently running task that has just
12321239
* been deleted. */
12331240
if( xSchedulerRunning != pdFALSE )

0 commit comments

Comments
 (0)