docs(debt): cite the bundled libc.prx for _Mtx_trylock, strdup and strndup #9613

Merged
JJenkx merged 1 commit from upstream-pr/9613 into main 2026-10-25 17:36:43 +00:00
JJenkx commented 2026-10-22 04:30:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T04:30:38Z.


What

Two libc debt entries said the console behaviour was unverified. This PR replaces that with what the libc.prx PPSA13934 ships in sce_module/ does. I read it from disassembly, not by measuring on a console. Only the debt file changes.

_Mtx_trylock (k6pGNMwJB08, 0x5cf0, 33 bytes)

  • It passes its argument to the import upoVrzMHFeE#A#B (scePthreadMutexTrylock, through the PLT stub at 0xc43c0) and maps the result:
    call   scePthreadMutexTrylock
    xor    %ecx,%ecx
    cmp    $0x80020010,%eax      ; SCE_KERNEL_ERROR_EBUSY
    mov    $0x4,%edx
    sete   %cl
    sub    %ecx,%edx             ; 3 for busy, 4 otherwise
    test   %eax,%eax
    cmovne %edx,%eax             ; 0 stays 0
    
  • So on the console, busy for an owned non-recursive mutex comes from the kernel mutex.
  • This libc keeps its own owner and count, and returns the same busy result. I didn't compare its result for a kernel error other than busy.

strdup (g7zzzLDYGw0, 0x6b440) and strndup (XGnuIBmEmyk, 0x6b650)

  • Neither checks for a null source:
    • strdup calls strlen (j4ViWNHEgww) on it.
    • strndup calls strnlen (5jNubw4vlAA).
  • Both then allocate the length + 1 and copy.
  • So both fault on a null source on the console, except strndup(NULL, 0): its strnlen reads nothing, and it returns an empty copy. Here that call returns null with EINVAL. The entry already explains why this libc returns EINVAL instead of faulting, and now also records that one case.

The qsort reading that was a second commit here moved to #9688, which makes qsort and qsort_s follow the bundled code and checks them against it.

Tested

Refreshed on 2026-10-24 as 38e535f939df1bcb74c1ee1a13fd6d37cf810ab7, one commit directly on main 25c1aa1e79329e0e2957b4fdd731144dad8be724, with no merge commits. The conflict touched the neighbouring nearbyintf debt entry: main's newer console measurement is preserved, while this PR's two-entry added/removed lines remain byte-identical to its prior head.

  • python3 tools/check_conventions.py --base 25c1aa1e79329e0e2957b4fdd731144dad8be724 and git diff --check 25c1aa1e79329e0e2957b4fdd731144dad8be724 pass.
  • Only docs/dev/debt/libc.md changes, with two lines added and two removed. No code, test, build, runtime or new console-measurement claim.
  • Pairwise merge-tree checks against #6713 668d51adbdb91248f49fdd28acbfd0b85adb98cd and #9087 7b400cbcfedb3f1235e1870f05ef59f2efea0578 find conflicts only in docs/dev/debt/libc.md. The retain-both landing agreements below remain applicable; neither is a functional dependency.

Landing order

The author of #6713 agrees that either landing order works. Resolve the additive _Mtx_trylock debt hunk by keeping main’s four entries, this PR’s _Mtx_trylock entry, then #6713’s “Application heap without process parameters” entry. If this PR lands first, #6713’s author will rebase accordingly. There is no code dependency between these PRs.

The author of #9087 agrees to either landing order: #9087 can land first and this PR will be refreshed afterward. If this PR lands first, #9087’s author will rebase its libc.md hunk and keep these two entries unchanged. Preserve both PRs’ overlapping strdup/strndup debt edits. There is no code dependency between these PRs.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4962123764 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9613). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T04:30:38Z. --- ### What Two libc debt entries said the console behaviour was unverified. This PR replaces that with what the `libc.prx` PPSA13934 ships in `sce_module/` does. I read it from disassembly, not by measuring on a console. Only the debt file changes. **`_Mtx_trylock` (`k6pGNMwJB08`, 0x5cf0, 33 bytes)** - It passes its argument to the import `upoVrzMHFeE#A#B` (`scePthreadMutexTrylock`, through the PLT stub at 0xc43c0) and maps the result: ``` call scePthreadMutexTrylock xor %ecx,%ecx cmp $0x80020010,%eax ; SCE_KERNEL_ERROR_EBUSY mov $0x4,%edx sete %cl sub %ecx,%edx ; 3 for busy, 4 otherwise test %eax,%eax cmovne %edx,%eax ; 0 stays 0 ``` - So on the console, busy for an owned non-recursive mutex comes from the kernel mutex. - This libc keeps its own owner and count, and returns the same busy result. I didn't compare its result for a kernel error other than busy. **`strdup` (`g7zzzLDYGw0`, 0x6b440) and `strndup` (`XGnuIBmEmyk`, 0x6b650)** - Neither checks for a null source: - `strdup` calls `strlen` (`j4ViWNHEgww`) on it. - `strndup` calls `strnlen` (`5jNubw4vlAA`). - Both then allocate the length + 1 and copy. - So both fault on a null source on the console, except `strndup(NULL, 0)`: its `strnlen` reads nothing, and it returns an empty copy. Here that call returns null with `EINVAL`. The entry already explains why this libc returns `EINVAL` instead of faulting, and now also records that one case. The `qsort` reading that was a second commit here moved to #9688, which makes `qsort` and `qsort_s` follow the bundled code and checks them against it. ### Tested Refreshed on 2026-10-24 as `38e535f939df1bcb74c1ee1a13fd6d37cf810ab7`, one commit directly on `main` `25c1aa1e79329e0e2957b4fdd731144dad8be724`, with no merge commits. The conflict touched the neighbouring `nearbyintf` debt entry: main's newer console measurement is preserved, while this PR's two-entry added/removed lines remain byte-identical to its prior head. - `python3 tools/check_conventions.py --base 25c1aa1e79329e0e2957b4fdd731144dad8be724` and `git diff --check 25c1aa1e79329e0e2957b4fdd731144dad8be724` pass. - Only `docs/dev/debt/libc.md` changes, with two lines added and two removed. No code, test, build, runtime or new console-measurement claim. - Pairwise merge-tree checks against #6713 `668d51adbdb91248f49fdd28acbfd0b85adb98cd` and #9087 `7b400cbcfedb3f1235e1870f05ef59f2efea0578` find conflicts only in `docs/dev/debt/libc.md`. The retain-both landing agreements below remain applicable; neither is a functional dependency. ### Landing order The author of #6713 [agrees that either landing order works](https://github.com/boykopovar/AnyPS5/pull/9613#issuecomment-6344493626). Resolve the additive `_Mtx_trylock` debt hunk by keeping main’s four entries, this PR’s `_Mtx_trylock` entry, then #6713’s “Application heap without process parameters” entry. If this PR lands first, #6713’s author will rebase accordingly. There is no code dependency between these PRs. The author of #9087 [agrees to either landing order](https://github.com/boykopovar/AnyPS5/pull/9613#issuecomment-6345573855): #9087 can land first and this PR will be refreshed afterward. If this PR lands first, #9087’s author will rebase its `libc.md` hunk and keep these two entries unchanged. Preserve both PRs’ overlapping `strdup`/`strndup` debt edits. There is no code dependency between these PRs. ### 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
JJenkx commented 2026-10-22 09:56:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T09:56:08Z.


Thanks for the review. I have converted this to a draft under the #5239 intake hold; there is no title run demonstrating a need for this documentation-only change.

The #6713 overlap is an insertion beside the _Mtx_trylock entry; #9087 changes adjacent secure-formatting entries beside strndup/strdup. Those diffs do not change the two behaviors documented here, but their shared context can still require a rebase. I will leave overlap coordination and a fresh rebase/check outstanding before making this ready again. Bundled PPSA13934 disassembly remains the evidence scope; no console measurement is claimed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6337953255 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9613#issuecomment-6337953255). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T09:56:08Z. --- Thanks for the review. I have converted this to a draft under the #5239 intake hold; there is no title run demonstrating a need for this documentation-only change. The #6713 overlap is an insertion beside the `_Mtx_trylock` entry; #9087 changes adjacent secure-formatting entries beside `strndup`/`strdup`. Those diffs do not change the two behaviors documented here, but their shared context can still require a rebase. I will leave overlap coordination and a fresh rebase/check outstanding before making this ready again. Bundled PPSA13934 disassembly remains the evidence scope; no console measurement is claimed.
JJenkx commented 2026-10-22 12:31:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T12:31:44Z.


Rebased onto main 8b3a6ba88d (head 8fcf18acf5). The two libc.md entries apply unchanged on top of the current file, and tools/check_conventions.py passes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6340807621 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9613#issuecomment-6340807621). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T12:31:44Z. --- Rebased onto `main` 8b3a6ba88d (head 8fcf18acf5). The two `libc.md` entries apply unchanged on top of the current file, and `tools/check_conventions.py` passes.
MarcZX10 commented 2026-10-22 13:15:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T13:15:13Z.

Review: DISMISSED


I withdraw the earlier #5239 intake-hold objection. The two disassembly-backed debt updates clearly distinguish bundled libc.prx evidence from PS5 console measurements, and the qsort item has been split into #9688 as described. Exact-head whitespace and conventions pass against current main 3ca07d086d5f44fbe3c00370e7f03953ab46ca1b; the current-main merge tree is clean. Hosted conventions, eligibility and labels pass; product jobs are skipped. This documentation-only change needs no runtime test, and I did not claim a console run.

I refreshed the overlap check manually: merging #9613 with #9087 is clean, but a merge-tree comparison with #6713 produces a content conflict in docs/dev/debt/libc.md on the _Mtx_trylock entry. Please coordinate the landing order with #6713's author and rebase the second PR preserving both entries; update Depends on only if one actually must land first. The PR currently descends from 8b3a6ba88d8fc74e768f1a7e8e9e36fb69842768, while current main is 3ca07d086d5f44fbe3c00370e7f03953ab46ca1b; please update it to current main and refresh the overlap check. This request is for current branch and overlap coordination only, not the obsolete intake hold.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5614796765 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9613#pullrequestreview-5614796765). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T13:15:13Z. **Review:** DISMISSED --- I withdraw the earlier #5239 intake-hold objection. The two disassembly-backed debt updates clearly distinguish bundled `libc.prx` evidence from PS5 console measurements, and the qsort item has been split into #9688 as described. Exact-head whitespace and conventions pass against current main `3ca07d086d5f44fbe3c00370e7f03953ab46ca1b`; the current-main merge tree is clean. Hosted conventions, eligibility and labels pass; product jobs are skipped. This documentation-only change needs no runtime test, and I did not claim a console run. I refreshed the overlap check manually: merging #9613 with #9087 is clean, but a merge-tree comparison with #6713 produces a content conflict in `docs/dev/debt/libc.md` on the `_Mtx_trylock` entry. Please coordinate the landing order with #6713's author and rebase the second PR preserving both entries; update `Depends on` only if one actually must land first. The PR currently descends from `8b3a6ba88d8fc74e768f1a7e8e9e36fb69842768`, while current main is `3ca07d086d5f44fbe3c00370e7f03953ab46ca1b`; please update it to current main and refresh the overlap check. This request is for current branch and overlap coordination only, not the obsolete intake hold.
MarcZX10 commented 2026-10-22 13:15:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T13:15:34Z.


Correction to my preceding review: I ran the two pairwise merge-tree checks separately. Both #9087 and #6713 produce a content conflict in docs/dev/debt/libc.md with this head. I incorrectly said #9087 merged cleanly. #9087 touches the strndup and strdup entry, and #6713 touches _Mtx_trylock; please coordinate both landing orders and preserve all three changes when rebasing. The current-main merge tree itself is clean.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6341685452 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9613#issuecomment-6341685452). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T13:15:34Z. --- Correction to my preceding review: I ran the two pairwise merge-tree checks separately. Both #9087 and #6713 produce a content conflict in `docs/dev/debt/libc.md` with this head. I incorrectly said #9087 merged cleanly. #9087 touches the `strndup and strdup` entry, and #6713 touches `_Mtx_trylock`; please coordinate both landing orders and preserve all three changes when rebasing. The current-main merge tree itself is clean.
JJenkx commented 2026-10-22 13:17:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T13:17:03Z.


@MarcZX10 thanks for the correction. I merged all three locally on top of this head (8fcf18acf5): first #9087 (orezraey), then #6713 (karimibrahim07). Both conflicts are adjacency only, and neither PR changes the text of the two entries this PR edits:

  • #9087: the conflict hunk is strndup and strdup followed by the snprintf_s and vsnprintf_s and vsscanf_s lines. The resolution keeps this PR's strndup and strdup line and then #9087's rewritten snprintf_s and vsnprintf_s line. #9087 itself deletes the old vsscanf_s line.
  • #6713: the conflict hunk is the _Mtx_trylock entry. Main added four entries above it after #6713 was opened (sceLibcBacktraceGetBufferSize, ApplicationGuestHeapApi, fdopen, scriptingGetMem). The resolution keeps those, then this PR's _Mtx_trylock line, then #6713's new "Application heap without process parameters" line.

Every added libc.md line of the three PRs is present verbatim in the result: 4 of 4 for #9087, 1 of 1 for #6713 and 2 of 2 here. check_conventions.py reports no errors. Its one warning is debt-length on #9087's own _WStoul entry (2,279 characters), not on this combination.

On landing order, this PR has no preference. Whichever of the three merges later only needs the resolution above. If one of #9087 or #6713 lands first, I'll rebase this onto it and keep their text unchanged.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6341715588 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9613#issuecomment-6341715588). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T13:17:03Z. --- @MarcZX10 thanks for the correction. I merged all three locally on top of this head (8fcf18acf5): first #9087 (orezraey), then #6713 (karimibrahim07). Both conflicts are adjacency only, and neither PR changes the text of the two entries this PR edits: - **#9087:** the conflict hunk is `strndup and strdup` followed by the `snprintf_s and vsnprintf_s` and `vsscanf_s` lines. The resolution keeps this PR's `strndup and strdup` line and then #9087's rewritten `snprintf_s and vsnprintf_s` line. #9087 itself deletes the old `vsscanf_s` line. - **#6713:** the conflict hunk is the `_Mtx_trylock` entry. Main added four entries above it after #6713 was opened (`sceLibcBacktraceGetBufferSize`, `ApplicationGuestHeapApi`, `fdopen`, `scriptingGetMem`). The resolution keeps those, then this PR's `_Mtx_trylock` line, then #6713's new "Application heap without process parameters" line. Every added `libc.md` line of the three PRs is present verbatim in the result: 4 of 4 for #9087, 1 of 1 for #6713 and 2 of 2 here. `check_conventions.py` reports no errors. Its one warning is `debt-length` on #9087's own `_WStoul` entry (2,279 characters), not on this combination. On landing order, this PR has no preference. Whichever of the three merges later only needs the resolution above. If one of #9087 or #6713 lands first, I'll rebase this onto it and keep their text unchanged. AI-assisted (Claude Code).
JJenkx commented 2026-10-22 13:28:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T13:28:46Z.


Marked ready for review. This was a draft only because of the #5239 intake hold, which @MarcZX10 has withdrawn (https://github.com/boykopovar/AnyPS5/pull/9613#issuecomment-6337453028 and on #9596).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6341958699 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9613#issuecomment-6341958699). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T13:28:46Z. --- Marked ready for review. This was a draft only because of the #5239 intake hold, which @MarcZX10 has withdrawn (https://github.com/boykopovar/AnyPS5/pull/9613#issuecomment-6337453028 and on #9596).
JJenkx commented 2026-10-22 15:18:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T15:18:20Z.


@orezraey @karimibrahim07 could you confirm a landing order for the adjacent docs/dev/debt/libc.md changes in #9087, #6713 and this PR? The reviewer requested agreement from the affected authors; my earlier resolution note did not tag you directly.

My proposed order is to let your implementation PRs land first and refresh this documentation-only PR afterward, preserving both of your debt updates. There is no code dependency on this PR, and I can also refresh after whichever one lands first if the other remains open. If this PR lands first, the previously documented adjacency resolution retains all three sets of changes.

Current heads checked for this request: this PR 8fcf18acf5, #9087 f8019fdbaf, #6713 668d51adbd. The earlier local three-way resolution and its conventions result are described in https://github.com/boykopovar/AnyPS5/pull/9613#issuecomment-6341715588; this request does not claim a fresh test run or agreement yet. Please let me know if either ordering conflicts with your plans.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6344319457 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9613#issuecomment-6344319457). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T15:18:20Z. --- @orezraey @karimibrahim07 could you confirm a landing order for the adjacent `docs/dev/debt/libc.md` changes in #9087, #6713 and this PR? The reviewer requested agreement from the affected authors; my earlier resolution note did not tag you directly. My proposed order is to let your implementation PRs land first and refresh this documentation-only PR afterward, preserving both of your debt updates. There is no code dependency on this PR, and I can also refresh after whichever one lands first if the other remains open. If this PR lands first, the previously documented adjacency resolution retains all three sets of changes. Current heads checked for this request: this PR `8fcf18acf5`, #9087 `f8019fdbaf`, #6713 `668d51adbd`. The earlier local three-way resolution and its conventions result are described in https://github.com/boykopovar/AnyPS5/pull/9613#issuecomment-6341715588; this request does not claim a fresh test run or agreement yet. Please let me know if either ordering conflicts with your plans.
karimibrahim07 commented 2026-10-22 15:26:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by karimibrahim07 on 2026-10-22T15:26:01Z.


@JJenkx agreed, any order works for #6713. Your resolution of the _Mtx_trylock hunk (main's four new entries, then this PR's _Mtx_trylock line, then #6713's "Application heap without process parameters" line) keeps everything #6713 adds. If this PR lands first I'll rebase #6713 onto it the same way. #6713 has no code dependency on it either way.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6344493626 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9613#issuecomment-6344493626). Originally posted by [karimibrahim07](https://github.com/karimibrahim07) on 2026-10-22T15:26:01Z. --- @JJenkx agreed, any order works for #6713. Your resolution of the `_Mtx_trylock` hunk (main's four new entries, then this PR's `_Mtx_trylock` line, then #6713's "Application heap without process parameters" line) keeps everything #6713 adds. If this PR lands first I'll rebase #6713 onto it the same way. #6713 has no code dependency on it either way. AI-assisted: yes
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!9613
No description provided.