Repository navigation
v0.13.0
Know what the registers and flags are doing. The crate stops refusing
instructions it can prove are safe to rewrite.
Emitted bytes changed
Nothing changes for an existing caller. The one rewrite this release adds is
off by default: DetourOptions::rewrite_compare_branches is false, so a
displaced CBZ/CBNZ that cannot reach its target is still refused exactly
as in 0.12.0. Turn it on and a CBZ at a site where every condition flag is
dead becomes CMP + B<cond>.W — different bytes, deliberately, and only
where they mean the same thing.
The 16-bit digest is unchanged: 0x0e06fda25d6b89e8.
Added
-
flags— which condition flags an instruction reads and writes, and
which are live at a point in an image.This is per-flag rather than a bool, and that is the whole point.
Insn::sets_flagssays that flags are written; the mnemonic says which.
Logical and shift operations withS—ANDS,ORRS,EORS,BICS,
MVNS,LSLS,LSRS,ASRS— write N, Z and C and leave V untouched,
with DDI 0403E.e A7.7.9 and its siblings saying// APSR.V unchanged
outright. Arithmetic and the comparisons write all four. A model that reads
sets_flagsas "all four die here" therefore reports V dead after an
ANDS, which would licence a rewrite that destroys a V the next branch
tests.Reads are asymmetric in the same way:
ADC,SBC,RSCandRRXconsume
the carry flag withcond: None, so a rule built oninsn.cond.is_some()
misses every one of them.live_afterfollows both the fall-through and the taken path. That is
not a refinement — the motivating caller is rewriting aCBZ, which is
itself a conditional branch, so half of what happens after it is at its
target. Anything it cannot follow (an unresolvable target, a target outside
the image, undecodable bytes, the walk budget running out) resolves to every
flag live. The approximation is one-directional by design: a flag reported
live may be dead, but a flag reported dead is dead on every path it saw. -
relocate::widen_compare_branch— rewritescbz rn, tascmp rn, #0beq.w t.relocaterefuses these outright, because the offset is
unsigned and forward-only (0 to 126 bytes, no backward form), so a stub in
free space essentially never reaches.
It takes the liveness as an argument rather than computing it, because it
receives anInsnand liveness is a property of the image around it. It
refuses unless every flag is dead. -
RelocateError::FlagsLive— names which flags are live, not just that
some are. Worth reading rather than treating as a yes/no: "only V" is the
common answer, because a nearbyANDSkills three of the four and looks as
though it killed all of them. -
DetourOptions::rewrite_compare_branches— opt in, and it does not make
the rewrite unconditional. Liveness is computed from the image at each
displaced instruction's original address, and a site where any flag survives
is still refused.
Hardened
-
A ten-lens audit of the new liveness code and the modules around it,
looped to convergence over six rounds. It confirmed 27 defects, all fixed
here. The four high-severity ones were all in this release's ownflags
code and all erred toward reporting a flag dead — the direction that turns
a refusal into a silent clobber:live_afterfollowing a literal load's
Targetinto the pool and decoding data as code;live_fromwalking with
the stateless decoder and so missing anITblock's flag reads and its
setflags = !InITBlock()suppression;readsmissingRRXused as a shift
operand; andwritesclaimingMSR APSR_gtouches the condition flags when
it writes only the GE bits. -
An integer-overflow class, fixed in six places. Arithmetic on a
caller-suppliedu32/usizeaddress done before the bounds check meant to
reject an extreme value — a panic in debug, a wrapped and wrong result in
release — inCommandTable::find,widen_compare_branch,build_stub,
disassemble,function_startandreachable. A crate that must never
crash on caller input now refuses these rather than overflowing. -
Every ARMv8-M / VFP citation in
docs/CONFORMANCE.mdcorrected (twelve
section numbers that named the wrong instruction), and the document is now
pinned totests/support/divergences.rsby a test, so the two cannot drift
again.Asm::finishalso stopped indexing its label table with an
unvalidated caller id, and several stale comment fragments were removed.
Deferred
- The
UNPREDICTABLEchannel onInsn, again. It needs
#[non_exhaustive]onInsn, which removes literal construction from a
struct whose hand-construction is a documented use case, so it needs a
builder designed first — and then every group module has to classify its own
encodings, which is a pass over nineteen files rather than an afternoon.
Shipping half of it would mean a second breaking release to finish it.