Skip to content

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

Open
krishalivaibhav wants to merge 2 commits into
boykopovar:mainfrom
krishalivaibhav:fix/macos-process-parameters-macho
Open

krishalivaibhav wants to merge 2 commits into
boykopovar:mainfrom
krishalivaibhav:fix/macos-process-parameters-macho

Conversation

@krishalivaibhav

@krishalivaibhav krishalivaibhav commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

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: feat(aot): consolidate native ARM64 compiler, runtime and consumers #5021 and Macos port #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

ApplicationProcessParameters used the dl_iterate_phdr search only on Linux,
so any guest using the application heap threw "unsupported executable
format" on macOS, where GuestImages.cpp already provides dl_iterate_phdr.
ProcessParametersFixture::Install also had no macOS branch and returned
false; it now fills a __APS5DATA,__meta section with version-2 relinker
metadata.

Co-authored-by: Himansh Raj <iamthehimansh@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

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 5021 core/libs/prx/libc/src/ApplicationProcessParameters.cpp
PR 6713 core/libs/prx/libc/src/ApplicationProcessParameters.cpp
core/libs/tests/ApplicationHeap.cpp
PR 7201 core/libs/prx/libc/src/ApplicationProcessParameters.cpp
core/libs/tests/ApplicationHeap.cpp

@MarcZX10

Copy link
Copy Markdown
Contributor

I compared the uncomparable patches for the exact changed function. Both open #5021 and #7201 already add the same two __APPLE__ condition changes to ApplicationProcessParameters.cpp that this PR adds. The new macOS fixture in this PR is additional, but the production change duplicates those branches. Please coordinate with the relevant authors on landing order and update Depends on; then rebase this PR so it retains the fixture without carrying a duplicate source change if one of those branches lands first. The local macOS integration results are author-reported; the upstream product test jobs are skipped on this PR. I am leaving it unapproved pending the overlap resolution.

@imellag imellag left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

ApplicationHeap installed process parameters only on Windows and Linux, so
application_heap_lazy had no way to do it on macOS. Use the shared fixture,
as a5a9184 does.

Co-authored-by: mugurc <mceker@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@krishalivaibhav

Copy link
Copy Markdown
Contributor Author

@imellag thanks for the A/B. I added the ApplicationHeap.cpp branch from mugurc's a5a9184e5c as a separate commit (d1f5a34), with mugurc credited as co-author. On M2, x86_64 Release, all 9 application_heap_* tests now pass, and guest_http, guest_rtc, guest_rtc_ps5_title and guest_ssl still pass.

@MarcZX10 agreed: the two __APPLE__ condition changes in ApplicationProcessParameters.cpp are also in #5021 and #7201. I updated the checklist to name both. @yabanana @marion909, would you be OK with this landing first, so your branches drop or keep those two lines on the next rebase? If you'd rather land yours first, I'll rebase this PR to keep only the test fixture and the ApplicationHeap.cpp change.

AI-assisted: yes (Claude Code)

@maximilianfv maximilianfv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants