feat(libkernel_sys): implement kenv #11032
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11032"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-25T14:35:27Z.
What
kenvwas a throwing stub in libkernel_sys. It now follows FreeBSD 11.4'ssys_kenvover an in-memory kernel environment:KENV_GETcopies outmin(len, strlen+1)bytes and returns the count (ENOENTfor a missing name; a negativelenis not truncated, as the kernel compares it as unsigned).KENV_SETfails withEINVALfor alenof 0 and capslenat 129; a negativelenbecomes a largesize_tin the kernel, so it passes that check and is capped like any other. It and replaces an existing variable; a name or value that does not fit its 128-byte limit plus NUL fails withENAMETOOLONG. A 513th variable is dropped silently, as in FreeBSD.KENV_UNSETremoves a variable (ENOENTif absent).KENV_DUMPwritesname=valuestrings separated by NULs, truncating atlenand returning the size needed (0 when everything fit).EFAULTbefore an unknown action givesEINVAL. The guest is uid 0, so the privilege checks pass.Guest strings are read with
CopyGuestPath_nid_no_patchand output goes throughGuestCopyOut_nid_no_patch, so a bad pointer returnsEFAULTinstead of faulting the host. The table starts empty because the console's boot environment is unmeasured; the debt entry records that and the copy-limit difference.Tested
Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,
-DBUILD_TESTING=ON.guest_kernel_sys: newCheckKernelEnvironmentcovers get/set/unset/dump, replacement, truncation, negative and zerolen(a negativelenonKENV_SETstores the value), 128-byte limits, the 512-variable cap,=inside a name, andEFAULTfor a null and an unreadable (0x10) name, value and dump buffer. Onmainit aborts withkenv_nid_postfix not implemented; on this branch it passes, three runs out of three.pr_overlap_encoding,agc_host_import_cut_lifetimeandagc_driver_depth_plane_partial_storefail the same way on plainmainin this environment;agc_import_settle_earlier_importfailed once in the parallel run and passes alone.python tools/check_conventions.py --base upstream/main: passes.Overlaps
Export.cppL133-134), #10421 (Export.Discovery.cppL110-119), #10427 (GuestKernelSys.cppL524), #10799 and #10838 (GuestKernelSys.cppL536), #10332 and #10335 (libkernel_sys.mddebt L12) touch neighbouring lines: proposed on each that it goes first and this PR rebases.getfsstat, mine) adds code at the same place: this PR goes first, then #11031 rebases.kenv.Checklist
main; no other open PR implements the same functionNotImplemented_nid_no_patch); no silent stubs added.mdfiles or images added to the repositoryAI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T14:37:04Z.
Review: COMMENTED
The added test file contains literal NUL bytes in the empty-value assertion and expected dump string (lines 555 and 561). GCC accepts them but emits
null character(s) preserved in literalwarnings, and tools treat the source as binary. Please spell these as the C++ escapes\0(\x00also works) so the test remains ordinary text and the intended embedded NUL is explicit. Exact-head checks:git diff --checkfor the PR files andtools/check_conventions.py --base upstream/mainpass;g++ -std=c++20 -fsyntax-onlyonGuestKernelSys.cppsucceeds with the two warnings noted.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T14:37:23Z.
Review: APPROVED
Reviewed the exact head against FreeBSD 11.4
sys_kenv. The GET, SET, UNSET and DUMP paths and their return/error behavior match the reference for the modeled in-memory environment; the implementation records the unmeasured boot environment and copy-limit difference as debt. Exact-head checks:git diff --checkfor the PR files andtools/check_conventions.py --base upstream/mainpass.g++ -std=c++20 -fsyntax-onlyonGuestKernelSys.cppsucceeds, with warnings for the two raw NUL bytes called out in my comment. The author reports the focused Windows suite passing three times; hosted product build/test checks are skipped, so I could not independently verify runtime behavior here.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T15:21:20Z.
Review: DISMISSED
Following up on my earlier note: the current head
af5ebe43b4d1a45a7e5363a7b5472d43e935b861still has two literal NUL bytes incore/libs/tests/GuestKernelSys.cpp(confirmed in the fetched file bytes). Please replace them with the C++ escape\\0so the file remains plain text and the intended embedded NUL is explicit. The previous exact-head syntax check succeeded but emitted GCC’snull character(s) preserved in literalwarnings; I’m requesting this small cleanup before the draft is ready.