abi: realign SysV host entries on Windows #990

Closed
github-bot wants to merge 2 commits from gh-pr/990/head into gh-pr/990/base
Owner

@⁠tsubaki-0x on GitHub · 2026-10-02 23:33 UTC · original
suzu/hello-kitty-abi-latest → main · +111 −0 · 2 files · 2 commits · closed without merging

PR Title

abi: realign SysV host entries on Windows

Problem

On Windows, a guest SysV call can enter a Kyty host function with a stack alignment that does not match what Clang expects for a normal SysV call.

When that host function later calls code using the Windows/MS ABI, the misalignment can propagate and cause aligned stack operations such as movaps to fault.

This was reproduced while investigating Hello Kitty Island Adventure (PPSA18176), related to #610.

On current main, the game could reach a host access violation during normal execution. Applying force_align_arg_pointer to SysV host entries prevented the alignment fault and allowed execution to continue.

Change

On Windows x86-64, make KYTY_SYSV_ABI use:

__attribute__((sysv_abi, force_align_arg_pointer))

Other platforms keep the existing sysv_abi definition unchanged.

Regression test

Added a Windows-only regression test that:

  1. Generates a small trampoline that deliberately enters a SysV host function with a misaligned stack.
  2. Calls an MS ABI helper from that function.
  3. Verifies that the MS ABI entry receives the expected stack alignment.

A/B result:

without force_align_arg_pointer: FAIL
with force_align_arg_pointer:    PASS

With the fix:

WindowsMisalignedSysvHostEntry ... ms_rsp_mod16=8 ok

Testing

  • Windows Release build with clang-cl: PASS
  • virtual_memory_allocation_tests --sysv-align-only: PASS
  • Same regression test without the ABI fix: FAIL as expected
  • Windows CI regression-test subset: PASS
  • Full local CTest: 49/52 PASS

The remaining three failures were reproduced unchanged without this patch:

  • kernel_file_system
  • shader_recompiler_compute
  • pm4_context_state

The change was also tested with the guest workload that originally exposed the alignment problem, where execution continued normally after applying the fix.

Scope

This change does not contain any game-specific workaround.

The regression test reproduces the stack-alignment condition independently of any guest binary or game data.

AI use

AI assistance was used during debugging, investigation, and regression-test development.

I reviewed the resulting code, reproduced the failure with and without the fix, built the affected targets, ran the regression tests locally, and manually validated the change against the workload that originally exposed the issue.

**@⁠tsubaki-0x** on GitHub · 2026-10-02 23:33 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/990) `suzu/hello-kitty-abi-latest` → `main` · +111 −0 · 2 files · 2 commits · closed without merging # PR Title abi: realign SysV host entries on Windows ## Problem On Windows, a guest SysV call can enter a Kyty host function with a stack alignment that does not match what Clang expects for a normal SysV call. When that host function later calls code using the Windows/MS ABI, the misalignment can propagate and cause aligned stack operations such as `movaps` to fault. This was reproduced while investigating Hello Kitty Island Adventure (PPSA18176), related to #610. On current `main`, the game could reach a host access violation during normal execution. Applying `force_align_arg_pointer` to SysV host entries prevented the alignment fault and allowed execution to continue. ## Change On Windows x86-64, make `KYTY_SYSV_ABI` use: ```cpp __attribute__((sysv_abi, force_align_arg_pointer)) ``` Other platforms keep the existing `sysv_abi` definition unchanged. ## Regression test Added a Windows-only regression test that: 1. Generates a small trampoline that deliberately enters a SysV host function with a misaligned stack. 2. Calls an MS ABI helper from that function. 3. Verifies that the MS ABI entry receives the expected stack alignment. A/B result: ```text without force_align_arg_pointer: FAIL with force_align_arg_pointer: PASS ``` With the fix: ```text WindowsMisalignedSysvHostEntry ... ms_rsp_mod16=8 ok ``` ## Testing - Windows Release build with clang-cl: PASS - `virtual_memory_allocation_tests --sysv-align-only`: PASS - Same regression test without the ABI fix: FAIL as expected - Windows CI regression-test subset: PASS - Full local CTest: 49/52 PASS The remaining three failures were reproduced unchanged without this patch: - `kernel_file_system` - `shader_recompiler_compute` - `pm4_context_state` The change was also tested with the guest workload that originally exposed the alignment problem, where execution continued normally after applying the fix. ## Scope This change does not contain any game-specific workaround. The regression test reproduces the stack-alignment condition independently of any guest binary or game data. ## AI use AI assistance was used during debugging, investigation, and regression-test development. I reviewed the resulting code, reproduced the failure with and without the fix, built the affected targets, ran the regression tests locally, and manually validated the change against the workload that originally exposed the issue.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:39:31 +00:00
github-bot closed this pull request 2026-11-26 09:39:31 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-02 23:38 UTC · original · edited 2026-10-03 00:07 UTC

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0a17c702-cc8b-4243-964d-e4de1d052366
📥 Commits

Reviewing files that changed from the base of the PR and between 82193ca55c and 617e728c93.

📒 Files selected for processing (1)
  • tests/VirtualMemoryAllocationTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

KYTY_SYSV_ABI now adds force_align_arg_pointer on Windows x86-64 and retains sysv_abi on other platforms. A new test exercises a Windows-ABI trampoline calling a SysV function with a misaligned stack. The test checks target execution, nested Windows-ABI stack alignment, and memory cleanup. Windows builds can run the test with --sysv-align-only; non-Windows builds report it as skipped.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 617e7

The Windows alignment change has no identified merge-blocking issue in the supplied evidence; it is ready for normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 617e7

The change is a narrowly scoped alignment correction, not a new access or authorization mechanism. The new execution path is confined to a regression test. Risk is low because the shared attribute affects existing Windows host functions, whose production behavior has not been exhaustively verified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The production effect extends to existing functions compiled with KYTY_SYSV_ABI on Windows x86-64, including guest-facing host APIs. It is not limited to the regression target, but the complete consumer inventory is unavailable.

Trust Boundaries and Controls

  • inferred — Stack realignment changes calling-convention handling, not isolation or authorization policy. The changed production definition adds no route or capability, and inspected existing host entries retain their validation controls.
  • observed — The new command-line selector and normal invocation are in the test executable. They invoke the fixed alignment test rather than exposing an additional production guest-to-host entrypoint.

Resilience and Maintainability Implications

  • observed — On normal return, the test restores saved Windows nonvolatile registers and stack state and frees its executable allocation before validation assertions. Its invocation state is local, and the supplied runner invokes it sequentially.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: realigning SysV host entries on Windows.
Description check ✅ Passed The description directly explains the Windows ABI alignment problem, the code change, the regression test, and the reported validation results.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-02 23:38 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/990#issuecomment-5963164493) · edited 2026-10-03 00:07 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/990?cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> Navigate logical layers of code changes, visualize relationships, and explore their blast radius. <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `0a17c702-cc8b-4243-964d-e4de1d052366` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 82193ca55ce21260a787fd1b6eb2d5858f1cc343 and 617e728c9309337fda2da0aba9f31bed0207930f. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `tests/VirtualMemoryAllocationTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough `KYTY_SYSV_ABI` now adds `force_align_arg_pointer` on Windows x86-64 and retains `sysv_abi` on other platforms. A new test exercises a Windows-ABI trampoline calling a SysV function with a misaligned stack. The test checks target execution, nested Windows-ABI stack alignment, and memory cleanup. Windows builds can run the test with `--sysv-align-only`; non-Windows builds report it as skipped. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"617e728c9309337fda2da0aba9f31bed0207930f" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _⚪ Minimal_ · up to `617e7` <!-- final_review_risk_coverage:{"sourceCommitId":"617e728c9309337fda2da0aba9f31bed0207930f","coveredCommitId":"617e728c9309337fda2da0aba9f31bed0207930f","kind":"reviewed"} --> The Windows alignment change has no identified merge-blocking issue in the supplied evidence; it is ready for normal checks. <!-- final_review_risk_end --> <!-- architecture_review_start --> ### Security Architecture Review **Security architecture risk:** _🔵 Low_ · up to `617e7` The change is a narrowly scoped alignment correction, not a new access or authorization mechanism. The new execution path is confined to a regression test. Risk is low because the shared attribute affects existing Windows host functions, whose production behavior has not been exhaustively verified. **Retained concerns** No architecture-level concerns identified. <details> <summary>Security review details</summary> **Security Blast Radius** - _inferred_ — The production effect extends to existing functions compiled with KYTY_SYSV_ABI on Windows x86-64, including guest-facing host APIs. It is not limited to the regression target, but the complete consumer inventory is unavailable. **Trust Boundaries and Controls** - _inferred_ — Stack realignment changes calling-convention handling, not isolation or authorization policy. The changed production definition adds no route or capability, and inspected existing host entries retain their validation controls. - _observed_ — The new command-line selector and normal invocation are in the test executable. They invoke the fixed alignment test rather than exposing an additional production guest-to-host entrypoint. **Resilience and Maintainability Implications** - _observed_ — On normal return, the test restores saved Windows nonvolatile registers and stack state and frees its executable allocation before validation assertions. Its invocation state is local, and the supplied runner invokes it sequentially. </details> <!-- architecture_review_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :---------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ✅ Passed | The title clearly and concisely identifies the main change: realigning SysV host entries on Windows. | | Description check | ✅ Passed | The description directly explains the Windows ABI alignment problem, the code change, the regression test, and the reported validation results. | | Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autopilot</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts > Autopilot is currently an internal CodeRabbit preview. <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=990)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-02 23:38 UTC · original · edited 2026-10-03 00:02 UTC
On tests/VirtualMemoryAllocationTests.cpp line 309 (outdated):

@@ -271,6 +271,72 @@ void RunTest(void (*test_func)()) {
 	}
 }
 
+#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
+struct MisalignedSysvHostEntryState {
+	bool      called        = false;
+	uintptr_t sysv_body_rsp = 0;
+	uintptr_t ms_entry_rsp  = 0;
+};
+[[gnu::naked]] static KYTY_MS_ABI uintptr_t CaptureMsAbiEntryRsp() {
+	asm volatile("movq %rsp, %rax\n\t"
+	             "retq");
+}
+
+[[gnu::noinline]] static KYTY_SYSV_ABI void MisalignedSysvHostEntryTarget(
+    MisalignedSysvHostEntryState* state) {
+	asm volatile("movq %%rsp, %0" : "=r"(state->sysv_body_rsp) : : "memory");
+	state->ms_entry_rsp = CaptureMsAbiEntryRsp();
+	asm volatile("" : : : "memory");
+	state->called = true;
+}
+
+void TestWindowsMisalignedSysvHostEntry() {
+	const char* test = "WindowsMisalignedSysvHostEntry";
+	constexpr uint64_t code_size = 0x4000;
+
+	const auto mapping = Libs::LibKernel::Memory::AllocateRuntimeMemory(
+	    0, code_size, Common::VirtualMemory::Mode::ExecuteReadWrite,
+	    "misaligned_sysv_host_entry_test");
+	Check(test, mapping != 0, "failed to allocate executable trampoline");
+
+	Xbyak::CodeGenerator code(code_size, reinterpret_cast<void*>(mapping));
+
+	// This trampoline itself is entered with the Windows x64 ABI. Keep the two
+	// nonvolatile registers balanced while deliberately leaving RSP at 8 mod 16
+	// before CALL. The CALL therefore enters the SysV target at 0 mod 16 instead
+	// of the 8 mod 16 that a normal SysV callee expects.
+	code.push(code.rdi);
+	code.push(code.r12);

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '265,345p' tests/VirtualMemoryAllocationTests.cpp
sed -n '1,35p' src/common/abi.h

Repository: KytyPS5/KytyPS5

Length of output: 3638


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- test references and entrypoint ---'
rg -n -C 5 'TestWindowsMisalignedSysvHostEntry|sysv-align-only|VirtualMemoryAllocationTests|Test.*VirtualMemory' tests src CMakeLists.txt 2>/dev/null | head -240
printf '%s\n' '--- ABI and compiler configuration references ---'
rg -n -C 4 'KYTY_SYSV_ABI|KYTY_MS_ABI|ms_abi|sysv_abi|force_align_arg_pointer|clang-cl|x86_64-w64|MinGW|Windows' . -g '!*.json' -g '!*.lock' | head -320
printf '%s\n' '--- relevant file outline and surrounding test sequence ---'
ast-grep outline tests/VirtualMemoryAllocationTests.cpp
sed -n '1,120p' tests/VirtualMemoryAllocationTests.cpp
sed -n '340,470p' tests/VirtualMemoryAllocationTests.cpp

Repository: KytyPS5/KytyPS5

Length of output: 43182


🏁 Script executed:

set -eu
printf '%s\n' '--- test references and entrypoint ---'
rg -n -C 5 'TestWindowsMisalignedSysvHostEntry|sysv-align-only|VirtualMemoryAllocationTests|Test.*VirtualMemory' tests src CMakeLists.txt 2>/dev/null | head -240
printf '%s\n' '--- ABI and compiler configuration references ---'
rg -n -C 4 'KYTY_SYSV_ABI|KYTY_MS_ABI|ms_abi|sysv_abi|force_align_arg_pointer|clang-cl|x86_64-w64|MinGW|Windows' . -g '!*.json' -g '!*.lock' | head -320
printf '%s\n' '--- relevant file outline and surrounding test sequence ---'
ast-grep outline tests/VirtualMemoryAllocationTests.cpp
sed -n '1,120p' tests/VirtualMemoryAllocationTests.cpp
sed -n '340,470p' tests/VirtualMemoryAllocationTests.cpp

Repository: KytyPS5/KytyPS5

Length of output: 43857


Preserve Windows nonvolatile state across the SysV call.

MisalignedSysvHostEntryTarget uses the SysV ABI. That ABI permits the target to clobber rsi and xmm6–xmm15. The Windows-ABI caller expects these registers to survive, but the trampoline saves only rdi and r12.

This test runs in the normal Windows test sequence. A target/compiler that uses these registers can corrupt live caller state after the trampoline returns. Save and restore rsi and xmm6–xmm15 while retaining the deliberate stack misalignment.

The impact is limited to this Windows test executable, so classify this as a minor issue rather than a major production stability issue.

✅ Addressed in commit 617e728

**@⁠coderabbitai[bot]** on GitHub · 2026-10-02 23:38 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/990#discussion_r4170702427) · edited 2026-10-03 00:02 UTC On `tests/VirtualMemoryAllocationTests.cpp` line 309 (outdated): ```diff @@ -271,6 +271,72 @@ void RunTest(void (*test_func)()) { } } +#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS +struct MisalignedSysvHostEntryState { + bool called = false; + uintptr_t sysv_body_rsp = 0; + uintptr_t ms_entry_rsp = 0; +}; +[[gnu::naked]] static KYTY_MS_ABI uintptr_t CaptureMsAbiEntryRsp() { + asm volatile("movq %rsp, %rax\n\t" + "retq"); +} + +[[gnu::noinline]] static KYTY_SYSV_ABI void MisalignedSysvHostEntryTarget( + MisalignedSysvHostEntryState* state) { + asm volatile("movq %%rsp, %0" : "=r"(state->sysv_body_rsp) : : "memory"); + state->ms_entry_rsp = CaptureMsAbiEntryRsp(); + asm volatile("" : : : "memory"); + state->called = true; +} + +void TestWindowsMisalignedSysvHostEntry() { + const char* test = "WindowsMisalignedSysvHostEntry"; + constexpr uint64_t code_size = 0x4000; + + const auto mapping = Libs::LibKernel::Memory::AllocateRuntimeMemory( + 0, code_size, Common::VirtualMemory::Mode::ExecuteReadWrite, + "misaligned_sysv_host_entry_test"); + Check(test, mapping != 0, "failed to allocate executable trampoline"); + + Xbyak::CodeGenerator code(code_size, reinterpret_cast<void*>(mapping)); + + // This trampoline itself is entered with the Windows x64 ABI. Keep the two + // nonvolatile registers balanced while deliberately leaving RSP at 8 mod 16 + // before CALL. The CALL therefore enters the SysV target at 0 mod 16 instead + // of the 8 mod 16 that a normal SysV callee expects. + code.push(code.rdi); + code.push(code.r12); ``` _🩺 Stability & Availability_ | _🟡 Minor_ | _⚡ Quick win_ <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash sed -n '265,345p' tests/VirtualMemoryAllocationTests.cpp sed -n '1,35p' src/common/abi.h ``` Repository: KytyPS5/KytyPS5 Length of output: 3638 --- 🏁 Script executed: ```bash #!/bin/bash set -eu printf '%s\n' '--- test references and entrypoint ---' rg -n -C 5 'TestWindowsMisalignedSysvHostEntry|sysv-align-only|VirtualMemoryAllocationTests|Test.*VirtualMemory' tests src CMakeLists.txt 2>/dev/null | head -240 printf '%s\n' '--- ABI and compiler configuration references ---' rg -n -C 4 'KYTY_SYSV_ABI|KYTY_MS_ABI|ms_abi|sysv_abi|force_align_arg_pointer|clang-cl|x86_64-w64|MinGW|Windows' . -g '!*.json' -g '!*.lock' | head -320 printf '%s\n' '--- relevant file outline and surrounding test sequence ---' ast-grep outline tests/VirtualMemoryAllocationTests.cpp sed -n '1,120p' tests/VirtualMemoryAllocationTests.cpp sed -n '340,470p' tests/VirtualMemoryAllocationTests.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 43182 --- 🏁 Script executed: ```bash set -eu printf '%s\n' '--- test references and entrypoint ---' rg -n -C 5 'TestWindowsMisalignedSysvHostEntry|sysv-align-only|VirtualMemoryAllocationTests|Test.*VirtualMemory' tests src CMakeLists.txt 2>/dev/null | head -240 printf '%s\n' '--- ABI and compiler configuration references ---' rg -n -C 4 'KYTY_SYSV_ABI|KYTY_MS_ABI|ms_abi|sysv_abi|force_align_arg_pointer|clang-cl|x86_64-w64|MinGW|Windows' . -g '!*.json' -g '!*.lock' | head -320 printf '%s\n' '--- relevant file outline and surrounding test sequence ---' ast-grep outline tests/VirtualMemoryAllocationTests.cpp sed -n '1,120p' tests/VirtualMemoryAllocationTests.cpp sed -n '340,470p' tests/VirtualMemoryAllocationTests.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 43857 --- </details> **Preserve Windows nonvolatile state across the SysV call.** `MisalignedSysvHostEntryTarget` uses the SysV ABI. That ABI permits the target to clobber `rsi` and `xmm6`–`xmm15`. The Windows-ABI caller expects these registers to survive, but the trampoline saves only `rdi` and `r12`. This test runs in the normal Windows test sequence. A target/compiler that uses these registers can corrupt live caller state after the trampoline returns. Save and restore `rsi` and `xmm6`–`xmm15` while retaining the deliberate stack misalignment. The impact is limited to this Windows test executable, so classify this as a minor issue rather than a major production stability issue. <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:26847c32e1c6a09a4b2faf8a --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 617e728
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-02 23:38 UTC · original · reviewed

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/VirtualMemoryAllocationTests.cpp (1)

319-330: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert the SysV target entry alignment.

sysv_body_rsp is captured after KYTY_SYSV_ABI applies force_align_arg_pointer, so it does not represent the target entry stack. If the trampoline enters the target with normal alignment, the target can still run and CaptureMsAbiEntryRsp() can still report 8. The test can therefore pass without detecting the regression.

Capture the post-CALL stack value in the trampoline and assert that it is 0 mod 16.

Suggested fix
 struct MisalignedSysvHostEntryState {
+	uintptr_t sysv_entry_rsp = 0;
 	bool      called        = false;
 	uintptr_t sysv_body_rsp = 0;
 	uintptr_t ms_entry_rsp  = 0;
 };
...
 	code.push(code.rdi);
 	code.push(code.r12);
 	code.mov(code.rdi, code.rcx);
+	code.mov(code.rax, code.rsp);
+	code.sub(code.rax, 8);
+	code.mov(code.qword[code.rdi], code.rax);
 	code.mov(code.rax, reinterpret_cast<uint64_t>(&MisalignedSysvHostEntryTarget));
 	code.call(code.rax);
...
 	Check(test, state.called, "misaligned SysV target was not called");
+	Check(test, (state.sysv_entry_rsp & 0x0f) == 0x00,
+	      "trampoline did not enter the SysV target with a misaligned stack");
 	Check(test, (state.ms_entry_rsp & 0x0f) == 0x08,

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 69546bec-de84-4903-b0b8-5f15017fc81f
📥 Commits

Reviewing files that changed from the base of the PR and between e317465d8a and 82193ca55c.

📒 Files selected for processing (2)
  • src/common/abi.h
  • tests/VirtualMemoryAllocationTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-02 23:38 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/990#pullrequestreview-5397880436) · **reviewed** **Actionable comments posted: 1** <details> <summary>🧹 Nitpick comments (1)</summary><blockquote> <details> <summary>tests/VirtualMemoryAllocationTests.cpp (1)</summary><blockquote> `319-330`: _🎯 Functional Correctness_ | _🔵 Trivial_ | _⚡ Quick win_ **Assert the SysV target entry alignment.** `sysv_body_rsp` is captured after `KYTY_SYSV_ABI` applies `force_align_arg_pointer`, so it does not represent the target entry stack. If the trampoline enters the target with normal alignment, the target can still run and `CaptureMsAbiEntryRsp()` can still report `8`. The test can therefore pass without detecting the regression. Capture the post-`CALL` stack value in the trampoline and assert that it is `0 mod 16`. <details> <summary>Suggested fix</summary> ```diff struct MisalignedSysvHostEntryState { + uintptr_t sysv_entry_rsp = 0; bool called = false; uintptr_t sysv_body_rsp = 0; uintptr_t ms_entry_rsp = 0; }; ... code.push(code.rdi); code.push(code.r12); code.mov(code.rdi, code.rcx); + code.mov(code.rax, code.rsp); + code.sub(code.rax, 8); + code.mov(code.qword[code.rdi], code.rax); code.mov(code.rax, reinterpret_cast<uint64_t>(&MisalignedSysvHostEntryTarget)); code.call(code.rax); ... Check(test, state.called, "misaligned SysV target was not called"); + Check(test, (state.sysv_entry_rsp & 0x0f) == 0x00, + "trampoline did not enter the SysV target with a misaligned stack"); Check(test, (state.ms_entry_rsp & 0x0f) == 0x08, ``` </details> <!-- cr-comment:v1:8ab383f5805f62f3ae32d714 --> </blockquote></details> </blockquote></details> --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `69546bec-de84-4903-b0b8-5f15017fc81f` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between e317465d8a773b33482ad367ad2f856154c8bc6d and 82193ca55ce21260a787fd1b6eb2d5858f1cc343. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `src/common/abi.h` * `tests/VirtualMemoryAllocationTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Author
Owner

@⁠theantipopau on GitHub · 2026-10-07 23:47 UTC · original

Integrated into our fork (theantipopau/KytyPS5 main, cherry-picks 324c6b52 + 475a42b0) on Windows x64 against current upstream/main (420bb51d):

  • Build clean (full all target).
  • virtual_memory_allocation_tests passes with the hardened alignment cases, both via ctest and a direct run: VirtualMemoryAllocationTests: all cases passed.
  • Applied on top of upstream's new agc: new abi (67d7db68) and the SysV/DLC scalar work without conflicts.

We exercise host-entry calls through real guest titles locally, so the Windows SysV realign matters on our path — confirmed no regression after integration.

**@⁠theantipopau** on GitHub · 2026-10-07 23:47 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/990#issuecomment-6049144995) Integrated into our fork (theantipopau/KytyPS5 `main`, cherry-picks `324c6b52` + `475a42b0`) on Windows x64 against current upstream/main (420bb51d): - Build clean (full `all` target). - `virtual_memory_allocation_tests` passes with the hardened alignment cases, both via ctest and a direct run: `VirtualMemoryAllocationTests: all cases passed`. - Applied on top of upstream's new `agc: new abi` (`67d7db68`) and the SysV/DLC scalar work without conflicts. We exercise host-entry calls through real guest titles locally, so the Windows SysV realign matters on our path — confirmed no regression after integration.
Author
Owner

@⁠Nmzik on GitHub · 2026-10-08 14:44 UTC · original

Invalid fix. Bug is somewhere else. Game is working fine

**@⁠Nmzik** on GitHub · 2026-10-08 14:44 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/990#issuecomment-6062407288) Invalid fix. Bug is somewhere else. Game is working fine

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.