File kvm-qemu-preXX-32bit-breakpoint-crash.patch of Package kvm

commit 63a54736f31f9e11da6fb52319bba26e7d24f571
Author: Jason Wessel <jason.wessel@windriver.com>
Date:   Tue Jan 26 16:29:50 2010 -0600

    target-i386: fix crash on x86 32bit linux host with hw breakpoint exceptions
    
    If you make use of hw breakpoints on a 32bit x86 linux host, qemu
    will segmentation fault when processing the exception.
    
    The problem is that the value of env is stored in $ebp in the op_helper
    raise_exception() function, and it can have the wrong value when
    calling it from non generated code.
    
    It is possible to work around the problem by restoring the value of
    env before calling raise_exception() using a new helper function that
    takes (CPUState *) as one of the arguments.
    
    Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
    Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>

Index: qemu-kvm-0.12.3/target-i386/exec.h
===================================================================
--- qemu-kvm-0.12.3.orig/target-i386/exec.h
+++ qemu-kvm-0.12.3/target-i386/exec.h
@@ -73,6 +73,7 @@ void do_interrupt_user(int intno, int is
                        target_ulong next_eip);
 void QEMU_NORETURN raise_exception_err(int exception_index, int error_code);
 void QEMU_NORETURN raise_exception(int exception_index);
+void QEMU_NORETURN raise_exception_env(int exception_index, CPUState *nenv);
 void do_smm_enter(void);
 
 /* n must be a constant to be efficient */
Index: qemu-kvm-0.12.3/target-i386/helper.c
===================================================================
--- qemu-kvm-0.12.3.orig/target-i386/helper.c
+++ qemu-kvm-0.12.3/target-i386/helper.c
@@ -1512,7 +1512,7 @@ int check_hw_breakpoints(CPUState *env,
 
 static CPUDebugExcpHandler *prev_debug_excp_handler;
 
-void raise_exception(int exception_index);
+void raise_exception_env(int exception_index, CPUState *env);
 
 static void breakpoint_handler(CPUState *env)
 {
@@ -1522,7 +1522,7 @@ static void breakpoint_handler(CPUState
         if (env->watchpoint_hit->flags & BP_CPU) {
             env->watchpoint_hit = NULL;
             if (check_hw_breakpoints(env, 0))
-                raise_exception(EXCP01_DB);
+                raise_exception_env(EXCP01_DB, env);
             else
                 cpu_resume_from_signal(env, NULL);
         }
@@ -1531,7 +1531,7 @@ static void breakpoint_handler(CPUState
             if (bp->pc == env->eip) {
                 if (bp->flags & BP_CPU) {
                     check_hw_breakpoints(env, 1);
-                    raise_exception(EXCP01_DB);
+                    raise_exception_env(EXCP01_DB, env);
                 }
                 break;
             }
Index: qemu-kvm-0.12.3/target-i386/op_helper.c
===================================================================
--- qemu-kvm-0.12.3.orig/target-i386/op_helper.c
+++ qemu-kvm-0.12.3/target-i386/op_helper.c
@@ -1351,6 +1351,11 @@ void raise_exception(int exception_index
     raise_interrupt(exception_index, 0, 0, 0);
 }
 
+void raise_exception_env(int exception_index, CPUState *nenv)
+{
+    env = nenv;
+    raise_exception(exception_index);
+}
 /* SMM support */
 
 #if defined(CONFIG_USER_ONLY)
openSUSE Build Service is sponsored by