code wiki / _hdl_build / _gpu_dxg_r4d_probe4.nx
_gpu_dxg_r4d_probe4.nx source
↩ module page · 103 lines · 7194 B
1// _gpu_dxg_r4d_probe4.nx -- SOVEREIGN-GPU ladder R4d PROBE pass 4: find the StandardAllocation flag bit
2// and attempt a UMD-less EXISTINGHEAP standard allocation on the 5080.
3//
4// Mapped so far (probes 1-3): global d3dkmt_createallocation (72B) device@0, alloc_count@44, allocation_info@48;
5// entry d3dkmt_allocationinfo2 allocation@0(OUT), sysmem@16, priv_drv_data@24. The struct mirrors Windows
6// D3DKMT_CREATEALLOCATION, predicting global flags@12, private_runtime_data@16, priv_drv_data@32(=pStandardAllocation
7// when StandardAllocation flag set), priv_drv_data_size@40. EXISTINGHEAP standard alloc = no vendor UMD blob:
8// desc D3DKMT_CREATESTANDARDALLOCATION { Type@0 = EXISTINGHEAP(1); Size@8 = bytes }, sysmem in the entry.
9// Method: hold the EXISTINGHEAP descriptor + page-aligned sysmem fixed, sweep flags@12 over bits 0..23, print
10// ret per bit. The bit that takes the host off the -75 EOVERFLOW path = StandardAllocation. If any fire returns
11// 0, dump the entry's OUT allocation handle. raw syscalls only. No log writes. license_tier: ORIGINAL
12import "nx_syscalls.nx"
13
14const ENUM2_CODE: i64 = 0xC0104714
15const QAI_CODE: i64 = 0xC0184709
16const OAFL_CODE: i64 = 0xC00C4701
17const CDEV_CODE: i64 = 0xC0404702
18const CALLOC_CODE: i64 = 0xC0484706
19
20func p(s: *u8) -> i64 { var nn: i64=0; while s[nn]!=(0 as u8){nn=nn+1} sys_write(1,s,nn); return 0 }
21func 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 }
22func 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 }
23func 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) }
24
25func query_type(fd: i64, handle: i64, qtype: i64, psize: i64, outv: *i64) -> i64 {
26 let priv: *u8 = sys_mmap(64); var zz: i64 = 0; while zz < 64 { priv[zz] = 0 as u8; zz = zz + 1 }
27 let req: *u8 = sys_mmap(64); var y: i64 = 0; while y < 64 { req[y] = 0 as u8; y = y + 1 }
28 let h: *i64 = (req as i64 + 0) as *i64; h[0] = (handle & 0xffffffff) | ((qtype & 0xffffffff) << 32)
29 let pd: *i64 = (req as i64 + 8) as *i64; pd[0] = priv as i64
30 let pds: *i64 = (req as i64 + 16) as *i64; pds[0] = psize & 0xffffffff
31 let ret: i64 = sys_ioctl(fd, QAI_CODE, req as i64); outv[0] = rd32(priv, 0); return ret
32}
33func open_from_luid(fd: i64, luid_lo: i64, luid_hi: i64, outh: *i64) -> i64 {
34 let req: *u8 = sys_mmap(64); var y: i64 = 0; while y < 64 { req[y] = 0 as u8; y = y + 1 }
35 let lo: *i64 = (req as i64 + 0) as *i64; lo[0] = (luid_lo & 0xffffffff) | ((luid_hi & 0xffffffff) << 32)
36 let ret: i64 = sys_ioctl(fd, OAFL_CODE, req as i64); outh[0] = rd32(req, 8); return ret
37}
38func create_device(fd: i64, adapter: i64, outd: *i64) -> i64 {
39 let buf: *u8 = sys_mmap(512); var bz: i64 = 0; while bz < 512 { buf[bz] = 0 as u8; bz = bz + 1 }
40 let a0: *i64 = (buf as i64) as *i64; a0[0] = adapter & 0xffffffff
41 let ret: i64 = sys_ioctl(fd, CDEV_CODE, buf as i64); outd[0] = rd32(buf, 12); return ret
42}
43func setu32(buf: *u8, off: i64, val: i64) -> i64 { let w: *u8 = (buf as i64 + off) as *u8; w[0]=(val&0xff) as u8; w[1]=((val>>8)&0xff) as u8; w[2]=((val>>16)&0xff) as u8; w[3]=((val>>24)&0xff) as u8; return 0 }
44func setu64(buf: *u8, off: i64, val: i64) -> i64 { let q: *i64 = (buf as i64 + off) as *i64; q[0]=val; return 0 }
45
46// fire an EXISTINGHEAP standard-allocation attempt with global flags=flagval; return ret, OUT alloc handle -> outh[0].
47func fire_std(fd: i64, device: i64, flagval: i64, desc: *u8, descsz: i64, sysmem: *u8, entry: *u8, outh: *i64) -> i64 {
48 var ez: i64 = 0; while ez < 128 { entry[ez] = 0 as u8; ez = ez + 1 }
49 setu64(entry, 16, sysmem as i64) // entry.sysmem @16
50 let buf: *u8 = sys_mmap(512); var bz: i64 = 0; while bz < 512 { buf[bz] = 0 as u8; bz = bz + 1 }
51 setu32(buf, 0, device & 0xffffffff) // device @0
52 setu32(buf, 12, flagval) // flags @12
53 setu64(buf, 32, desc as i64) // priv_drv_data @32 = pStandardAllocation
54 setu32(buf, 40, descsz) // priv_drv_data_size @40
55 setu32(buf, 44, 1) // alloc_count @44 = 1
56 setu64(buf, 48, entry as i64) // allocation_info @48
57 let ret: i64 = sys_ioctl(fd, CALLOC_CODE, buf as i64)
58 outh[0] = rd32(entry, 0) // entry.allocation @0 (OUT)
59 return ret
60}
61
62func main() -> i64 {
63 p("=== R4d PROBE-4: StandardAllocation flag-bit sweep + EXISTINGHEAP attempt ===\n" as *u8)
64 let fd: i64 = sys_openat_rd("/dev/dxg" as *u8)
65 if fd < 0 { p("open(/dev/dxg) failed\n" as *u8); sys_exit(1); return 1 }
66 let ainfo: *u8 = sys_mmap(4096); var z: i64 = 0; while z < 4096 { ainfo[z] = 0 as u8; z = z + 1 }
67 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
68 sys_ioctl(fd, ENUM2_CODE, ereq as i64); let nc: i64 = rd32(ereq, 0)
69 let v: *i64 = sys_mmap(16); var disc_lo: i64 = 0; var disc_hi: i64 = 0
70 var ai: i64 = 0
71 while ai < nc {
72 let base: i64 = ai * 20; let eh: i64 = rd32(ainfo, base)
73 let qret: i64 = query_type(fd, eh, 15, 4, v); let t: i64 = v[0]
74 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) } } }
75 ai = ai + 1
76 }
77 let ah: *i64 = sys_mmap(16); open_from_luid(fd, disc_lo, disc_hi, ah)
78 let dh: *i64 = sys_mmap(16); create_device(fd, ah[0], dh); let device: i64 = dh[0]
79
80 // EXISTINGHEAP descriptor + page-aligned sysmem (4096).
81 let desc: *u8 = sys_mmap(64); var dz: i64 = 0; while dz < 64 { desc[dz] = 0 as u8; dz = dz + 1 }
82 setu32(desc, 0, 1) // Type = EXISTINGHEAP(1)
83 setu64(desc, 8, 4096) // ExistingHeapData.Size = 4096
84 let sysmem: *u8 = sys_mmap(4096); var sz: i64 = 0; while sz < 4096 { sysmem[sz] = 0 as u8; sz = sz + 1 }
85 let entry: *u8 = sys_mmap(256)
86 let oh: *i64 = sys_mmap(16)
87
88 let r0: i64 = fire_std(fd, device, 0, desc, 16, sysmem, entry, oh)
89 p(" flags=0 baseline ret=" as *u8); n(r0); p("\n bit : flags : ret : OUT_alloc_handle\n" as *u8)
90 var bit: i64 = 0
91 while bit < 24 {
92 let fv: i64 = 1 << bit
93 let r: i64 = fire_std(fd, device, fv, desc, 16, sysmem, entry, oh)
94 p(" " as *u8); n(bit); p(" : " as *u8); x(fv); p(" : ret=" as *u8); n(r); p(" : alloc=" as *u8); x(oh[0])
95 if r == 0 { p(" <== SUCCESS!!" as *u8) }
96 else { if r != 0 - 75 { p(" <- off the -75 path" as *u8) } }
97 p("\n" as *u8)
98 bit = bit + 1
99 }
100 sys_close(fd)
101 p("=== R4d PROBE-4 DONE ===\n" as *u8)
102 return 0
103}