fix: compute PF, ZF, SF after AAA and AAS instructions#2311
Open
huehuehuehueing wants to merge 1 commit intounicorn-engine:devfrom
Open
fix: compute PF, ZF, SF after AAA and AAS instructions#2311huehuehuehueing wants to merge 1 commit intounicorn-engine:devfrom
huehuehuehueing wants to merge 1 commit intounicorn-engine:devfrom
Conversation
helper_aaa and helper_aas only updated CF and AF in eflags, leaving PF, ZF, SF, and OF stale from the prior instruction. While Intel documents these flags as undefined after AAA/AAS, real x86 CPUs consistently set them based on the masked AL result. The sibling helpers helper_daa and helper_das in the same file already compute these flags correctly. This causes observable divergence when code branches on PF (e.g. JP/JNP) after AAA, which occurs in real-world binaries. The fix computes ZF, PF, SF from the result AL after AAA/AAS, using the same approach as DAA/DAS. Two regression tests verify the correct flag values. Signed-off-by: Larry H <l.gr@dartmouth.edu>
4 tasks
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.
Summary
helper_aaaandhelper_aasonly updated CF and AF, leaving PF, ZF, SF, and OF stale from the prior instructionhelper_daa/helper_dasin the same file already compute these flags correctlyFix
Compute ZF, PF, SF from result AL after AAA/AAS, using the same approach as DAA/DAS.
Test plan
test_x86_aaa_flags-- verifies PF, ZF, SF, CF after AAA with adjustmenttest_x86_aas_flags-- verifies PF, ZF, SF, CF after AAS with adjustment