Repository navigation
Conversation
1.0.2.1 imports XMemAllocDefault, XMemFreeDefault, XMemAllocatePhysicalPages, XMemFreePhysicalPages, XMemMapPhysicalPages, XMemMapPhysicalPagesScatter and XMemIsToolsMemAvailable; none were in the shim table, so loading stopped on unresolved imports. XMemFree now releases only pointers this shim handed out. The title also frees console pointers (its own arenas, mapped physical pages); passing those to the CRT is what produced STATUS_HEAP_CORRUPTION (0xC0000374) on the retail executable. Virtual allocations keep the console's attribute word and its page-protection byte apart. The title asks for 0x801 on a 24 GiB reservation and traps on int3 when VirtualAlloc rejects it; the host accepts eight low-byte protections only, so an unknown word becomes PAGE_READWRITE and is recorded once. MEM_LARGE_PAGES is dropped and traced rather than failing the reservation. Opt-in traces (LEONIDA_XMEM_HEAP_PROBE, LEONIDA_XMEM_NOFREE) record the allocator table and each virtual allocation.
The Xbox-only call hands the title's memory manager the console's virtual-address ranges. The host has one address space and the D3D12 layer allocates from it, so there is nothing to configure and the call returns S_OK. Its argument list is not documented; the first call records all four registers, a hex view of every argument that points at readable memory and the caller, because 1.0.2.1 traps (int3) shortly after the call when the descriptors are not what it expects. LEONIDA_CVMX_RET overrides the return for the experiment.
The title's console toolchain folds every thread-local access to TEB->ThreadLocalStoragePointer[0] (7,802 gs:[58][0] sites in 1.0.2.1), so its CRT ignores the index the loader patches into its TLS directory. gta6rt.exe is the process's first module and owns index 0; the title wrote its cached allocator pointer to host TLS +0x13a8, read host garbage back at game+0x104075 (0xC0000005), and the same write ended in STATUS_HEAP_CORRUPTION (0xC0000374) on the next malloc. Loader now takes mirror_index0. For the first image it copies the raw template and zero-fill to the base of the host EXE's index-0 block, on the loading thread, on threads that were already running, and on DLL_THREAD_ATTACH. The loader's own reserved helper slot still receives a separate copy, so the patched _tls_index keeps working. src/host_tls_pad.cpp reserves the room: MSVC's tlssup.obj puts 272 bytes of empty .tls before the .tls\$ contributions, then the pad. The template ends inside the pad, before _Init_thread_epoch and the task queue's thread-locals, and mirror_index0_block enforces that range at run time. Every runtime thread_local moves to a TlsAlloc slot (shims/host_tls.h): startup trace state, XThread time-sensitive flag, save read count, queue pump guard and the loader's per-thread slot table. Otherwise the title's data would overwrite them. startup_trace gains the diagnostics that found this: guard-page write watch with re-arm, a last-resort unhandled record, faulting registers plus the TEB TLS vector, slot 0 and +0x13a8 on access violations, and the LEONIDA_TLS_INFO layout dump. Verified with cmake --build runtime/build --config RelWithDebInfo --target gta6rt (clean). With the mirror the heap corruption and the game+0x104075 fault are gone; the title runs to its own int3 (0x80000003) at game+0x5a91c21. The test targets were not built.
|
Independent Windows build test of Setup: Windows 11 x64, MSVC 19.44.35220 (
AI-assisted review/test. |
|
Code read of 6643030 (the TLS commit), beyond the link error already reported above:
AI-assisted (Claude Code). |
|
Overlaps #4313 (RT-259). From the two diffs, both PRs aim at the same fault: under
What #7524 has that #4313 doesn't:
#4313 has 4 Windows Read from the diffs only; nothing built or run for this comment. AI-assisted (Claude Code). |
host_tls_pad.cpp was added only to gta6rt, so loader_test (and any other target compiling pe_loader.cpp) failed to link on guest_tls_pad_end. The pad and its accessors now live in pe_loader.cpp: gta6rt.exe, the only image that owns static TLS index 0, defines LEONIDA_MIRROR_INDEX0 and gets the real 8 KiB pad; other targets get null accessors and never set Module::mirror_index0. Verified: gta6rt and loader_test build clean, ctest -R ^loader$ passes.
|
Fixed in f302413. The pad now lives in Verified locally: |
|
Build break on this branch, reproduced twice from a clean configure (no local changes):
The third commit says the pad is defined in pe_loader.cpp so every loader target links, but xmem_test is not a loader target: its link line is est/xmem_test.cpp.obj shims/xmem.cpp.obj shims/registry.cpp.obj, and startup_trace.h (pulled in by xmem.cpp) now calls guest_tls_pad() from open(). Nothing in that set defines it. Two ways out:
Environment: VS 2026 (MSVC 14.52), Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, Windows 11 26300, RTX 4080. Built with |
|
Integration signal (no change requested): on Windows 11 26200, RTX 3070 Ti (driver 32.0.15.9649), main 9f53c50, merging this PR with #6582 and #4348 locally on the retail 1.0.2.1 executable: the TLS-index-0 fault is gone, XErrorReport is served, DStorageGetFactory and IDStorageFactoryX::OpenFile return the shim interfaces, and the title creates the D3D12 device on the Vulkan backend (D3D12XboxCreateDevice ok, RTX 3070 Ti, subgroup 32). The next fault is device slot 26's by-value-return ABI (AV reading this=1 at +0xd0), which #6964 addresses. So the TLS half survives the next three subsystems. No game data in this report. |
|
Follow-up: with the link break above worked around locally, this branch does reach a retail 1.0.2.1 title, and the next What the branch gets past (no patch beyond the link workaround): the loader change alone stops early, with Adding the flat So the ordering for a title bring-up looks like: TLS index 0 (this PR) -> flat XErrorReport -> DStorageGetFactory. Environment: VS 2026 (MSVC 14.52), Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, Windows 11 26300, RTX 4080. No game |
…ad symbol startup_trace.h reached the pad through a function in pe_loader.cpp, so every target that compiles xmem.cpp or startup_trace_test but not the loader failed to link. The pad is now reached through a function pointer that pe_loader.cpp sets during static initialisation; targets without it report no pad. Review fixes in the same pass: capacity is measured once as guest_tls_pad_end() - module_tls_slots()[0] instead of comparing another thread's block against the loading thread's pad; a mirror module writes 0 to its AddressOfIndex and installs no copy at all (the helper slot is still claimed for its thread events), so there is a single index-0 copy and no allocation before the range check; thread_tls_slots() is freed on DLL_THREAD_DETACH; mirror records are never VirtualFree'd.
… leg XGameRuntimeInitialize resolves the flat export XErrorReport after a failed API initialisation; without it GetProcAddress returned null and the title reported 0x8924010a instead of the real status. The export logs the HRESULT and forwards to the callback the title registered.
The retail title imports DStorageGetFactory from XCRDAPI.dll and traps when the import is classified but unserved. This is the console DirectStorage factory and file path taken from ItsNotRexed#4348 (mariuslozo-boop), rebased onto the current tree: factory and file interfaces, queue, status array, fences, synthetic files through the file shims, and the access-violation-to-E_DSTORAGE_ACCESS_VIOLATION guard. dstorage_test covers the factory over synthetic files; unimplemented_policy_test classifies xcrdapi. Verified: gta6rt builds, the title passes DStorageGetFactory and OpenFile, and ctest dstorage/loader/unimplemented_policy pass.
… fail The shim gained both behaviours for the retail boot: 0x20000000 large-page requests fall back to ordinary committed pages, and nonzero attribute words are recorded and served. The test still asserted the old rejection.
|
Measured in a local integration on main 9f53c50: this PR plus #6582/#4348/#6964/#6954/#7076/#7021 booted the retail title to 1,181 ok D3D12 calls (device, 5 queues, 7 allocators, 5 fences, 581 list/Close pairs) and, merged again in the console-command-list stack, past device+queue+fence. It fixes the index-0 access violation in both runs. #4313 targets the same fault; only one loader-owned index-0 scheme can land. Suggest this one is canonical and #4313 closes, or rebases as a test-only addition (a loader test that asserts the pad and the copy). Closed #7473 was the earlier attempt at the same fix. Not asking anyone to drop work - just flagging the overlap so the loader change stays single-sourced. |
|
Measured against #4313, which is already in the #7154 stack and ships a This branch has no test for the mirror. The pad is safe only while it is the first thing in the block, and the code does not check that. In the clang-cl/xwin build the pad starts at block Scope: this PR is 8 commits, not the 3 the description names. Not a blocker, just a detail: agent: yes |
Yoshi-OOF
left a comment
There was a problem hiding this comment.
Independent test on Windows 11 x64 (build 26300), MSVC 19.44, RelWithDebInfo, RTX 5070 Ti (621.24). At upstream dde82f27e, initialization completed, but --run stopped with 0xC0000374. At this PR head the same package progressed to the WSAStartup entry breakpoint, where I deliberately stopped it before Winsock initialization. No heap failure was observed before that stop; this is not a frame or gameplay result, or a TLS-only A/B.
The run also produced six malformed JSONL records: five virtual allocation attribute events and one large-page event. hex() returns a bare 0x... token, which is not a JSON number. With the three string-quoting changes below, a rebuilt run to the same breakpoint produced 23/23 valid JSONL records, including all six XMem events. The protection fallback was not reached, but uses the same invalid encoding.
No game data or logs attached. AI-assisted: yes.
| if (first) { | ||
| rt::startup_trace::event( | ||
| "xmem_virtual_alloc_protect", | ||
| "\"protect\":" + rt::startup_trace::hex(protect) + ",\"caller\":" + |
There was a problem hiding this comment.
Quote the hexadecimal protection value for valid JSONL.
| "\"protect\":" + rt::startup_trace::hex(protect) + ",\"caller\":" + | |
| "\"protect\":" + rt::startup_trace::quote(rt::startup_trace::hex(protect)) + ",\"caller\":" + |
| if (!seen.insert(attributes).second) return; | ||
| } | ||
| rt::startup_trace::event("xmem_virtual_alloc_attributes", | ||
| "\"attributes\":" + rt::startup_trace::hex(attributes) + |
There was a problem hiding this comment.
Use the same JSON string representation as the existing xmem_attributes event.
| "\"attributes\":" + rt::startup_trace::hex(attributes) + | |
| "\"attributes\":" + rt::startup_trace::quote(rt::startup_trace::hex(attributes)) + |
| "\"allocation_type\":" + rt::startup_trace::hex(allocation_type) + ",\"caller\":" + | ||
| rt::startup_trace::quote( | ||
| rt::startup_trace::where(reinterpret_cast<uint64_t>(_ReturnAddress())))); |
There was a problem hiding this comment.
Quote the hexadecimal allocation type too.
| "\"allocation_type\":" + rt::startup_trace::hex(allocation_type) + ",\"caller\":" + | |
| rt::startup_trace::quote( | |
| rt::startup_trace::where(reinterpret_cast<uint64_t>(_ReturnAddress())))); | |
| "\"allocation_type\":" + rt::startup_trace::quote(rt::startup_trace::hex(allocation_type)) + | |
| ",\"caller\":" + rt::startup_trace::quote( | |
| rt::startup_trace::where(reinterpret_cast<uint64_t>(_ReturnAddress())))); |
|
Second check on a Windows 11 machine (RTX 5080, driver 616.92), own 1.0.2.1 package, MSVC 2022 Before ( With this head ( That next stop is this branch's older Commands: |
…gainst main Update docs/retail_boot_chain.md "What clears it" column against current main: - Stops 1, 2, 6, 10, 11 landed on main (ItsNotRexed#6919, 042c5f3: physical pages, 2 MiB pages, and placeholder reservations). - Stop 3 landed on main (e417570: XErrorReport in runtime/shims/xgameruntime.cpp). - Replace closed unmerged PR ItsNotRexed#4313 (Stop 4) with tracking open PRs ItsNotRexed#8379, ItsNotRexed#7524. - Replace closed unmerged PR ItsNotRexed#4348 (Stop 5) with active takeover PR ItsNotRexed#8461, ItsNotRexed#7784. - Link open tracking PRs for Stops 7, 9, 12 (ItsNotRexed#8851, ItsNotRexed#9061, ItsNotRexed#2490, ItsNotRexed#9045, ItsNotRexed#8414). Addresses agulerman's finding in ItsNotRexed#8868.
|
Ran this PR against a real copy. It moves the frontier from 4 to 6 on this box. Machine: Windows 11 26300, Ryzen 7 5700X3D, RX 9070 XT (RDNA4, gfx1201), AMD 32.0.32029.2010 (26.11.2). Build: MSVC 19.44 (unpacked 14.44 toolset + SDK 10.0.28000), Ninja,
This PR ( So: TLS blocks are handed out, the title gets through Nothing about that is a criticism of the PR — it is the point: on this configuration it clears the TLS stop cleanly and lands exactly where the boot-chain doc says the next wall is. I have not merged it with the other boot PRs; this is #7524 alone on its base. AI-assisted — agent: yes. |
|
Tested the TLS part of this PR on the retail executable under Wine 11.22 (Linux, AMD RX 9070 XT on RADV), on
The TLS fix looks separable from the DirectStorage/xmem work here; splitting it out would make it mergeable on its own. AI-assisted (Claude Code), run and checked by me. |
|
Code review of What is right
What is wrong or unhandled at
|
… module TLS index 0 (RT-259) Squashed from ItsNotRexed#4313 by mariuslozo-boop, head 28ea6b9 (security scan PASS). Taken instead of ItsNotRexed#7524 for the TLS index 0 fix: ItsNotRexed#7524's head moved past its scanned sha (and grew a DirectStorage bundle), and its mirror scheme keeps two copies of the title's TLS and misses threads that already exist (review on ItsNotRexed#7524). Conflicts: pe_loader.cpp on_host_thread_event keeps main's forget_ended_thread_id / release_existing_blocks_of_this_thread first, then the PR's two-pass kTlsSlotCount loops (so the executable's slot is covered; the off-by-one reported on the PR comes from taking main's bounds). install_on_existing_threads is bounded by kTlsSlotCount too, so threads already running at load() (thread-pool workers) get the executable's slot-0 copy, as main does for every other module; loader_tls_index0_test now checks that load() gave the early thread its copy and that install/uninstall are no-ops there. CMakeLists.txt keeps both test sets; README keeps main's already-running-thread text plus the PR's ordering sentence and index-0 limits.
Three commits from bringing up a retail 1.0.2.1 title with
gta6rt --run.Why the loader change
The title's console toolchain folds every thread-local access to
TEB->ThreadLocalStoragePointer[0]: 7,802 sites in its.textreadgs:[58][0]directly, ignoring the index patched into its TLS directory.gta6rt.exeis the process's first module and therefore owns index 0, so the title wrote its cached allocator pointer to host TLS+0x13a8, read host garbage back atgame+0x104075(0xC0000005), and the same write ended inSTATUS_HEAP_CORRUPTION(0xC0000374) on the nextmalloc.Loadernow takesmirror_index0(set only by--run). For the first image it copies the raw template and zero-fill to the base of the host EXE's index-0 block: on the loading thread, on threads already running, and onDLL_THREAD_ATTACH. The loader's reserved helper slot still gets its own copy, so the patched_tls_indexpath is unchanged.src/host_tls_pad.cppreserves the room. MSVC'stlssup.objemits 272 bytes of empty.tlsbefore the.tls\$contributions, then the pad; the copy ends inside the pad, before_Init_thread_epochand the task queue's thread-locals.mirror_index0_blockchecks that range at run time and fails the load if it does not hold.All runtime
thread_localstate moves toTlsAllocslots (shims/host_tls.h): startup trace,XThreadSetTimeSensitive, the save read count, the queue pump guard and the loader's per-thread slot table. Otherwise the title's data overwrites it.Other commits
xmem: serve the seven imports the title needs (XMemAllocDefault,XMemFreeDefault, the physical-page calls,XMemIsToolsMemAvailable); free only blocks the shim allocated; split the console attribute word from the page-protection byte (0x801on a 24 GiB reservation becomesPAGE_READWRITE); drop and traceMEM_LARGE_PAGESinstead of failing.d3d12_xs: implementD3D12ConfigureVirtualMemoryX. The host has one address space, so it returnsS_OK; the first call records the undocumented argument layout and caller, since the title traps shortly after when the descriptors are not what it expects.Diagnostics
startup_trace.hgains the tools that found the fault: a one-shot guard-page write watch with trap-flag re-arm, a last-resort unhandled-exception record, faulting registers plus the TEB TLS vector / slot 0 /+0x13a8on access violations, and aLEONIDA_TLS_INFOblock-layout dump.Verification
cmake --build runtime/build --config RelWithDebInfo --target gta6rtis clean (/W4 /permissive-). With the mirror in place the heap corruption and thegame+0x104075fault are gone; the title now runs to its ownint3(0x80000003) atgame+0x5a91c21, which is the next blocker rather than a loader fault.The 200+ test targets were not built for this branch. The change is gated on
mirror_index0, whose default is off, so test executables load images exactly as before.No game data is included in the diff.