feat(libkernel): throw for a null pthread_condattr_getclock output #12925
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12925"
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 KernelPanicNT on 2026-10-29T14:38:14Z.
What
pthread_condattr_getclockno longer reachesNotImplemented_nid_no_patch: a null output pointer with a valid attribute now throwsstd::invalid_argument, because the native call faults there.scePthreadCondattrGetclockthrewstd::runtime_errorin the same case and now throwsstd::invalid_argumenttoo, so both forms report a native fault the same way. Every other path ofpthread_condattr_getclock,pthread_condattr_setclock,scePthreadCondattrGetclockandscePthreadCondattrSetclockalready matched the measurement and is unchanged. The test now checks every invalid clock ID from -1 to 16 for both setters. The two debt entries now list only what is still open.Source of the behaviour
Measured with a homebrew probe running as a payload process on a device. The probe resolved the system
pthread_condattr_*andscePthreadCondattr*symbols and used only its own attribute objects, with a fault handler around each call. It ran three sequences: POSIX init/set/get, SCE init/set/get, and SCE init/set with the POSIX getter.setclock0, 1, 2, 4getclockreports the IDsetclock-1, 3, 5 to 16EINVAL(POSIX 22, SCE0x80020016); stored clock unchangedsetclockwith a null attribute or a null handleEINVALgetclockwith a null attribute, a null handle or a destroyed attributeEINVAL; output not writtenpthread_condattr_getclockEINVAL(22) for a null attribute, a null handle or a destroyed attribute, without writing the outputdestroypthread_condattr_getclock(valid, nullptr)NotImplemented_nid_no_patchstd::invalid_argumentscePthreadCondattrGetclock(valid, nullptr)std::runtime_errorstd::invalid_argumentNot measured: a null or destroyed attribute together with a null output. It still returns
EINVAL, because FreeBSD 11.4 libthr checks the attribute first.Posix/Cond.cpp#L75-L80(pthread_condattr_getclock),libkernel_sys/Export.cpp#L1122-L1127(scePthreadCondattrGetclock), and the setter it already matched:Pthread/src/Cond.cpp#L207-L213.libkernel.md#L44,libkernel_sys.md#L11.std::invalid_argumentwhere the native code faults:libc.md#L38(feholdexcept).REVERSE_ENGINEERING.md.Tested
Linux (Ubuntu, GCC).
guest_pthread_condattrandguest_kernel_syspass. Both expectstd::invalid_argumentfor a null output with a valid attribute, andguest_pthread_condattralso checks that every invalid clock ID from -1 to 16 is refused by both setters and leaves the stored clock unchanged. WithPosix/Cond.cppandlibkernel_sys/Export.cppfrommain, both tests abort:guest_pthread_condattron thestd::runtime_errorfromNotImplemented_nid_no_patch, andguest_kernel_syson thestd::runtime_errorfromscePthreadCondattrGetclock.tools/progress.py: +1 implemented function (pthread_condattr_getclock, libkernel 700/745 -> 701/745).tools/check_conventions.pypasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T17:24:08Z.
Review: APPROVED
Reviewed head
602fc9c55aagainstmainbb04a4f1ea. I approve it.What I checked (macOS arm64, Apple clang, host only)
git merge-treeagainstbb04a4f1eamerges cleanly.git diff --checkis clean.tools/check_conventions.py --base upstream/mainpasses, and it also passes with this PR's title and body.d106002967is the same tree asreleng/11.4(gh api comparereportsidentical). Lines 82-90 ofthr_condattr.ccheck the attribute before writing throughclock_id. That is the order both getters keep for the unmeasured case of a null attribute with a null output.scePthreadCondattrSetclockverbatim from this head, plus the PR's rows (null/unset/destroyed attribute with and without an output, valid attribute with a null output for both forms, setclock 0/1/2/4 and -1/3/5..16 for both setters). It passes.main'sNotImplemented_nid_no_patchmain'sstd::runtime_errorINT_MAX)Optional, not blocking
libkernel.mdentry cited the payload SDK'spthread.hfor the signature. The new entry drops that link, and the signature's source is still useful. Consider keeping it.AI-assisted: yes