runtime/src/pe_loader.cpp reads LEONIDA_TLS_GA_PATCH in ga_tls_patch_enabled()
to switch the /GA slot-0 TLS rewrite (patch_ga_tls_reads) off, and no document
named it: tests/test_docs_env_vars.py failed on current main (5d74c27) with
"read by the code and named in no .md file: LEONIDA_TLS_GA_PATCH
(runtime/src/pe_loader.cpp:519)".
Document it in the PE loader's TLS section, next to the TLS index the loader
assigns: what the rewrite does, when it runs, and that "0" turns it off.
Tested with python -I tests/test_docs_env_vars.py (4/4 pass; the same test
fails on main) on macOS 27.0.1 arm64, Python 3.12.10.
A view unmapped whole has nothing to remap, so a fault on it is a real fault. Publishing it anyway
overwrote g_last_split, and a reader still faulting on the remainder of the split before it was
not retried.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/design.md lists these LDS atomics as not GPU-verified: the
instructions were measured with tools/hw_oracle and the translations
CPU-checked, but the translated SPIR-V never ran on a GPU.
cs_lds_atomics_ext.asm runs one lane through ds_mskor_b32 (DATA2 bits
outside DATA ORed in), ds_mskor_rtn_b32, ds_xor_rtn_b64 then ds_and_b64
on the same element, ds_add_rtn_f32 (1.5 + 2.25), and ds_inc_rtn_u32,
ds_dec_u32 and ds_rsub_u32 at their edge cases. The eight expected
words are derived in its header from the design.md rows. The fixture
is registered in check.py and run_gpu_tests.py next to
cs_lds_b64_cmpst, and the four rows note the GPU check.
load() rewrites a /GA executable's `mov r64, gs:[58h]` reads to a TlsAlloc slot whose value is a per-thread
view with the image's block at [0] (pe_loader.h, tls_ga_slot). install_thread_block creates that view for
the loading thread and for threads started after load(), but install_on_existing_threads gave the threads
that were already running only the block in TEB->ThreadLocalStoragePointer[tls_index]. A rewritten index-0
read on such a thread then loaded null and dereferenced it: the task queue runs a title's callbacks on pool
workers that predate the load, so this is the same AV the main thread had at exe+0x104075, moved to a worker.
Each existing thread now also gets a view of its own in TEB->TlsSlots[ga_slot], and ~Loader, the thread's
detach event and a reused thread id free it with the block.
Tested: runtime/test/loader_tls_test.cpp maps a new handmade /GA EXE fixture (tiny_ga_tls) and reads its
__declspec(thread) value from the loading thread, from a thread that existed before load() and from a later
one, then again after a second load(). Without the pe_loader change that test dies with 0xC0000005 on the
existing thread; with it all 95 checks pass. ctest -R loader: 4/4 passed (Windows 11, MSVC 19.44,
RelWithDebInfo, no GPU needed).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Slot 55 is the console's CreateDerivedPipelineState(pBasePSO, n, pRecords,
riid, ppv): n = 1..4 records of 0x14c bytes (a u32 tag, payload at +4) that
patch the base PSO's state before a new PSO is created.
- Slot 86 keeps a deep copy of the stream it creates on the returned PSO
(ID3D12Object private data, released with the PSO): shader bytecode,
stream-output and input-layout arrays and strings, cached blobs, and
AddRef'd root signatures.
- Slot 55 patches a copy of the base stream and creates the PSO through the
slot 86 path, so a derived PSO can itself be a base.
- Tags: 0 = DEPTH_STENCIL (or the DEPTH_STENCIL1 prefix), 1 = RASTERIZER,
2 = BLEND, 3 = sample mask (TomBox layout; the 1.0.2.1 title does not write
it), 5 = StencilReadMask and StencilWriteMask bytes overlaid on the base's
DEPTH_STENCIL, applied in record order. Other tags are refused.
- A base not created through slots 86/55, a base without the matching
subobject, malformed records, and n outside 1..4 are refused with E_FAIL or
E_INVALIDARG and a null output, each logged once.
- Slot 55 shadows PC CreateReservedResource1 (PC slot 55) on the proxy, as
slot 78 shadows PC CreateReservedResource2 in #7125; the vulkan device test
calls the PC method on the real device behind the proxy.
Tests: pso_stream_test (synthetic streams: console subobject offsets, deep
copy, patching, tag 5 overlay and record order, refusals) and
device_proxy_test over WARP (refusals, graphics base via slot 86, n = 3 and
n = 4 derivations, a derivation from a derived PSO).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LwHrL5Lxc1rum25b6tnpo8
(cherry picked from commit d80c40845d7eca9163f937de943b65482b7f0657)
The proxy also serves host callers: d3d12_vulkan_device_test drives the Vulkan device through it,
and its ID3D12Device5::CreateMetaCommand call (PC slot 61) landed in proxy_create_sampler_x
(found by nullmarsh on #7115: the test stopped at line 5763 instead of main's known line 6574).
Slot 61 now checks the caller's return address with a classifier the runtime installs
(set_console_caller, the name #7490 uses): D3D12XboxCreateDevice installs
rt::shims::mapped_image_base, so only a caller in an image the guest loader mapped gets
CreateSamplerX. Any other caller, and every caller when no classifier is installed, is forwarded
to the PC slot 61.
xs_proxy_mock_test checks all three cases: no classifier (PC slot 61), a guest caller (PC
CreateSampler with the same words; a null description skipped) and a host caller under an
installed classifier (PC slot 61). d3d12_vulkan_device_test again stops at line 6574, as on main.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 8f756ebe048af042638ce51a61490f35f4f44ee3)
#6935 routes the Xbox device proxy's slot 78 to the title's SetFrameIntervalX, by design: the proxy is the
title's device, answers ID3D12Device11 with itself, and shadows PC slots the way 62 and 76 already are. The
test still called the PC ID3D12Device10::CreateReservedResource2 through the proxy, so the call reached
SetFrameIntervalX and `tiles == 1` failed (@fever308's finding on #7049). The PC method is now checked on
the Vulkan device behind the proxy, the same call and the same expectations.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 703fc03a72694da4b9bcf47ba5399db34600fec5)
main's XErrorReport export (6312c057f) duplicated the one ladder-frame
already has; kept ladder-frame's definition and table entry. Brings in
the /GA TLS index 0 loader change (b7a3fed28).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Slot 81 goes through route_xbox_device_slot like the other Xbox routes, so
an override onto 70 or 74 still wins. Kept ladder-frame's slots 86/101/108
and the 74 env-slot mode next to #8869's slot 81 tests and its
LEONIDA_XS_FRAME_EVENTS_SLOT override. The handled-slots comment in the
header is rewritten as one list that matches device_slot_overridden.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Any non-empty value other than "0" lifts the frame-event cap: a
WaitFrameEventX hands its token out at once (no vblank grid, no latency
throttle) and PresentX presents unsynced, so the frame rate is whatever
the title renders. Registration and suspension keep their errors, an
uncapped frame's statistics report its present time, and the flag
survives suspend/resume. frame_pacer_test covers the grid's removal and
restoration.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Under d16 one component fills one VGPR and the tfe status follows it, so vdata is v[7:8] / v[11:12]. Same 1000 seeds and the same check as cs_imgload_d16 (vk_store_test load-d16, saturation row included). Suggested by nnonno91, who ran this companion on gfx1036 and an RTX 5090.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xgameruntime.lib's XGameRuntimeInitialize looks up "XErrorReport" with
GetProcAddress next to QueryApiImpl, the InitializeApiImpl* entries and
UninitializeApiImpl, and refuses to initialise when it is missing. In the
retail executable that is the lookup at +0x55e2b7e and the null check at
+0x55e2c08, after which boot stops at an int3 (+0x5a91c21).
The shim now exports XErrorReport(HRESULT, const char*) as a DLL export,
forwarding to the IXErrorImpl report it already served (callback, S_OK).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The retail game_scarlett_master.exe is built with /GA: it reads its TLS as
ThreadLocalStoragePointer[0] directly, without _tls_index, because the process
EXE always owns index 0. Mapped into gta6rt, index 0 belongs to gta6rt.exe, so
the game's allocator read gta6rt's TLS block and faulted at exe+0x104075.
load() now rewrites each `mov r64, gs:[58h]` in the EXE's executable sections
(53,246 sites in the retail exe) to `mov r64, gs:[1480h + 8 * slot]`, reading a
TlsAlloc slot (TEB->TlsSlots). Each thread's value there is a small view with
the image's TLS block at [0] and at [tls_index]. The rewrite is the same length
and runs before any of the image's code, TLS callbacks included. DLLs and
images whose index is already 0 are left alone; LEONIDA_TLS_GA_PATCH=0 turns it
off.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
unmap_range unmaps a straddling view whole and maps its remainders again, so pages the caller did not name are
briefly unmapped (aslan2142, #7584). The span being split is published and a vectored handler makes a faulting
access inside it wait, then retries it once the page is mapped again.
Taken from the follow-up patch of @matheuskshn (930e78a2, tested by them on an RTX 4070 Ti: replay_quad_list_test fails the two non-indexed cases on a6b31d51 and passes with it). Re-run here: replay_quad_list_test and d3d12_rect_list_test exit 0 on the pod (Wine, RTX 4090).
Found in review under MSVC /W4: the loop's local 'pages' shadowed the function's own. Renamed to
cached_pages; no behaviour change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
d3d12_execute_indirect_validation reports five host-parity mismatches on the RTX 5060 and on
WARP: the layer accepts an argument buffer range the host refuses. Both live hosts bound the
bytes the signature can walk, max_count * stride, so a record that fits at the end of the
buffer while its stride runs past it is refused (offset 240 with stride 20 in a 256-byte
buffer), and both check the offset itself when max_count is 0, which the layer skipped
entirely.
The layer validated with (max_count - 1) * stride + record_size and only when max_count was
non-zero. It now uses the same span as the host and validates every call, in d3d12_com.cpp
(recording, so Close fails as the host's does) and in vulkan_replay.h (replay, which had its
own copy of the old arithmetic).
The test's positive GPU path recorded the same out-of-range calls the parity table marks as
refused, so it moves to an exact-fit range (244 + 12 == 256) and a max_count 0 no-op at the
buffer's end (offset 256), and the five parity rows take the verdict both hosts give here.
A placed buffer is a range of its heap's arena memory, but only the heap
held that range: releasing the application's last ID3D12Heap pointer
freed it while placed buffers in it were still alive, so the next heap
or committed buffer got the same GPU address and the arena zeroed and
overwrote the live buffer. On D3D12 a placed resource holds a reference
on its heap, so releasing the heap first is legal.
The placed buffer now holds the heap's range (the shared allocation
whose deleter returns it to the arena). New d3d12_placed_heap_lifetime
test: red on main (the new heap's buffer lands on 0x10000, the live
buffer's address), green with the fix.
AI-assisted (Claude Code)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>