import assert from 'node:assert/strict'; import {prepare,compiled,symbols,bindings,bootId} from './native_irq_fixture.mjs'; import {NATIVE_STAGES} from '../../scripts/os-acceptance/features/k2155-native-capture.mjs'; import {checkNativeIrqs} from '../../scripts/os-acceptance/features/k2155-native-irq-check.mjs'; import {IRQ_FORGERIES,irqForgery} from '../../scripts/os-acceptance/features/k2155-irq-dma-check.mjs'; const W=b=>Array.from({length:b.length/8},(_,i)=>b.readBigUInt64LE(i*8)),l=W(compiled.OS_K2155_IRQ_LAYOUT).map(Number); function fixture(first,tco){ const original=prepare(first,tco),stages=[...NATIVE_STAGES];stages.splice(4,4,first,first+1,first===100?110:100,first===100?111:101); const snapshots=stages.map((stage,index)=>{ const source=index<2?0:index<4?1:index<8?index-2:6,s=Object.fromEntries(Object.entries(original[source]).map(([k,b])=>[k,Buffer.from(b)])); s.OS_K2155_EVIDENCE=Buffer.alloc(512);s.OS_K2155_EVIDENCE.writeBigUInt64LE(0x4b32313535494e54n);s.OS_K2155_EVIDENCE.writeBigUInt64LE(BigInt(stage),8); s.OS_K2155_CPU_STATE=Buffer.alloc(64); if(index>=4&&index<8){const entry=W(s.OS_K2155_IRQ_EVENTS).slice((index>=6?1:0)*16);s.OS_K2155_CPU_STATE.writeBigUInt64LE(BigInt(symbols.__os_k2155_irq_vectors.address),8);s.OS_K2155_CPU_STATE.writeBigUInt64LE(entry[3]-512n,24);} if(index>=8&&index<16){s.OS_K2155_IRQ_STATE.writeBigUInt64LE(0n,128);s['irq-owner'][l[17]]=0;s['irq-owner'][l[18]]=0;for(let d=0;d<2;d++)s['gic-'+d+'-enable'].writeUInt32LE(0xc000,0);} if(stage===70)delete s['irq-owner'];return s; });return {snapshots,compiled,symbols,bindings,bootId}; } const rejected=[]; for(const first of [100,110])for(const tco of [0n,1n<<25n]){ const input=fixture(first,tco);assert.equal(checkNativeIrqs(input).handlerEretVerified,true); for(const entry of IRQ_FORGERIES){ if(entry[0]==='false-mask-extension-flag')continue; const changed=[...entry];changed[1]=entry[1]===0?1:entry[1]===2?4:entry[1]===3?5:entry[0]==='masked-source-enabled'?16:8; assert.throws(()=>checkNativeIrqs({...input,snapshots:irqForgery(input.snapshots,changed,compiled)}),entry[0]);rejected.push(first+':'+tco+':'+entry[0]); } for(const[name,stage,key,offset]of [['false-mask-native-view',20,'OS_K2155_IRQ_STATE',128],['mask-before-authorized-request',2,'gic-0-enable',1],['callback-sp-above-frame',first,'OS_K2155_CPU_STATE',26]]){ const copy=input.snapshots.map(s=>({...s})),i=copy.findIndex(s=>Number(s.OS_K2155_EVIDENCE.readBigUInt64LE(8))===stage);copy[i][key]=Buffer.from(copy[i][key]);copy[i][key][offset]^=name==='callback-sp-above-frame'?0x10:name==='mask-before-authorized-request'?0x80:1; if(name==='callback-sp-above-frame')copy[i][key].writeBigUInt64LE(copy[i]['irq-frame'].readBigUInt64LE(l[22]),24); assert.throws(()=>checkNativeIrqs({...input,snapshots:copy}),name);rejected.push(first+':'+tco+':'+name); } const copy=input.snapshots.map(s=>({...s}));copy.at(-1)['irq-owner']=Buffer.from(input.snapshots.at(-2)['irq-owner']);assert.throws(()=>checkNativeIrqs({...input,snapshots:copy}),'expired-owner');rejected.push(first+':'+tco+':expired-owner'); } console.log(JSON.stringify({status:'NATIVE_IRQ_HOST_TESTS_PASSED',syntheticFixture:true,positiveFixtures:4,rejected,guestAccepted:false,productAccepted:false,fullNativeShutdownVerified:false}));