Skip to content

feat(libkernel): implement sysctlnametomib for the sysctl names AnyPS5 serves - #5502

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
ahmad3a4:feat/libkernel-sysctlnametomib
Oct 14, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
ahmad3a4:feat/libkernel-sysctlnametomib

Conversation

@ahmad3a4

@ahmad3a4 ahmad3a4 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What

sysctlnametomib (UkEV4hvMo1E) is not exported, so Java 25 LAN / DNS (PPSA99869) stops in the loader on main:

FAIL: unresolved ELF import UkEV4hvMo1E from libkernel.prx

It is added in SystemConfiguration.cpp for the names whose MIB sysctl already serves, with their FreeBSD numbers from <sys/sysctl.h>:

Name MIB
hw.model 6.2
hw.ncpu 6.3
hw.physmem 6.5
hw.realmem 6.12
kern.arandom 1.37
kern.proc.pathname 1.14.12 (the caller appends the pid)

The rest follows FreeBSD:

  • Size handling is that of sysctlnametomib.c, which runs name2oid through sysctl with *sizep scaled to bytes and back. With a null mibp it reports the entry count. With a short buffer it copies what fits, sets *sizep to the entries copied and fails with ENOMEM, through the same CopyOut that sysctl uses.
  • Errors are those of sysctl_sysctl_name2oid in kern_sysctl.c: an empty name fails with ENOENT, and a name of MAXPATHLEN (1024) bytes or more fails with ENAMETOOLONG.
  • machdep.cacheline_size fails with ENOENT, as sysctlbyname already answers it.
  • Null pointers for the name or the size throw invalid_argument: sysctlnametomib.c dereferences both (strlen(name), *sizep *= sizeof(int)) before the syscall, so FreeBSD faults there.

Any other name throws "unsupported name", as sysctlbyname does. kern.sdk_version, kern.rng_pseudo, machdep.tsc_freq and vm.overcommit throw too: sysctlbyname answers them by name, but sysctl serves no MIB for them that this could return.

The new function sits at the end of the file, apart from the sysctl and sysctlbyname branches other pull requests change.

guest_system_configuration checks, for every name:

  • the count with a null buffer;
  • the MIB with a larger buffer, the entry after it left untouched.

It then checks that:

  • the hw.ncpu MIB reads the processor count back through sysctl;
  • the hw.realmem MIB reads through sysctl the value sysctlbyname("hw.realmem") gives;
  • kern.proc.pathname plus -1 reads /app0/eboot.bin;
  • a buffer of 1 and of 0 entries fails with ENOMEM and keeps the copied entry;
  • the empty name, machdep.cacheline_size and a 1024-byte name give the errors above, and null pointers throw;
  • a 1023-byte name and kern.cp_times throw.

On main the test does not link (undefined reference to sysctlnametomib_nid_postfix).

Tested

Windows 11 Pro (26200), WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON, rebased onto main 1209d37:

  • guest_system_configuration passes (3 runs).
  • The full build and full ctest pass: 1140 tests, 8 of them skipped by their own environment checks.
  • The NID patch of libkernel.prx succeeds.

With the PR, Java 25 LAN / DNS (PPSA99869, relinked with --trap-sdk-syscall-stubs) gets past this import, and the loader stops at the next one:

FAIL: unresolved ELF import psx0YiAKm7k from libSceLibcInternal.prx

psx0YiAKm7k is fegetenv (#5563). tools/import_audit.py goes from 4 absent imports to 3.

Linux not tested.

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
  • Unblocks: PPSA99869 Java 25 LAN / DNS (PPSA99869) #5501
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

@karimibrahim07 karimibrahim07 mentioned this pull request Oct 13, 2026
11 tasks done
@Amirtheshwaran Amirtheshwaran mentioned this pull request Oct 14, 2026
11 tasks done
@pipe1os

pipe1os commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Built and ran this on Windows: head 0cb9540ab merged onto main f5424b4db (no conflicts), Windows 11, WinLibs GCC 15.2.0, Ninja Release.

  • guest_system_configuration passes. With SystemConfiguration.cpp put back to main and the test kept, it doesn't link (undefined reference to sysctlnametomib_nid_postfix).
  • Java 25 LAN / DNS (PPSA99869, Java 25 LAN / DNS (PPSA99869) #5501), relinked with --windows --to-intel --trap-sdk-syscall-stubs. On main the loader stops at UkEV4hvMo1E; with this PR it gets to FAIL: unresolved ELF import psx0YiAKm7k from libSceLibcInternal.prx (feat(libc): implement fegetenv #5563).

Two things against FreeBSD 11.0:

  1. hw.realmem isn't in the table. main serves it through sysctl (6.12) and sysctlbyname since fe54938, which landed after this branch's base. On the merge, sysctlbyname("hw.realmem") returns 0 but sysctlnametomib("hw.realmem") throws unsupported name hw.realmem. Probably just needs {"hw.realmem", {6, 12}, 2}.
  2. A null name or size returns EFAULT. sysctlnametomib.c dereferences both in userland (*sizep *= sizeof(int), strlen(name)) before the syscall, so the caller faults there. sysctlbyname on main already answers EFAULT the same way, so maybe that's the accepted convention, but a throw would be closer.

Everything else lines up: ENOENT for an empty name and ENAMETOOLONG from 1024 bytes (sysctl_sysctl_name2oid), a short buffer copying what fits with ENOMEM and the copied length (sysctl_old_user, userland_sysctl L1996-L1999), and the MIB numbers (sysctl.h).

AI-assisted.

…5 serves

Map hw.model, hw.ncpu, hw.physmem, hw.realmem, kern.arandom and
kern.proc.pathname to their FreeBSD MIBs with the size handling of
FreeBSD's libc wrapper over name2oid, fail with ENOENT and ENAMETOOLONG
as name2oid does, and throw for null pointers, which FreeBSD's wrapper
dereferences, and for names sysctl does not serve.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ahmad3a4
ahmad3a4 force-pushed the feat/libkernel-sysctlnametomib branch from 0cb9540 to cc3d25d Compare October 14, 2026 08:02
@ahmad3a4

Copy link
Copy Markdown
Contributor Author

Thanks for building and running it. Both points are in the new head cc3d25d, rebased onto main 1209d37:

  • hw.realmem maps to {6, 12}. guest_system_configuration reads it through sysctl with that MIB and compares it with sysctlbyname("hw.realmem").
  • A null name or size now throws invalid_argument, since sysctlnametomib.c faults on both before the syscall. sysctlbyname is left as it is.

kern.sdk_version, kern.rng_pseudo, machdep.tsc_freq and vm.overcommit still throw: sysctlbyname answers them by name, but sysctl serves no MIB for them.

Re-tested on Windows: guest_system_configuration passes, and the full ctest passes (1140 tests, 8 skipped by their environment checks). PPSA99869 still gets past UkEV4hvMo1E and stops at psx0YiAKm7k (#5563).

AI-assisted.

@adriadam10 adriadam10 self-assigned this Oct 14, 2026
@github-actions

Copy link
Copy Markdown

Progress report (31bfc4e → cc3d25d)

➖ System libraries: 88.19% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel sysctlnametomib_nid_postfix

@adriadam10

Copy link
Copy Markdown
Collaborator

Checked on the merge with main: guest_system_configuration passes and fails to link without the change, the MIB numbers, name2oid errors and ENOMEM handling match FreeBSD, and both points from the earlier review (hw.realmem, null name/size) are addressed with tests. Windows run by @pipe1os also confirms the loader gets past UkEV4hvMo1E. Merging.

@adriadam10
adriadam10 merged commit c4b4a74 into boykopovar:main Oct 14, 2026
8 of 9 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.

3 participants