libkernel: alarm() accepts seconds above INT32_MAX/2 that FreeBSD rejects with EINVAL (returns -1); fix branch ready #6940
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 husseinkad on 2026-10-16T20:28:24Z.
alarm()accepts any number of seconds, soalarm(UINT_MAX)arms a timer about 136 years out and returns the old remaining time. FreeBSD 11.4alarm()is a thin wrapper oversetitimer(ITIMER_REAL), andkern_setitimerfails anyit_value.tv_secaboveINT32_MAX / 2(1,073,741,823) withEINVAL(if (itimerfix(&aitv->it_value) || aitv->it_value.tv_sec > INT32_MAX / 2) return (EINVAL);), soalarm()returns -1 (the largest unsigned value) and the pending alarm is left alone.setitimerhere already applies that bound (#3800), soalarmandsetitimerdisagreed.Fix branch: https://github.com/husseinkad/AnyPS5/tree/fix/libkernel-alarm-range (one commit; it merges cleanly into current main;
libkernel/System/src/Signals.cppandtests/GuestGetitimer.cpp). For seconds above 1,073,741,823,GuestAlarm_nid_no_patchnow setserrnoto 22, returnsUINT_MAXand changes nothing;MaxItimerSecondswas moved above the alarm code.GuestGetitimer.cpppreviously asserted thatalarm(UINT_MAX)arms a long alarm; it now arms the largest valid alarm, checks that the three out-of-range values fail withEINVAL, and checks the pending alarm is unchanged.Checks:
guest_getitimer,guest_itimerandguest_signalspass.alarm(1073741824),alarm(INT_MAX),alarm(2^31)andalarm(UINT_MAX)now return 4294967295 witherrno22 (main accepted them); afteralarm(30), a failingalarm(UINT_MAX)leaves about 30 s pending andalarm(0)returns 30 (main replaced it with a roughly 4.29e9 s alarm). Unchanged:alarm(0), 1, 2, 100,000,000, 100,000,001 and 1,073,741,823 behave as on main, successive alarms return the previous remaining seconds,errnois untouched on success, a 1 s alarm still deliversSIGALRM(exit 142 with the default disposition),SIG_IGNis harmless andalarm(0)cancels.setitimeragrees withalarmat every value tested.alarm(UINT_MAX)arming a long alarm, and found nothing wrong.check_conventions.pyis clean.Not covered: one probe run hung at process exit once and did not recur in 15 branch runs and 12 main runs, so I cannot tie it to this change.
pr_overlap.pycould not compare #3986 (the signal mask, other parts ofSignals.cpp) and #6044 (it movesGuestGetitimer.cpptotests/time/, so a trivial rebase of the test edit is needed when it lands); by hand neither conflicts. Based on the FreeBSD source, not a console measurement. Only Windows was built and run.AI-assisted: yes