feat(libkernel): implement pthread_mutex_getprioceiling and setprioceiling #9326
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9326"
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 erickerxhalli on 2026-10-21T18:31:22Z.
What
Implements
pthread_mutex_getprioceiling,pthread_mutex_setprioceilingand their SCE twinsscePthreadMutexGetprioceilingandscePthreadMutexSetprioceilingin libkernel; all four threwNotImplemented_nid_no_patchfrom libkernel_sys. They are declared once inlibkernel/include/Api.hppwith their real signatures, and the four(void)discovery declarations are removed fromlibkernel_sys/include/Api.hpp.scePthreadMutexInitnow copies the attribute's protocol and ceiling into the mutex, so a mutex made through the SCE calls or throughpthread_mutex_init(which calls it) gets them;scePthreadMutexattrSetprotocolstores the protocol since #8373. The getters returnEINVAL(0x80020016from the SCE twin) for a static, adaptive or destroyed handle or a mutex withoutPTHREAD_PRIO_PROTECT, before the output pointer is used. This, and the SCE path passing the protocol and ceiling on, follow firmware 13.42's libkernel_sys as BunnyFl reported in this PR; the checks match FreeBSD 11.4's_pthread_mutex_getprioceiling. A null mutex, or a null output for a priority-protected mutex, throws: the console dereferences it.The set does the same checks, then, as FreeBSD's
do_set_ceilingdoes in the kernel, takes the mutex unless the caller holds it, so it waits for another holder, and writes the previous ceiling whenold_ceilingis given. On the console that part runs in the kernel (_umtx_opUMTX_OP_SET_CEILING), which the 13.42 dump does not contain, so it is recorded as unverified. FreeBSD rejects a ceiling aboveRTP_PRIO_MAX(31), a bound that does not fit the console's 256-767SCHED_RRpriorities, so a ceiling outsidesched_get_priority_min(SCHED_RR)tosched_get_priority_max(SCHED_RR)throws. The SCE twins' signatures follow Orbital'sdb_types.json. Priority protection itself is still not applied. The gaps are under Functional indocs/dev/debt/libkernel.md.The new
guest_pthread_mutex_prioceilingtest checksEINVALand0x80020016, with and without an output pointer, for a static, adaptive, default and destroyed mutex; the ceiling taken from a POSIX attribute; the set with and without the old-ceiling output; that 255 and 768 throw and leave the ceiling; the set while the caller holds the mutex and while another thread does. It also covers a mutex made entirely through the SCE calls (protocol 2 with ceiling 300, and protocols 0 and 1, which giveEINVAL), a POSIX attribute passed toscePthreadMutexInit, and an SCE attribute passed topthread_mutex_init, each read and written through the other API.Tested
addd914):ctestran 2287 tests; 2275 passed, includingguest_pthread_mutex_prioceiling,guest_pthread_mutexattr,guest_pthread_mutex_errors,guest_pthread_timed_locks,guest_pthread_destroyed_objects,guest_kernel_sys,patched_librariesandpublic_headers. The 12 failures come from the container, not this change:guest_net_protocol,guest_net_buffer_validation,guest_net_nodelay_readback,guest_sce_net_keepalive,guest_socket_options,guest_socket_stream_options,guest_socket_address_lengthandguest_tcpopenAF_INET6sockets and the container has no IPv6;agc_submit_progress,agc_submit_progress_no_timeline,agc_driver_pipelined_metadata_passandagc_driver_pipelined_metadata_pass_draw_pipelinestop atvkCreateInstance(VK_ERROR_INCOMPATIBLE_DRIVER), as it has no Vulkan driver.scePthreadMutexInit, copying only the protocol, checking the output pointer before the protocol, returning 0 for a null output on a priority-protected mutex, or returning POSIX numbers from the SCE twins each makesguest_pthread_mutex_prioceilingfail. On the first commit, dropping the protocol check, the old-ceiling write, the owner check, the unlock or the range check each did too.addd914):build.ymlwithfull=true,linux=falseon my fork passed (run); the only skips were tests that need Vulkan or a display.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
https://claude.ai/code/session_01WYjMwvLdPR8iX8EP8tQYWa
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T05:47:48Z.
Review: COMMENTED
Checked against main
4a17c7175and FreeBSD libthr thr_mutex.c (_pthread_mutex_getprioceiling/_setprioceiling) and kern_umtx.cdo_set_ceiling:old_ceilingis written only when non-null. Throwing outside 256..767 instead of applying RTP_PRIO_MAX seems reasonable, and it is recorded in the debt file.scePthreadMutexattrSetprotocol(src/Mutex.cpp:149) validates the protocol and discards it, andscePthreadMutexInit(src/Mutex.cpp:159-166) copies only the type. The protocol and ceiling are copied only inpthread_mutex_init(Posix/Mutex.cpp:68-71). SoscePthreadMutexattrSetprotocol(&a, 2)+scePthreadMutexInit(&m, &a, "m")+scePthreadMutexGetprioceiling(&m, &c)returns0x80020016for a mutex the title asked to be PRIO_PROTECT. The same happens withpthread_mutexattr_setprotocol+scePthreadMutexInit.scePthreadMutexattrSetprotocol, resetting the ceiling aspthread_mutexattr_setprotocoldoes, and move the protocol/ceiling copy intoscePthreadMutexInitnext toSetType. Then both init paths agree, and the "scePthreadMutexInit copies none" debt sentence can go. A test that creates the mutex through the SCE calls would cover it.scePthreadMutexInit". The code does it only inpthread_mutex_init.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T20:01:21Z.
Review: COMMENTED
Correction (2026-11-01): this review's claim that maintainers close PRs without a title ID is wrong. CONTRIBUTING allows
Unblocks: none; a title is only required when the PR fixes a title. The technical points below are unaffected.No title evidence. The template says
Unblocks: noneand the body names no title ID and no log line showing a title callingpthread_mutex_getprioceilingorsetprioceiling(or the SCE twins) on main. Please add the title ID and the log line (for example theNotImplementedhit these four exports produce today inlibkernel_sys/Export.Discovery.cpp), otherwise this is the export-only shape that gets closed.One question tied to the code:
pthread_mutex_setprioceiling_nid_postfixthrows for a ceiling outside the SCHED_RR range, while the getter and the other invalid-handle cases returnEINVAL. If the console returns an error code for an out-of-range ceiling rather than faulting, the throw turns a valid-input case into a host exception. What does the firmware 13.42 disassembly show for that check?