Files
nvdriver/tools/check_pf_illumination_bindings_binary.py

39 lines
3.2 KiB
Python

#!/usr/bin/env python3
"""Original pure GPIO/DISP assignment instructions, no target execution/hardware."""
from pathlib import Path
import hashlib,json,struct,warnings
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=Path('/home/geodd/nvidia-driver/analysis-580.178.04/extracted/kernel/nvidia/nv-kernel.o_binary')
SHA='5269a23ffba19a17fe16f076463e7ad4151254659441d1711bee6c6221ff6f4b'
assert hashlib.sha256(P.read_bytes()).hexdigest()==SHA
TEXT=0x10000000;DATA=0x30000000;STACK=0x40000000;STOP=0x60000000
with P.open('rb') as f:
e=ELFFile(f);symbols=list(e.get_section_by_name('.symtab').iter_symbols());byname={s.name:s for s in symbols};text=bytearray(e.get_section_by_name('.text').data());index=e.get_section_index('.text')
names=['_nv005976rm','_nv005966rm'];ranges=[(byname[n]['st_value'],byname[n]['st_size']) for n in names]
for rel in e.get_section_by_name('.rela.text').iter_relocations():
off=rel['r_offset']
if not any(a<=off<a+size for a,size in ranges):continue
sym=symbols[rel['r_info_sym']];assert rel['r_info_type']==11 and sym['st_shndx']==index
struct.pack_into('<i',text,off,TEXT+sym['st_value']+rel['r_addend'])
reverse={TEXT+s['st_value']:s.name for s in symbols if s['st_info']['type']=='STT_FUNC'}
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+0x20010,struct.pack('<H',2));uc.mem_write(DATA+0x21010,struct.pack('<H',0x23))
rows=[]
for disp_ip in range(64):
uc.mem_write(DATA+0x20012,struct.pack('<H',disp_ip))
for name,offsets in [('_nv005976rm',[0x2b0]),('_nv005966rm',[0x11e0,0x11e8])]:
uc.mem_write(DATA,bytes(0x10000));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+byname[name]['st_value'],STOP,count=20000);assert uc.reg_read(UC_X86_REG_RIP)==STOP
for offset in offsets:
target=reverse[struct.unpack('<Q',uc.mem_read(DATA+offset,8))[0]]
expected='_nv029937rm' if offset==0x2b0 else ({0x11e0:'_nv024753rm',0x11e8:'_nv023428rm'} if disp_ip==9 else {0x11e0:'_nv024751rm',0x11e8:'_nv023426rm'})[offset]
assert target==expected,(disp_ip,hex(offset),target,expected)
rows.append({'setter':name,'chip_hal':35,'rm_hal':2,'display_ip_hal':disp_ip,'offset':hex(offset),'target':target})
report={'artifact_sha256':SHA,'passed':True,'rows':rows,'limits':['Pure original assignment instructions only. No native target calls or hardware access.','Dispatch is parametrized by actual Display IP; this does not assert a physical GV100 device has IP HAL9.','GPU forwarding bindings +668/+670 come from prior hash-pinned GPU HAL binder plus fresh target instructions.']}
(R/'reports/gpu-pf-illumination-bindings.json').write_text(json.dumps(report,indent=2)+'\n')
print(len(rows),'GPIO/DISP callback bindings verified; no assumed Display IP')