Skip to content

Commit 408b1d3

Browse files
committed
xtensa: add trap handler for division by zero
Add c-level handler for the division by zero exception and kill the task if it was thrown from the kernel space or send SIGFPE otherwise. Signed-off-by: Max Filippov <[email protected]>
1 parent b011946 commit 408b1d3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

arch/xtensa/kernel/traps.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
*/
5050

5151
static void do_illegal_instruction(struct pt_regs *regs);
52+
static void do_div0(struct pt_regs *regs);
5253
static void do_interrupt(struct pt_regs *regs);
5354
#if XTENSA_FAKE_NMI
5455
static void do_nmi(struct pt_regs *regs);
@@ -95,7 +96,7 @@ static dispatch_init_table_t __initdata dispatch_init_table[] = {
9596
#ifdef SUPPORT_WINDOWED
9697
{ EXCCAUSE_ALLOCA, USER|KRNL, fast_alloca },
9798
#endif
98-
/* EXCCAUSE_INTEGER_DIVIDE_BY_ZERO unhandled */
99+
{ EXCCAUSE_INTEGER_DIVIDE_BY_ZERO, 0, do_div0 },
99100
/* EXCCAUSE_PRIVILEGED unhandled */
100101
#if XCHAL_UNALIGNED_LOAD_EXCEPTION || XCHAL_UNALIGNED_STORE_EXCEPTION
101102
#ifdef CONFIG_XTENSA_UNALIGNED_USER
@@ -307,6 +308,11 @@ static void do_illegal_instruction(struct pt_regs *regs)
307308
force_sig(SIGILL);
308309
}
309310

311+
static void do_div0(struct pt_regs *regs)
312+
{
313+
__die_if_kernel("Unhandled division by 0 in kernel", regs, SIGKILL);
314+
force_sig_fault(SIGFPE, FPE_INTDIV, (void __user *)regs->pc);
315+
}
310316

311317
/*
312318
* Handle unaligned memory accesses from user space. Kill task.

0 commit comments

Comments
 (0)