Skip to contentSkip to conversation

x86_emulate: fix side-effect macro call

PATCH In review Samuel Thibault 1 participant 2 messages Feb 5, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86_emulate: fix side-effect macro call

x86_emulate: fix side-effect macro call
Both jmp_rel and insn_fetch_type increment eip, so it's not compiler-safe to nest the calls.

---
Yes, I actually got a bug because of this, with debian's gcc 4.2.3.

xen/arch/x86/x86_emulate.c +4 -2
diff -r 52f222b319ef xen/arch/x86/x86_emulate.c
@@ -2644,9 +2644,11 @@
         break;
     }
 
-    case 0xeb: /* jmp (short) */
-        jmp_rel(insn_fetch_type(int8_t));
+    case 0xeb: /* jmp (short) */ {
+        int8_t rel = insn_fetch_type(int8_t);
+        jmp_rel(rel);
         break;
+    }
 
     case 0xf1: /* int1 (icebp) */
         src.val = EXC_DB;
#1 lore raw
Quoted 3 lines · Samuel Thibault, le Tue 05 Feb 2008 15:33:55 +0000, a écrit :

x86_emulate: fix side-effect macro call
Both jmp_rel and insn_fetch_type increment eip, so it's not compiler-safe to nest the calls.

Another way to fix it would be to change jmp_rel:

- _regs.eip += (int)(rel);
+ int _rel = (int)(rel);
+ _regs.eip += _rel;

Samuel