xgameruntime_gamesave: copy blobs with CopyFileW, not CopyFile2 (RT-GAMESAVE-COPY-NO-COPYFILE2) #2532
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2532"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-28T01:08:48Z.
Claimed in the coordination issue as: RT-GAMESAVE-COPY-NO-COPYFILE2 (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7231450902)
Depends on: none, but touches
copy_blob()as #2003 does (#2003 already conflicts withmain)What and why
This fixes item 1 of kevincommits' batch 18 in #1608 (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7231277215).
copy_blob()inruntime/shims/xgameruntime_gamesave.cpphas two jobs:It used
std::filesystem::copy_file, which in MSVC callsCopyFile2. Wine 9 and the Protons built on it do not implementCopyFile2, and the call aborts the process ("unimplemented function KERNEL32.dll.CopyFile2, aborting"). So the first save that overwrote a blob would kill the title there.file_system.cpp,pe_loader.cppand three tests already avoidCopyFile2for the same reason.copy_blob()now callsCopyFileW(from, to, FALSE). On Windows it copies the same way as before: contents, attributes and the last-write time, replacing an existing file. That last part also covers what #2003 adds tocopy_blob(keeping the source's last-write time).Tested
xgameruntime_gamesave_testgains a case that patches this process'sCopyFile2to fail and count its calls, the way Wine's stub would. It then runs:Both must work, with zero
CopyFile2calls. The patch is removed afterwards.copy_blob, 3 checks fail. With the fix, 96/96 pass.ctest -R xgameruntime: 8/8 pass.GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11 (CPU-only test; not run under Wine)
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T02:01:38Z.
Reviewed at head
03d17a395on Windows 11 (MSVC 202219.44).Verification
xgameruntime_gamesave_test.xgameruntime_gamesave_test: 96/96 checks passed on Windows 11.Finding (Request changes)
CopyFile2is absent (xgameruntime_gamesave_test.cpp:87-95,112,537-538):The production switch to
CopyFileWfor backup and restore (xgameruntime_gamesave.cpp:488-506,568-586) is clean and preserves rollback/backup-retention behavior. However, inxgameruntime_gamesave_test.cpp:537-538,CopyFile2Trapleaves itself unarmed whenGetProcAddressdoes not findCopyFile2, and Case E unconditionally failscheck(trap.armed(), "CopyFile2 is trapped"). Because Wine 9 lacks theCopyFile2export — the exact reason for this PR — the regression test will fail on Wine 9 even when both blob operations succeed. Treating a missingCopyFile2export as expected on Wine (distinguishing export-absent from patch-failed) and still running the overwrite + rollback functional checks fixes this cleanly.AI-assisted review + local MSVC verification.
Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-28T02:06:04Z.
Thanks @timbot103, fixed in
842e0f641.CopyFile2Trapnow tells a missing export apart from a patch that failed:CopyFile2export (Wine 9): the trap records that and stays unarmed. Case E prints a note and still runs the overwrite and rollback checks against the real host. With no export, nothing can callCopyFile2, so the zero-calls check holds trivially.CopyFile2 is trapped, or the host has none.On Windows 11, all 96 checks pass, with the trap armed. I have no Wine 9 setup here, so the absent-export path was not run. AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T07:05:25Z.
#2532 | head
842e0f641c(merged cleanly with main09c1539483) |ctest --test-dir runtime/build -C RelWithDebInfo -R "^xgameruntime_gamesave$" --output-on-failure| red on main:xgameruntime_gamesave.cppcallsstd::filesystem::copy_file, importingMSVCP140.dll!__std_fs_copy_file(note: on Windows 11 with VC++ runtime14.44,__std_fs_copy_fileusesCreateFileW+ read/write rather thanCopyFile2, whereas pre-14.38msvcp140.dll/ Wine 9 redistributables route__std_fs_copy_filetoCopyFile2viaapi-ms-win-core-file-l1-2-0->KernelBase.dll!CopyFile2) | green on PR+main:1/1CTest passes (xgameruntime_gamesave96/96checks in0.34s,0CopyFile2calls under bothkernel32.dll!CopyFile2andKernelBase.dll!CopyFile2traps, anddumpbin /importsconfirms__std_fs_copy_fileis gone in favor ofKERNEL32.dll!CopyFileW);check_no_game_data.py0violations | Windows 11, RTX 3090 (610.88), Vulkan SDK 1.4.363.1 | AI-assisted: yesImported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T14:36:34Z.
Review: COMMENTED
Static code audit against
842e0f641+ec740bcc3.Major —
runtime/shims/xgameruntime_gamesave.cpp:492. Wine 9'sCopyFileWreturns success after a source read error once the destination has been opened. During rollback, that can leave the live blob truncated and cause cleanup to delete the intact backup (runtime/shims/xgameruntime_gamesave.cpp:502,runtime/shims/xgameruntime_gamesave.cpp:520). A write error can also leave a partial destination. Wine 9 copy implementationPlease use a checked copy to a sibling staging file, then replace the destination only after the copy completes. Case E covers overwrite and rollback after a blocked update. A copy fault test should also assert that an incomplete restore leaves the backup intact.
AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-28T20:10:30Z.
Review: COMMENTED
Reviewed and locally tested
842e0f641(runtime/shims/xgameruntime_gamesave.cpp,runtime/test/xgameruntime_gamesave_test.cpp).Local verification:
xgameruntime_gamesave_test(MSVC Release / Ninja) and ranctest -R ^xgameruntime_gamesave$: 1/1 passed.python -I scripts/check_no_game_data.py: passed.Switching away from
std::filesystem::copy_fileavoids the Wine 9CopyFile2abort, and updatingCopyFile2Trapso Case E runs without aCopyFile2export is clean. However, I second @timbot103's concern oncopy_blob(runtime/shims/xgameruntime_gamesave.cpp:492, called during rollback at:502before deleting the backup at:520): on Wine 9 specifically,CopyFileWoverwrites the destination in place and can returnTRUEafter a source read failure once the destination has been opened, which could truncate the live blob during rollback and then delete the intact backup. Copying via a checked read/write loop into a sibling staging file and replacing the destination withMoveFileExW(..., MOVEFILE_REPLACE_EXISTING)would avoid bothCopyFile2and Wine 9'sCopyFileWquirk.AI-assisted (Antigravity, Gemini).
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T22:04:11Z.
Verified by OreoFR
c1ecf04ed+ PR head842e0f641; green run in a merge package of 11 PRs, no new ctest failure vs mainctest -R "^xgameruntime_gamesave$"AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-28T23:23:14Z.
Tested
842e0f641merged (no commit) withmainaa918e5d9. GPUs tested: NVIDIA GeForce RTX 3080, driver 621.40, Windows 11 10.0.26300; MSVC 19.52 (Visual Studio 18), RelWithDebInfo, Ninja.xgameruntime_gamesavepasses.runtime/shims/xgameruntime_gamesave.cppback tomain,xgameruntime_gamesavefails 3 checks:an update that overwrites a blob succeeds without CopyFile2a failed update copies a back from its backup without CopyFile2no commit or rollback calls CopyFile2 (Wine 9 has none)No blocker from my side. AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T23:25:19Z.
Merged after TheGeogeo's red/green check (check: green with this PR, red with
main's code, no regression over the relinked tests) and a re-check here: no conflict withmain7f0b878d3, same head as checked,no-game-datagreen, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known onmainor Vulkan: vk_xdxr_postbuild_readback vk_bindless_dimensions d3d12_compile_pool xbox_present ). The Python jobs fail onmaintoo.AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.