arch: fix addrenv_switch changing this_task causing exceptions

After addrenv_switch(), the current running task (this_task) may change due to
deferred work execution. Update all architecture interrupt, syscall, and exit
handlers to re-fetch tcb = this_task() after addrenv_switch(). Ensures scheduler
and context operations use the correct TCB, preventing context corruption and
exceptions across SMP and memory-protected builds.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5
2025-05-06 19:24:52 +08:00
committed by Alan C. Assis
parent 113bb02568
commit 657ac8317e
35 changed files with 92 additions and 50 deletions
+7 -6
View File
@@ -67,12 +67,6 @@ void up_exit(int status)
tcb = this_task();
/* Adjusts time slice for SCHED_RR & SCHED_SPORADIC cases
* NOTE: the API also adjusts the global IRQ control for SMP
*/
g_running_tasks[this_cpu()] = tcb;
#ifdef CONFIG_ARCH_ADDRENV
/* Make sure that the address environment for the previously running
* task is closed down gracefully (data caches dump, MMU flushed) and
@@ -81,8 +75,15 @@ void up_exit(int status)
*/
addrenv_switch(tcb);
tcb = this_task();
#endif
/* Adjusts time slice for SCHED_RR & SCHED_SPORADIC cases
* NOTE: the API also adjusts the global IRQ control for SMP
*/
g_running_tasks[this_cpu()] = tcb;
/* Then switch contexts */
x86_fullcontextrestore(tcb->xcp.regs);
+1
View File
@@ -91,6 +91,7 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb)
*/
addrenv_switch(tcb);
tcb = this_task();
#endif
/* Update scheduler parameters */
+1
View File
@@ -121,6 +121,7 @@ static uint32_t *common_handler(int irq, uint32_t *regs)
*/
addrenv_switch(tcb);
tcb = this_task();
#endif
/* Update scheduler parameters */