feat(libkernel): implement _umtx_op SEM2_WAIT, SEM2_WAKE and MUTEX_WAKE2 #19450
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19450"
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 SHOnnay on 2026-11-13T10:49:52Z.
What
_umtx_opoperationsMUTEX_WAKE2(22),SEM2_WAIT(23) andSEM2_WAKE(24) no longer throw. They follow FreeBSD stable/11sys/kern/kern_umtx.cat5ed7eb0d97ba:do_wake2_umutex(L1287-1377),do_sem2_wait(L3195-3273) anddo_sem2_wake(L3276-3313). The_usem2layout{_count, _flags},USEM_HAS_WAITERS(0x80000000) andUSEM_MAX_COUNTcome fromsys/sys/_umtx.handsys/sys/umtx.h.All three use the file's existing wait queues. The bucket mutex plays the role of FreeBSD's umtxq busy lock.
SEM2_WAITUmtxDeadline, with the same size-dependent forms as the other operations.EFAULT; a misaligned object throws, asSEM_WAITdoes.USEM_COUNTis non-zero. Otherwise it setsUSEM_HAS_WAITERSwith a compare-and-swap from 0, or sees it already set, and sleeps.ETIMEDOUT, an unreadable count givesEFAULT. The count is never decremented here; userland does that, as on FreeBSD.SEM2_WAKE_flagsgivesEFAULT, as FreeBSD'sfueword32of_flags.USEM_HAS_WAITERS, then wakes one waiter.MUTEX_WAKE2val; priority inherit and protect together giveEINVAL.UMUTEX_CONTESTED. With one, it sets it only while the mutex is owned. It then wakes one waiter if the mutex has no owner.Still throwing: the legacy lock,
SHM, robust lists and robust umutexes, includingMUTEX_WAKE2withUMUTEX_ROBUST, which FreeBSD treats as a normal mutex here. The debt entry is updated.Tested
macOS 27 on Apple M1. libkernel does not build on macOS, so the registered
guest_umtx_optest was not run; a Linux or Windows run is needed.Harness. A temporary harness, not committed, built the unchanged
SyncOnAddress.cppandTimedWait.cppwith the extendedGuestUmtxOp.cppand minimal stand-ins, for x86-64 under Rosetta (arm64 cannot build the file's x86 inline assembly).not implemented: _umtx_op operation 23, exit 134TSan also reports a race in the existing
ConditionWaitReleasesTheMutexAndWakes(a non-atomic read ofhasWaiters), on base as on this branch.New test cases, all with real threads:
timespec, relative_umtx_time, absolute and pastUMTX_ABSTIME, andEINVALEFAULTfor null and for address 0x10MUTEX_WAKE2with no waiters,EINVAL, the robust flag throwing, and contested repair with a single wake, with twoLOCKwaiters and oneMUTEX_WAITwaiterThe old assertion that
SEM2_WAITthrows now usesSHM.Mutation check: all 7 hand mutations failed the harness:
MUTEX_WAKE2wakes while ownedMUTEX_WAKE2ignores the waiter countMUTEX_WAKE2sets contested with one waiter on an unowned mutexOverlap. No open PR implements these operations.
SyncOnAddress.cpp; each merges with this branch without conflict, and each merged tree passes the harness._umtx_opdebt line, so the second to merge needs that line merged by hand.Not verified:
USYNC_PROCESS_SHARED, which is ignored, as for the existing operationsChecklist
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-13T18:34:02Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
7429e6b166:tools/check_conventions.pypassed;git diff --checkclean.guest_umtx_op_testsbuilt cleanly.guest_umtx_op):core/libs/prx/libkernel/SyncOnAddress/src/SyncOnAddress.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Generated withfooter from the description; the AI-assisted checkbox can stay.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T05:14:24Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
b3ccff0da7:tools/check_conventions.pypassed;git diff --checkclean.guest_umtx_op_testsbuilt cleanly.guest_umtx_op):core/libs/prx/libkernel/SyncOnAddress/src/SyncOnAddress.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Generated withfooter from the description; the AI-assisted checkbox can stay.Looks Good To Me