feat(libkernel): implement pthread_rwlock_reltimedrdlock_np and pthread_rwlock_reltimedwrlock_np #9265

Merged
HQasper merged 1 commit from upstream-pr/9265 into main 2026-10-23 03:05:37 +00:00
HQasper commented 2026-10-21 16:56:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by HQasper on 2026-10-21T16:56:55Z.


What

pthread_rwlock_reltimedrdlock_np (dYv-+If2GPk) and pthread_rwlock_reltimedwrlock_np (RRnSj8h8VR4) were missing from libkernel.prx, so a title importing either stopped at load with FAIL: unresolved ELF import ... from libkernel.prx.

  • In libkernel they sit next to the absolute-time pthread_rwlock_timed*lock calls: a zero lock is initialized as by pthread_rwlock_rdlock, then scePthreadRwlockTimedrdlock / scePthreadRwlockTimedwrlock run with the microsecond count and the SCE error is turned into a POSIX error number, the same way pthread_cond_reltimedwait_np maps onto scePthreadCondTimedwait.
  • The throwing copies in libkernel_sys/Export.Discovery.cpp are removed, since check_conventions allows an export in one library only (duplicate-export). An import of these two from libkernel_sys now no longer resolves, as for the other libkernel pthread calls.
  • The signature (rwlock, u32 usec) comes only from shadPS4, which registers one function for each of these NIDs and for its scePthreadRwlockTimed* twin (rwlock.cpp); FreeBSD 11.4 libthr has no such functions. This is recorded in the libkernel debt file.

Tested

Linux (Ubuntu container, GCC, Release, BUILD_TESTING=ON):

  • guest_pthread_rwlock with a new relative-timeout case: passed. It checks a zero lock initialized by both calls, EINVAL after destroy, a shared read beside another reader, ETIMEDOUT after at least 15 ms for a 20 ms timeout and at once for 0 against a reader and a writer, and that a long timeout succeeds once the holder lets go. Breaking the write call (timeout forced to 0) makes it fail.
  • guest_cond_timedwait and guest_kernel_sys (unchanged): passed.
  • After nid_patcher, the patched libkernel.prx exports dYv-+If2GPk and RRnSj8h8VR4 (nm -D).
  • python3 tools/check_conventions.py --base upstream/main: passed.
    Windows 10 (MinGW-w64 GCC 15.2.0 WinLibs x86_64-ucrt-posix-seh r7, Release, BUILD_TESTING=ON), on 923eb034b, which has the same implementation; the later commit only drops two test lines and moves the debt entry:
  • guest_pthread_rwlock, guest_cond_timedwait and guest_kernel_sys: 3 of 3 passed.

Not tested: any title. None of the titles checked here import the two NIDs.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Duplicate and overlap check

Checked on 2026-10-21 against upstream main cecb540a6 and the heads of all 918 open pull requests:

  • No open pull request and no commit on main adds or changes pthread_rwlock_reltimedrdlock_np or pthread_rwlock_reltimedwrlock_np; on main they appear only as the libkernel_sys stubs this removes (44c531bf0).
  • The branch merges cleanly into main, and merging it with each open pull request adds no conflict that the pull request does not already have with main.
  • Related: #9165 makes scePthreadRwlockTimed*lock time out instead of returning EDEADLK when the caller holds the write lock. These two calls inherit that, and the new test makes no claim about that case; with #9165 merged in, guest_pthread_rwlock still passes. #8373 (rwlock attributes) and #9160 touch the same files in other places; the debt entry was placed away from #9160's and #9165's insertions.
  • Not duplicates: #8890 (pthread_timedjoin_np) and #9072 (fiber attach) are other functions from the same scan.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4955259394 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9265). Originally posted by [HQasper](https://github.com/HQasper) on 2026-10-21T16:56:55Z. --- ### What `pthread_rwlock_reltimedrdlock_np` (`dYv-+If2GPk`) and `pthread_rwlock_reltimedwrlock_np` (`RRnSj8h8VR4`) were missing from `libkernel.prx`, so a title importing either stopped at load with `FAIL: unresolved ELF import ... from libkernel.prx`. - In libkernel they sit next to the absolute-time `pthread_rwlock_timed*lock` calls: a zero lock is initialized as by `pthread_rwlock_rdlock`, then `scePthreadRwlockTimedrdlock` / `scePthreadRwlockTimedwrlock` run with the microsecond count and the SCE error is turned into a POSIX error number, the same way `pthread_cond_reltimedwait_np` maps onto `scePthreadCondTimedwait`. - The throwing copies in `libkernel_sys/Export.Discovery.cpp` are removed, since `check_conventions` allows an export in one library only (`duplicate-export`). An import of these two from `libkernel_sys` now no longer resolves, as for the other libkernel pthread calls. - The signature `(rwlock, u32 usec)` comes only from shadPS4, which registers one function for each of these NIDs and for its `scePthreadRwlockTimed*` twin ([`rwlock.cpp`](https://github.com/shadps4-emu/shadPS4/blob/3a9f57265d28975658f1ca941daa5c879c7a74bd/src/core/libraries/kernel/threads/rwlock.cpp#L167-L179)); FreeBSD 11.4 libthr has no such functions. This is recorded in the libkernel debt file. ### Tested Linux (Ubuntu container, GCC, Release, `BUILD_TESTING=ON`): - `guest_pthread_rwlock` with a new relative-timeout case: passed. It checks a zero lock initialized by both calls, `EINVAL` after destroy, a shared read beside another reader, `ETIMEDOUT` after at least 15 ms for a 20 ms timeout and at once for 0 against a reader and a writer, and that a long timeout succeeds once the holder lets go. Breaking the write call (timeout forced to 0) makes it fail. - `guest_cond_timedwait` and `guest_kernel_sys` (unchanged): passed. - After `nid_patcher`, the patched `libkernel.prx` exports `dYv-+If2GPk` and `RRnSj8h8VR4` (`nm -D`). - `python3 tools/check_conventions.py --base upstream/main`: passed. Windows 10 (MinGW-w64 GCC 15.2.0 WinLibs `x86_64-ucrt-posix-seh` r7, Release, `BUILD_TESTING=ON`), on 923eb034b, which has the same implementation; the later commit only drops two test lines and moves the debt entry: - `guest_pthread_rwlock`, `guest_cond_timedwait` and `guest_kernel_sys`: 3 of 3 passed. Not tested: any title. None of the titles checked here import the two NIDs. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes ### Duplicate and overlap check Checked on 2026-10-21 against upstream `main` cecb540a6 and the heads of all 918 open pull requests: - No open pull request and no commit on `main` adds or changes `pthread_rwlock_reltimedrdlock_np` or `pthread_rwlock_reltimedwrlock_np`; on `main` they appear only as the libkernel_sys stubs this removes (44c531bf0). - The branch merges cleanly into `main`, and merging it with each open pull request adds no conflict that the pull request does not already have with `main`. - Related: #9165 makes `scePthreadRwlockTimed*lock` time out instead of returning `EDEADLK` when the caller holds the write lock. These two calls inherit that, and the new test makes no claim about that case; with #9165 merged in, `guest_pthread_rwlock` still passes. #8373 (rwlock attributes) and #9160 touch the same files in other places; the debt entry was placed away from #9160's and #9165's insertions. - Not duplicates: #8890 (`pthread_timedjoin_np`) and #9072 (fiber attach) are other functions from the same scan.
github-actions[bot] commented 2026-10-21 16:57:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T16:57:46Z.


Progress report (d34da5d → 8f13fe7)

📈 System libraries: 42.12% (+0.02%, +2 implemented, -2 removed functions)

✅ 2 implemented
Library Name
libkernel pthread_rwlock_reltimedrdlock_np_nid_postfix
libkernel pthread_rwlock_reltimedwrlock_np_nid_postfix
🗑️ 2 removed
Library Name
libkernel_sys pthread_rwlock_reltimedrdlock_np_nid_postfix
libkernel_sys pthread_rwlock_reltimedwrlock_np_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6321662182 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9265#issuecomment-6321662182). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T16:57:46Z. --- <!-- progress-report --> ### Progress report (d34da5d → 8f13fe7) 📈 **System libraries**: 42.12% (+0.02%, +2 implemented, -2 removed functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libkernel | `pthread_rwlock_reltimedrdlock_np_nid_postfix` | | libkernel | `pthread_rwlock_reltimedwrlock_np_nid_postfix` | </details> <details> <summary>🗑️ 2 removed</summary> | Library | Name | | - | - | | libkernel_sys | `pthread_rwlock_reltimedrdlock_np_nid_postfix` | | libkernel_sys | `pthread_rwlock_reltimedwrlock_np_nid_postfix` | </details>
harisibrar1 commented 2026-10-22 18:17:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T18:17:10Z.

Review: APPROVED


Checked against main a6646f8464 and shadPS4 rwlock.cpp @3a9f57265d:

  • The NIDs check out: dYv-+If2GPk and RRnSj8h8VR4 hash from the two names.
  • shadPS4 registers the same (rwlock, u32 usec) function for these NIDs and, via ORBIS(...), for scePthreadRwlockTimedrdlock/Timedwrlock. Forwarding to main's scePthreadRwlockTimed*lock(rwlock, KernelUseconds) is therefore consistent, and the error mapping (ETIMEDOUT, EINVAL for a destroyed lock, EDEADLK when the caller holds the write lock) is the same one main's absolute pthread_rwlock_timed*lock already uses.
  • The branch still merges cleanly into current main, and main hasn't touched the rwlock sources or the test since your base. Looks good to me.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5618842836 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9265#pullrequestreview-5618842836). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-22T18:17:10Z. **Review:** APPROVED --- Checked against main a6646f8464 and shadPS4 rwlock.cpp @3a9f57265d: - The NIDs check out: `dYv-+If2GPk` and `RRnSj8h8VR4` hash from the two names. - shadPS4 registers the same `(rwlock, u32 usec)` function for these NIDs and, via `ORBIS(...)`, for `scePthreadRwlockTimedrdlock`/`Timedwrlock`. Forwarding to main's `scePthreadRwlockTimed*lock(rwlock, KernelUseconds)` is therefore consistent, and the error mapping (ETIMEDOUT, EINVAL for a destroyed lock, EDEADLK when the caller holds the write lock) is the same one main's absolute `pthread_rwlock_timed*lock` already uses. - The branch still merges cleanly into current main, and main hasn't touched the rwlock sources or the test since your base. Looks good to me. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!9265
No description provided.