target/i386: Call gen_update_cc_op() after set_cc_op() in gen_compute_eflags() - #2373
Open
unknown-1-0 wants to merge 1 commit into
Conversation
…mpute_eflags()` `gen_update_cc_op()` updates the `env->cc_op` value only if `s->cc_op_dirty` is set. In `gen_compute_eflags()`, `set_cc_op()` is responsible for setting that variable to `true` when needed. Since `gen_update_cc_op()` was previously called before `set_cc_op()` inside `gen_compute_eflags()`, `s->cc_op_dirty` might not be set to `true` when it should be. This can lead to the `env->cc_op` write being completely omitted in the generated TCG micro-ops. Although this omission may later be corrected by a `gen_update_cc_op()` call at the end of `disas_insn()`, that correction may not happen when the instruction faults before it completes. This can lead to a state where `env->cc_src` contains the calculated RFLAGS and `env->cc_op` holds the value other than `CC_OP_EFLAGS`. This in turn causes incorrect RFLAGS values to be computed after the instruction fault. Fix this bug by calling `gen_update_cc_op()` after `set_cc_op()` to ensure that `s->cc_op_dirty` is properly updated. Signed-off-by: Andrey Polivoda <apolivodaa433@gmail.com>
unknown-1-0
force-pushed
the
i386-fix-incorrect-flags-on-fault-after-eflags-overwrite
branch
from
July 24, 2026 09:28
8bf08a5 to
2378011
Compare
Author
|
Fixed brace style of the |
Author
|
@wtdcode, I know you are busy reviewing other PRs, but could you please share your opinion on this one before the next release (#2356)? If you have time, please also take a look at my other x86-related fixes: Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
gen_update_cc_op()updates theenv->cc_opvalue only ifs->cc_op_dirtyis set.In
gen_compute_eflags(),set_cc_op()is responsible for setting that variable totruewhen needed.Since
gen_update_cc_op()was previously called beforeset_cc_op()insidegen_compute_eflags(),s->cc_op_dirtymight not be set totruewhen it should be. This can lead to theenv->cc_opwrite being completely omitted in the generated TCG micro-ops.Although this omission may later be corrected by a
gen_update_cc_op()call at the end ofdisas_insn(), that correction may not happen when the instruction faults before it completes. This can lead to a state whereenv->cc_srccontains the calculated RFLAGS andenv->cc_opholds the value other thanCC_OP_EFLAGS. This in turn causes incorrect RFLAGS values to be computed after the instruction fault.Fix this bug by calling
gen_update_cc_op()afterset_cc_op()to ensure thats->cc_op_dirtyis properly updated.