Skip to content

Runtime: fix ANSI CP_ACP path encoding, HLE alias stubs/handles, forwarders, and stub creation race - #101

Merged
ivall merged 1 commit into
xcl-dev:mainfrom
raylitebull:fix/resolver-aliases-and-ansi-paths
Nov 23, 2026
Merged

ivall merged 1 commit into
xcl-dev:mainfrom
raylitebull:fix/resolver-aliases-and-ansi-paths

Conversation

@raylitebull

Copy link
Copy Markdown
Member

Summary

Fixes ANSI path codepage encoding, HLE alias stub return codes, GetModuleHandle parity for console-only aliases, ordinal/forwarder resolution, and a make_stub_info TOCTOU race in crates/xcl/src/{util.rs, resolver.rs, stubs.rs, modules.rs, hle/kernelx.rs}:

  1. write_ansi_out CP_ACP encoding (util.rs):

    • Confirmed CP_ACP matches util::from_ansi_ptr, vfs_hooks::w_to_a, and Windows GetModuleFileNameA.
    • Replaced raw UTF-8 copy with WideCharToMultiByte(CP_ACP, ...) and character-boundary-safe truncation (binary-searching complete Unicode scalar-value UTF-16 prefixes so DBCS/UTF-8 multi-byte sequences and surrogate pairs are never split, setting ERROR_INSUFFICIENT_BUFFER on truncation).
    • Tested on Windows (GetACP() == 1252):
      • C:\Jeux\Été\game.exe (CP1252) and C:\Hry\Český_Život\game.exe (CP1250) round-trip cleanly via from_ansi_ptr.
      • C:\Games\漢\game.exe (CJK outside CP1250/CP1252) substitutes '?' (C:\Games\?\game.exe, NUL-terminated, matching Windows GetModuleFileNameA) and round-trips on codepages representing '漢'.
  2. HLE alias stub return fallback (stubs.rs, resolver.rs):

    • Added StubDb::return_for_with_fallback(dll, fallback_dll, name) so routed HLE alias DLLs (xgameplatform.dll, xgameruntime.thunks.dll, d3d12x.dll, etc.) inherit their canonical module's stubdb.toml default (E_NOTIMPL) instead of silently returning 0 (S_OK), while BOOL/handle families (kernelx.dll) keep 0, per-alias overrides still win, and every stub call continues to be recorded in report.json.
  3. GetModuleHandleW/A/Ex parity for console-only aliases & loaded @stub DLLs (hle/kernelx.rs, modules.rs, resolver.rs):

    • For aliases_are_system() aliases, tries Windows GetModuleHandleW first (preserving real handles for kernel32.dll, etc.) and falls back to modules::hle_handle(m.name) when Windows returns 0 (advapi32legacy.dll, kernel32legacy.dll, minappmodelx.dll).
    • For Route::Stub, returns modules::find_hle_handle(&key).unwrap_or(0) so unloaded optional probes still return 0 while loaded @stub DLLs match LoadLibrary.
  4. Ordinal fallback & GetProcAddress forwarder contract (resolver.rs):

    • Unmapped ordinal imports in resolve_hle fall through to system_proc only when c == key (preventing cross-DLL ordinal mismatches on console-only aliases).
    • Threaded allow_stub through resolve_export_of_mapped so get_proc_address returns None instead of synthesizing stubs on unresolvable forwarders, and switched forwarder splitting to rsplit_once('.') to support dotted DLL names.
  5. stubs::make_stub_info TOCTOU race (stubs.rs):

    • Held BY_KEY across lookup, thunk allocation, ALL push, and map insert (strict lock order BY_KEY -> leaf ARENA/ALL), eliminating duplicate thunks and duplicate ALL entries under concurrency.

Testing

  • Added 7 targeted regression & stress tests:
    • ansi_out_encodes_codepage_and_truncates_on_char_boundaries (CP1252, CP1250 "Č"/"Ž", CJK '漢', CP932 DBCS, UTF-8 surrogate pair)
    • make_stub_info_is_race_free_under_concurrency (8 threads × 50 iterations stress test)
    • hle_alias_stubs_inherit_canonical_module_default
    • ordinal_imports_fall_through_only_to_matching_system_dll
    • mapped_forwarders_preserve_get_proc_address_contract_and_dotted_dll_names
    • get_module_handle_matches_load_library_for_console_aliases_and_stubs
    • builtin_db_parses_with_overrides
  • Verified after rebasing onto origin/main (60599a9): cargo build --workspace and cargo test --workspace -- --test-threads=4 pass with 0 failures and 0 new warnings.

@ivall
ivall merged commit fe63082 into xcl-dev:main Nov 23, 2026
@ivall

ivall commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Merged together with #95–#102 and checked on Windows 11 with an RX 9070: cargo test --workspace green with the retail samples (shader pack, console DLLs, texture archive), lib tests also with XCL_SPLIT_WAVE64=1; XDefiant (title screen, a scripted A reaches its "Xbox network unavailable" dialog), Unicorn Overlord and Minecraft run. Thanks!

Ahmet-Dedeler added a commit to Ahmet-Dedeler/xcl that referenced this pull request Nov 23, 2026
- kernelx: XMemIsToolsMemAvailable (TRUE; the title stops at an int3 on FALSE);
  XMemMapPhysicalPagesScatter without a page array unmaps the addresses.
- xgameruntime: 128 vtable slots per object (later GDKs call past 96), the XDisplay HDR
  class (XDisplayTryEnableHdrMode: Disabled).
- d3d12x: device xcl-dev#101 CreateStateObject from console code fails cleanly (E_NOTIMPL) instead
  of S_OK with no object.

Dropped as upstream has its own: XG xcl-dev#10 GetResourceTiling, illegal-instruction bytes in the
crash line.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
Ahmet-Dedeler added a commit to Ahmet-Dedeler/xcl that referenced this pull request Nov 24, 2026
- kernelx: XMemIsToolsMemAvailable (TRUE; the title stops at an int3 on FALSE);
  XMemMapPhysicalPagesScatter without a page array unmaps the addresses.
- xgameruntime: 128 vtable slots per object (later GDKs call past 96), the XDisplay HDR
  class (XDisplayTryEnableHdrMode: Disabled).
- d3d12x: device xcl-dev#101 CreateStateObject from console code fails cleanly (E_NOTIMPL) instead
  of S_OK with no object.

Dropped as upstream has its own: XG xcl-dev#10 GetResourceTiling, illegal-instruction bytes in the
crash line.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
burber added a commit to burber/xcl that referenced this pull request Nov 24, 2026
…t pipeline waits; what list xcl-dev#101 takes

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kole07139 pushed a commit to kole07139/xcl that referenced this pull request Nov 25, 2026
The three lines of the first commit read "none / none / 0" in runs where
the title had stopped after its first xcl-dev#101: no fence and no queue was
behind, yet nothing was presented. What showed the stop was a SYNC_GRAPH
cell whose recorded value is above what was submitted and completed,
with no GPU wait armed: a list that writes the value was recorded and
never submitted, so the submitting thread is held (GreemSC's runs, RX
7900 XT; the thread dump then named that thread).

cells_behind_summary lists such cells, and those with armed waits:
memory, completed, submitted (and on which queue), recorded and CPU
values, and the armed waits with their age. It takes the graph with
try_lock, since a dump can come while a submitting thread holds it.
The function is GreemSC's, from the review of this PR.

Co-authored-by: GreemSC <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XZrhsCAiLU1tTuEBwPLaRW
kole07139 pushed a commit to kole07139/xcl that referenced this pull request Nov 25, 2026
The three lines of the first commit read "none / none / 0" in runs where
the title had stopped after its first xcl-dev#101: no fence and no queue was
behind, yet nothing was presented. What showed the stop was a SYNC_GRAPH
cell whose recorded value is above what was submitted and completed,
with no GPU wait armed: a list that writes the value was recorded and
never submitted, so the submitting thread is held (GreemSC's runs, RX
7900 XT; the thread dump then named that thread).

cells_behind_summary lists such cells, and those with armed waits:
memory, completed, submitted (and on which queue), recorded and CPU
values, and the armed waits with their age. It takes the graph with
try_lock, since a dump can come while a submitting thread holds it.
The cell is read with ReadProcessMemory (dstorage::read_own), since
the title can decommit its page at any time; an unreadable cell shows
"mem unreadable" (bmjask's review).
The function is GreemSC's, from the review of this PR.

Co-authored-by: GreemSC <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XZrhsCAiLU1tTuEBwPLaRW
bmjask referenced this pull request in bmjask/xcl Nov 26, 2026
The three lines of the first commit read "none / none / 0" in runs where
the title had stopped after its first #101: no fence and no queue was
behind, yet nothing was presented. What showed the stop was a SYNC_GRAPH
cell whose recorded value is above what was submitted and completed,
with no GPU wait armed: a list that writes the value was recorded and
never submitted, so the submitting thread is held (GreemSC's runs, RX
7900 XT; the thread dump then named that thread).

cells_behind_summary lists such cells, and those with armed waits:
memory, completed, submitted (and on which queue), recorded and CPU
values, and the armed waits with their age. It takes the graph with
try_lock, since a dump can come while a submitting thread holds it.
The cell is read with ReadProcessMemory (dstorage::read_own), since
the title can decommit its page at any time; an unreadable cell shows
"mem unreadable" (bmjask's review).
The function is GreemSC's, from the review of this PR.

Co-authored-by: GreemSC <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XZrhsCAiLU1tTuEBwPLaRW
bmjask referenced this pull request in bmjask/xcl Nov 26, 2026
The three lines of the first commit read "none / none / 0" in runs where
the title had stopped after its first #101: no fence and no queue was
behind, yet nothing was presented. What showed the stop was a SYNC_GRAPH
cell whose recorded value is above what was submitted and completed,
with no GPU wait armed: a list that writes the value was recorded and
never submitted, so the submitting thread is held (GreemSC's runs, RX
7900 XT; the thread dump then named that thread).

cells_behind_summary lists such cells, and those with armed waits:
memory, completed, submitted (and on which queue), recorded and CPU
values, and the armed waits with their age. It takes the graph with
try_lock, since a dump can come while a submitting thread holds it.
The cell is read with ReadProcessMemory (dstorage::read_own), since
the title can decommit its page at any time; an unreadable cell shows
"mem unreadable" (bmjask's review).
The function is GreemSC's, from the review of this PR.

Co-authored-by: GreemSC <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XZrhsCAiLU1tTuEBwPLaRW
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants