fix(xgameruntime): make the XMem and XThread edge cases deterministic #43

Open
github-bot wants to merge 1 commit from github-bot/gh-43 into main AGit
Owner

@⁠wildheathen on GitHub · 2026-11-21 19:28 UTC · original
wildheathen:fix/xmem-edge-cases → main · +102 −18 · 2 files · 1 commits · open

Summary

Makes a few XMem/XThread edge cases deterministic instead of depending on the host allocator. Titles that follow the API do not notice; the HLE now answers the same way everywhere.

  • XMemFree(nullptr) is a no-op and no longer reaches the allocation hook.
  • XMemVirtualAlloc with size == 0 returns nullptr (on non-Windows hosts it used to allocate 4096 bytes).
  • XMemVirtualFree rejects a decommit without a range (MEM_DECOMMIT needs a size).
  • XThreadAssertNotTimeSensitive logs the misuse to stderr when called on a time-sensitive thread (the console would break into the debugger; the HLE stays non-fatal).
  • The default allocator is documented as heap-backed, zero-filled and 16-byte aligned.

No new functions and no new types.

Tests

tests/test_xgameruntime_abi.cpp extends the existing XMem/XThread sections: zero-filled and 16-byte aligned default allocations, a half hook pair is rejected and leaves the current pair alone, freeing null never reaches the hook, zero-size virtual allocation, reserve / decommit / release, and the time-sensitive flag being per thread (a worker starts clean and does not leak its setting back).

Verification

  • Built with MSVC + Ninja x64. Full suite: everything passes except the three tests that already fail on an unmodified origin/main (test_boot_hello_scarlett, test_boot_rt_showcase, test_d3d12_guest_texture; see #1 and #2).
  • Overlap: #23 adds XMemVirtualProtect/XMemVirtualQuery right after XMemVirtualFree and extends the same test block, so a trivial rebase may be needed depending on merge order.
**@⁠wildheathen** on GitHub · 2026-11-21 19:28 UTC · [original](https://github.com/Freminet/ScarlettX/pull/43) `wildheathen:fix/xmem-edge-cases` → `main` · +102 −18 · 2 files · 1 commits · open ## Summary Makes a few `XMem`/`XThread` edge cases deterministic instead of depending on the host allocator. Titles that follow the API do not notice; the HLE now answers the same way everywhere. - `XMemFree(nullptr)` is a no-op and no longer reaches the allocation hook. - `XMemVirtualAlloc` with `size == 0` returns `nullptr` (on non-Windows hosts it used to allocate 4096 bytes). - `XMemVirtualFree` rejects a decommit without a range (`MEM_DECOMMIT` needs a size). - `XThreadAssertNotTimeSensitive` logs the misuse to stderr when called on a time-sensitive thread (the console would break into the debugger; the HLE stays non-fatal). - The default allocator is documented as heap-backed, zero-filled and 16-byte aligned. No new functions and no new types. ## Tests `tests/test_xgameruntime_abi.cpp` extends the existing XMem/XThread sections: zero-filled and 16-byte aligned default allocations, a half hook pair is rejected and leaves the current pair alone, freeing null never reaches the hook, zero-size virtual allocation, reserve / decommit / release, and the time-sensitive flag being per thread (a worker starts clean and does not leak its setting back). ## Verification - Built with MSVC + Ninja x64. Full suite: everything passes except the three tests that already fail on an unmodified `origin/main` (`test_boot_hello_scarlett`, `test_boot_rt_showcase`, `test_d3d12_guest_texture`; see #1 and #2). - Overlap: #23 adds `XMemVirtualProtect`/`XMemVirtualQuery` right after `XMemVirtualFree` and extends the same test block, so a trivial rebase may be needed depending on merge order.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:56:49 +00:00
This pull request has changes conflicting with the target branch.
  • src/shims/xgameruntime_shim.cpp
  • tests/test_xgameruntime_abi.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/43/head:github-bot/gh-43'
git switch 'github-bot/gh-43'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-43'
git switch 'github-bot/gh-43'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-43'
git switch 'github-bot/gh-43'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-43'
git switch 'main'
git merge --squash 'github-bot/gh-43'
git switch 'main'
git merge --ff-only 'github-bot/gh-43'
git switch 'main'
git merge 'github-bot/gh-43'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.