Skip to contentSkip to conversation

target: i386: mem_helper: Fix ldaxr instruction 64 bit alignment issue temporarily for stable-4.1

PATCH New [email protected] 1 participant 1 message Jul 12, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target: i386: mem_helper: Fix ldaxr instruction 64 bit alignment issue temporarily for stable-4.1

From: Chen Gang <[email protected]>

This fix does not consider about the lock feature which may cause another issues, but excuse me, I don't know how to fix it. At present, the fix runs OK for my case in windows oledb32.dll in wine.

Welcome anyone to fix it, thanks.

---
 target/i386/mem_helper.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
target/i386/mem_helper.c +7 -1
index d50d4b0c40..8c37b05fae 100644
@@ -68,7 +68,13 @@ void helper_cmpxchg8b(CPUX86State *env, target_ulong a0)
         uint64_t *haddr = g2h(a0);
         cmpv = cpu_to_le64(cmpv);
         newv = cpu_to_le64(newv);
-        oldv = atomic_cmpxchg__nocheck(haddr, cmpv, newv);
+        if ((unsigned long)haddr % 8) {
+            volatile uint64_t tmp = *haddr; /* avoid compiler optimization */
+            oldv = atomic_cmpxchg__nocheck(&tmp, cmpv, newv);
+            *haddr = tmp;
+        } else {
+            oldv = atomic_cmpxchg__nocheck(haddr, cmpv, newv);
+        }
         oldv = le64_to_cpu(oldv);
     }
 #else
Signature · 1 line
2.24.0.308.g228f53135a