Skip to contentSkip to conversation

mips: fix abort on integer overflow

PATCH Superseded Mikulas Patocka 2 participants 4 messages Sep 24, 2023 – Oct 3, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mips: fix abort on integer overflow

Qemu mips userspace emulation crashes with "qemu: unhandled CPU exception 0x15 - aborting" when one of the integer arithmetic instructions detects an overflow.

This patch fixes it so that it delivers SIGFPE with FPE_INTOVF instead.

---
 linux-user/mips/cpu_loop.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
linux-user/mips/cpu_loop.c +3 -1
Index: qemu/linux-user/mips/cpu_loop.c
===================================================================
@@ -180,7 +180,9 @@ done_syscall:
             }
             force_sig_fault(TARGET_SIGFPE, si_code, env->active_tc.PC);
             break;
-
+	case EXCP_OVERFLOW:
+            do_tr_or_bp(env, BRK_OVERFLOW, false);
+            break;
         /* The code below was inspired by the MIPS Linux kernel trap
          * handling code in arch/mips/kernel/traps.c.
          */
#1 lore raw
Quoted 18 lines · Mikulas Patocka

Qemu mips userspace emulation crashes with "qemu: unhandled CPU exception 0x15 - aborting" when one of the integer arithmetic instructions detects an overflow.

This patch fixes it so that it delivers SIGFPE with FPE_INTOVF instead.

---
  linux-user/mips/cpu_loop.c |    4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

Index: qemu/linux-user/mips/cpu_loop.c
===================================================================

linux-user/mips/cpu_loop.c done_syscall: · line 185

Quoted 7 lines
linux-user/mips/cpu_loop.c +3 -1
@@ -180,7 +180,9 @@ done_syscall:
              }
              force_sig_fault(TARGET_SIGFPE, si_code, env->active_tc.PC);
              break;
-
+	case EXCP_OVERFLOW:
+            do_tr_or_bp(env, BRK_OVERFLOW, false);
+            break;

Just call force_sig_fault directly.

r~

#2 lore raw

PATCH v2 1/1 mips: fix abort on integer overflow

Quoted 4 lines · Richard Henderson

Just call force_sig_fault directly.

r~

OK. Here I'm resending it.

Mikulas

From: Mikulas Patocka <[email protected]>

Qemu mips userspace emulation crashes with "qemu: unhandled CPU exception 0x15 - aborting" when one of the integer arithmetic instructions detects an overflow.

This patch fixes it so that it delivers SIGFPE with FPE_INTOVF instead.

---
 linux-user/mips/cpu_loop.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
linux-user/mips/cpu_loop.c +3 -1
Index: qemu/linux-user/mips/cpu_loop.c
===================================================================
@@ -180,7 +180,9 @@ done_syscall:
             }
             force_sig_fault(TARGET_SIGFPE, si_code, env->active_tc.PC);
             break;
-
+	case EXCP_OVERFLOW:
+            force_sig_fault(TARGET_SIGFPE, TARGET_FPE_INTOVF, env->active_tc.PC);
+            break;
         /* The code below was inspired by the MIPS Linux kernel trap
          * handling code in arch/mips/kernel/traps.c.
          */
Reviewed-by on v2 1/1
#3 lore raw
Quoted 17 lines · Mikulas Patocka
Quoted 4 lines · Richard Henderson

Just call force_sig_fault directly.

r~

OK. Here I'm resending it.

Mikulas

From: Mikulas Patocka <[email protected]>

Quoted 8 lines

Qemu mips userspace emulation crashes with "qemu: unhandled CPU exception 0x15 - aborting" when one of the integer arithmetic instructions detects an overflow.

This patch fixes it so that it delivers SIGFPE with FPE_INTOVF instead.

and queued to linux-user-next.

r~