fix(libkernel): start the pthread object with the thread id #2184
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2184"
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 EdouardSence on 2026-10-09T11:05:07Z.
What
Ratchet & Clank: Rift Apart (PPSA01474) reads its thread id straight from the pthread object. It calls
pthread_self()and loads the first 32 bits it points to. That matches FreeBSD's libthr, which PS5 libkernel derives from:struct pthreadstarts withlong tid.The title then uses that id to find a per-thread allocator in its own table:
On Linux,
PthreadPrivatecurrently starts withstd::thread _thr:pthread_t;_thris empty, so the title reads 0. It matches an empty table slot, gets a null allocator and crashes with SIGSEGV about 19 s in.Changes:
PthreadPrivatenow starts withlong tid, taken from a process-wide counter that starts at 100000, the first FreeBSD thread id. Every thread object gets one, including adopted threads.scePthreadGetthreadidreturns the calling thread'stid, as FreeBSD'spthread_getthreadid_npreturnsTID(curthread). Before, it returned a hash ofstd::thread::idon Linux andGetCurrentThreadId()on Windows, so the two ids could disagree.Tested
Linux (CachyOS, GCC), RX 9070 XT.
guest_thread_selfnow checks three things:longof the main thread's and a created thread's pthread objects is non-zero, and differs between the two threads;scePthreadGetthreadid();ctest: 511/512. The failing test isimport_audit, which can't read the commit hash in my worktree and is unrelated.tools/check_conventions.pypasses.main43972e69+ #1673, #1339, #1836, #1837, #1893, #2105, plus a local placeholder formunlock:cmpq $0x0,(%rbx)withrbx = 0, inside the title'shashmap32<T>construction. The allocator came from that thread-id lookup.PA_SC_CONSERVATIVE_RASTERIZATION_CNTL=0xe6000check.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by rmz-24 on 2026-10-09T12:26:03Z.
Windows run: Windows 11 Pro 25H2 (10.0.26200.9457), RTX 5060 Ti (NVIDIA 617.42), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release,
-DANYPS5_ENABLE_SPIRV_TOOLS=ON, full build pluslibs. 3a4bc11d cherry-picked onto currentmaind70b8998(applies cleanly).guest_thread_selfpasses.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:15:13Z.
long tidis 32 bits on Windows, so there the first 8 bytes of the pthread object are the id plus 4 bytes of padding, while FreeBSD'slong tidis 64 bits. Please make itstd::int64_t(Pthread.hpp:81, and the counter on line 78), and readstd::int64_tinThreadIdFieldin the test.Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-10T08:00:13Z.
Done in
94409c9f:nextThreadIdandPthread::tidarestd::int64_tnow, andThreadIdField(and the two values compared in the test) readstd::int64_t. The first 8 bytes of the pthread object are the id on every host, as on FreeBSD.Rebased onto current
main(a29bae31). Linux, GCC, Release: full ctest passes 641 of 642,guest_thread_selfincluded. The one failure isimport_audit(source_commitisNonebecause my build tree is a git worktree), unrelated.tools/check_conventions.pypasses.Written by Claude (AI assistant) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T08:27:41Z.
Checked on Linux (GCC, Release):
guest_thread_self,guest_sched_priorityandguest_pthread_renamepass on the PR merged ontomain;guest_thread_selffails without the change. Thestd::int64_ttid Dean asked for is in94409c9f, so the first 8 bytes of the pthread object are the id on every host. Windows run by @rmz-24 was on the previous commit. Merging.