Loader: keep the cleared TLS callback pointer out of base relocations #4

Manually merged
github merged 1 commit from gh-pr/4/head into gh-pr/4/base 2026-11-26 03:46:13 +00:00
Owner

@⁠Exorion1er on GitHub · 2026-11-23 22:37 UTC · original
Exorion1er:fix/tls-callbacks-reloc → main · +58 −0 · 1 files · 1 commits · merged 2026-11-23 22:45 UTC

What

prepare() clears the TLS AddressOfCallBacks field but keeps its DIR64 base relocation. If the prepared copy is mapped anywhere but its preferred base, the relocation rewrites the 0 as the rebase delta, and the OS loader then walks a callback array at that bogus address.

On Windows this stays hidden because the copy gets 0x140000000. Under Wine/Proton, DYNAMIC_BASE DLLs are mapped high (here at 0x6ffff23c0000), so LoadLibraryExW faults inside ntdll before any title code runs.

The fix makes that relocation entry IMAGE_REL_BASED_ABSOLUTE (a no-op); patches_own_test_binary now asserts that no relocation targets the cleared field.

Tested

  • Fedora 44, GE-Proton11-12 (Wine 11.0), RX 9070 XT (RADV, Mesa 26.2.7), cross-built with xwin: before, a crash in ntdll during victory_loader::load; after, the title boots through the first-boot screens, the intro video with sound and the start menus (tested by hand).
  • cargo test -p victory-loader --lib under Wine: 6 passed.
  • Not run on Windows; there the copy loads at its preferred base, so the relocation changes nothing.

Note for Linux/Proton users (no code change)

Past the loader, vkd3d-proton caps shader-visible view heaps at 1,000,000 descriptors by default. GTA VI's heap is 1,245,184 (+65,536 dynamic), so VIctory falls back to the capped heap ("host view heap capped at 1000000") and the GPU page-faults on the first descriptor read past it. VKD3D_CONFIG=descriptor_heap (vkd3d-proton with VK_EXT_descriptor_heap, e.g. RADV on Mesa 26.2) lifts the cap, and the menus run at 30 fps.

🤖 Generated with Claude Code

**@⁠Exorion1er** on GitHub · 2026-11-23 22:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/4) `Exorion1er:fix/tls-callbacks-reloc` → `main` · +58 −0 · 1 files · 1 commits · merged 2026-11-23 22:45 UTC ## What `prepare()` clears the TLS `AddressOfCallBacks` field but keeps its DIR64 base relocation. If the prepared copy is mapped anywhere but its preferred base, the relocation rewrites the 0 as the rebase delta, and the OS loader then walks a callback array at that bogus address. On Windows this stays hidden because the copy gets 0x140000000. Under Wine/Proton, DYNAMIC_BASE DLLs are mapped high (here at 0x6ffff23c0000), so `LoadLibraryExW` faults inside ntdll before any title code runs. The fix makes that relocation entry `IMAGE_REL_BASED_ABSOLUTE` (a no-op); `patches_own_test_binary` now asserts that no relocation targets the cleared field. ## Tested - Fedora 44, GE-Proton11-12 (Wine 11.0), RX 9070 XT (RADV, Mesa 26.2.7), cross-built with xwin: before, a crash in ntdll during `victory_loader::load`; after, the title boots through the first-boot screens, the intro video with sound and the start menus (tested by hand). - `cargo test -p victory-loader --lib` under Wine: 6 passed. - Not run on Windows; there the copy loads at its preferred base, so the relocation changes nothing. ## Note for Linux/Proton users (no code change) Past the loader, vkd3d-proton caps shader-visible view heaps at 1,000,000 descriptors by default. GTA VI's heap is 1,245,184 (+65,536 dynamic), so VIctory falls back to the capped heap ("host view heap capped at 1000000") and the GPU page-faults on the first descriptor read past it. `VKD3D_CONFIG=descriptor_heap` (vkd3d-proton with `VK_EXT_descriptor_heap`, e.g. RADV on Mesa 26.2) lifts the cap, and the menus run at 30 fps. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
prepare() zeroes the title's TLS AddressOfCallBacks but left the
IMAGE_REL_BASED_DIR64 entry that patches it. When the loader maps the
prepared copy away from its preferred base, that entry turns the 0 into
the rebase delta and the loader reads TLS callbacks from there. On
Windows the copy lands at 0x140000000 so the delta is 0; under Wine,
which maps DYNAMIC_BASE images high, LoadLibraryExW faults in ntdll
before any title code runs.

The entry is now rewritten as IMAGE_REL_BASED_ABSOLUTE (a no-op), and
the prepare test checks that no relocation targets the cleared field.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:46:11 +00:00
github manually merged commit c21208c18a into gh-pr/4/base 2026-11-26 03:46:13 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-23 22:45 UTC · original

Good catch, thanks for the PR

**@⁠Marvisak** on GitHub · 2026-11-23 22:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/4#issuecomment-7116142425) Good catch, thanks for the PR
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!4
No description provided.