mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 14:38:47 +00:00
19 lines
3.6 KiB
Python
19 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Read-only verification of exact original engine dispatcher HW-breakpoint sites."""
|
|
from pathlib import Path
|
|
from elftools.elf.elffile import ELFFile
|
|
import json,struct,subprocess,hashlib
|
|
R=Path(__file__).resolve().parents[1];C=Path('/root/.debug/[kernel.kcore]/a3aac8f0306fd819566d868c7c422dbdcf1e7d42/2026111719514581');M=Path('/lib/modules/5.15.0-202-generic/updates/dkms/nvidia.ko');K=R/'reports/original-live-init-pt-3/kallsyms.txt';lookup={}
|
|
for line in K.read_text().splitlines():
|
|
fields=line.split()
|
|
if len(fields)>=3:lookup[fields[2]]=int(fields[0],16)
|
|
sites=[('InitUnlocked','_nv026844rm',0x3e,0x58,True),('InitLocked','_nv026844rm',0x80,0x50,False),('PreLoad','_nv031217rm',0x184,0x60,False),('Load','_nv031217rm',0x31f,0x68,False)]
|
|
with M.open('rb')as f:
|
|
e=ELFFile(f);s=e.get_section_by_name('.symtab');symbols={s.name:s for s in s.iter_symbols()};text=e.get_section_by_name('.text').data();disk={name:text[symbols[name]['st_value']:symbols[name]['st_value']+symbols[name]['st_size']]for name in ['_nv026844rm','_nv031217rm','_nv031215rm']};assembly={name:subprocess.check_output(['objdump','-d','--disassemble='+name,str(M)],text=True)for name in disk}
|
|
with(C/'kcore').open('rb')as f:
|
|
e=ELFFile(f);segments=[p for p in e.iter_segments()if p['p_type']=='PT_LOAD'];rows=[]
|
|
for stage,name,off,slot,optional in sites:
|
|
ip=lookup[name]+off;ph=next(p for p in segments if p['p_vaddr']<=ip-16 and ip+16<=p['p_vaddr']+p['p_filesz']);f.seek(ph['p_offset']+ip-16-ph['p_vaddr']);live=f.read(32);instruction=live[16:21];target=ip+5+struct.unpack('<i',instruction[1:5])[0]if instruction[0]in[0xe8,0xe9]else None
|
|
rows.append({'stage':stage,'symbol':name,'symbol_offset':hex(off),'runtime_ip':hex(ip),'original_rm_text_offset':hex(symbols[name]['st_value']-0x200d0+off),'installed_module_text_offset':hex(symbols[name]['st_value']+off),'installed_instruction5_hex':disk[name][off:off+5].hex(),'cached_runtime_instruction5_hex':instruction.hex(),'cached_runtime_context32_hex':live.hex(),'branch_target':hex(target)if target else None,'target_is_actual_kernel_rax_thunk':target==lookup['__x86_indirect_thunk_rax'],'vtable_slot':hex(slot),'intr_registers':{'AX':'actual immediate method address (RAX)','DI':'GPU owner pointer (RDI)','SI':'actual EngState subobject pointer (RSI)','DX':'load flags for PreLoad/Load; unspecified for Init sites'},'optional_callback_route':optional,'claim':'A sample at this exact before-dispatch instruction proves attempted immediate method dispatch, not callback completion/status or final HAL body.'})
|
|
report={'read_only':True,'source_module':str(M),'cached_runtime_code':str(C/'kcore'),'kallsyms_snapshot':str(K),'sites':rows,'ranges':[{'symbol':n,'runtime_start':hex(lookup[n]),'bytes':symbols[n]['st_size']}for n in ['_nv026844rm','_nv031217rm','_nv031215rm']],'functions_assembly':assembly,'needed_debug_slots':4,'three_site_minimum':['InitLocked','PreLoad','Load'],'three_site_omission':'InitUnlocked is conditionally executed before InitLocked andmustnotbeclaimedcoveredbythree-sitecapture.','interpretation':['Capture actualAX/DI/SI/DX with exactinstruction-address identities, timestamp,TID,CPU andsampleloss counters.','Resolve AX againstmatchingloadedmodule symbols; it maynameanEngState wrapper, notfinalselectedengineHALbody.','GPU/engine identities areactualpointervaluesforassociation, notcopy/dereferencecapabilities.','Successfulsamplingorder isdispatchattemptorder only. Returnstatus/bodycompletionisnotrecorded.','Function-only PT ranges maymisscallee reachedthrough outsidefilter kernelretpolinethunk.'],'tracing_changed':False};(R/'reports/gpu-engine-dispatch-sites.json').write_text(json.dumps(report,indent=2)+'\n');print(json.dumps(rows,indent=2))
|