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

Manually merged
github merged 4 commits from gh-pr/28/head into gh-pr/28/base 2026-11-26 03:47:07 +00:00
Owner

@⁠ifBars on GitHub · 2026-11-23 23:20 UTC · original
ifBars:fix/windows10-import-directory → main · +91 −6 · 2 files · 4 commits · merged 2026-11-24 00:31 UTC

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.

**@⁠ifBars** on GitHub · 2026-11-23 23:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/28) `ifBars:fix/windows10-import-directory` → `main` · +91 −6 · 2 files · 4 commits · merged 2026-11-24 00:31 UTC ## 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.
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.
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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:47:05 +00:00
github manually merged commit 0e5953d1dd into gh-pr/28/base 2026-11-26 03:47:07 +00:00
Author
Owner

@⁠Sunkiller-qc on GitHub · 2026-11-23 23:46 UTC · original

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.

**@⁠Sunkiller-qc** on GitHub · 2026-11-23 23:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/28#issuecomment-7117355106) 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.
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 00:06 UTC · original

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 #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).

**@⁠DaviTostes** on GitHub · 2026-11-24 00:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/28#issuecomment-7117702626) 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 #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).
Author
Owner

@⁠ifBars on GitHub · 2026-11-24 00:03 UTC · original · edited 2026-11-24 00:07 UTC

@⁠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.

**@⁠ifBars** on GitHub · 2026-11-24 00:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/28#issuecomment-7117654127) · edited 2026-11-24 00:07 UTC @⁠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.
Author
Owner

@⁠ifBars on GitHub · 2026-11-23 23:55 UTC · original · edited 2026-11-24 00:07 UTC

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** on GitHub · 2026-11-23 23:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/28#issuecomment-7117518299) · edited 2026-11-24 00:07 UTC **Update:** A static TLS check changed the conclusion below. See the [corrected results and fix](https://git.gtahub.st/github/Marvisak--VIctory/pulls/28). @⁠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.
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 00:07 UTC · original

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 #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).

**@⁠DaviTostes** on GitHub · 2026-11-24 00:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/28#issuecomment-7117733812) 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 #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).
Author
Owner

@⁠Proudnoob4 on GitHub · 2026-11-24 00:21 UTC · original

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.
  • #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 (#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; #44 skips it in that test.
**@⁠Proudnoob4** on GitHub · 2026-11-24 00:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/28#issuecomment-7117982788) 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. - **#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 (#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; #44 skips it in that test.
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 00:28 UTC · original

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 #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).

**@⁠DaviTostes** on GitHub · 2026-11-24 00:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/28#issuecomment-7118100372) 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 #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).
Author
Owner

@⁠erLCoder on GitHub · 2026-11-24 06:09 UTC · original

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).

**@⁠erLCoder** on GitHub · 2026-11-24 06:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/28#issuecomment-7123638071) 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).
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!28
No description provided.