loader: write the guest fault context into the log file #2227

Open
github-bot wants to merge 5 commits from github-bot/gh-2227 into main AGit
Owner

@⁠Nawid3333 on GitHub · 2026-11-12 05:34 UTC · original
Nawid3333:fix/fault-report-in-log → main · +172 −32 · 3 files · 5 commits · open

Cause

With file logging (_kyty.txt), Log::Write goes to a spdlog file sink and std::printf reaches only the console (Log::Initialize, src/common/logging/log.cpp). The host exception handler prints the guest fault context (thread, registers, the code bytes around pc, the top of the stack) with std::printf, then calls EXIT, which writes its error line with Log::WriteToConsoleAndLog. So the log attached to a report has the Unhandled host exception line but not the context. Of the 34 _kyty.txt attached to issues here that contain Unhandled host exception, one has the context block, and that one is a console capture saved under that name. #2206 is a recent example.

Change

  • First commit: the report moves unchanged into Loader::ReportUnhandledHostException, so a test can run it.
  • Second commit: the report formats the same lines into one buffer on the stack (fmt::basic_memory_buffer with fmt::format_to, so nothing is allocated before the output) and writes it with Log::WriteToConsoleAndLog, the call EXIT uses, before EXIT.

With file logging the block now reaches the console and the file. With console logging it is printed once, as before. With silent logging it still goes to the console.

Test

FaultReportReachesTheLogFile in virtual_memory_allocation_tests starts the test binary again with --fault-report <file>. That child turns on file logging and calls ReportUnhandledHostException with a made-up access violation whose pc and rsp point into two static arrays. The parent checks that the child ended through EXIT and that the file holds the error line, the context header with the thread and rax, the code row with the byte at pc, and the first stack row. A child that has not ended within the test's timeout is killed and the test fails. The child sets up only configuration and logging (third commit): the full test start reserves the guest memory, and on a Windows CI runner that reservation failed in the child, which then ended through EXIT before file logging was on.

  • First commit (main + the test): FaultReportReachesTheLogFile failed: the guest fault context is missing from the log file
  • Second commit: VirtualMemoryAllocationTests: all cases passed

(Local build: Windows 11, clang-cl.)

Fork CI (run): virtual_memory_allocation passed on Windows, Linux and macOS.

Written with Claude Code (AI): Claude Code wrote the change and the test and ran them; Claude Opus reviewed the diff.

**@⁠Nawid3333** on GitHub · 2026-11-12 05:34 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2227) `Nawid3333:fix/fault-report-in-log` → `main` · +172 −32 · 3 files · 5 commits · open ## Cause With file logging (`_kyty.txt`), `Log::Write` goes to a spdlog file sink and `std::printf` reaches only the console (`Log::Initialize`, src/common/logging/log.cpp). The host exception handler prints the guest fault context (thread, registers, the code bytes around pc, the top of the stack) with `std::printf`, then calls `EXIT`, which writes its error line with `Log::WriteToConsoleAndLog`. So the log attached to a report has the `Unhandled host exception` line but not the context. Of the 34 `_kyty.txt` attached to issues here that contain `Unhandled host exception`, one has the context block, and that one is a console capture saved under that name. #2206 is a recent example. ## Change - First commit: the report moves unchanged into `Loader::ReportUnhandledHostException`, so a test can run it. - Second commit: the report formats the same lines into one buffer on the stack (`fmt::basic_memory_buffer` with `fmt::format_to`, so nothing is allocated before the output) and writes it with `Log::WriteToConsoleAndLog`, the call `EXIT` uses, before `EXIT`. With file logging the block now reaches the console and the file. With console logging it is printed once, as before. With silent logging it still goes to the console. ## Test `FaultReportReachesTheLogFile` in `virtual_memory_allocation_tests` starts the test binary again with `--fault-report <file>`. That child turns on file logging and calls `ReportUnhandledHostException` with a made-up access violation whose pc and rsp point into two static arrays. The parent checks that the child ended through `EXIT` and that the file holds the error line, the context header with the thread and `rax`, the code row with the byte at pc, and the first stack row. A child that has not ended within the test's timeout is killed and the test fails. The child sets up only configuration and logging (third commit): the full test start reserves the guest memory, and on a Windows CI runner that reservation failed in the child, which then ended through `EXIT` before file logging was on. - First commit (main + the test): `FaultReportReachesTheLogFile failed: the guest fault context is missing from the log file` - Second commit: `VirtualMemoryAllocationTests: all cases passed` (Local build: Windows 11, clang-cl.) Fork CI ([run](https://github.com/Nawid3333/KytyPS5/actions/runs/43157715060)): `virtual_memory_allocation` passed on Windows, Linux and macOS. Written with Claude Code (AI): Claude Code wrote the change and the test and ran them; Claude Opus reviewed the diff.
The report of an unhandled host exception moves into
Loader::ReportUnhandledHostException, unchanged, so a test can run it.
FaultReportReachesTheLogFile runs the report in a child process that
logs to a file and checks the file for the error and the guest fault
context.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The context of an unhandled host exception (thread, registers, code
bytes and stack) was printed with std::printf. With file logging
std::printf reaches only the console, so _kyty.txt, the log attached to
reports, held the error line without the context. The report is now
built with the same formats and written with Log::WriteToConsoleAndLog,
as EXIT writes the error line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Windows CI runner cannot reserve the guest direct memory, so the
child's full subsystem start exited with 321 before file logging was
set up, and the test found an empty log file.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A signal delivered to the test process makes waitpid fail with EINTR;
the polling loop then stopped early and reported a timeout, and the
blocking wait after SIGKILL could leave the child unreaped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:17:19 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-12 05:37 UTC · original · edited 2026-11-23 23:47 UTC

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The exception handler now uses ReportUnhandledHostException to report unhandled host exceptions. The function formats guest fault context in a memory buffer and writes the report to the console and log. The test suite adds a child-process test that triggers a synthetic access violation and checks the log contents and child exit status.

Suggested reviewers: nmzik, ew-sudo

Change: Bug fix

Merge Risk: Minimal · up to 6b56e

Unhandled host exception reports now reach the log file as well as the console. No merge-blocking risk was identified in the supplied change.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "loader: write the guest fault context into the log file" matches the main change. The PR moves the unhandled host exception report into Loader::ReportUnhandledHostException and writes it th…
Description check Passed The description explains the cause (std::printf reaching only the console under file logging), the change (a new ReportUnhandledHostException function, a stack-buffer report sent through Log::WriteToC…
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: Title check

Explanation

The title "loader: write the guest fault context into the log file" matches the main change. The PR moves the unhandled host exception report into Loader::ReportUnhandledHostException and writes it through Log::WriteToConsoleAndLog, so the context reaches the file log. The title is specific and concise, and it follows the repository's scope-prefixed style.

Full details: Description check

Explanation

The description explains the cause (std::printf reaching only the console under file logging), the change (a new ReportUnhandledHostException function, a stack-buffer report sent through Log::WriteToConsoleAndLog before EXIT), and the test (FaultReportReachesTheLogFile with a child process). All of this matches the raw summary and the objectives.

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 22f880fc65 and 6b56e45e38.

Files selected for processing: 1

  • tests/VirtualMemoryAllocationTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-12 05:37 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2227#issuecomment-6815669067) · edited 2026-11-23 23:47 UTC <!-- coderabbit-ai-generated:v1 --> <!-- 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/2227?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-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_status_start --> No actionable comments were generated in the recent review. <!-- recent_review_status_end --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> <br> The exception handler now uses `ReportUnhandledHostException` to report unhandled host exceptions. The function formats guest fault context in a memory buffer and writes the report to the console and log. The test suite adds a child-process test that triggers a synthetic access violation and checks the log contents and child exit status. **Suggested reviewers:** `nmzik`, `ew-sudo` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"6b56e45e38582c7c733c9d262ec35fbb869e730d" --> <!-- change_assessment_priority:{"version":1,"urgency":"p3","manual":false} --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · up to <code>6b56e</code></summary> <dl> <dd> <br> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `6b56e` --> <!-- final_review_risk_coverage:{"sourceCommitId":"6b56e45e38582c7c733c9d262ec35fbb869e730d","coveredCommitId":"6b56e45e38582c7c733c9d262ec35fbb869e730d","kind":"reviewed"} --> Unhandled host exception reports now reach the log file as well as the console. No merge-blocking risk was identified in the supplied change. <!-- 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</strong></summary> <dl> <dd> <br> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title "loader: write the guest fault context into the log file" matches the main change. The PR moves the unhandled host exception report into Loader::ReportUnhandledHostException and writes it th… | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description explains the cause (std::printf reaching only the console under file logging), the change (a new ReportUnhandledHostException function, a stack-buffer report sent through Log::WriteToC… | | 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. | <details> <summary><strong>Full details: Title check</strong></summary> <dl> <dd> <br> **Explanation** The title "loader: write the guest fault context into the log file" matches the main change. The PR moves the unhandled host exception report into Loader::ReportUnhandledHostException and writes it through Log::WriteToConsoleAndLog, so the context reaches the file log. The title is specific and concise, and it follows the repository's scope-prefixed style. </dd> </dl> </details> <details> <summary><strong>Full details: Description check</strong></summary> <dl> <dd> <br> **Explanation** The description explains the cause (std::printf reaching only the console under file logging), the change (a new ReportUnhandledHostException function, a stack-buffer report sent through Log::WriteToConsoleAndLog before EXIT), and the test (FaultReportReachesTheLogFile with a child process). All of this matches the raw summary and the objectives. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=2227)! 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> <br> - [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> <!-- tips_end --> <!-- recent_review_start --> <h6> <details> <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Recent review info</strong></summary> <dl> <dd> <br> <!-- review_info_content --> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary> <dl> <dd> <br> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/4e90654506c8078649e2c1d22c763164406497da/.coderabbit.yaml>) - **Commit**: [4e90654](<https://github.com/KytyPS5/KytyPS5/commit/4e90654506c8078649e2c1d22c763164406497da>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `dcd69bf4-73cb-43c5-966e-846c4cd45e57` </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</strong></summary> <dl> <dd> <br> Reviewing files that changed from the base of the PR and between 22f880fc65dbb77c31e73c336d656c6e262e30d5 and 6b56e45e38582c7c733c9d262ec35fbb869e730d. </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 1</strong></summary> <dl> <dd> <br> * `tests/VirtualMemoryAllocationTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. </dd> </dl> </details> </h6> <!-- recent_review_end -->
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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