feat(libc): print the text that registers point at in Windows crash reports #5962

Merged
nikowolf123 merged 1 commit from upstream-pr/5962 into main 2026-10-17 04:51:44 +00:00
nikowolf123 commented 2026-10-14 17:13:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-14T17:13:57Z.


What

Several Unreal titles on Windows end in their own libc fatal path with the LowLevelFatalError message in a register, as UTF-16. For each register, the crash report prints the eight 64-bit words it points at (CrashReport.cpp:341), so it shows only the first 64 bytes of that message, which is 32 UTF-16 characters:

  • Demon Slayer PPSA03490 (#4238): [r13] "LowLevelFatalError [File:Unknown] ..." (UTF-16, the dump shows 64 bytes). The reporter wrote that the text of the fatal error is not established. Other runs of it stopped on the same out-of-memory allocation as Sifu PPSA03001, whose log prints the message (#3209 comment).
  • Stray PPSA02100 (#4238 comment): the buffer at r12 starts with LowLevelFatalError [File:Unknown]. The text is unknown because the dump keeps 64 bytes.
  • Lies of P PPSA10261 (#4238 comment): the same register signature (rax deadbeefcafebabe, read of 0xffffffffffffffff in the title's libc.prx). The comment shows no message.
  • Returnal PPSA01285 (#4239 comment): the message turned out to be PS5 Out of Memory. It was first found by reading the title's image (the UTF-16 format string before the fatal call), not in the report.

With this change, the report prints the text at such a register up to its NUL (at most 512 characters), so the next report of a stop like the Stray one shows the message instead of its first 32 characters, as far as it is printable ASCII.

After the register memory dump, the report now checks every general register except rsp. If a register points at readable memory that starts with at least four printable ASCII characters, it prints that text, as UTF-16LE (checked first) or as single bytes. The new Windows test's report contains, among other lines:

  [r12] "allocation failed in the heap"
  [r13] u"LowLevelFatalError [File:Unknown] [Line: 42] Out of memory"
  [r14] "PAGE END"...
  • Printable means 0x20 to 0x7e, tab, line feed and carriage return. Tabs, line breaks, quotes and backslashes are escaped, so each register stays on one line.
  • The text ends at a NUL, at the first other character, after 512 characters, at the end of readable memory, or when the 960-byte line buffer is full. ... after the closing quote means that no NUL ended it within those limits.
  • The bytes are read with the report's existing ReadCode (L193-L203), which checks the first page and every following page with VirtualQuery before reading it. Values below 0x10000 are skipped. It reads at most 1026 bytes per register.
  • The buffers are static, as in ReportCallTrace, so a stack-overflow report does not need 2 KiB more stack. The report already runs once per process.
  • It is on by default, unlike APS5_CRASH_INDIRECT_MEMORY, because a register that points at anything else adds no line.

The formatting is in core/libs/prx/libc/include/CrashText.hpp, a header without Windows calls, so its test runs on Linux too. There is no Linux crash report to extend: the whole of CrashReport.cpp is inside #ifdef _WIN32, and on Linux no host code prints the registers of a fault.

docs/user/USAGE.md describes the new lines under "Windows crash diagnostics".

#4855 (@fdfawef324) also changes CrashReport.cpp. It adds failure-report hooks after the thread list. git merge-tree merges this branch cleanly with #4855's head 82de94cbe and with main e34c47921.

Tested

Windows 11 Pro 10.0.26200 with WinLibs GCC 15.2.0 r7 (x86_64-ucrt-posix-seh), Release, Ninja, -DBUILD_TESTING=ON. I built libc and the test targets below and ran them with ctest --output-on-failure --timeout 120:

  • crash_text, windows_crash_text, windows_backtrace_report, undeliverable_host_exception and windows_exceptions: 5/5 pass.
  • windows_crash_text alone: 20 of 20 repeats pass.
  • main's CrashReport.cpp with the rest of this branch: windows_crash_text fails with Required regular expression not found. Its report has only the hex-word lines for r12 and r13.

windows_crash_text loads libc.prx and sets r12 to an ASCII string, r13 to a UTF-16 string, r14 to 8 text bytes that end at a PAGE_NOACCESS page, and rbx to 8 bytes that are not text. It then reads address 8. The test passes when the report shows the three lines above and no text line for rbx. The report also prints text lines for rcx, rdx and r11, which held the same pointers. crash_text checks the formatter in 15 cases: NUL-terminated, cut off by the end of the buffer, cut off by a non-ASCII unit, too short, a pointer value, the 512-character limit (with and without a NUL right after it), a full output buffer (also in the middle of an escape) and escaping.

Linux (WSL Ubuntu, GCC 15.2.0, Release): crash_text passes, and tools/check_test_registration.py build reports 843 test executable(s), 0 built and not run as recorded, none new. CrashText.cpp built directly with g++ -O2 -fsanitize=address,undefined also passes.

main's tools/check_conventions.py --base origin/main passes with this title and body.

Not tested with a game: I have no PS5 dumps.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none (diagnostic for the LowLevelFatalError stops on #4238)
  • GPUs tested: n/a
  • AI-assisted: yes. Written with Claude Code; I reviewed every line and ran the tests above.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4861611146 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5962). Originally posted by [nikowolf123](https://github.com/nikowolf123) on 2026-10-14T17:13:57Z. --- ### What Several Unreal titles on Windows end in their own libc fatal path with the `LowLevelFatalError` message in a register, as UTF-16. For each register, the crash report prints the eight 64-bit words it points at ([`CrashReport.cpp:341`](https://github.com/boykopovar/AnyPS5/blob/a453108cf7768b71879b0e832d367a935c43440d/core/libs/prx/libc/src/specifics/windows/CrashReport.cpp#L341)), so it shows only the first 64 bytes of that message, which is 32 UTF-16 characters: - Demon Slayer PPSA03490 ([#4238](https://github.com/boykopovar/AnyPS5/issues/4238)): `[r13] "LowLevelFatalError [File:Unknown] ..." (UTF-16, the dump shows 64 bytes)`. The reporter wrote that the text of the fatal error is not established. Other runs of it stopped on the same out-of-memory allocation as Sifu PPSA03001, whose log prints the message ([#3209 comment](https://github.com/boykopovar/AnyPS5/issues/3209#issuecomment-6115162714)). - Stray PPSA02100 ([#4238 comment](https://github.com/boykopovar/AnyPS5/issues/4238#issuecomment-6118786117)): the buffer at `r12` starts with `LowLevelFatalError [File:Unknown]`. The text is unknown because the dump keeps 64 bytes. - Lies of P PPSA10261 ([#4238 comment](https://github.com/boykopovar/AnyPS5/issues/4238#issuecomment-6124570982)): the same register signature (`rax deadbeefcafebabe`, read of `0xffffffffffffffff` in the title's `libc.prx`). The comment shows no message. - Returnal PPSA01285 ([#4239 comment](https://github.com/boykopovar/AnyPS5/issues/4239#issuecomment-6116628324)): the message turned out to be `PS5 Out of Memory`. It was first found by reading the title's image (the UTF-16 format string before the fatal call), not in the report. With this change, the report prints the text at such a register up to its NUL (at most 512 characters), so the next report of a stop like the Stray one shows the message instead of its first 32 characters, as far as it is printable ASCII. After the register memory dump, the report now checks every general register except `rsp`. If a register points at readable memory that starts with at least four printable ASCII characters, it prints that text, as UTF-16LE (checked first) or as single bytes. The new Windows test's report contains, among other lines: ``` [r12] "allocation failed in the heap" [r13] u"LowLevelFatalError [File:Unknown] [Line: 42] Out of memory" [r14] "PAGE END"... ``` - Printable means 0x20 to 0x7e, tab, line feed and carriage return. Tabs, line breaks, quotes and backslashes are escaped, so each register stays on one line. - The text ends at a NUL, at the first other character, after 512 characters, at the end of readable memory, or when the 960-byte line buffer is full. `...` after the closing quote means that no NUL ended it within those limits. - The bytes are read with the report's existing `ReadCode` ([L193-L203](https://github.com/boykopovar/AnyPS5/blob/a453108cf7768b71879b0e832d367a935c43440d/core/libs/prx/libc/src/specifics/windows/CrashReport.cpp#L193-L203)), which checks the first page and every following page with `VirtualQuery` before reading it. Values below 0x10000 are skipped. It reads at most 1026 bytes per register. - The buffers are static, as in `ReportCallTrace`, so a stack-overflow report does not need 2 KiB more stack. The report already runs once per process. - It is on by default, unlike `APS5_CRASH_INDIRECT_MEMORY`, because a register that points at anything else adds no line. The formatting is in `core/libs/prx/libc/include/CrashText.hpp`, a header without Windows calls, so its test runs on Linux too. There is no Linux crash report to extend: the whole of `CrashReport.cpp` is inside `#ifdef _WIN32`, and on Linux no host code prints the registers of a fault. `docs/user/USAGE.md` describes the new lines under "Windows crash diagnostics". #4855 (@fdfawef324) also changes `CrashReport.cpp`. It adds failure-report hooks after the thread list. `git merge-tree` merges this branch cleanly with #4855's head `82de94cbe` and with `main` `e34c47921`. ### Tested Windows 11 Pro 10.0.26200 with WinLibs GCC 15.2.0 r7 (`x86_64-ucrt-posix-seh`), Release, Ninja, `-DBUILD_TESTING=ON`. I built `libc` and the test targets below and ran them with `ctest --output-on-failure --timeout 120`: - `crash_text`, `windows_crash_text`, `windows_backtrace_report`, `undeliverable_host_exception` and `windows_exceptions`: 5/5 pass. - `windows_crash_text` alone: 20 of 20 repeats pass. - `main`'s `CrashReport.cpp` with the rest of this branch: `windows_crash_text` fails with `Required regular expression not found`. Its report has only the hex-word lines for `r12` and `r13`. `windows_crash_text` loads `libc.prx` and sets `r12` to an ASCII string, `r13` to a UTF-16 string, `r14` to 8 text bytes that end at a `PAGE_NOACCESS` page, and `rbx` to 8 bytes that are not text. It then reads address 8. The test passes when the report shows the three lines above and no text line for `rbx`. The report also prints text lines for `rcx`, `rdx` and `r11`, which held the same pointers. `crash_text` checks the formatter in 15 cases: NUL-terminated, cut off by the end of the buffer, cut off by a non-ASCII unit, too short, a pointer value, the 512-character limit (with and without a NUL right after it), a full output buffer (also in the middle of an escape) and escaping. Linux (WSL Ubuntu, GCC 15.2.0, Release): `crash_text` passes, and `tools/check_test_registration.py build` reports `843 test executable(s), 0 built and not run as recorded, none new`. `CrashText.cpp` built directly with `g++ -O2 -fsanitize=address,undefined` also passes. `main`'s `tools/check_conventions.py --base origin/main` passes with this title and body. Not tested with a game: I have no PS5 dumps. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none (diagnostic for the `LowLevelFatalError` stops on #4238) - [x] GPUs tested: n/a - [x] AI-assisted: yes. Written with Claude Code; I reviewed every line and ran the tests above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-14 17:17:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T17:17:52Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4891 docs/user/USAGE.md
PR 5021 core/libs/CMakeLists.txt
docs/user/USAGE.md
PR 5390 docs/user/USAGE.md
PR 5925 docs/user/USAGE.md
PR 6044 core/libs/CMakeLists.txt
PR 6222 core/libs/CMakeLists.txt
PR 6771 docs/user/USAGE.md
PR 6946 docs/user/USAGE.md
PR 6947 docs/user/USAGE.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6174092315 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5962#issuecomment-6174092315). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T17:17:52Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 4891](https://www.github.com/boykopovar/AnyPS5/pull/4891) | `docs/user/USAGE.md` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/CMakeLists.txt`<br>`docs/user/USAGE.md` | | [PR 5390](https://www.github.com/boykopovar/AnyPS5/pull/5390) | `docs/user/USAGE.md` | | [PR 5925](https://www.github.com/boykopovar/AnyPS5/pull/5925) | `docs/user/USAGE.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/CMakeLists.txt` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `core/libs/CMakeLists.txt` | | [PR 6771](https://www.github.com/boykopovar/AnyPS5/pull/6771) | `docs/user/USAGE.md` | | [PR 6946](https://www.github.com/boykopovar/AnyPS5/pull/6946) | `docs/user/USAGE.md` | | [PR 6947](https://www.github.com/boykopovar/AnyPS5/pull/6947) | `docs/user/USAGE.md` |
adriadam10 commented 2026-10-16 19:22:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T19:22:48Z.


Checked the formatter's bounds (output capacity, escape at the limit, 512-character cap, odd sizes) and the reads through ReadCode; crash_text passes on Linux. main had moved (a new include next to yours in CrashReport.cpp), so I rebased and resolved it. Merging once the Windows Build is green; windows_crash_text is the evidence for the new report lines.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6223012230 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5962#issuecomment-6223012230). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-16T19:22:48Z. --- Checked the formatter's bounds (output capacity, escape at the limit, 512-character cap, odd sizes) and the reads through `ReadCode`; `crash_text` passes on Linux. `main` had moved (a new include next to yours in `CrashReport.cpp`), so I rebased and resolved it. Merging once the Windows Build is green; `windows_crash_text` is the evidence for the new report lines.
adriadam10 commented 2026-10-16 19:37:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T19:37:04Z.


Re-checked on the rebased head merged onto current main: no conflicts, crash_text passes on Linux, formatter bounds and ReadCode reads unchanged from the earlier review. Merging once the Windows Build is green; windows_crash_text is the evidence for the new report lines.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6223252541 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5962#issuecomment-6223252541). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-16T19:37:04Z. --- Re-checked on the rebased head merged onto current `main`: no conflicts, `crash_text` passes on Linux, formatter bounds and `ReadCode` reads unchanged from the earlier review. Merging once the Windows Build is green; `windows_crash_text` is the evidence for the new report lines.
adriadam10 commented 2026-10-16 21:38:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T21:38:54Z.


main added a test block next to yours in core/libs/CMakeLists.txt; I rebased and placed the crash_text blocks before it (no other change). crash_text passes on Linux, formatter bounds and ReadCode reads unchanged from the earlier review. Merging once the Windows Build is green; windows_crash_text is the evidence for the new report lines.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6225198644 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5962#issuecomment-6225198644). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-16T21:38:54Z. --- `main` added a test block next to yours in `core/libs/CMakeLists.txt`; I rebased and placed the `crash_text` blocks before it (no other change). `crash_text` passes on Linux, formatter bounds and `ReadCode` reads unchanged from the earlier review. Merging once the Windows Build is green; `windows_crash_text` is the evidence for the new report lines.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!5962
No description provided.