#!/usr/bin/env python3 """Exact selected020153 base-level cache-prefix stores from original inference.""" from pathlib import Path import re,json,argparse,hashlib,subprocess r=Path(__file__).resolve().parent.parent;p=argparse.ArgumentParser();p.add_argument('--check',action='store_true');a=p.parse_args() s=next(Path('/home/geodd/nvidia-driver/analysis-580.178.04/decompiled/kernel-rm-all/functions').glob('*/*__nv020153rm.c')).read_text();s=s[:s.index(' lVar11 = *(long *)(param_1 + 0x1ec0);')] rows=[] for index,value in re.findall(r'(?:\*param_5|param_5\[([^]]+)\]) = (0x[0-9a-f]+);',s): i=0 if not index else int(index,0);assert i%4==0;rows.append((i//4,int(value,16))) flags=[int(off,16)//16 for off in re.findall(r'\*\(undefined1 \*\)\(\(long\)param_5 \+ (0x[0-9a-f]+)\) = 0;',s)] assert [i for i,v in rows]==list(range(66))+list(range(67,75)) and flags==list(range(66)) code='// Generated from literal original020153 base-level cache prefix.\nconst ADDRESS_STORES: &[(usize,u32)] = &[\n'+''.join(f' ({i},0x{v:x}),\n' for i,v in rows)+'];\n' toolchain=re.search(r'channel\s*=\s*"([^"]+)"',(r/'rust-toolchain.toml').read_text()).group(1) code=subprocess.run([str(Path.home()/'.rustup/toolchains'/f'{toolchain}-x86_64-unknown-linux-gnu/bin/rustfmt'),'--edition','2024'],input=code,text=True,capture_output=True,check=True).stdout report={'source_sha256':'5269a23ffba19a17fe16f076463e7ad4151254659441d1711bee6c6221ff6f4b','inferred_prefix_sha256':hashlib.sha256(s.encode()).hexdigest(),'address_stores':rows,'clear_byte_d_rows':flags,'untouched_address_rows':[66]+list(range(75,130)),'limits':'Only actual constructor stores; all other record fields retain caller-provided state. No empty/default records or hardware access.'} for out,text in [(r/'src/nvidia/src/gpu/clock_cache_data.rs',code),(r/'reports/gpu-clock-cache-data.json',json.dumps(report,indent=2)+'\n')]: if a.check: if out.read_text()!=text:raise SystemExit('Stale '+str(out)) else:out.write_text(text) print('Original020153cache:74address stores,66byteD clears; record66 address untouched')