feat(libkernel_sys): implement uuidgen #9195

Merged
gazaret merged 2 commits from upstream-pr/9195 into main 2026-10-26 21:29:18 +00:00
gazaret commented 2026-10-21 15:00:00 +00:00 (Migrated from github.com)

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's kern_uuidgen and sys_uuidgen:

  • version 1 UUIDs with RFC 4122 variant bits; a batch of count gets consecutive 100 ns timestamps taken from the guest CLOCK_REALTIME (clock_gettime in libkernel, so time scaling applies);
  • a 14-bit clock sequence that is random on first use, incremented when the clock has not passed the last timestamp of the previous batch, and kept otherwise;
  • EINVAL for a count outside 1 to 2048, and EFAULT for a null store after the generator state advances, as copyout fails 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.cpp with its own test, so it does not touch Export.cpp or GuestKernelSys.cpp, which many open libkernel_sys pull requests change.

Tested

Ubuntu 22.04 (WSL2), GCC 13.4, Release, rebased on main 14c99b52a, full BUILD_TESTING=ON build:

  • New 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.
  • uuidgen is declared once, in libkernel_sys/include/Api.hpp, with the GuestUuid layout next to it. ctest -R 'kernel_sys|public_headers|patched_librar|nid_': 97 of 97 pass, public_headers and its compile batches included (public_headers fails on the previous head, which declared uuidgen locally in the test).
  • ctest -R 'patched_librar|nid_': all pass.
  • tools/check_conventions.py --base origin/main: no findings.
  • Open pull requests were checked for uuidgen: none implements it.
  • No title 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4953687257 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9195). Originally posted by [gazaret](https://github.com/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's [`kern_uuidgen` and `sys_uuidgen`](https://github.com/freebsd/freebsd-src/blob/53c4471833e8e5e57b4d1b501b1a52b343bb0451/sys/kern/kern_uuid.c#L129-L198): - version 1 UUIDs with RFC 4122 variant bits; a batch of `count` gets consecutive 100 ns timestamps taken from the guest `CLOCK_REALTIME` (`clock_gettime` in libkernel, so time scaling applies); - a 14-bit clock sequence that is random on first use, incremented when the clock has not passed the last timestamp of the previous batch, and kept otherwise; - `EINVAL` for a count outside 1 to 2048, and `EFAULT` for a null store after the generator state advances, as `copyout` fails 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.cpp` with its own test, so it does not touch `Export.cpp` or `GuestKernelSys.cpp`, which many open libkernel_sys pull requests change. ### Tested Ubuntu 22.04 (WSL2), GCC 13.4, Release, rebased on `main` 14c99b52a, full `BUILD_TESTING=ON` build: - New `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. - `uuidgen` is declared once, in `libkernel_sys/include/Api.hpp`, with the `GuestUuid` layout next to it. `ctest -R 'kernel_sys|public_headers|patched_librar|nid_'`: 97 of 97 pass, `public_headers` and its compile batches included (`public_headers` fails on the previous head, which declared `uuidgen` locally in the test). - `ctest -R 'patched_librar|nid_'`: all pass. - `tools/check_conventions.py --base origin/main`: no findings. - Open pull requests were checked for `uuidgen`: none implements it. - No title tested. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
harisibrar1 commented 2026-10-22 04:12:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T04:12:16Z.

Review: APPROVED


Checked against main 6ef5a1c4c and FreeBSD sys/kern/kern_uuid.c @ 53c44718 (plus ps5-payload-dev/sdk sce_stubs/libkernel_sys.c):

  • kern_uuidgen/sys_uuidgen match: EINVAL outside 1..2048; the clock sequence is random on first use, +1 when uuid_last.time >= now, kept otherwise; uuid_last.time = (time + count - 1) & ((1<<60)-1); EFAULT only after the state has advanced, as with copyout.
  • Bits and byte order: version 1 goes in time_hi_and_version, the 10xx variant in clock_seq_hi_and_reserved, and the sequence high byte comes first, as FreeBSD's htobe16(seq | 0x8000) gives. The time fields are little-endian, as in struct uuid.
  • The random multicast node chosen once is the same as uuid_node() filling uuid_ether[0] when no Ethernet interface is registered. The MAC difference is recorded in the debt file.
  • uuidgen is @function in the SDK's libkernel_sys stubs. libkernel_sys already links libkernel and libc through core/libs/CMakeLists.txt, so clock_gettime_nid_postfix and __error_nid_postfix resolve.
  • Builds on Windows (WinLibs GCC 15.2.0 r7, full BUILD_TESTING=ON build) merged onto main 6ef5a1c4c; the only failing step is the existing ImageArrayWindowPastLayerLimit.cpp alignment 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609167191 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9195#pullrequestreview-5609167191). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-22T04:12:16Z. **Review:** APPROVED --- Checked against main 6ef5a1c4c and FreeBSD sys/kern/kern_uuid.c @ 53c44718 (plus ps5-payload-dev/sdk sce_stubs/libkernel_sys.c): - `kern_uuidgen`/`sys_uuidgen` match: EINVAL outside 1..2048; the clock sequence is random on first use, +1 when `uuid_last.time >= now`, kept otherwise; `uuid_last.time = (time + count - 1) & ((1<<60)-1)`; EFAULT only after the state has advanced, as with `copyout`. - Bits and byte order: version 1 goes in `time_hi_and_version`, the 10xx variant in `clock_seq_hi_and_reserved`, and the sequence high byte comes first, as FreeBSD's `htobe16(seq | 0x8000)` gives. The time fields are little-endian, as in `struct uuid`. - The random multicast node chosen once is the same as `uuid_node()` filling `uuid_ether[0]` when no Ethernet interface is registered. The MAC difference is recorded in the debt file. - `uuidgen` is `@function` in the SDK's libkernel_sys stubs. libkernel_sys already links libkernel and libc through core/libs/CMakeLists.txt, so `clock_gettime_nid_postfix` and `__error_nid_postfix` resolve. - Builds on Windows (WinLibs GCC 15.2.0 r7, full `BUILD_TESTING=ON` build) merged onto main 6ef5a1c4c; the only failing step is the existing `ImageArrayWindowPastLayerLimit.cpp` alignment 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.
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!9195
No description provided.