[PATCH v2] linux-user/sh4: Deliver SIGILL on invalid instruction

Mikulas Patocka posted 1 patch 2 weeks, 6 days ago
Failed in applying to current master (apply log)
linux-user/sh4/cpu_loop.c |    7 +++++++
1 file changed, 7 insertions(+)
[PATCH v2] linux-user/sh4: Deliver SIGILL on invalid instruction
Posted by Mikulas Patocka 2 weeks, 6 days ago
On invalid instruction, deliver SIGILL rather than crashing the whole
process unconditionally.

Cc: qemu-stable@nongnu.org
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

---
 linux-user/sh4/cpu_loop.c |    7 +++++++
 1 file changed, 7 insertions(+)

Index: qemu/linux-user/sh4/cpu_loop.c
===================================================================
--- qemu.orig/linux-user/sh4/cpu_loop.c	2026-08-05 18:05:44.000000000 +0200
+++ qemu/linux-user/sh4/cpu_loop.c	2026-08-05 18:12:12.000000000 +0200
@@ -64,6 +64,13 @@ void cpu_loop(CPUSH4State *env)
             cpu_exec_step_atomic(cs);
             arch_interrupt = false;
             break;
+        case 0x180:
+            /* Illegal instruction */
+            /* fallthrough */
+        case 0x1a0:
+            /* Illegal instruction in delay slot */
+            force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc);
+            break;
         default:
             fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr);
             cpu_dump_state(cs, stderr, 0);
Re: [PATCH v2] linux-user/sh4: Deliver SIGILL on invalid instruction
Posted by yoshinori.sato@nifty.com 2 weeks, 6 days ago
On Thu, 06 Aug 2026 01:23:04 +0900,
Mikulas Patocka wrote:
> 
> On invalid instruction, deliver SIGILL rather than crashing the whole
> process unconditionally.
> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> 
> ---
>  linux-user/sh4/cpu_loop.c |    7 +++++++
>  1 file changed, 7 insertions(+)
> 
> Index: qemu/linux-user/sh4/cpu_loop.c
> ===================================================================
> --- qemu.orig/linux-user/sh4/cpu_loop.c	2026-08-05 18:05:44.000000000 +0200
> +++ qemu/linux-user/sh4/cpu_loop.c	2026-08-05 18:12:12.000000000 +0200
> @@ -64,6 +64,13 @@ void cpu_loop(CPUSH4State *env)
>              cpu_exec_step_atomic(cs);
>              arch_interrupt = false;
>              break;
> +        case 0x180:
> +            /* Illegal instruction */
> +            /* fallthrough */
> +        case 0x1a0:
> +            /* Illegal instruction in delay slot */
> +            force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc);
> +            break;
>          default:
>              fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr);
>              cpu_dump_state(cs, stderr, 0);
> 

Reviewed-by: Yoshinori Sato <yoshinori.sato@nifty.com>

-- 
Yosinori Sato
Re: [PATCH v2] linux-user/sh4: Deliver SIGILL on invalid instruction
Posted by Richard Henderson 2 weeks, 6 days ago
On 8/5/26 09:23, Mikulas Patocka wrote:
> On invalid instruction, deliver SIGILL rather than crashing the whole
> process unconditionally.
> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> 
> ---
>   linux-user/sh4/cpu_loop.c |    7 +++++++
>   1 file changed, 7 insertions(+)
> 
> Index: qemu/linux-user/sh4/cpu_loop.c
> ===================================================================
> --- qemu.orig/linux-user/sh4/cpu_loop.c	2026-08-05 18:05:44.000000000 +0200
> +++ qemu/linux-user/sh4/cpu_loop.c	2026-08-05 18:12:12.000000000 +0200
> @@ -64,6 +64,13 @@ void cpu_loop(CPUSH4State *env)
>               cpu_exec_step_atomic(cs);
>               arch_interrupt = false;
>               break;
> +        case 0x180:
> +            /* Illegal instruction */
> +            /* fallthrough */
> +        case 0x1a0:
> +            /* Illegal instruction in delay slot */
> +            force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc);
> +            break;
>           default:
>               fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr);
>               cpu_dump_state(cs, stderr, 0);
> 

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~