Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(win-isa-guard): geplante Sprungdistanz nach dem isa-Vergleich zulassen

purpleec6b1be76e95
diff --git a/scripts/__fixtures__/win-isa/scheduled-jump-no-guard-own-code.disasm.txt b/scripts/__fixtures__/win-isa/scheduled-jump-no-guard-own-code.disasm.txt
new file mode 100644
index 00000000..d8681798
--- /dev/null
+++ b/scripts/__fixtures__/win-isa/scheduled-jump-no-guard-own-code.disasm.txt
@@ -0,0 +1,23 @@
+Dump of file fixture: the negative twin of scheduled-jump-own-code.*. Byte
+for byte the same function, the same isa-flag compare and the same
+scheduled mov, with ONE line taken out: the jl that jumped over the two
+vpmullq into the scalar fallback. Without it the compare's result is never
+branched on and execution falls straight into the AVX-512 block, which is
+the real K1 crash shape.
+
+This must stay UNPROTECTED. It is what keeps the tolerance added for form
+(i) honest: the guard learned to follow a conditional jump across
+instructions that cannot write EFLAGS, not to accept "there is a cmp on the
+isa flag somewhere above".
+
+ 000000018007A970: 48 83 EC 18 sub rsp,18h
+ 000000018007A974: 83 3D 15 10 19 00 cmp dword ptr [000000018020B990h],6
+ 06
+ 000000018007A97B: 4C 8B 19 mov r11,qword ptr [rcx]
+ 000000018007AA0A: 0F 54 C4 andps xmm0,xmm4
+ 000000018007AA0D: 62 F2 FD 08 40 D5 vpmullq xmm2,xmm0,xmm5
+ 000000018007AA25: 0F 54 C4 andps xmm0,xmm4
+ 000000018007AA28: 62 F2 FD 08 40 CD vpmullq xmm1,xmm0,xmm5
+ 000000018007AA4D: C3 ret
+ 000000018007AA4E: 48 89 5C 24 20 mov qword ptr [rsp+20h],rbx
+ 000000018007AA53: 45 33 C0 xor r8d,r8d
diff --git a/scripts/__fixtures__/win-isa/scheduled-jump-no-guard-own-code.map.txt b/scripts/__fixtures__/win-isa/scheduled-jump-no-guard-own-code.map.txt
new file mode 100644
index 00000000..3862b74c
--- /dev/null
+++ b/scripts/__fixtures__/win-isa/scheduled-jump-no-guard-own-code.map.txt
@@ -0,0 +1,5 @@
+ Static symbols
+
+ 0001:00079970 ??$?RV<lambda_293274331f3afe7f67f2cdc1c506ab8a>@@@<lambda_2cf90e514c4f0c737c9be315b83cf30f>@@QEBA?A_PV<lambda_293274331f3afe7f67f2cdc1c506ab8a>@@@Z 000000018007a970 f i llama-kv-cache.obj
+ 0001:00079b80 ??$_Copy_nodes@$0A@@llama_kv_cache@@QEAAXXZ 000000018007ab80 f i llama-kv-cache.obj
+ 0003:00000010 __isa_available 000000018020b990 MSVCRT:cpu_disp.obj
diff --git a/scripts/__fixtures__/win-isa/scheduled-jump-own-code.disasm.txt b/scripts/__fixtures__/win-isa/scheduled-jump-own-code.disasm.txt
new file mode 100644
index 00000000..87164762
--- /dev/null
+++ b/scripts/__fixtures__/win-isa/scheduled-jump-own-code.disasm.txt
@@ -0,0 +1,31 @@
+Dump of file fixture: known false-red form (i)/A, the real shape found in
+llama.dll built with MSVC 14.51.36256 (VS 2026) during the toolset review of
+21.09.2026, lu-301/bau/isa-review-1451.md section 2. Own code
+(llama-kv-cache.obj), two AVX-512DQ+VL vpmullq, and a genuine
+__isa_available >= 6 check whose jl jumps over both of them into the scalar
+fallback. The MSVC scheduler moved one unrelated "mov r11,qword ptr [rcx]"
+between the cmp and the jl, which the guard's original "the jump must be the
+very next line" rule could not follow, so it called this UNPROTECTED.
+
+A mov cannot write EFLAGS, so the jl still evaluates that same cmp: this
+must come out ALLOWED_PROTECTED. Its negative twin,
+scheduled-jump-no-guard-own-code.*, is the identical shape with the jl
+removed and must stay UNPROTECTED, so this fixture proves the scheduler
+tolerance and not "a cmp on the isa flag is enough".
+
+Addresses, bytes and text are copied verbatim from the runner's
+llama.dll.disasm.txt; only the untouched middle of the vector block is left
+out.
+
+ 000000018007A970: 48 83 EC 18 sub rsp,18h
+ 000000018007A974: 83 3D 15 10 19 00 cmp dword ptr [000000018020B990h],6
+ 06
+ 000000018007A97B: 4C 8B 19 mov r11,qword ptr [rcx]
+ 000000018007A97E: 0F 8C CA 00 00 00 jl 000000018007AA4E
+ 000000018007AA0A: 0F 54 C4 andps xmm0,xmm4
+ 000000018007AA0D: 62 F2 FD 08 40 D5 vpmullq xmm2,xmm0,xmm5
+ 000000018007AA25: 0F 54 C4 andps xmm0,xmm4
+ 000000018007AA28: 62 F2 FD 08 40 CD vpmullq xmm1,xmm0,xmm5
+ 000000018007AA4D: C3 ret
+ 000000018007AA4E: 48 89 5C 24 20 mov qword ptr [rsp+20h],rbx
+ 000000018007AA53: 45 33 C0 xor r8d,r8d
diff --git a/scripts/__fixtures__/win-isa/scheduled-jump-own-code.map.txt b/scripts/__fixtures__/win-isa/scheduled-jump-own-code.map.txt
new file mode 100644
index 00000000..3862b74c
--- /dev/null
+++ b/scripts/__fixtures__/win-isa/scheduled-jump-own-code.map.txt
@@ -0,0 +1,5 @@
+ Static symbols
+
+ 0001:00079970 ??$?RV<lambda_293274331f3afe7f67f2cdc1c506ab8a>@@@<lambda_2cf90e514c4f0c737c9be315b83cf30f>@@QEBA?A_PV<lambda_293274331f3afe7f67f2cdc1c506ab8a>@@@Z 000000018007a970 f i llama-kv-cache.obj
+ 0001:00079b80 ??$_Copy_nodes@$0A@@llama_kv_cache@@QEAAXXZ 000000018007ab80 f i llama-kv-cache.obj
+ 0003:00000010 __isa_available 000000018020b990 MSVCRT:cpu_disp.obj
diff --git a/scripts/verify-sidecar-isa.sh b/scripts/verify-sidecar-isa.sh
index f1e7605f..9514ab53 100755
--- a/scripts/verify-sidecar-isa.sh
+++ b/scripts/verify-sidecar-isa.sh
@@ -51,8 +51,11 @@
# (msvcprt:vector_algorithms.obj and the wmemcmp/memcmp fast path, see
# win-isa-guard.mjs isAllowlisted) rather than re-deriving it from source on
# every run. That trust is pinned to a Major.Minor MSVC LINKER version
-# (WINDOWS_REVIEWED_LINKER_VERSIONS below, currently "14.44", i.e. MSVC
-# 19.44.35222.0 / VS 2022 17.14, lu-301/bau/review-k1-avx.md section 3) and
+# (WINDOWS_REVIEWED_LINKER_VERSIONS below, currently "14.44 14.51":
+# 14.44 is MSVC 19.44.35222.0 / VS 2022 17.14, lu-301/bau/review-k1-avx.md
+# section 3; 14.51 is MSVC 19.51.36256 / VS 2026, reviewed 21.09.2026 on the
+# GitHub-runner dumps in lu-301/bau/isa-review-14.51/, written up in
+# lu-301/bau/isa-review-1451.md) and
# check_toolset_version turns the guard red the moment a build used a
# different one, rather than silently keep trusting an allowlist nobody
# re-checked. To clear a red toolset-pin failure: re-run the Opus-style
@@ -70,6 +73,21 @@
# and the sidecar build cache (keyed on hashFiles('scripts/build-llama.sh'))
# only defers it, it does not remove it.
#
+# DURCHSICHTSSTAND 14.51 (21.09.2026, lu-301/bau/isa-review-1451.md, dumps in
+# lu-301/bau/isa-review-14.51/): the CRT/STL allowlist holds on MSVC
+# 19.51.36256 / VS 2026. All 924 allowlisted VEX/EVEX hits across the nine
+# base modules sit in msvcprt:vector_algorithms.obj, in 18 functions, and
+# every one of them reaches its first AVX instruction only through a read of
+# __isa_enabled plus a conditional jump over the block, either in its own
+# body or, for the four helper families _Find_end_cmpeq, _Search_cmpeq,
+# _Impl_first_avx and _Impl_last_avx, in the dispatching caller. This
+# toolset produced no wmemcmp/memcmp hit at all, so the
+# WMEMCMP_MEMCMP_HOST_OBJECTS half of the allowlist was not exercised by
+# 14.51 and stays trusted on the 14.44 review alone. The one new finding,
+# two vpmullq in llama.dll's llama-kv-cache.obj, was a false red of known
+# form (i) and was closed in win-isa-guard.mjs's checkDominance, not
+# allowlisted away.
+#
# Usage: scripts/verify-sidecar-isa.sh <triple>
set -euo pipefail
@@ -353,7 +371,7 @@ if [[ "$TRIPLE" == *-windows-* ]]; then
# principle ship an unguarded fast path in the same object and this guard
# would not notice, so pin the toolset that was actually reviewed and go
# red, with a concrete next step, the moment the build uses a different one.
- WINDOWS_REVIEWED_LINKER_VERSIONS="14.44"
+ WINDOWS_REVIEWED_LINKER_VERSIONS="14.44 14.51"
check_toolset_version() {
local file="$1" hdr ver
hdr="$(dumpbin_run /nologo /headers "$file")" || vdie "dumpbin /headers failed on $file"
@@ -361,9 +379,9 @@ if [[ "$TRIPLE" == *-windows-* ]]; then
[ -n "$ver" ] || vdie "could not read a linker version out of dumpbin /headers on $file"
case " $WINDOWS_REVIEWED_LINKER_VERSIONS " in
*" $ver "*)
- vlog "$file: linker version $ver matches the reviewed MSVC toolset (19.44.35222.0, VS 2022 17.14, lu-301/bau/review-k1-avx.md)" ;;
+ vlog "$file: linker version $ver matches one of the reviewed MSVC toolsets (14.44 = 19.44.35222.0, VS 2022 17.14, lu-301/bau/review-k1-avx.md; 14.51 = 19.51.36256, VS 2026, lu-301/bau/isa-review-1451.md)" ;;
*)
- vdie "$file: linker version is $ver, not one of the reviewed toolsets ($WINDOWS_REVIEWED_LINKER_VERSIONS, MSVC 19.44.35222.0 / VS 2022 17.14, lu-301/bau/review-k1-avx.md section 3). A new toolset can change whether vector_algorithms.obj/wmemcmp still self-guard the way the CRT/STL allowlist assumes: re-run the Opus-style disassembly review against the new toolset before trusting it, then add its linker version to WINDOWS_REVIEWED_LINKER_VERSIONS here" ;;
+ vdie "$file: linker version is $ver, not one of the reviewed toolsets ($WINDOWS_REVIEWED_LINKER_VERSIONS; 14.44 = MSVC 19.44.35222.0 / VS 2022 17.14, lu-301/bau/review-k1-avx.md section 3, 14.51 = MSVC 19.51.36256 / VS 2026, lu-301/bau/isa-review-1451.md). A new toolset can change whether vector_algorithms.obj/wmemcmp still self-guard the way the CRT/STL allowlist assumes: re-run the Opus-style disassembly review against the new toolset before trusting it, then add its linker version to WINDOWS_REVIEWED_LINKER_VERSIONS here" ;;
esac
}
diff --git a/scripts/win-isa-guard.mjs b/scripts/win-isa-guard.mjs
index 055ce783..c7dfec90 100644
--- a/scripts/win-isa-guard.mjs
+++ b/scripts/win-isa-guard.mjs
@@ -384,6 +384,55 @@ function isCompareMnemonic(mnemonic) {
return mnemonic === 'cmp' || mnemonic === 'test';
}
+// Known false-red form A (see checkDominance's comment and
+// lu-301/bau/isa-review-1451.md): the MSVC scheduler is free to put
+// instructions between the guarding cmp/test and the conditional jump that
+// consumes its result, because those instructions do not touch EFLAGS. The
+// original "the jump must be the very next line" rule cannot tell that apart
+// from "an unrelated jump", so it called correctly guarded code UNPROTECTED.
+//
+// The property that actually matters is not adjacency, it is that the
+// conditional jump still evaluates THIS cmp/test: nothing between them may
+// write EFLAGS. So this is an ALLOWLIST of mnemonics that provably leave
+// every flag alone, and anything not on it (any arithmetic or logical
+// operation, any shift, any second cmp/test, any setcc/cmovcc that would at
+// least read the flags, any call, any ret, any jump) ends the scan and the
+// candidate read is rejected, exactly as before. That keeps N1's hole shut:
+// the fake-green shape A fixture (fake-unrelated-jump-own-code) puts a
+// flag-WRITING "test rax,rax" between the isa read and the jump, so it is
+// still not reachable through this list and still comes out UNPROTECTED.
+//
+// Only data movement is listed, nothing clever: the legacy and VEX register
+// and memory moves, lea, the stack pair, and the padding nop MSVC emits.
+const FLAG_PRESERVING_MNEMONICS = new Set([
+ 'mov', 'movzx', 'movsx', 'movsxd', 'movabs', 'lea', 'nop', 'push', 'pop',
+ 'movdqa', 'movdqu', 'movaps', 'movups', 'movq', 'movd', 'movss', 'movsd',
+ 'vmovdqa', 'vmovdqu', 'vmovaps', 'vmovups', 'vmovq', 'vmovd',
+]);
+
+// How far past the compare the scan may run before giving up. The two real
+// shapes this exists for are short: one intervening mov in the llama.dll
+// llama-kv-cache.obj lambda (lu-301/bau/isa-review-1451.md section 2) and
+// three in wmemcmp (ggml.dll, form A as first written down). The cap is not
+// what makes this safe, the EFLAGS allowlist above is; it only keeps the
+// scan from wandering across half a function.
+const MAX_SCHEDULED_INSTRUCTIONS_BEFORE_JUMP = 8;
+
+// Starting right after `compareIdx`, find the conditional jump that consumes
+// that compare's flags: skip over instructions that cannot have changed them,
+// stop at anything else. Returns the jump line, or null.
+function findBoundConditionalJump(linesSortedByAddr, compareIdx, hitAddr) {
+ for (let k = 1; k <= MAX_SCHEDULED_INSTRUCTIONS_BEFORE_JUMP + 1; k += 1) {
+ const cand = linesSortedByAddr[compareIdx + k];
+ if (!cand || cand.addr >= hitAddr) return null;
+ if (/^j/.test(cand.mnemonic)) {
+ return cand.mnemonic === 'jmp' ? null : cand;
+ }
+ if (!FLAG_PRESERVING_MNEMONICS.has(cand.mnemonic)) return null;
+ }
+ return null;
+}
+
// True when `text`'s FIRST operand is exactly `reg` (word-bounded, so "cl"
// does not accidentally match inside "rcl" and "eax" does not match "reax").
function firstOperandIsRegister(text, reg) {
@@ -401,12 +450,15 @@ function firstOperandIsRegister(text, reg) {
// land past the hit, followed by an unconditional AVX block;
// F) the isa flag's ADDRESS used only as a bare immediate constant (never
// dereferenced), with an unrelated jump and then the hit.
-// Closed by requiring the conditional jump to sit IMMEDIATELY after a
-// cmp/test instruction (no other instruction between them) that is itself
-// bound to the isa-flag read: either the read line directly compares the
-// flag's memory location (no intermediate register), or the read loads the
-// flag into a register and that SAME register is the compare's first
-// operand. Verified against the real Fundstelle 2a shape (mov ecx,dword ptr
+// Closed by requiring the conditional jump to be the one that consumes a
+// cmp/test instruction that is itself bound to the isa-flag read: either the
+// read line directly compares the flag's memory location (no intermediate
+// register), or the read loads the flag into a register and that SAME
+// register is the compare's first operand. Between that compare and the jump
+// only instructions that cannot have written EFLAGS may stand
+// (FLAG_PRESERVING_MNEMONICS / findBoundConditionalJump above; this used to
+// be a strict "the very next line" rule, which is where false-red form A
+// below came from). Verified against the real Fundstelle 2a shape (mov ecx,dword ptr
// [isa] / cmp ecx,5 / jl) in the fixtures and the unit tests below; the two
// fake-green shapes are checked-in fixtures that must come out UNPROTECTED
// (scripts/__fixtures__/win-isa/fake-*-own-code.*).
@@ -415,14 +467,21 @@ function firstOperandIsRegister(text, reg) {
// this closes real holes, but it is stricter than some genuinely protected
// MSVC code, and rot is the direction that costs a human an hour, not the
// direction that costs a customer a crash, so that trade was made
-// deliberately. Four forms are KNOWN to come out UNPROTECTED (false red)
+// deliberately. Four forms were KNOWN to come out UNPROTECTED (false red)
// even though they are correctly guarded; if the address flagged UNPROTECTED
// matches one of these when disassembled by hand, it is a known codegen
// pattern, not a K1 regression:
-// (i) the exact real shape shipped in wmemcmp (ggml.dll): "cmp [isa],eax
-// / mov rbx,rcx / mov r9,rcx / mov r10,rdx / je <past-the-hit>" -
-// the MSVC scheduler put three unrelated movs between the cmp and
-// the jump instead of emitting them back to back;
+// (i) FIXED, no longer false red, see FLAG_PRESERVING_MNEMONICS and
+// findBoundConditionalJump above and the fixture
+// scheduled-jump-own-code.*: the shape shipped in wmemcmp (ggml.dll),
+// "cmp [isa],eax / mov rbx,rcx / mov r9,rcx / mov r10,rdx /
+// je <past-the-hit>", and the same shape with one intervening mov
+// found in llama.dll on MSVC 14.51 (llama-kv-cache.obj, the two
+// vpmullq at 18007AA0D/18007AA28, lu-301/bau/isa-review-1451.md
+// section 2). The MSVC scheduler put unrelated movs between the cmp
+// and the jump instead of emitting them back to back. Those movs
+// cannot write EFLAGS, so the jump still evaluates that same cmp and
+// the guard now follows it across them;
// (ii) a cached comparison register: "mov eax,[isa] / mov ecx,eax /
// cmp ecx,6 / jl <past-the-hit>" - the load and the compare use
// different registers, linked through a copy checkDominance does
@@ -484,9 +543,8 @@ export function checkDominance(linesSortedByAddr, isaVAs, functionStart, functio
if (!compareLine) continue;
const compareIdx = linesSortedByAddr.indexOf(compareLine);
- const jumpLine = linesSortedByAddr[compareIdx + 1];
- if (!jumpLine || jumpLine.addr >= hitAddr) continue;
- if (!/^j/.test(jumpLine.mnemonic) || jumpLine.mnemonic === 'jmp') continue;
+ const jumpLine = findBoundConditionalJump(linesSortedByAddr, compareIdx, hitAddr);
+ if (!jumpLine) continue;
const m = /([0-9A-Fa-f]{6,16})h?\s*$/.exec(jumpLine.text.trim());
if (!m) continue;
const target = parseInt(m[1], 16);
@@ -497,7 +555,7 @@ export function checkDominance(linesSortedByAddr, isaVAs, functionStart, functio
return {
protected: false,
- reason: `an isa-flag read exists before the hit, but no conditional jump immediately following a cmp/test bound to that same read lands past the hit inside the function (review-waechter-windows.md N1). Disassemble this address by hand before treating it as a build regression: check whether an __isa_available/__isa_enabled/_Avx2WmemEnabled check with a jump over this instruction actually exists in the real disassembly. If it does and only misses this rule's shape (e.g. the scheduler put other instructions between the compare and the jump, the compare uses a cached or partial register, or the guard is a bt/jae bit test - see the four known false-red forms documented above checkDominance), that is a known codegen pattern, not a regression: add a fixture reproducing the exact shape and extend checkDominance with a justification tying it to that fixture, the same way the two fake-green shapes above are fixtured. If no such check exists at all, this is a genuine K1 AVX regression and must be treated as one, not allowlisted away.`,
+ reason: `an isa-flag read exists before the hit, but no conditional jump consuming a cmp/test bound to that same read lands past the hit inside the function (review-waechter-windows.md N1). Disassemble this address by hand before treating it as a build regression: check whether an __isa_available/__isa_enabled/_Avx2WmemEnabled check with a jump over this instruction actually exists in the real disassembly. If it does and only misses this rule's shape (e.g. the compare uses a cached or partial register, or the guard is a bt/jae bit test - see the known false-red forms (ii) to (iv) documented above checkDominance), that is a known codegen pattern, not a regression: add a fixture reproducing the exact shape and extend checkDominance with a justification tying it to that fixture, the same way form (i) and the two fake-green shapes above are fixtured. If no such check exists at all, this is a genuine K1 AVX regression and must be treated as one, not allowlisted away.`,
};
}
diff --git a/scripts/win-isa-guard.test.mjs b/scripts/win-isa-guard.test.mjs
index 076868dc..d6c00f8a 100644
--- a/scripts/win-isa-guard.test.mjs
+++ b/scripts/win-isa-guard.test.mjs
@@ -159,7 +159,7 @@ test('N1: the isa ADDRESS used only as a bare immediate (never dereferenced) doe
assert.equal(dom.protected, false);
});
-test('N1: the conditional jump must immediately follow the bound cmp/test, not merely appear somewhere after it', () => {
+test('N1: an instruction that WRITES EFLAGS between the bound cmp/test and the jump breaks the binding', () => {
const lines = parseDisasmLines([
' 0000000180027ED6: 8B 0D BC 19 07 00 mov ecx,dword ptr [0000000180099898h]',
' 0000000180027F7E: 83 F9 05 cmp ecx,5',
@@ -168,7 +168,70 @@ test('N1: the conditional jump must immediately follow the bound cmp/test, not m
' 0000000180027F83: C4 C2 71 46 C2 vpsravd xmm0,xmm1,xmm10',
].join('\n'));
const dom = checkDominance(lines, [0x180099898], 0x180027e10, 0x180028010, 0x180027f83);
- assert.equal(dom.protected, false, 'an unrelated instruction between the cmp and the jump breaks the "immediately follows" requirement');
+ assert.equal(dom.protected, false, 'the test rax,rax overwrote the flags, so the jl no longer evaluates the isa compare');
+});
+
+// Form (i)/A, see FLAG_PRESERVING_MNEMONICS in win-isa-guard.mjs and the
+// fixture pair scheduled-jump-own-code.* / scheduled-jump-no-guard-own-code.*
+// this pair of tests mirrors in miniature.
+test('form (i): movs between the bound cmp/test and the jump are followed across, because they cannot write EFLAGS', () => {
+ const lines = parseDisasmLines([
+ ' 000000018007A974: 83 3D 15 10 19 00 cmp dword ptr [000000018020B990h],6',
+ ' 000000018007A97B: 4C 8B 19 mov r11,qword ptr [rcx]',
+ ' 000000018007A97E: 0F 8C CA 00 00 00 jl 000000018007AA4E',
+ ' 000000018007AA0D: 62 F2 FD 08 40 D5 vpmullq xmm2,xmm0,xmm5',
+ ' 000000018007AA4E: 48 89 5C 24 20 mov qword ptr [rsp+20h],rbx',
+ ].join('\n'));
+ const dom = checkDominance(lines, [0x18020b990], 0x18007a970, 0x18007ab80, 0x18007aa0d);
+ assert.equal(dom.protected, true, 'the real MSVC 14.51 shape from llama.dll, lu-301/bau/isa-review-1451.md section 2');
+});
+
+test('form (i) is not a free pass: the same shape without the conditional jump stays unprotected', () => {
+ const lines = parseDisasmLines([
+ ' 000000018007A974: 83 3D 15 10 19 00 cmp dword ptr [000000018020B990h],6',
+ ' 000000018007A97B: 4C 8B 19 mov r11,qword ptr [rcx]',
+ ' 000000018007AA0D: 62 F2 FD 08 40 D5 vpmullq xmm2,xmm0,xmm5',
+ ].join('\n'));
+ const dom = checkDominance(lines, [0x18020b990], 0x18007a970, 0x18007ab80, 0x18007aa0d);
+ assert.equal(dom.protected, false);
+});
+
+test('form (i) stops at the cap: more scheduled movs than MAX_SCHEDULED_INSTRUCTIONS_BEFORE_JUMP is not followed', () => {
+ const movs = [];
+ for (let i = 0; i < 9; i += 1) {
+ const addr = (0x18007a980 + i * 3).toString(16).padStart(16, '0').toUpperCase();
+ movs.push(` ${addr}: 4C 8B 19 mov r11,qword ptr [rcx]`);
+ }
+ const lines = parseDisasmLines([
+ ' 000000018007A974: 83 3D 15 10 19 00 cmp dword ptr [000000018020B990h],6',
+ ...movs,
+ ' 000000018007A9A0: 0F 8C CA 00 00 00 jl 000000018007AA4E',
+ ' 000000018007AA0D: 62 F2 FD 08 40 D5 vpmullq xmm2,xmm0,xmm5',
+ ' 000000018007AA4E: 48 89 5C 24 20 mov qword ptr [rsp+20h],rbx',
+ ].join('\n'));
+ const dom = checkDominance(lines, [0x18020b990], 0x18007a970, 0x18007ab80, 0x18007aa0d);
+ assert.equal(dom.protected, false);
+});
+
+test('fixture: scheduled-jump-own-code (real MSVC 14.51 llama.dll form (i)) -> ALLOWED_PROTECTED', () => {
+ const { disasmText, mapText } = loadFixture('scheduled-jump-own-code');
+ const result = evaluateModule({ moduleName: 'scheduled-jump-own-code', disasmText, mapText });
+ assert.equal(result.hitCount, 2, 'both vpmullq are VEX/EVEX hits');
+ assert.equal(result.ownedHitCount, 2);
+ assert.equal(result.decodeArtifactCount, 0, 'xmm0/xmm2/xmm5 are not APX registers');
+ assert.equal(result.unprotected.length, 0);
+ for (const v of result.verdicts) {
+ assert.equal(v.verdict, 'ALLOWED_PROTECTED');
+ assert.equal(v.owner.obj, 'llama-kv-cache.obj', 'own code, so the CRT allowlist must not be what saved it');
+ }
+});
+
+test('fixture: scheduled-jump-no-guard-own-code (the same form with the jump removed) MUST stay UNPROTECTED', () => {
+ const { disasmText, mapText } = loadFixture('scheduled-jump-no-guard-own-code');
+ const result = evaluateModule({ moduleName: 'scheduled-jump-no-guard-own-code', disasmText, mapText });
+ assert.equal(result.hitCount, 2);
+ assert.equal(result.unprotected.length, 2);
+ for (const v of result.verdicts) assert.equal(v.verdict, 'UNPROTECTED');
});
test('fixture: fake-unrelated-jump-own-code (Opus pattern A) MUST come out UNPROTECTED', () => {
@@ -307,11 +370,17 @@ test('R7 does not loosen the other fixtures: the red probe and both fake-green s
// A guard rule that excuses a class of hit is exactly the kind of change
// that can quietly take the existing probes with it, so they are asserted
// again from here rather than only in their own tests above.
- for (const name of ['unprotected-own-code', 'fake-unrelated-jump-own-code', 'fake-address-as-constant-own-code']) {
+ const stillRed = [
+ ['unprotected-own-code', 1],
+ ['fake-unrelated-jump-own-code', 1],
+ ['fake-address-as-constant-own-code', 1],
+ ['scheduled-jump-no-guard-own-code', 2],
+ ];
+ for (const [name, expected] of stillRed) {
const { disasmText, mapText } = loadFixture(name);
const result = evaluateModule({ moduleName: name, disasmText, mapText });
assert.equal(result.decodeArtifactCount, 0, `${name} must not be touched by R7`);
- assert.equal(result.unprotected.length, 1, `${name} must still be RED`);
+ assert.equal(result.unprotected.length, expected, `${name} must still be RED`);
}
});