libkernel: sem_timedwait fails with EINVAL on an available semaphore when the timeout is NULL or out of range; fix branch ready #3119
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 milescoviello on 2026-10-10T22:35:19Z.
sem_timedwaitvalidatesabs_timeoutbefore it looks at the semaphore. With a count of 1 and a NULL timeout or one withtv_nsec = 1000000000, it returns -1 witherrno22 and leaves the count at 1. FreeBSD's_sem_clockwait_np(lib/libc/gen/sem_new.c) takes an available semaphore first and checks the timeout only when the thread would block ("The timeout argument is only supposed to be checked if the thread would have blocked"). A NULL timeout means no limit there: FreeBSD'ssem_waitissem_timedwait(sem, NULL). POSIX allows skipping the check when the semaphore can be locked immediately.Fix on my fork:
milescoviello/AnyPS5:fix/sem-timedwait-timeout-check(one commit,e7d71abf, onmain4d27834f; the 12 commits onmainsince then don't touch these files): take the semaphore first, wait without a limit for NULL, and keepEINVAL/ETIMEDOUTwhen the call would block.guest_posix_sem_postgains checks that fail on main and pass with the fix. Linux only; Windows was not built or tested (no platform-specific code).Setup: Gentoo, Linux 7.2.8, GCC 15.3.0, Release with CI's configure flags,
main4d27834f.Tested: the new checks fail on
mainand pass with the fix. Fullctestwith the fix on Linux (RTX 5090 Laptop GPU): no new failures; the only failures are the knownagc_driver_dcc_keys_first_write(#2767) and twoguest_video_out_*tests that time out with the displays powered off.tools/check_conventions.pypasses. All five fixes I am filing today also pass their tests merged together on the currentmain.Not opened as a PR because intake is paused for new contributors; a maintainer is welcome to carry the commit.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by hikazey on 2026-10-11T00:53:14Z.
Windows check, since the issue says Windows wasn't tested. This branch merged onto
mainf1ae427b, Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release with CI's configure flags.guest_posix_sem_*Sem.cppreverted tomain, test keptThe two full-suite failures also fail on plain
mainhere (pr_overlap_encoding: the two*_error_preserves_unicodecases;guest_filesystem: line 276, guest errno 14), so they are unrelated.AI-assisted: yes (Claude Code).