import assert from 'node:assert/strict'; import {faultStageOrder} from './k2155-native-fault-stages.mjs'; import {checkFaultOwnership} from './k2155-native-fault-ownership-check.mjs'; import {checkFaultWorkers} from './k2155-native-fault-worker-check.mjs'; import {checkFaultIrqs} from './k2155-native-fault-irq-check.mjs'; import {checkFaultDma} from './k2155-native-fault-dma-check.mjs'; const W=b=>Array.from({length:b.length/8},(_,i)=>b.readBigUInt64LE(i*8)); export function checkNativeFault(input){ const {snapshots,faultId}=input,stages=snapshots.map(s=>Number(s.OS_K2155_EVIDENCE.readBigUInt64LE(8))),c=faultStageOrder(stages,faultId); const before=snapshots[0].OS_K2155_EVIDENCE.readBigUInt64LE(16),guard=snapshots[1].OS_K2155_THREAD_GUARDS.readBigUInt64LE(24); let previous=0n; for(const[index,s]of snapshots.entries()){ const f=W(s.OS_K2155_FAULT_STATE),calls=W(s.OS_K2155_FAULT_IO_CALLS),native=W(s.OS_K2155_NATIVE_STATE),final=stages[index]===80; assert.equal(f.length,32);assert.equal(calls.length,1);assert.ok(calls[0]>=previous);previous=calls[0];assert.ok(calls[0]>=native[2]); const expected=Array(32).fill(0n);expected[0]=0x4b32313535464155n;expected[1]=BigInt(faultId);expected[10]=before; if(faultId===3&&index>=15){expected[8]=guard;expected[9]=0x4b313032304c4f56n;} if(final){ expected[2]=BigInt(c.phase);expected[3]=BigInt(c.error);expected[4]=1n;expected[5]=faultId===5?2n:0n;expected[6]=faultId===5?0xffffffffffffffffn:22n; expected[11]=before-34n+BigInt(c.releasedPages);expected[12]=BigInt(c.nativePhase);expected[13]=native[20];expected[14]=faultId===5?1n:0n; expected[16]=BigInt(c.liveThreads);expected[17]=BigInt(c.masked);expected[19]=1n;expected[20]=expected[21]=calls[0];expected[23]=1n;expected[24]=2n;expected[25]=1n; assert.ok(calls[0]>0n);if(faultId===5)assert.ok(calls[0]>native[2]);else assert.equal(calls[0],native[2]); }else if(index<15)assert.equal(calls[0],0n); assert.deepEqual(f,expected,'exact refusal status; no invented held count after partial release'); } return {case:c,ownership:checkFaultOwnership(input),workers:checkFaultWorkers(input),irqs:checkFaultIrqs(input),dma:checkFaultDma(input), cleanReceipt:false,authorizationReusable:false,retryAccessesBackend:false,guestAccepted:false,productAccepted:false}; }