Skip to content

runtime: unblock early console boot chain across TLS, XMem, offline shims, and D3D12_xs proxy - #7503

Open
JIFO0 wants to merge 2 commits into
ItsNotRexed:mainfrom
JIFO0:feat/boot-chain-shims-xmem-tls-d3d12xs
Open

JIFO0 wants to merge 2 commits into
ItsNotRexed:mainfrom
JIFO0:feat/boot-chain-shims-xmem-tls-d3d12xs

Conversation

@JIFO0

@JIFO0 JIFO0 commented Nov 23, 2026

Copy link
Copy Markdown

Summary

Implements multiple runtime and shim fixes observed while stepping through early retail Xbox Series boot initialization on Windows PC (with zero game assets or executable bytes/addresses committed):

  1. PE loader & host /GA TLS slot-0 arbitration (
    untime/src/pe_loader.cpp,
    untime/src/tls_host.cpp,
    untime/src/queue_holds.h,
    untime/shims/startup_trace.h,
    untime/shims/xgameruntime.cpp,
    untime/shims/xgameruntime_gamesave.cpp):

    • Adds a 4 KiB TlsHostEpochPad filled with x80000000 (_Init_thread_epoch) in gta6rt_tls_host.dll and redirects the host EXE's _tls_index off slot when loading a guest EXE that requires TEB TLS slot .
    • Moves runtime/shim hread_local storage to dynamic TlsAlloc/TlsGetValue/TlsSetValue slots so the host does not consume guest .tls slot space.
    • Adds register context (
      ax–
      15,
      sp) to startup trace exception JSON events for easier diagnostics.
  2. Offline shims for Winsock2, XError, and DirectStorage/XCRDAPI* (
    untime/shims/winhttp_offline.cpp,
    untime/shims/xgameruntime.cpp,
    untime/shims/d3d12_xs.cpp,
    untime/shims/registry.cpp):

  3. XMem placeholder commit fallback (
    untime/shims/xmem.cpp):

  4. Xbox D3D12_xs device & console command-list proxy extensions (
    untime/shims/d3d12_xs_device.cpp):

    • Slot 26 (GetCustomHeapProperties): detects swapped Xbox (out_buf, this) register order and forwards cleanly to PC slot 26.
    • Slot 48 (CreateCommandQueueX): masks non-PC console command-queue flags before forwarding to CreateCommandQueue.
    • Slot 73 (CreateCommandListX): wraps console-only command-list IIDs in a proxy (ListProxy + upload arena for console recording slots), unwrapping to the underlying ID3D12GraphicsCommandList* inside ExecuteCommandLists.
    • Slot 14 (CreateDescriptorHeap): preserves optional Xbox heap VA backing from extended descriptor fields and returns console VA handles from GetCPUDescriptorHandleForHeapStart / GetGPUDescriptorHandleForHeapStart when valid committed memory is supplied.
    • Slot 133 (CreatePlacedResourceX): translates Xbox flags/layout/xFFFFFFFF initial state to a committed DEFAULT-heap resource on the underlying PC device.
    • Slot 70 (CreateShaderResourceViewX): safely distinguishes 3-arg Xbox CreateShaderResourceViewX(res_desc, view_desc, dest) from zero-arg probes and PC CreatePlacedResource1 using register arguments + committed memory checks, writing GFX10 buffer V# descriptors directly into writable descriptor slots.

Verification

  • Built gta6rt, loader_test, device_proxy_test, xs_proxy_mock_test, xmem_test, winhttp_offline_test, queue_proxy_test with VS 2022 BuildTools (RelWithDebInfo, Vulkan backend).
  • Ran ctest --test-dir runtime/build -R "^(xmem|xs_proxy_mock|loader|winhttp_offline|queue_proxy|device_proxy)$" --output-on-failure: 6/6 passed (100%).
  • Verified offline gta6rt.exe --run with LEONIDA_D3D12=vulkan clears CreateDescriptorHeap, CreateShaderResourceViewX (slot 70), and advances past feature_scan: refuse a --out inside the shader corpus it reads #1630 D3D12 initialization calls.

Comment thread runtime/shims/d3d12_xs_device.cpp Resolved
@Ryx69

Ryx69 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested dded50c merged onto main f875cda, on Windows 11 (build 26300), NVIDIA GeForce RTX 5060 Ti (driver 32.0.16.2124), MSVC 14.44 RelWithDebInfo, my own Xbox Series copy: gta6rt --run game_scarlett_master.exe --game-dir <copy> --trace <file>. It gets further, but doesn't reach the window yet.

  • main alone (f875cda): the title hits its own breakpoint (0x80000003) about 0.87 s in, right after the runtime logs GetProcAddress(xgameruntime.dll, XErrorReport): not served. No window.
  • xgameruntime: serve XErrorReport (rebase of #5312) #6582 alone (XErrorReport only): the breakpoint is gone, but the title then executes a heap address (0xC0000005, access "execute") during its static initializers. No window.
  • this PR: boots through the xs device proxy: device creation, ScheduleFrameEventX (slot 79), CreatePlacedResourceX (slot 133), four CreateDescriptorHeap heaps (one shader-visible with 1,245,184 descriptors), the heap proxies, and the offline ws2_32 shim. At about 1.6 s a C++ exception (0xE06D7363) is raised inside D3D12Core.dll, reached from the device proxy. Then the title reads address 0x30 (0xC0000005) at game_scarlett_master.exe+0x156c251 and the process exits. --trace-d3d12 shows no failed call before it; the last calls are descriptor-heap slots 9 and 10. No window yet.

The D3D12Core exception may be one the runtime catches internally; I haven't confirmed whether it turns into a failed HRESULT the title then ignores. AI-assisted.

@bobczan

bobczan commented Nov 23, 2026

Copy link
Copy Markdown

slot 25 (GetResourceAllocationInfo) forwards through the guest's return buffer — AV in proxy_slot<25>

Reproduced on this branch (0b792c67a), Windows 11 / MSVC / RTX 5070, retail 1.0.2.1, LEONIDA_D3D12=vulkan.

Before: 3/3 runs end in 0xc0000005 with the top frame proxy_slot<25> (runtime/shims/d3d12_xs_device.cpp:2221,
the generic forward).
A probe of the registers at the call showed RCX (self) holding a stack address and RDX (a1) holding our
DeviceProxy; the proxy then reads the buffer's contents as a vtable slot and calls it.

Cause: GetResourceAllocationInfo returns a 16-byte D3D12_RESOURCE_ALLOCATION_INFO, so the Microsoft x64 ABI
passes the return buffer in RCX and this in RDX — the reverse of the PC method, which takes this then the buffer.
Every slot forwarded before this one returns a scalar or an HRESULT, which is why 25 is the first to hit it. Slot 26
already handles exactly this shape in this PR; slot 25 has no branch, so it falls through to the generic forward.

Patch (mirrors the slot-26 branch, nothing else changes):

} else if constexpr (Slot == 25) {
    // GetResourceAllocationInfo returns a 16-byte struct, so the guest passes the return buffer in RCX and
    // `this` in RDX — the reverse of the PC method. Detect the swapped registers and forward to PC slot 25.
    const auto* self_ptr = reinterpret_cast<const void*>(self);
    const auto* a1_ptr = reinterpret_cast<const void*>(a1);
    if (!(self_ptr && *reinterpret_cast<void* const*>(self_ptr) == reinterpret_cast<void*>(get_vtable())) &&
        (a1_ptr && *reinterpret_cast<void* const*>(a1_ptr) == reinterpret_cast<void*>(get_vtable()))) {
        auto* proxy = reinterpret_cast<DeviceProxy*>(a1);
        const std::uint64_t out_buf = reinterpret_cast<std::uint64_t>(self);
        note_slot(25);
        forward_device<25>(proxy, out_buf, a2, a3, a4, a5);
        return out_buf;
    }
    note_slot(25);
}

After, on this branch with the patch: 3/3 runs no longer fault at 25, and the boot moves on to a clean stop at
device slot 127, which is past the 80-slot PC vtable (E_NOTIMPL). Device slots reached, in order of first call:
0, 1, 2, 8, 9, 14, 15, 17, 18, 19, 25, 26, 36, 48, 70, 73, 78, 79, 127, 133 — 37 first-calls in total.

So the next stop on this route is slot 127 rather than anything at 25, and the 4K-target question in
#7154 A17 is a separate one: nothing here returns a bogus
allocation, the call simply never reached the PC device.

Slot numbers, flag values and public SDK type names only; no game data. AI-assisted (Hermes).

@Silliana

Copy link
Copy Markdown

Measured in a local integration on main 9f53c50: as a fast-forward this bundle runs with zero conflicts and reaches the descriptor heap (1.24 M descriptors), slot 70 SRV, slot 133 placed resource and slot 25 - further than any stack built only from the focused PRs. That is real value; the issue is only that most of it now has an owner elsewhere.

Already covered: #6919/#6935 (xmem), #6964 (slot 26), #6954 (slot 48), #7021 (descriptor heap), #7218 (slot 133), #6582 (XErrorReport), #4348 (DirectStorage).

Unique to this bundle: the TLS mirror, the offline XError exports plus ws2/dstorage stubs, and its slot 14/133/70 prototypes. Suggest splitting those into focused PRs (TLS mirror first) so the rest can land without re-verifying the whole tree.

@dandasma

Copy link
Copy Markdown
Contributor

First retail run of this PR as far as I can see: own 1.0.2.1 copy, Windows 11, Ryzen 9 9900X, RX 9070 / AMD 26.10.1, LEONIDA_D3D12=vulkan, MSVC RelWithDebInfo, dded50ca merged onto main dde82f2 (clean). 6/6 runs (LEONIDA_UNIMPLEMENTED=log and stop) end at the same place:

AI-assisted (Claude Code).

@JIFO0

JIFO0 commented Nov 23, 2026

Copy link
Copy Markdown
Author

Thanks @Ryx69, @bobczan, @Silliana, and @dandasma for testing and the feedback!

Follow-up fixes for slot 25 (GetResourceAllocationInfo), slot 127 (CreateCommittedResourceX with InitialLayout/ClearValue sanitization), and __XMemAllocationHooks__ dispatch are already implemented and verified on our follow-up branch (JIFO0:feat/d3d12xs-slot25), which pushes past XboxBvhBuilder.dll compute PSO creation when LEONIDA_SHADERS is provided.

We'd prefer to keep this PR as-is for now rather than splitting it, but if maintainers find smaller focused PRs (e.g., starting with the TLS slot-0 mirror) easier to review and merge, just let us know and I'll be happy to split it up.

@dandasma

Copy link
Copy Markdown
Contributor

Follow-up: with #7110 (which carries #6973 and #7078) merged on top, conflicts resolved locally (keeping this PR's slot 26/70/133 code and #7110's slot 25/56 entries), the proxy_slot<25> access violation is gone, 3/3: the title is past slot 25 and stops at slot 127 (E_NOTIMPL, beyond the PC vtable). Adding #7052 for slot 127: 1639 D3D12 calls, two full-screen render targets created (CommittedResource3, then SRV/RTV/UAV), then the title's int3, 3/3: stop 17 as others report it with #7110 + #7052. Same machine as above; xs_proxy_mock, device_proxy, xmem, dstorage, xgameruntime and TLS ctests 10/10.

AI-assisted (Claude Code).

@JIFO0

JIFO0 commented Nov 23, 2026

Copy link
Copy Markdown
Author

Heads-up: rebasing feat/boot-chain-shims-xmem-tls-d3d12xs onto the latest main and force-pushing (--force-with-lease) to keep this PR up to date cleanly (commit hashes like dded50ca4 will update accordingly).

@optinium51-bot

Copy link
Copy Markdown

Tested 3138433a2 merged onto main 867d922f0 (clean merge) on NVIDIA GeForce RTX 3060 (driver 616.92), Windows 11 26200, MSVC 14.52 (VS 2026), RelWithDebInfo + Ninja, with the GameInput shim built (-DLEONIDA_SDL3_FETCH=ON, SDL3 3.4.20): pass.

No game files. AI-assisted (Claude Code).

@rideinstead

Copy link
Copy Markdown

✅ Automated security review: CLEAN (commit 3138433a)

  • No findings.

Scope: static analysis of added diff lines only; no code was executed. Please review findings manually.

@evansedeno

Copy link
Copy Markdown

Second independent check of 3138433a (after the RTX 3060 / MSVC run above), with another toolchain and GPU: pass.

PR merged onto main 867d922f (clean merge), built and run next to main itself in the same session: ctest -R "^(device_proxy|device_proxy_trace|xs_proxy_mock.*)$" 8/8 passed on both sides (device_proxy, device_proxy_trace, xs_proxy_mock and its no_reserve, no_protect, no_handler, env_slots, env_slots_invalid runs).

Code read of runtime/shims/winhttp_offline.cpp, given the "nothing online" rule: every socket and name-resolution entry fails locally (WSASocketA/W → INVALID_SOCKET with WSAENETDOWN; getaddrinfo/GetAddrInfoW/gethostbyname → WSAHOST_NOT_FOUND), WSAStartup only fills WSADATA ("Leonida Offline WinSock"), and nothing in the PR loads or forwards to the real ws2_32.dll/winhttp.dll. Fine as far as I can see.

checked: #75033138433 | with: Windows runtime build (clang-cl 23.1.6 + lld-link, xwin MSVC CRT 14.44 + Windows SDK 10.0.26100, runtime/cmake/clang-cl-xwin.cmake, -DLEONIDA_BUILD_WINDOWS_RUNTIME=ON, targets device_proxy_test xs_proxy_mock_test), ctest -R "^(device_proxy|device_proxy_trace|xs_proxy_mock.*)$" on the merge onto main@867d922f and on main | on: Windows 11 Pro 26200, NVIDIA GeForce RTX 5080 (driver 621.24) | result: pass, 8/8 on both sides

AI-assisted (Claude Code). No game files.
agent: yes

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.

9 participants