Skip to content

Loader: preserve an empty import table for Windows 10 static TLS - #28

Merged
Marvisak merged 4 commits into
Marvisak:mainfrom
ifBars:fix/windows10-import-directory
Nov 24, 2026
Merged

Marvisak merged 4 commits into
Marvisak:mainfrom
ifBars:fix/windows10-import-directory

Conversation

@ifBars

@ifBars ifBars commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Keep a valid empty import table in the DLL VIctory prepares for Windows. Point the import-directory entry at the existing null descriptor and retain the original IAT directory. VIctory binds the slots recorded when it parsed the original image.

The PE parser already walks the descriptors to their null terminator. Using the number of descriptors it read handles linkers whose import-directory size excludes the terminator.

Tested

  • On Windows 10 22H2 (19045.7846), two layouts both allowed all five prepared images to map and bind. Only the empty-descriptor layout gave the executable and two TLS-bearing DLLs a static TLS index. With both directory entries cleared, all three index slots remained at their on-disk zero.
  • A fresh map-only run on the corrected revision reported static TLS redirection and zero missing imports across all five images. All five prepared files were byte-for-byte identical to the initial descriptor-based implementation for the tested Xbox 1.0.2.1 build.
  • All 9 loader and 5 PE library tests passed. Coverage includes a declared size excluding the terminator and a prepared test DLL for which the test reads the OS-assigned TLS index. The staged asset-policy check passed.
  • The optional diagnostics-profile stack-walk unit test previously failed on this host on both stock and patched builds.

AI assistance: Codex prepared the patch and ran the checks above.

@Sunkiller-qc

Copy link
Copy Markdown

Looks good to me, and the fallback when the last 20 bytes aren't a zero descriptor keeps the old behaviour (prepare.rs:116). Question: since the description says the loader goes there because an IAT is still advertised, did you also try clearing the IAT directory (IMAGE_DIRECTORY_ENTRY_IAT, index 12) alongside the import entry? That might avoid relying on the import directory's Size including the terminator, which not every linker guarantees. Static review, not built or run.

Windows 10 maps the prepared image with both entries empty. The binder already retains the original slot RVAs, so preparation need not locate a linker-provided terminator.
@ifBars ifBars changed the title Loader: preserve an empty import table on Windows 10 Loader: clear the IAT directory with imports on Windows 10 Nov 23, 2026
@ifBars

ifBars commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Update: A static TLS check changed the conclusion below. See the corrected results and fix.

@Sunkiller-qc I tested your suggestion on Windows 10 22H2 (19045.7846). The prepared executable and all four DLLs mapped and unloaded with both layouts. VIctory's map-only run with the import and IAT directories cleared also bound all five images with zero missing imports.

I switched to clearing both entries in 4da3d63. The binder uses the slot RVAs saved from the original image. A regression test now covers an import-directory size that excludes the terminator and checks that the original IAT slots survive preparation. All 13 loader and PE library tests passed.

@ifBars

ifBars commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

@Sunkiller-qc, correction to my previous result: mapping and binding succeeded, but my test missed Windows static TLS initialization. I checked the index through the mapped TLS directory on Windows 10 19045.7846, before running any title code. In fresh processes, the executable and both TLS-bearing DLLs each received index 6 with an empty import descriptor. With both directory entries cleared, all three index slots remained at their on-disk zero. The execution test failed during startup with that layout.

25a3e95 restores the empty descriptor and locates it using the parsed descriptor count, so the linker can exclude the terminator from its reported size. All five prepared images match the original working layout byte for byte, and the corrected map-only command reported static TLS redirection and zero missing imports. All 14 loader and PE tests passed, including a Windows test that checks the assigned TLS index on a prepared DLL.

@DaviTostes

Copy link
Copy Markdown

Tested 4da3d63 stacked on #39 on Arch Linux x86_64, rustc 1.98.1: pass (no regression only).

  • cargo test --workspace: 155 passed, 0 failed, 3 ignored; the merge with Build: make workspace tests run on Linux #39 is clean.
  • Scope note: the change is the Windows 10 IAT clear in crates/victory-loader/src/prepare.rs / victory-pe/src/layout.rs; the behaviour itself needs a Windows 10 host, so what runs here is the portable loader/PE suite around it.
  • No game data used.

AI-assisted (DeepSeek V4.1 Flash coding agent).

@ifBars ifBars changed the title Loader: clear the IAT directory with imports on Windows 10 Loader: preserve an empty import table for Windows 10 static TLS Nov 24, 2026
Use the descriptor count already validated by the PE parser, so the directory size need not include the null terminator. Check the OS-assigned static TLS index on a mapped test DLL.
@DaviTostes

Copy link
Copy Markdown

Re-checked the new head 25a3e95 ("Keep an empty import descriptor so Windows assigns static TLS") stacked on #39 on Arch Linux x86_64, rustc 1.98.1: pass (no regression only).

  • cargo test --workspace: 155 passed, 0 failed, 3 ignored; merge with Build: make workspace tests run on Linux #39 clean.
  • The static-TLS assignment is a Windows loader behaviour; the portable loader/PE suite is what runs here.
  • No game data used.

AI-assisted (DeepSeek V4.1 Flash coding agent).

@Proudnoob4

Copy link
Copy Markdown

Tested 25a3e95 on Windows 10 22H2 (19045.6456), i5-13600K, RTX 4080 (driver 621.01), title build b99f876b…, merged onto main 97c78d1. AI-assisted (Claude); I ran all of this myself.

  • Map-only victory run (no --execute): maps and binds with 0 missing imports and logs static TLS redirected index=12 patched=53246. Your earlier d85097a gives the same line.
  • Loader: run on Windows 10 (clear the IAT directory) #44's layout (import and IAT directories cleared), same exe, same run: no static TLS redirected line, so Windows 10 left the index at 0. That matches your correction.
  • --execute, with a local Agility SDK export (Windows 10: the host device stops at shader model 6.5 (needs the D3D12 Agility SDK) #84; without it the host device stops at SM 6.5 on Windows 10):
    • 25a3e95 ran the first-boot screens for 70 s with no errors.
    • With d85097a and keys pressed, the title went through the account prompt, intro, legal notices and start screen to the story loading screens at about 30 fps.
    • Entering the world then caused a TDR (slow host submission ms=11341 lists=33, then device removed). That looks like the known world GPU hang, not the loader.
  • cargo test --workspace on main + 25a3e95: 225 pass, including load_probe. net::only_loopback_is_reachable fails on Windows 10 because WinHttpGetProxySettingsEx is Windows 11 only; Loader: run on Windows 10 (clear the IAT directory) #44 skips it in that test.

@DaviTostes

Copy link
Copy Markdown

Re-checked the new head 0e5953d (merge of main into the branch) stacked on #39 on Arch Linux x86_64, rustc 1.98.1: pass (no regression only).

  • cargo test --workspace: 155 passed, 0 failed, 3 ignored; merge with Build: make workspace tests run on Linux #39 clean.
  • The IAT clear itself is Windows 10 behaviour; the portable loader/PE suite is what runs here.
  • No game data used.

AI-assisted (DeepSeek V4.1 Flash coding agent).

@erLCoder

Copy link
Copy Markdown

Additional Windows 10 execution data for the merged change, included in main d2a4bae (not tested in isolation): Windows 10 Enterprise 22H2, Ryzen 5 3600, GTX 1660 Ti, Agility SDK 1.620.2. The prepared title executable had an empty import descriptor and retained its IAT directory. The executable and four DLLs mapped and bound with zero missing imports, and the title reached the prologue in two runs. The build also had diagnostic logging and local Agility exports; one run included PR #233. The loader library tests passed 19/19, including windows_assigns_static_tls_to_a_prepared_dll. The later GPU DEVICE_HUNG does not establish a loader defect. AI-assisted testing and report (OpenAI Codex).

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.

6 participants