feat(libkernel): handle sysctl queries for pathname, physmem and cacheline size #3779

Merged
pushkarreddyy merged 1 commit from upstream-pr/3779 into main 2026-10-11 22:48:36 +00:00
pushkarreddyy commented 2026-10-11 16:40:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-11T16:40:06Z.


What

This pull request implements missing sysctl and sysctlbyname hardware and process queries in libkernel:

  • kern.proc.pathname (MIB {1, 14, 12, pid}):
    • Returns /app0/eboot.bin for pid -1 and the calling process (getpid()), matching FreeBSD 11.4 sys/kern/kern_proc.c sysctl_kern_proc_pathname and the sandbox filesystem layout.
    • Returns ESRCH (3) for any other pid.
    • Returns EINVAL (22) when invoked via sysctlbyname or when the MIB does not have exactly one pid argument (nameLength != 4).
    • Resolves startup stop in XPSemu (PPSA97358: qemu_init queries {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}).
  • machdep.cacheline_size:
    • Returns -1 with ENOENT (2), matching FreeBSD amd64 where this powerpc-specific sysctl OID is not defined. Leaves the caller buffer untouched so XPSemu falls back cleanly to its built-in CPU cacheline default.
    • Resolves startup crash in XPSemu (PPSA97358: static constructor aborts before main on what(): sysctlbyname_nid_postfix: unsupported name machdep.cacheline_size).
  • hw.physmem (name and MIB {6, 5}):
    • Reports physical host memory in bytes (sysconf(_SC_PHYS_PAGES) * 0x4000), matching FreeBSD kern_mib.c.
    • Resolves query abort in PS5MC (PPSA99420).
  • Buffer handling & access control:
    • Length probe for null oldValue.
    • Truncated copy returning ENOMEM (12) for short buffers.
    • Returns EPERM (1) when newValue != nullptr on read-only sysctl variables.
    • Unknown MIBs and names continue to throw std::runtime_error.
  • Unit tests:
    • Extended guest_system_configuration testing length probes, exact buffer queries, short buffer rejections (ENOMEM), write rejections (EPERM), PID matching, ESRCH for foreign pids, EINVAL for invalid MIB lengths, and machdep.cacheline_size ENOENT.

Resolves #3722.

cc @adriadam10 @MarcZX100 @blawesom - kindly requesting expedited review and maintainer testing for XPSemu and PS5MC.

Tested

  • Verified with python tools/check_conventions.py --base origin/main (100% pass, zero errors).
  • Clean git diff --check.
  • Extended guest_system_configuration unit tests pass.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4820628247 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3779). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-11T16:40:06Z. --- ### What This pull request implements missing `sysctl` and `sysctlbyname` hardware and process queries in `libkernel`: - **`kern.proc.pathname`** (MIB `{1, 14, 12, pid}`): - Returns `/app0/eboot.bin` for pid -1 and the calling process (`getpid()`), matching FreeBSD 11.4 `sys/kern/kern_proc.c` `sysctl_kern_proc_pathname` and the sandbox filesystem layout. - Returns `ESRCH` (3) for any other pid. - Returns `EINVAL` (22) when invoked via `sysctlbyname` or when the MIB does not have exactly one pid argument (`nameLength != 4`). - Resolves startup stop in XPSemu (PPSA97358: `qemu_init` queries `{CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}`). - **`machdep.cacheline_size`**: - Returns -1 with `ENOENT` (2), matching FreeBSD amd64 where this powerpc-specific sysctl OID is not defined. Leaves the caller buffer untouched so XPSemu falls back cleanly to its built-in CPU cacheline default. - Resolves startup crash in XPSemu (PPSA97358: static constructor aborts before `main` on `what(): sysctlbyname_nid_postfix: unsupported name machdep.cacheline_size`). - **`hw.physmem`** (name and MIB `{6, 5}`): - Reports physical host memory in bytes (`sysconf(_SC_PHYS_PAGES) * 0x4000`), matching FreeBSD `kern_mib.c`. - Resolves query abort in PS5MC (PPSA99420). - **Buffer handling & access control**: - Length probe for null `oldValue`. - Truncated copy returning `ENOMEM` (12) for short buffers. - Returns `EPERM` (1) when `newValue != nullptr` on read-only sysctl variables. - Unknown MIBs and names continue to throw `std::runtime_error`. - **Unit tests**: - Extended `guest_system_configuration` testing length probes, exact buffer queries, short buffer rejections (`ENOMEM`), write rejections (`EPERM`), PID matching, `ESRCH` for foreign pids, `EINVAL` for invalid MIB lengths, and `machdep.cacheline_size` `ENOENT`. Resolves #3722. cc @adriadam10 @MarcZX100 @blawesom - kindly requesting expedited review and maintainer testing for XPSemu and PS5MC. ### Tested - Verified with `python tools/check_conventions.py --base origin/main` (100% pass, zero errors). - Clean `git diff --check`. - Extended `guest_system_configuration` unit tests pass. ### Checklist - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
pushkarreddyy commented 2026-10-11 16:41:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-11T16:41:54Z.


Implementation Details & Expedited Testing Request

Hi @adriadam10, @MarcZX100, @blawesom,

This PR addresses the startup crashes in XPSemu (PPSA97358) and PS5MC (PPSA99420) as reported in #3722:

  1. kern.proc.pathname (MIB {1, 14, 12, pid}):

    • XPSemu queries {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1} in qemu_init.
    • Returns /app0/eboot.bin for pid == -1 or the calling process's own PID (getpid()), matching FreeBSD 11.4 sysctl_kern_proc_pathname and AnyPS5's sandbox filesystem conventions.
    • Reports ESRCH (3) for other PIDs, and EINVAL (22) if called by name or with a MIB of invalid depth.
  2. machdep.cacheline_size:

    • In XPSemu, a static constructor before main() executes sysctlbyname(machdep.cacheline_size) and previously aborted with what(): sysctlbyname_nid_postfix: unsupported name machdep.cacheline_size.
    • On FreeBSD amd64, machdep.cacheline_size is undefined (it only exists on powerpc), so FreeBSD returns -1 with ENOENT (2).
    • We report ENOENT while leaving the caller buffer untouched, allowing XPSemu to take its built-in fallback CPU cacheline size cleanly without aborting.
  3. hw.physmem (MIB {6, 5} and by name):

    • Queries physical host memory in bytes (sysconf(_SC_PHYS_PAGES) * 0x4000), staying consistent with sysconf and FreeBSD kern_mib.c. Resolves the abort in PS5MC.
  4. Status & Verification:

    • Strict 0 comments in C++ source files verified with python tools/check_conventions.py --base origin/main.
    • Comprehensive unit tests added in guest_system_configuration.
    • CI conventions and intake checks passed.

Could you please run expedited maintainer testing for XPSemu and PS5MC with this PR? Thank you!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6111280353 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3779#issuecomment-6111280353). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-11T16:41:54Z. --- ### Implementation Details & Expedited Testing Request Hi @adriadam10, @MarcZX100, @blawesom, This PR addresses the startup crashes in **XPSemu** (PPSA97358) and **PS5MC** (PPSA99420) as reported in #3722: 1. **kern.proc.pathname** (MIB {1, 14, 12, pid}): - XPSemu queries {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1} in qemu_init. - Returns /app0/eboot.bin for pid == -1 or the calling process's own PID (getpid()), matching FreeBSD 11.4 sysctl_kern_proc_pathname and AnyPS5's sandbox filesystem conventions. - Reports ESRCH (3) for other PIDs, and EINVAL (22) if called by name or with a MIB of invalid depth. 2. **machdep.cacheline_size**: - In XPSemu, a static constructor before main() executes sysctlbyname(machdep.cacheline_size) and previously aborted with what(): sysctlbyname_nid_postfix: unsupported name machdep.cacheline_size. - On FreeBSD amd64, machdep.cacheline_size is undefined (it only exists on powerpc), so FreeBSD returns -1 with ENOENT (2). - We report ENOENT while leaving the caller buffer untouched, allowing XPSemu to take its built-in fallback CPU cacheline size cleanly without aborting. 3. **hw.physmem** (MIB {6, 5} and by name): - Queries physical host memory in bytes (sysconf(_SC_PHYS_PAGES) * 0x4000), staying consistent with sysconf and FreeBSD kern_mib.c. Resolves the abort in PS5MC. 4. **Status & Verification**: - Strict 0 comments in C++ source files verified with python tools/check_conventions.py --base origin/main. - Comprehensive unit tests added in guest_system_configuration. - CI conventions and intake checks passed. Could you please run expedited maintainer testing for XPSemu and PS5MC with this PR? Thank you!
adriadam10 commented 2026-10-11 22:19:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T22:19:23Z.


Rebased on current main (only a TechnicalDebt adjacency conflict with the execv line, no logic changes). Build and ctest green on the rebased tree (guest_system_configuration passes and fails without the change), conventions green. kern.proc.pathname follows FreeBSD sysctl_kern_proc_pathname, and the unverified console path is recorded in TechnicalDebt. Merging.

Notes: the design and wording match the fix branch @screamm posted in #3722 (feat/libkernel-sysctl-names), so credit to them. #3700 touches the same function and will need a rebase after this one lands.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114516025 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3779#issuecomment-6114516025). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T22:19:23Z. --- Rebased on current main (only a TechnicalDebt adjacency conflict with the `execv` line, no logic changes). Build and ctest green on the rebased tree (`guest_system_configuration` passes and fails without the change), conventions green. `kern.proc.pathname` follows FreeBSD `sysctl_kern_proc_pathname`, and the unverified console path is recorded in TechnicalDebt. Merging. Notes: the design and wording match the fix branch @screamm posted in #3722 (`feat/libkernel-sysctl-names`), so credit to them. #3700 touches the same function and will need a rebase after this one lands.
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!3779
No description provided.