Skip to content

Commit

Permalink
fix regresion from apache#14881
Browse files Browse the repository at this point in the history
reason:
svc call may trigger hardfalt

Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 committed Dec 6, 2024
1 parent 1e49cb4 commit 36797cd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
13 changes: 12 additions & 1 deletion arch/arm/src/armv6-m/arm_doirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ void exception_direct(void)
}
}

static inline_function bool restore_context(int irq, uint32_t *regs)
{
if ((NVIC_IRQ_SVCALL == irq || NVIC_IRQ_HARDFAULT == irq) &&
regs[REG_R0] == SYS_restore_context)
{
return true;
}

return false;
}

uint32_t *arm_doirq(int irq, uint32_t *regs)
{
struct tcb_s **running_task = &g_running_tasks[this_cpu()];
Expand All @@ -65,7 +76,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 (!restore_context(irq, regs))
{
tcb->xcp.regs = regs;
}
Expand Down
13 changes: 12 additions & 1 deletion arch/arm/src/armv7-m/arm_doirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ void exception_direct(void)
}
}

static inline_function bool restore_context(int irq, uint32_t *regs)
{
if ((NVIC_IRQ_SVCALL == irq || NVIC_IRQ_HARDFAULT == irq) &&
regs[REG_R0] == SYS_restore_context)
{
return true;
}

return false;
}

uint32_t *arm_doirq(int irq, uint32_t *regs)
{
struct tcb_s **running_task = &g_running_tasks[this_cpu()];
Expand All @@ -65,7 +76,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 (!restore_context(irq, regs))
{
tcb->xcp.regs = regs;
}
Expand Down
13 changes: 12 additions & 1 deletion arch/arm/src/armv8-m/arm_doirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ void exception_direct(void)
}
}

static inline_function bool restore_context(int irq, uint32_t *regs)
{
if ((NVIC_IRQ_SVCALL == irq || NVIC_IRQ_HARDFAULT == irq) &&
regs[REG_R0] == SYS_restore_context)
{
return true;
}

return false;
}

uint32_t *arm_doirq(int irq, uint32_t *regs)
{
struct tcb_s **running_task = &g_running_tasks[this_cpu()];
Expand All @@ -76,7 +87,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 (!restore_context(irq, regs))
{
tcb->xcp.regs = regs;
}
Expand Down

0 comments on commit 36797cd

Please sign in to comment.