diff --git a/qemu/include/exec/exec-all.h b/qemu/include/exec/exec-all.h index 976de3e3..6923f6fb 100644 --- a/qemu/include/exec/exec-all.h +++ b/qemu/include/exec/exec-all.h @@ -193,6 +193,7 @@ struct TranslationBlock { uint16_t cflags; /* compile flags */ #define CF_COUNT_MASK 0x7fff #define CF_LAST_IO 0x8000 /* Last insn may be an IO access. */ +#define CF_NOCACHE 0x10000 /* To be freed after execution */ void *tc_ptr; /* pointer to the translated code */ /* next matching tb for physical address. */ diff --git a/qemu/translate-all.c b/qemu/translate-all.c index 3dfa1fe7..955b7b50 100644 --- a/qemu/translate-all.c +++ b/qemu/translate-all.c @@ -283,6 +283,12 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t retaddr) tb = tb_find_pc(env->uc, retaddr); if (tb) { cpu_restore_state_from_tb(cpu, tb, retaddr); + if (tb->cflags & CF_NOCACHE) { + /* one-shot translation, invalidate it immediately */ + cpu->current_tb = NULL; + tb_phys_invalidate(cpu->uc, tb, -1); + tb_free(cpu->uc, tb); + } return true; } return false;