Skip to content

xmem: preserve ownership and native errors after partial releases - #8825

Closed
Demon12377 wants to merge 3 commits into
ProjectLeonida:mainfrom
Demon12377:codex/xmem-release-retry
Closed

Demon12377 wants to merge 3 commits into
ProjectLeonida:mainfrom
Demon12377:codex/xmem-release-retry

Conversation

@Demon12377

@Demon12377 Demon12377 commented Nov 23, 2026 •

Copy link
Copy Markdown

Claimed in the coordination issue as: #8344 (comment)

Depends on: #7742 at 51736cd2f2b2e2a08a37ae0c67a359ab2b362142. This is a separate failure-handling follow-up. The first commit carries #7742's implementation and normal-path tests, credited to @ASTROWwwW; the next commit adds failing regression cases, and the final commit fixes them. Textual overlap with the other open XMem work (#7580, #7712, #8289) needs the usual rebase after those land.

What and why

When an unmap or release fails partway through TitleVirtualFree(base, 0, MEM_RELEASE), #7742 erases the range bookkeeping even though some views/placeholders remain. A retry then falls back to the host call at the old base, and the first native error is replaced with ERROR_INVALID_ADDRESS.

Keep original-base retry aliases over only the surviving owned spans, trim confirmed freed windows, and preserve the first native error after unlocking. Re-query native split topology on retry so remapping a retained placeholder still works. Preserve independent nested owners while letting the outer owner release its carved windows. A fresh reservation invalidates/re-homes old aliases and keeps the new owner's memory out of the old retry; native reserve and bookkeeping share the physical-memory mutex.

Controlled failure callbacks are compiled only into xmem_test. The runtime has no test callback storage or setter.

Tested

Windows 10 Pro x64, build 19045; MSVC 19.44 / VS 2022 Build Tools 14.44; Windows SDK 10.0.26100.0; CMake 4.4.4. GPU unused, no game files.

  • The same 290 checks: regression commit 09ab692bbd974001aecc53c6697da06608b82eeb completes with 24 failures; fixed head completes with 290 passed / 0 failed. Allocations and views are real small local Windows fixtures; the API failures are deliberately injected, not a claim about natural failure frequency.
  • Covers failed unmap/free/query, allocation-end query failure, repeated partial retries, wrong-size retry, hole/base/survivor reuse, remapping split survivors, independent versus carved nested ownership, and partial-survivor replacement.
  • Production xmem.cpp compiled without the test flag; dumpbin /symbols confirms no test setter/callback storage.
  • Independent negative-control and production-build report by Kalmarv: reported 290/290 on three runs, the same 24 failures after replacing only xmem.cpp with the regression version, and a clean production gta6rt build without hook symbols. Their report does not claim a full-suite, Wine or retail run.
  • git diff --check and scripts/check_no_game_data.py on all four files pass.
  • Independent static review resolved the nested-owner and retained-window issues before the final run.
  • Independent Windows 11 check by smowlyy: reported the same head combined locally with main 867d922f0, clean build/no-game-data check, and 290 checks passed.
  • Integration report by lohant27-netizen: reported the same head combined locally with main and four other changes without conflicts; xmem passes. Their batch has other runtime failures, so this is an integration report, not an all-green full-suite or CI result.

Reproduce either the regression commit or the fixed head:

cmake -S runtime -B build-xmem -G "Visual Studio 17 2022" -A x64 "-DCMAKE_SYSTEM_VERSION=10.0.26100.0" -DLEONIDA_SDL3=OFF
cmake --build build-xmem --config RelWithDebInfo --target xmem_test --parallel 1
ctest --test-dir build-xmem -C RelWithDebInfo -R "^xmem$" --output-on-failure

Vulkan headers are absent on this host, so this is the targeted CPU test, not a full runtime/GPU test result. Retail execution was not tested.

AI-assisted: yes (Codex, implementation and independent review agents).

Checklist

  • No game data, keys or decryption, including logs/reports quoted here.
  • Translator-contract requirement: not applicable; no translator changes.

Dependency snapshot: ItsNotRexed#7742 at 51736cd. The subsequent commits contain the new regression cases and failure-handling fix.
The 290-check suite completes with 24 failures on the ItsNotRexed#7742 implementation. Failure callbacks are compiled only into xmem_test. Claim: ItsNotRexed#8344 (comment)

AI-assisted: yes (Codex).
Keep original-base retry aliases over surviving owned spans, preserve nested ownership, and invalidate/rehome aliases on tracked address reuse. Serialize reserve and bookkeeping. The same 290 checks now pass.

AI-assisted: yes (Codex; implementation and independent review agents).
@smowlyy

smowlyy commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Verified head 406b00c23 merged onto main (867d922f0) on native Windows 11 (10.0.26300.9974, MSVC 19.44, RelWithDebInfo):

  • python -I scripts/check_no_game_data.py on all 4 changed files: clean (exit 0)
  • cmake --build runtime/build --target xmem_test --parallel: built cleanly
  • ctest --test-dir runtime/build -R '^xmem$' --output-on-failure -V: 1/1 passed (xmem_test: OK (290 checks))

AI-assisted.

@lohant27-netizen

Copy link
Copy Markdown

Tested 406b00c23 on Windows 11 (10.0.26300), NVIDIA GeForce RTX 5070 (driver 32.0.16.2101, subgroup 32), MSVC with SDK 10.0.26100, Release, merged onto main 867d922f0 together with #8871, #8869, #8825, #8863 and #8885 (no conflicts): pass.

@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown

AI-assisted independent validation (Claude Code), native Windows, CPU only, no game files.

Tested PR head 406b00c23 as is on Windows 11 (10.0.26200) with MSVC 19.44.35215 (VS 2022 generator), RelWithDebInfo. Its base is d612f6548; it merges cleanly onto current main 867d922f0, and the 31 commits between them touch no xmem file and not runtime/CMakeLists.txt. This adds a native negative control and a production-build check to the existing Windows runs.

@sds-228 sds-228 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the ownership bookkeeping in release_range, retry aliases, window trimming, and native-error capture; partial-release and nested-owner paths are consistent and the first native error is preserved. The failure hooks are confined to xmem_test via LEONIDA_XMEM_TEST_HOOKS, with no production storage or setter, and the injected unmap/free/query failures cover the claimed regressions. No game data, keys, or paths/logs were introduced. I could not build or run the C++ tests here because no local C++ compiler is available.

AI-assisted (OpenCode).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants