import assert from'node:assert/strict';import{createHash}from'node:crypto';import{inspectMetricsInputs}from'./cpu-watchdog-metrics-inputs-proof.mjs';import{watchdogSymbols}from'./cpu-watchdog-capture.mjs'; export const watchdogModelLayout=[32,0,8,16,24,72,0,32,40,48,56,64,80,0,72,56,0,32,40,48,168,0,8,16,112,120,128,136,144,152,160,32,0,8,16,24],watchdogSlotLayout=[80,0,72,64,0,56,88,0,80]; export const watchdogCodeHashes={watchdogCycle:[1304,'cb82438ef1427d5749a3073d2feffbc21e3d6a14a5642ebe00eec0431e19e205'],watchdogDrive:[1624,'1211564938470db21669a1529be7cbad11e221d863218d6fc3758688e44b3112'],watchdogAccept:[140,'39b8bacbc2189b932cb5add8c8a9ecfbe8b3ec91fa7fc87f3c223dd7af399407'],watchdogAcknowledge:[284,'717165b9b449f407d2980b22e0e13ba70df214381812c48c5b3eb1145478c2d8'],watchdogBind:[392,'de13c4d77edbd2d9de41cc1b4e2c7035a225d2a0dd8a64631f22b54077ca062e'],watchdogPoll:[124,'91b8757346f6d21cf538f573a82d73b3592b665e13109c5e47b179751a1bcd0d'],watchdogClose:[88,'57fd7770c2ebb8887e121613fa4c2afeb3dbc9ff8501b88bd7917a21fde98d15'],watchdogCloseCall:[12,'4b42a1e57b8580381cb0358f41a2be306c3d00508f64ca7a512206d9bc438fbf']}; export const watchdogInstructionSites={watchdogCycle:[[652,0xc89ffc38],[660,0xc8dffcec],[672,0xc8dffcec],[760,0xd53800b2],[764,0xd53b4221],[772,0xd5382011],[788,0xd53be032],[1168,0xc89ffd57]],watchdogDrive:[[36,0xd53be036],[40,0xd53be009],[1068,0xd53be028],[1088,0xd53be028],[1108,0xd53be021],[1152,0xf1000d1f],[1164,0xf100111f],[1176,0xf100111f],[1232,0xf100191f],[1260,0xf1000d1f],[1272,0xf100111f],[1388,0xc89ffd28],[1472,0xf100051f],[1480,0xfa440920],[1484,0xfa400900],[1488,0xfa470940],[1528,0xc89ffd36]]}; export const watchdogCallSites=[['watchdogDrive',172,'watchdogBind'],['watchdogDrive',1004,'watchdogAccept'],['watchdogDrive',1020,'watchdogAccept'],['watchdogDrive',1112,'watchdogPoll'],['watchdogDrive',1204,'watchdogCloseCall'],['watchdogDrive',1428,'watchdogAccept'],['watchdogDrive',1436,'watchdogCloseCall'],['watchdogAccept',80,'watchdogAcknowledge'],['watchdogCloseCall',8,'watchdogClose','b']]; export function inspectWatchdogInputs(compiled,symbols){const inherited=inspectMetricsInputs(compiled,symbols);for(const[n,size]of Object.entries(watchdogSymbols)){assert.equal(symbols[n]?.size,size,n);assert.equal(compiled[n]?.length,size,n);}for(const[n,expected]of[['OS_K2095_MODEL_LAYOUT',watchdogModelLayout],['OS_K2095_SLOT_LAYOUT',watchdogSlotLayout]]){assert.deepEqual(Array.from({length:compiled[n].length/8},(_,i)=>Number(compiled[n].readBigUInt64LE(i*8))),expected,n);assert.ok(symbols[n].address>=symbols._image_start.address+64&&symbols[n].address+symbols[n].size<=symbols._text_start.address,'header metadata stays in its alignment gap');} const spans=Object.keys(watchdogSymbols).filter(n=>!n.includes('LAYOUT')).map(n=>symbols[n]).sort((a,b)=>a.address-b.address);for(let i=0;i=symbols.__bss_start.address&&s.address+s.size<=Math.ceil(symbols.__bss_start.address/4096)*4096,'zeroed metadata stays in data-to-BSS gap');if(i)assert.ok(s.address>=spans[i-1].address+spans[i-1].size)} for(const[n,[size,hash]]of Object.entries(watchdogCodeHashes)){assert.equal(compiled[n]?.length,size,n);assert.equal(symbols[n]?.size,size,n);assert.equal(createHash('sha256').update(compiled[n]).digest('hex'),hash,n+' complete compiled code');} for(const[n,sites]of Object.entries(watchdogInstructionSites))for(const[at,op]of sites)assert.equal(compiled[n].readUInt32LE(at),op,n+' response gate '+at); for(const[n,at,to,kind]of watchdogCallSites){const op=compiled[n].readUInt32LE(at);assert.equal((op&0xfc000000)>>>0,kind==='b'?0x14000000:0x94000000);assert.equal(symbols[n].address+at+((op<<6)>>4),symbols[to].address,n+' calls '+to);} return{...inherited,watchdogCompiledCodeBytes:3968,watchdogCompiledModelBytes:888,watchdogCompiledCallSites:9,watchdogMetadataPackedWithoutOverlap:true}; }