From 023c4c480385c4c81f0947d45bcc48b5e43a1960 Mon Sep 17 00:00:00 2001 From: Edmund Grimley Evans Date: Tue, 4 Jul 2017 13:09:53 +0100 Subject: [PATCH] i#2491 ARM unallocated encodings: Better handling of undecoded instrs. In check_encode_decode_consistency(), do not try to reencode an OP_UNDECODED instruction. In instr_encode_arch(), use instr->opcode, not instr_get_opcode(instr), as the latter can call the decoder, which is unhelpful when we are trying to encode. Fixes #2491 Change-Id: I66c42dc87268f1722eae4600b364026896796fc8 --- core/arch/arm/decode.c | 8 ++++++-- core/arch/arm/encode.c | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/core/arch/arm/decode.c b/core/arch/arm/decode.c index dc267a68e05..48fb162fc5b 100644 --- a/core/arch/arm/decode.c +++ b/core/arch/arm/decode.c @@ -2893,8 +2893,12 @@ check_encode_decode_consistency(dcontext_t *dcontext, instrlist_t *ilist) byte buf[THUMB_LONG_INSTR_SIZE]; instr_t tmp; byte *pc, *npc; - app_pc addr = instr_get_raw_bits(check); - int check_len = instr_length(dcontext, check); + app_pc addr; + int check_len; + if (check->opcode == OP_UNDECODED) + continue; + addr = instr_get_raw_bits(check); + check_len = instr_length(dcontext, check); instr_set_raw_bits_valid(check, false); pc = instr_encode_to_copy(dcontext, check, buf, addr); instr_init(dcontext, &tmp); diff --git a/core/arch/arm/encode.c b/core/arch/arm/encode.c index 260802f254a..97dabe313e5 100644 --- a/core/arch/arm/encode.c +++ b/core/arch/arm/encode.c @@ -2766,7 +2766,7 @@ instr_encode_arch(dcontext_t *dcontext, instr_t *instr, byte *copy_pc, byte *fin } decode_info_init_for_instr(&di, instr); - di.opcode = instr_get_opcode(instr); + di.opcode = instr->opcode; di.check_reachable = check_reachable; di.start_pc = copy_pc; di.final_pc = final_pc;