[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 1/9] exec-all.h: Use stl_p to avoid undefined beh
From: |
Richard Henderson |
Subject: |
[Qemu-devel] [PATCH v2 1/9] exec-all.h: Use stl_p to avoid undefined behaviour patching x86 jumps |
Date: |
Tue, 1 Apr 2014 13:53:26 -0700 |
From: Peter Maydell <address@hidden>
The code which patches x86 jump instructions assumes it can do an
unaligned write of a uint32_t. This is actually safe on x86, but it's
still undefined behaviour. We have infrastructure for doing efficient
unaligned accesses which doesn't engage in undefined behaviour, so
use it.
This is technically fractionally less efficient, at least with gcc 4.6;
instead of one instruction:
7b2: 89 3e mov %edi,(%rsi)
we get an extra spurious store to the stack slot:
7b2: 89 7c 24 64 mov %edi,0x64(%rsp)
7b6: 89 3e mov %edi,(%rsi)
Reviewed-by: Alex Bennée <address@hidden>
Signed-off-by: Peter Maydell <address@hidden>
Signed-off-by: Richard Henderson <address@hidden>
---
include/exec/exec-all.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index f9ac332..1c49a21 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -229,7 +229,7 @@ void ppc_tb_set_jmp_target(unsigned long jmp_addr, unsigned
long addr);
static inline void tb_set_jmp_target1(uintptr_t jmp_addr, uintptr_t addr)
{
/* patch the branch destination */
- *(uint32_t *)jmp_addr = addr - (jmp_addr + 4);
+ stl_p((void*)jmp_addr, addr - (jmp_addr + 4));
/* no need to flush icache explicitly */
}
#elif defined(__aarch64__)
--
1.9.0
- [Qemu-devel] [PATCH v2 0/9] tcg: tidy the type of code_ptr, Richard Henderson, 2014/04/01
- [Qemu-devel] [PATCH v2 1/9] exec-all.h: Use stl_p to avoid undefined behaviour patching x86 jumps,
Richard Henderson <=
- [Qemu-devel] [PATCH v2 2/9] tcg: Avoid stores to unaligned addresses, Richard Henderson, 2014/04/01
- [Qemu-devel] [PATCH v2 3/9] tcg: Avoid undefined behaviour patching code at unaligned addresses, Richard Henderson, 2014/04/01
- [Qemu-devel] [PATCH v2 4/9] tcg: Introduce byte pointer arithmetic helpers, Richard Henderson, 2014/04/01
- [Qemu-devel] [PATCH v2 5/9] tcg: Define tcg_insn_unit for code pointers, Richard Henderson, 2014/04/01
- [Qemu-devel] [PATCH v2 6/9] tcg-i386: Define TCG_TARGET_INSN_UNIT_SIZE, Richard Henderson, 2014/04/01
- [Qemu-devel] [PATCH v2 7/9] tcg-ppc64: Define TCG_TARGET_INSN_UNIT_SIZE, Richard Henderson, 2014/04/01
- [Qemu-devel] [PATCH v2 8/9] tcg-ppc: Define TCG_TARGET_INSN_UNIT_SIZE, Richard Henderson, 2014/04/01
- [Qemu-devel] [PATCH v2 9/9] tcg-sparc: Define TCG_TARGET_INSN_UNIT_SIZE, Richard Henderson, 2014/04/01