code wiki / _hdl_build / _gpu_dxg_r1_recon4.nx
_gpu_dxg_r1_recon4.nx source
↩ module page · 118 lines · 6769 B
1// _gpu_dxg_r1_recon4.nx -- R1 recon pass 4. GROUND TRUTH from WSL2-Linux-Kernel
2// (linux-msft-wsl-6.6.y) uapi d3dkmthk.h: enum kmtqueryadapterinfotype has ONLY
3// _KMTQAITYPE_UMDRIVERPRIVATE=0, _KMTQAITYPE_ADAPTERTYPE=15, _KMTQAITYPE_ADAPTERTYPE_RENDER=57.
4// There is NO ADAPTERREGISTRYINFO and NO adapter_string struct -> the "RTX 5080" DESCRIPTION STRING
5// is NOT retrievable via QueryAdapterInfo on WSL2 dxgkrnl. The task's ABI hint (full Windows header)
6// does not match WSL. dxgkio_query_adapter_info forwards to the host after resolving the handle via
7// dxgprocess_adapter_by_handle (NULL -> -EINVAL).
8//
9// This pass tests the ONLY valid WSL query type for ADAPTER IDENTITY: type=15 ADAPTERTYPE, which
10// returns struct d3dkmt_adaptertype (a 4-byte bitfield union: render_supported/display_supported/
11// software_device/paravirtualized/compute_only/...). That can POSITIVELY distinguish the real
12// RTX 5080 (paravirtualized=1, render_supported=1, software_device=0) from the WSL software render
13// adapter (software_device=1), even though it is NOT the literal name string.
14//
15// We use the OPENED per-process handle (from OpenAdapterFromLuid nr=0x01 size12, pinned in pass 3),
16// type=15, private_data_size=4, and DUMP the returned 4-byte adaptertype value + decode the bits,
17// for BOTH adapters. We also retry on the ENUM handle to confirm which handle dxgprocess_adapter_by_
18// handle accepts. AUTHOR=ORGAN / NO-WAVE / raw syscalls only. license_tier: ORIGINAL
19import "nx_syscalls.nx"
20
21const DXG_LX_DXENUMADAPTERS2: i64 = 0xC0104714
22const QAI_CODE: i64 = 0xC0184709 // QueryAdapterInfo, 24-byte struct
23
24func p(s: *u8) -> i64 { var nn: i64=0; while s[nn]!=(0 as u8){nn=nn+1} sys_write(1,s,nn); return 0 }
25func 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 }
26func 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 }
27
28func query(fd: i64, handle: i64, qtype: i64, priv: *u8, psize: i64) -> i64 {
29 var z: i64 = 0; while z < 64 { priv[z] = 0 as u8; z = z + 1 }
30 let req: *u8 = sys_mmap(64); var y: i64 = 0; while y < 64 { req[y] = 0 as u8; y = y + 1 }
31 let h: *i64 = (req as i64 + 0) as *i64
32 h[0] = (handle & 0xffffffff) | ((qtype & 0xffffffff) << 32)
33 let pd: *i64 = (req as i64 + 8) as *i64; pd[0] = priv as i64
34 let pds: *i64 = (req as i64 + 16) as *i64; pds[0] = psize & 0xffffffff
35 return sys_ioctl(fd, QAI_CODE, req as i64)
36}
37
38func open_from_luid(fd: i64, la: i64, lb: i64, out_h: *i64) -> i64 {
39 let code: i64 = (3<<30) | (12<<16) | (0x47<<8) | 1 // nr=0x01, 12-byte struct (pinned pass3)
40 let req: *u8 = sys_mmap(64); var y: i64 = 0; while y < 64 { req[y] = 0 as u8; y = y + 1 }
41 let lp: *i64 = (req as i64 + 0) as *i64
42 lp[0] = (la & 0xffffffff) | ((lb & 0xffffffff) << 32)
43 let ret: i64 = sys_ioctl(fd, code, req as i64)
44 let hp: *i64 = (req as i64 + 8) as *i64
45 out_h[0] = hp[0] & 0xffffffff
46 return ret
47}
48
49func decode_adaptertype(v: i64) -> i64 {
50 p(" render_supported=" as *u8); n(v & 1)
51 p(" display_supported=" as *u8); n((v>>1) & 1)
52 p(" software_device=" as *u8); n((v>>2) & 1)
53 p(" post_device=" as *u8); n((v>>3) & 1)
54 p(" hybrid_discrete=" as *u8); n((v>>4) & 1)
55 p(" hybrid_integrated=" as *u8); n((v>>5) & 1)
56 p("\n indirect_display=" as *u8); n((v>>6) & 1)
57 p(" paravirtualized=" as *u8); n((v>>7) & 1)
58 p(" acg_supported=" as *u8); n((v>>8) & 1)
59 p(" compute_only=" as *u8); n((v>>11) & 1)
60 p(" prototype=" as *u8); n((v>>12) & 1)
61 p("\n" as *u8)
62 return 0
63}
64
65func try_type(fd: i64, label: *u8, handle: i64, qtype: i64, sz: i64, priv: *u8) -> i64 {
66 let qret: i64 = query(fd, handle, qtype, priv, sz)
67 p(" " as *u8); p(label); p(" handle=" as *u8); x(handle); p(" type=" as *u8); n(qtype); p(" size=" as *u8); n(sz); p(" ret=" as *u8); n(qret)
68 if qret == 0 {
69 let v: i64 = (priv[0] as i64)|((priv[1] as i64)<<8)|((priv[2] as i64)<<16)|((priv[3] as i64)<<24)
70 p(" adaptertype.value=" as *u8); x(v); p("\n" as *u8)
71 decode_adaptertype(v)
72 } else { p("\n" as *u8) }
73 return qret
74}
75
76func main() -> i64 {
77 p("=== R1 RECON pass4: ADAPTERTYPE(15) identity via host query (the ONLY WSL identity path) ===\n" as *u8)
78 let fd: i64 = sys_openat_rd("/dev/dxg" as *u8)
79 if fd < 0 { p("open fail\n" as *u8); sys_exit(1); return 1 }
80
81 let ainfo: *u8 = sys_mmap(4096); var z: i64 = 0; while z < 4096 { ainfo[z] = 0 as u8; z = z + 1 }
82 let ereq: *u8 = sys_mmap(64); var y: i64 = 0; while y < 64 { ereq[y] = 0 as u8; y = y + 1 }
83 ereq[0] = 8 as u8; let r8: *i64 = (ereq as i64 + 8) as *i64; r8[0] = ainfo as i64
84 let eret: i64 = sys_ioctl(fd, DXG_LX_DXENUMADAPTERS2, ereq as i64)
85 let nc: i64 = (ereq[0] as i64)|((ereq[1] as i64)<<8)|((ereq[2] as i64)<<16)|((ereq[3] as i64)<<24)
86 if eret != 0 { p("enum fail\n" as *u8); sys_exit(1); return 1 }
87 p("enum ok num_adapters=" as *u8); n(nc); p("\n" as *u8)
88
89 let priv: *u8 = sys_mmap(4096)
90 let oh_box: *i64 = sys_mmap(16)
91
92 var ai: i64 = 0
93 while ai < nc {
94 let base: i64 = ai * 20
95 let enumh: i64 = (ainfo[base] as i64)|((ainfo[base+1] as i64)<<8)|((ainfo[base+2] as i64)<<16)|((ainfo[base+3] as i64)<<24)
96 let la: i64 = (ainfo[base+4] as i64)|((ainfo[base+5] as i64)<<8)|((ainfo[base+6] as i64)<<16)|((ainfo[base+7] as i64)<<24)
97 let lb: i64 = (ainfo[base+8] as i64)|((ainfo[base+9] as i64)<<8)|((ainfo[base+10] as i64)<<16)|((ainfo[base+11] as i64)<<24)
98 p("\n--- adapter[" as *u8); n(ai); p("] enum_handle=" as *u8); x(enumh); p(" luid.a=" as *u8); x(la); p(" ---\n" as *u8)
99
100 let oret: i64 = open_from_luid(fd, la, lb, oh_box)
101 let opened: i64 = oh_box[0]
102 p(" OpenAdapterFromLuid ret=" as *u8); n(oret); p(" opened_handle=" as *u8); x(opened); p("\n" as *u8)
103
104 p(" [ADAPTERTYPE=15] (identity bitfield):\n" as *u8)
105 try_type(fd, "opened" as *u8, opened, 15, 4, priv)
106 try_type(fd, "enum " as *u8, enumh, 15, 4, priv)
107 p(" [ADAPTERTYPE_RENDER=57]:\n" as *u8)
108 try_type(fd, "opened" as *u8, opened, 57, 4, priv)
109 p(" [UMDRIVERPRIVATE=0 size=8]:\n" as *u8)
110 try_type(fd, "opened" as *u8, opened, 0, 8, priv)
111
112 ai = ai + 1
113 }
114
115 sys_close(fd)
116 p("\n=== R1 RECON pass4 DONE ===\n" as *u8)
117 return 0
118}