[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 14/32] tcg/arm: Return false on failure from patch_re
From: |
Richard Henderson |
Subject: |
[Qemu-devel] [PULL 14/32] tcg/arm: Return false on failure from patch_reloc |
Date: |
Thu, 13 Dec 2018 21:19:05 -0600 |
This does require an extra two checks within the slow paths
to replace the assert that we're moving.
Reviewed-by: Alex Bennée <address@hidden>
Signed-off-by: Richard Henderson <address@hidden>
---
tcg/arm/tcg-target.inc.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/tcg/arm/tcg-target.inc.c b/tcg/arm/tcg-target.inc.c
index deefa20fbf..49f57d655e 100644
--- a/tcg/arm/tcg-target.inc.c
+++ b/tcg/arm/tcg-target.inc.c
@@ -187,10 +187,14 @@ static const uint8_t tcg_cond_to_arm_cond[] = {
[TCG_COND_GTU] = COND_HI,
};
-static inline void reloc_pc24(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
+static inline bool reloc_pc24(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
{
ptrdiff_t offset = (tcg_ptr_byte_diff(target, code_ptr) - 8) >> 2;
- *code_ptr = (*code_ptr & ~0xffffff) | (offset & 0xffffff);
+ if (offset == sextract32(offset, 0, 24)) {
+ *code_ptr = (*code_ptr & ~0xffffff) | (offset & 0xffffff);
+ return true;
+ }
+ return false;
}
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
@@ -199,7 +203,7 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
tcg_debug_assert(addend == 0);
if (type == R_ARM_PC24) {
- reloc_pc24(code_ptr, (tcg_insn_unit *)value);
+ return reloc_pc24(code_ptr, (tcg_insn_unit *)value);
} else if (type == R_ARM_PC13) {
intptr_t diff = value - (uintptr_t)(code_ptr + 2);
tcg_insn_unit insn = *code_ptr;
@@ -213,7 +217,11 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
} else {
int rd = extract32(insn, 12, 4);
int rt = rd == TCG_REG_PC ? TCG_REG_TMP : rd;
- assert(diff >= 0x1000 && diff < 0x100000);
+
+ if (diff < 0x1000 || diff >= 0x100000) {
+ return false;
+ }
+
/* add rt, pc, #high */
*code_ptr++ = ((insn & 0xf0000000) | (1 << 25) | ARITH_ADD
| (TCG_REG_PC << 16) | (rt << 12)
@@ -1372,7 +1380,8 @@ static void tcg_out_qemu_ld_slow_path(TCGContext *s,
TCGLabelQemuLdst *lb)
TCGMemOp opc = get_memop(oi);
void *func;
- reloc_pc24(lb->label_ptr[0], s->code_ptr);
+ bool ok = reloc_pc24(lb->label_ptr[0], s->code_ptr);
+ tcg_debug_assert(ok);
argreg = tcg_out_arg_reg32(s, TCG_REG_R0, TCG_AREG0);
if (TARGET_LONG_BITS == 64) {
@@ -1432,7 +1441,8 @@ static void tcg_out_qemu_st_slow_path(TCGContext *s,
TCGLabelQemuLdst *lb)
TCGMemOpIdx oi = lb->oi;
TCGMemOp opc = get_memop(oi);
- reloc_pc24(lb->label_ptr[0], s->code_ptr);
+ bool ok = reloc_pc24(lb->label_ptr[0], s->code_ptr);
+ tcg_debug_assert(ok);
argreg = TCG_REG_R0;
argreg = tcg_out_arg_reg32(s, argreg, TCG_AREG0);
--
2.17.2
- [Qemu-devel] [PULL 03/32] tcg/aarch64: Remove reloc_pc26_atomic, (continued)
- [Qemu-devel] [PULL 03/32] tcg/aarch64: Remove reloc_pc26_atomic, Richard Henderson, 2018/12/13
- [Qemu-devel] [PULL 05/32] tcg/arm: Remove reloc_pc24_atomic, Richard Henderson, 2018/12/13
- [Qemu-devel] [PULL 04/32] tcg/aarch64: Fold away "noaddr" branch routines, Richard Henderson, 2018/12/13
- [Qemu-devel] [PULL 06/32] tcg/arm: Fold away "noaddr" branch routines, Richard Henderson, 2018/12/13
- [Qemu-devel] [PULL 07/32] tcg/ppc: Fold away "noaddr" branch routines, Richard Henderson, 2018/12/13
- [Qemu-devel] [PULL 08/32] tcg/s390: Remove retranslation code, Richard Henderson, 2018/12/13
- [Qemu-devel] [PULL 10/32] tcg/mips: Remove retranslation code, Richard Henderson, 2018/12/13
- [Qemu-devel] [PULL 09/32] tcg/sparc: Remove retranslation code, Richard Henderson, 2018/12/13
- [Qemu-devel] [PULL 12/32] tcg/i386: Return false on failure from patch_reloc, Richard Henderson, 2018/12/13
- [Qemu-devel] [PULL 11/32] tcg: Return success from patch_reloc, Richard Henderson, 2018/12/13
- [Qemu-devel] [PULL 14/32] tcg/arm: Return false on failure from patch_reloc,
Richard Henderson <=
- [Qemu-devel] [PULL 13/32] tcg/aarch64: Return false on failure from patch_reloc, Richard Henderson, 2018/12/13
- [Qemu-devel] [PULL 15/32] tcg/ppc: Return false on failure from patch_reloc, Richard Henderson, 2018/12/13
- [Qemu-devel] [PULL 17/32] tcg/i386: Propagate is64 to tcg_out_qemu_ld_direct, Richard Henderson, 2018/12/13
- [Qemu-devel] [PULL 16/32] tcg/s390x: Return false on failure from patch_reloc, Richard Henderson, 2018/12/13
- [Qemu-devel] [PULL 19/32] tcg/i386: Implement INDEX_op_extr{lh}_i64_i32 for 32-bit guests, Richard Henderson, 2018/12/13
- [Qemu-devel] [PULL 18/32] tcg/i386: Propagate is64 to tcg_out_qemu_ld_slow_path, Richard Henderson, 2018/12/13
- [Qemu-devel] [PULL 21/32] tcg/i386: Precompute all guest_base parameters, Richard Henderson, 2018/12/13
- [Qemu-devel] [PULL 23/32] tcg: Clean up generic bswap32, Richard Henderson, 2018/12/13
- [Qemu-devel] [PULL 29/32] qht-bench: document -p flag, Richard Henderson, 2018/12/13
- [Qemu-devel] [PULL 22/32] tcg/i386: Add setup_guest_base_seg for FreeBSD, Richard Henderson, 2018/12/13