fix: stop guest exits from running host teardown #1688

Closed
github-bot wants to merge 1 commit from gh-pr/1688/head into gh-pr/1688/base
Owner

@⁠joedeangelis533-bot on GitHub · 2026-10-19 03:39 UTC · original
joedeangelis533-bot:fix/guest-exit-host-teardown → main · +155 −20 · 6 files · 1 commits · closed without merging

Game problem

Mafia: The Old Country (PPSA14299) and Astro Bot (PPSA21564) are reported in #1540, section 4, to crash during guest exit when host teardown releases guest memory or configuration while other threads are still running. That report used a custom Linux build; its game runs have not been independently reproduced here.

On current upstream, both the libc and libkernel exit exports call host ::exit, which runs host atexit callbacks and static teardown before terminating the process.

Change

Register both exit NIDs against one SysV-ABI entry point that uses the existing Common::DbgExit routine. That runs the registered emergency cleanup callbacks, flushes C streams and calls std::_Exit, preserving the guest status while avoiding normal host teardown.

Add a regression executable to CMake/CTest, kyty_tests, and the Windows, Linux and macOS CI build/test selections. The test keeps another thread alive and checks exits from both the main thread and a worker.

This addresses the exit-time failure mechanism only. It does not fix the APR/content-loading or guest-stdout problems also described in #1540, so it should not close that whole issue. #1569 addresses the separate guest-stdout request.

Validation

Local Windows x86-64, Clang 23.1.3 / LLVM-MinGW, C++20:

  • All six native regression cases pass: requested statuses 0, 37 and 255, each from the main thread and a worker. They check the exact status, absence of host atexit teardown, execution of an emergency callback and flushed buffered C output.
  • A negative control using the original ::exit behavior reaches the host teardown guard in all six cases, returning 97 instead of the requested status.
  • The actual added CMake target and CTest registration configure, build and pass in an isolated project. It compiles the real guestExit.h, assert.cpp, subsystems.cpp and test source; only unrelated fatal-report logging functions are stubbed in that local harness.
  • Clean application of the exported patch matches the committed files, and rebuilding that copy passes all six cases. Executable and temporary-report paths containing spaces also pass.
  • Both modified production translation units pass C++20 syntax checks with the pinned fmt dependency.
  • New files pass the repository's clang-format 22.1.3 configuration. CI YAML parses, all three platform jobs select the test, and git diff --check passes.

The full emulator, the normal Visual Studio clang-cl build, Linux/macOS runtime tests and the commercial games have not been run locally. The isolated test build does not replace full project CI or game retesting.

Review points

Normal host destructors are deliberately skipped. Persistence must use the existing emergency callbacks or explicit flushing; destructor-only graphics cache persistence is separate work in #1312. The two exit exports also lose their former optional PRINT_NAME trace when sharing the entry point.

AI assistance

Prepared with Codex for the contributor, who explicitly directed submission of this patch. AI assistance covered investigation, implementation, regression tests, automated validation and this description. No independent human code review or commercial-game test result is claimed; the validation above was automated locally.

**@⁠joedeangelis533-bot** on GitHub · 2026-10-19 03:39 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1688) `joedeangelis533-bot:fix/guest-exit-host-teardown` → `main` · +155 −20 · 6 files · 1 commits · closed without merging ## Game problem Mafia: The Old Country (PPSA14299) and Astro Bot (PPSA21564) are reported in #1540, section 4, to crash during guest exit when host teardown releases guest memory or configuration while other threads are still running. That report used a custom Linux build; its game runs have not been independently reproduced here. On current upstream, both the libc and libkernel exit exports call host `::exit`, which runs host atexit callbacks and static teardown before terminating the process. ## Change Register both exit NIDs against one SysV-ABI entry point that uses the existing `Common::DbgExit` routine. That runs the registered emergency cleanup callbacks, flushes C streams and calls `std::_Exit`, preserving the guest status while avoiding normal host teardown. Add a regression executable to CMake/CTest, `kyty_tests`, and the Windows, Linux and macOS CI build/test selections. The test keeps another thread alive and checks exits from both the main thread and a worker. This addresses the exit-time failure mechanism only. It does not fix the APR/content-loading or guest-stdout problems also described in #1540, so it should not close that whole issue. #1569 addresses the separate guest-stdout request. ## Validation Local Windows x86-64, Clang 23.1.3 / LLVM-MinGW, C++20: - All six native regression cases pass: requested statuses 0, 37 and 255, each from the main thread and a worker. They check the exact status, absence of host atexit teardown, execution of an emergency callback and flushed buffered C output. - A negative control using the original `::exit` behavior reaches the host teardown guard in all six cases, returning 97 instead of the requested status. - The actual added CMake target and CTest registration configure, build and pass in an isolated project. It compiles the real `guestExit.h`, `assert.cpp`, `subsystems.cpp` and test source; only unrelated fatal-report logging functions are stubbed in that local harness. - Clean application of the exported patch matches the committed files, and rebuilding that copy passes all six cases. Executable and temporary-report paths containing spaces also pass. - Both modified production translation units pass C++20 syntax checks with the pinned fmt dependency. - New files pass the repository's clang-format 22.1.3 configuration. CI YAML parses, all three platform jobs select the test, and `git diff --check` passes. The full emulator, the normal Visual Studio clang-cl build, Linux/macOS runtime tests and the commercial games have not been run locally. The isolated test build does not replace full project CI or game retesting. ## Review points Normal host destructors are deliberately skipped. Persistence must use the existing emergency callbacks or explicit flushing; destructor-only graphics cache persistence is separate work in #1312. The two exit exports also lose their former optional `PRINT_NAME` trace when sharing the entry point. ## AI assistance Prepared with Codex for the contributor, who explicitly directed submission of this patch. AI assistance covered investigation, implementation, regression tests, automated validation and this description. No independent human code review or commercial-game test result is claimed; the validation above was automated locally.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:03:22 +00:00
github-bot closed this pull request 2026-11-26 10:03:22 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-19 03:43 UTC · original

Review in Change Stack →

📝 Walkthrough

The change adds Libs::GuestExit, which calls Common::DbgExit, and routes the guest exit exports in libC.cpp and libKernel.cpp to that function. It adds child-process tests for several exit statuses on main and worker threads, registers the tests with CMake, and selects them in the Windows, macOS, and Linux workflows.

Suggested reviewers: nmzik

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: 🔵 Low · up to 564d0

Guest exit behavior is tested, but a regression in either export binding could go undetected. Add binding coverage or accept that bounded gap before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 6.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 4 files. (2 skipped: 2… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the primary change: preventing guest exits from triggering host teardown.
Description check Passed The description directly explains the guest-exit issue, implementation, regression tests, validation, and known limitations.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 6.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 4 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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-19 03:43 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1688#issuecomment-6259168713) <!-- 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/1688?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> The change adds `Libs::GuestExit`, which calls `Common::DbgExit`, and routes the guest exit exports in `libC.cpp` and `libKernel.cpp` to that function. It adds child-process tests for several exit statuses on main and worker threads, registers the tests with CMake, and selects them in the Windows, macOS, and Linux workflows. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬇️ Low <!-- change_assessment_commit:"564d066807da14ff61891609929ee590bc22fd76" --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>🔵 Low</strong> · up to <code>564d0</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🔵 Low** · up to `564d0` --> <!-- final_review_risk_coverage:{"sourceCommitId":"564d066807da14ff61891609929ee590bc22fd76","coveredCommitId":"564d066807da14ff61891609929ee590bc22fd76","kind":"reviewed"} --> Guest exit behavior is tested, but a regression in either export binding could go undetected. Add binding coverage or accept that bounded gap before merging. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 warning</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :----------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Warning](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg) | Docstring coverage is 6.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 4 files. (2 skipped: 2… | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly summarizes the primary change: preventing guest exits from triggering host teardown. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the guest-exit issue, implementation, regression tests, validation, and known limitations. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **Explanation** Docstring coverage is 6.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 4 files. (2 skipped: 2 unsupported.) **Resolution** Write docstrings for the functions missing them to satisfy the coverage threshold. </dd> </dl> </details> </dd> </dl> </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">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1688)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [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) </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-19 03:43 UTC · original · reviewed

🧹 Nitpick comments: 1
tests/GuestExitTests.cpp: 1

55-70: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Exercise the exported NIDs in this regression test.

GuestExitTests.cpp calls Libs::GuestExit(status) directly. It never resolves or invokes uMei1W9uyNo or 6Z83sYWFlA8. Reverting either LIB_FUNC binding to the former ::exit wrapper therefore leaves all six cases testing the unchanged helper. Resolve both NIDs and invoke the resulting KYTY_SYSV_ABI function pointers in the child cases, using a target that links the corresponding library initializers.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e6ec303a-4bfc-4ad7-baa2-cc9f78010ff1
📥 Commits

Reviewing files that changed from the base of the PR and between 099de8dea6 and 564d066807.

📒 Files selected for processing: 6
  • .github/workflows/build.yml
  • CMakeLists.txt
  • src/libs/guestExit.h
  • src/libs/libC.cpp
  • src/libs/libKernel.cpp
  • tests/GuestExitTests.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-19 03:43 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1688#pullrequestreview-5566659093) · **reviewed** <details> <summary>🧹 Nitpick comments: 1</summary><blockquote> <details> <summary>tests/GuestExitTests.cpp: 1</summary><blockquote> `55-70`: **📐 Maintainability & Code Quality** | **🔵 Trivial** | **🏗️ Heavy lift** **Exercise the exported NIDs in this regression test.** `GuestExitTests.cpp` calls `Libs::GuestExit(status)` directly. It never resolves or invokes `uMei1W9uyNo` or `6Z83sYWFlA8`. Reverting either `LIB_FUNC` binding to the former `::exit` wrapper therefore leaves all six cases testing the unchanged helper. Resolve both NIDs and invoke the resulting `KYTY_SYSV_ABI` function pointers in the child cases, using a target that links the corresponding library initializers. <!-- cr-comment:v1:4b16a0742ddd7f73fe32d604 --> </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**: `e6ec303a-4bfc-4ad7-baa2-cc9f78010ff1` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 099de8dea62cbf17c8e06a6c24e72b38475d1566 and 564d066807da14ff61891609929ee590bc22fd76. </details> <details> <summary>📒 Files selected for processing: 6</summary> * `.github/workflows/build.yml` * `CMakeLists.txt` * `src/libs/guestExit.h` * `src/libs/libC.cpp` * `src/libs/libKernel.cpp` * `tests/GuestExitTests.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 --> <!-- coderabbit-review-publication v1 publication=252f9fa1-6be4-47de-9e2b-b69a60721fb5 attempt=9145407f-3466-4ff7-a7f1-3f604f05031d batch=1/1 -->

Pull request closed

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