from pathlib import Path import json,hashlib,tempfile,shutil,struct,subprocess base=Path('reports/os-implementation');c=base/'K2100-overlap-service-staging-BuMNeN/product-one-bank-direct-256-mode-210';cp=json.loads((c/'smp-worker-checkpoints.json').read_text())[0] def words(p):b=Path(p).read_bytes();return list(struct.unpack('<'+'Q'*(len(b)//8),b)) e=words(cp['dumps']['OS_K2045_EVIDENCE']['path']);layout=e[102:126];b=Path(cp['dumps']['authority']['path']).read_bytes();u=lambda off:struct.unpack_from('=16*4096);old=[e[40+i]+j*4096 for i in range(6)for j in range(5)];assert len(set(old))==30 and all(a in live for a in old) out=Path(tempfile.mkdtemp(prefix='K2100-overlap-capacity-review-',dir=base));source=base/'K2100-overlap-service-preflight-d3dp7s/sources/kernel/src/runtime' for f in ['frame_authority.rs','platform_ram.rs']:shutil.copyfile(source/f,out/f) shutil.copyfile(__file__,out/'harness.py.txt') rs='''#![allow(dead_code)] mod platform_ram;mod frame_authority; use frame_authority::{Allocator,Plan,Error,MAX_LIVE};use platform_ram::Region; fn main(){assert_eq!(MAX_LIVE,80);let mut a=Allocator::uninitialized();a.initialize(Plan::already_admitted(&[Region{start:0x40000000,end:0x50000000}]).unwrap(),2100).unwrap(); let addresses: [u64;74]=LIVE;let retired:[u64;30]=OLD;let mut owned=addresses.into_iter().map(|p|Some(a.allocate_at(p).unwrap())).collect::>();let before=a.audit().unwrap();assert_eq!(before.live_pages,74); let mut rx=Vec::new();for i in 0..6{rx.push(a.allocate_at(START+i*4096).unwrap());}let full=a.audit().unwrap();assert_eq!(full.live_pages,80);assert_eq!(a.allocate_at(START+6*4096).err(),Some(Error::Capacity));assert_eq!(a.audit().unwrap(),full); for p in rx{a.release(&p).unwrap();}assert_eq!(a.audit().unwrap(),before); for address in retired{let i=owned.iter().position(|p|p.as_ref().is_some_and(|p|p.address()==address)).unwrap();let p=owned[i].take().unwrap();a.release(&p).unwrap();} let ready=a.audit().unwrap();assert_eq!(ready.live_pages,44);let mut rx=Vec::new();for i in 0..7{rx.push(a.allocate_at(START+i*4096).unwrap());}assert_eq!(a.audit().unwrap().live_pages,51);for p in rx{a.release(&p).unwrap();}assert_eq!(a.audit().unwrap(),ready); let mut process=Vec::new();for _ in 0..34{process.push(a.allocate().unwrap());}assert_eq!(a.audit().unwrap().live_pages,78);for p in process{a.release(&p).unwrap();}assert_eq!(a.audit().unwrap(),ready);println!("actual_native_allocator: original74+RX7 rejected_at_80; early_retire30 ->44; RX7=51; process_peak=78; limit80 unchanged; all acquired leases returned");} '''.replace('LIVE',str(live),1) if False else '' # Keep the MAX_LIVE identifier intact when substituting data placeholders. rs='''#![allow(dead_code)] mod platform_ram;mod frame_authority; use frame_authority::{Allocator,Plan,Error,MAX_LIVE};use platform_ram::Region; fn main(){assert_eq!(MAX_LIVE,80);let mut a=Allocator::uninitialized();a.initialize(Plan::already_admitted(&[Region{start:0x40000000,end:0x50000000}]).unwrap(),2100).unwrap(); let addresses:[u64;74]=__LIVE__;let retired:[u64;30]=__OLD__;let mut owned=addresses.into_iter().map(|p|Some(a.allocate_at(p).unwrap())).collect::>();let before=a.audit().unwrap();assert_eq!(before.live_pages,74); let mut rx=Vec::new();for i in 0..6{rx.push(a.allocate_at(__START__+i*4096).unwrap());}let full=a.audit().unwrap();assert_eq!(full.live_pages,80);assert_eq!(a.allocate_at(__START__+6*4096).err(),Some(Error::Capacity));assert_eq!(a.audit().unwrap(),full); for p in rx{a.release(&p).unwrap();}assert_eq!(a.audit().unwrap(),before); for address in retired{let i=owned.iter().position(|p|p.as_ref().is_some_and(|p|p.address()==address)).unwrap();let p=owned[i].take().unwrap();a.release(&p).unwrap();} let ready=a.audit().unwrap();assert_eq!(ready.live_pages,44);let mut rx=Vec::new();for i in 0..7{rx.push(a.allocate_at(__START__+i*4096).unwrap());}assert_eq!(a.audit().unwrap().live_pages,51);for p in rx{a.release(&p).unwrap();}assert_eq!(a.audit().unwrap(),ready); let mut process=Vec::new();for _ in 0..34{process.push(a.allocate().unwrap());}assert_eq!(a.audit().unwrap().live_pages,78);for p in process{a.release(&p).unwrap();}assert_eq!(a.audit().unwrap(),ready);println!("actual_native_allocator: original74+RX7 rejected_at_80; early_retire30 ->44; RX7=51; process_peak=78; limit80 unchanged; all acquired leases returned");} '''.replace('__LIVE__',str(live)).replace('__OLD__',str(old)).replace('__START__',str(start)+'u64');(out/'capacity.rs').write_text(rs) build=subprocess.run(['rustc','--edition=2024',str(out/'capacity.rs'),'-o',str(out/'capacity')],capture_output=True,text=True);(out/'compile.log').write_text(build.stdout+build.stderr);assert build.returncode==0,build.stderr run=subprocess.run([str(out/'capacity')],capture_output=True,text=True);(out/'test.log').write_text(run.stdout+run.stderr);assert run.returncode==0,run.stderr art=lambda p:{'path':str(p),'sha256':hashlib.sha256(Path(p).read_bytes()).hexdigest()} r={'status':'OVERLAP_CAPACITY_DIAGNOSED_AND_TESTED','guestAccepted':False,'productAccepted':False,'scope':'Exact native allocator source replayed on host with the 74 active addresses captured from the failed guest. RX allocation seven exceeds the unchanged 80-record capacity. Returning the 30 pages of finished inherited queue threads leaves 44 records; RX7 and a 34-frame process resource peak then fit. This host occupancy replay is not guest acceptance.','activeRecords':74,'maximumRecords':80,'earlyRetiredPages':30,'retainedRecordsAfter':44,'rxPeak':51,'processPeak':78,'authority':cp['dumps']['authority'],'evidence':cp['dumps']['OS_K2045_EVIDENCE'],'source':art(out/'frame_authority.rs'),'platform':art(out/'platform_ram.rs'),'fixture':art(out/'capacity.rs'),'harness':art(out/'harness.py.txt'),'log':art(out/'test.log'),'failedSerial':art(c/'failed-serial.log')} (out/'report.json').write_text(json.dumps(r,indent=2)+'\n');print(out/'report.json');print(run.stdout)