mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 14:38:47 +00:00
38 lines
3.3 KiB
Python
38 lines
3.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Evaluate the original timer setter and assert selected GV100 time-read bindings."""
|
|
import hashlib,json,struct,warnings
|
|
from _binary_path import resolve_580_binary
|
|
from pathlib import Path
|
|
warnings.filterwarnings('ignore',category=UserWarning,module='unicorn')
|
|
from elftools.elf.elffile import ELFFile
|
|
from unicorn import Uc,UC_ARCH_X86,UC_MODE_64
|
|
from unicorn.x86_const import *
|
|
R=Path(__file__).resolve().parents[1];P=resolve_580_binary()
|
|
TEXT=0x10000000;DATA=0x30000000;STACK=0x40000000;STOP=0x60000000
|
|
sets={'OBJTMR':['_nv006016rm']};all_names=sum(sets.values(),[])
|
|
expected={'OBJTMR':{0x190:'_nv059661rm',0x1a0:'_nv059635rm',0x1b8:'_nv059597rm',0x1c0:'_nv059609rm',0x1c8:'_nv059606rm',0x1d0:'_nv059583rm',0x1e8:'_nv059571rm',0x1f8:'_nv059648rm',0x208:'_nv059576rm'}}
|
|
with P.open('rb') as f:
|
|
e=ELFFile(f);symbols=list(e.get_section_by_name('.symtab').iter_symbols());defined={s.name:s for s in symbols};text=bytearray(e.get_section_by_name('.text').data());text_index=e.get_section_index('.text');functions={n:(defined[n]['st_value'],defined[n]['st_size']) for n in all_names};relocations=0
|
|
for r in e.get_section_by_name('.rela.text').iter_relocations():
|
|
off=r['r_offset']
|
|
if not any(a<=off<a+size for a,size in functions.values()):continue
|
|
s=symbols[r['r_info_sym']];assert r['r_info_type']==11 and s['st_shndx']==text_index
|
|
struct.pack_into('<i',text,off,TEXT+s['st_value']+r['r_addend']);relocations+=1
|
|
uc=Uc(UC_ARCH_X86,UC_MODE_64);uc.mem_map(TEXT,(len(text)+4095)&~4095);uc.mem_write(TEXT,bytes(text));uc.mem_map(DATA,0x30000);uc.mem_map(STACK,0x10000);uc.mem_map(STOP,4096)
|
|
uc.mem_write(DATA+0x20000+16,struct.pack('<H',0x23));uc.mem_write(DATA+0x21000+16,struct.pack('<H',2))
|
|
rows=[]
|
|
for cls,names in sets.items():
|
|
uc.mem_write(DATA,bytes(0x10000))
|
|
for name in names:
|
|
uc.reg_write(UC_X86_REG_RDI,DATA);uc.reg_write(UC_X86_REG_RSI,DATA+0x20000);uc.reg_write(UC_X86_REG_RDX,DATA+0x21000);uc.reg_write(UC_X86_REG_RSP,STACK+0xfff8);uc.reg_write(UC_X86_REG_RBP,STACK+0x8000);uc.mem_write(STACK+0xfff8,struct.pack('<Q',STOP));uc.emu_start(TEXT+functions[name][0],STOP,count=10000);assert uc.reg_read(UC_X86_REG_RIP)==STOP
|
|
reverse={TEXT+s["st_value"]:s.name for s in symbols if s["st_info"]["type"]=="STT_FUNC"}
|
|
for offset in range(0x170,0x280,8):
|
|
actual=struct.unpack('<Q',uc.mem_read(DATA+offset,8))[0]
|
|
if actual:
|
|
rows.append({'class':cls,'offset':hex(offset),'target':reverse.get(actual),'target_text_offset':hex(actual-TEXT)})
|
|
print(hex(offset),reverse.get(actual))
|
|
for offset,target in expected[cls].items():
|
|
actual=struct.unpack('<Q',uc.mem_read(DATA+offset,8))[0];assert actual==TEXT+defined[target]['st_value'],(cls,hex(offset),target,hex(actual));assert any(row['offset']==hex(offset) and row['target']==target for row in rows)
|
|
report={'passed':True,'artifact_sha256':hashlib.sha256(P.read_bytes()).hexdigest(),'architecture_HAL_index':'0x23','runtime_HAL_index':2,'runtime':'PF monolithic','pure_setter_relocations_applied':relocations,'setters':{k:v for k,v in sets.items()},'verified_bindings':rows,'execution':'Original pure assignment instructions only in isolated Unicorn memory; no driver function calls, native execution or hardware access'}
|
|
(R/'reports/gpu-timer-bindings-binary.json').write_text(json.dumps(report,indent=2)+'\n');print(len(rows),'original instruction-emulated GV100 bindings verified')
|