feat(libc): implement Dinkumware mutex and condition exports #3079

Merged
MarcZX10 merged 6 commits from upstream-pr/3079 into main 2026-10-10 22:52:50 +00:00
MarcZX10 commented 2026-10-10 21:50:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T21:50:59Z.


What

Carry the Dinkumware mutex and condition-variable implementation offered from screamm's branch in issue #3068. The source branch's single commit (56b03751) records its author as David <[email protected]> and Claude as co-author; this PR preserves that commit metadata. The issue links the branch to screamm, but the commit metadata does not identify David with that account, so attribution has not been rewritten.

The eight exports use the console's pointer-to-handle ABI. The title libc.prx disassembly reported in this review shows _Mtx_lock mapping success to _Thrd_success (0), 0x8002000b to _Thrd_busy (3), and other failures to _Thrd_error (4). Its internal mutex initialization checks recursive flag 0x100; other types use default attributes. _Mtx_unlock and _Cnd_wait return success regardless of their internal result. The host implementation models these results, while guarding invalid handles and destroying a locked mutex with exceptions. The default mutex attribute and those guard cases remain unverified on console hardware and are recorded in TechnicalDebt.md.

Tested

  • Local Linux Release build of libc and guest_libc_threads_tests on the rebased head; guest_libc_threads passed 20 consecutive runs.
  • tools/check_conventions.py --base upstream/main and git diff --check pass.
  • The source contributor reported a Windows 11 Pro 26220 / WinLibs GCC 15.2.0 Release full build and guest_libc_threads 3/3 on the source commit, before the carried follow-up changes in this PR.
  • The PR workflow skips full Linux and Windows builds under repository policy; current-head automated checks are running after this push.

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 in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4814683279 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3079). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T21:50:59Z. --- ### What Carry the Dinkumware mutex and condition-variable implementation offered from screamm's branch in issue #3068. The source branch's single commit (`56b03751`) records its author as `David <[email protected]>` and Claude as co-author; this PR preserves that commit metadata. The issue links the branch to screamm, but the commit metadata does not identify David with that account, so attribution has not been rewritten. The eight exports use the console's pointer-to-handle ABI. The title `libc.prx` disassembly reported in this review shows `_Mtx_lock` mapping success to `_Thrd_success` (0), `0x8002000b` to `_Thrd_busy` (3), and other failures to `_Thrd_error` (4). Its internal mutex initialization checks recursive flag `0x100`; other types use default attributes. `_Mtx_unlock` and `_Cnd_wait` return success regardless of their internal result. The host implementation models these results, while guarding invalid handles and destroying a locked mutex with exceptions. The default mutex attribute and those guard cases remain unverified on console hardware and are recorded in `TechnicalDebt.md`. ### Tested - Local Linux Release build of `libc` and `guest_libc_threads_tests` on the rebased head; `guest_libc_threads` passed 20 consecutive runs. - `tools/check_conventions.py --base upstream/main` and `git diff --check` pass. - The source contributor reported a Windows 11 Pro 26220 / WinLibs GCC 15.2.0 Release full build and `guest_libc_threads` 3/3 on the source commit, before the carried follow-up changes in this PR. - The PR workflow skips full Linux and Windows builds under repository policy; current-head automated checks are running after this push. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-10 21:51:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T21:51:27Z.


Progress report (3330144 → b603d19)

📈 System libraries: 85.15% (+0.24%, +8 implemented functions)

✅ 8 implemented
Library Name
libc _Cnd_broadcast_nid_postfix
libc _Cnd_destroy_nid_postfix
libc _Cnd_init_nid_postfix
libc _Cnd_wait_nid_postfix
libc _Mtx_destroy_nid_postfix
libc _Mtx_init_nid_postfix
libc _Mtx_lock_nid_postfix
libc _Mtx_unlock_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102554500 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3079#issuecomment-6102554500). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T21:51:27Z. --- <!-- progress-report --> ### Progress report (3330144 → b603d19) 📈 **System libraries**: 85.15% (+0.24%, +8 implemented functions) <details> <summary>✅ 8 implemented</summary> | Library | Name | | - | - | | libc | `_Cnd_broadcast_nid_postfix` | | libc | `_Cnd_destroy_nid_postfix` | | libc | `_Cnd_init_nid_postfix` | | libc | `_Cnd_wait_nid_postfix` | | libc | `_Mtx_destroy_nid_postfix` | | libc | `_Mtx_init_nid_postfix` | | libc | `_Mtx_lock_nid_postfix` | | libc | `_Mtx_unlock_nid_postfix` | </details>
adriadam10 commented 2026-10-10 21:53:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T21:53:26Z.

Review: CHANGES_REQUESTED


Thanks for carrying this. The build and guest_libc_threads pass here on Linux (20/20 repeats), but the ABI doesn't match the console, so I can't merge it yet:

  • core/libs/prx/libc/src/Threads.cpp:39-55,65-155: the handle is taken by value (microsoft/STL contract), but the console's exports take a pointer to the handle. The aerolib names for the PS5 exports are _Mtx_init(pthread_mutex**, int), _Mtx_lock(pthread_mutex**) and _Cnd_wait(pthread_cond**, pthread_mutex**), and the disassembly of _Mtx_lock in a title's libc.prx (vaddr 0x5a30, 33 bytes) forwards rdi untouched to an internal lock call and maps its result (0 → 0, 0x8002000b → _Thrd_busy, anything else → _Thrd_error (4)). A real title passes the address of the slot that _Mtx_init filled, so ResolveMutex reads the wrong word and throws. Please take void** for lock, unlock, destroy and _Cnd_wait/_Cnd_broadcast/_Cnd_destroy (dereference once) and check the result mapping against that disassembly (_Mtx_unlock, _Cnd_wait, _Mtx_destroy too).
  • core/libs/tests/GuestLibcThreads.cpp: the tests only pin the by-value signature, so they pass with the wrong ABI. Update them to pass &handle, and keep a case where the dereferenced slot is not a handle created by _Mtx_init.
  • Threads.cpp:57-59: IsOwnedByCaller reads the plain int count before checking owner, which is a data race when another thread unlocks. Check owner first.
  • docs/dev/TechnicalDebt.md:490: the "unverified whether it takes the handle by value" part will need rewriting once the above is done; the line is also the last of its section, where every PR appends and conflicts. Please put it a few lines up.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5480936619 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3079#pullrequestreview-5480936619). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T21:53:26Z. **Review:** CHANGES_REQUESTED --- Thanks for carrying this. The build and `guest_libc_threads` pass here on Linux (20/20 repeats), but the ABI doesn't match the console, so I can't merge it yet: - `core/libs/prx/libc/src/Threads.cpp:39-55,65-155`: the handle is taken by value (microsoft/STL contract), but the console's exports take a pointer to the handle. The aerolib names for the PS5 exports are `_Mtx_init(pthread_mutex**, int)`, `_Mtx_lock(pthread_mutex**)` and `_Cnd_wait(pthread_cond**, pthread_mutex**)`, and the disassembly of `_Mtx_lock` in a title's `libc.prx` (vaddr `0x5a30`, 33 bytes) forwards `rdi` untouched to an internal lock call and maps its result (`0` → `0`, `0x8002000b` → `_Thrd_busy`, anything else → `_Thrd_error` (4)). A real title passes the address of the slot that `_Mtx_init` filled, so `ResolveMutex` reads the wrong word and throws. Please take `void**` for lock, unlock, destroy and `_Cnd_wait`/`_Cnd_broadcast`/`_Cnd_destroy` (dereference once) and check the result mapping against that disassembly (`_Mtx_unlock`, `_Cnd_wait`, `_Mtx_destroy` too). - `core/libs/tests/GuestLibcThreads.cpp`: the tests only pin the by-value signature, so they pass with the wrong ABI. Update them to pass `&handle`, and keep a case where the dereferenced slot is not a handle created by `_Mtx_init`. - `Threads.cpp:57-59`: `IsOwnedByCaller` reads the plain `int count` before checking `owner`, which is a data race when another thread unlocks. Check `owner` first. - `docs/dev/TechnicalDebt.md:490`: the "unverified whether it takes the handle by value" part will need rewriting once the above is done; the line is also the last of its section, where every PR appends and conflicts. Please put it a few lines up.
MarcZX10 commented 2026-10-10 22:03:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T22:03:40Z.


Addressed in commits e5920758, 6d3e9384 and cdc86c35.

  • Changed the handle-consuming exports to take void** and dereference the handle slot once. The test declarations and calls now use &handle, including empty/invalid slots.
  • Check the atomic owner before reading the non-atomic lock count. _Mtx_lock maps deadlock to _Thrd_busy (3) and other host system_errors to _Thrd_error (4); invalid unlocks and waits return _Thrd_error. _Mtx_destroy has no status result and still throws when asked to destroy a locked mutex.
  • Moved and updated the TechnicalDebt entry to record the console ABI evidence, known result mapping, and remaining unverified behavior.

Validation on the current head: Release libc and guest_libc_threads_tests build; guest_libc_threads passes 20 consecutive runs; local and CI conventions pass. The automatic register-context, write-watch and Linux/macOS/Windows relinker jobs also passed on the preceding update. Full Linux and Windows builds were skipped by the repository's PR workflow policy.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102656194 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3079#issuecomment-6102656194). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T22:03:40Z. --- Addressed in commits `e5920758`, `6d3e9384` and `cdc86c35`. - Changed the handle-consuming exports to take `void**` and dereference the handle slot once. The test declarations and calls now use `&handle`, including empty/invalid slots. - Check the atomic owner before reading the non-atomic lock count. `_Mtx_lock` maps deadlock to `_Thrd_busy` (3) and other host `system_error`s to `_Thrd_error` (4); invalid unlocks and waits return `_Thrd_error`. `_Mtx_destroy` has no status result and still throws when asked to destroy a locked mutex. - Moved and updated the TechnicalDebt entry to record the console ABI evidence, known result mapping, and remaining unverified behavior. Validation on the current head: Release `libc` and `guest_libc_threads_tests` build; `guest_libc_threads` passes 20 consecutive runs; local and CI conventions pass. The automatic register-context, write-watch and Linux/macOS/Windows relinker jobs also passed on the preceding update. Full Linux and Windows builds were skipped by the repository's PR workflow policy.
MarcZX10 commented 2026-10-10 22:06:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T22:06:04Z.


Follow-up to the overlap notice for #3047: I moved this PR's TechnicalDebt.md entry beside the existing libc thread-runtime note, away from the line where #3047 adds its pthread_kill entry. The two implementations do not depend on each other; this docs-only commit avoids the insertion conflict.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102676183 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3079#issuecomment-6102676183). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T22:06:04Z. --- Follow-up to the overlap notice for #3047: I moved this PR's `TechnicalDebt.md` entry beside the existing libc thread-runtime note, away from the line where #3047 adds its `pthread_kill` entry. The two implementations do not depend on each other; this docs-only commit avoids the insertion conflict.
MarcZX10 commented 2026-10-10 22:09:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T22:09:50Z.


The rebase onto current main is complete. I preserved the upstream changes and kept the TechnicalDebt entry beside std_execute_once, which also avoids the insertion overlap with #3047. On the rebased head, Release libc and guest_libc_threads_tests build, guest_libc_threads passed 20 consecutive runs, and conventions plus git diff --check pass. CI has passed eligibility and conventions; the platform test matrix is still running. The ABI, data race, and result-mapping changes requested in the review are included in the rebased commits. Please re-review when the checks finish.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102707460 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3079#issuecomment-6102707460). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T22:09:50Z. --- The rebase onto current `main` is complete. I preserved the upstream changes and kept the TechnicalDebt entry beside `std_execute_once`, which also avoids the insertion overlap with #3047. On the rebased head, Release `libc` and `guest_libc_threads_tests` build, `guest_libc_threads` passed 20 consecutive runs, and conventions plus `git diff --check` pass. CI has passed eligibility and conventions; the platform test matrix is still running. The ABI, data race, and result-mapping changes requested in the review are included in the rebased commits. Please re-review when the checks finish.
adriadam10 commented 2026-10-10 22:14:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:14:44Z.

Review: CHANGES_REQUESTED


Thanks for the changes: the void** handles, the owner-before-count check and the moved TechnicalDebt line look right, and the build and guest_libc_threads pass here on Linux. The disassembly of a title's libc.prx still disagrees with what the tests pin:

  • Threads.cpp:118-127, :150-172: _Mtx_unlock (vaddr 0x5a20) and _Cnd_wait (0x4ea0) just call the internal unlock/wait on their arguments and return 0, whatever the internal call returned. Returning _Thrd_error for an unowned unlock or an invalid wait is not what the console does. Please return 0 there, or throw for the cases whose real outcome depends on pthread internals; GuestLibcThreads.cpp:52,54,146,149 need to follow.
  • Threads.cpp:74,100-102: the internal init at 0x5900 only tests bit 0x100 (recursive: settype(2)); every other type uses the default attributes, and no type is rejected. The default mutex relocked by its owner fails with 0x8002000b, which _Mtx_lock maps to _Thrd_busy (3). So a plain (0x01) mutex should return busy on relock like the others (GuestLibcThreads.cpp:63-64 pins success), and the type validation throws where the console accepts.
  • docs/dev/TechnicalDebt.md:162: the unlock/wait/relock mappings are now known from the disassembly; rewrite the line to say what is still unverified (e.g. that the default attribute is error-checking, inferred from the 0x8002000b mapping).
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5480996051 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3079#pullrequestreview-5480996051). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T22:14:44Z. **Review:** CHANGES_REQUESTED --- Thanks for the changes: the `void**` handles, the owner-before-count check and the moved TechnicalDebt line look right, and the build and `guest_libc_threads` pass here on Linux. The disassembly of a title's `libc.prx` still disagrees with what the tests pin: - `Threads.cpp:118-127`, `:150-172`: `_Mtx_unlock` (vaddr `0x5a20`) and `_Cnd_wait` (`0x4ea0`) just call the internal unlock/wait on their arguments and return 0, whatever the internal call returned. Returning `_Thrd_error` for an unowned unlock or an invalid wait is not what the console does. Please return 0 there, or throw for the cases whose real outcome depends on pthread internals; `GuestLibcThreads.cpp:52,54,146,149` need to follow. - `Threads.cpp:74,100-102`: the internal init at `0x5900` only tests bit `0x100` (recursive: `settype(2)`); every other type uses the default attributes, and no type is rejected. The default mutex relocked by its owner fails with `0x8002000b`, which `_Mtx_lock` maps to `_Thrd_busy` (3). So a plain (`0x01`) mutex should return busy on relock like the others (`GuestLibcThreads.cpp:63-64` pins success), and the type validation throws where the console accepts. - `docs/dev/TechnicalDebt.md:162`: the unlock/wait/relock mappings are now known from the disassembly; rewrite the line to say what is still unverified (e.g. that the default attribute is error-checking, inferred from the `0x8002000b` mapping).
adriadam10 commented 2026-10-10 22:21:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:21:21Z.

Review: CHANGES_REQUESTED


The new head only rebases onto main; Threads.cpp and GuestLibcThreads.cpp are unchanged, so the points from the previous review still apply:

  • Threads.cpp:118-127, :150-172: _Mtx_unlock and _Cnd_wait return 0 on the console whatever the internal call returned. Return 0 there (or throw where the real outcome depends on pthread internals); GuestLibcThreads.cpp:52,54,146,149 need to follow.
  • Threads.cpp:74,100-102: the internal init only tests bit 0x100, every other type gets the default attributes and none is rejected. Relocking a plain (0x01) mutex returns busy (3) like the others (GuestLibcThreads.cpp:63-64 pins success), and the type validation should not throw.
  • docs/dev/TechnicalDebt.md:162: rewrite it to say only what is still unverified (e.g. that the default attribute is error-checking, inferred from the 0x8002000b mapping).
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5481012832 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3079#pullrequestreview-5481012832). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T22:21:21Z. **Review:** CHANGES_REQUESTED --- The new head only rebases onto `main`; `Threads.cpp` and `GuestLibcThreads.cpp` are unchanged, so the points from the previous review still apply: - `Threads.cpp:118-127`, `:150-172`: `_Mtx_unlock` and `_Cnd_wait` return 0 on the console whatever the internal call returned. Return 0 there (or throw where the real outcome depends on pthread internals); `GuestLibcThreads.cpp:52,54,146,149` need to follow. - `Threads.cpp:74,100-102`: the internal init only tests bit `0x100`, every other type gets the default attributes and none is rejected. Relocking a plain (`0x01`) mutex returns busy (3) like the others (`GuestLibcThreads.cpp:63-64` pins success), and the type validation should not throw. - `docs/dev/TechnicalDebt.md:162`: rewrite it to say only what is still unverified (e.g. that the default attribute is error-checking, inferred from the `0x8002000b` mapping).
MarcZX10 commented 2026-10-10 22:22:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T22:22:58Z.


Follow-up: I rebased again onto current main after #3078 merged. The full diff remains unchanged, and the current-head CI matrix has now passed eligibility, conventions, report, register-context, write-watch and all three relinker jobs. Full Linux and Windows builds remain skipped under the PR workflow policy. The local Release build and 20 consecutive guest_libc_threads runs also passed. Please re-review this current head when convenient.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102812373 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3079#issuecomment-6102812373). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T22:22:58Z. --- Follow-up: I rebased again onto current `main` after #3078 merged. The full diff remains unchanged, and the current-head CI matrix has now passed eligibility, conventions, report, register-context, write-watch and all three relinker jobs. Full Linux and Windows builds remain skipped under the PR workflow policy. The local Release build and 20 consecutive `guest_libc_threads` runs also passed. Please re-review this current head when convenient.
fma-rc commented 2026-10-10 22:30:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-10T22:30:33Z.


One more thing on aa00494a, built on Linux (GCC 16.2.1): _Mtx_destroy frees the object but leaves the slot pointing at it. In a small probe against the exports, after _Mtx_init(&m, 2) and _Mtx_destroy(&m) the slot still holds the old handle, and a following _Mtx_lock(&m) returns 0 instead of throwing, so it is working on freed memory. _Cnd_destroy looks the same from the code but I only ran the mutex case.

Clearing the slot (or storing a destroyed marker) in both destroy functions would make a use after destroy fail loudly.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102872922 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3079#issuecomment-6102872922). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-10T22:30:33Z. --- One more thing on aa00494a, built on Linux (GCC 16.2.1): `_Mtx_destroy` frees the object but leaves the slot pointing at it. In a small probe against the exports, after `_Mtx_init(&m, 2)` and `_Mtx_destroy(&m)` the slot still holds the old handle, and a following `_Mtx_lock(&m)` returns 0 instead of throwing, so it is working on freed memory. `_Cnd_destroy` looks the same from the code but I only ran the mutex case. Clearing the slot (or storing a destroyed marker) in both destroy functions would make a use after destroy fail loudly.
Dextroid17 commented 2026-10-10 22:35:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-10T22:35:05Z.

Review: COMMENTED


The stubs-to-implementation move is clean, and what stands out first is that the normal paths follow the contract exactly: _Mtx_lock returns busy on a second plain lock, _Mtx_unlock returns error when called from the wrong thread, and the test pins both of those alongside destroy-while-locked and an invalid handle. Those are the cases a Dinkumware implementation is judged on, and defining the _Thrd_* result set instead of returning bare numbers keeps them readable.

The invalid-handle paths are the one place I would ask about the contract. They throw — invalid_argument for a null or foreign handle, logic_error for destroying a locked mutex — and the reference you cite does not throw at all: in microsoft/STL's xthreads.h these _Mtx_* and _Cnd_* entries are declared noexcept and report through _Thrd_result, while their public C++ face, std::mutex::lock, is documented to throw std::system_error and nothing else. invalid_argument and logic_error appear in neither set, so a guest catching what the contract allows would not catch them and would not even be able to reason about them from the cited headers. If the throws are a deliberate debug aid, saying so is enough; if the console's behaviour is what is being modelled, the _Thrd_* codes are already sitting in the file.

And the question this tree always asks of a libc implementation: which title reaches these exports, and which log line changes from NotImplemented to real behaviour? The description does not claim one, which is honest — but that line turning over is exactly the evidence that would make this landable, and if no title has reached them yet, saying so is just as useful to whoever tests next.

Two things worth keeping exactly as they are. The cited microsoft/STL contract is the right reference for these functions, and recording the console ABI uncertainty in TechnicalDebt.md rather than asserting it is the correct call — the entry names the headers it checked and says plainly that the console build is unverified.

One thing that does not match the description, if it matters to anyone reading later. The body says the original commit author is preserved, but the commits on this PR are authored by a local [email protected] identity and by you; none is authored by screamm. The code may well be theirs — issue #3068 points at their branch — but the authorship record is not, and in a project that has been careful about exactly this, the discrepancy is worth a look rather than silence. The other carried change in this batch does keep its author, so this reads like an accident rather than a policy.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5481052863 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3079#pullrequestreview-5481052863). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-10T22:35:05Z. **Review:** COMMENTED --- The stubs-to-implementation move is clean, and what stands out first is that the *normal* paths follow the contract exactly: `_Mtx_lock` returns busy on a second plain lock, `_Mtx_unlock` returns error when called from the wrong thread, and the test pins both of those alongside destroy-while-locked and an invalid handle. Those are the cases a Dinkumware implementation is judged on, and defining the `_Thrd_*` result set instead of returning bare numbers keeps them readable. **The invalid-handle paths are the one place I would ask about the contract.** They throw — `invalid_argument` for a null or foreign handle, `logic_error` for destroying a locked mutex — and the reference you cite does not throw at all: in microsoft/STL's `xthreads.h` these `_Mtx_*` and `_Cnd_*` entries are declared `noexcept` and report through `_Thrd_result`, while their public C++ face, `std::mutex::lock`, is documented to throw `std::system_error` and nothing else. `invalid_argument` and `logic_error` appear in neither set, so a guest catching what the contract allows would not catch them and would not even be able to reason about them from the cited headers. If the throws are a deliberate debug aid, saying so is enough; if the console's behaviour is what is being modelled, the `_Thrd_*` codes are already sitting in the file. **And the question this tree always asks of a libc implementation:** which title reaches these exports, and which log line changes from `NotImplemented` to real behaviour? The description does not claim one, which is honest — but that line turning over is exactly the evidence that would make this landable, and if no title has reached them yet, saying so is just as useful to whoever tests next. **Two things worth keeping exactly as they are.** The cited microsoft/STL contract is the right reference for these functions, and recording the console ABI uncertainty in `TechnicalDebt.md` rather than asserting it is the correct call — the entry names the headers it checked and says plainly that the console build is unverified. **One thing that does not match the description, if it matters to anyone reading later.** The body says the original commit author is preserved, but the commits on this PR are authored by a local `[email protected]` identity and by you; none is authored by screamm. The code may well be theirs — issue #3068 points at their branch — but the authorship record is not, and in a project that has been careful about exactly this, the discrepancy is worth a look rather than silence. The other carried change in this batch does keep its author, so this reads like an accident rather than a policy. Written with AI assistance.
MarcZX10 commented 2026-10-10 22:36:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T22:36:39Z.


The latest probe found that _Mtx_destroy and _Cnd_destroy freed their objects but left the guest handle slots pointing at the freed memory. Both destroy functions now clear the caller's slot after deletion. The tests assert that the slots become null and that subsequent lock/broadcast calls reject them safely.

Validation on this head: Release libc and guest_libc_threads_tests build; guest_libc_threads passed 20 consecutive runs; conventions and git diff --check passed. Please re-review the updated head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102921850 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3079#issuecomment-6102921850). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T22:36:39Z. --- The latest probe found that `_Mtx_destroy` and `_Cnd_destroy` freed their objects but left the guest handle slots pointing at the freed memory. Both destroy functions now clear the caller's slot after deletion. The tests assert that the slots become null and that subsequent lock/broadcast calls reject them safely. Validation on this head: Release `libc` and `guest_libc_threads_tests` build; `guest_libc_threads` passed 20 consecutive runs; conventions and `git diff --check` passed. Please re-review the updated head.
adriadam10 commented 2026-10-10 22:39:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:39:14Z.

Review: CHANGES_REQUESTED


Thanks for the destroy fix (slots cleared, tests assert it); the build and guest_libc_threads pass here on Linux. The new head doesn't touch the points from the last two reviews, which still apply:

  • core/libs/prx/libc/src/Threads.cpp:119-127, :152-173: _Mtx_unlock (vaddr 0x5a20) and _Cnd_wait (0x4ea0) in a title's libc.prx call the internal unlock/wait and return 0 whatever it returned. Return 0 there (or throw where the real outcome depends on pthread internals); core/libs/tests/GuestLibcThreads.cpp:52,54,148,151 need to follow.
  • Threads.cpp:74-75,100-103: the internal init at 0x5900 only tests bit 0x100 (recursive); every other type gets the default attributes and none is rejected. The default mutex relocked by its owner fails with 0x8002000b, which _Mtx_lock maps to busy (3), so a plain (0x01) mutex must return busy on relock (GuestLibcThreads.cpp:64-66 pins success), and the type validation shouldn't throw.
  • docs/dev/TechnicalDebt.md:162: once the above is done, rewrite it to list only what is still unverified (e.g. that the default attribute is error-checking, inferred from the 0x8002000b mapping).
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5481063156 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3079#pullrequestreview-5481063156). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T22:39:14Z. **Review:** CHANGES_REQUESTED --- Thanks for the destroy fix (slots cleared, tests assert it); the build and `guest_libc_threads` pass here on Linux. The new head doesn't touch the points from the last two reviews, which still apply: - `core/libs/prx/libc/src/Threads.cpp:119-127`, `:152-173`: `_Mtx_unlock` (vaddr `0x5a20`) and `_Cnd_wait` (`0x4ea0`) in a title's `libc.prx` call the internal unlock/wait and return 0 whatever it returned. Return 0 there (or throw where the real outcome depends on pthread internals); `core/libs/tests/GuestLibcThreads.cpp:52,54,148,151` need to follow. - `Threads.cpp:74-75,100-103`: the internal init at `0x5900` only tests bit `0x100` (recursive); every other type gets the default attributes and none is rejected. The default mutex relocked by its owner fails with `0x8002000b`, which `_Mtx_lock` maps to busy (3), so a plain (`0x01`) mutex must return busy on relock (`GuestLibcThreads.cpp:64-66` pins success), and the type validation shouldn't throw. - `docs/dev/TechnicalDebt.md:162`: once the above is done, rewrite it to list only what is still unverified (e.g. that the default attribute is error-checking, inferred from the `0x8002000b` mapping).
MarcZX10 commented 2026-10-10 22:48:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T22:48:12Z.


Thanks for the detailed follow-up. I updated the implementation and tests on the rebased head:

  • _Mtx_init no longer rejects type values. The host model treats only 0x100 as recursive, uses the default behavior for other values, and returns _Thrd_busy when the owner relocks a non-recursive mutex.
  • _Mtx_unlock and _Cnd_wait now return success for the unowned or recursive-count cases that the console wrapper reports as success. The host model leaves those invalid operations without changing lock state. A host condition_variable error still propagates as an exception after restoring the mutex bookkeeping.
  • The TechnicalDebt entry now records only the remaining console uncertainty: whether the default attributes are error-checking, inferred from the observed plain-mutex relock result, and the behavior of the host-side invalid-handle/destroy-while-locked guards.

The throws for null or foreign handles and destroying a locked mutex are deliberate host-side diagnostic guards. I have not found console evidence for those invalid inputs, so I am not presenting those exceptions as Dinkumware or console behavior. No title-level run or log line for these exports is available yet.

I also checked the source attribution: issue #3068 links the source branch to screamm, while the source commit itself records David <[email protected]> and Claude as co-author. I preserved that metadata and corrected the PR description to state the discrepancy instead of changing authorship without evidence.

Validation on this head: Linux Release libc and guest_libc_threads_tests build; guest_libc_threads passes 20 consecutive runs; conventions and git diff --check pass. Please re-review this rebased head. The current PR workflow skips the full Linux and Windows builds under repository policy.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103011318 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3079#issuecomment-6103011318). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T22:48:12Z. --- Thanks for the detailed follow-up. I updated the implementation and tests on the rebased head: - `_Mtx_init` no longer rejects type values. The host model treats only `0x100` as recursive, uses the default behavior for other values, and returns `_Thrd_busy` when the owner relocks a non-recursive mutex. - `_Mtx_unlock` and `_Cnd_wait` now return success for the unowned or recursive-count cases that the console wrapper reports as success. The host model leaves those invalid operations without changing lock state. A host `condition_variable` error still propagates as an exception after restoring the mutex bookkeeping. - The TechnicalDebt entry now records only the remaining console uncertainty: whether the default attributes are error-checking, inferred from the observed plain-mutex relock result, and the behavior of the host-side invalid-handle/destroy-while-locked guards. The throws for null or foreign handles and destroying a locked mutex are deliberate host-side diagnostic guards. I have not found console evidence for those invalid inputs, so I am not presenting those exceptions as Dinkumware or console behavior. No title-level run or log line for these exports is available yet. I also checked the source attribution: issue #3068 links the source branch to screamm, while the source commit itself records `David <[email protected]>` and Claude as co-author. I preserved that metadata and corrected the PR description to state the discrepancy instead of changing authorship without evidence. Validation on this head: Linux Release `libc` and `guest_libc_threads_tests` build; `guest_libc_threads` passes 20 consecutive runs; conventions and `git diff --check` pass. Please re-review this rebased head. The current PR workflow skips the full Linux and Windows builds under repository policy.
adriadam10 commented 2026-10-10 22:52:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:52:46Z.

Review: APPROVED


Checked the build and guest_libc_threads on Linux (partial ctest 63/63), and that all points from the previous reviews are in this head (void** handles, owner-before-count, _Mtx_unlock/_Cnd_wait returning success, 0x100-only recursive type, plain relock returning busy, destroy clearing the slot, TechnicalDebt rewritten). Merging once CI finishes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5481095690 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3079#pullrequestreview-5481095690). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T22:52:46Z. **Review:** APPROVED --- Checked the build and `guest_libc_threads` on Linux (partial ctest 63/63), and that all points from the previous reviews are in this head (`void**` handles, owner-before-count, `_Mtx_unlock`/`_Cnd_wait` returning success, `0x100`-only recursive type, plain relock returning busy, destroy clearing the slot, TechnicalDebt rewritten). Merging once CI finishes.
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!3079
No description provided.