Skip to content

feat(libkernel): add setitimer on the alarm timer - #3800

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
YossiYad:carry/libkernel-setitimer
Oct 12, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
YossiYad:carry/libkernel-setitimer

Conversation

@YossiYad

Copy link
Copy Markdown
Contributor

What

Carries screamm's screamm/AnyPS5:feat/libkernel-setitimer commit from #3735 unchanged onto current main, preserving its author:

  • Implement setitimer on the existing alarm timer thread, after FreeBSD 11.4 kern_time.c and alarm.c: EINVAL for an unknown timer or a value/interval with a negative field, tv_usec >= 1000000 or more than INT32_MAX/2 seconds; a null value reads the timer (EFAULT when the output is null too, after the timer check); a zero value disarms and returns the previous remaining time and interval; a non-zero value arms, re-armed by it_interval on expiry. alarm now clears the interval as FreeBSD's does.
  • It never reports success for a signal it cannot deliver, which is why the earlier libkernel/libSceLibcInternal: functions, permission persistence and LoadExec handover needed by PS5 homebrew #3293 was closed. Expiry with a guest SIGALRM handler or while SIGALRM is blocked throws with the reason, as alarm already does; ITIMER_VIRTUAL/ITIMER_PROF throw when armed (no CPU time accounting) and read as zero; an interval below 1 ms throws (the kernel's tick rounding is not known). Recorded in TechnicalDebt.
  • PS5MC (PPSA99420) imports setitimer, as reported in libkernel: setitimer is absent (PS5MC); branch ready on the alarm timer, never reporting an undelivered signal #3735.

getitimer is in the open #3572 and touches the same Signals.cpp; whichever merges second should read the interval this PR stores (alarms.interval), since #3572 reports it as always 0.

The library progress moves from 2903/3383 (85.81%) to 2904/3384 (85.82%). The total rises by one because setitimer was not exported before.

Closes #3735.

Tested

Linux (Bazzite 44, GCC 16.2.1, Ninja, Release, -DBUILD_TESTING=ON), based on main a11c8f7f:

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Progress report (0142215 → 5e1ffc2)

➖ System libraries: 86.46% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel setitimer_nid_postfix

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed labels Oct 11, 2026
@YossiYad
YossiYad force-pushed the carry/libkernel-setitimer branch from 2d9da88 to ec642b2 Compare October 11, 2026 22:20
@YossiYad

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (33067ca0c). main gained getitimer in 1fc9b4d, which declares the same GuestItimerval in Signals.cpp; the carried commit now keeps the one copy from main, with no other change to it.

One follow-up commit: getitimer on main always reported a zero it_interval, which was true while alarm was the only writer. With setitimer arming a periodic ITIMER_REAL, it read back as one-shot. ec642b2 reports the interval and extends guest_itimer to read the timer through getitimer after re-arming; the new check fails without the fix (getitimer did not report the setitimer interval).

Linux, GCC, Release: full ctest 901/901 before the follow-up; after it guest_itimer, guest_getitimer, guest_signals and guest_signal_sets pass. tools/check_conventions.py --base upstream/main passes.

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 11, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Same as #3781: conflicts with main in docs/dev/TechnicalDebt.md; please rebase.

@MarcZX10

Copy link
Copy Markdown
Contributor

I independently rebuilt the carried implementation on current main (bca7a29d) with GCC 12.2, Release/Ninja, and BUILD_TESTING=ON. The guest_itimer and guest_signals CTest cases passed (2/2), including the getitimer interval regression check, and tools/check_conventions.py --base upstream/main passed. This validates the rebase integration locally; it does not change the PR branch or replace its CI.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
#4382 core/libs/prx/libkernel/System/src/Signals.cpp L92, L101, L107, L113, L126, L128, L138-142, L183
core/libs/tests/GuestItimer.cpp
setitimer_nid_postfix core/libs/tests/GuestItimer.cpp

@ArekatlaNishanthchowdary

Copy link
Copy Markdown
Contributor

Rebase handoff: the two commits rebased onto current main, authorship unchanged: ArekatlaNishanthchowdary:carry/libkernel-setitimer-rebased (638bc3df3, base d53960612).

The only conflict was docs/dev/TechnicalDebt.md, which main split into one file per library in 342a8c4. The setitimer entry is now the last line of docs/dev/debt/libkernel.md, with its link changed to ../../../core/...; TechnicalDebt.md is left as on main. The code applied without conflict.

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release: full build passes, full ctest 996/996 passed, tools/check_conventions.py --base origin/main passes. Linux not run.

To pick it up: git fetch https://github.com/ArekatlaNishanthchowdary/AnyPS5 carry/libkernel-setitimer-rebased && git reset --hard FETCH_HEAD, then force-push.

AI-assisted: yes (Claude Code).

screamm and others added 2 commits October 12, 2026 22:08
PS5MC (PPSA99420) imports setitimer (hPWDGx8ioXQ, aerolib) at registry
index 472, after tcsetpgrp and before getitimer. Predicted stop:
"FAIL: unresolved ELF import hPWDGx8ioXQ from libkernel.prx".

setitimer follows FreeBSD 11.4 kern_time.c (8c639945) sys_setitimer and
kern_setitimer: EINVAL for an unknown timer and for an itimerfix failure
or more than INT32_MAX / 2 seconds; a zero value clears the interval and
disarms; a null value reads the timer, EFAULT when the output is null too.
ITIMER_REAL shares the alarm state, now with an interval that re-arms it
as realitexpire does; alarm clears it, as FreeBSD's alarm.c does.

Guest SIGALRM handlers are not run, so an expiry with a handler, or with
SIGALRM blocked (signals are never left pending), throws naming the
interval; SIG_IGN drops it and the default disposition exits with 142,
as alarm already did. Intervals below 1 ms throw (itimerfix rounds them
to tick / 16 and the console's hz is unknown). ITIMER_VIRTUAL and
ITIMER_PROF throw when armed and read and disarm as zero.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
getitimer on main predates setitimer and always reported a zero it_interval, so a periodic ITIMER_REAL armed by setitimer read back as one-shot.
@adriadam10

Copy link
Copy Markdown
Collaborator

Rebased onto current main; the only conflict was the TechnicalDebt entry, now in docs/dev/debt/libkernel.md (author and code unchanged). Checked on Linux: build, guest_itimer, guest_signals and guest_signal_sets pass. Merging once CI is green. #4382 carries the same commit and becomes redundant.

@adriadam10
adriadam10 force-pushed the carry/libkernel-setitimer branch from ec642b2 to 5e1ffc2 Compare October 12, 2026 20:11
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 12, 2026
@adriadam10
adriadam10 merged commit 5382635 into boykopovar:main Oct 12, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libkernel: setitimer is absent (PS5MC); branch ready on the alarm timer, never reporting an undelivered signal

6 participants