Skip to content

feat(libkernel): answer kern.proc.env for the calling process - #9736

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
LeandroLP23:feat/libkernel-kern-proc-env
Oct 23, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
LeandroLP23:feat/libkernel-kern-proc-env

Conversation

@LeandroLP23

@LeandroLP23 LeandroLP23 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What

PS5VR (PPSA99177) stops at start-up, right after it loads libSceVrTracker2:

what():  sysctl_nid_postfix: unsupported MIB 1.14.35.12828

That MIB is {CTL_KERN, KERN_PROC, KERN_PROC_ENV, pid}, and the title asks for its own pid. sysctl now answers it as FreeBSD 11's sysctl_kern_proc_env does for the calling process:

  • It returns the process's start-up environment strings. AnyPS5 starts a title with an empty environment: the environ libkernel exports and libc's getenv both begin empty. So the call returns 0 bytes. FreeBSD reads the start-up strings, not later setenv changes, so those changes don't show up there either.
  • EINVAL for a MIB without exactly one pid. ESRCH for any other pid, -1 included, as pget gives. EPERM for a write. These are the same rules as the kern.proc.vmmap handler next to it.

Which variables, if any, the console starts an application with is unverified. That is recorded in docs/dev/debt/libkernel.md.

Tested

Windows 11, Ryzen AI 7 350 / Radeon 860M, WinLibs GCC 15.2, Release.

  • PS5VR (PPSA99177, catalog 1.2.0), 40 s runs:
    • main cc00785: the title ends with the unsupported MIB 1.14.35.<pid> exception above.
    • This PR, rebased on main 8b3a6ba (run again after the rebase): it gets past the call and lists its library (library: list Library -> ok, 7 items). It then shows its TV screen: the PS5VR logo, "Put on your PlayStation VR2" and the phone-link QR code. It also logs vr: headset setup failed, as expected with no PlayStation VR2 attached (sceHmd2Initialize -> 0x81110016).
  • guest_system_configuration has a new CheckEnvSysctl, which covers:
    • the size query and the read for the own pid: 0 bytes, buffer untouched, errno unchanged;
    • a write;
    • a foreign pid and pid -1;
    • a MIB that is too short and one that is too long.
      It fails on main's SystemConfiguration.cpp and passes with this change. ctest -R "sysctl|system_config|guest_process": 6 of 6 pass.
  • python tools/check_conventions.py --base origin/main passes.
  • tools/pr_overlap.py on the rebased branch:

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: PPSA99177 Homebrew catalog on main d8888df9b (Windows, AMD): 23 titles reach their own UI #5745
  • GPUs tested: n/a
  • AI-assisted: yes

@github-actions github-actions Bot added the unblocks title Names a title ID on the Unblocks line label Oct 22, 2026
@github-actions

github-actions Bot commented Oct 22, 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 docs/dev/debt/libkernel.md
PR 6044 core/libs/tests/GuestSystemConfiguration.cpp
PR 6149 docs/dev/debt/libkernel.md
PR 6469 docs/dev/debt/libkernel.md
PR 6740 docs/dev/debt/libkernel.md
PR 6830 docs/dev/debt/libkernel.md
PR 6936 docs/dev/debt/libkernel.md
PR 7049 docs/dev/debt/libkernel.md
PR 7088 docs/dev/debt/libkernel.md
PR 7105 docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7509 docs/dev/debt/libkernel.md
PR 7511 docs/dev/debt/libkernel.md
PR 7565 docs/dev/debt/libkernel.md
PR 7653 docs/dev/debt/libkernel.md
PR 8010 docs/dev/debt/libkernel.md
PR 8448 docs/dev/debt/libkernel.md
PR 8520 docs/dev/debt/libkernel.md
PR 8553 core/libs/prx/libkernel/System/src/SystemConfiguration.cpp
core/libs/tests/GuestSystemConfiguration.cpp
docs/dev/debt/libkernel.md
PR 9133 docs/dev/debt/libkernel.md
PR 9160 docs/dev/debt/libkernel.md
PR 9284 docs/dev/debt/libkernel.md
PR 9293 docs/dev/debt/libkernel.md
PR 9297 docs/dev/debt/libkernel.md
PR 9302 docs/dev/debt/libkernel.md
PR 9561 docs/dev/debt/libkernel.md
PR 9575 docs/dev/debt/libkernel.md
PR 9669 docs/dev/debt/libkernel.md
PR 9693 docs/dev/debt/libkernel.md

@MarcZX10

Copy link
Copy Markdown
Contributor

I checked this against current main: the PR is 11 commits behind, although it still merges cleanly. Please refresh the branch and rerun the focused sysctl/system-configuration tests and overlap check against the current tree before merge. The title-specific Unblocks: PPSA99177 #5745 entry is present; the hosted full Linux/Windows jobs are skipped on PRs by repository policy.

PS5VR (PPSA99177) reads sysctl {CTL_KERN, KERN_PROC, KERN_PROC_ENV, pid}
for its own pid at start-up and stopped on "unsupported MIB 1.14.35.<pid>".
The call now returns the empty start-up environment that environ and
libc's getenv also begin with, and follows FreeBSD 11's
sysctl_kern_proc_env for the errors: EINVAL for a MIB without exactly one
pid, ESRCH for another pid or -1, EPERM for a write.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LeandroLP23
LeandroLP23 force-pushed the feat/libkernel-kern-proc-env branch from b436f15 to 6e1df42 Compare October 22, 2026 12:57
@LeandroLP23

Copy link
Copy Markdown
Contributor Author

Rebased on current main 8b3a6ba (0 behind), head 6e1df42. Full build on Windows (WinLibs GCC 15.2, Release), then:

The PR description is updated to match.

@harisibrar1 harisibrar1 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.

Checked against main 3ca07d0 and FreeBSD releng/11.4 sys/kern/kern_proc.c (sysctl_kern_proc_env, lines 1975-2001, node flags at 2956):

  • The errors match FreeBSD 11.4: EINVAL when namelen != 1, ESRCH from pget for a foreign pid and for -1, and EPERM for a write from the CTLFLAG_RD node before the handler runs. The EPERM-before-EINVAL order in the new branch matches too.
  • 0 bytes is consistent with main: environ_nid_postfix starts as emptyEnvironment (libkernel/System/src/Process.cpp:224) and libc's table starts empty (libc/src/Environment.cpp:26). The console's real start-up environment is recorded in the debt entry.
  • No commit since cc00785 touches the three files, so the refresh MarcZX10 asked for should be conflict-free.
  • Optional nit: CopyOut(nullptr, 0, ...) ends in std::memcpy(oldValue, nullptr, 0), which is formally UB even with a zero length. A one-byte static empty buffer as the source would sidestep it. Not blocking.

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

@oneandonlydean oneandonlydean self-assigned this Oct 22, 2026
@oneandonlydean
oneandonlydean merged commit dd5b2a3 into boykopovar:main Oct 23, 2026
12 checks passed
@LeandroLP23
LeandroLP23 deleted the feat/libkernel-kern-proc-env branch October 23, 2026 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs libkernel unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants