Repository navigation
Conversation
…ress is reused XGameSaveUpdate and the async jobs keep a raw container (or provider, or update) pointer, and the handle checks look the address up in the live set only. XGameSaveCloseContainer frees the container, the heap hands the same address to the next XGameSaveCreateContainer, and the stale pointer passes as live again: SubmitUpdate of an update of the closed container commits its blobs into the new container's folder, and a ReadBlobDataAsync started on it completes with the other container's blobs. Every handle now gets a serial when it is made; an update keeps its container's serial and each async job the serial of the handle it names, and the checks compare address and serial. xgameruntime_gamesave_test reproduces the reuse (under Wine the address comes back at once): three checks fail without the change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claim and finding: #5934 (comment)
Cause
runtime/shims/xgameruntime_gamesave.cppchecks a handle by its address only (live(), theg_containersset), andXGameSaveCloseContainer(:682on main561b65a8) frees the container. The heap may give that address to the nextXGameSaveCreateContainer. Two things keep a container pointer after the call that gave it:XGameSaveUpdate::container,:197, set insave_create_update:761).submit_update(:434-436) checks only that the address is a live container. After the address is reused,XGameSaveSubmitUpdateon an update of the closed container commits its blobs into the new container's folder;Job::container,:447).XGameSaveReadBlobDataAsyncchecks the container when its work runs (:484). A read started on a container that is closed before the work runs, with the address reused, completes S_OK with the other container's blobs.The quota, delete and submit jobs keep a provider or update pointer the same way.
xgameruntime_user.cpp:85-88notes the same reuse forXUserHandle, where it does no harm because every handle names the one user. Here each container is a different save, so it is not harmless: data goes into, or is loaded from, the wrong save slot, where the shim means to returnE_GS_HANDLE_EXPIRED.Fix
Every provider, container and update gets a serial when it is made, and no two get the same one. An update keeps its container's serial, and each async job keeps the serial of the handle it names (0, which no handle has, when that handle was not live at the call). The checks become "address is live and its serial matches" (
live_as). A closed handle now stays expired after its address is reused, and nothing else changes.Tests
xgameruntime_gamesave_testgets a new section. It creates container "first", makes an update with a blob, starts aReadBlobDataAsyncon a manual queue and closes "first". Then it creates containers until one lands at the same address (it prints SKIP if the heap never reuses it) and writes a blob into that new container "second". Three checks follow:SubmitUpdateof the stale update returnsE_GS_HANDLE_EXPIRED;second;E_GS_HANDLE_EXPIREDand no result.Under Wine 11.20 the address comes back on the first try. On main all three checks fail: the update returns S_OK and writes
local-user\second\mine, and the read returns the other container's blobs. With the fix, all 56 checks pass.Platform: Windows runtime cross-built with clang-cl 22 + xwin on Linux and run under Wine 11.20 (not native Windows). CPU only, no GPU, no game files. Full
ctest -j1 --timeout 300before and after: main561b65a8230/246 passed, 16 failed (gameinput_host, device_proxy, device_proxy_trace, file_system, run_tiny_game_abort_exit_codes, vk_pipeline_check_cli, d3d12_noop_copy, d3d12_indirect_dispatch_count, d3d12_clear, d3d12_typeless_depth, d3d12_residency, d3d12_heap_properties, d3d12_present, dxgi_swapchain, d3d12_indirect_rt, d3d12_clear_formats). With the change the same 16 failed, andxbox_presentalso failed:[rt] d3d12: present failed (VkResult -11)on this desktop's live swapchain.xbox_present_testdoes not build either changed file (it linksgta6rt_d3d12_com), so this is the display environment, not this change.xgameruntime_gamesavepasses.Overlap: #5113, #5189, #5190 and #5203 also edit this file, but in other places (commit staging, read packing, name encoding, long paths). None of them changes the handle checks. If one of them lands first, a rebase should be mechanical.
AI-assisted (Claude Code).
🤖 Generated with Claude Code