feat(libc): forward the C11 thread and TSS calls to libkernel #8859

Merged
hypermoist merged 3 commits from upstream-pr/8859 into main 2026-10-21 12:54:23 +00:00
hypermoist commented 2026-10-21 03:31:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-21T03:31:34Z.


What

Adds the Dinkumware C11 thread and thread-specific-storage entry points that libc still lacked. The evidence is the decrypted libSceLibcInternal.sprx (PS5 12.00). Each export there is an 11-byte frame that calls one libkernel function and returns its result unchanged:

Export (NID) Address Calls
_Call_once (fttiF7rDdak) 0x1d360 scePthreadOnce
_Tss_create (amHyU7v8f-A) 0xd5440 scePthreadKeyCreate
_Tss_delete (g5cG7QtKLTA) 0xd5450 scePthreadKeyDelete
_Tss_set (ibyFt0bPyTk) 0xd5460 scePthreadSetspecific
_Tss_get (lOVQnEJEzvY) 0xd5470 scePthreadGetspecific
_Thrd_equal (BnV7WrHdPLU) 0x1cc80 scePthreadEqual
_Thrd_current (n2-b3O8qvqk) 0x1cca0 scePthreadSelf
_Thrd_exit (cFsD9R4iY50) 0x1cb70 scePthreadExit with the exit code zero-extended to a pointer

_Mtx_current_owns (VYQwFs4CC4Y, 0x1b040) returns 1 whatever its argument, so it does the same here.

The results are not translated to thrd_* codes: the console returns the libkernel value as it is, for example 0x80020016 from _Tss_create. libc can't link libkernel, so libkernel hands libc a table of these eight functions at load, in the same constructor that #8148 added for pthread_create/pthread_join/pthread_detach. Each libc entry throws if nothing is registered.

Not included:

  • _Thrd_yield: #8352 adds it.
  • _Mtx_timedlock: the console calls scePthreadMutexTimedlock on its own mutex objects, but this libc's _Mtx_* use their own mutex type.
  • _Thrd_create, _Thrd_start, _Thrd_abort and the _Cnd_*_at_thread_exit family: these have real bodies, not one-call forwards.

Tested

Linux (CachyOS, GCC, Release): full build. All 539 guest_*, kernel and Ampr tests pass.

guest_libc_threads gains two parts:

  • a real round trip through libkernel's keys (_Tss_create, _Tss_get, _Tss_set, _Tss_delete);
  • a table of fake forwards that checks every argument and the unchanged results, _Mtx_current_owns, and the throw once the table is cleared.

_Thrd_exit is not called in the test because it does not return.

tools/check_conventions.py is clean, and there is no overlap with open pull requests.

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 (libc only)
  • AI-assisted: yes (Claude Code), reviewed by the contributor

🤖 Generated with Claude Code

https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4945960183 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8859). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-21T03:31:34Z. --- ### What Adds the Dinkumware C11 thread and thread-specific-storage entry points that libc still lacked. The evidence is the decrypted `libSceLibcInternal.sprx` (PS5 12.00). Each export there is an 11-byte frame that calls one libkernel function and returns its result unchanged: | Export (NID) | Address | Calls | |---|---|---| | `_Call_once` (`fttiF7rDdak`) | 0x1d360 | `scePthreadOnce` | | `_Tss_create` (`amHyU7v8f-A`) | 0xd5440 | `scePthreadKeyCreate` | | `_Tss_delete` (`g5cG7QtKLTA`) | 0xd5450 | `scePthreadKeyDelete` | | `_Tss_set` (`ibyFt0bPyTk`) | 0xd5460 | `scePthreadSetspecific` | | `_Tss_get` (`lOVQnEJEzvY`) | 0xd5470 | `scePthreadGetspecific` | | `_Thrd_equal` (`BnV7WrHdPLU`) | 0x1cc80 | `scePthreadEqual` | | `_Thrd_current` (`n2-b3O8qvqk`) | 0x1cca0 | `scePthreadSelf` | | `_Thrd_exit` (`cFsD9R4iY50`) | 0x1cb70 | `scePthreadExit` with the exit code zero-extended to a pointer | `_Mtx_current_owns` (`VYQwFs4CC4Y`, 0x1b040) returns 1 whatever its argument, so it does the same here. The results are not translated to `thrd_*` codes: the console returns the libkernel value as it is, for example `0x80020016` from `_Tss_create`. libc can't link libkernel, so libkernel hands libc a table of these eight functions at load, in the same constructor that #8148 added for `pthread_create`/`pthread_join`/`pthread_detach`. Each libc entry throws if nothing is registered. Not included: - `_Thrd_yield`: #8352 adds it. - `_Mtx_timedlock`: the console calls `scePthreadMutexTimedlock` on its own mutex objects, but this libc's `_Mtx_*` use their own mutex type. - `_Thrd_create`, `_Thrd_start`, `_Thrd_abort` and the `_Cnd_*_at_thread_exit` family: these have real bodies, not one-call forwards. ### Tested Linux (CachyOS, GCC, Release): full build. All 539 `guest_*`, kernel and Ampr tests pass. `guest_libc_threads` gains two parts: - a real round trip through libkernel's keys (`_Tss_create`, `_Tss_get`, `_Tss_set`, `_Tss_delete`); - a table of fake forwards that checks every argument and the unchanged results, `_Mtx_current_owns`, and the throw once the table is cleared. `_Thrd_exit` is not called in the test because it does not return. `tools/check_conventions.py` is clean, and there is no overlap with open pull requests. ### 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 (libc only) - [x] AI-assisted: yes (Claude Code), reviewed by the contributor 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK
github-actions[bot] commented 2026-10-21 03:32:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T03:32:17Z.


Progress report (27fabb6 → 58c9254)

📈 System libraries: 48.95% (+0.05%, +9 implemented functions)

✅ 9 implemented
Library Name
libc _Call_once_nid_postfix
libc _Mtx_current_owns_nid_postfix
libc _Thrd_current_nid_postfix
libc _Thrd_equal_nid_postfix
libc _Thrd_exit_nid_postfix
libc _Tss_create_nid_postfix
libc _Tss_delete_nid_postfix
libc _Tss_get_nid_postfix
libc _Tss_set_nid_postfix
⚪ 1 behaviourally empty (constant return or throw)
Library Name
libc _Mtx_current_owns_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6307342544 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8859#issuecomment-6307342544). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T03:32:17Z. --- <!-- progress-report --> ### Progress report (27fabb6 → 58c9254) 📈 **System libraries**: 48.95% (+0.05%, +9 implemented functions) <details> <summary>✅ 9 implemented</summary> | Library | Name | | - | - | | libc | `_Call_once_nid_postfix` | | libc | `_Mtx_current_owns_nid_postfix` | | libc | `_Thrd_current_nid_postfix` | | libc | `_Thrd_equal_nid_postfix` | | libc | `_Thrd_exit_nid_postfix` | | libc | `_Tss_create_nid_postfix` | | libc | `_Tss_delete_nid_postfix` | | libc | `_Tss_get_nid_postfix` | | libc | `_Tss_set_nid_postfix` | </details> <details> <summary>⚪ 1 behaviourally empty (constant return or throw)</summary> | Library | Name | | - | - | | libc | `_Mtx_current_owns_nid_postfix` | </details>
github-actions[bot] commented 2026-10-21 03:42:42 +00:00 (Migrated from github.com)

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


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 8352 core/libs/tests/GuestLibcThreads.cpp L36, L301-302

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.

Pull request Shared files not compared
PR 1835 core/libs/prx/libc/src/Threads.cpp
PR 5021 core/libs/prx/libc/src/Threads.cpp
PR 6044 core/libs/tests/GuestLibcThreads.cpp
PR 7201 core/libs/prx/libc/src/Threads.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6307485068 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8859#issuecomment-6307485068). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T03:42:42Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 8352](https://www.github.com/boykopovar/AnyPS5/pull/8352) | `core/libs/tests/GuestLibcThreads.cpp` [L36](https://github.com/boykopovar/AnyPS5/blob/86b84244fbf0dc0a0e70c3368c630d0c5bb7fee2/core/libs/tests/GuestLibcThreads.cpp#L36), [L301-302](https://github.com/boykopovar/AnyPS5/blob/86b84244fbf0dc0a0e70c3368c630d0c5bb7fee2/core/libs/tests/GuestLibcThreads.cpp#L301-L302) | | | 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. | Pull request | Shared files not compared | |---|---| | [PR 1835](https://www.github.com/boykopovar/AnyPS5/pull/1835) | `core/libs/prx/libc/src/Threads.cpp` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libc/src/Threads.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestLibcThreads.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libc/src/Threads.cpp` |
oneandonlydean commented 2026-10-21 10:42:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T10:42:21Z.


@hypermoist thanks. The thread test fails on Windows in CI run 39581680886 (Linux passes):

162 - guest_libc_threads (Exit code 0xc0000409)

0xc0000409 is a fail-fast abort (an abort(), an invalid-parameter handler or a stack-buffer check). Since this PR changes Threads.cpp and Thread.cpp along with GuestLibcThreads.cpp, it's likely in the new thrd/tss forwarding on Windows. Could you run guest_libc_threads on Windows and take a look?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6313999393 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8859#issuecomment-6313999393). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T10:42:21Z. --- @hypermoist thanks. The thread test fails on Windows in CI run 39581680886 (Linux passes): ``` 162 - guest_libc_threads (Exit code 0xc0000409) ``` `0xc0000409` is a fail-fast abort (an `abort()`, an invalid-parameter handler or a stack-buffer check). Since this PR changes `Threads.cpp` and `Thread.cpp` along with `GuestLibcThreads.cpp`, it's likely in the new `thrd`/`tss` forwarding on Windows. Could you run `guest_libc_threads` on Windows and take a look?
hypermoist commented 2026-10-21 10:47:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-21T10:47:36Z.


Thanks @oneandonlydean. The abort was _Tss_create_nid_postfix: libkernel threads are not registered: on Windows a DLL is only loaded when the executable imports from it, and guest_libc_threads_tests imported nothing from libkernel, so its load-time registration never ran (Linux loads every linked library, hence the pass there). 02bf457027 makes KernelKeys compare _Thrd_current with scePthreadSelf, which imports libkernel and checks the forward at the same time.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6314089451 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8859#issuecomment-6314089451). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-21T10:47:36Z. --- Thanks @oneandonlydean. The abort was `_Tss_create_nid_postfix: libkernel threads are not registered`: on Windows a DLL is only loaded when the executable imports from it, and `guest_libc_threads_tests` imported nothing from libkernel, so its load-time registration never ran (Linux loads every linked library, hence the pass there). 02bf457027 makes `KernelKeys` compare `_Thrd_current` with `scePthreadSelf`, which imports libkernel and checks the forward at the same time.
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!8859
No description provided.