fix(libkernel): estimate kern.proc.proc with five extra records, as FreeBSD 11.4 does #22014

Merged
brajankw merged 1 commit from upstream-pr/22014 into main 2026-11-18 04:20:40 +00:00
brajankw commented 2026-11-17 01:32:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by brajankw on 2026-11-17T01:32:43Z.


What

sysctl {CTL_KERN, KERN_PROC, KERN_PROC_PROC} with a null output reported the size of the one record it returns. FreeBSD 11.4's sysctl_kern_proc adds five kinfo_proc records to a null-output query ("overestimate by 5 procs") before it counts the processes (the kern.proc.proc entry in docs/dev/debt/libkernel.md).

  • A null output now reports six records' size, 6 × 1,088 bytes. The records written to a buffer, and ENOMEM for a short one, are unchanged.
  • GuestSystemConfiguration.cpp: the size query with three and with four MIB elements gives 6 × 1,088; sysctlbyname("kern.proc.proc") gives the same size.
  • The debt fragment records the estimate; the console's answer stays unverified.

Tested

Linux (Debian 13, GCC 14.2.0, Release), on main ab5089590a.

  • ctest -R '^guest_system_configuration$': passed.
  • Negative control: with main's SystemConfiguration.cpp and this branch's test, guest_system_configuration aborts at the size check.
  • Full ctest (5893 tests, -j 12) with this branch merged together with my other three branches of this batch: 5877 passed. The 16 failures are the set that fails on main in the same environment: six agc_driver cases (agc_driver_image_table_packed_guards passes when run on its own) and ten that need a .git directory, network or a passwd entry for the user.
  • python3 tools/check_conventions.py --base origin/main: passed.
  • python3 tools/pr_overlap.py --branch: no overlap with open pull requests. It also merges cleanly with #21986, which edits another branch of the same sysctl function.
  • Not tested on Windows or macOS. No title.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5348644405 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22014). Originally posted by [brajankw](https://github.com/brajankw) on 2026-11-17T01:32:43Z. --- ### What `sysctl` {`CTL_KERN`, `KERN_PROC`, `KERN_PROC_PROC`} with a null output reported the size of the one record it returns. FreeBSD 11.4's [`sysctl_kern_proc`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_proc.c) adds five `kinfo_proc` records to a null-output query ("overestimate by 5 procs") before it counts the processes (the `kern.proc.proc` entry in `docs/dev/debt/libkernel.md`). - A null output now reports six records' size, 6 × 1,088 bytes. The records written to a buffer, and `ENOMEM` for a short one, are unchanged. - `GuestSystemConfiguration.cpp`: the size query with three and with four MIB elements gives 6 × 1,088; `sysctlbyname("kern.proc.proc")` gives the same size. - The debt fragment records the estimate; the console's answer stays unverified. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Linux (Debian 13, GCC 14.2.0, Release), on `main` `ab5089590a`. - `ctest -R '^guest_system_configuration$'`: passed. - Negative control: with `main`'s `SystemConfiguration.cpp` and this branch's test, `guest_system_configuration` aborts at the size check. - Full `ctest` (5893 tests, `-j 12`) with this branch merged together with my other three branches of this batch: 5877 passed. The 16 failures are the set that fails on `main` in the same environment: six `agc_driver` cases (`agc_driver_image_table_packed_guards` passes when run on its own) and ten that need a `.git` directory, network or a passwd entry for the user. - `python3 tools/check_conventions.py --base origin/main`: passed. - `python3 tools/pr_overlap.py --branch`: no overlap with open pull requests. It also merges cleanly with #21986, which edits another branch of the same `sysctl` function. - Not tested on Windows or macOS. No title. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-17 01:35:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T01:35:47Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against b130917876:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_system_configuration_tests built cleanly.
  • CTest (guest_system_configuration):
    1/1 Test #5368: guest_system_configuration .......   Passed    0.08 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libkernel/System/src/SystemConfiguration.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #5368: guest_system_configuration .......Subprocess aborted***Exception:   0.42 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified sysctl_nid_postfix kern.proc.proc handler in core/libs/prx/libkernel/System/src/SystemConfiguration.cpp handles oldValue == nullptr by invoking CopyOut with EstimatedExtraProcesses + 1 records (6 * sizeof(GuestKinfoProc)).
    • Verified CopyOut behavior when oldValue == nullptr: it correctly writes the required length into oldLength via GuestCopyOut_nid_no_patch if oldLength != nullptr, and returns 0 without dereferencing oldValue.
    • Verified non-null buffer path retains existing single-process record output behavior and correctly returns ENOMEM (12) when capacity < sizeof(GuestKinfoProc).
    • Verified docs/dev/debt/changes/fix-libkernel-sysctl-proc-list-size-estimate.md follows the required technical debt fragment format and conforms strictly to AGENTS.md rules.
    • Verified test coverage in core/libs/tests/GuestSystemConfiguration.cpp asserts the 6 * 1088 byte length estimate for both 3-element and 4-element MIB queries.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5931181173 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22014#pullrequestreview-5931181173). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-17T01:35:47Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `b130917876`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_system_configuration_tests` built cleanly. - **CTest** (`guest_system_configuration`): ``` 1/1 Test #5368: guest_system_configuration ....... Passed 0.08 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libkernel/System/src/SystemConfiguration.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #5368: guest_system_configuration .......Subprocess aborted***Exception: 0.42 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified sysctl_nid_postfix kern.proc.proc handler in core/libs/prx/libkernel/System/src/SystemConfiguration.cpp handles oldValue == nullptr by invoking CopyOut with EstimatedExtraProcesses + 1 records (6 * sizeof(GuestKinfoProc)). - Verified CopyOut behavior when oldValue == nullptr: it correctly writes the required length into oldLength via GuestCopyOut_nid_no_patch if oldLength != nullptr, and returns 0 without dereferencing oldValue. - Verified non-null buffer path retains existing single-process record output behavior and correctly returns ENOMEM (12) when capacity < sizeof(GuestKinfoProc). - Verified docs/dev/debt/changes/fix-libkernel-sysctl-proc-list-size-estimate.md follows the required technical debt fragment format and conforms strictly to AGENTS.md rules. - Verified test coverage in core/libs/tests/GuestSystemConfiguration.cpp asserts the 6 * 1088 byte length estimate for both 3-element and 4-element MIB queries. Looks Good To Me
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!22014
No description provided.