Repository navigation
FID PR1: SLEIGH instruction-mask accessor + design doc - #94
Merged
Merged
Conversation
The first PR of the FID (Function-ID fingerprinting) port: the SLEIGH
instruction-mask accessor that every FID hash consumes, plus the whole-feature
design doc (docs/fid-design.md). FID's hashes are operand-independent — they
fingerprint a function by the bits SLEIGH pins to a constant (opcode /
addressing-mode bits) while masking out operand-value bits. kuna had no way to
ask "which bits of this decoded instruction are fixed?"; this accessor adds it.
Purely additive, zero decode-behavior change. PR1 touches the proven kuna-sleigh
core but adds ONLY a new DecisionNode method and a new Sleigh accessor; no
existing decode path is modified. instruction_mask re-uses obtain_context
verbatim and then reads the resolved constructor tree. Proof: make test 675/675
PARITY OK, and make rust-test's .sla content-parity + datatest parity are
byte-identical.
Two additions:
- DecisionNode::resolve_matched (slghsymbol.rs, beside resolve): a variant of
resolve that walks the decision tree byte-for-byte identically but at the
terminal node returns the matched (DisjointPattern, ct) pair (re-running
pat.is_match to capture the specific leaf). SubtableSymbol::resolve_matched
forwards to it. No decode path calls these.
- Sleigh::instruction_mask (sleigh.rs, beside instruction_length) returning
InsnMask { bytes, fixed_mask, length, operands } (+ OperandView, OpObject
{Scalar/Register/Address}). Lives in sleigh.rs because obtain_context/
ParserContext/ConstructState/ParserWalker are private. It obtain_contexts at
Pcode state, walks the matched ConstructState arena, ORs each node's fixed
instruction bits (get_mask context=false, shifted by the node offset) into
fixed_mask, and classifies each operand's resolved FixedHandle.
Gotchas honored: multi-word masks walked byte-by-byte respecting node offsets;
context-stream bits never folded into the byte mask; MAX_INSTRUCTION_LEN=16 cap;
delay slots handled by the per-addr granularity.
Sample (hand-checked vs objdump):
add eax,0x12345678 = 05 78 56 34 12 -> fixed [ff,00,00,00,00] + Scalar{0x12345678}
mov ecx,imm32 = b9 ... -> [f8,...] (b8+rd reg selector free)
add eax,ecx = 01 c8 -> [ff,c0] (modrm reg/rm = operand bits)
mov eax,[rbx+disp32]= 8b 83 78 56 34 12 -> [ff,c0,00,00,00,00] + Scalar{0x12345678}
This is the AIF/FID-family prerequisite the build-plan flagged. No FID
hashing/DB/pass here — PR1 is the accessor only.
Gates: make test 675/675 PARITY OK; make test-stages PARITY OK (203/203);
make rust-test green (incl. .sla content-parity). New unit gate
(kuna-sleigh/tests/instruction_mask.rs, 4 x86-64 cases) RAN: 4 passed, 0 ignored.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb
# Conflicts: # docs/analysis-port-log.md
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.
FID PR1 — the SLEIGH instruction-mask accessor (the fingerprinting prerequisite)
The first PR of the FID (Function-ID fingerprinting) port. FID's hashes are
operand-independent: they fingerprint a function by the bits SLEIGH pins to a
constant (opcode / addressing-mode bits) while masking out the bits that carry
operand values (immediates, displacements, register selectors). kuna's decoder
discards the matched
DisjointPatternafterDecisionNode::resolve, so there wasno way to recover which bits of a decoded instruction are fixed. This PR adds
that accessor — and the whole-feature design doc,
docs/fid-design.md.PR1 is the accessor only — no FID hashing/DB/pass (those are PR2+ per the
design doc's ordered breakdown).
What the accessor does
Sleigh::instruction_mask(addr) -> InsnMask { bytes, fixed_mask, length, operands }:fixed_mask[i]has a 1 wherever SLEIGH pins a fixed encoding bit;operand_mask = !fixed_mask.operands: Vec<OperandView>carries each operand's value-bit mask and itsclassified
OpObjects —Scalar { signed, .. }/Register { offset }/Address,read off the resolved
FixedHandles.It re-uses
obtain_contextverbatim, then walks the matchedConstructStatearena: per node it re-runs the decision tree (new
DecisionNode::resolve_matched)to recover the specific leaf
DisjointPattern, then ORs that pattern's fixedinstruction bits (
get_mask(.., context=false)) intofixed_mask, shifted bythe node's byte offset, byte-by-byte. Context-stream bits are never folded in;
MAX_INSTRUCTION_LEN=16caps the buffer.Sample (hand-checked against
objdump -d -M intel)fixed_maskadd eax,0x1234567805 78 56 34 12[ff,00,00,00,00]Scalar{0x12345678}mov ecx,imm32b9 44 33 22 11[f8,00,00,00,00]b8+rdopcode — low-3 register selector freeadd eax,ecx01 c8[ff,c0]mov eax,[rbx+disp32]8b 83 78 56 34 12[ff,c0,00,00,00,00]Scalar{0x12345678}Each row pins its opcode bits and zeroes its operand bytes — exactly the
operand-independence FID's full hash needs.
Additive / byte-identical proof
PR1 touches the proven
kuna-sleighcore but is purely additive — a newDecisionNodemethod (resolve_matched) and a newSleighaccessor(
instruction_mask); no existing decode path is modified. The diff is twokuna-sleighsource files + the design doc + a new unit test + the port log. No.slaand no datatest changed. As a result:make test675/675 PARITY OK..slacontent-parity is untouched —make rust-testgreen (the SLEIGHcompiler emits the same bytes; nothing in the spec or compiler changed).
Gates
make test— 675/675 PARITY OKmake test-stages— PARITY OK (203/203; count raised by the concurrent worker)make rust-test— green, including the.slacontent-parity testskuna-sleigh/tests/instruction_mask.rs(4 x86-64 cases) — RAN: 4 passed, 0 ignoredNote / gotcha
RIP-relative
[rip+disp32]forms (mod=00 rm=101) need address arithmetic theminimal standalone test harness does not supply, so the disp32 test uses the
register-base
mov reg,[base+disp32]form. This is a harness limitation, not anaccessor limitation (the same harness would fail RIP-relative in
print_assemblytoo).
🤖 Generated with Claude Code
https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb