Repository navigation
feat(libc): implement the _Smtx shared mutex calls over libkernel's rwlocks - #12146
Conversation
Progress report (7feb37e → 7542cc1)📈 System libraries: 26.39% (+0.02%, +12 implemented functions) ✅ 12 implemented
Changed libraries (implemented exports)
|
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Windows result (the description has WSL2 only). Setup: Windows 11 Pro 26300, AMD Ryzen 7 7800X3D, WinLibs GCC 15.2.0 r7, Ninja Release, Test: No control: the Not tested: Linux on this machine (in the description), macOS, contention beyond what the test does, any title. AI-assisted (Claude Code). Follow-up, 2026-10-30 — private frozen-main integration qualification: author Windows 11 Pro 26300 / WinLibs GCC 15.2.0 r7 and Ubuntu 22.04.1 / WSL2 / GCC 11.4.0, Ninja Release: on each platform, the actual selected thread family passed 67/67 on main and 67/67 on the private composition, with zero skips; the unchanged shared-mutex fixture passed 20/20 executions (one registration). Linux's first invocation was loader-traced, followed by 19 normal serial repeats. Both libc/libkernel were freshly rebuilt together with the matching forward-table layout, and Release checks use direct abort calls. Each platform's actual patched production libc exports all 12 NIDs; fixture imports and live module/loader evidence resolve the same-arm unpatched production libc/libkernel. Patched NID export inspection and source-named fixture execution are separate evidence paths. Main plus only the identical fixture/registration produces the expected compile-availability RED for missing declarations/forward fields; this is not runtime RED. Focused CPU component evidence for the private composition. Follow-up qualification assisted by Codex. Follow-up, 2026-10-30 — shared macOS CI prerequisite At exact head Existing PR #13220 commit Please integrate the existing #13220 fix into this branch, or rerun the macOS jobs after it lands, so CI can continue on a fresh head. AI-assisted (Claude Code; Codex follow-up). |
cefb2b4 to
ec195de
Compare
ec195de to
6d7b03b
Compare
|
Windows run of the current head Setup: Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
I didn't repeat the native AI-assisted: yes (Claude Code). |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
The wrapper mapping, thread tests, and native time-difference comparison are thoroughly documented, but this branch is based on main 2227f13661, while current main is 52c09d567d2fa453494dd720fcf53a98149468e4 (500 commits ahead). CONTRIBUTING.md requires each branch to be based on current main, so the exact-head results do not yet establish that this large thread/runtime change integrates with the current pthread implementation.
What I ran
- Reviewed exact head
6d7b03b730560c3772b370811f5b8c25d1a81c07and its declared base. - Ran a merge preview and
git diff --checkagainst currentmain. - Checked the author’s focused Linux/Windows tests, native comparison, and current hosted checks.
Results
| Check | Result |
|---|---|
| Current-main merge preview | Clean, but current main is not in the branch history |
git diff --check |
Passed |
| Focused tests | Author reports 20 mutex-test runs and 69 thread tests on the older base; Windows also reports 20 and 69 passes on this head |
| Native comparison | Reported comparison is on an earlier head; the implementation of the time-difference helper is unchanged by the rebase |
| Current product jobs | Skipped by hosted PR CI |
Please refresh onto current main and rerun the focused shared-mutex and pthread suites on that exact integrated head. I did not run a local build or the thread tests.
…wlocks The bundled libc.prx (J03093718) implements std::shared_mutex's _Smtx_* calls as thin wrappers of scePthreadRwlock*: a zero result stays 0, a 0x8002xxxx kernel code becomes its errno and any other result becomes 1. _Smtx_init names the lock SceLibc_V2Smtx, _Smtx_init_with_name passes a non-empty name, and the timed locks turn the absolute timespec into microseconds with std::__sce_v2::_Timespec64_diff_to_useconds, which is exported as well.
6d7b03b to
3c592e8
Compare
MarcZX10
left a comment
There was a problem hiding this comment.
Re-checked — changes requested
The new report gives 20 runs of guest_libc_shared_mutex, the listed pthread/thread suite, and all twelve export checks on 3c592e8141. The branch is based on 1b580f13cf; current main is ba5b5330b3, and it has changed this PR's libc CMake registration since that base. Please merge current main and rerun the focused mutex/thread tests and export check on the resulting exact head. The existing report does not cover that integration.
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
I reviewed exact head 797464dfc282e61031ea9081f308930a3d4bd060 against PR base 98ddd9c1792bbab016ceed5db267a93d1d61f00a; its merge preview against current upstream main b7488e1ff53e6cfca82af972df1d09fa71e7051d is clean. Local git diff --check and repository conventions passed, and source/ABI plus CMake test registration were inspected; the author reports the exact-head shared-mutex test passing 20/20 and 67 related thread tests on WSL2, as well as zero mismatches in an earlier native-helper comparison. I did not build or run tests locally: hosted Windows CI passed but explicitly skipped this guest test, Linux CI was skipped, and both macOS write-watch jobs failed at CMake configuration on duplicate test names in the separate write-watch test project. Console/title behavior remains unverified. Reviewed implementation
|
@MarcZX10 The head 797464d you approved still merges cleanly into current @B-Howell Thanks for the Windows and Linux runs. The two macOS |
|
@AlexFigas Thanks. #13220 has now landed in One detail on the rerun: in I checked this branch only statically: head 797464d merges cleanly with |
|
@MarcZX10 #13220 has landed, so I merged |
|
@AlexFigas The two red At this head both macOS |
|
@MarcZX10 Head 7542cc1 merges current |
What
AnyPS5's libc had none of the
_Smtx_*calls behindstd::shared_mutexandstd::shared_timed_mutex. The bundledlibc.prxof PPSA21564 (buildJ03093718) exports all eleven, and this PR adds them as that binary implements them, plus the helper its timed locks call.Each call is a thin wrapper of a libkernel rwlock call:
_Smtx_initscePthreadRwlockInit(smtx, NULL, "SceLibc_V2Smtx")_Smtx_init_with_namescePthreadRwlockInit(smtx, NULL, name)_Smtx_destroyscePthreadRwlockDestroy_Smtx_lock_exclusive,_Smtx_lock_sharedscePthreadRwlockWrlock,scePthreadRwlockRdlock_Smtx_try_lock_exclusive,_Smtx_try_lock_sharedscePthreadRwlockTrywrlock,scePthreadRwlockTryrdlock_Smtx_timedlock_exclusive,_Smtx_timedlock_sharedscePthreadRwlockTimedwrlock,scePthreadRwlockTimedrdlock_Smtx_unlock_exclusive,_Smtx_unlock_sharedscePthreadRwlockUnlock0x8002xxxxbecomes its errno, the low 16 bits. Any other non-zero result becomes 1._Smtx_initbuildsSceLibc_V2Smtxwithsnprintf("SceLibc_%s", "V2Smtx")._Smtx_init_with_namepasses the name only when it is non-null and non-empty (strncmp(name, "", 1)), the ruleSyncObjectNamealready applies to thestd::__sce_v2mutexes. The binary also drops the default name when the process's libc parameter has a non-null field at 0xa0. AnyPS5'sscePthreadRwlockInitdoes not keep names, so that case is not modelled.timespecthroughstd::__sce_v2::_Timespec64_diff_to_useconds(0xc9600, NIDm2SotKzIAw4), which this PR exports too. It readssceKernelGettimeofdayand normalizes the target's nanoseconds by floor division. A target that is not in the future gives 0. Otherwise the result is the difference rounded up to whole microseconds, asseconds * 1000000 + usecin 32 bits, so a wait longer than about 2147 s wraps. The port reads the same realtime microseconds through_Xtime_get_ticks.libc reaches libkernel through
PthreadSyncForwards_nid_no_patch, as thestd::__sce_v2::_Mtx_*calls already do. libkernel now registers its nine rwlock functions there. The new entries sit beforedetach, so #9447's entries appended afteryielddo not collide with them.Tested
On Ubuntu 24.04.5 under WSL2 (GCC 13.3, Release), head 7542cc1 (this PR with
main1a5267f merged in; b9bd78e hadmain4ac683f and 797464dmain98ddd9c) unless noted. The 72 thread-family tests (guest_libc_shared_mutex,guest_libc_threads,guest_pthread_*,guest_kernel_sys_pthread*andthreads*,guest_std_thread*) pass 3 runs on it,guest_libc_shared_mutexpasses 20 repeats in a row, and the standalone configure ofcore/libs/tests/write_watchthat the macOS jobs run succeeds now that #13220 is onmain. Therelinkerjobs that failed on b9bd78e failed incheck_skips_ctestbecausemainhad lost--require-testsintools/check_skips.py;mainhas restored it, andcheck_skipsandcheck_skips_ctestpass on this head.guest_libc_shared_mutex. It passes 20 runs in a row.scePthreadRwlockTrywrlockon the same handle returns0x80020010, so the handle is a libkernel rwlock._Timespec64_diff_to_useconds: past and zero targets give 0; nanoseconds of −2 s and +2 s are normalized; a target 2 s + 1 ns ahead rounds up; 3000 s ahead wraps to 3,000,000,000 as an unsigned 32-bit value; a null pointer throws.0x80020023→ 35,0x8002ffff→ 65535,0x80550001, −1 and 7 → 1, for every wrapper. Without libkernel registered, a call throwsstd::runtime_error._Timespec64_diff_to_usecondsis unchanged since). I mapped the binary's segments into a Linux process, stubbed itssceKernelGettimeofdayimport and ran its_Timespec64_diff_to_usecondsnext to this one. They agree on 19,200 edge combinations (nanoseconds at 0, ±1, ±10⁹ − 1, ±10⁹, ±10⁹ + 1, ±2·10⁹,INT64_MIN,INT64_MAX, and so on, against several current times) and on 3,000,000 random targets: 0 mismatches.main's newguest_pthread_cancel_inactive_wait_*cases included:guest_kernel_sys_pthread*,guest_pthread_*,guest_libc_threads,guest_libc_cnd_*,guest_sce_v2_exceptionsandguest_ult_sync_rwlock-*. The builtlibc.prxexports all twelve NIDs.python3 tools/check_conventions.py --base origin/mainpasses.python3 tools/pr_overlap.py --branch feat/libc-shared-mutexlists no pull request with the same exports or conflicting lines.std::__sce_v2::_Thrd_startand others) also extendsPthreadSyncForwards_nid_no_patchand could not be compared, because it conflicts withmain.main, feat(libc): add the std::__sce_v2 thread start, timed wait, clock and processor count calls #9447 among them. Merged with this branch, each gives the same conflicts as merged withmain(git merge-tree), so this PR adds no conflict.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)