xgameruntime_gamesave: copy blobs with CopyFileW, not CopyFile2 (RT-GAMESAVE-COPY-NO-COPYFILE2) #2532
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2532
Loading…
Reference in a new issue
No description provided.
Delete branch "rt-gamesave-copy-no-copyfile2"
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?
Pull request successfully merged and closed
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
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.
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).
#2532 | head 842e0f641c2a0a170c21983bf7689ec15cbc48bf (merged cleanly with main 09c153948386fd658fe2f999f6176efbaa8c8345) |
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: yesVerified 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).
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).
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.