fix(libc): use the default heap for an executable without process parameters #11979

Merged
xXPBSXx merged 5 commits from upstream-pr/11979 into main 2026-10-28 22:49:55 +00:00
xXPBSXx commented 2026-10-27 14:23:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-27T14:23:04Z.


What

Carries #6713 (karimibrahim07, head 668d51adbd; both commits keep their authorship), rebased onto current main after a conflict in docs/dev/debt/libc.md, as offered in the hand-off comment on that PR. The rebase adds only the new "Application heap without process parameters" line to docs/dev/debt/libc.md. The review asked to reconcile this PR's debt notes with #10947 (merged on 27 October); after the rebase this PR adds only that one line to the debt file, and its own nearbyintf and _Thrd_sleep notes are no longer part of the diff. Whether the entries on main agree with each other is not checked here.

An ELF without a PT_SCE_PROCPARAM segment, such as a ps5-payload-dev SDK program, got no .procpar section when relinked for Windows. Its first allocation then stopped with application heap: process metadata is missing; relink the executable (read in the code, not run on the unchanged main). That message, added together with the .procpar writer in 9f2b41b9a1, asks for a relink, but relinking such an ELF cannot add process parameters it does not have.

  • WindowsPePatcher now writes a .procpar section with address 0 and size 0 when the ELF has no PT_SCE_PROCPARAM segment.
  • ApplicationProcessParameters_nid_no_patch returns a static zeroed 0x40-byte block for that record, so callers that read the compiled SDK version at offset 16 see 0.
  • ApplicationHeapInitialize_nid_no_patch recognises that block by its address and registers the heap's existing default allocator, as it already does for an all-null replacement table. sceKernelGetProcParam returns the result of that lookup, so it returns the same block (read in the code).

An executable without any .procpar section still gets the relink message (application_heap_stats_missing still passes). The new entry in docs/dev/debt/libc.md records that, on the console, such a program runs inside its launcher's process, whose parameters aren't modelled (this is the entry's wording, not something measured here). On Linux the process-parameter lookup is unchanged and still throws application heap: invalid or missing process parameters when it finds none (read in ApplicationProcessParameters.cpp, not run here).

Overlap: 170 of the 1295 open pull requests change at least one of the files this PR touches; git merge-tree of this branch with each of their heads, each on the merge base git finds, reports a conflict for 22 of them. 20 of those already conflict with main on their own (almost all in docs/dev/debt/libc.md), so this change adds no landing order for them. #11302 (in docs/dev/debt/libc.md) and #11463 (in core/relinker/CMakeLists.txt) conflict only with this branch; whichever lands second rebases and keeps both changes. The authors of #11302 and #11463 are asked here which of the pull requests should land first, and this PR waits for their answer before the landing order is fixed. No pull request of mine is a dependency (Depends on: none).

Tested

Windows 10 Pro (19045), WinLibs GCC 15.2.0 r7, Ninja Release, BUILD_TESTING=ON, and Ubuntu 24.04 under WSL2 (a virtualised kernel, not bare-metal; GCC 13.3, Release), both on main 8ff4baf534 with this branch on top; each arm built fresh (ninja exit code 0 read), 5 runs each:

  • Windows, this branch: application_heap* (10 tests, including the new application_heap_without_parameters) and the new relinker test windows_process_parameters pass, 11 of 11, in all five runs.
  • Windows, same main with ApplicationHeap.cpp, ApplicationProcessParameters.cpp and WindowsPePatcher.cpp reverted and the tests kept: 2 of 11 fail in all five runs. application_heap_without_parameters stops with exit code 0xc0000409, and windows_process_parameters fails.
  • Linux (WSL2), this branch: the application_heap* tests that exist on Linux and windows_process_parameters pass, 13 of 13, in all five runs. With the three files reverted, 1 of 13 fails in all five runs: windows_process_parameters.
  • Green arm repeated after the rebase onto main eece5da035 (before the final rebase onto 1089f2bbfd, which changes none of the PR's files or test targets): 3 runs each, Windows 11 of 11 and Linux (WSL2) 13 of 13.
  • Follow-up commit (zeroed block instead of null): Windows, 3 runs, 11 of 11 pass; with the production files of the previous head (0cb4dde2ee, which returns null) and the new test, application_heap_without_parameters fails in all three runs (1 of 11); Linux (WSL2), 3 runs, 13 of 13 pass. The callers that read offset 16 were not run.
  • A second run of the same head, built and run independently in a separate worktree and session on the same machine, gave the same result: on Windows 3 runs of 11 of 11, and with the three files reverted 2 of 11 failing in all three runs (the same two tests); on Linux (WSL2) 3 runs of 13 of 13. The Linux run with the files reverted was not repeated there.
  • python tools/check_conventions.py --base upstream/main passes with this title and description; git merge-tree against main 1089f2bbfd is clean.
  • Not run here: the full suite, macOS, and the Quake homebrew run described on #6713 (it needs #6697, #6702 and #6707).

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
  • Fixes: none
  • GPUs tested: n/a
  • AI-assisted: yes

Co-authored by the original author of #6713.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5035525227 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11979). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-27T14:23:04Z. --- ### What Carries #6713 (karimibrahim07, head `668d51adbd`; both commits keep their authorship), rebased onto current `main` after a conflict in `docs/dev/debt/libc.md`, as offered in [the hand-off comment](https://github.com/boykopovar/AnyPS5/pull/6713#issuecomment-6396477116) on that PR. The rebase adds only the new "Application heap without process parameters" line to `docs/dev/debt/libc.md`. The [review](https://github.com/boykopovar/AnyPS5/pull/6713#pullrequestreview-5643418084) asked to reconcile this PR's debt notes with #10947 (merged on 27 October); after the rebase this PR adds only that one line to the debt file, and its own `nearbyintf` and `_Thrd_sleep` notes are no longer part of the diff. Whether the entries on `main` agree with each other is not checked here. An ELF without a `PT_SCE_PROCPARAM` segment, such as a [ps5-payload-dev SDK](https://github.com/ps5-payload-dev/sdk) program, got no `.procpar` section when relinked for Windows. Its first allocation then stopped with `application heap: process metadata is missing; relink the executable` (read in the code, not run on the unchanged `main`). That message, added together with the `.procpar` writer in `9f2b41b9a1`, asks for a relink, but relinking such an ELF cannot add process parameters it does not have. - `WindowsPePatcher` now writes a `.procpar` section with address 0 and size 0 when the ELF has no `PT_SCE_PROCPARAM` segment. - `ApplicationProcessParameters_nid_no_patch` returns a static zeroed 0x40-byte block for that record, so callers that read the compiled SDK version at offset 16 see 0. - `ApplicationHeapInitialize_nid_no_patch` recognises that block by its address and registers the heap's existing default allocator, as it already does for an all-null replacement table. `sceKernelGetProcParam` returns the result of that lookup, so it returns the same block (read in the code). An executable without any `.procpar` section still gets the relink message (`application_heap_stats_missing` still passes). The new entry in `docs/dev/debt/libc.md` records that, on the console, such a program runs inside its launcher's process, whose parameters aren't modelled (this is the entry's wording, not something measured here). On Linux the process-parameter lookup is unchanged and still throws `application heap: invalid or missing process parameters` when it finds none (read in `ApplicationProcessParameters.cpp`, not run here). Overlap: 170 of the 1295 open pull requests change at least one of the files this PR touches; `git merge-tree` of this branch with each of their heads, each on the merge base git finds, reports a conflict for 22 of them. 20 of those already conflict with `main` on their own (almost all in `docs/dev/debt/libc.md`), so this change adds no landing order for them. #11302 (in `docs/dev/debt/libc.md`) and #11463 (in `core/relinker/CMakeLists.txt`) conflict only with this branch; whichever lands second rebases and keeps both changes. The authors of #11302 and #11463 are asked here which of the pull requests should land first, and this PR waits for their answer before the landing order is fixed. No pull request of mine is a dependency (`Depends on: none`). ### Tested Windows 10 Pro (19045), WinLibs GCC 15.2.0 r7, Ninja Release, `BUILD_TESTING=ON`, and Ubuntu 24.04 under WSL2 (a virtualised kernel, not bare-metal; GCC 13.3, Release), both on `main` `8ff4baf534` with this branch on top; each arm built fresh (ninja exit code 0 read), 5 runs each: - Windows, this branch: `application_heap*` (10 tests, including the new `application_heap_without_parameters`) and the new relinker test `windows_process_parameters` pass, 11 of 11, in all five runs. - Windows, same `main` with `ApplicationHeap.cpp`, `ApplicationProcessParameters.cpp` and `WindowsPePatcher.cpp` reverted and the tests kept: 2 of 11 fail in all five runs. `application_heap_without_parameters` stops with exit code `0xc0000409`, and `windows_process_parameters` fails. - Linux (WSL2), this branch: the `application_heap*` tests that exist on Linux and `windows_process_parameters` pass, 13 of 13, in all five runs. With the three files reverted, 1 of 13 fails in all five runs: `windows_process_parameters`. - Green arm repeated after the rebase onto `main` `eece5da035` (before the final rebase onto `1089f2bbfd`, which changes none of the PR's files or test targets): 3 runs each, Windows 11 of 11 and Linux (WSL2) 13 of 13. - Follow-up commit (zeroed block instead of null): Windows, 3 runs, 11 of 11 pass; with the production files of the previous head (`0cb4dde2ee`, which returns null) and the new test, `application_heap_without_parameters` fails in all three runs (1 of 11); Linux (WSL2), 3 runs, 13 of 13 pass. The callers that read offset 16 were not run. - A second run of the same head, built and run independently in a separate worktree and session on the same machine, gave the same result: on Windows 3 runs of 11 of 11, and with the three files reverted 2 of 11 failing in all three runs (the same two tests); on Linux (WSL2) 3 runs of 13 of 13. The Linux run with the files reverted was not repeated there. - `python tools/check_conventions.py --base upstream/main` passes with this title and description; `git merge-tree` against `main` `1089f2bbfd` is clean. - Not run here: the full suite, macOS, and the Quake homebrew run described on #6713 (it needs #6697, #6702 and #6707). ### 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] Fixes: none - [x] GPUs tested: n/a - [x] AI-assisted: yes Co-authored by the original author of #6713. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
rooklz commented 2026-10-28 05:35:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T05:35:33Z.

Review: COMMENTED


Reviewed the relinker half on the head 944b4d753e, merged onto main 895ead67f7. I could not build the libc half or its application_heap_without_parameters test: they are Windows-only, and I only have macOS here.

Ran

  • Relinker-only build of the merge, ctest 371 of 371 passed. The new windows_process_parameters test passes.
  • The windows-latest failure on this run is shader_cache_native_paths timing out after 20.36 s. This PR changes no shader files.
  • Section headers the relinker writes for main_fixture(): .procpar has RVA 0x11000, VirtualSize 8, SizeOfRawData 0, PointerToRawData 0, flags 0x40000040. The loader zero-fills it, so the reader gets address 0 and size 0, which is what the new branch in ApplicationProcessParameters_nid_no_patch expects.

Mutants of the WindowsPePatcher.cpp hunk, run against the new test

mutant result
hunk removed killed
std::vector<std::uint8_t>(8, 1) killed
empty data killed
std::vector<std::uint8_t>(4) survives
std::vector<std::uint8_t>(16) survives
flag 0x40u changed to 0x80u survives

Raw size and raw offset are both 0 here, so stored is b"" and the zero check passes whatever the section holds. The test only checks that the section exists. The reader rejects any VirtualSize other than 8 (invalid process metadata section), so mutants 4 and 16 would fail at runtime on Windows while this test still passes. This is not blocking, but one more assertion catches both of them. The head still passes with it:

import struct
...
        header, = struct.unpack_from("<I", data, 0x3C)
        optional_size, = struct.unpack_from("<H", data, header + 20)
        index = [section[0] for section in pe_sections(data)].index(b".procpar")
        virtual_size, = struct.unpack_from("<I", data, header + 24 + optional_size + index * 40 + 8)
        assert virtual_size == 8, virtual_size

I only read the libc side. Using found instead of result != nullptr keeps the duplicate check working when the empty record comes first. The new debt line says that returning a zeroed block, not null, from sceKernelGetProcParam has not been measured, which is right.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5678223726 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11979#pullrequestreview-5678223726). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-28T05:35:33Z. **Review:** COMMENTED --- Reviewed the relinker half on the head `944b4d753e`, merged onto `main` `895ead67f7`. I could not build the libc half or its `application_heap_without_parameters` test: they are Windows-only, and I only have macOS here. **Ran** - Relinker-only build of the merge, `ctest` 371 of 371 passed. The new `windows_process_parameters` test passes. - The `windows-latest` failure on this run is `shader_cache_native_paths` timing out after 20.36 s. This PR changes no shader files. - Section headers the relinker writes for `main_fixture()`: `.procpar` has RVA `0x11000`, VirtualSize 8, SizeOfRawData **0**, PointerToRawData **0**, flags `0x40000040`. The loader zero-fills it, so the reader gets address 0 and size 0, which is what the new branch in `ApplicationProcessParameters_nid_no_patch` expects. **Mutants of the `WindowsPePatcher.cpp` hunk, run against the new test** | mutant | result | |---|---| | hunk removed | killed | | `std::vector<std::uint8_t>(8, 1)` | killed | | empty data | killed | | `std::vector<std::uint8_t>(4)` | **survives** | | `std::vector<std::uint8_t>(16)` | **survives** | | flag `0x40u` changed to `0x80u` | survives | Raw size and raw offset are both 0 here, so `stored` is `b""` and the zero check passes whatever the section holds. The test only checks that the section exists. The reader rejects any VirtualSize other than 8 (`invalid process metadata section`), so mutants 4 and 16 would fail at runtime on Windows while this test still passes. This is not blocking, but one more assertion catches both of them. The head still passes with it: ```python import struct ... header, = struct.unpack_from("<I", data, 0x3C) optional_size, = struct.unpack_from("<H", data, header + 20) index = [section[0] for section in pe_sections(data)].index(b".procpar") virtual_size, = struct.unpack_from("<I", data, header + 24 + optional_size + index * 40 + 8) assert virtual_size == 8, virtual_size ``` I only read the libc side. Using `found` instead of `result != nullptr` keeps the duplicate check working when the empty record comes first. The new debt line says that returning a zeroed block, not null, from `sceKernelGetProcParam` has not been measured, which is right. AI-assisted: yes
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!11979
No description provided.