fix(libkernel): report the creation guard size from the thread attribute queries #8041
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8041"
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 plokmklo on 2026-10-19T18:39:52Z.
What
pthread_attr_get_npandscePthreadAttrGetnever wrote the guard size into the destination attribute, so a thread created with a guard size of 0 still reported whatever the caller's attribute already held. FreeBSD 11.4_pthread_attr_get_np(thr_attr.c) copies the thread's creation attribute, guard size included, and the default is the page size (_thr_guard_default).PthreadPrivatenow stores the guard size of the attribute the thread was created with (0x1000 for default-attribute and adopted threads), and both queries report it. A newguest_pthread_guard_sizetest creates threads with guard sizes 0, 1, 100, 0x1000 and 0x10000 and requires both queries to report exactly those values — from inside the live thread and after join, against a destination attribute pre-filled with a stale value — while a default-attribute thread and the adopted main thread report 0x1000. It fails on main (the stale value survives) and passes with this change.Tested
Ubuntu 24.04 (GCC 13.3, sandbox build):
guest_pthread_guard_size,guest_pthread_attr,guest_pthread_attr_stack,guest_pthread_attr_errors,guest_pthread_stack,guest_pthread_join_detachall pass; the PthreadPrivate field default keeps adopted threads at 0x1000.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 wachi35676 on 2026-10-19T22:29:43Z.
Three things, from a Windows build of this PR merged onto
main9127ea36d(Windows 11 Home 26300, WinLibs GCC 15.2.0, Release,BUILD_TESTING=ON).Duplicate. #6893 (open since 2026-10-16) makes the same change:
guardSizeinPthreadPrivate;pthread_attr_get_npandscePthreadAttrGet;GuestPthreadGuardSize.cpp.Its head has been run on Windows and on Linux by other reviewers, with a negative control.
The new test doesn't compile with MinGW.
ProbeEntryhas noAPS5_VABI, so it can't convert toPthreadEntry(sysv_abi):The same error appears at line 82. A Windows build with
BUILD_TESTING=ONstops there.Wrong value for a caller-supplied stack. FreeBSD 11.4
create_stacksetspattr->guardsize_attr = 0whenstackaddr_attris set, andpthread_attr_get_npthen reports 0. Here the thread keeps the attribute's guard size. A probe:scePthreadAttrSetstack(&attr, stack, 0x40000)andscePthreadAttrSetguardsize(&attr, 0x2000);scePthreadAttrGetinto an attribute pre-set to 0x7000.It prints:
#6893 handles this case:
guardSize = attr->stackAddress ? 0 : attr->_guardsize.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T04:50:18Z.
Thanks. The attribute change itself looks right, but the new test doesn't compile on Windows, so CI fails before it runs (run 39370718241):
PthreadEntryis a System V function pointer, andProbeEntry(line 29) is declared with the host's default ABI. On Linux the two are the same ABI, so it compiles there; on Windows they aren't. The other pthread tests declare their entries with the macro, e.g.static void* APS5_VABI ReturnArgument(void* arg). A one-word fix:With that change, the file compiles cleanly for Windows here (llvm-mingw,
-fsyntax-only), and both errors go away.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T07:10:04Z.
Review: COMMENTED
Reviewed — no blocking findings
The guard size is copied from the creation attribute into each thread and returned by both query functions; the prepared bundle includes all six changed files, and I found no verified blocking defect.
What I ran
Reviewed head
0d8f38812afa0b39ff117cbf7a16561889f08be0using the prepared diff andrepo_read.pytargeted reads. No tests or build commands were run. The author reports running six tests on Ubuntu 24.04; I did not independently verify those results.Results
Negative control
Not run. No assertion or code mutation was applied.
Findings
Blocking
None.
Non-blocking
None.
Sources
Reviewed
core/libs/prx/libkernel/CMakeLists.txt,core/libs/prx/libkernel/Pthread/Posix/Attr.cpp,core/libs/prx/libkernel/Pthread/include/Pthread.hpp,core/libs/prx/libkernel/Pthread/src/Attr.cpp,core/libs/prx/libkernel/Pthread/src/Thread.cpp, andcore/libs/tests/GuestPthreadGuardSize.cppagainst the prepared diff at the pinned head.Not verified
Build and test results were not independently verified. The reviewed bundle listed no excluded changed files; I read the relevant changed code and test source shown in the diff and targeted repository ranges for surrounding implementation.
To get this to a good state
Nothing is required.
Pull request closed