Skip to contentSkip to conversation

Fix qemu endless loop when raising a SIGSEGV/SIGBUS signal with gdbstub in user emulation

PATCH In review Lionel Landwerlin 2 participants 3 messages Jan 3, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix qemu endless loop when raising a SIGSEGV/SIGBUS signal with gdbstub in user emulation

Let's compile a very simple program :

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int
main (int argc, char *argv[])

{
        int *i = NULL;

        sleep (1);

        *i = 42;

        return EXIT_SUCCESS;
}

Now run this program under qemu with gdbstub :

qemu -g 1234 ./test-segfault

Run gdb on the same program, connect it to qemu and start execution. This program will raise a SIGSEGV signal and qemu will be locked in an endless loop. Gdb will never be notify by qemu of SIGSEGV signal.

The following post provides a fix for that.

Regards,

Signature · 3 lines
Lione Landwerlin                                         

O p e n W i d e                    14, rue Gaillon 75002 Paris
#1 lore raw

When a SIGSEGV signal is raised in user mode emulation the current test to know whether the signal is sent by the kernel is wrong :

info->si_code == SI_KERNEL

according to /usr/include/bits/siginfo.h it should be

info->si_code > 0

/* Values for `si_code'. Positive values are reserved for kernel-generated
signals. */

there is a lot of enums for that, all starting at positives values :

/* `si_code' values for SIGILL signal. */
enum
{
ILL_ILLOPC = 1, /* Illegal opcode. */
...

/* `si_code' values for SIGFPE signal. */
enum
{
FPE_INTDIV = 1, /* Integer divide by zero. */
...

/* `si_code' values for SIGSEGV signal. */
enum
{
SEGV_MAPERR = 1, /* Address not mapped to object. */
....

---
 linux-user/signal.c |   4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
linux-user/signal.c +2 -2
index 5e30522..0d81106 100644
@@ -441,9 +441,9 @@ static void host_signal_handler(int host_signum, siginfo_t *info,
     target_siginfo_t tinfo;
 
     /* the CPU emulator uses some host signals to detect exceptions,
-       we we forward to it some signals */
+       we forward to it some signals */
     if ((host_signum == SIGSEGV || host_signum == SIGBUS)
-        && info->si_code == SI_KERNEL) {
+        && info->si_code > 0) {
         if (cpu_signal_handler(host_signum, info, puc))
             return;
     }
Signature · 7 lines
1.5.6.5


-- 
Lione Landwerlin                                         

O p e n W i d e                    14, rue Gaillon 75002 Paris
#2 lore raw
Quoted 9 lines · Lionel Landwerlin

When a SIGSEGV signal is raised in user mode emulation the current test to know whether the signal is sent by the kernel is wrong :

info->si_code == SI_KERNEL

according to /usr/include/bits/siginfo.h it should be

info->si_code > 0

We were working on the same thing at the same time, but you has been faster :) Patch applied, thanks.

Signature · 4 lines
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   [email protected]         | [email protected]
   `-    people.debian.org/~aurel32 | www.aurel32.net