fix(macos): read application process parameters from Mach-O images #10876

Merged
krishalivaibhav merged 2 commits from upstream-pr/10876 into main 2026-10-27 06:58:53 +00:00
krishalivaibhav commented 2026-10-25 07:10:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by krishalivaibhav on 2026-10-25T07:10:12Z.


What

On macOS, any guest that uses the application heap threw unsupported executable format. The reason is that ApplicationProcessParameters_nid_no_patch only searched for the process parameters with dl_iterate_phdr on Linux. macOS already provides dl_iterate_phdr through GuestImages.cpp, so this PR widens the two #elif defined(__linux__) checks in ApplicationProcessParameters.cpp to || defined(__APPLE__).

ProcessParametersFixture::Install had no macOS branch and returned false. It now fills a __APS5DATA,__meta section with version-2 relinker metadata, which is the same layout the Linux branch builds.

The Linux and Windows branches are unchanged. The fixture change follows iamthehimansh's feat/macos-port (#8658), and iamthehimansh is credited as co-author.

Tested

macOS: Apple Silicon M2, macOS 27.2, AppleClang, x86_64 Release, on a local integration of main + #10419 + #10366 + #10369 + #7631 + #7804 + #4630 + #10552 + #10853 + this commit:

  • guest_http, guest_rtc, guest_rtc_ps5_title and guest_ssl pass (they failed before);
  • guest_ssl_transport_kernel and guest_ssl_transport_net also need the separate libSceSsl symbol PR;
  • all 9 application_heap_* tests pass (with the ApplicationHeap.cpp commit, from mugurc's a5a9184e5c);
  • ctest -R '^(guest_|libc_|libkernel_)': no new failures.

Building on macOS needs #10552 and the PRs listed above.

Linux/Windows: not built locally. Only __APPLE__ branches are added.

Checklist

  • Based on current main. Overlap: #5021 and #7201 also add the two __APPLE__ conditions in ApplicationProcessParameters.cpp; the test fixture and the ApplicationHeap.cpp change are only here
  • 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
  • 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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5002648171 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10876). Originally posted by [krishalivaibhav](https://github.com/krishalivaibhav) on 2026-10-25T07:10:12Z. --- ### What On macOS, any guest that uses the application heap threw `unsupported executable format`. The reason is that `ApplicationProcessParameters_nid_no_patch` only searched for the process parameters with `dl_iterate_phdr` on Linux. macOS already provides `dl_iterate_phdr` through `GuestImages.cpp`, so this PR widens the two `#elif defined(__linux__)` checks in `ApplicationProcessParameters.cpp` to `|| defined(__APPLE__)`. `ProcessParametersFixture::Install` had no macOS branch and returned false. It now fills a `__APS5DATA,__meta` section with version-2 relinker metadata, which is the same layout the Linux branch builds. The Linux and Windows branches are unchanged. The fixture change follows iamthehimansh's `feat/macos-port` (#8658), and iamthehimansh is credited as co-author. ### Tested macOS: Apple Silicon M2, macOS 27.2, AppleClang, x86_64 Release, on a local integration of `main` + #10419 + #10366 + #10369 + #7631 + #7804 + #4630 + #10552 + #10853 + this commit: - `guest_http`, `guest_rtc`, `guest_rtc_ps5_title` and `guest_ssl` pass (they failed before); - `guest_ssl_transport_kernel` and `guest_ssl_transport_net` also need the separate libSceSsl symbol PR; - all 9 `application_heap_*` tests pass (with the `ApplicationHeap.cpp` commit, from mugurc's `a5a9184e5c`); - `ctest -R '^(guest_|libc_|libkernel_)'`: no new failures. Building on macOS needs #10552 and the PRs listed above. Linux/Windows: not built locally. Only `__APPLE__` branches are added. ### Checklist - [x] Based on current `main`. Overlap: #5021 and #7201 also add the two `__APPLE__` conditions in `ApplicationProcessParameters.cpp`; the test fixture and the `ApplicationHeap.cpp` change are only here - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository - [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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
imellag commented 2026-10-25 08:56:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-25T08:56:15Z.

Review: DISMISSED


Tested head cb2416f8c2 on Apple M4 Pro, macOS 27.0.1, Apple clang 21, x86-64 under Rosetta 2. The tree is main 61fc572cee plus the open macOS build PRs and the parts of mugurc's series that #7201 also carries. Only this change was toggled, with main's versions of ApplicationProcessParameters.cpp, ProcessParametersFixture.hpp and ApplicationHeap.cpp as the base.

ctest -R '^guest_' -j6 (672 tests): 39 fail without this PR, 17 with it, and none fails only with it. The 22 that now pass are:

  • guest_appcontent, guest_coredump_attach, guest_coredump_user_data, guest_hmd, guest_hmd2, guest_http, guest_kernel_sys_sdk_version;
  • guest_np_commerce_dialog, guest_rtc, guest_rtc_ps5_title, guest_screenshot, guest_screenshot_large_overlay, guest_ssl, guest_usb_storage_dialog, guest_vr_tracker2;
  • the eight guest_convert_keycode* tests.

Requested change. application_heap_scripting and application_heap_lazy still abort with this PR, because ApplicationHeap.cpp installs the process parameters itself and has no macOS branch. mugurc's a5a9184e5c adds one with the fixture this PR now fills:

#elif defined(__APPLE__)
#include "ProcessParametersFixture.hpp"
#endif
...
#elif defined(__APPLE__)
    require(ProcessParametersFixture::Install(process.data(), process.size()));
#endif

With those four lines added to this PR, all 9 application_heap_* tests pass. Without them, 7 of 9 pass, the same as on main. Since this PR is what makes the fixture work on macOS, could you add them here, so the application heap tests get the same fix as the others?

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5642354458 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10876#pullrequestreview-5642354458). Originally posted by [imellag](https://github.com/imellag) on 2026-10-25T08:56:15Z. **Review:** DISMISSED --- Tested head `cb2416f8c2` on Apple M4 Pro, macOS 27.0.1, Apple clang 21, x86-64 under Rosetta 2. The tree is `main` `61fc572cee` plus the open macOS build PRs and the parts of mugurc's series that #7201 also carries. Only this change was toggled, with `main`'s versions of `ApplicationProcessParameters.cpp`, `ProcessParametersFixture.hpp` and `ApplicationHeap.cpp` as the base. `ctest -R '^guest_' -j6` (672 tests): 39 fail without this PR, 17 with it, and none fails only with it. The 22 that now pass are: - `guest_appcontent`, `guest_coredump_attach`, `guest_coredump_user_data`, `guest_hmd`, `guest_hmd2`, `guest_http`, `guest_kernel_sys_sdk_version`; - `guest_np_commerce_dialog`, `guest_rtc`, `guest_rtc_ps5_title`, `guest_screenshot`, `guest_screenshot_large_overlay`, `guest_ssl`, `guest_usb_storage_dialog`, `guest_vr_tracker2`; - the eight `guest_convert_keycode*` tests. **Requested change.** `application_heap_scripting` and `application_heap_lazy` still abort with this PR, because `ApplicationHeap.cpp` installs the process parameters itself and has no macOS branch. mugurc's `a5a9184e5c` adds one with the fixture this PR now fills: ```cpp #elif defined(__APPLE__) #include "ProcessParametersFixture.hpp" #endif ... #elif defined(__APPLE__) require(ProcessParametersFixture::Install(process.data(), process.size())); #endif ``` With those four lines added to this PR, all 9 `application_heap_*` tests pass. Without them, 7 of 9 pass, the same as on `main`. Since this PR is what makes the fixture work on macOS, could you add them here, so the application heap tests get the same fix as the others? AI-assisted: yes
maximilianfv commented 2026-10-25 13:20:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by maximilianfv on 2026-10-25T13:20:33Z.

Review: APPROVED


Approving: on macOS the two __APPLE__ conditions and the fixture fix all 24 tests that abort for lack of process parameters, in 3 of 3 runs, and none of the 40 tests I ran fails with it. The three items below are small and none of them blocks merging.

Tested on Apple M1 Pro, macOS 27.0.1 (x86_64 build under Rosetta 2)

Applied at d1f5a3410a to mugurc's macOS series (27e968974) merged with main at 2742004ed2, with other open macOS fixes. The series already carries near-identical macOS branches in all three files this PR touches, so for both arms those three files were reset to main's content. The rest of the series stayed in place, and only this PR's diff was toggled. 40 tests (application_heap_* plus every guest_* test whose source includes ProcessParametersFixture.hpp, plus 7 neighbouring tests the name prefixes matched), 3 runs per arm:

application_heap_* (9) the 22 fixture guest_* tests guest_ssl_transport_kernel, _net other 7
Without this PR 7 pass. scripting and lazy abort with application heap: unsupported executable format all abort or fail. Install returns false (process parameters were not installed) fail pass
With this PR 9 pass 22 pass fail, same check: a server certificate without a loaded CA passed the initial verify options pass

The same results came up in all 3 runs of each arm. The SSL transport failure is the separate libSceSsl gap that the description already names.

Findings (non-blocking)

  1. core/libs/tests/ProcessParametersFixture.hpp:96: headers[0].p_flags is left at 0. In a fixture test that registers the main image (GuestAllocationsRegisterMainImage, reached from sceKernelMapDirectMemory), collectImagePages in core/libs/prx/libc/src/GuestAllocations.cpp:286-287 then marks the page of process as neither readable nor writable, although the test writes to it. None of the 40 tests fails from it. Fix: headers[0].p_flags = PF_W; (PF_W is in main's ElfTypes.hpp, PF_R is not, and collectImagePages treats PF_W as readable and writable). GuestFlexibleMemoryModule.cpp sets PF_R | PF_W on its header.
  2. Credit: closed #7332 (ycarogabriel-lgtm, opened 2026-10-18) has the same ApplicationProcessParameters.cpp change (same blob pair, 5efa1f00d31..8a556bd0e01) and the first macOS __APS5DATA,__meta fixture. mugurc's a5a9184e5c names it ("#7332 makes the same change to the fixture"). Please link #7332 under What and add a Co-authored-by: for its author to cb2416f8c2, next to the #8658 credit.
  3. Description:
    • The fixture's layout is the one the macOS relinker writes (MacOsImage.cpp) and GuestImages.cpp reads. The Linux branch builds no such layout: it rewrites a spare program header in place. "the same layout the Linux branch builds" should say so.
    • ctest -R '^(guest_|libc_|libkernel_)': no test names start with libc_ or libkernel_, so that run covered only guest_*.

AI-assisted: yes (Claude Code applied the PR, ran the tests, read the code and wrote this review).

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643364412 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10876#pullrequestreview-5643364412). Originally posted by [maximilianfv](https://github.com/maximilianfv) on 2026-10-25T13:20:33Z. **Review:** APPROVED --- Approving: on macOS the two `__APPLE__` conditions and the fixture fix all 24 tests that abort for lack of process parameters, in 3 of 3 runs, and none of the 40 tests I ran fails with it. The three items below are small and none of them blocks merging. ### Tested on Apple M1 Pro, macOS 27.0.1 (x86_64 build under Rosetta 2) Applied at `d1f5a3410a` to mugurc's macOS series (`27e968974`) merged with `main` at `2742004ed2`, with other open macOS fixes. The series already carries near-identical macOS branches in all three files this PR touches, so for both arms those three files were reset to `main`'s content. The rest of the series stayed in place, and only this PR's diff was toggled. 40 tests (`application_heap_*` plus every `guest_*` test whose source includes `ProcessParametersFixture.hpp`, plus 7 neighbouring tests the name prefixes matched), 3 runs per arm: | | `application_heap_*` (9) | the 22 fixture `guest_*` tests | `guest_ssl_transport_kernel`, `_net` | other 7 | |---|---|---|---|---| | Without this PR | 7 pass. `scripting` and `lazy` abort with `application heap: unsupported executable format` | all abort or fail. `Install` returns false (`process parameters were not installed`) | fail | pass | | With this PR | 9 pass | 22 pass | fail, same check: `a server certificate without a loaded CA passed the initial verify options` | pass | The same results came up in all 3 runs of each arm. The SSL transport failure is the separate libSceSsl gap that the description already names. ### Findings (non-blocking) 1. `core/libs/tests/ProcessParametersFixture.hpp:96`: `headers[0].p_flags` is left at 0. In a fixture test that registers the main image (`GuestAllocationsRegisterMainImage`, reached from `sceKernelMapDirectMemory`), `collectImagePages` in `core/libs/prx/libc/src/GuestAllocations.cpp:286-287` then marks the page of `process` as neither readable nor writable, although the test writes to it. None of the 40 tests fails from it. Fix: `headers[0].p_flags = PF_W;` (`PF_W` is in `main`'s `ElfTypes.hpp`, `PF_R` is not, and `collectImagePages` treats `PF_W` as readable and writable). `GuestFlexibleMemoryModule.cpp` sets `PF_R | PF_W` on its header. 2. Credit: closed #7332 (ycarogabriel-lgtm, opened 2026-10-18) has the same `ApplicationProcessParameters.cpp` change (same blob pair, `5efa1f00d31..8a556bd0e01`) and the first macOS `__APS5DATA,__meta` fixture. mugurc's `a5a9184e5c` names it ("#7332 makes the same change to the fixture"). Please link #7332 under `What` and add a `Co-authored-by:` for its author to `cb2416f8c2`, next to the #8658 credit. 3. Description: - The fixture's layout is the one the macOS relinker writes (`MacOsImage.cpp`) and `GuestImages.cpp` reads. The Linux branch builds no such layout: it rewrites a spare program header in place. "the same layout the Linux branch builds" should say so. - `ctest -R '^(guest_|libc_|libkernel_)'`: no test names start with `libc_` or `libkernel_`, so that run covered only `guest_*`. AI-assisted: yes (Claude Code applied the PR, ran the tests, read the code and wrote this review).
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!10876
No description provided.