Skip to content

Commit

Permalink
arch/risc-v/src/common/riscv_exception.c: Just _exit the user task ca…
Browse files Browse the repository at this point in the history
…using an exception

We shouldn't panic the kernel when a user task excepts, we can just kill the user task and
it's children.

Signed-off-by: Jukka Laitinen <[email protected]>
  • Loading branch information
jlaitine committed Mar 19, 2024
1 parent b524715 commit 114b7cb
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions arch/risc-v/src/common/riscv_exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>

#include "sched/sched.h"
#include "riscv_internal.h"
#include "chip.h"

Expand Down Expand Up @@ -72,17 +73,26 @@ static const char *g_reasons_str[RISCV_MAX_EXCEPTION + 1] =

int riscv_exception(int mcause, void *regs, void *args)
{
FAR struct tcb_s *tcb = this_task();
uintptr_t cause = mcause & RISCV_IRQ_MASK;

_alert("EXCEPTION: %s. MCAUSE: %" PRIxREG ", EPC: %" PRIxREG
", MTVAL: %" PRIxREG "\n",
mcause > RISCV_MAX_EXCEPTION ? "Unknown" : g_reasons_str[cause],
cause, READ_CSR(CSR_EPC), READ_CSR(CSR_TVAL));

_alert("PANIC!!! Exception = %" PRIxREG "\n", cause);
up_irq_save();
CURRENT_REGS = regs;
PANIC_WITH_REGS("panic", regs);
if ((tcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_KERNEL)
{
tcb->flags |= TCB_FLAG_FORCED_CANCEL;
_exit(SIGSEGV);
}
else
{
_alert("PANIC!!! Exception = %" PRIxREG "\n", cause);
up_irq_save();
CURRENT_REGS = regs;
PANIC_WITH_REGS("panic", regs);
}

return 0;
}
Expand Down

0 comments on commit 114b7cb

Please sign in to comment.