Skip to content

Commit

Permalink
arch: set (*running_task)->xcp.regs to NULL when exit from irq/exception
Browse files Browse the repository at this point in the history
reason:
(*running_task)->xcp.regs is invalid when in threadcontext, we marke it as NULL to avoid misusage

Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 authored and xiaoxiang781216 committed Jan 22, 2025
1 parent 4211ce3 commit a095b1d
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 6 deletions.
9 changes: 8 additions & 1 deletion arch/arm/src/arm/arm_syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,12 @@ uint32_t *arm_syscall(uint32_t *regs)
* SYS_context_switch system call.
*/

return tcb->xcp.regs;
regs = tcb->xcp.regs;

/* (*running_task)->xcp.regs is about to become invalid
* and will be marked as NULL to avoid misusage.
*/

(*running_task)->xcp.regs = NULL;
return regs;
}
5 changes: 5 additions & 0 deletions arch/arm/src/armv6-m/arm_doirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,10 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)

board_autoled_off(LED_INIRQ);

/* (*running_task)->xcp.regs is about to become invalid
* and will be marked as NULL to avoid misusage.
*/

(*running_task)->xcp.regs = NULL;
return regs;
}
6 changes: 6 additions & 0 deletions arch/arm/src/armv7-a/arm_doirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,11 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
#endif

board_autoled_off(LED_INIRQ);

/* (*running_task)->xcp.regs is about to become invalid
* and will be marked as NULL to avoid misusage.
*/

tcb->xcp.regs = NULL;
return regs;
}
6 changes: 6 additions & 0 deletions arch/arm/src/armv7-a/arm_syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,12 @@ uint32_t *arm_syscall(uint32_t *regs)

up_set_interrupt_context(false);

/* (*running_task)->xcp.regs is about to become invalid
* and will be marked as NULL to avoid misusage.
*/

(*running_task)->xcp.regs = NULL;

/* Return the last value of curent_regs. This supports context switches
* on return from the exception. That capability is only used with the
* SYS_context_switch system call.
Expand Down
5 changes: 5 additions & 0 deletions arch/arm/src/armv7-m/arm_doirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,10 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)

board_autoled_off(LED_INIRQ);

/* (*running_task)->xcp.regs is about to become invalid
* and will be marked as NULL to avoid misusage.
*/

(*running_task)->xcp.regs = NULL;
return regs;
}
6 changes: 6 additions & 0 deletions arch/arm/src/armv7-r/arm_syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,12 @@ uint32_t *arm_syscall(uint32_t *regs)

up_set_interrupt_context(false);

/* (*running_task)->xcp.regs is about to become invalid
* and will be marked as NULL to avoid misusage.
*/

(*running_task)->xcp.regs = NULL;

/* Return the last value of curent_regs. This supports context switches
* on return from the exception. That capability is only used with the
* SYS_context_switch system call.
Expand Down
5 changes: 5 additions & 0 deletions arch/arm/src/armv8-m/arm_doirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,10 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
}
#endif

/* (*running_task)->xcp.regs is about to become invalid
* and will be marked as NULL to avoid misusage.
*/

(*running_task)->xcp.regs = NULL;
return regs;
}
6 changes: 6 additions & 0 deletions arch/arm/src/armv8-r/arm_syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,12 @@ uint32_t *arm_syscall(uint32_t *regs)

up_set_interrupt_context(false);

/* (*running_task)->xcp.regs is about to become invalid
* and will be marked as NULL to avoid misusage.
*/

(*running_task)->xcp.regs = NULL;

/* Return the last value of curent_regs. This supports context switches
* on return from the exception. That capability is only used with the
* SYS_context_switch system call.
Expand Down
5 changes: 5 additions & 0 deletions arch/arm64/src/common/arm64_doirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ uint64_t *arm64_doirq(int irq, uint64_t * regs)

write_sysreg((uintptr_t)tcb & ~1ul, tpidr_el1);

/* (*running_task)->xcp.regs is about to become invalid
* and will be marked as NULL to avoid misusage.
*/

tcb->xcp.regs = NULL;
return regs;
}

Expand Down
9 changes: 8 additions & 1 deletion arch/arm64/src/common/arm64_syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,5 +324,12 @@ uint64_t *arm64_syscall(uint64_t *regs)
break;
}

return tcb->xcp.regs;
regs = tcb->xcp.regs;

/* (*running_task)->xcp.regs is about to become invalid
* and will be marked as NULL to avoid misusage.
*/

(*running_task)->xcp.regs = NULL;
return regs;
}
6 changes: 6 additions & 0 deletions arch/ceva/src/common/ceva_doirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ uint32_t *ceva_doirq(int irq, uint32_t *regs)
memcpy((uint32_t *)regs[REG_SP], regs, XCPTCONTEXT_SIZE);
regs = (uint32_t *)regs[REG_SP];
}

/* (*running_task)->xcp.regs is about to become invalid
* and will be marked as NULL to avoid misusage.
*/

(*running_task)->xcp.regs = NULL;
}

return regs;
Expand Down
6 changes: 6 additions & 0 deletions arch/hc/src/common/hc_doirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,11 @@ uint8_t *hc_doirq(int irq, uint8_t *regs)
up_set_current_regs(NULL);
#endif
board_autoled_off(LED_INIRQ);

/* (*running_task)->xcp.regs is about to become invalid
* and will be marked as NULL to avoid misusage.
*/

(*running_task)->xcp.regs = NULL;
return regs;
}
10 changes: 9 additions & 1 deletion arch/risc-v/src/common/riscv_doirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,13 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs)

#endif
board_autoled_off(LED_INIRQ);
return tcb->xcp.regs;

regs = tcb->xcp.regs;

/* (*running_task)->xcp.regs is about to become invalid
* and will be marked as NULL to avoid misusage.
*/

(*running_task)->xcp.regs = NULL;
return regs;
}
9 changes: 8 additions & 1 deletion arch/risc-v/src/common/supervisor/riscv_perform_syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,12 @@ void *riscv_perform_syscall(uintreg_t *regs)

up_set_interrupt_context(false);

return tcb->xcp.regs;
regs = tcb->xcp.regs;

/* (*running_task)->xcp.regs is about to become invalid
* and will be marked as NULL to avoid misusage.
*/

(*running_task)->xcp.regs = NULL;
return regs;
}
5 changes: 5 additions & 0 deletions arch/tricore/src/common/tricore_doirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ IFX_INTERRUPT_INTERNAL(tricore_doirq, 0, 255)

up_set_current_regs(NULL);

/* (*running_task)->xcp.regs is about to become invalid
* and will be marked as NULL to avoid misusage.
*/

(*running_task)->xcp.regs = NULL;
board_autoled_off(LED_INIRQ);
#endif
}
8 changes: 7 additions & 1 deletion arch/x86_64/src/intel64/intel64_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,14 @@ static uint64_t *common_handler(int irq, uint64_t *regs)
/* Clear irq flag */

up_set_interrupt_context(false);
regs = tcb->xcp.regs;

return tcb->xcp.regs;
/* (*running_task)->xcp.regs is about to become invalid
* and will be marked as NULL to avoid misusage.
*/

(*running_task)->xcp.regs = NULL;
return regs;
}
#endif

Expand Down
10 changes: 9 additions & 1 deletion arch/xtensa/src/common/xtensa_irqdispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,13 @@ uint32_t *xtensa_irq_dispatch(int irq, uint32_t *regs)
#endif

board_autoled_off(LED_INIRQ);
return tcb->xcp.regs;

regs = tcb->xcp.regs;

/* (*running_task)->xcp.regs is about to become invalid
* and will be marked as NULL to avoid misusage.
*/

(*running_task)->xcp.regs = NULL;
return regs;
}

0 comments on commit a095b1d

Please sign in to comment.