Skip to content

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

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
pushkarreddyy:feat/libkernel-sysctl-pathname-hw-physmem
Oct 11, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
pushkarreddyy:feat/libkernel-sysctl-pathname-hw-physmem

Conversation

@pushkarreddyy

Copy link
Copy Markdown
Contributor

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

@pushkarreddyy

Copy link
Copy Markdown
Contributor Author

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!

@github-actions github-actions Bot mentioned this pull request Oct 11, 2026
9 tasks done
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 11, 2026
@adriadam10

Copy link
Copy Markdown
Collaborator

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.

@adriadam10
adriadam10 force-pushed the feat/libkernel-sysctl-pathname-hw-physmem branch from 354f242 to 931aaa2 Compare October 11, 2026 22:19
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 11, 2026
@adriadam10
adriadam10 merged commit 22cecd5 into boykopovar:main Oct 11, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libkernel: sysctl throws for kern.proc.pathname, machdep.cacheline_size and hw.physmem (XPSemu, PS5MC); fix branch ready

2 participants