fix(libc): print sceLibcInternalHeapErrorReportForGame's report as a PS5 does #10236

Merged
orezraey merged 3 commits from upstream-pr/10236 into main 2026-10-24 15:16:57 +00:00
orezraey commented 2026-10-23 15:11:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-23T15:11:02Z.


What

sceLibcInternalHeapErrorReportForGame measured on a retail PS5 (firmware 13.60) through libSceLibcInternal.sprx from a payload process, with the call on a watchdog thread so a non-returning call could not block the loader. The sources and console logs are in this gist (pheaprep to pheaprep7; non-ASCII log bytes escaped as \xNN).

The console writes this to standard output, not standard error, and returns:

[SceLibc] A heap error is detected.
[SceLibc] -- Mspace Name --
[SceLibc] <name> (<number>)
[SceLibc] -- Error reason --
[SceLibc] segment out of range.
[SceLibc] pid:<0x7c> tid:<0x18c31>
  • <name> is the C string at heap + 0x3B0, read without a length limit.
  • (<number>) is the 32-bit value at heap + 0x3F4, printed with %2u ( ( 7), (4294967295)) and left out when it is 0.
  • The two reason lines appear for error 1 only. The 38 other values measured print none: 0, 2 to 15, 2^4 to 2^19, 2^24, 2^29 to 2^31, 0xFF, 0x7FFFFFFF and 0xFFFFFFFF (pheaprep4 and pheaprep5).
  • The output did not depend on the block's contents; with a valid heap the block was always a mapped page, so whether the console reads it is not shown. A null heap faults.

Before, AnyPS5 wrote one line with the three values to the host's standard error. It now writes the console's lines to the guest's standard output and keeps that diagnostic line on the host's standard error. The pid and tid are the host process's and thread's ids, where the console prints its own process and kernel thread ids. The block is not read here. A null heap throws. The debt entry is rewritten.

Tested

Windows 11, MinGW (winlibs).

  • guest_heap_report_for_game checks both reports (error 1 with a number, error 2 without), the pid, the host diagnostic and the throw for a null heap. It fails on main and passes three runs in a row with the change, as do the 24 other heap tests.
  • Linux (WSL2, kernel 6.18, GCC 16.2.1, Release): guest_heap_report_for_game builds and passes three runs in a row at f90172bf48, covering the syscall(SYS_gettid) path.
  • tools/check_conventions.py passes; tools/pr_overlap.py reports only shared debt files.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4984926209 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10236). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-23T15:11:02Z. --- ### What `sceLibcInternalHeapErrorReportForGame` measured on a retail PS5 (firmware 13.60) through `libSceLibcInternal.sprx` from a payload process, with the call on a watchdog thread so a non-returning call could not block the loader. The sources and console logs are in [this gist](https://gist.github.com/orezraey/788804e12128cadb1704868c705842b9) (`pheaprep` to `pheaprep7`; non-ASCII log bytes escaped as `\xNN`). The console writes this to standard output, not standard error, and returns: ``` [SceLibc] A heap error is detected. [SceLibc] -- Mspace Name -- [SceLibc] <name> (<number>) [SceLibc] -- Error reason -- [SceLibc] segment out of range. [SceLibc] pid:<0x7c> tid:<0x18c31> ``` - `<name>` is the C string at `heap + 0x3B0`, read without a length limit. - ` (<number>)` is the 32-bit value at `heap + 0x3F4`, printed with `%2u` (` ( 7)`, `(4294967295)`) and left out when it is 0. - The two reason lines appear for error 1 only. The 38 other values measured print none: 0, 2 to 15, 2^4 to 2^19, 2^24, 2^29 to 2^31, 0xFF, 0x7FFFFFFF and 0xFFFFFFFF (`pheaprep4` and `pheaprep5`). - The output did not depend on the block's contents; with a valid heap the block was always a mapped page, so whether the console reads it is not shown. A null heap faults. Before, AnyPS5 wrote one line with the three values to the host's standard error. It now writes the console's lines to the guest's standard output and keeps that diagnostic line on the host's standard error. The pid and tid are the host process's and thread's ids, where the console prints its own process and kernel thread ids. The block is not read here. A null heap throws. The debt entry is rewritten. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11, MinGW (winlibs). - `guest_heap_report_for_game` checks both reports (error 1 with a number, error 2 without), the pid, the host diagnostic and the throw for a null heap. It fails on `main` and passes three runs in a row with the change, as do the 24 other heap tests. - Linux (WSL2, kernel 6.18, GCC 16.2.1, Release): `guest_heap_report_for_game` builds and passes three runs in a row at f90172bf48, covering the `syscall(SYS_gettid)` path. - `tools/check_conventions.py` passes; `tools/pr_overlap.py` reports only shared debt files. ### 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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
harisibrar1 commented 2026-10-24 12:30:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T12:30:04Z.

Review: COMMENTED


Checked against main 87666fc5d6 and the gist 788804e121 (pheaprep–pheaprep7, probe.h):

  • The stdout claim holds up well: in pheaprep4, sending fd 2 to /dev/null still printed the report and sending fd 1 there silenced it. The offsets, (%2u), "omitted when 0" and the null-heap fault all match the logs too. Nice probes.
  • "Every power of two up to 2^31" doesn't match pheaprep5. Its 1u << (e - 16 + 4) loop covers 2^4–2^19, and the extra cases add 2^24 and 2^29–2^31, so 2^20–2^23 and 2^25–2^28 were never called. Could the description say which values were tested?
  • The debt entry's "40 other values" counts calls rather than values. pheaprep5's 40 calls include error 1 and three duplicates (0x100, 0x1000, 0x10000); with 0xff and 0xffffffff from pheaprep4, I count 38 distinct values other than 1.
  • "The block is not read" isn't shown either: with a valid heap the block was always fake+4096, which is mapped, and the null-block run also had a null heap. Perhaps "output does not depend on the block's contents; not read here" instead.
  • Small one: the pid is the host process id as well, not only the tid. Worth saying next to the tid note.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638240100 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10236#pullrequestreview-5638240100). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T12:30:04Z. **Review:** COMMENTED --- Checked against main 87666fc5d6 and the gist 788804e121 (pheaprep–pheaprep7, probe.h): - The stdout claim holds up well: in pheaprep4, sending fd 2 to /dev/null still printed the report and sending fd 1 there silenced it. The offsets, ` (%2u)`, "omitted when 0" and the null-heap fault all match the logs too. Nice probes. - "Every power of two up to 2^31" doesn't match pheaprep5. Its `1u << (e - 16 + 4)` loop covers 2^4–2^19, and the extra cases add 2^24 and 2^29–2^31, so 2^20–2^23 and 2^25–2^28 were never called. Could the description say which values were tested? - The debt entry's "40 other values" counts calls rather than values. pheaprep5's 40 calls include error 1 and three duplicates (0x100, 0x1000, 0x10000); with 0xff and 0xffffffff from pheaprep4, I count 38 distinct values other than 1. - "The block is not read" isn't shown either: with a valid heap the block was always fake+4096, which is mapped, and the null-block run also had a null heap. Perhaps "output does not depend on the block's contents; not read here" instead. - Small one: the pid is the host process id as well, not only the tid. Worth saying next to the tid note. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
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!10236
No description provided.