diff mbox series

linux-user/hppa: Fix segfaults on page zero

Message ID Ysc3vc0T+qfjiyKo@p100 (mailing list archive)
State New, archived
Headers show
Series linux-user/hppa: Fix segfaults on page zero | expand

Commit Message

Helge Deller July 7, 2022, 7:45 p.m. UTC
This program:

    int main(void) { asm("bv %r0(%r0)"); return 0; }

produces on real hardware the expected segfault:

--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x3} ---
+++ killed by SIGSEGV +++
Segmentation fault

But when run on linux-user you get instead internal qemu errors:

ERROR: linux-user/hppa/cpu_loop.c:172:cpu_loop: code should not be reached
Bail out! ERROR: linux-user/hppa/cpu_loop.c:172:cpu_loop: code should not be reached
ERROR: accel/tcg/cpu-exec.c:933:cpu_exec: assertion failed: (cpu == current_cpu)
Bail out! ERROR: accel/tcg/cpu-exec.c:933:cpu_exec: assertion failed: (cpu == current_cpu)

Fix it by adding the missing case for the EXCP_IMP trap in
cpu_loop() and raise a segfault.

Signed-off-by: Helge Deller <deller@gmx.de>

Comments

Philippe Mathieu-Daudé July 12, 2022, 10:31 p.m. UTC | #1
On 7/7/22 21:45, Helge Deller wrote:
> This program:
> 
>      int main(void) { asm("bv %r0(%r0)"); return 0; }
> 
> produces on real hardware the expected segfault:
> 
> --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x3} ---
> +++ killed by SIGSEGV +++
> Segmentation fault
> 
> But when run on linux-user you get instead internal qemu errors:
> 
> ERROR: linux-user/hppa/cpu_loop.c:172:cpu_loop: code should not be reached
> Bail out! ERROR: linux-user/hppa/cpu_loop.c:172:cpu_loop: code should not be reached
> ERROR: accel/tcg/cpu-exec.c:933:cpu_exec: assertion failed: (cpu == current_cpu)
> Bail out! ERROR: accel/tcg/cpu-exec.c:933:cpu_exec: assertion failed: (cpu == current_cpu)
> 
> Fix it by adding the missing case for the EXCP_IMP trap in
> cpu_loop() and raise a segfault.
> 
> Signed-off-by: Helge Deller <deller@gmx.de>
> 
> diff --git a/linux-user/hppa/cpu_loop.c b/linux-user/hppa/cpu_loop.c
> index a576d1a249..8f374aeef6 100644
> --- a/linux-user/hppa/cpu_loop.c
> +++ b/linux-user/hppa/cpu_loop.c
> @@ -143,6 +143,9 @@ void cpu_loop(CPUHPPAState *env)
>               env->iaoq_f = env->gr[31];
>               env->iaoq_b = env->gr[31] + 4;
>               break;
> +        case EXCP_IMP:
> +            force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR, env->iaoq_f);
> +            break;
>           case EXCP_ILL:
>               force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->iaoq_f);
>               break;

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
diff mbox series

Patch

diff --git a/linux-user/hppa/cpu_loop.c b/linux-user/hppa/cpu_loop.c
index a576d1a249..8f374aeef6 100644
--- a/linux-user/hppa/cpu_loop.c
+++ b/linux-user/hppa/cpu_loop.c
@@ -143,6 +143,9 @@  void cpu_loop(CPUHPPAState *env)
             env->iaoq_f = env->gr[31];
             env->iaoq_b = env->gr[31] + 4;
             break;
+        case EXCP_IMP:
+            force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR, env->iaoq_f);
+            break;
         case EXCP_ILL:
             force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->iaoq_f);
             break;