kernelx: implement GetModuleFileNameEx and GetModuleBaseName for mapped images #1174

Open
Ivankiosan wants to merge 1 commit from upstream-pr/1183 into main
Ivankiosan commented 2026-11-24 12:56:21 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Ivankiosan on 2026-11-24T12:56:21Z.


Implements GetModuleFileNameExW, GetModuleFileNameExA, K32GetModuleFileNameExW, K32GetModuleFileNameExA, GetModuleBaseNameW, GetModuleBaseNameA, K32GetModuleBaseNameW, and K32GetModuleBaseNameA in kernelx so titles, crash reporters, profilers, and diagnostics querying XCL-mapped executables and DLLs get their real file paths and base names rather than failing with ERROR_INVALID_HANDLE from Windows' native PEB module list.

What is in it

  • Implements GetModuleFileNameExW, GetModuleFileNameExA, K32GetModuleFileNameExW, K32GetModuleFileNameExA, GetModuleBaseNameW, GetModuleBaseNameA, K32GetModuleBaseNameW, and K32GetModuleBaseNameA in crates/xcl/src/hle/kernelx.rs for XCL's manually-mapped images (the title executable and console/runtime DLLs).
  • Routes psapi.dll through kernelx with fallback to native psapi.dll in crates/xcl/src/hle/mod.rs.
  • When called on the current process (process == GetCurrentProcess() or GetProcessId(process) == GetCurrentProcessId()):
    • Resolves hModule == 0 (or m.base) to the title executable or mapped image path/basename instead of failing under Windows' native PEB loader list.
    • Rejects null destination buffer or zero capacity with ERROR_INVALID_PARAMETER and returns 0.
    • Forwards native modules (such as kernel32.dll or ntdll.dll) and cross-process queries to the native psapi/kernel32 APIs.
  • Adds comprehensive unit test hle::kernelx::tests::get_module_file_name_ex_and_base_name_answer_for_mapped_images covering wide and ANSI variants, current process pseudo-handle and real OpenProcess handle, null/zero-capacity validation, and native module fallback.

Tested

  • Hardware/OS: AMD Radeon RX 7600 (driver 32.0.12028.1005), Windows 11, rustc 1.99.1 (58cf8f9c3 2026-10-13) / MSVC 14.51.
  • cargo test --workspace -- --test-threads=4: all 699 unit tests passed, all integration tests passed, 0 failures across the workspace.
  • Unit test: cargo test -p xcl --lib get_module_file_name_ex_and_base_name_answer_for_mapped_images: 1 passed, 0 failed.
  • Built release binary target/release/xcl.exe (cargo build --release -p xcl).

Regression run

main:
text xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: AMD Radeon RX 7600 title: 419239bf seconds: 10 exit: 0x0 frames shown: 26 (PresentX 26) presents per 2 s (last 3): 0 0 23 device removals: 0 crashes: 0 peak commit: 8172 MB

PR head:
text xcl-smoke v1 commit: a72a430471aecaae37bdb710d08986f701756d78 gpu: AMD Radeon RX 7600 title: 419239bf seconds: 10 exit: 0x0 frames shown: 26 (PresentX 26) presents per 2 s (last 3): 0 0 23 device removals: 0 crashes: 0 peak commit: 8366 MB

Not tested

  • Cross-process module inspection from an external process querying XCL.
  • Linux / Wine / Proton environment (smoke run and unit tests executed on native Windows 11).

AI use

  • Google Antigravity (Gemini): audited module resolution in kernelx.rs and mod.rs, implemented the GetModuleFileNameEx and GetModuleBaseName functions and unit tests, verified workspace tests and executed the local GPU smoke regression.
<!-- greyfinch-sync:ivall/xcl:issue:5472564831 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1183). Originally posted by [Ivankiosan](https://github.com/Ivankiosan) on 2026-11-24T12:56:21Z. --- Implements `GetModuleFileNameExW`, `GetModuleFileNameExA`, `K32GetModuleFileNameExW`, `K32GetModuleFileNameExA`, `GetModuleBaseNameW`, `GetModuleBaseNameA`, `K32GetModuleBaseNameW`, and `K32GetModuleBaseNameA` in `kernelx` so titles, crash reporters, profilers, and diagnostics querying XCL-mapped executables and DLLs get their real file paths and base names rather than failing with `ERROR_INVALID_HANDLE` from Windows' native PEB module list. **What is in it** - Implements `GetModuleFileNameExW`, `GetModuleFileNameExA`, `K32GetModuleFileNameExW`, `K32GetModuleFileNameExA`, `GetModuleBaseNameW`, `GetModuleBaseNameA`, `K32GetModuleBaseNameW`, and `K32GetModuleBaseNameA` in `crates/xcl/src/hle/kernelx.rs` for XCL's manually-mapped images (the title executable and console/runtime DLLs). - Routes `psapi.dll` through `kernelx` with fallback to native `psapi.dll` in `crates/xcl/src/hle/mod.rs`. - When called on the current process (`process == GetCurrentProcess()` or `GetProcessId(process) == GetCurrentProcessId()`): - Resolves `hModule == 0` (or `m.base`) to the title executable or mapped image path/basename instead of failing under Windows' native PEB loader list. - Rejects null destination buffer or zero capacity with `ERROR_INVALID_PARAMETER` and returns `0`. - Forwards native modules (such as `kernel32.dll` or `ntdll.dll`) and cross-process queries to the native `psapi`/`kernel32` APIs. - Adds comprehensive unit test `hle::kernelx::tests::get_module_file_name_ex_and_base_name_answer_for_mapped_images` covering wide and ANSI variants, current process pseudo-handle and real OpenProcess handle, null/zero-capacity validation, and native module fallback. **Tested** - Hardware/OS: AMD Radeon RX 7600 (driver 32.0.12028.1005), Windows 11, `rustc 1.99.1 (58cf8f9c3 2026-10-13)` / MSVC 14.51. - `cargo test --workspace -- --test-threads=4`: all 699 unit tests passed, all integration tests passed, 0 failures across the workspace. - Unit test: `cargo test -p xcl --lib get_module_file_name_ex_and_base_name_answer_for_mapped_images`: 1 passed, 0 failed. - Built release binary `target/release/xcl.exe` (`cargo build --release -p xcl`). **Regression run** main: ``text xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: AMD Radeon RX 7600 title: 419239bf seconds: 10 exit: 0x0 frames shown: 26 (PresentX 26) presents per 2 s (last 3): 0 0 23 device removals: 0 crashes: 0 peak commit: 8172 MB `` PR head: ``text xcl-smoke v1 commit: a72a430471aecaae37bdb710d08986f701756d78 gpu: AMD Radeon RX 7600 title: 419239bf seconds: 10 exit: 0x0 frames shown: 26 (PresentX 26) presents per 2 s (last 3): 0 0 23 device removals: 0 crashes: 0 peak commit: 8366 MB `` **Not tested** - Cross-process module inspection from an external process querying XCL. - Linux / Wine / Proton environment (smoke run and unit tests executed on native Windows 11). **AI use** - Google Antigravity (Gemini): audited module resolution in `kernelx.rs` and `mod.rs`, implemented the `GetModuleFileNameEx` and `GetModuleBaseName` functions and unit tests, verified workspace tests and executed the local GPU smoke regression.
DavidM1911 commented 2026-11-24 14:06:29 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T13:13:39Z.


Independent verification on current main 384f7f7 (branch already contains it — clean).

Machine: Windows 11, Ryzen 9 7900X; Rust stable MSVC, debug.

  • cargo test -p xcl --lib module_file: 1 passed, 0 failed — get_module_file_name_ex_and_base_name_answer_for_mapped_images covers the new GetModuleFileNameEx/GetModuleBaseName implementation; cargo test -p xcl --lib module: 6 passed overall.

AI use: test runs by Devin (Cognition, SWE-2); no code changes.

<!-- greyfinch-sync:ivall/xcl:comment:7132528282 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1183#issuecomment-7132528282). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T13:13:39Z. --- Independent verification on current `main` `384f7f7` (branch already contains it — clean). **Machine:** Windows 11, Ryzen 9 7900X; Rust stable MSVC, debug. - `cargo test -p xcl --lib module_file`: **1 passed, 0 failed** — `get_module_file_name_ex_and_base_name_answer_for_mapped_images` covers the new GetModuleFileNameEx/GetModuleBaseName implementation; `cargo test -p xcl --lib module`: 6 passed overall. AI use: test runs by Devin (Cognition, SWE-2); no code changes.
JoaoPauluu commented 2026-11-24 15:05:57 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by JoaoPauluu on 2026-11-24T14:34:53Z.


A run on Linux under Wine.

Tested

  • RTX 3060 12 GB (NVIDIA 620.70.06, 32-lane waves), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from #257, DXC 1.9.2609.5. Release, cross-built for x86_64-pc-windows-gnu. a72a430 as it is (based on 47efa2e), no uncommitted changes. The lib test binary runs under Wine, one test per process (--exact). GetModuleFileNameEx / GetModuleBaseName for host modules come from Wine here.
  • hle::kernelx::tests::get_module_file_name_ex_and_base_name_answer_for_mapped_images: ok, no SKIPPED.

Not tested

  • whether the new tests fail without the change on this stack; the rest of the suite on this head; a retail title; native Windows.

AI use

  • Claude Code (Claude Opus 5.5) built the head, ran the tests and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.
<!-- greyfinch-sync:ivall/xcl:comment:7134609404 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1183#issuecomment-7134609404). Originally posted by [JoaoPauluu](https://github.com/JoaoPauluu) on 2026-11-24T14:34:53Z. --- A run on Linux under Wine. **Tested** - RTX 3060 12 GB (NVIDIA 620.70.06, 32-lane waves), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from #257, DXC 1.9.2609.5. Release, cross-built for `x86_64-pc-windows-gnu`. `a72a430` as it is (based on `47efa2e`), no uncommitted changes. The lib test binary runs under Wine, one test per process (`--exact`). `GetModuleFileNameEx` / `GetModuleBaseName` for host modules come from Wine here. - `hle::kernelx::tests::get_module_file_name_ex_and_base_name_answer_for_mapped_images`: **ok**, no SKIPPED. **Not tested** - whether the new tests fail without the change on this stack; the rest of the suite on this head; a retail title; native Windows. **AI use** - Claude Code (Claude Opus 5.5) built the head, ran the tests and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.
github-actions[bot] commented 2026-11-27 21:26:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-27T21:26:40Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7228449012 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1183#issuecomment-7228449012). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-27T21:26:40Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 05:01:32 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:01:32Z.


Triage (#1607) – head a72a430

No open or merged PR adds GetModuleFileNameEx / GetModuleBaseName, and main has neither. Calls for this process answer from XCL's mapped modules; other handles and processes fall through to the system psapi, and adding psapi.dll to kernelx's fallback list keeps the rest of psapi resolving.
No problems found in the diff. The branch conflicts with main.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7301345474 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1183#issuecomment-7301345474). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:01:32Z. --- **Triage (#1607)** – head a72a430 No open or merged PR adds GetModuleFileNameEx / GetModuleBaseName, and main has neither. Calls for this process answer from XCL's mapped modules; other handles and processes fall through to the system psapi, and adding `psapi.dll` to kernelx's fallback list keeps the rest of psapi resolving. No problems found in the diff. The branch conflicts with main. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1183:upstream-pr/1183'
git switch 'upstream-pr/1183'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1183'
git switch 'upstream-pr/1183'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1183'
git switch 'upstream-pr/1183'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1183'
git switch 'main'
git merge --squash 'upstream-pr/1183'
git switch 'main'
git merge --ff-only 'upstream-pr/1183'
git switch 'main'
git merge 'upstream-pr/1183'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1174
No description provided.