feat(libkernel_sys): implement scePthreadMutexIsowned, utrace and tcsetsid #9713
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9713"
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 simonbronk on 2026-10-22T09:38:41Z.
What
Implements 3 libkernel_sys exports that were discovery stubs:
scePthreadMutexIsownedreturns 0 when libkernel's existingpthread_mutex_isowned_npreturns 0, and0x80020000plus its result (0x80020001) when the calling thread owns the mutex. That is what firmware 13.42'slibkernel_sys.sprxdoes, as BunnyFl measured by running the export in an emulator. An uninitialized or destroyed mutex, or one another thread owns, gets 0.utracereturns 0 without reading its record.sys_utracedoes that for a process ktrace does not trace, and nothing traces the guest.tcsetsid(fd, pid)fails withEINVALunlesspidisgetsid(0), then issuesTIOCSCTTYwith a null argument through the guestioctl, as libc'stermios.cdoes and as BunnyFl confirmed in firmware 13.42's module. No guest descriptor is a terminal, so an open descriptor getsENOTTYand a closed oneEBADF.The guest socket
ioctlreturnedEFAULTfor any null argument before looking at the request, which would maketcsetsidon a socket fail withEFAULT. As in FreeBSD'ssys_ioctl, which copies nothing for a void request without a parameter length,Udp.cppnow faults on a null argument only for a request with input or a length; the existing socket checks inguest_kernel_fcntlkeep theirEFAULT.The implementations are in
libkernel_sys/Export.cpp, next to the other implemented exports, and their stubs are removed fromExport.Discovery.cpp. Thepthread_switch_add_np/pthread_switch_delete_nppart of this PR was dropped when it was rebased, since #9172 already returnsENOTSUPfrom both. The debt entry records what was measured and the assumption that the PS5 kernel hasKTRACE(without itutracewould returnENOSYS).Tested
Linux, Ubuntu 24.04 x86-64 container under Rosetta on Apple silicon (Colima), GCC 13, RelWithDebInfo with ASan, head
eea3c721a7(maind820fef182merged in).guest_kernel_sysgets new checks:scePthreadMutexIsownedbefore init, after init, while locked (0x80020001from the owner, 0 from another thread), after unlock and after destroy;utracewith a record, with an empty one and with 4096 bytes (errno untouched);tcsetsidwith a wrong session (EINVAL, checked before the descriptor), on an open file and on a UDP socket (ENOTTY) and on -1 (EBADF).The full build fails only in
libSceAddressSanitizer, which this PR does not touch: in an ASan build its declarations clash with GCC's__asan_*built-ins, the same onmaind820fef182, and #12894 stops building it under ASan. Every test target below was then built explicitly (exit 0). 48 focused tests pass with no ASan reports: theguest_kernel_sys*tests,guest_pthread_mutex_errors,guest_pthread_mutexattr,guest_pthread_barrier,guest_getlogin,guest_getlogin_no_session,guest_np_session_signaling,guest_net_socket_state,guest_kernel_fcntl,guest_kernel_fcntl_sync,guest_udp,guest_sendfileand theguest_socket_*tests. Windows: Dom3005 ran an earlier head onmain11f976b27c(focused suite passes). macOS not run.check_conventions.py --base origin/mainpasses.pr_overlap.pyreports no PR with the same exports; its only conflicting lines are with #11219, which edits the socketioctlnext to theUdp.cppline changed here; orezraey will keep both if this lands first. No title tested.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T12:05:48Z.
Review: COMMENTED
Reviewed exact head 085590dd4c31b0ec6ef01cecac623b2d2821cf6d. The implementations are narrowly scoped and the checked behaviors line up with the cited FreeBSD 11.4 sources: the mutex ownership query returns a boolean-style result, switch hooks return
ENOTSUP, andtcsetsidvalidates the session before issuingTIOCSCTTY. The tests cover owner/non-owner and destroyed-mutex cases, errno precedence, and utrace argument sizes. Current conventions and diff checks pass; merge is clean. I could not independently runguest_kernel_sysbecause there is no configured build here and the filesystem is full. The PR’s Linux/ASan run and Windows/macOS status are author-reported; hosted product CI is skipped. Please refresh this 13-commits-behind branch to current main and rerun the focused suite on that base before approval. No code-level defect found in this review.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T13:34:07Z.
I reviewed this head alongside open #9582, which removes the throwing
pthread_timedjoin_npdeclaration from the samelibkernel_sys/Export.Discovery.cpparea where this PR removes the twopthread_switch_*declarations.git merge-treeon the exact open heads reports a content conflict in that file. Could you and the #9582 author agree on an order/resolution and preserve both sets of removals when rebasing? This is an integration note only; I am not asking either PR to add a dependency unless one actually needs to wait.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T15:37:00Z.
Review: DISMISSED
I reviewed exact head 085590dd4c31b0ec6ef01cecac623b2d2821cf6d.
Checks run locally:
The mutex ownership query, unsupported switch hooks, and untraced utrace behavior are consistent with the cited FreeBSD 11.4 implementations, subject to the PS5 KTRACE assumption already documented in the debt note. I found no major functional defect.
One small fidelity detail: FreeBSD 11.4 tcsetsid calls ioctl(fd, TIOCSCTTY, NULL), while this implementation passes a pointer to a local zero integer. AnyPS5 currently returns ENOTTY for guest file descriptors either way, so this does not change the covered result, but forwarding nullptr would match the cited libc behavior.
Before merge, update the branch to current main and rerun the focused suite. This head is 63 commits behind current main; CONTRIBUTING.md requires branches to stay up to date. The main commits since its base do not touch the four changed paths, but the sync and post-sync validation remain outstanding.