arch/mips/pic32mx: record the running task on interrupt exit.

pic32mx_decodeirq() saves the interrupted context into
g_running_tasks[this_cpu()]->xcp.regs on entry, but nothing updates
g_running_tasks[] after a context switch: every interrupt saves the
context into the Idle task's TCB, and once a task exits (up_exit() sets
the entry to NULL) no context is saved at all and the next context
switch restores stale registers.

Set g_running_tasks[this_cpu()] to this_task() before returning, as
pic32mz_decodeirq() does.  This is the same bug that crashed the
PIC32MZ-W1 when the netinit thread exited.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
This commit is contained in:
Daniel P. Carvalho 2026-10-04 01:08:08 -03:00 • committed by Alan C. Assis
parent 4f7de715a7
commit d4097a27e2

View file

@ -36,6 +36,7 @@
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
#include <sched/sched.h>
#include "mips_internal.h"
#include "pic32mx_int.h"
@ -141,6 +142,12 @@ uint32_t *pic32mx_decodeirq(uint32_t *regs)
regs = up_current_regs();
/* Record the task that will run when the interrupt returns. Its state
* is saved to its TCB on the next interrupt entry (see above).
*/
*running_task = this_task();
#if defined(CONFIG_ARCH_FPU) || defined(CONFIG_ARCH_ADDRENV)
/* Check for a context switch. If a context switch occurred, then
* g_current_regs will have a different value than it did on entry. If an