fix(libc): return the calling thread from _Thrd_id as the console's libc.prx does #9170
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9170"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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'slibc.prx, and both found the same thing:np6xXcXEnXE#D#A, ELF vaddr0x4f20(11 bytes), calls the PLT ... and returns with RAX unchanged", with the PLT slot resolving toaI+OeCz8xrQ,scePthreadSelf. "It does not callscePthreadGetthreadid."0xcab10, whose relocation namesscePthreadSelf... and returns RAX unchanged."_Thrd_idwith no arguments and compares all 64 bits of the result with the id its_Thrd_createstored, a self-join check; this works only if_Thrd_idreturns 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 unmodifiedmain7e2ba73e4creaches 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_idnow returnsThreadForwards(__func__).self(), the samescePthreadSelfthat libkernel registers and that_Thrd_currentalready 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_idnow says what_Thrd_idreturns and where that comes from (a reading of the body, not a measurement) instead of why it throws.Tested
libc.prxbuilds forward the export the same way: in Cyberpunk 2077 (PPSA04029),np6xXcXEnXEat0x4bb0jumps through the GOT entry relocated toscePthreadSelf(aI+OeCz8xrQ), PPSA02530 has the same shape at0x4e20, and the title'slibREDGalaxy64.prximportsnp6xXcXEnXE. They also rebased and verified the change onmainf26434afa3(Linux, GCC 16.2.1).Ubuntu 24.04 x86-64 container (GCC 13.3, Release) under Rosetta on an Apple M5 Mac.
guest_libc_threadsgets three checks:_Thrd_id()equalsscePthreadSelf()with libkernel's forwards, returns the fakeselfresult when the test registers its own forwards, and throws once they're unregistered.Threads.cpp,guest_libc_threadsaborts withwhat(): _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/mainpasses.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
ce50ab75aand its basee072e8840:net_dontwait_blocking_*tests fail on both.agc_driver_sgpr_pattern_fill_keysfailed on one side only; it is intermittent under parallel ctest (#8708).guest_libc_threadspasses (1/1; 1/1 on the base).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T15:42:56Z.
Windows data point for
ce50ab75amerged ontomaincecb540a6(clean,git merge-treerc 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.core/libs/prx/libc/src/Threads.cpprestored tomain(the new test cases kept): fails 3 of 3, exit code0xc0000409(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_idreturns. Not tested: other platforms, a title run.AI-assisted (Claude Code).
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_postfixexport. I confirmed its current diff defines that symbol inlibc/Export.cppreturning1, while this PR defines it inThreads.cppby forwardingscePthreadSelf(). 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 online 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 implementedafter #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 currentmain, change the checklist’sUnblocksentry accordingly.Current base and checks
This head is 601 commits behind current
main(merge basee072e8840a). Please update it and rerunguest_libc_threadson the rebased head.git diff --check: passed.The forwarding implementation is supported by strong source evidence. Please reconcile the competing export, title record, and current-base validation before merge.
Imported from boykopovar/AnyPS5. Originally posted by krishalivaibhav on 2026-10-22T12:58:56Z.
Code review:
_Thrd_idforwarding toscePthreadSelfmatches both cited readings of the console body (#4164, #8711), and returning the fullvoid*keeps RAX unchanged, as the console does. For the overlap with #9416: that PR returns a constant1for the same export, which neither reading supports, so it seems simplest for #9416 to drop its_Thrd_idand leave the export to this PR. (Code review only; I don't own PPSA22520.)Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-22T13:34:09Z.
Rebased onto current
main(8b3e39832a): headeca9862e90, same diff.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
scePthreadSelfunchanged, and_Thrd_currentuses 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.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 saysDepends 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.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_idforwards toscePthreadSelflike_Thrd_current, matching the cited readings, andguest_libc_threadsfails onmain. The merge queue refused it because of MarcZX10's change request, which is still unmet:uint64_t _Thrd_id_nid_postfix() { return 1; }incore/libs/prx/libc/Export.cpp. Two definitions of the same export don't link, so whichever PR lands second breaks the build. The constant1isn't supported by either console reading or the PPSA23827 call site.Depends onand say so here. Once #9416 no longer defines_Thrd_id, this is ready to merge.