Repository navigation
Conversation
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
If I clear NZCV and execute
cfinv, the nextb.csshould take the branch. With VEXfd41c675and PyVEX6a81d15f, carry stays clear. Reading NZCV immediately afterxaflagandaxflagshows the same problem. Both instructions leave the old flags in place.Architectural definition
Arm’s A64 instruction reference (2025-09 release) gives the following rules. Each expression uses the flags before the instruction executes.
CFINV(FlagM)XAFLAG(FlagM2)(NOT C) AND (NOT Z),Z AND C,C OR Zand(NOT C) AND Z, respectively.AXFLAG(FlagM2)Z OR Vand C toC AND (NOT V). Clear N and V.Reproducer
Here is a standalone example using angr. Each case writes the starting flags with
msr nzcv, x0, executes the instruction, then reads the flags back withmrs x3, nzcv. N, Z, C and V occupy bits 31 through 28.I get this output on master.
Root cause
The VEX AArch64 decoder returns
NoDecodefor all three instruction words. PyVEX then accepts them through its genericInstruction_MSRfallback. That handler advances the PC without emitting a flag write, so the followingmrs x3, nzcvreads the previous value. PyVEX fallback at the tested revisionFix
Decode the three instructions in
guest_arm64_toIR.c. Read NZCV withmk_arm64g_calculate_flags_nzcv(), apply the operation to those input bits, and write the resulting flags withsetFlags_COPY. Reading all four flags first matters forAXFLAG, where the incoming V contributes to the new Z before V is cleared. The patch models execution with the corresponding architectural feature present.Validation
With the patch, the reproducer reads back
0x20000000,0x80000000and0x40000000, respectively. I repeated the sequence with every possible starting NZCV value. I also replaced the initialmsrwithcmpto check flags produced by arithmetic, including a signed overflow.