feat(libkernel_sys): implement uuidgen #9195
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9195"
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 gazaret on 2026-10-21T15:00:00Z.
What
Implements
uuidgen(store, count)in libkernel_sys, one of the stubs added by #8837, following FreeBSD 11'skern_uuidgenandsys_uuidgen:countgets consecutive 100 ns timestamps taken from the guestCLOCK_REALTIME(clock_gettimein libkernel, so time scaling applies);EINVALfor a count outside 1 to 2048, andEFAULTfor a null store after the generator state advances, ascopyoutfails there.The node differs from the console: it is 48 random bits with the multicast bit set, chosen once per process, which is FreeBSD's fallback when no Ethernet interface is registered. The console's kernel presumably uses its own MAC address; that is recorded in
docs/dev/debt/libkernel_sys.md.The code is in its own
Uuid.cppwith its own test, so it does not touchExport.cpporGuestKernelSys.cpp, which many open libkernel_sys pull requests change.Tested
Ubuntu 22.04 (WSL2), GCC 13.4, Release, rebased on
main14c99b52a, fullBUILD_TESTING=ONbuild:guest_kernel_sys_uuid: count bounds (EINVAL), null store (EFAULT), version and variant bits, multicast node shared by every UUID, same clock sequence and consecutive timestamps within a batch, the next batch either later with the same sequence or with the sequence incremented, and a timestamp within 60 s of the host clock. Passes 3 of 3 runs.uuidgenis declared once, inlibkernel_sys/include/Api.hpp, with theGuestUuidlayout next to it.ctest -R 'kernel_sys|public_headers|patched_librar|nid_': 97 of 97 pass,public_headersand its compile batches included (public_headersfails on the previous head, which declareduuidgenlocally in the test).ctest -R 'patched_librar|nid_': all pass.tools/check_conventions.py --base origin/main: no findings.uuidgen: none implements it.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T04:12:16Z.
Review: APPROVED
Checked against main
6ef5a1c4cand FreeBSD sys/kern/kern_uuid.c @ 53c44718 (plus ps5-payload-dev/sdk sce_stubs/libkernel_sys.c):kern_uuidgen/sys_uuidgenmatch: EINVAL outside 1..2048; the clock sequence is random on first use, +1 whenuuid_last.time >= now, kept otherwise;uuid_last.time = (time + count - 1) & ((1<<60)-1); EFAULT only after the state has advanced, as withcopyout.time_hi_and_version, the 10xx variant inclock_seq_hi_and_reserved, and the sequence high byte comes first, as FreeBSD'shtobe16(seq | 0x8000)gives. The time fields are little-endian, as instruct uuid.uuid_node()fillinguuid_ether[0]when no Ethernet interface is registered. The MAC difference is recorded in the debt file.uuidgenis@functionin the SDK's libkernel_sys stubs. libkernel_sys already links libkernel and libc through core/libs/CMakeLists.txt, soclock_gettime_nid_postfixand__error_nid_postfixresolve.BUILD_TESTING=ONbuild) merged onto main6ef5a1c4c; the only failing step is the existingImageArrayWindowPastLayerLimit.cppalignment error that #8310 fixes. Not run here: this machine's Smart App Control blocks freshly built test executables.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.