"""Execute compiled window observation after the resource-helper boundary. All inputs are modeled host fixtures. The actual resource function is validated separately; this proof starts at its compiled return-site and uses its explicit Result bytes. Guest timing and whole-kernel behavior remain separate evidence. """ from pathlib import Path import hashlib import importlib.util import json import re import shutil import subprocess import sys import tempfile machine_path = Path(__file__).with_name('k2100-aarch64-admission-machine.py') spec = importlib.util.spec_from_file_location('admission_machine', machine_path) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) Machine = module.AdmissionMachine out = Path(tempfile.mkdtemp(prefix='K2100-native-window-flow-proof-', dir='reports/os-implementation')) shutil.copyfile(__file__, out / 'harness.py.txt') shutil.copyfile(machine_path, out / 'machine.py.txt') def artifact(path): path = Path(path) return dict(path=str(path), sha256=hashlib.sha256(path.read_bytes()).hexdigest()) def checked(a): assert artifact(a['path'])['sha256'] == a['sha256'] return Path(a['path']).read_bytes() def pack(values): return b''.join(int(v).to_bytes(8, 'little') for v in values) try: preflight_path = Path(sys.argv[1]) pre = json.loads(preflight_path.read_text()) assert pre['status'] == 'NATIVE_MODELS_COMPILED' image = checked(pre['artifacts']['image']) checked(pre['artifacts']['elf']) symbol_rows = [] for line in checked(pre['artifacts']['nm']).decode().splitlines(): a = line.split() if len(a) == 4: symbol_rows.append(dict(address=int(a[0], 16), size=int(a[1], 16), kind=a[2], name=a[3])) def pick(part, exact=False): rows = [s for s in symbol_rows if (s['name'] == part if exact else part in s['name']) and s['size'] and not s['name'].startswith('_RNC')] assert len(rows) == 1, (part, len(rows)) return rows[0] base = next(s['address'] for s in symbol_rows if s['name'] == '_image_start') bss_end = next(s['address'] for s in symbol_rows if s['name'] == '__bss_end') initial = bytearray(max(len(image), bss_end - base)) initial[:len(image)] = image selected = {key: pick(fragment) for key, fragment in [('window', '8duration6window'), ('observation', '8duration11observation')]} sysroot = subprocess.check_output(['rustc', '--print', 'sysroot'], text=True).strip() host = next(l[6:] for l in subprocess.check_output(['rustc', '-vV'], text=True).splitlines() if l.startswith('host: ')) objdump = sysroot + '/lib/rustlib/' + host + '/bin/llvm-objdump' instructions = {} decoded_functions = {} def decode(symbol): address, size = symbol['address'], symbol['size'] if address in decoded_functions: return text = subprocess.check_output([objdump, '-d', '--start-address=' + str(address), '--stop-address=' + str(address + size), pre['artifacts']['elf']['path']], text=True) path = out / (hex(address) + '.txt') path.write_text(text) local = {} for line in text.splitlines(): m = re.match(r'^\s*([0-9a-f]+):\s+([0-9a-f]{8})\s+(\S+)(.*)$', line) if not m: continue pc, raw = int(m[1], 16), int(m[2], 16) assert raw == int.from_bytes(image[pc - base:pc - base + 4], 'little') local[pc] = (m[3], re.sub(r'<[^>]*>', '', m[4].split('//', 1)[0]).strip()) assert len(local) * 4 == size assert not instructions.keys() & local.keys() instructions.update(local) decoded_functions[address] = {**symbol, 'disassembly': artifact(path)} for pc in local: raw = int.from_bytes(image[pc - base:pc - base + 4], 'little') if raw & 0x7c000000 != 0x14000000: continue immediate = raw & 0x3ffffff if immediate & (1 << 25): immediate -= 1 << 26 target = pc + immediate * 4 if address <= target < address + size: continue # Outliner labels can be duplicated across LLVM codegen units. # Resolve the actual call target address, never a name-keyed map. if target == pick('8duration9resources')['address']: continue targets = [s for s in symbol_rows if s['address'] == target and s['size'] and s['kind'] in ('t', 'T')] assert targets and len({s['size'] for s in targets}) == 1, (hex(target), targets) decode(targets[0]) for symbol in selected.values(): decode(symbol) locations = {name: pick(name,True)['address'] for name in ['OS_K2100_WORKLOAD_BINDINGS','OS_K2100_WORKLOAD_PROGRESS','OS_K2100_WORKLOAD_MONITOR','OS_K2100_WORKLOAD_SUMMARY']} baseline = pick('8duration8BASELINE')['address'] stack = 0x70000000 cases=[];visited=set() # The actual compiled Result layout is tag, Resources(3), Audit(7). audit = [65536,256,32,65248,65024,192,32] default_resources=[audit[3],4,4] default_progress=[30,20,10,10,10,10] assert instructions[0x40242720] == ('ldp','x8, x19, [sp, #0x180]') assert instructions[0x4024278c][0] == 'bl' assert instructions[0x4024296c] == ('b','0x4024278c') def raw_at(m,address,size): data,at=m.locate(address,size);return bytes(data[at:at+size]) def write_bytes(m,address,data): region,at=m.locate(address,len(data));region[at:at+len(data)]=data def execute(count,label,mutation=None,valid=False,hardware=None,resource_failure=False): hw=dict(mpidr_el1=0,daif=960,currentel=4,ttbr0_el1=0x40000000,tcr_el1=0,sctlr_el1=0,spsel=1,cntpct_el0=300) if hardware:hw.update(hardware) m=Machine(instructions,[(base,initial),(stack,bytes(65536))],hw);m.sp=stack+0x4000 resources=[audit[3],count,count] bindings=[];prior_progress=[];next_progress=[];cpu_rows=[] for cpu in range(4): binding=[1,0x2100,cpu,1] if cpu