libc: the Dinkumware _Mtx_* and _Cnd_* exports are stubs; fix branch ready #3068

Closed
opened 2026-10-10 21:33:08 +00:00 by screamm · 1 comment
screamm commented 2026-10-10 21:33:08 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-10T21:33:08Z.


The Dinkumware C-thread exports _Mtx_init, _Mtx_destroy, _Mtx_lock, _Mtx_unlock, _Cnd_init, _Cnd_destroy, _Cnd_wait and _Cnd_broadcast in libc (Export.cpp) are NotImplemented_nid_no_patch stubs, so a title whose C++ runtime reaches std::mutex or std::condition_variable through libc.prx stops at its first lock.

Fix branch ready: screamm:feat/libc-dinkumware-threads (56b03751, one commit on main 262c0316). I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commit as is.

  • New core/libs/prx/libc/src/Threads.cpp implements the eight exports after microsoft/STL xthreads.h, mutex.cpp and cond.cpp (commit da52dc0f): init stores null and then a heap handle and returns _Thrd_nomem on allocation failure; the other calls take the handle by value and return _Thrd_success; an owner relocking a plain or recursive mutex counts the lock, relocking any other non-recursive type returns _Thrd_busy. libc cannot call libkernel, so each handle wraps a host std::mutex with owner and count, or a host std::condition_variable.
  • Cases the source leaves to asserts throw: null handles, unsupported type bits, destroying a locked mutex, unlocking or waiting on a mutex the caller does not own, waiting with a recursive count above one, and a handle not made by init.
  • TechnicalDebt records what is unverified on a console, chiefly whether the console's build takes the handle by value like microsoft/STL or by pointer.
  • New guest_libc_threads covers init/lock/unlock/destroy, the busy and counting relock rules, a recursive mutex excluding another thread, 4 threads × 20000 locked increments, two waiters woken by one broadcast, and every throwing case.

Tested on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, full build including libs: guest_libc_threads 5/5 and 3/3 after the last change; ctest -j8 -E "^agc_|video_out" 388/389, the one failure being guest_avplayer, which passes 3/3 alone and is unrelated (it also fails under -j8 load on unchanged main here). tools/check_conventions.py --base main and git diff --check pass. Not run on Linux.

Written with Claude Code assistance (implementation by a subagent, reviewed and validated in this session).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5795466411 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3068). Originally posted by [screamm](https://github.com/screamm) on 2026-10-10T21:33:08Z. --- The Dinkumware C-thread exports `_Mtx_init`, `_Mtx_destroy`, `_Mtx_lock`, `_Mtx_unlock`, `_Cnd_init`, `_Cnd_destroy`, `_Cnd_wait` and `_Cnd_broadcast` in libc ([Export.cpp](https://github.com/boykopovar/AnyPS5/blob/main/core/libs/prx/libc/Export.cpp)) are `NotImplemented_nid_no_patch` stubs, so a title whose C++ runtime reaches `std::mutex` or `std::condition_variable` through libc.prx stops at its first lock. **Fix branch ready:** [`screamm:feat/libc-dinkumware-threads`](https://github.com/screamm/AnyPS5/tree/feat/libc-dinkumware-threads) (`56b03751`, one commit on `main` `262c0316`). I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commit as is. - New `core/libs/prx/libc/src/Threads.cpp` implements the eight exports after microsoft/STL `xthreads.h`, `mutex.cpp` and `cond.cpp` (commit `da52dc0f`): init stores null and then a heap handle and returns `_Thrd_nomem` on allocation failure; the other calls take the handle by value and return `_Thrd_success`; an owner relocking a plain or recursive mutex counts the lock, relocking any other non-recursive type returns `_Thrd_busy`. libc cannot call libkernel, so each handle wraps a host `std::mutex` with owner and count, or a host `std::condition_variable`. - Cases the source leaves to asserts throw: null handles, unsupported type bits, destroying a locked mutex, unlocking or waiting on a mutex the caller does not own, waiting with a recursive count above one, and a handle not made by init. - TechnicalDebt records what is unverified on a console, chiefly whether the console's build takes the handle by value like microsoft/STL or by pointer. - New `guest_libc_threads` covers init/lock/unlock/destroy, the busy and counting relock rules, a recursive mutex excluding another thread, 4 threads × 20000 locked increments, two waiters woken by one broadcast, and every throwing case. **Tested** on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`, full build including `libs`: `guest_libc_threads` 5/5 and 3/3 after the last change; `ctest -j8 -E "^agc_|video_out"` 388/389, the one failure being `guest_avplayer`, which passes 3/3 alone and is unrelated (it also fails under `-j8` load on unchanged `main` here). `tools/check_conventions.py --base main` and `git diff --check` pass. Not run on Linux. Written with Claude Code assistance (implementation by a subagent, reviewed and validated in this session).
adriadam10 commented 2026-10-10 22:52:53 +00:00 (Migrated from github.com)
Author
Contributor

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


Fixed by #3079: the eight Dinkumware Mtx/Cnd exports are implemented in libc, covered by guest_libc_threads.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103046552 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3068#issuecomment-6103046552). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T22:52:53Z. --- Fixed by #3079: the eight Dinkumware _Mtx_*/_Cnd_* exports are implemented in libc, covered by `guest_libc_threads`.
Sign in to join this conversation.
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#3068
No description provided.