feat(libc): optionally dump indirect memory in Windows crash reports #4780

Merged
ivica00 merged 2 commits from upstream-pr/4780 into main 2026-10-14 10:48:15 +00:00
ivica00 commented 2026-10-12 21:37:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ivica00 on 2026-10-12T21:37:53Z.


What

Windows crash reports show the words pointed to by registers, but stop before the structures those words reference. Set APS5_CRASH_INDIRECT_MEMORY=1 to include one additional pointer level: up to eight 64-byte blocks per register, labelled with the register, pointer offset and target address. The option is disabled when unset or empty. Executable targets and reads that fail or return fewer than 64 bytes are skipped through ReadProcessMemory.

This is a generic diagnostic aid.

Tested

  • Windows 11 x64, WinLibs GCC 15.2, Release, AMD Radeon RX 9070 XT.
  • windows_exceptions and guest_raise_exception: passed.
  • Rebased on current upstream/main and verified with tools/check_conventions.py --base upstream/main.

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
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4835284595 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4780). Originally posted by [ivica00](https://github.com/ivica00) on 2026-10-12T21:37:53Z. --- ### What Windows crash reports show the words pointed to by registers, but stop before the structures those words reference. Set `APS5_CRASH_INDIRECT_MEMORY=1` to include one additional pointer level: up to eight 64-byte blocks per register, labelled with the register, pointer offset and target address. The option is disabled when unset or empty. Executable targets and reads that fail or return fewer than 64 bytes are skipped through `ReadProcessMemory`. This is a generic diagnostic aid. ### Tested - Windows 11 x64, WinLibs GCC 15.2, Release, AMD Radeon RX 9070 XT. - `windows_exceptions` and `guest_raise_exception`: passed. - Rebased on current `upstream/main` and verified with `tools/check_conventions.py --base upstream/main`. ### Checklist - [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 - [x] GPUs tested: n/a - [x] AI-assisted: yes
adriadam10 commented 2026-10-13 15:27:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T15:27:08Z.

Review: CHANGES_REQUESTED


Thanks, the idea is fine and the code is small. One thing to fix:

  • core/libs/prx/libc/src/specifics/windows/CrashReport.cpp:285: GetEnvironmentVariableA("APS5_CRASH_INDIRECT_MEMORY", nullptr, 0) != 0 returns the required buffer size including the terminator when the variable exists, so an empty value returns 1 and enables the dump. The description and docs/user/USAGE.md say an empty variable keeps it disabled. Read the value into a small buffer and enable it only when it is non-empty (or exactly 1, and then say so in USAGE.md, which currently documents =1 while any value works).

Please also check the Windows build job once pushed (PR CI skips it; it runs on dispatch). Happy to merge after that.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5505997834 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4780#pullrequestreview-5505997834). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T15:27:08Z. **Review:** CHANGES_REQUESTED --- Thanks, the idea is fine and the code is small. One thing to fix: - `core/libs/prx/libc/src/specifics/windows/CrashReport.cpp:285`: `GetEnvironmentVariableA("APS5_CRASH_INDIRECT_MEMORY", nullptr, 0) != 0` returns the required buffer size including the terminator when the variable exists, so an empty value returns 1 and enables the dump. The description and `docs/user/USAGE.md` say an empty variable keeps it disabled. Read the value into a small buffer and enable it only when it is non-empty (or exactly `1`, and then say so in USAGE.md, which currently documents `=1` while any value works). Please also check the Windows build job once pushed (PR CI skips it; it runs on dispatch). Happy to merge after that.
ivica00 commented 2026-10-13 17:16:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ivica00 on 2026-10-13T17:16:50Z.


Thanks @adriadam10! Rebased onto current \upstream/main\ and updated the \APS5_CRASH_INDIRECT_MEMORY\ environment check to read into a buffer so that an unset or empty variable keeps the indirect memory dump disabled as documented in \USAGE.md.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6151109492 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4780#issuecomment-6151109492). Originally posted by [ivica00](https://github.com/ivica00) on 2026-10-13T17:16:50Z. --- Thanks @adriadam10! Rebased onto current \upstream/main\ and updated the \APS5_CRASH_INDIRECT_MEMORY\ environment check to read into a buffer so that an unset or empty variable keeps the indirect memory dump disabled as documented in \USAGE.md\.
github-actions[bot] commented 2026-10-13 18:37:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T18:37:08Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4855 docs/user/USAGE.md L175
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6152541217 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4780#issuecomment-6152541217). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T18:37:08Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4855 | `docs/user/USAGE.md` [L175](https://github.com/boykopovar/AnyPS5/blob/3e577edac2159830bd3befff32b3690fd54cfcfe/docs/user/USAGE.md#L175) | | |
gunerky commented 2026-10-13 19:11:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gunerky on 2026-10-13T19:11:37Z.


I checked the updated environment-value handling at PR head 139bc7b9816939bf9a00905cb12656d387cdcd2d on Windows x64, WinLibs GCC 15.2.0, optimized (-O3 -DNDEBUG) with native SEH defaults. The unset/empty fix works, and the advertised APS5_CRASH_INDIRECT_MEMORY=1 setting produces the expected indirect data.

One small boundary case remains: nonempty values that do not fit in the 16-byte buffer disable the option in my run.

Value Indirect blocks in the controlled fixture
Unset or empty none
1, 0, true, or 15 x characters present
16, 17, 255, or 4096 x characters none

At the longer lengths, GetEnvironmentVariableA returns the required size rather than successfully filling the buffer. Microsoft documents that the buffer contents are undefined in that case, so testing indirectBuffer[0] then does not reliably implement the description's nonempty-value rule. This is a configuration edge; =1 works normally.

The unchanged head CrashReport.cpp and CallTrace.cpp were compiled into an isolated probe with synthetic exception data and fixture-owned memory. Correct labels/data, read-only targets, and exclusion of executable/partial/unreadable targets passed; partial, unaligned and null register roots completed without indirect output. No game was used. This probe is not a full PR build and does not replace the requested Windows build job or validate concurrent mapping changes.

AI-assisted: yes; fixture, execution and result checking assisted by Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6153162871 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4780#issuecomment-6153162871). Originally posted by [gunerky](https://github.com/gunerky) on 2026-10-13T19:11:37Z. --- I checked the updated environment-value handling at PR head `139bc7b9816939bf9a00905cb12656d387cdcd2d` on Windows x64, WinLibs GCC 15.2.0, optimized (`-O3 -DNDEBUG`) with native SEH defaults. The unset/empty fix works, and the advertised `APS5_CRASH_INDIRECT_MEMORY=1` setting produces the expected indirect data. One small boundary case remains: nonempty values that do not fit in the 16-byte buffer disable the option in my run. | Value | Indirect blocks in the controlled fixture | | --- | --- | | Unset or empty | none | | `1`, `0`, `true`, or 15 `x` characters | present | | 16, 17, 255, or 4096 `x` characters | none | At the longer lengths, `GetEnvironmentVariableA` returns the required size rather than successfully filling the buffer. [Microsoft documents that the buffer contents are undefined in that case](https://learn.microsoft.com/en-us/windows/win32/api/processenv/nf-processenv-getenvironmentvariablea), so testing `indirectBuffer[0]` then does not reliably implement the description's nonempty-value rule. This is a configuration edge; `=1` works normally. The unchanged head `CrashReport.cpp` and `CallTrace.cpp` were compiled into an isolated probe with synthetic exception data and fixture-owned memory. Correct labels/data, read-only targets, and exclusion of executable/partial/unreadable targets passed; partial, unaligned and null register roots completed without indirect output. No game was used. This probe is not a full PR build and does not replace the requested Windows build job or validate concurrent mapping changes. AI-assisted: yes; fixture, execution and result checking assisted by Codex.
ivica00 commented 2026-10-13 20:27:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ivica00 on 2026-10-13T20:27:06Z.


Thanks @gunerky. The 16-byte buffer was the problem: when GetEnvironmentVariableA cannot store the value it returns the required size and leaves the buffer undefined, so indirectBuffer[0] was not a reliable nonempty check.

6d33b36e7 queries the required size with a null buffer instead. An unset variable returns 0 and an empty value returns 1, so both stay disabled. Any nonempty value, including ones longer than 15 characters, returns a size greater than 1 and enables the dump. USAGE.md is unchanged: unset or empty disables it, and any other value enables it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6154534826 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4780#issuecomment-6154534826). Originally posted by [ivica00](https://github.com/ivica00) on 2026-10-13T20:27:06Z. --- Thanks @gunerky. The 16-byte buffer was the problem: when `GetEnvironmentVariableA` cannot store the value it returns the required size and leaves the buffer undefined, so `indirectBuffer[0]` was not a reliable nonempty check. `6d33b36e7` queries the required size with a null buffer instead. An unset variable returns 0 and an empty value returns 1, so both stay disabled. Any nonempty value, including ones longer than 15 characters, returns a size greater than 1 and enables the dump. `USAGE.md` is unchanged: unset or empty disables it, and any other value enables it.
adriadam10 commented 2026-10-14 10:41:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T10:41:57Z.

Review: APPROVED


Checked the env-value handling (GetEnvironmentVariableA with a null buffer returns 0 unset, 1 empty, >1 otherwise, so > 1 matches USAGE.md), the readability/executable skips and the 64-byte read, and the libc build and ctest on Linux; the Windows job covers the rest. Merging once the Windows build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5516666786 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4780#pullrequestreview-5516666786). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T10:41:57Z. **Review:** APPROVED --- Checked the env-value handling (`GetEnvironmentVariableA` with a null buffer returns 0 unset, 1 empty, >1 otherwise, so `> 1` matches USAGE.md), the readability/executable skips and the 64-byte read, and the libc build and ctest on Linux; the Windows job covers the rest. Merging once the Windows build is green.
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!4780
No description provided.