Skip to content

fix(libkernel): accept null results in gettimeofday and clock_getres - #2291

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
AchrafReyani:fix/libkernel-null-time-results
Oct 10, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
AchrafReyani:fix/libkernel-null-time-results

Conversation

@AchrafReyani

Copy link
Copy Markdown
Contributor

What

FreeBSD treats both result pointers as optional:

  • gettimeofday(tp, tzp) stores the time only when tp is not null (sys_gettimeofday: if (uap->tp) ...), so gettimeofday(NULL, &tz) or gettimeofday(NULL, NULL) succeeds.
  • clock_getres(id, res) stores the resolution only when res is not null, so clock_getres(id, NULL) succeeds. POSIX says the same, and it is the usual way to check that a clock exists.

Both functions threw std::invalid_argument for a null result, which aborts the title. They now write into a local value instead, and every other path is unchanged.

Overlap: #1676 adds a branch right after the clock_getres null check that this replaces, so whichever lands second needs a two-line rebase. I'll do it here if #1676 goes first.

Tested

Windows 11, WinLibs GCC 15.2.0 r7, Release, -DBUILD_TESTING=ON:

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 (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

@AchrafReyani

Copy link
Copy Markdown
Contributor Author

Full Linux and Windows builds and tests for this head (7d04df2e), using the project's Build workflow. I can't start the upstream manual run, so I ran the same build.yml in my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into current main (d70b8998):

Job Result
linux success; full build, ctest: 516/516 passed
windows success; full build, ctest: 507/507 passed
relinker (Linux, Windows, macOS) success

Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/37947367784

@github-actions github-actions Bot added libkernel needs rebase Conflicts with main, rebase needed labels Oct 9, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

This conflicts with main after today's merges; could you rebase? It passed testing and is otherwise ready.

FreeBSD's gettimeofday stores the time only when tp is not null, and
clock_getres the resolution only when res is not null; both succeed
otherwise. Both threw, which aborted a title probing a clock or only
asking for the time zone. Write into a local result instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AchrafReyani
AchrafReyani force-pushed the fix/libkernel-null-time-results branch from 7d04df2 to 70d6382 Compare October 10, 2026 03:33
@AchrafReyani

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (70d6382). The only conflict was in clock_getres: main added the CPU-clock redirect after the old null check. The null result is now replaced first, then the redirect runs, so clock_getres(cpuClock, NULL) also succeeds.

On Windows, guest_freebsd_clocks, guest_cpu_time_clocks and guest_thread_cpu_clock pass, ctest -E "^agc_|video_out" is 297/297, and check_conventions.py passes. The full Linux and Windows build for the new head is running and will be posted here.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 10, 2026
@AchrafReyani

Copy link
Copy Markdown
Contributor Author

Full Linux and Windows builds and tests for this head (70d6382e), using the project's Build workflow. I can't start the upstream manual run, so I ran the same build.yml in my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into current main (c72d5ce1):

Job Result
linux success; full build, ctest: 587/587 passed
windows success; full build, ctest: 573/573 passed
relinker (Linux, Windows, macOS) success

Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/38021702524

@oneandonlydean
oneandonlydean merged commit 50cea78 into boykopovar:main Oct 10, 2026
12 checks passed
SleglJan pushed a commit to SleglJan/AnyPS5 that referenced this pull request Oct 10, 2026
…ll-time-results

fix(libkernel): accept null results in gettimeofday and clock_getres
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.

2 participants