mirror of
https://github.com/apache/nuttx.git
synced 2026-05-26 02:36:11 +08:00
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:
@@ -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);
|
||||
|
||||
@@ -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 */
|
||||
|
||||
|
||||
@@ -121,6 +121,7 @@ static uint32_t *common_handler(int irq, uint32_t *regs)
|
||||
*/
|
||||
|
||||
addrenv_switch(tcb);
|
||||
tcb = this_task();
|
||||
#endif
|
||||
|
||||
/* Update scheduler parameters */
|
||||
|
||||
Reference in New Issue
Block a user