Commit Graph

9 Commits

Author SHA1 Message Date
44ddf9b052 Merge pull request #1600 from thiefyzheng/fix/test-tempdir-stripped-env 2026-11-29 13:44:40 +01:00
b17397f0dd tests: derive every test's scratch folder from test_temp_dir::temp_dir, not GetTempPath (TEST-TEMPDIR-STRIPPED-ENV)
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.
2026-11-28 19:01:06 +00:00
842e0f641c xgameruntime_gamesave_test: Case E runs where the host has no CopyFile2
CopyFile2Trap left itself unarmed when kernel32 exports no CopyFile2,
and Case E then failed on Wine 9, the host this PR is for (timbot103's
review on #2532). A missing export is now told apart from a patch that
failed: with no CopyFile2 there is nothing that could be called, so the
overwrite and rollback checks run against the real host, and only an
export that exists but cannot be patched fails the check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 20:06:01 -06:00
03d17a395e xgameruntime_gamesave: copy blobs with CopyFileW, not CopyFile2
copy_blob() backs up a blob before a commit overwrites it and copies it
back when an update is rolled back. It used std::filesystem::copy_file,
which in MSVC calls CopyFile2. Wine 9 and the Protons built on it do not
implement CopyFile2, and the call aborts the process (kevincommits'
finding in #1608, batch 18 item 1). file_system.cpp already avoids it
for the same reason.

copy_blob() now calls CopyFileW(from, to, FALSE). On Windows it copies
the same way: contents, attributes and last-write time, replacing an
existing file.

xgameruntime_gamesave_test gains a case that patches this process's
CopyFile2 to fail and count calls, as Wine's stub would, then runs an
update that overwrites a blob and one that is rolled back. Its 3 checks
fail with main's copy_blob and pass with the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 19:08:34 -06:00
2bf19e6908 xgameruntime: LEONIDA_TRACE_XGAMESAVE logs every XGameSave call
With LEONIDA_TRACE_XGAMESAVE=1 the offline XGameSaveImpl logs one
"[rt] xgamesave:" line per XGameSave* and XGameSaveFiles* call: the call,
its handles, container and blob names, sizes and HRESULT, with the
milliseconds since the process started and the thread id. An async call
also logs when begin() schedules its job, when the work runs (and how
long it waited on the queue), when it completes and when the title
collects the result, all naming the title's XAsyncBlock. Blob contents
are never logged. Off by default: a call then pays one relaxed load.

xgameruntime_gamesave_test turns it on through a test hook, writes and
reads a blob (sync and async) and checks the lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 04:28:00 +01:00
be829a4d64 xgameruntime_gamesave: accept an XGameSaveReadBlobData buffer of the unpadded size
A title sizes the read buffer as the sum of sizeof(XGameSaveBlob), the data and
the name with its NUL for each blob. The shim required the 8-byte aligned layout
and refused such a buffer with E_GS_PROVIDED_BUFFER_TOO_SMALL. The minimum (and
the async result size) is now the unpadded sum; the blobs are packed aligned
when the buffer has room for that and back to back otherwise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
2026-11-26 16:21:19 +01:00
34e6b29682 xgameruntime_gamesave: undo a partly applied update instead of leaving it (RT-GAMESAVE-COMMIT-ROLLBACK)
commit() replaced blobs one rename at a time. When a later rename failed (the blob held open by another
process without FILE_SHARE_DELETE), the earlier renames stayed, the update returned
E_GS_OUT_OF_LOCAL_STORAGE and the container was left half new, with "<blob>~" temporaries behind.

Each op now copies its blob to "<blob>~b~" before it changes the blob. A failed op undoes the applied ones,
newest first. Deletes are applied in the same ordered pass, so a failed write also undoes a delete. The
scratch names end in '~', which encode_name never produces and decode_name rejects, so enumeration and the
quota never see them. A backup whose restore failed is kept, and later commits only remove backups they
wrote themselves. A commit drops the temporaries of one that died midway. A blob never leaves its name, so a
process that dies midway leaves each blob old or new, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 17:33:10 +01:00
2cc83a803f xgameruntime: a closed XGameSave container stays expired when its address is reused (#6312)
Squash-merged after review of PR #6312 - xgameruntime: a closed XGameSave container stays expired when its address is reused
2026-11-23 08:06:44 -06:00
de67135246 Runtime: offline XGameSaveImpl (save provider, containers, blobs, updates)
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>
2026-11-23 00:38:01 -05:00