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

Merged
LeandroLP23 merged 1 commit from upstream-pr/9736 into main 2026-10-23 08:47:33 +00:00
LeandroLP23 commented 2026-10-22 10:58:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-22T10:58:44Z.


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 cc0078595d: the title ends with the unsupported MIB 1.14.35.<pid> exception above.
    • This PR, rebased on main 8b3a6ba88d (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:
    • #8910 edits the docs/dev/debt/libkernel.md line after kern.proc.vmmap, so the new entry sits before kern.proc.vmmap instead. A local merge of #8910 into this branch is clean.
    • #8553 edits the same three files for other MIBs (kern.smp.maxcpus, kern.stackprot, kern.sched.name, kern.timecounter.hardware). It already conflicts with main in docs/dev/debt/libSceIme.md, a file this PR doesn't touch.

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 #5745
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4966247837 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9736). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-22T10:58:44Z. --- ### 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`](https://github.com/freebsd/freebsd-src/blob/releng/11.0/sys/kern/kern_proc.c) 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` cc0078595d: the title ends with the `unsupported MIB 1.14.35.<pid>` exception above. - This PR, rebased on `main` 8b3a6ba88d (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: - #8910 edits the `docs/dev/debt/libkernel.md` line after `kern.proc.vmmap`, so the new entry sits before `kern.proc.vmmap` instead. A local merge of #8910 into this branch is clean. - #8553 edits the same three files for other MIBs (`kern.smp.maxcpus`, `kern.stackprot`, `kern.sched.name`, `kern.timecounter.hardware`). It already conflicts with `main` in `docs/dev/debt/libSceIme.md`, a file this PR doesn't touch. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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] Fixes: none - [x] Unblocks: PPSA99177 #5745 - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-22 11:54:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T11:54:45Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6340107368 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9736#issuecomment-6340107368). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T11:54:45Z. --- 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.
LeandroLP23 commented 2026-10-22 12:57:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-22T12:57:42Z.


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

  • ctest -R "sysctl|system_config|guest_process": 6 of 6 pass, guest_system_configuration included.
  • PS5VR (PPSA99177), 40 s: it gets past the sysctl call and reaches library: list Library -> ok, 7 items, as before the rebase.
  • check_conventions.py --base origin/main passes.
  • pr_overlap.py: #8910 changed the debt line right after kern.proc.vmmap, where the new entry was, so I moved the entry one line up, before kern.proc.vmmap. A local merge of #8910 into this branch is now clean. #8553 already conflicts with main in docs/dev/debt/libSceIme.md, which this PR doesn't touch.

The PR description is updated to match.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6341320431 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9736#issuecomment-6341320431). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-22T12:57:42Z. --- Rebased on current `main` 8b3a6ba88d (0 behind), head 6e1df42286. Full build on Windows (WinLibs GCC 15.2, Release), then: - `ctest -R "sysctl|system_config|guest_process"`: 6 of 6 pass, `guest_system_configuration` included. - PS5VR (PPSA99177), 40 s: it gets past the `sysctl` call and reaches `library: list Library -> ok, 7 items`, as before the rebase. - `check_conventions.py --base origin/main` passes. - `pr_overlap.py`: #8910 changed the debt line right after `kern.proc.vmmap`, where the new entry was, so I moved the entry one line up, before `kern.proc.vmmap`. A local merge of #8910 into this branch is now clean. #8553 already conflicts with `main` in `docs/dev/debt/libSceIme.md`, which this PR doesn't touch. The PR description is updated to match.
harisibrar1 commented 2026-10-22 13:08:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T13:08:06Z.

Review: APPROVED


Checked against main 3ca07d086d 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 cc0078595d 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5614691165 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9736#pullrequestreview-5614691165). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-22T13:08:06Z. **Review:** APPROVED --- Checked against main 3ca07d086d 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 cc0078595d 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.
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!9736
No description provided.