feat(libc): implement alarm #2765
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2765"
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 TheAggie on 2026-10-10T13:15:43Z.
What
RetroArch (PPSA99169) stops at
alarmon currentmain:This implements it, following FreeBSD.
alarm(seconds)arms one process-wide real-time alarm and returns the seconds left on the previous one. Any partial second counts, as in FreeBSD'salarm.c, which adds one whenit_value.tv_usecis non-zero.alarm(0)cancels the pending alarm.sigaction/signalapplies:alarm: delivering SIGALRM to a guest handler is not implemented, because the signal layer has no asynchronous delivery to a guest handler yet.GuestAlarm_nid_no_patch). libSceLibcInternal, which titles importalarmfrom, forwards to it.Tested
Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release.
guest_signal_tests:alarm(0)with nothing pending returns 0; arming 5 and then re-arming 3 returns 5; cancelling returns 3, then 0. With SIGALRM ignored, a 1-second alarm expires during a 1.5 s sleep without ending the process, and nothing is left pending.maincf8b129e2: onmainit stops at the line above. With this branch it gets pastalarmand stops atFAIL: unresolved ELF import E4wZaG1zSFc from libSceLibcInternal.prx(dirname, closed #1761).maincf8b129e2. Full suite: 550 of 554 pass, 1 skipped.agc_driver_prepared_shaders_debug_failureandguest_memoryfail the same way on cleanmainon this machine.agc_driver_prepared_shadersfailed under the parallel run and passes alone (twice). It was run from the generatedCTestTestfile.cmakecommands because antivirus blocksctest.exeon this machine.tools/check_conventions.pypasses.The default-disposition and guest-handler paths end the process, so they have no in-process test. Not tested on Linux or macOS.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T13:16:06Z.
Progress report (
181420f→e5ae8df)➖ System libraries: 85.66% (+0.0%, +1 implemented functions)
✅ 1 implemented
alarm_nid_postfixImported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-10T13:39:46Z.
A second title stops at
alarmonmain. I triaged the whole homebrew catalog onmaincf8b129e2(Windows 11, MinGW-w64 GCC 15.2.0; each release ZIP checked against its catalog sha256, relinked withrelinker --windows --registry, run for 12 s):mainDQXJraCc1rA(alarm)E4wZaG1zSFc(dirname)DQXJraCc1rA(alarm)E4wZaG1zSFc(dirname)The "with this PR" column comes from one build of
mainwith this PR plus #1872, #2478 and #2024, which add unrelated imports (pthread_set_name_np,dup/dup2,utime).AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:04:20Z.
Review: CHANGES_REQUESTED
Thanks,
alarmis a real next stop for RetroArch/Porpoise. One blocker, found on Linux:guest_signalshangs on Linux (killed after 455 s by ctest); onmainit passes. All checks finish, then the process never exits.alarmLock/alarmChangedare function-local-namespace statics, andRunAlarmsis a detached thread parked inalarmChanged.wait(lock)(core/libs/prx/libkernel/System/src/Signals.cpp:109). At exit the staticstd::condition_variableis destroyed with a waiter still on it, and glibc'spthread_cond_destroyblocks forever. A 10-line program with a detached thread waiting on a global condition variable reproduces it. MinGW doesn't block there, which is why it passed on your machine. This would also hang any guest process that callsalarmand then exits normally.Fix: don't destroy the state at exit (e.g. heap-allocate the mutex/condition variable/deadline and leak them), or make the thread stoppable and joined; then rerun
guest_signalson Linux.Signals.cpp(lines 7-8); whichever lands second needs a trivial rebase.The rest matches FreeBSD's
alarm.c(round-up remaining seconds,alarm(0)cancels) and the new test pins those values.Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-10T22:12:05Z.
Linux check, since this was only run on Windows: 018097ec merged onto
main262c0316(clean), Ubuntu 24.04, GCC 13, Release.guest_signalshangs on Linux. Onmainthe same binary exits 0 at once; with this PR it never exits (killed after 45 s withSIGKILL; plaintimeoutcan't stop it because the test ignores signal 15). A marker printed at the end ofmain()does show up, so every check passes and the hang is at process exit. At that point both threads sit infutex_do_wait: the main thread and the detachedRunAlarmsthread.That fits static destruction:
alarmChangedandalarmLockare namespace-scope statics, and glibc'spthread_cond_destroyblocks while the detached thread is still a waiter on the condition variable. A title that callsalarmand then returns frommainwould hang the same way on Linux. Keeping the alarm state alive for the whole process should avoid it, for example putting the mutex, condition variable and deadline in a struct allocated once withnewand never destroyed, or havingRunAlarmstake no lock that is destroyed at exit.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T23:27:18Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libkernel/System/src/Signals.cppL7-8Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-10T23:28:01Z.
Thanks @adriadam10 and @babyhuey for running it on Linux. Fixed in
e5ae8dfc:AlarmStateallocated once withnewand never destroyed.RunAlarmsthread waits on is torn down at exit.I also rebased onto current
main(no conflicts; #3047 hasn't landed yet, so the include change will be a one-line rebase whichever goes second).guest_signalspasses on Windows. I don't have a Linux machine here to confirm the exit hang is gone. Could one of you rerun it there?AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-10T23:32:37Z.
Confirmed on Linux:
e5ae8dfcmerged ontomainad336923(clean), Ubuntu 24.04, GCC 13, Release.guest_signalsnow exits 0 in 1 to 2 s on each of five runs, and passes 5/5 underctest --repeat until-fail:5. Porpoise (PPSA99764) gets pastalarmand stops atundefined symbol: 2eQpqTjJ5Y4(asinh).Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T23:40:24Z.
Review: APPROVED
Checked on Linux: build and
guest_signalspass on the merge with main (and fail to link without the change); the exit hang is gone, also confirmed by @babyhuey on Ubuntu.alarmsemantics match FreeBSDalarm.c(rounding up partial seconds, 0 cancels), and the unmodelled guest-handler path throws. Merging.