feat(libkernel_sys): identify the initial pthread #9160
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9160"
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 yabanana on 2026-10-21T14:04:49Z.
What
Implement
pthread_main_npfrom the libkernel_sys discovery exports. Linux identifies the process's initial thread usinggettid() == getpid(), including when a worker first loads libkernel. Other hosts retain the library-initialization-thread model and its explicit limitation in technical debt. Querying does not change errno; the runtime does not expose a pre-initialization -1 state.The signature and initial-thread semantics follow FreeBSD 11.4 thr_main_np.c and the public PS5 SDK pthread_np.h. Console behavior is unmeasured.
Following the maintainer's landing-order request, the attribute implementations and tests are removed. The current #9156 covers all four formerly overlapping attributes, so this PR now supplies only the initial-thread query. It adds no affinityTail field or attribute-layout changes. The earlier implementation remains in published history; its clearing/tail behavior came from FreeBSD, not a console measurement. This remaining query can land independently of #9156.
Tested
24 October update: head
12ff96135fc8ba65a24b49ac15ebf2751ef03986includes mainc8d34aa8f4d8058d57169cc1e423ba6db00faaf0.Built with GCC 13.3 / Ubuntu 24.04 targeting Linux x86-64. SHA256-verified copies of the unchanged build outputs ran in a full Linux guest kernel: Alpine 6.12.110-0-virt, QEMU system 8.2.2 TCG, cpu=max, 2 vCPUs, 1536 MiB. CPU execution is emulated; process_vm_* calls run in the guest kernel. No syscall shim or unchecked-copy fallback.
10/10 executions pass: four initial-thread query cases (ordinary and worker-first loading, each unpatched/NID-patched) plus six common kernel/filesystem regressions. The worker-first negative control against the previous libraries remains historical evidence. Attribute tests and implementations belong to #9156.
benjaminmathias's native Windows report passes the preceding head's ten Windows cases and twelve shared regressions three times each on WinLibs GCC 15.2.0 r7, Windows 11 Pro / Ryzen 7 5700X3D. It used main
c9b2660d563pluscd3e37795d, without #9156; selected-DLL checks completed and original-stub controls failed. This is evidence for that integration, not a native Windows execution of the current reduced head. The two remaining Windows main-query cases retain the same behavior/assertions and the current fixture cross-links locally with MinGW 13.2.Whitespace and current-main conventions checks pass. Published ancestry and contributor authorship are retained; this head merges cleanly with the pinned main. Full upstream Linux/Windows CI requires a fresh maintainer dispatch. No console or title-unblock claim.
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 DavidSamir on 2026-10-21T15:09:33Z.
A comparison from a branch I wrote for the same export, which I closed in favour of this PR (#9197). The design is the same. The one difference is how the initial thread is identified on Linux: this PR records the thread that ran the module's initializer (
initialThreadId), while I usedgettid() == getpid(), which is the definition of a process's main thread and does not depend on which thread loads libkernel. The two agree whenever the main thread loads libkernel, which is the case at start-up.On Windows I checked that the relinked executable's entry stub loads the libraries and then enters the ELF entry itself on the process's primary thread, since it imports no thread-creation function, so the initializer-thread approach is right there. I did not test the Linux case.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T11:59:29Z.
Review: CHANGES_REQUESTED
The Linux behavior has substantial evidence, including the worker-first-load regression, but the Windows target still lacks a supported-toolchain result. The earlier Windows run failed to link
guest_kernel_sys_threads_tests.exewith undefined__gxx_personality_v0; the current target still links only${CMAKE_DL_LIBS}. The reported cross-link used MinGW 13.2 and explicitly is not the repository’s supported WinLibs 15.2 runtime check. The automatic Windows job is path-skipped, so the ten Windows query cases and selected patched/unpatched DLL assertion have not run on the supported toolchain. Please provide that build/run (or correct the target link and then run it) before approval. The latest Linux 22/22 result is useful and does not resolve this Windows-specific gap.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T18:42:49Z.
Review: APPROVED
Reviewed the implementation, the new test fixture, technical-debt note, and current merge/check status. The affinity setter and getter preserve FreeBSD 11.4’s reset, size, zero-tail, and unsupported-bit behavior; the extra mask storage is appended so existing private-field offsets stay intact, and both SCE attribute paths clear the added tail when replacing the mask. The Linux main-thread check uses kernel TID/PID identity, which addresses late loading from a worker, while the non-Linux initialization-thread limitation is explicit. The focused fixture covers patched and unpatched exports, error precedence, mask boundaries, thread identity, and late loading. The PR reports 22/22 Linux guest-VM executions and Windows cross-link validation; current hosted product jobs are skipped. I found no blocking issue in the reviewed diff.