mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 14:38:47 +00:00
30 lines
3.2 KiB
Python
30 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Independently validate original selected GV100 Lpwr child+108 binding."""
|
|
from pathlib import Path
|
|
import argparse,hashlib,json,struct,subprocess
|
|
from elftools.elf.elffile import ELFFile
|
|
root=Path(__file__).resolve().parent.parent
|
|
p=argparse.ArgumentParser();p.add_argument('--check',action='store_true');args=p.parse_args()
|
|
source=Path('/home/geodd/nvidia-driver/analysis-580.178.04/extracted/kernel/nvidia/nv-kernel.o_binary')
|
|
with source.open('rb') as stream:
|
|
elf=ELFFile(stream);symbols=list(elf.get_section_by_name('.symtab').iter_symbols());by_name={s.name:s for s in symbols};rodata=elf.get_section_by_name('.rodata').data()
|
|
owner=by_name['_nv003037rm'];child=by_name['_nv002888rm']
|
|
owner_meta=struct.unpack_from('<II',rodata,owner['st_value']);child_meta=struct.unpack_from('<II',rodata,child['st_value'])
|
|
assert owner_meta==(0x1230,0x112230) and child_meta==(0x13910,0x8ae552)
|
|
# Lpwr vtable base5160 has metadata003037; StateInit at+f0=042751.
|
|
rel={r['r_offset']:r for r in elf.get_section_by_name('.rela.rodata').iter_relocations()}
|
|
assert symbols[rel[0x4dc5160]['r_info_sym']].name=='_nv003037rm'
|
|
assert symbols[rel[0x4dc5250]['r_info_sym']].name=='_nv042751rm'
|
|
method=by_name['_nv019295rm'];text=elf.get_section(method['st_shndx']).data();raw=text[method['st_value']:method['st_value']+method['st_size']]
|
|
assert raw==bytes.fromhex('f30f1efac3'), raw.hex() # Original ENDBR64; RET.
|
|
fixture=root/'tools/gpu_gv100_lpwr108_bindings_eval.c';binary=root/'target/lpwr108-binding-oracle';binary.parent.mkdir(exist_ok=True)
|
|
subprocess.run(['cc','-std=gnu11','-O0','-fno-strict-aliasing',str(fixture),'-o',str(binary)],check=True)
|
|
lines=subprocess.check_output([str(binary)],text=True).splitlines()
|
|
assert lines==[f'chip{chip:02x} RM{i} +108={fn}' for chip,fn in [(0x23,'_nv019295rm'),(0x34,'_nv019288rm'),(0x3d,'_nv019290rm'),(0x3c,'_nv019294rm')] for i in range(3)]
|
|
report={'source_sha256':hashlib.sha256(source.read_bytes()).hexdigest(),'fixture_sha256':hashlib.sha256(fixture.read_bytes()).hexdigest(),'owner_metadata':{'symbol':owner.name,'bytes':owner_meta[0],'class_id':hex(owner_meta[1]),'public_name':'Lpwr'},'child_metadata':{'symbol':child.name,'bytes':child_meta[0],'class_id':hex(child_meta[1]),'name':'unresolved; use numeric class ID'},'owner_original_vtable':{'section_offset':'0x4dc5160','state_init_offset':'0xf0','state_init_function':'_nv042751rm'},'GV100_chip_HAL':'0x23','selected_runtime_bindings':lines[:3],'other_chip_counterexamples':lines[3:],'selected_function':'_nv019295rm','original_text_bytes':raw.hex(),'limits':['Compiled literal inferred original HAL setter with address-only callbacks. No original constructor execution.','Original selected callback bytes are verified ENDBR64; RET, so no memory/state/IO effects.','Full Lpwr/child initialization and actual constructed input objects remain required elsewhere.','No hardware or original machine-code execution.']}
|
|
out=root/'reports/gpu-gv100-lpwr108-oracle.json';payload=json.dumps(report,indent=2)+'\n'
|
|
if args.check:
|
|
if out.read_text()!=payload:raise SystemExit('Stale '+str(out))
|
|
else:out.write_text(payload)
|
|
print('Original GV100 Lpwr child+108:3 RM bindings+9 other-chip counterexamples; exact ENDBR64/RET bytes verified')
|