fix(libkernel): clamp POSIX deadlines beyond the clock range instead … #4005
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4005"
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 zmeizy on 2026-10-11T21:12:33Z.
What
PosixThread::RelativeMicroseconds(Pthread/Posix/Common.hpp) turns an absolute deadline into a relative wait.pthread_rwlock_timedrdlock,pthread_rwlock_timedwrlock,pthread_cond_timedwaitandsem_timedwaitall use it. It converted the deadline tostd::chrono::nanoseconds, so atv_secbeyond about 9.2 × 10^9 (the year 2262) overflowed 64 bits, which is undefined behaviour.{INT64_MAX, 0}, a common "wait forever" value, wrapped negative and timed out at once.The seconds are now compared first:
UINT_MAXµs) gives that maximum, as large valid deadlines already did.Tested
Ubuntu 24.04, GCC 13.3, on
main0a8b1d32.guest_pthread_rwlock, new check with a reader holding the lock:pthread_rwlock_timedwrlockwith{INT64_MIN, 0}returnsETIMEDOUT.{INT64_MAX, 0}it waits until the reader releases the lock, then returns 0.mainwithout the change (ETIMEDOUTat once forINT64_MAX) and passes with it.guest_cond_timedwait,guest_posix_sem_init,guest_posix_sem_postandguest_pthread_mutexattrpass.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (n/a).mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
https://claude.ai/code/session_01Ha6Tsy62AFUyp9a5Mf7vjA