fix(libc): return the calling thread from _Thrd_id as the console's libc.prx does #9170

Merged
rooklz merged 1 commit from upstream-pr/9170 into main 2026-10-25 16:34:32 +00:00
rooklz commented 2026-10-21 14:09:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-21T14:09:56Z.


What

_Thrd_id (np6xXcXEnXE) threw on main because its return value wasn't known. Two people have since read its body in the console's libc.prx, and both found the same thing:

  • p3n1cillin on #4164 (comment): "Export np6xXcXEnXE#D#A, ELF vaddr 0x4f20 (11 bytes), calls the PLT ... and returns with RAX unchanged", with the PLT slot resolving to aI+OeCz8xrQ, scePthreadSelf. "It does not call scePthreadGetthreadid."
  • ivica00 on #8711 (closed): it "calls PLT 0xcab10, whose relocation names scePthreadSelf ... and returns RAX unchanged."
  • xXPBSXx on this PR (comment): PPSA23827's thread wrapper destructor calls _Thrd_id with no arguments and compares all 64 bits of the result with the id its _Thrd_create stored, a self-join check; this works only if _Thrd_id returns the same pointer-wide value the creation stored.

Earlier Animal Well (PPSA22520, #966) reports stopped at _Thrd_id_nid_postfix not implemented; a retest on 2026-10-22 on unmodified main 7e2ba73e4c reaches gameplay without this change, so this PR no longer claims to unblock that title. It stays a fix for any title that calls the export, as PPSA23827 does.

MarcZX10 asked on #4164 for a focused follow-up once the libc export location was settled, which #8148 did. So _Thrd_id now returns ThreadForwards(__func__).self(), the same scePthreadSelf that libkernel registers and that _Thrd_current already returns. It hands back the full pointer-width value, as the console body does (RAX unchanged), so a caller that only reads EAX gets the low half either way. With no thread forwards registered it throws, like _Thrd_current.

The libc debt entry for std::_Pad, _Thrd_join, _Thrd_detach, _Thrd_id now says what _Thrd_id returns and where that comes from (a reading of the body, not a measurement) instead of why it throws.

Tested

  • @edubox found that title libc.prx builds forward the export the same way: in Cyberpunk 2077 (PPSA04029), np6xXcXEnXE at 0x4bb0 jumps through the GOT entry relocated to scePthreadSelf (aI+OeCz8xrQ), PPSA02530 has the same shape at 0x4e20, and the title's libREDGalaxy64.prx imports np6xXcXEnXE. They also rebased and verified the change on main f26434afa3 (Linux, GCC 16.2.1).

Ubuntu 24.04 x86-64 container (GCC 13.3, Release) under Rosetta on an Apple M5 Mac.

  • guest_libc_threads gets three checks: _Thrd_id() equals scePthreadSelf() with libkernel's forwards, returns the fake self result when the test registers its own forwards, and throws once they're unregistered.
  • With main's Threads.cpp, guest_libc_threads aborts with what(): _Thrd_id_nid_postfix not implemented. With this change it passes.
  • tools/progress.py --module libc: 1217/1225 before, 1218/1225 after.
  • check_conventions.py --base origin/main passes.

I don't have Animal Well, so I haven't run it. #8636 reports that on main "the title runs until _Thrd_id_nid_postfix not implemented", which is the throw this removes; what it hits next is unknown to me.

Hosted runs on my fork (GitHub runners), this branch ce50ab75a and its base e072e8840:

  • Ubuntu 24.04 x86-64, GCC 13.3, full build with the CI configure flags, tests on lavapipe: 1805/1809 with the change, 1806/1809 on the base. The three net_dontwait_blocking_* tests fail on both. agc_driver_sgpr_pattern_fill_keys failed on one side only; it is intermittent under parallel ctest (#8708).
  • Windows Server 2025, WinLibs GCC 15.2.0, full build: it builds, and guest_libc_threads passes (1/1; 1/1 on the base).

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:4952980657 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9170). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-21T14:09:56Z. --- ### What `_Thrd_id` (`np6xXcXEnXE`) threw on main because its return value wasn't known. Two people have since read its body in the console's `libc.prx`, and both found the same thing: - p3n1cillin on #4164 ([comment](https://github.com/boykopovar/AnyPS5/pull/4164#issuecomment-6128161219)): "Export `np6xXcXEnXE#D#A`, ELF vaddr `0x4f20` (11 bytes), calls the PLT ... and returns with RAX unchanged", with the PLT slot resolving to `aI+OeCz8xrQ`, `scePthreadSelf`. "It does not call `scePthreadGetthreadid`." - ivica00 on #8711 (closed): it "calls PLT `0xcab10`, whose relocation names `scePthreadSelf` ... and returns RAX unchanged." - xXPBSXx on this PR ([comment](https://github.com/boykopovar/AnyPS5/pull/9170#issuecomment-6356279018)): PPSA23827's thread wrapper destructor calls `_Thrd_id` with no arguments and compares all 64 bits of the result with the id its `_Thrd_create` stored, a self-join check; this works only if `_Thrd_id` returns the same pointer-wide value the creation stored. Earlier Animal Well (PPSA22520, #966) reports stopped at `_Thrd_id_nid_postfix not implemented`; a retest on 2026-10-22 on unmodified `main` `7e2ba73e4c` reaches gameplay without this change, so this PR no longer claims to unblock that title. It stays a fix for any title that calls the export, as PPSA23827 does. MarcZX10 asked on #4164 for a focused follow-up once the libc export location was settled, which #8148 did. So `_Thrd_id` now returns `ThreadForwards(__func__).self()`, the same `scePthreadSelf` that libkernel registers and that `_Thrd_current` already returns. It hands back the full pointer-width value, as the console body does (RAX unchanged), so a caller that only reads EAX gets the low half either way. With no thread forwards registered it throws, like `_Thrd_current`. The libc debt entry for `std::_Pad, _Thrd_join, _Thrd_detach, _Thrd_id` now says what `_Thrd_id` returns and where that comes from (a reading of the body, not a measurement) instead of why it throws. ### Tested - @edubox found that title `libc.prx` builds forward the export the same way: in Cyberpunk 2077 (PPSA04029), `np6xXcXEnXE` at `0x4bb0` jumps through the GOT entry relocated to `scePthreadSelf` (`aI+OeCz8xrQ`), PPSA02530 has the same shape at `0x4e20`, and the title's `libREDGalaxy64.prx` imports `np6xXcXEnXE`. They also rebased and verified the change on `main` `f26434afa3` (Linux, GCC 16.2.1). <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Ubuntu 24.04 x86-64 container (GCC 13.3, Release) under Rosetta on an Apple M5 Mac. - `guest_libc_threads` gets three checks: `_Thrd_id()` equals `scePthreadSelf()` with libkernel's forwards, returns the fake `self` result when the test registers its own forwards, and throws once they're unregistered. - With main's `Threads.cpp`, `guest_libc_threads` aborts with `what(): _Thrd_id_nid_postfix not implemented`. With this change it passes. - `tools/progress.py --module libc`: 1217/1225 before, 1218/1225 after. - `check_conventions.py --base origin/main` passes. I don't have Animal Well, so I haven't run it. #8636 reports that on main "the title runs until `_Thrd_id_nid_postfix not implemented`", which is the throw this removes; what it hits next is unknown to me. Hosted runs on my fork (GitHub runners), this branch `ce50ab75a` and its base `e072e8840`: - Ubuntu 24.04 x86-64, GCC 13.3, full build with the CI configure flags, tests on lavapipe: 1805/1809 with the change, 1806/1809 on the base. The three `net_dontwait_blocking_*` tests fail on both. `agc_driver_sgpr_pattern_fill_keys` failed on one side only; it is intermittent under parallel ctest (#8708). - Windows Server 2025, WinLibs GCC 15.2.0, full build: it builds, and `guest_libc_threads` passes (1/1; 1/1 on the base). ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
xXPBSXx commented 2026-10-21 15:42:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T15:42:56Z.


Windows data point for ce50ab75a merged onto main cecb540a6 (clean, git merge-tree rc 0): Windows 10.0.19045, MinGW-w64 GCC 15.2.0, Release. ctest -N -R '^guest_libc_threads$' lists exactly that one test; ctest --no-tests=error -R '^guest_libc_threads$' was run three times per tree.

  • With the PR: passes 3 of 3 (0.1-0.8 s).
  • Same tree with core/libs/prx/libc/src/Threads.cpp restored to main (the new test cases kept): fails 3 of 3, exit code 0xc0000409 (the test process aborts).
    This only shows that the new test separates the two trees on Windows; it does not measure what the console's _Thrd_id returns. Not tested: other platforms, a title run.
    AI-assisted (Claude Code).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6320050300 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9170#issuecomment-6320050300). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T15:42:56Z. --- Windows data point for `ce50ab75a` merged onto `main` `cecb540a6` (clean, `git merge-tree` rc 0): Windows 10.0.19045, MinGW-w64 GCC 15.2.0, Release. `ctest -N -R '^guest_libc_threads$'` lists exactly that one test; `ctest --no-tests=error -R '^guest_libc_threads$'` was run three times per tree. - With the PR: passes 3 of 3 (0.1-0.8 s). - Same tree with `core/libs/prx/libc/src/Threads.cpp` restored to `main` (the new test cases kept): fails 3 of 3, exit code `0xc0000409` (the test process aborts). This only shows that the new test separates the two trees on Windows; it does not measure what the console's `_Thrd_id` returns. Not tested: other platforms, a title run. AI-assisted (Claude Code).
MarcZX10 commented 2026-10-22 08:31:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T08:31:55Z.

Review: CHANGES_REQUESTED


Review

The one-line forwarding implementation matches the two cited console readings, and the added test checks it with the registered and test-provided thread forwards. I did not find a defect in that forwarding path. Two coordination items and a test-context update are needed before approval.

Same export in #9416

The current overlap report identifies #9416 as defining the same _Thrd_id_nid_postfix export. I confirmed its current diff defines that symbol in libc/Export.cpp returning 1, while this PR defines it in Threads.cpp by forwarding scePthreadSelf(). These are competing implementations of the same export and cannot both be integrated as written.

Please coordinate with the #9416 author and maintainers on the single implementation and landing order, then update the overlap notes and Depends on line if the PRs are intentionally stacked. I’m recording the conflict, not presuming which PR should land.

Title bring-up record

The linked Animal Well discussion currently says there is no blocker and does not list this PR. A newer report in #8636 says the title reaches _Thrd_id_nid_postfix not implemented after #8636’s fix. Please update the discussion with that current test context, add this PR to its open-PR list, and state whether the stop is still reproducible. If it is no longer a blocker on current main, change the checklist’s Unblocks entry accordingly.

Current base and checks

This head is 601 commits behind current main (merge base e072e8840a). Please update it and rerun guest_libc_threads on the rebased head.

  • git diff --check: passed.
  • Current conventions, eligibility, intake, labels, and report jobs passed.
  • Register-context jobs passed on Ubuntu and macOS (Debug/Release); relinker jobs passed on macOS, Ubuntu, and Windows; relinker ASan and both write-watch jobs passed.
  • Linux and Windows product-test jobs were skipped. The local and fork test results in the PR description are author-reported on the older base; the full Linux run included one intermittent AGC test failure on the PR side, which the report identifies.

The forwarding implementation is supported by strong source evidence. Please reconcile the competing export, title record, and current-base validation before merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5611366560 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9170#pullrequestreview-5611366560). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T08:31:55Z. **Review:** CHANGES_REQUESTED --- ## Review The one-line forwarding implementation matches the two cited console readings, and the added test checks it with the registered and test-provided thread forwards. I did not find a defect in that forwarding path. Two coordination items and a test-context update are needed before approval. ### Same export in #9416 The current overlap report identifies #9416 as defining the same `_Thrd_id_nid_postfix` export. I confirmed its current diff defines that symbol in `libc/Export.cpp` returning `1`, while this PR defines it in `Threads.cpp` by forwarding `scePthreadSelf()`. These are competing implementations of the same export and cannot both be integrated as written. Please coordinate with the #9416 author and maintainers on the single implementation and landing order, then update the overlap notes and `Depends on` line if the PRs are intentionally stacked. I’m recording the conflict, not presuming which PR should land. ### Title bring-up record The linked [Animal Well discussion](https://github.com/boykopovar/AnyPS5/discussions/966) currently says there is no blocker and does not list this PR. A newer report in #8636 says the title reaches `_Thrd_id_nid_postfix not implemented` after #8636’s fix. Please update the discussion with that current test context, add this PR to its open-PR list, and state whether the stop is still reproducible. If it is no longer a blocker on current `main`, change the checklist’s `Unblocks` entry accordingly. ### Current base and checks This head is 601 commits behind current `main` (merge base `e072e8840a`). Please update it and rerun `guest_libc_threads` on the rebased head. - `git diff --check`: passed. - Current conventions, eligibility, intake, labels, and report jobs passed. - Register-context jobs passed on Ubuntu and macOS (Debug/Release); relinker jobs passed on macOS, Ubuntu, and Windows; relinker ASan and both write-watch jobs passed. - Linux and Windows product-test jobs were skipped. The local and fork test results in the PR description are author-reported on the older base; the full Linux run included one intermittent AGC test failure on the PR side, which the report identifies. The forwarding implementation is supported by strong source evidence. Please reconcile the competing export, title record, and current-base validation before merge.
krishalivaibhav commented 2026-10-22 12:58:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by krishalivaibhav on 2026-10-22T12:58:56Z.


Code review: _Thrd_id forwarding to scePthreadSelf matches both cited readings of the console body (#4164, #8711), and returning the full void* keeps RAX unchanged, as the console does. For the overlap with #9416: that PR returns a constant 1 for the same export, which neither reading supports, so it seems simplest for #9416 to drop its _Thrd_id and leave the export to this PR. (Code review only; I don't own PPSA22520.)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6341344260 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9170#issuecomment-6341344260). Originally posted by [krishalivaibhav](https://github.com/krishalivaibhav) on 2026-10-22T12:58:56Z. --- Code review: `_Thrd_id` forwarding to `scePthreadSelf` matches both cited readings of the console body (#4164, #8711), and returning the full `void*` keeps RAX unchanged, as the console does. For the overlap with #9416: that PR returns a constant `1` for the same export, which neither reading supports, so it seems simplest for #9416 to drop its `_Thrd_id` and leave the export to this PR. (Code review only; I don't own PPSA22520.)
rooklz commented 2026-10-22 13:34:09 +00:00 (Migrated from github.com)

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


Rebased onto current main (8b3e39832a): head eca9862e90, same diff.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6342071370 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9170#issuecomment-6342071370). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-22T13:34:09Z. --- Rebased onto current `main` (`8b3e39832a`): head `eca9862e90`, same diff.
MarcZX10 commented 2026-10-23 22:10:39 +00:00 (Migrated from github.com)

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

Review: APPROVED


Reviewed the implementation against the evidence summarized in the PR: the console export returns the result of scePthreadSelf unchanged, and _Thrd_current uses the same registered forward. The added test covers the registered kernel forward, a test double, and the missing-forward failure path. The author reports the focused Linux and Windows tests passing, with CI conventions, eligibility, labels, relinker matrix, register-context and write-watch jobs green. I found no blocking issue.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5634976601 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9170#pullrequestreview-5634976601). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T22:10:39Z. **Review:** APPROVED --- Reviewed the implementation against the evidence summarized in the PR: the console export returns the result of `scePthreadSelf` unchanged, and `_Thrd_current` uses the same registered forward. The added test covers the registered kernel forward, a test double, and the missing-forward failure path. The author reports the focused Linux and Windows tests passing, with CI conventions, eligibility, labels, relinker matrix, register-context and write-watch jobs green. I found no blocking issue.
MarcZX10 commented 2026-10-23 23:34:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T23:34:56Z.

Review: DISMISSED


The forwarding implementation and its focused test remain supported by the cited console evidence. I need to correct my earlier approval because the live overlap report still lists open #9416 as defining _Thrd_id_nid_postfix, and this PR still says Depends on: none. The #9416 author has not agreed to drop or sequence its competing export, so the repository’s overlap rule is not satisfied. Please coordinate the single implementation/landing order with that author and update the dependency line (or wait for #9416 to close/remove the duplicate). I’ll re-review once that is resolved.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5635525877 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9170#pullrequestreview-5635525877). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T23:34:56Z. **Review:** DISMISSED --- The forwarding implementation and its focused test remain supported by the cited console evidence. I need to correct my earlier approval because the live overlap report still lists open #9416 as defining `_Thrd_id_nid_postfix`, and this PR still says `Depends on: none`. The #9416 author has not agreed to drop or sequence its competing export, so the repository’s overlap rule is not satisfied. Please coordinate the single implementation/landing order with that author and update the dependency line (or wait for #9416 to close/remove the duplicate). I’ll re-review once that is resolved.
adriadam10 commented 2026-10-24 13:01:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-24T13:01:52Z.

Review: CHANGES_REQUESTED


The implementation and its test are fine: _Thrd_id forwards to scePthreadSelf like _Thrd_current, matching the cited readings, and guest_libc_threads fails on main. The merge queue refused it because of MarcZX10's change request, which is still unmet:

  • #9416 is open and still defines uint64_t _Thrd_id_nid_postfix() { return 1; } in core/libs/prx/libc/Export.cpp. Two definitions of the same export don't link, so whichever PR lands second breaks the build. The constant 1 isn't supported by either console reading or the PPSA23827 call site.
  • To unblock: #9416 drops that line (already asked there), or this PR lands after #9416 replaces it. If you want the second option, record it under Depends on and say so here. Once #9416 no longer defines _Thrd_id, this is ready to merge.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638336413 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9170#pullrequestreview-5638336413). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-24T13:01:52Z. **Review:** CHANGES_REQUESTED --- The implementation and its test are fine: `_Thrd_id` forwards to `scePthreadSelf` like `_Thrd_current`, matching the cited readings, and `guest_libc_threads` fails on `main`. The merge queue refused it because of MarcZX10's change request, which is still unmet: - #9416 is open and still defines `uint64_t _Thrd_id_nid_postfix() { return 1; }` in `core/libs/prx/libc/Export.cpp`. Two definitions of the same export don't link, so whichever PR lands second breaks the build. The constant `1` isn't supported by either console reading or the PPSA23827 call site. - To unblock: #9416 drops that line (already asked there), or this PR lands after #9416 replaces it. If you want the second option, record it under `Depends on` and say so here. Once #9416 no longer defines `_Thrd_id`, this is ready to merge.
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!9170
No description provided.