After map_image, the loader writes into the mapped image twice: the bound
address of every import and the image's TLS index. Every step after it
(parse_exports, bind_imports, protect_sections, register_unwind,
initialise, ~Loader) reads the headers back from the mapping. A
FirstThunk or AddressOfIndex below SizeOfHeaders therefore replaced
e_lfanew or the section table, and the next read went outside the image
or used headers nobody validated. The loader already refuses a section
or a base relocation there; this closes the two remaining writes.
An index at RVA 0 is refused too: index_rva doubles as "no index", so the
index was silently never written.
Found by mutation fuzzing rt::Loader::load. The six new cases in
test_pe_loader_bounds build their images by hand; four of them fail
without this change.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
resolve_compat() calls LoadLibraryExW on a file from LEONIDA_COMPAT_DIR. For
a file Windows cannot map (truncated, wrong machine, not a PE image) the
system raises a modal "Bad Image" hard-error box, and LoadLibraryExW does
not return until someone clicks OK. The loader reports that failure itself
one line later, so the box only stalls it: gta6rt hangs on a headless
machine, and loader_test, which writes such a file on purpose, waits for a
click in every unattended ctest run.
The load now runs with SEM_FAILCRITICALERRORS set on the calling thread, and
the thread's previous error mode is restored afterwards. The Windows error
code is read before the mode is put back.
loader_test checks that the mode comes back unchanged, that the message
still carries the error code, and that the refusal does not wait on a box.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The merge that brought the mirrored pull requests into main (6dece9231) left the DirectStorage shim out, noting
that it "needs the typed-error zlib inflate". The shim's commits (f87d05fdd, ac1843da2, 00551ba00, by
mariuslozo-boop and Kelebek) are ancestors of main, but its files are not in the tree, so the retail
executable's XCRDAPI.dll!DStorageGetFactory import is unimplemented (issue #47, stop 5 of
docs/retail_boot_chain.md).
- shims/dstorage.cpp, shims/dstorage_xs_abi.h, test/dstorage_test.cpp and docs/directstorage.md are back as
those commits left them.
- leonida::zlib_inflate reports why it failed through an optional ZlibError* (header, data, checksum, limit),
which the shim turns into its E_DSTORAGE_ZLIB_* codes. This is the same interface the shim was written
against, added to main's current table-driven inflater; callers that pass no pointer behave as before.
- registry.cpp classes xcrdapi.dll!DStorageGetFactory as an HRESULT import, the retail spelling #47 found
missing.
- CMake and scripts/build_runtime.ps1 build the shim into gta6rt, and CMake builds and registers dstorage_test.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt
ShaderLibrary::load read the main index plus fspx/ and bvh/, but not library/index.json, where the pipeline library's compute programs are translated. Slot-67 FSPX lookups therefore found no entry for those programs even when the index existed.
Read library/index.json as an optional sub-index and count its entries with the FSPX ones. Add regression coverage for fspx/-before-library/ ordering, code/state lookup, and absent or malformed library indexes.
Merged from the TreXito/mangrove copy of the original repository, which carried
contributor pull requests that were never merged here.
Kept: rdna2spirv fixes (ds_append/ds_consume, v_ldexp_f16 under MODE.FP_ROUND,
thread-group SGPR, fma exact), the differential fuzzers (dot, vint, wint, vrel, cvt,
f16misc, salu, mode) with their tests, the exe/import fail-fast and int3 cause tools,
Zen 2 instruction emulation (cpu_emulation.h) and the xapu.dll/chad.dll shims.
Not taken, because they conflict with different implementations already on main:
the D3D12 Xbox-ABI layer, xmem, acphal, loader TLS, f64_diff, DirectStorage (needs the
typed-error zlib inflate), and the copy's own MANGROVE.md and README changes.
Fixes four bugs in --f16-interp-fallback per-pipeline linking:
1. link_f16_halves() no longer skips patching on its fast path when static
VS/PS half locations exceed top_location or when an unused VS static half
collides with a raw PS input location.
2. Demoting an unused VS static half Output variable to Private now strips
all interface-only decorations (NoPerspective, Flat, Patch, Centroid,
Sample, Invariant, Location, Component), avoiding invalid SPIR-V.
3. keep_ps_locs now preserves raw PS input locations (ps_raw_locs) when
picking relocation slots.
4. CreateGraphicsPipelineState now runs link_f16_halves() when only VS
declares f16_halves and derives top_location from the physical device's
min(maxVertexOutputComponents, maxFragmentInputComponents) instead of
hardcoding 29.
Adds regression tests (cases 6-10) and interface-only decoration validation
in runtime/test/spirv_f16_halves_test.cpp.
AI-assisted (Antigravity).
The game runs AVX code from its TLS callbacks on, so a CPU or OS without
AVX (a QEMU qemu64 guest) died with a bare 0xC000001D. Check CPUID.1
AVX/OSXSAVE and XCR0 YMM state first, print one line and exit 4 (3 is
LEONIDA_UNIMPLEMENTED=stop). --dry-run is unchanged and
LEONIDA_SKIP_CPU_CHECK=1 skips the check.
AI-assisted.
xmem commits physical pages on first touch (#7556), so a range the title has
mapped but not written yet is still MEM_RESERVE when it places a buffer on it
through device slot 133, and the Vulkan layer's import (#7218) refuses reserved
pages and answers with its fallback buffer, which the title's writes never reach.
Slot 133 now calls a registered pages hook (set_placed_at_va_pages_hook, next to
set_placed_at_va_handler) with the buffer's range before the handler; gta6rt
registers rt::xmem::commit_physical_range. A failed commit is logged once and the
handler still runs. Textures don't call it. The Vulkan layer doesn't link xmem.
Tests: xs_proxy_mock_test checks the hook order, arguments, failure and texture
cases; the new d3d12_xmem_placed_test places a buffer on untouched xmem physical
pages and checks the fallback without the hook, and with it the import and a GPU
copy reading the CPU's writes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A question that keeps coming back on the boot path is "what is actually on screen", and the window is not a reliable
answer: under Wine it is not mapped at all, and even on Windows a compositor or a capture-blocked surface can hide
the content. The presenter already copies every presented frame into a staging buffer when capture is enabled, so
this adds the disk side: `LEONIDA_CAPTURE=<dir>` writes each captured frame as a binary PPM and appends the extent
and the mean RGB to `<dir>/index.txt`, with `LEONIDA_CAPTURE_EVERY` and `LEONIDA_CAPTURE_LIMIT` bounding the run.
Off unless set, and created with the folder if it is missing. The write happens on the fence that already covers the
copy, so the present path is untouched.
d3d12_present_test turns it on and checks the files against the colour the test clears to: at least half the captured
frames (it resizes and injects failures on purpose, so a frame caught mid-transition is a near miss), and no frame
black. A capture that reads the wrong or a stale buffer fails there instead of in a report months later.
`CommandList::clear_depth_stencil` (`runtime/src/command_list.h`) refused a `ClearDepthStencilView` whose depth was
outside [0, 1] or NaN, and one whose `D3D12_CLEAR_FLAGS` were 0, so `Close` answered `E_INVALIDARG` and the whole
`ExecuteCommandLists` submission was dropped. Windows' D3D12 closes those lists: on WARP a `D32_FLOAT` target keeps
1.5, -0.5 and NaN exactly as given, and a clear that names no plane clears nothing. `d3d12_clear_test` now reads those
back on WARP and on the layer, and `d3d12_close_parity_test` measures the four `Close` verdicts.
A title that clears depth with a computed value (or wraps the clear in a flag mask that can be 0) lost that frame's
depth clear and, with it, the whole submission's work. The call is now recorded with the depth as given (a D16 target
still quantizes at replay) or, with no plane named, recorded as nothing.
d3d12_clear_test adds three read-back comparisons (1.5/-0.5, NaN, flags 0), command_list_test asserts the accepted
calls and the stored values, and the four close-parity rows move from the known-difference table to `match`.
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>
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>