code wiki / _hdl_build / _gpu_dxg_r4d_probe.nx
_gpu_dxg_r4d_probe.nx source
↩ module page · 87 lines · 5910 B
1// _gpu_dxg_r4d_probe.nx -- SOVEREIGN-GPU ladder R4d PROBE pass 1: locate alloc_count in d3dkmt_createallocation.
2//
3// LX_DXCREATEALLOCATION = 0xC0484706 (nr=0x06, size 72, recon-pinned). Its 72-byte struct carries pointer
4// fields (allocation_info array + private_runtime_data) that can't be size-swept; first we must find the
5// u32 `alloc_count` the kernel validates FIRST. Method: with device@0 fixed and all else zero (baseline ret
6// = -EINVAL), set each candidate u32 offset to (a) 1 and (b) a HUGE value 0x40000000, and watch where the
7// return code DIVERGES from baseline -- a huge count makes the kernel's allocation-array sizing fail
8// distinctly (e.g. -ENOMEM/-12 or -E2BIG/-7), pinpointing alloc_count. raw syscalls only. No log writes.
9// license_tier: ORIGINAL
10import "nx_syscalls.nx"
11
12const ENUM2_CODE: i64 = 0xC0104714
13const QAI_CODE: i64 = 0xC0184709
14const OAFL_CODE: i64 = 0xC00C4701
15const CDEV_CODE: i64 = 0xC0404702
16const CALLOC_CODE: i64 = 0xC0484706 // LX_DXCREATEALLOCATION (size 72)
17
18func p(s: *u8) -> i64 { var nn: i64=0; while s[nn]!=(0 as u8){nn=nn+1} sys_write(1,s,nn); return 0 }
19func n(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 }
20func x(v: i64) -> i64 { p("0x" as *u8); let bb:*u8=sys_mmap(20); var k:i64=0; var m:i64=v; if m==0{bb[0]=48;k=1}; while m>0{ let d:i64=m&15; if d<10{bb[k]=(48+d) as u8}else{bb[k]=(87+d) as u8}; m=(m>>4); k=k+1 } var i:i64=0; let o:*u8=sys_mmap(20); while i<k{o[i]=bb[k-1-i];i=i+1} sys_write(1,o,k); return 0 }
21func rd32(buf: *u8, off: i64) -> i64 { return (buf[off] as i64)|((buf[off+1] as i64)<<8)|((buf[off+2] as i64)<<16)|((buf[off+3] as i64)<<24) }
22
23func query_type(fd: i64, handle: i64, qtype: i64, psize: i64, outv: *i64) -> i64 {
24 let priv: *u8 = sys_mmap(64); var zz: i64 = 0; while zz < 64 { priv[zz] = 0 as u8; zz = zz + 1 }
25 let req: *u8 = sys_mmap(64); var y: i64 = 0; while y < 64 { req[y] = 0 as u8; y = y + 1 }
26 let h: *i64 = (req as i64 + 0) as *i64; h[0] = (handle & 0xffffffff) | ((qtype & 0xffffffff) << 32)
27 let pd: *i64 = (req as i64 + 8) as *i64; pd[0] = priv as i64
28 let pds: *i64 = (req as i64 + 16) as *i64; pds[0] = psize & 0xffffffff
29 let ret: i64 = sys_ioctl(fd, QAI_CODE, req as i64); outv[0] = rd32(priv, 0); return ret
30}
31func open_from_luid(fd: i64, luid_lo: i64, luid_hi: i64, outh: *i64) -> i64 {
32 let req: *u8 = sys_mmap(64); var y: i64 = 0; while y < 64 { req[y] = 0 as u8; y = y + 1 }
33 let lo: *i64 = (req as i64 + 0) as *i64; lo[0] = (luid_lo & 0xffffffff) | ((luid_hi & 0xffffffff) << 32)
34 let ret: i64 = sys_ioctl(fd, OAFL_CODE, req as i64); outh[0] = rd32(req, 8); return ret
35}
36func create_device(fd: i64, adapter: i64, outd: *i64) -> i64 {
37 let buf: *u8 = sys_mmap(512); var bz: i64 = 0; while bz < 512 { buf[bz] = 0 as u8; bz = bz + 1 }
38 let a0: *i64 = (buf as i64) as *i64; a0[0] = adapter & 0xffffffff
39 let ret: i64 = sys_ioctl(fd, CDEV_CODE, buf as i64); outd[0] = rd32(buf, 12); return ret
40}
41// fire CREATEALLOCATION with device@0 and u32@off = val (everything else zero). returns ioctl ret.
42func fire(fd: i64, device: i64, off: i64, val: i64) -> i64 {
43 let buf: *u8 = sys_mmap(512); var bz: i64 = 0; while bz < 512 { buf[bz] = 0 as u8; bz = bz + 1 }
44 let d0: *i64 = (buf as i64) as *i64; d0[0] = device & 0xffffffff
45 if off > 0 { let pp: *i64 = (buf as i64 + off) as *i64; pp[0] = val & 0xffffffff }
46 return sys_ioctl(fd, CALLOC_CODE, buf as i64)
47}
48
49func main() -> i64 {
50 p("=== R4d PROBE-1: locate alloc_count in LX_DXCREATEALLOCATION (72B) ===\n" as *u8)
51 let fd: i64 = sys_openat_rd("/dev/dxg" as *u8)
52 if fd < 0 { p("open(/dev/dxg) failed\n" as *u8); sys_exit(1); return 1 }
53 let ainfo: *u8 = sys_mmap(4096); var z: i64 = 0; while z < 4096 { ainfo[z] = 0 as u8; z = z + 1 }
54 let ereq: *u8 = sys_mmap(64); ereq[0] = 8 as u8; let r8: *i64 = (ereq as i64 + 8) as *i64; r8[0] = ainfo as i64
55 sys_ioctl(fd, ENUM2_CODE, ereq as i64); let nc: i64 = rd32(ereq, 0)
56 let v: *i64 = sys_mmap(16); var disc_lo: i64 = 0; var disc_hi: i64 = 0
57 var ai: i64 = 0
58 while ai < nc {
59 let base: i64 = ai * 20; let eh: i64 = rd32(ainfo, base)
60 let qret: i64 = query_type(fd, eh, 15, 4, v); let t: i64 = v[0]
61 if qret == 0 { if ((t>>4)&1) == 1 { if ((t>>2)&1) == 0 { disc_lo = rd32(ainfo, base+4); disc_hi = rd32(ainfo, base+8) } } }
62 ai = ai + 1
63 }
64 let ah: *i64 = sys_mmap(16); open_from_luid(fd, disc_lo, disc_hi, ah)
65 let dh: *i64 = sys_mmap(16); let dr: i64 = create_device(fd, ah[0], dh); let device: i64 = dh[0]
66 p(" device=" as *u8); x(device); p(" create ret=" as *u8); n(dr); p("\n" as *u8)
67
68 let baseline: i64 = fire(fd, device, 0, 0)
69 p(" baseline (all-zero, device@0) ret=" as *u8); n(baseline); p("\n\n" as *u8)
70 p(" offset : ret(val=1) : ret(val=0x40000000) <- divergence from baseline pinpoints alloc_count\n" as *u8)
71 let offs: *i64 = sys_mmap(256)
72 offs[0]=4; offs[1]=8; offs[2]=12; offs[3]=16; offs[4]=20; offs[5]=24; offs[6]=28; offs[7]=32; offs[8]=36; offs[9]=40; offs[10]=44; offs[11]=48; offs[12]=52; offs[13]=56; offs[14]=60; offs[15]=64; offs[16]=68; offs[17]=0
73 var oi: i64 = 0
74 while offs[oi] != 0 {
75 let o: i64 = offs[oi]
76 let r_one: i64 = fire(fd, device, o, 1)
77 let r_big: i64 = fire(fd, device, o, 0x40000000)
78 p(" @" as *u8); n(o); p(" : " as *u8); n(r_one); p(" : " as *u8); n(r_big)
79 if r_big != baseline { p(" <== DIVERGES (candidate alloc_count)" as *u8) }
80 else { if r_one != baseline { p(" <- val=1 diverges" as *u8) } }
81 p("\n" as *u8)
82 oi = oi + 1
83 }
84 sys_close(fd)
85 p("=== R4d PROBE-1 DONE ===\n" as *u8)
86 return 0
87}