A diagnostic for the retail boot (RT-5 follow-ups), off the hot path and with no behaviour change unless asked
for: LEONIDA_SKIP_ASSERTS=N (src/assert_skip.h, installed by main.cpp before any image code runs under
--init/--run): a vectored handler, added last, steps over up to N int3 (0xCC) at addresses in no host module and
logs each one as module+RVA (and as an int3_skipped trace event when --trace is open). After N it says so once
and the next int3 ends the run as before. An int3 in a host module, a breakpoint with no 0xCC at its address, or
a RIP that is neither at nor one past the 0xCC is passed on. Needs no --trace and no debugger.
Tests (synthetic, no game files): assert_skip_test (int3 in a VirtualAlloc'd page, the limit, a host-module int3,
a two-byte int 3, value parsing) and run_tiny_game_skip_asserts (two int3 in the mapped stand-in game, stepped
over end to end).
Carried over from old upstream PR 9961 (#228) without its caller logging for forwarded device slots, which the
carry-over of old PR 9990 (#1390) brings instead.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With TMP, TEMP and USERPROFILE all unset, GetTempPathW returns C:\Windows\, and the throwing create_directories/copy_file/ofstream on C:\Windows\leonida_* aborts with 0xc0000409 before the test body runs. runtime/test/test_temp_dir.h grows one entry, testfiles::temp_dir(): LEONIDA_TEST_DIR when set, the current directory when the temp environment is stripped (Windows), else the standard temp resolution. Fifty-two test files and the tiny_game fixture that called GetTempPathA/W or temp_directory_path directly now use it; d3d12_queue_handover_test.cpp also checks the _sopen_s result in capture_stderr instead of silently returning empty stderr. One runtime source function needed the same fallback because tests exercise it: tls_host_clone_dir in runtime/src/pe_loader.cpp (the loader_tls tests). Rebased onto current main after its D3D-448 additions to d3d12_mesh_test.cpp (3-way; the mesh test keeps both). Verification on a Windows VM: stripped environment - the previously crashing d3d12 tests exit 77 (no usable Vulkan device) instead of aborting, file_system_test runs all 505 checks and loader_test all 95 with zero failures; normal environment - identical outcomes; LEONIDA_TEST_DIR honored under a fully stripped environment (the scratch folder observed mid-run inside it, cleaned up after the pass). The finding is whoalin1's (coordination issue #14, 02:37:44Z).
AI-assisted.
Two bugs from kevincommits' finding in #1608 (item 2):
- module_name() and module_name_w() stripped the directory and then
added ".dll" when no '.' was left, so "" and a path ending in a slash
came out as ".dll". That passed every `dll.empty()` guard and went to
the bundled loader's lookups as a module name. Both now return an
empty name there.
- host_module_name() caches HMODULE -> module name for GetProcAddress on
host modules, and free_library() never removed the entry. A DLL loaded
later at the same base was then served the freed module's shims.
free_library() now erases the entry when FreeLibrary succeeds; a module
that is still loaded is looked up again on the next call.
New test library_loader_names: a fake bundled loader records the names
it is asked for, and a fixture DLL with no relocations at a fixed base is
loaded as wsock32.dll (a shimmed host module), freed, and loaded again
under a plain name at the same base. Both checks fail on main.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After the merge the tree held this branch's older states of files main maintains. Run against main's code,
tests/test_acphal_abi.py and 11 of the 15 translator tests that differed failed, and the C++ runtime would have
been built from two generations of its sources. So that the merge cannot break what main builds and tests:
- runtime/ is main's, file for file (68 files only this branch had are not carried over);
- every file under tools/, tests/ and docs/ that both sides have is main's (80 files);
- ten translator tests only this branch has, which test rules main's translator does not have, and their
fixtures are left out.
What main gains: d3d12/ (the Rust D3D12 runtime), its launchers and helpers (Launcher.bat, scripts/play*.ps1,
play-linux.sh, port_ctl.py, smooth-motion.ps1, fetch_vkd3d_proton.py, sync_victory.py), mods/example_lua, eleven
notes under docs/, seven tools and the tests that pass with main's code, the README's sections and credits, and
the "Runtime traps" section of AGENTS.md. Everything left out here is on the branch port/d3d12-nvidia.
Checked: compileall; make_game.py --help; check_no_game_data.py over every file this adds to main; the
line-ending, docs-encoding, CI-registration and docs tests; each test file that differs from main, on its own.
Not run: the whole translator suite, the C++ build, cargo over d3d12/ after the merge (d3d12/ is byte for byte the
branch's), CI.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Brings the D3D12 runtime branch (d3d12/, its launcher scripts and notes, and the pull requests reviewed and applied
on it) together with mandy's main.
Conflicts (67 files, none under d3d12/): docs/, make_game.py, runtime/, scripts/build_runtime.ps1, tests/ and
tools/. Every one takes main's side: main is where that code is maintained, and this branch's copies were older
states of the same files or the same pull requests in another form. tests/test_fspx_unpack.py is main's too, as it
tests main's tools/fspx_unpack.py. Nothing under d3d12/ is changed by the merge.
Checked before pushing: python -m compileall over make_game.py, tools and tests; make_game.py --help;
scripts/check_no_game_data.py over the files this adds to main; tests/test_text_write_line_endings.py. The
translator suite, the C++ runtime build and CI have not run on the result.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Review follow-up for #1564:
- Registration and the cleanup of exit, quick_exit and _cexit hold one recursive lock of the run's own, from before the thread-local callback through the table's drain (and _cexit's stream flush), as the UCRT holds its exit lock: two threads never clean up at once, and a registration from another thread waits for the cleanup. The exiting thread may still register from a handler, _cexit still returns, and the lock is released before the run ends (end_run), also when a handler ends the run from inside a drain.
- Each guest cleanup callback (atexit, at_quick_exit, the thread-local destructor callback) runs inside a C++ exception boundary: one that throws ends the run through game_abort, as the UCRT's terminate() would (exit code 3), instead of leaving the process with 0xE06D7363.
tiny_atexit gains four modes, held to the native sequence: concurrent_cexit (a second thread's _cexit, with a thread_local of its own, waits for the cleanup), quick_exit_register (an at_quick_exit from a second thread during a quick_exit drain waits, so its handler never runs), quick_exit_throw and exit_throw (exit code 3). In the concurrent modes the slow handler waits until the second thread is about to call, so the sequence is fixed under any scheduling with the lock. All four fail on c5b51e9 through --run.
The game's at_quick_exit() (_crt_at_quick_exit) and _register_thread_local_exe_atexit_callback still
reached the host CRT, which the game shares with gta6rt. Under `gta6rt --run`:
- quick_exit() ran none of the game's at_quick_exit handlers;
- exit() and _cexit() never ran the exiting thread's thread_local destructors, and a second
registration in the host's one-slot callback would terminate gta6rt.
Now _crt_at_quick_exit goes to a second table of the run's own, which quick_exit() runs newest first
under the exit lock; _exit() and _Exit() run none (they no longer share game_quick_exit). The thread-local
callback is the run's own: exit() and _cexit() call it with DLL_PROCESS_DETACH before the atexit handlers,
as the UCRT does, and a second registration aborts, as the UCRT's terminate() does. Both reset per run.
tiny_atexit gains five modes (at_quick_exit, at_quick_exit_exit, at_quick_exit__exit, thread_local_exit,
thread_local_cexit). Their expected sequences in check_atexit.cmake were measured by running the fixture
natively on Windows 11; before this change --run differed on at_quick_exit, thread_local_exit and
thread_local_cexit. run_tiny_atexit now holds 13 paths to the Windows sequence.
#2315 kept `_register_thread_local_exe_atexit_callback` away from the host UCRT, which fast-fails a second
registration in the process (gta6rt's own startup makes the first). Review points fixed on top:
- The callback is a `_tls_callback_type` (UCRT process.h: `void (__stdcall*)(void*, unsigned long, void*)`), not
`void (*)()`: vcruntime's TLS destructor callback reads its reason argument, which was left as whatever rdx held.
It is now called as `(nullptr, DLL_PROCESS_DETACH, nullptr)`, as the UCRT does.
- `exit` and `_cexit` call it before the atexit table, as the UCRT does: the leaving thread's thread_local objects end
before the static ones ([basic.start.term]). #2315 ran it after the static destructors, and not in `_cexit`.
- The extra call on every thread detach is dropped, with the per-thread flag and the loader's include of the process
shim: the loader already calls the same function from the executable's TLS directory with DLL_THREAD_DETACH, and
the UCRT never calls the registered one there. The call after a returning entry point is dropped too (MSVC's
mainCRTStartup calls exit itself).
- run_tiny_atexit gains thread_local_exit and thread_local_cexit: a thread_local object of the main thread must end
before the handlers and destructors. On main the --run path never ends it (Wine) or stops at the second
registration (Windows).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ported from VIctory (GPL-3.0-or-later, Marvisak and contributors, DexNom fork):
host.rs (window, caption thread, title_window), queue.rs PresentX, frame.rs,
dxgi.rs (display mode), capture.rs (request file, PNG), victory-hle
lifecycle.rs (CreateWindowExA fit and close), and upstream native_1440p.rs.
- shims/xbox_window: D3D12XboxCreateDevice on the Vulkan device attaches a
present handler for console-layout devices. At the first PresentX (queue
slot 32) it takes the title's own window (or opens one on a pumping
thread, fitted to the work area), makes the swapchain on the presenting
queue's VkQueue and forwards to XboxPresentation. The caption reads
"Leonida | <fps> fps <ms> ms/frame", set once a second by its own thread.
- shims/title_window: the title's CreateWindowExA/W (ext-ms-win-rtcore-
ntuser-window-*), shrunk to the screen; Close ends the run, Alt/F10 do not
enter menu mode.
- XboxPresentation::use_device_frame_clock: tokens come from the device's
slots 78-81 (VIctory's clock); presents do not wait for a vblank.
- shims/xbox_display: the console DXGI adapter/output; output slot 21 lists
LEONIDA_DISPLAY_MODE. src/display_profile.h patches the executable's SDR
mode, scanout reservation, scene scale and Settings viewport for
LEONIDA_DISPLAY_MODE=2560x1440 (LEONIDA_RENDER_SCALE): measured 2560x1440
window and back buffers instead of 3840x2160.
- VulkanPresenter::request_snapshot: the next presented frame copied in its
own command buffer; LEONIDA_CAPTURE_DIR + request file writes it as PNG
(src/png_write.h) on a thread of its own.
- Tests: run_tiny_present(_title_window) (stand-in title through gta6rt
--run, screenshot pixels checked) and present_window_parts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gta6rt --first-run-ui defaulted LEONIDA_KEYBOARD_PAD to always, so keys
typed into another program reached the title's consent pages (#1552,
hazard 1). Default to the focused mode 1; scripted presses still run
while the window is unfocused. tiny_game checks the default under
run_tiny_first_run_ui, which now clears the caller's setting.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The base is 8a242efeb, the merge of main and #984. 68 files conflicted; they were resolved in seven groups by
one rule: the same change in two forms keeps the base's form, everything only #939 has is kept, and where the
two solve one problem in two ways the base's is the frame and #939's plugs into it.
A, the Xbox proxy (d3d12_xs_device.cpp/.h, d3d12_xs.cpp, d3d12_xs_pso_stream.cpp/.h, d3d12_xs_alloc_size.h,
d3d12_xs_desc_clean.h, device_proxy_test.cpp, queue_proxy_test.cpp): the base's files with #939's additions
ported in. Device slot 57 asks #939's NativeGraphicsFactory first and falls back to the base's
proxy_create_graphics_pipeline_from_native_code on E_NOTIMPL. Kept from #939: the providers (texture lease,
raw texture view, resource by address, constant view, descriptor mapping, depth-stencil UAV, texture pages),
the title-backed descriptor mirror, slot 13's feature answers, GPU labels on list slots 71/72. Dropped: #939's
duplicates of the boot ladder routes, its fallback window, its slot 133 stand-in.
A2 (xs_proxy_mock_test.cpp): the base's test with #939's slot 70 raw-buffer case; presentation cases follow
#939's rule that a device which ever had a handler has no queue fallback.
B1, the Vulkan device (d3d12_vulkan_device.cpp, d3d12_com.cpp/.h, shader_library.h, queue_families.h,
pipeline_cache_file.h, startup_trace.h): one lazy-pipeline mechanism, the base's; #939's pending_base_compile
and first_use_backend_pipelines dropped, prepare_on_bind and cold_graphics_compile kept. create_texture keeps
the base's signature; #939's deferred backing is folded into the base's placed-memory binder. #939's quad
lists as triangle indices.
B2, the D3D12 tests (d3d12_existing_heap, a8_dimensions, pipeline_cache_seed, title_va, rect_list,
shader_library, loader_tls_index0, draw, compute, xmem_placed, shader_library_corpus): the base's tests where
both carry the same case, #939's cases added (rebound tables, linear texture map, large vertex batch,
executable shaders, default A8 views).
C, the backend (vulkan_replay.h, vulkan_backend.h, vulkan_bindless.h, vulkan_scratch.h, vulkan_present.h,
rect_list_geometry.h, vk_test_device.h, vk_pipeline_check.cpp, vk_store_test.cpp, bindless_sizing_test.cpp,
replay_texture_barrier_test.cpp): the base's prepare_draw and lazy compute, its #1055 release rule and its
rectangle generator; #939's rectangle variants, GPU quad index expansion, 1D/3D and depth-stencil UAVs, the
label fence on the base's submit.
D, memory, services, presentation (xmem.cpp/.h, xg_xs.cpp, xg_xs_test.cpp, title_va_alias.h and its test,
main.cpp, frame_pacer.h, xbox_present.cpp/.h; xgameruntime_offline.cpp for one comment): the base's xmem with
#939's label hooks, file-backed sections and pin_mapped_data; both texture computers in xg_xs.cpp, the base's
answering first; --first-run-ui kept without host speech in its profile.
E, build, tools, docs (runtime/CMakeLists.txt, make_game.py, tools/rdna2spirv.py, tools/shader_disasm.py,
scripts, tests, docs; docs/README.md and tests/test_exe_shaders_stage.py beyond the conflicts): the base's
v_dot4 decode, #281's disassembler form and tests/semantic/test_fspx_dot4_op_sel_disasm.py dropped; the
base's executable-shader step with #939's cache fix; 366 registered tests.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Merges main at 1154976d4 into the integration branch at 273b3bdf9 (merge base ece4ba5b3). 42 files conflicted;
this commit is the resolution only. Build and test repairs follow in their own commits.
Rule of resolution: where both sides added different things, both stay; where both made the same change in two
forms, main's reviewed form stays and whatever #984's form did in addition is carried into it; where the two
changed the same code for different purposes, both purposes are kept.
Xbox proxy code (runtime/shims/d3d12_xs_device.cpp, d3d12_xs_device.h, d3d12_xs.cpp, d3d12_xs_alloc_size.h,
d3d12_xs_desc_clean.h, registry.cpp):
- d3d12_xs_device.cpp is #984's file with main's differing pieces ported in: env_slot and the configurable device
routes, XboxQueueSlotRoutes, PresentationHandler / set_presentation_handler, the console caller rule for device
slots 61 and 74 (#383, #385), route_xbox_device_slot, slot 81 as GetFrameStatisticsX, create_host_device, the
console-form rule for slots 25 and 56, the console list IID of #359, and the forms of queue slot 18 (#403) and
list slot 139 (#396).
- Kept from #984: the list proxy with handle translation, queue slots 16/17 as Signal/Wait, the fence's
completed-value mirror, the shared FrameTokenSource, PresentX through queue_present_x when no handler is
attached (slot 30, or 32 on a queue detected as the newer layout), slots 27/53/55/57/70/71/133, the wider
pc_resource_desc, S_OK for queue slots past the PC table.
- Dropped: #984's GetFrameEventsX and LEONIDA_XS_FRAME_EVENTS_SLOT, its second-word rule for slot 61, its
undetected-layout rule for queue slot 18, its list IID mapping to GraphicsCommandList6; main's copy of the base
list proxy, its null-view slot 70 and its refusing slot 133.
Proxy tests (runtime/test/xs_proxy_mock_test.cpp, device_proxy_test.cpp, queue_proxy_test.cpp):
- Checks of both sides, each run once; main's forms of the render-target size and layout checks with #984's extra
cases added; main's --env-slots-74 and #984's --env-slots-70.
- Adapted to the merged code: the queue tail answers S_OK, slot 73 answers an unknown IID with the list proxy,
the queue slot 18 case installs a console caller. Dropped: #984's slot 81 GetFrameEventsX cases.
D3D12/Vulkan layer (runtime/shims/d3d12_com.cpp, d3d12_vulkan_device.cpp, runtime/src/command_list.h,
frame_pacer.h, shader_library.h, vulkan_backend.h, vulkan_replay.h, runtime/test/command_list_test.cpp,
d3d12_close_parity_test.cpp, d3d12_execute_indirect_validation_test.cpp, replay_texture_barrier_test.cpp,
vk_pipeline_check.cpp, vk_test_device.h):
- Resource::create_texture: #984's title images (deferred placed, pending streamed, title pool) and main's
ordinary textures (#1413 shared blocks, #1364 staging fallback) are exclusive branches chosen by the texture's
origin, so both pools run on disjoint sets of textures.
- frame_pacer.h is main's pacer (#402) with #984's FrameTokenSource as the token counter.
- main's forms kept for ExecuteIndirect (#1066, #377), the barrier into LAYOUT_UNDEFINED (#1055), the B4G4R4A4
stand-in, per-face stencil masks, the unaligned tile staging (#528) and the device-lost flag (#980).
- shader_library.h: main's block inflate; #984's `bulk` parameter now defaults to true so main's callers keep it.
- Dropped: #984's B8G8R8A8 stand-in for B4G4R4A4 targets, its refusal of separate stencil masks, its zero-count
refusal in ExecuteIndirect, its wider UNDEFINED -> UNDEFINED release and the test case for it.
Other shims (runtime/shims/dstorage.cpp, file_system.cpp, gameinput.cpp, xgameruntime_offline.cpp,
runtime/test/xgameruntime_offline_test.cpp, xmem_test.cpp):
- ReadFile and DirectStorage reads: #984's pinned kernel_writes read, then main's touch_pages retry on
ERROR_NOACCESS. main's rt::fs::read_file is folded into #984's read_file.
- gameinput: main's strict LEONIDA_INPUT_SCRIPT parser with #984's rsup/rsdown entries.
- Speech synthesis: main's one silent voice and handle checks; #984's accept-anything form dropped.
Build, tools, docs (runtime/CMakeLists.txt, runtime/cmake/translator_deps.cmake, scripts/build_runtime.ps1,
make_game.py, tools/rdna2spirv.py, shader_disasm.py, shader_ir.py, shader_library.py,
runtime/test/shaders/cs_imgload_tfe.asm, cs_imgload_d16_tfe.asm, docs/README.md, boot.md, d3d12_vulkan.md,
runtime/README.md):
- Unions of the test, target and source lists; spirv_loop_guard.py added to translator_deps.cmake.
- rdna2spirv.py: main's DPP compare rule (#957), SMEM vcc base (#647) and widen_wave64_masks (#1021); #984's
restore_skipped_instructions and restore_dot4_inline_sel. #984's duplicate widen_wave64_valu_masks dropped.
- shader_disasm.py and shader_ir.py: main's structure with #984's one-line-per-dword llvm-mc input and wave flags.
- shader_library.py: main's structure with #984's --compute-hashes and per-state compute variants.
One file that did not conflict is changed here: tools/rdna2_decode.py. Git kept both sides' decoders for a VOPC
compare with a DPP operand, and #984's narrower one shadowed main's; it is main's file again.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
One squashed commit of a fork that was developed on a Linux/Proton machine and
tested on two native Windows machines. On all of them the retail 1.0.2.1
package now launches, shows its launch movie, first-run pages and landing
prompt, runs the story load to its end with the loading slideshow drawing its
artwork, and enters the world phase. A first world frame is not verified yet.
docs/linux_proton.md has the setup, a healthy boot's timeline, the machines
and where it stops.
Runtime: frames in the title's own window; DirectStorage pinned reads,
page-list scatter/gather, BCPack and unshuffle with a locally generated
predictor file; pooled, device-local and deferred image backing for streamed
and placed textures; enhanced barriers into LAYOUT_UNDEFINED; a bindless table
that degrades instead of refusing a submission; a descriptor hash finalizer
(off until a library carries it); directly indexed heap offsets for compute
dispatches and VS/PS/GS draws; title buffer windows outside a fragmented
arena; opt-in device-local copies of streamed buffer views; write-fault
retries under the tracker lock, shared trackers and write-watched title memory
for native Windows; device-loss, compute-input and memory probes.
Translator: loop bounds at structured exits, the eight FidelityFX programs
that use a packed-dot form the disassembler skips, buffer bounds modes per
view kind, a compaction option, the hash finalizer option.
Tools and scripts: Linux boot scripts (Wine/Proton, no network), a Windows
boot script, the paired compute translation script.
No game data. AI-assisted (Claude Code and Codex agents), reviewed and booted
by people on the machines named in docs/linux_proton.md.
Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
loader_tls checks the /GA rewrite inside a test EXE that links pe_loader.cpp. The stop BL-1 describes is in
gta6rt itself: there module TLS index 0 holds gta6rt.exe's own TLS, which the runtime uses on every thread,
and the title's entry point runs on a thread gta6rt starts. Nothing ran a /GA image through that path.
tiny_game_ga is tiny_game.cpp built with /GA (and /INCLUDE:_tls_used, as tiny_ga_tls has, because /GA can
drop the last _tls_index reference). run_tiny_game_ga_tls runs its `tls` mode through gta6rt --run:
thread_local on the entry thread and on a thread the game starts.
It passes on main as it is; no loader change. With LEONIDA_TLS_GA_PATCH=0 the same run fails its thread_local
check and exits 1, while the non-/GA tiny_game still passes with the rewrite off, so the test separates the
two shapes. That run writes into gta6rt's own TLS, so it is not registered as a test.
Tested on Windows 11, MSVC 19.44 (VS 2022 Build Tools), Ninja, RelWithDebInfo, NVIDIA RTX 4070 SUPER driver
621.24: run_tiny_game_ga_tls passes, 30 runs in a row; ctest -R run_tiny_game 11 of 11; full ctest 305 of
307, the two failures main has (d3d12_execute_indirect_validation, d3d12_depth_resolve), and the per-test
results differ from main's only by the new test. tests/test_ctest_registration.py passes. Not run on the
retail executable: that needs game files.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
BL-1 (docs/boot_leads.md) says code built with /GA reads its TLS at module index 0 and that main stops there.
main already carries a fix (b7a3fed28 and 4710549af: load() rewrites the executable's gs:[58h] reads to a
per-thread view with the image's block at [0]), but no test maps a /GA executable and a second TLS module at
the same time, and no test shows that the fixture's code really has the index-0 shape: the CRT objects linked
into it read gs:[58h] through _tls_index, so "some reads were rewritten" holds for a non-/GA build too.
tiny_ga_tls gets ga_tls_address(), which returns where its code looks for its variable without touching it.
The new case uses it three ways. With LEONIDA_TLS_GA_PATCH=0 the address lies in this test EXE's own block at
index 0: the stop-4 shape, shown without reading or writing another module's TLS. By default it lies in the
fixture's own block, on the loading thread and on a thread started after load(), while tiny_tls.dll mapped
beside it keeps a block at its own index, gets its thread attach and detach, and this EXE's block and value
stay at index 0 of each thread's real TLS array. ~Loader takes the view out again.
No loader change: the case passes on main as it is, which is the finding. pe_loader.cpp and tls_host.cpp are
untouched.
Tested on Windows 11, MSVC 19.44 (VS 2022 Build Tools), Ninja, RelWithDebInfo, at main 8f05e09e2:
loader_tls_test OK (118 checks, 95 before), 40 runs in a row; with LEONIDA_TLS_GA_PATCH=0 set for the whole
process, 8 checks fail, as they should (7 existing ones and "by default load() rewrites the EXE's index-0
TLS reads"). MSVC emits the index-0 read for ga_tls_address at /Od and at /O2 (checked in the listing). Full
ctest: 304 of 306, the same two failures as main (d3d12_execute_indirect_validation, d3d12_depth_resolve).
Not run on the retail executable: that needs game files.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
Keep completion batches with their owning Vulkan context. Test switching primitives, caller overrides, and the dynamic EXEC and uniform null-descriptor guards used for dimension-specific storage views.
The stack is ladder-frame (ASTROWwwW's integration of the retail boot pull requests) with the old pull requests
7604, 7286, 7584, 6446, 8591, 7384, 7535, 7448, 9137 and 9419 and local fixes on top. main carries many of those
commits as ancestors without their content, so the merge was made against main's tree, not its history: nothing
main dropped is dropped again here.
Resolved by hand:
- d3d12_xs_device.cpp and frame_pacer.h: the stack's Xbox-ABI layer, plus main's uncapped pacer and its two new
registration hooks (set_placed_at_va_pages_hook is called before slot 133's handler; the console descriptor
heap handler is stored but slot 14 still uses the title-backed heaps of old PR 7021).
- xmem.cpp, xmem_test.cpp: the stack's run-mapped physical pages. main's commit-on-touch xmem with the two
view-protection fixes it lost (7e8e3c1db, 954fcb106) boots to 50,468 pipelines and then fails a submit with an
unknown resource, so it is not used here yet.
- acphal.cpp, acphal_test.cpp, vulkan_replay.h (acceleration structure copy), README: main's.
- CMakeLists.txt, build_runtime.ps1, d3d12_com.cpp, d3d12_vulkan_device.cpp, shader_library.h, docs: both sides.
Measured (Linux, Wine 11.21 staging, RTX 5070 Ti, driver 615.78.08, clang-cl 22.1.8 + xwin, own 1.0.2.1 copy,
network off, LEONIDA_GRAPHICS_STAGE_LAYOUT=1, 300 s): 50,470 pipeline states created, 197,998 ExecuteCommandLists
with none failed, 148,467 DrawInstanced, 99,008 PresentX.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt
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>
libHttpClient.GDK.dll and XCurl.dll reach the GDK runtime through
xgameruntime.lib's thunks: LoadLibraryW("xgameruntime.dll"), then
GetProcAddress of InitializeApiImpl, InitializeApiImplEx,
InitializeApiImplEx2, QueryApiImpl, UninitializeApiImpl and XErrorReport.
The shims served only the first five. Without XErrorReport the thunks
refuse the runtime before they call any initializer: under gta6rt --run,
HCInitialize returned 0x89240101 (E_GAMERUNTIME_DLL_NOT_FOUND) and
curl_global_init returned CURLE_FAILED_INIT.
XErrorReport is now served by the function behind IXErrorImpl slot 3, so
a report reaches the XErrorSetCallback callback either way.
xgameruntime_test and the tiny_gdk_load fixture check all six names and
that a report through the export reaches the callback.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Squash-merged after review of PR #5468 - gta6rt: link with an 8 MB stack; a game thread with the default size had 1 MB for a driver's compiler (RT-400)
A GDK title opens its save provider at boot; QueryApiImpl now serves
XGameSaveImpl (IXGameSaveImpl..3, 33 slots from xgameruntime-docs' layout,
signatures and error codes from the public GDK reference). Saves are files
in LEONIDA_SAVE_DIR\local-user\<container>\<blob> (default
%LOCALAPPDATA%\Leonida\saves), %-encoded: the layout tools/saves.py import
already writes. Updates are buffered and committed by write-then-rename;
container names follow the documented rule; the 16 MB update limit, the
documented E_GS_* codes, async variants through XAsync, and the
XGameSaveFiles folder/quota slots. Assumptions (quota, blob-name length,
nullptr blob list) are marked in the source and docs.
xgameruntime_gamesave_test drives every slot (50 checks). The two tests that
used XGameSaveImpl's id as "a class not served" now use a made-up id.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From the second review of 89cec3b8:
- The first load_tls_host_clone call is now the home clone, from .CRT$XCT,
and it registered cleanup_tls_clones_at_exit with atexit before
g_tls_clones was dynamically initialized in .CRT$XCU. The vector's
destructor then ran first and the cleanup walked a destroyed vector, so
--dry-run, --init and every return-1 path left the slot clones'
leonida_tls_host_<pid>_<slot>.dll files in %TEMP%. g_tls_clones is now
allocated with the first record and never destroyed, and the atexit
handler is registered there. The home clone cannot be deleted while it is
mapped (DeleteFileW and a POSIX-semantics delete both fail with
ERROR_ACCESS_DENIED), so it is left for the next run's sweep, as the
README says.
- process_alive() took an ended process as alive while another process
still held a handle to it (CMake's execute_process does), so the next
run's sweep skipped its files; it now reads the exit code.
- reserve_tls_index0 catches what reserve_index0 throws (for example
std::filesystem::temp_directory_path) and stores it as the reason, so the
reservation fails before main with a message instead of ending gta6rt.
The owner's file name is taken before the move, so nothing can throw
between the move and recording it.
- Tests: run_tiny_tls_clone_cleanup runs gta6rt --dry-run, --init and
--dry-run on tiny_tls_clones.exe (three TLS modules, so one slot clone)
and checks that each run's PID leaves no clone file but its home clone and
that the next run deletes that one; it fails with the old cleanup.
run_tiny_tls_ga also runs with TMP and TEMP naming a missing folder: the
reservation fails, --run and --init refuse the image with the reason and
run none of it, --dry-run maps it with the note.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes from the review of the index-0 change:
- The lazy move at the first executable map stopped other threads and swapped
their slots, guarded by a "thread is inside gta6rt.exe" check. That is not
enough: MSVC keeps &ThreadLocalStoragePointer[_tls_index] across calls
(zlib_inflate saves it at [rbp-80h] across memset, push_back and
inflate_codes, then reads _Init_thread_epoch through it), so a thread
stopped in the heap or memset still reads the wrong slot afterwards. The
move is now rt::reserve_tls_index0(), done once at process start: gta6rt
calls it from a .CRT$XCT initializer, before its own static initializers
and before any of its threads; the CRT startup frames above it hold no TLS
slot address (checked in the disassembly). It swaps slots 0 and home on the
calling thread only; no thread enumeration, suspension, TEB writes or
TlsAlloc mark are left.
- The home clone's block was the helper's 514 bytes, smaller than
gta6rt.exe's 1398-byte TLS. The home clone is now written from
gta6rt_tls_host.dll with its TLS directory pointed at a new 16 KiB export,
gta6rt_tls_home_template, filled with a copy of the EXE's template and its
alignment (LdrpAllocateTls copies End - Start and ignores SizeOfZeroFill,
so the zero fill is part of the range). Every new thread then has a fresh
copy of gta6rt.exe's TLS at the home index from its first instruction, so
no adoption step or window before the helper's DLL_THREAD_ATTACH is left.
The mapped template is checked against the EXE's after the load.
- The owner is GetModuleHandleW(nullptr) with _tls_index 0, not any module
whose index reads 0.
- A primary helper without gta6rt_tls_host_set_thread_event is refused.
- An executable that does not get index 0 (no reservation, or another
executable holds it) is refused by --run and --init with an error; its /GA
code would read and write another module's TLS through slot 0. The README
no longer says it "reads the first one's slot 0".
- Thread attach installs every module's copy before any TLS callback runs,
as Windows allocates all blocks before the first DllMain.
- Tests: loader_tls_index0 (runs) checks this EXE's block moving from slot 0
to the home index by identity, the home template's size and content, and
that the getter reads slot 0 with its _tls_index pointing elsewhere (fails
for a non-/GA build of the fixture); loader_tls_index0_threads reserves
while threads are being created, with one suspended thread that has no TLS
array yet and tiny_thread_hook.dll running test code before the helper's
DLL_THREAD_ATTACH; loader_tls_index0_noreserve maps without the
reservation. The tiny_tls_ga.cpp comment names the real test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Windows gives the process executable module TLS index 0, and MSVC code built
with /GA reads TEB->ThreadLocalStoragePointer[0] without loading _tls_index.
The loader gave a mapped EXE a gta6rt_tls_host.dll clone's index instead, so a
thread_local int v = 42 EXE built /O2 /GA /MD printed tls_index=6 value=0
under gta6rt --run (natively tls_index=0 value=42).
Index 0 belongs to gta6rt.exe itself (and to each test EXE that links
pe_loader.cpp): measured through _tls_index == 0 before any mapping and the
new tls_index0 trace event. All of its own TLS reads go through _tls_index,
so the first time an executable is mapped the loader loads one more helper
clone (leonida_tls_host_<pid>_home.dll), stops the other threads, swaps
slots 0 and the clone's index on every thread and writes that index into the
owner's _tls_index. Threads started later swap their own slots first thing
in the helper's DLL_THREAD_ATTACH. Both pointers are OS-allocated blocks of
that thread and the OS frees every slot at thread exit, so the swap is
permanent and nothing is restored. The executable then takes slot 0
(kMainImageSlot) through the existing per-thread install, thread events and
~Loader paths; DLLs keep the helper indices. A second executable mapped
while one is live, or a move that cannot be made (a thread kept running in
the owner's code for 250 ms), gets a helper index and a stderr note.
Measured on Windows 11 26300 to make the swap safe: a new thread publishes
its TLS array in the TEB only once it is filled (LdrpAllocateTls), an ending
one clears it before freeing the blocks (LdrpFreeTls), LoadLibrary of a TLS
DLL updates other threads in one NtSetInformationProcess call, and an EXE's
TLS callbacks run after every DllMain for thread attach and detach.
Tests: loader_tls_index0 maps tiny_tls_ga.exe (built /GA, code shape
checked) next to tiny_tls.dll: 42 on the loading thread, a pre-existing
thread and new threads, this EXE's own TLS intact on all of them, two runs
in a row, a second executable at once, and a busy thread holding the move
off. run_tiny_tls_ga runs it under gta6rt --run and --init and checks the
trace names gta6rt.exe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
game_abort() ended the run directly, so a title's own SIGABRT handler never ran. Raise SIGABRT only when a handler is registered (the guest's signal() import binds to the host CRT), leaving the default and ignored cases ending with code 3 so the host is never killed. Add a synthetic fixture with handler, returning-handler, ignore and default modes plus a native-vs-loader exit-code test.
AI-assisted (OpenCode)
dll_thread_calls and tiny_tls_cb_only link with /NODEFAULTLIB, but the Visual Studio generator's Debug config compiles with /RTC1,
whose checks reference _RTC_InitBase and _RTC_Shutdown: LNK1120 in Debug. Both fixtures define the two as no-ops when
__MSVC_RUNTIME_CHECKS is set. Release and RelWithDebInfo are unchanged.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- gameinput_host_test decides the skip before mapping: LoadLibraryExW of GameInput.dll from System32. Only "not found"
skips (77); an import that then binds to nothing is a failure. Breaking host ordinal binding in Loader::resolve now
fails the test (4 failures) instead of skipping.
- The gameinput_host fixture links in Debug: /RTC1 with /NODEFAULTLIB left _RTC_InitBase, _RTC_Shutdown and
_RTC_CheckStackVars unresolved, so the fixture defines them as no-ops when runtime checks are on.
- The fixture reports E_FAIL, not S_OK, when GameInputCreate fails, and the test counts a gamepad as attached only when
the library was created.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
IXGameImpl3 : IXGameImpl2 : IXGameImpl (xgameruntime include/xgame.idl), slots
3-5: XGameGetXboxTitleId gives MicrosoftGame.Config's <TitleId> (E_FAIL without
one, E_INVALIDARG for a null pointer), void XLaunchNewGame is logged and
returns, XLaunchRestartOnCrash succeeds with nothing registered. A retail Gen9
title asks QueryApiImpl for this class (Freminet/ScarlettX's observation).
The config reader is shared with XPackageGetUserLocale. The two tests that used
XGameImpl's id as their example of an unserved class now use XGameSaveImpl's.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tiny_frame imports d3d12_xs.dll!D3D12XboxCreateDevice from a link-time stub
and does the least a title does before its first frame: queue, allocator,
list, fence, an RTV heap with its start handle read in the console shape, a
committed target, a clear, a copy to a readback buffer, a fence wait, and a
check of every pixel. It returns from main with the device still alive.
run_tiny_frame runs it under gta6rt --run --trace-d3d12 with
LEONIDA_D3D12=vulkan; check_tiny_frame.py checks the verdict, the shim
binding and the call order, and exits 77 when d3d12_com_test, its probe,
finds no usable Vulkan device. tests/test_check_tiny_frame.py covers the
checker on synthetic output.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The mapped EXE registered atexit handlers and static destructors with the
host CRT's process-wide table, which gta6rt never runs, so they were lost.
They now go to a table of the run's own: exit() and a return from main run
it newest first (including handlers registered during exit), _cexit() runs
it and returns, and _exit/_Exit/quick_exit/ExitProcess/abort skip it, as
natively. exit/_exit/_Exit/quick_exit share an exit lock like the CRT's,
each run starts with an empty table, and a failed registration returns an
error instead of throwing into the game.
New run_tiny_atexit compares a stand-in program run natively and through
--run for 8 termination paths. Not covered yet: at_quick_exit and the
thread_local destructor callback.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/gameinput.md says that without the SDL3 shim the loader binds
GameInputCreate to the host's GameInput.dll, but nothing tested it.
gameinput_host_test maps a CRT-free fixture DLL built against the SDK's
gameinput.lib and checks that the import binds to the host copy (the test links
no shim table), that GameInputCreate and GetCurrentTimestamp work from mapped
code, that GetCurrentReading answers, and, with a pad attached, that
GetGamepadState succeeds. It skips (77) where there is no GameInput.dll, and is
only built when gameinput.lib is found.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>