From 4a1c5ff071f54b875000797c0e602632641d2295 Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Fri, 28 Aug 2015 16:06:06 +0800 Subject: [PATCH] x86: verify until address early when translating block in frontend. this should fix issue #63 --- qemu/cpu-exec.c | 7 ------- qemu/target-i386/translate.c | 10 ++++++++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/qemu/cpu-exec.c b/qemu/cpu-exec.c index 7d23caac..1e26e1b9 100644 --- a/qemu/cpu-exec.c +++ b/qemu/cpu-exec.c @@ -117,13 +117,6 @@ int cpu_exec(struct uc_struct *uc, CPUArchState *env) // qq (uc->arch == UC_ARCH_M68K && cpu->exception_index == 0x2f) /* M68K's EXCP_TRAP15 */ ) { cpu->halted = 1; - //cpu->exception_index = EXCP_HLT; - //no_shutdown = 0; - //printf(">>> calling shutdown-request...\n"); - //printf(">>> ** current EIP = %x\n", X86_CPU(cpu)->env.eip); - //qemu_system_shutdown_request(); - //pause_all_vcpus(); - //cpu_loop_exit(cpu); ret = EXCP_HLT; break; } diff --git a/qemu/target-i386/translate.c b/qemu/target-i386/translate.c index 7ce37ef8..10dc33d8 100644 --- a/qemu/target-i386/translate.c +++ b/qemu/target-i386/translate.c @@ -8254,7 +8254,7 @@ static inline void gen_intermediate_code_internal(uint8_t *gen_opc_cc_op, uint64_t flags; target_ulong pc_start; target_ulong cs_base; - int num_insns; + int num_insns = 0; int max_insns; bool block_full = false; @@ -8339,12 +8339,18 @@ static inline void gen_intermediate_code_internal(uint8_t *gen_opc_cc_op, // done with initializing TCG variables env->uc->init_tcg = true; + // early check to see if the address of this block is the until address + if (tb->pc == env->uc->addr_end) { + gen_tb_start(tcg_ctx); + gen_interrupt(dc, 0x99, tb->pc - tb->cs_base, tb->pc - tb->cs_base); + goto done_generating; + } + gen_opc_end = tcg_ctx->gen_opc_buf + OPC_MAX_SIZE; dc->is_jmp = DISAS_NEXT; pc_ptr = pc_start; lj = -1; - num_insns = 0; max_insns = tb->cflags & CF_COUNT_MASK; if (max_insns == 0) max_insns = CF_COUNT_MASK;