From d20189bdfa2c42c02934be888e908d30cc6e1638 Mon Sep 17 00:00:00 2001 From: hujun5 Date: Fri, 6 Dec 2024 21:29:08 +0800 Subject: [PATCH] armv6m: fix regresion from https://github.com/apache/nuttx/pull/14881 reason: svc call may trigger hardfalt Signed-off-by: hujun5 --- arch/arm/src/armv6-m/arm_doirq.c | 2 +- arch/arm/src/armv6-m/arm_sigdeliver.c | 1 + arch/arm/src/common/arm_exit.c | 11 ++++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/arm/src/armv6-m/arm_doirq.c b/arch/arm/src/armv6-m/arm_doirq.c index aa9578d87dec7..dbbf25a6e576e 100644 --- a/arch/arm/src/armv6-m/arm_doirq.c +++ b/arch/arm/src/armv6-m/arm_doirq.c @@ -65,7 +65,7 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) * is invalid, and we can safely overwrite it. */ - if (!(NVIC_IRQ_SVCALL == irq && regs[REG_R0] == SYS_restore_context)) + if (*running_task != NULL) { tcb->xcp.regs = regs; } diff --git a/arch/arm/src/armv6-m/arm_sigdeliver.c b/arch/arm/src/armv6-m/arm_sigdeliver.c index 4d6228ea3fb68..d9ce126b9e541 100644 --- a/arch/arm/src/armv6-m/arm_sigdeliver.c +++ b/arch/arm/src/armv6-m/arm_sigdeliver.c @@ -165,6 +165,7 @@ void arm_sigdeliver(void) rtcb->irqcount--; #endif + g_running_tasks[this_cpu()] = NULL; rtcb->xcp.regs = rtcb->xcp.saved_regs; arm_fullcontextrestore(); UNUSED(regs); diff --git a/arch/arm/src/common/arm_exit.c b/arch/arm/src/common/arm_exit.c index 09a0f481d0b07..1f184e6bce661 100644 --- a/arch/arm/src/common/arm_exit.c +++ b/arch/arm/src/common/arm_exit.c @@ -60,9 +60,18 @@ void up_exit(int status) nxtask_exit(); - /* Scheduler parameters will update inside syscall */ + /* Update g_running_tasks */ +#ifdef CONFIG_ARCH_ARMV6M + /* ARMV6M syscal may trigger hard fault, We use + * running_task != NULL to determine whether it is + * a context for restoration. + */ + + g_running_tasks[this_cpu()] = NULL; +#else g_running_tasks[this_cpu()] = this_task(); +#endif /* Then switch contexts */