feat(libkernel_sys): implement pthread_getstack_np #15111
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15111"
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 arcwiser on 2026-11-02T16:40:04Z.
What
Implement
pthread_getstack_npin libkernel_sys with the firmware 13.42 two-output ABI. Report the calling guest thread's tracked stack base and size, preserve the firmware write order, and document the unmeasured incidental return value plusEFAULThost-safety fallback. Add coverage for the initial thread, a child calling the export on its custom-sized stack, and invalid output pointers.Tested
Windows, MSYS2 UCRT64 GCC 16.2.0:
cmake --build build --target guest_kernel_sys_pthread_np_tests --parallel 6ctest --test-dir build -R '^guest_kernel_sys_pthread_np_(rwlockattr|kind|stack)$|^public_headers$' --output-on-failurepython tools/check_conventions.py --base origin/mainpython tools/pr_overlap.py --branch codex/sys-library-functions; manually compared every reported shared-file PR, none implementspthread_getstack_npChecklist
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 BunnyFl on 2026-11-02T17:01:45Z.
Review: CHANGES_REQUESTED
The firmware gives this export a different signature, so the new argument order doesn't match what titles call.
Firmware 13.42's
libkernel.sprx(sha2564be40bf838a46e1ff83a1809960672526139b09dda6c4a6592cfeb485d29f243),pthread_getstack_np(ruZ9hhQ8oUk,0xdb70), read from disassembly to the return, not measured on a console. This is the whole function:rdiis the address output andrsithe size output. The PR's(Pthread thread, void** stackAddress, std::size_t* stackSize)reads the caller's address pointer as a thread handle. A title callingpthread_getstack_np(&addr, &size)would getESRCH, or worse.EINVALandESRCHresults have no counterpart in the module. A null output faults on the console. A checked write for null outputs is fine as a host-safety fallback if the debt entry says so; the two error codes shouldn't be pinned as console behaviour.raxholds the stack size atret. What callers rely on isn't settled, so if the declaration keepsint, the entry should say the result is unmeasured.Could it become
(void** stackAddress, std::size_t* stackSize)for the current thread, with the tests reworked to match? I didn't build this branch; the points above come from the module.Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T17:46:24Z.
Review: APPROVED
Thanks.
e5322eaed8matches firmware 13.42'spthread_getstack_np(0xdb70inlibkernel.sprx):(void** stackAddress, std::size_t* stackSize)for the calling thread, with no thread argument.EFAULTresult for a null or unwritable output is listed inlibkernel_sys.mdas a host-safety fallback where the module faults, with the address written before the size, in the module's order.thread->stackAddress/stackSizeare the low address and size of the stack, both for host-started threads (SetStackFromHost) and for guest threads created with a stack size, so both kinds of thread report their real stack.Tested on Windows 11, WinLibs GCC 15.2.0, with this head merged onto
main: the threeguest_kernel_sys_pthread_np_*modes andpublic_headerspass 4/4, andcheck_conventions.pypasses. Withmain'sThreadQueries.cpp,Export.Discovery.cppandApi.hpp, the new tests don't compile against the old parameterless stub.