From caf2fe1ddb4c6786e94f8603f27ab2b90edf8872 Mon Sep 17 00:00:00 2001 From: lazymio Date: Fri, 25 Feb 2022 22:23:44 +0100 Subject: [PATCH] Clear state when exiting from uc_emu_start This may cause unexpected result when we are in a nested uc_emu_start --- qemu/softmmu/cpus.c | 3 +++ uc.c | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/qemu/softmmu/cpus.c b/qemu/softmmu/cpus.c index 25568fac..e8de7941 100644 --- a/qemu/softmmu/cpus.c +++ b/qemu/softmmu/cpus.c @@ -128,6 +128,9 @@ static int tcg_cpu_exec(struct uc_struct *uc) } } uc->exit_request = 0; + uc->cpu->exit_request = 0; + uc->cpu->icount_decr_ptr->u16.high = 0; + uc->cpu->tcg_exit_req = 0; return finish; } diff --git a/uc.c b/uc.c index 01bbb549..99bfe35b 100644 --- a/uc.c +++ b/uc.c @@ -709,6 +709,8 @@ UNICORN_EXPORT uc_err uc_emu_start(uc_engine *uc, uint64_t begin, uint64_t until, uint64_t timeout, size_t count) { + uc_err err; + // reset the counter uc->emu_counter = 0; uc->invalid_error = UC_ERR_OK; @@ -852,7 +854,11 @@ uc_err uc_emu_start(uc_engine *uc, uint64_t begin, uint64_t until, qemu_thread_join(&uc->timer); } - return uc->invalid_error; + // We may be in a nested uc_emu_start and thus clear invalid_error + // once we are done. + err = uc->invalid_error; + uc->invalid_error = 0; + return err; } UNICORN_EXPORT