feat(libkernel): match event flags to PS5 and add shared flags #9134
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9134"
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 orezraey on 2026-10-21T13:01:37Z.
What
Event flag behaviour measured on a retail PS5 (firmware 13.60) with five homebrew probes. The sources and console logs are in this gist (
evflagtoevflag5).Attributes and wait modes
sceKernelCreateEventFlagaccepts attribute bits 0x1, 0x2, 0x10, 0x20 and 0x100. It returns EINVAL for 0x1|0x2 (we accepted it), for 0x10|0x20 (unchanged), and for every other bit (0x4 to 0x80000000, one at a time).0x8002003F) with or without 0x100. An empty name is accepted.sceKernelWaitEventFlagandsceKernelPollEventFlagignore mode bits outside the match (0x3) and clear (0x30) fields, soOR|0x100,OR|0x80000000andAND|0x4behave likeORandAND. We returned EINVAL. A mode still needs exactly one of AND and OR, and not both clear bits.Result pattern on errors
Shared flags (attribute 0x100) and
sceKernelCloseEventFlagsceKernelCloseEventFlagwas a stub inlibkernel_sys. It is now implemented next to the other event flag functions inlibkernel, and the stub is removed, sincecheck_conventions.pyrejects the same export in two libraries.SceShellCoreUtilAppFocus, can be opened on the console. They do not exist here, so opening them returns ESRCH; the debt entry says so.Wake order
The multi-waiter wake order was also measured. Waiters are served in FIFO order, and each satisfied waiter's clear is applied before the next one is checked. Eight scenarios covered AND and OR, both clear modes, and FIFO and PRIO flags. They all match what we do, so the "unverified on PS5" debt entry for
sceKernelSetEventFlagis removed.Not measured: whether ENAMETOOLONG or EINVAL comes first when a call has both a bad attribute and a long name. Handles are still host addresses here, while the console uses small IDs. Both are recorded under
sceKernelCreateEventFlagindocs/dev/debt/libkernel.md.Tested
Windows 11, MinGW (winlibs).
guest_kernel_errors,kernel_error, theguest_kernel_systests and thesavedatatests pass (17 tests), andguest_kernel_errorspassed 10 runs in a row. The new cases cover:tools/check_conventions.pypasses.tools/progress.pycountssceKernelCreateEventFlagand the newsceKernelCloseEventFlagas implemented. Linux was not built.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-22T05:47:44Z.
Review: COMMENTED
Checked against main
4a17c7175and the console logs in the linked gist (evflag…evflag5):0x8002003f, and the result pattern is 0 on ECANCELED, EACCES and EPERM. Closing an opened handle returns 0, and deleting through it returns EPERM. Lock order (registry, then flag) is consistent across Create, Open and Delete. The only other internal caller, libSceSaveData'screate_signalled_flagwith attribute 0x20, is unaffected.sceKernelCreateEventFlag(&ef, <32-char name>, 0x3, 0, nullptr)returns EINVAL here because the attribute checks run before thestrlen(name) >= EVF_NAME_CAPACITYcheck, andevflag3only tries long names with 0x20 and 0x120. The PR description says this order was not measured, butdocs/dev/debt/libkernel.mddoesn't record it. Please add asceKernelCreateEventFlagdebt entry, or extend the event flag entry, saying so.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-22T05:52:59Z.
Added a
sceKernelCreateEventFlagentry todocs/dev/debt/libkernel.mdin8a217a1224. It says that a call with both an invalid attribute and a 32-byte or longer name returns EINVAL here, because the attribute checks run first, and that the console order was not measured sinceevflag3only used 0x20 and 0x120. It also notes that handles are host addresses here while the console returns small IDs. This is a docs-only change;check_conventions.pypasses.Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T12:54:52Z.
Review: APPROVED
Rechecked at
8a217a1224:sceKernelCreateEventFlagentry (libkernel.md:63) matches the code. The attribute checks at EventFlag.cpp:150-152 return EINVAL before the name-length check at line 153, and the entry records that the console order wasn't measured (only 0x20/0x120 with long names).RegisterEventFlag(EventFlag.cpp:109) does produce.sceKernelSetEventFlag"unverified" entry is backed by the wake-order measurements in the description, and the Set loop is unchanged.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.