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

Mikulas Patocka posted 1 patch 2 weeks ago
Failed in applying to current master (apply log)
There is a newer version of this series
linux-user/sh4/cpu_loop.c |    4 ++++
1 file changed, 4 insertions(+)
[PATCH] linux-user/sh4: Deliver SIGILL on invalid instruction
Posted by Mikulas Patocka 2 weeks 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 |    4 ++++
 1 file changed, 4 insertions(+)

Index: qemu/linux-user/sh4/cpu_loop.c
===================================================================
--- qemu.orig/linux-user/sh4/cpu_loop.c	2026-08-02 19:02:25.000000000 +0200
+++ qemu/linux-user/sh4/cpu_loop.c	2026-08-02 19:06:40.000000000 +0200
@@ -64,6 +64,10 @@ void cpu_loop(CPUSH4State *env)
             cpu_exec_step_atomic(cs);
             arch_interrupt = false;
             break;
+        case 0x180:
+            /* Illegal instruction */
+            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] linux-user/sh4: Deliver SIGILL on invalid instruction
Posted by Richard Henderson 1 week, 5 days ago
On 8/3/26 12:42, 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 |    4 ++++
>   1 file changed, 4 insertions(+)
> 
> Index: qemu/linux-user/sh4/cpu_loop.c
> ===================================================================
> --- qemu.orig/linux-user/sh4/cpu_loop.c	2026-08-02 19:02:25.000000000 +0200
> +++ qemu/linux-user/sh4/cpu_loop.c	2026-08-02 19:06:40.000000000 +0200
> @@ -64,6 +64,10 @@ void cpu_loop(CPUSH4State *env)
>               cpu_exec_step_atomic(cs);
>               arch_interrupt = false;
>               break;
> +        case 0x180:
> +            /* Illegal instruction */
> +            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);
> 

Missing 0x1a0, from helper_raise_slot_illegal_instruction.

r~
Re: [PATCH] linux-user/sh4: Deliver SIGILL on invalid instruction
Posted by Mikulas Patocka 1 week, 5 days ago

On Wed, 5 Aug 2026, Richard Henderson wrote:

> On 8/3/26 12:42, 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 |    4 ++++
> >   1 file changed, 4 insertions(+)
> > 
> > Index: qemu/linux-user/sh4/cpu_loop.c
> > ===================================================================
> > --- qemu.orig/linux-user/sh4/cpu_loop.c	2026-08-02 19:02:25.000000000
> > +0200
> > +++ qemu/linux-user/sh4/cpu_loop.c	2026-08-02 19:06:40.000000000 +0200
> > @@ -64,6 +64,10 @@ void cpu_loop(CPUSH4State *env)
> >               cpu_exec_step_atomic(cs);
> >               arch_interrupt = false;
> >               break;
> > +        case 0x180:
> > +            /* Illegal instruction */
> > +            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);
> > 
> 
> Missing 0x1a0, from helper_raise_slot_illegal_instruction.
> 
> r~

OK, I'm sending version 2 of the patch.

Mikulas
Re: [PATCH] linux-user/sh4: Deliver SIGILL on invalid instruction
Posted by yoshinori.sato@nifty.com 1 week, 6 days ago
On Tue, 04 Aug 2026 04:42:29 +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 |    4 ++++
>  1 file changed, 4 insertions(+)
> 
> Index: qemu/linux-user/sh4/cpu_loop.c
> ===================================================================
> --- qemu.orig/linux-user/sh4/cpu_loop.c	2026-08-02 19:02:25.000000000 +0200
> +++ qemu/linux-user/sh4/cpu_loop.c	2026-08-02 19:06:40.000000000 +0200
> @@ -64,6 +64,10 @@ void cpu_loop(CPUSH4State *env)
>              cpu_exec_step_atomic(cs);
>              arch_interrupt = false;
>              break;
> +        case 0x180:
> +            /* Illegal instruction */
> +            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