Skip to contentSkip to conversation

Bug in AMD64 emulation Was: [AMD64] Possible problem with the DF flag during the SYSCALL instruction

PATCH In review Jakub Jermar 2 participants 3 messages Mar 25, 2008 – Mar 27, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Bug in AMD64 emulation Was: [AMD64] Possible problem with the DF flag during the SYSCALL instruction

Hi,

as no one has picked my previous report up yet, I am resending my patch again. The patch fixes a bug in the way QEMU emulates AMD64 instruction called SYSCALL. The problem appears to be stale DF variable.

Jakub

helper.c.new renamed from helper.c +1 -0
@@ -1008,6 +1008,7 @@
                                DESC_S_MASK |
                                DESC_W_MASK | DESC_A_MASK);
         env->eflags &= ~env->fmask;
+	DF = 1 - (2 * ((env->eflags >> 10) & 1));
         if (code64)
             env->eip = env->lstar;
         else
#1 lore raw

Hi,

Quoted 1 line · Jakub Jermar

as no one has picked my previous report up yet, I am resending my patch again. The patch fixes a bug in the way QEMU emulates AMD64 instruction called SYSCALL. The problem appears to be stale DF variable.

Sorry I didn't have a look at it before. Good catch though!

helper.c.new line 1011

Quoted 11 lines

Jakub

helper.c.new renamed from helper.c +1 -0
@@ -1008,6 +1008,7 @@
                               DESC_S_MASK |
                               DESC_W_MASK | DESC_A_MASK);
        env->eflags &= ~env->fmask;
+	DF = 1 - (2 * ((env->eflags >> 10) & 1));

I believe you're searching for load_eflags(), which automatically updates the DF flag. Take a look at the SVM code for that issue as well (helper.c:helper_vmrun).

helper.c.new line 1014

Quoted 4 lines
helper.c.new renamed from helper.c +0 -0
        if (code64)
            env->eip = env->lstar;
        else

Alex

#2 lore raw
Quoted 7 lines · Alexander Graf

Hi,

Quoted 1 line · Jakub Jermar

as no one has picked my previous report up yet, I am resending my patch again. The patch fixes a bug in the way QEMU emulates AMD64 instruction called SYSCALL. The problem appears to be stale DF variable.

Sorry I didn't have a look at it before. Good catch though!

...

Quoted 1 line

I believe you're searching for load_eflags(), which automatically updates the DF flag. Take a look at the SVM code for that issue as well (helper.c:helper_vmrun).

The included patch updates the DF flag in helper_syscall() using the load_eflags(). I thought of doing this as simply as possible and here's
probably the result. When the first parameter of load_eflags() has
the same value as env->eflags, the second argument doesn't matter, that's why it is 0.

Will you consider this for applying?

Thanks,
Jakub

target-i386/helper.c +1 -0
diff -ru qemu-0.9.1/target-i386/helper.c qemu-0.9.1-jj/target-i386/helper.c
@@ -1008,6 +1008,7 @@
                                DESC_S_MASK |
                                DESC_W_MASK | DESC_A_MASK);
         env->eflags &= ~env->fmask;
+        load_eflags(env->eflags, 0);
         if (code64)
             env->eip = env->lstar;
         else