Skip to content

fix(libkernel): report the creation guard size from the thread attribute queries - #8041

Closed
plokmklo wants to merge 3 commits into
boykopovar:mainfrom
plokmklo:fix/libkernel-pthread-guard-size
Closed

plokmklo wants to merge 3 commits into
boykopovar:mainfrom
plokmklo:fix/libkernel-pthread-guard-size

Conversation

@plokmklo

Copy link
Copy Markdown
Contributor

What

pthread_attr_get_np and scePthreadAttrGet never 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).

PthreadPrivate now 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 new guest_pthread_guard_size test 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_detach all pass; the PthreadPrivate field default keeps adopted threads at 0x1000.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: libkernel: pthread_attr_get_np and scePthreadAttrGet do not report the thread's guard size; fix branch ready #6891
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

…ute queries

pthread_attr_get_np and scePthreadAttrGet never wrote the guard size into
the destination attribute, so a thread created with guard size 0 reported
whatever the caller's attribute already held. FreeBSD 11.4
_pthread_attr_get_np copies the thread's creation attribute, guard size
included, with a page-size default.

PthreadPrivate now stores the guard size of the attribute the thread was
created with (0x1000 for default-attr and adopted threads), and both
queries report it.

New guest_pthread_guard_size test: threads created with guard sizes 0, 1,
100, 0x1000 and 0x10000 report exactly those values through both queries
(from inside the thread and after join, against a destination attribute
pre-filled with a stale value); a default-attr thread and the adopted main
thread report 0x1000.

Fixes boykopovar#6891
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4563 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 6149 core/libs/prx/libkernel/CMakeLists.txt
PR 6936 core/libs/prx/libkernel/CMakeLists.txt
PR 7149 core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 8592 core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 9156 core/libs/prx/libkernel/CMakeLists.txt
PR 9293 core/libs/prx/libkernel/CMakeLists.txt
PR 9297 core/libs/prx/libkernel/CMakeLists.txt
PR 9302 core/libs/prx/libkernel/CMakeLists.txt
PR 9383 core/libs/prx/libkernel/CMakeLists.txt
PR 9389 core/libs/prx/libkernel/CMakeLists.txt
PR 9557 core/libs/prx/libkernel/CMakeLists.txt
PR 9566 core/libs/prx/libkernel/CMakeLists.txt
PR 11896 core/libs/prx/libkernel/CMakeLists.txt
PR 12130 core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 12544 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 12642 core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 12682 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 12688 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 12700 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 12965 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 15040 core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 16372 core/libs/prx/libkernel/CMakeLists.txt
PR 16790 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 17439 core/libs/prx/libkernel/CMakeLists.txt
PR 17463 core/libs/prx/libkernel/CMakeLists.txt
PR 17484 core/libs/prx/libkernel/CMakeLists.txt
PR 17513 core/libs/prx/libkernel/CMakeLists.txt
PR 18112 core/libs/prx/libkernel/CMakeLists.txt
PR 18190 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/Posix/Attr.cpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 18293 core/libs/prx/libkernel/CMakeLists.txt
PR 19181 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 21020 core/libs/prx/libkernel/CMakeLists.txt
PR 21026 core/libs/prx/libkernel/CMakeLists.txt
PR 21041 core/libs/prx/libkernel/CMakeLists.txt
PR 21051 core/libs/prx/libkernel/CMakeLists.txt
PR 21058 core/libs/prx/libkernel/CMakeLists.txt
PR 21132 core/libs/prx/libkernel/CMakeLists.txt
PR 21135 core/libs/prx/libkernel/CMakeLists.txt
PR 21464 core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 21571 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 21604 core/libs/prx/libkernel/CMakeLists.txt
PR 21619 core/libs/prx/libkernel/CMakeLists.txt
PR 21625 core/libs/prx/libkernel/CMakeLists.txt
PR 21626 core/libs/prx/libkernel/CMakeLists.txt
PR 21647 core/libs/prx/libkernel/CMakeLists.txt
PR 21655 core/libs/prx/libkernel/CMakeLists.txt
PR 21663 core/libs/prx/libkernel/CMakeLists.txt
PR 22391 core/libs/prx/libkernel/CMakeLists.txt
PR 22479 core/libs/prx/libkernel/CMakeLists.txt
PR 23953 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 24343 core/libs/prx/libkernel/CMakeLists.txt
PR 25949 core/libs/prx/libkernel/CMakeLists.txt
PR 25999 core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 26174 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 26206 core/libs/prx/libkernel/CMakeLists.txt
PR 27563 core/libs/prx/libkernel/CMakeLists.txt
PR 27642 core/libs/prx/libkernel/Pthread/Posix/Attr.cpp
PR 27717 core/libs/prx/libkernel/CMakeLists.txt
PR 27813 core/libs/prx/libkernel/CMakeLists.txt
PR 27864 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 27994 core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 28043 core/libs/prx/libkernel/CMakeLists.txt
PR 28045 core/libs/prx/libkernel/CMakeLists.txt
PR 28051 core/libs/prx/libkernel/CMakeLists.txt
PR 28210 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 28253 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 28255 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 28299 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 28323 core/libs/prx/libkernel/CMakeLists.txt
PR 28434 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 28679 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 28702 core/libs/prx/libkernel/CMakeLists.txt

@github-actions github-actions Bot added fix error Closes an issue (Fixes #N) libkernel build labels Oct 19, 2026
@wachi35676

Copy link
Copy Markdown
Contributor

Three things, from a Windows build of this PR merged onto main 9127ea3 (Windows 11 Home 26300, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON).

  1. Duplicate. fix(libkernel): report thread guard size from attribute queries #6893 (open since 2026-10-16) makes the same change:

    • guardSize in PthreadPrivate;
    • reported by pthread_attr_get_np and scePthreadAttrGet;
    • a new GuestPthreadGuardSize.cpp.
      Its head has been run on Windows and on Linux by other reviewers, with a negative control.
  2. The new test doesn't compile with MinGW. ProbeEntry has no APS5_VABI, so it can't convert to PthreadEntry (sysv_abi):

    GuestPthreadGuardSize.cpp:70:50: error: invalid conversion from 'void* (*)(void*)' to 'PthreadEntry' {aka 'void* (__attribute__((sysv_abi)) *)(void*)'} [-fpermissive]
    

    The same error appears at line 82. A Windows build with BUILD_TESTING=ON stops there.

  3. Wrong value for a caller-supplied stack. FreeBSD 11.4 create_stack sets pattr->guardsize_attr = 0 when stackaddr_attr is set, and pthread_attr_get_np then reports 0. Here the thread keeps the attribute's guard size. A probe:

    • creates a thread with scePthreadAttrSetstack(&attr, stack, 0x40000) and scePthreadAttrSetguardsize(&attr, 0x2000);
    • joins it;
    • calls scePthreadAttrGet into an attribute pre-set to 0x7000.

    It prints:

    user stack + guard 0x2000: create=0 attrget=0 reported guard=0x2000 (FreeBSD 11.4 create_stack: 0)
    

    fix(libkernel): report thread guard size from attribute queries #6893 handles this case: guardSize = attr->stackAddress ? 0 : attr->_guardsize.

AI-assisted: yes (Claude Code); results above were run on this machine.

@oneandonlydean oneandonlydean self-assigned this Oct 20, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks. The attribute change itself looks right, but the new test doesn't compile on Windows, so CI fails before it runs (run 39370718241):

GuestPthreadGuardSize.cpp:70:50: error: invalid conversion from 'void* (*)(void*)' to 'PthreadEntry' {aka 'void* (__attribute__((sysv_abi)) *)(void*)'}
GuestPthreadGuardSize.cpp:82:50: (same)

PthreadEntry is a System V function pointer, and ProbeEntry (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:

static void* APS5_VABI ProbeEntry(void* opaque) {

With that change, the file compiles cleanly for Windows here (llvm-mingw, -fsyntax-only), and both errors go away.

@wachi35676

Copy link
Copy Markdown
Contributor

Re-checked head 0d8f38812a merged onto main b90d009d9f (clean). Windows 11 with WinLibs GCC 15.2.0, and WSL Ubuntu 24.04 with GCC 13.3, both Release.

  1. It still doesn't build on Windows. GuestPthreadGuardSize.cpp:58:50 and :70:50 give invalid conversion from 'void* (*)(void*)' to 'PthreadEntry' {aka 'void* (__attribute__((sysv_abi)) *)(void*)'}. static void* APS5_VABI ProbeEntry(void* opaque) fixes it, as @oneandonlydean showed.
  2. With that fixed, the test fails on both platforms. RequireProbe calls scePthreadAttrGet(thread, &attr) (line 39) after scePthreadJoin, and on current main that returns an error for a thread that has ended. I didn't bisect when this changed. Linux gives Subprocess aborted, and Windows aborts at the same line. On Windows the ctest entry first fails with 0xc0000135, because it lacks the ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel>" that guest_pthread_attr_stack has. Querying the attributes from inside the thread, as ProbeEntry already does, avoids the ended-thread case.
  3. A caller-supplied stack still reports the attribute's guard size. With scePthreadAttrSetstack(&attr, stack, 0x40000) and scePthreadAttrSetguardsize(&attr, 0x2000), both scePthreadAttrGet and pthread_attr_get_np inside the thread report 0x2000. FreeBSD 11.4 create_stack sets guardsize_attr = 0 when stackaddr_attr is set (thr_create.c#L237-L250), so it reports 0.

AI-assisted: yes (Claude Code); results above were run on this machine.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@plokmklo The latest run confirms the existing Windows entry-ABI problem and explains the failure after that is fixed. The current test queries the thread again after scePthreadJoin, while current main rejects queries for an ended thread; it already checks both getters inside ProbeEntry. Please use a live-thread check, add APS5_VABI to ProbeEntry, and give guest_pthread_guard_size the Windows libkernel PATH entry before rerunning it on Linux and Windows.

The supplied-stack result also needs reconciling: the report gets the requested 0x2000 guard, while the cited FreeBSD 11.4 create_stack explicitly sets guardsize_attr to zero for a caller-provided stack. Please establish the intended contract and cover that case, keeping any unmeasured console behavior explicit.

@BunnyFl

BunnyFl commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Data for the supplied-stack question, from the disassembly of firmware 13.42's libkernel.sprx (sha256 4be40bf838a46e1f…). I read the code; I did not run it.

  • scePthreadCreate and pthread_create both call the same internal create function. It copies the caller's attribute object into the new thread. If the copied stack address (attribute offset 0x18, written by scePthreadAttrSetstack, pthread_attr_setstack and scePthreadAttrSetstackaddr) is non-zero, it stores 0 into the thread's copy of the guard size (offset 0x28) and sets bit 0x100 in the flags word (FreeBSD's THR_STACK_USER). This is the FreeBSD create_stack rule that wachi35676 cited.
  • scePthreadAttrGet calls pthread_attr_get_np, which copies the thread's attributes, including that guard field, into the caller's object. scePthreadAttrGetguardsize and pthread_attr_getguardsize both read offset 0x28. So for a thread created with a caller-supplied stack, both getters report a guard size of 0.
  • That store goes to the thread's copy, not to the caller's attribute object.

@maskym

maskym commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Windows result for head 0d8f38812a, merged alone into main 75f3702aed (the PR's Tested section names no Windows run; it conflicts textually with #9938, so it was tested in its own tree).

Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, BUILD_TESTING=ON, Ninja.

Three things stop guest_pthread_guard_size on this host:

  1. GuestPthreadGuardSize.cpp:17: static void* ProbeEntry(void* opaque) has no APS5_VABI, so scePthreadCreate(&thread, &attr, ProbeEntry, ...) does not compile here (invalid conversion from 'void* (*)(void*)' to 'PthreadEntry' {aka 'void* (__attribute__((sysv_abi)) *)(void*)'} at lines 58 and 70). On Linux the System V convention is the default, which is why it builds there. The sibling tests declare their entries as static void* APS5_VABI Name(void*).
  2. libkernel/CMakeLists.txt: the new add_test(NAME guest_pthread_guard_size ...) has no if(WIN32) set_tests_properties(... ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel>") of its own (the block that follows it belongs to guest_pthread_attr_stack), so under ctest the executable exits with 0xc0000135 (STATUS_DLL_NOT_FOUND) before running.
  3. With 1 and 2 patched locally, the test aborts in RequireProbe at line 37: scePthreadAttrGet(thread, &attr) returns 0x80020003 (SCE_KERNEL_ERROR_ESRCH) for the thread that was just joined at line 60, from the LockLiveGuestThread check in Attr.cpp:93-94. Querying a joined thread's attributes is what the test does by design (RequireProbe(thread, size) after scePthreadJoin); on this host the joined thread is no longer live. I did not check what the console returns for a joined thread here, so I can't say which side is right, only that the test's expectation does not hold on Windows.

Not run on a PS5.

AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@plokmklo the remaining conventions failure here is only in the PR description: the Depends on: none and Unblocks: none checklist lines are unchecked. Please tick them (or replace none with the PR numbers if there are any). No code change is needed for this check.

@JJenkx

JJenkx commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 0d8f38812a, merged onto main 49f3653632 (65f494fc21).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release.

guest_pthread_guard_size_tests does not compile on Windows:

core/libs/tests/GuestPthreadGuardSize.cpp:58:50: error: invalid conversion from 'void* (*)(void*)' to 'PthreadEntry' {aka 'void* (__attribute__((sysv_abi)) *)(void*)'}

PthreadEntry is a SysV-ABI function pointer. ProbeEntry (line 17) is declared as a plain static void* ProbeEntry(void* opaque), which on Linux is the same calling convention, but on Windows is the Microsoft x64 ABI. Declaring it static void* APS5_VABI ProbeEntry(void* opaque), like other tests' thread entries, fixes it on both hosts. The same applies at line 70.

AI-assisted: yes.

@kiwe147

kiwe147 commented Nov 20, 2026

Copy link
Copy Markdown

The new test does not compile on Windows on current main c8f72e9 (applied with git apply -C1, the CMake and source hunks land cleanly):

core/libs/tests/GuestPthreadGuardSize.cpp:58:50: error: invalid conversion from 'void* (*)(void*)' to 'PthreadEntry' {aka 'void* (__attribute__((sysv_abi)) *)(void*)'}
core/libs/tests/GuestPthreadGuardSize.cpp:70:50: error: (same, second `scePthreadCreate` call)

PthreadEntry is now a sysv_abi function pointer, and ProbeEntry is a plain function. Declaring it APS5_VABI, as GuestPthreadDestructorLifetime.cpp does for its thread entries, should fix it (I did not try). On Linux the attribute is the default, so this only shows on MinGW. Because of this, guest_pthread_guard_size is "Not Run" in my run, so the guard-size change itself is untested here.

Setup: tested head 0d8f38812a on main c8f72e9. Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. The tests below are host-side; the GPU is not involved. For the whole-batch numbers I used an RTX 3080 (driver 621.24) and the Ryzen iGPU (gfx1036, driver 32.0.21036.18).

Whole batch (this PR was one of 11 applied together on main c8f72e9: #10007, #11109, #12184, #14103, #14108, #13804, #10518, #13977, #8041, #8043 (its hunk reverted, see #8043), #12056; #9584 did not apply): the clean main baseline fails 4 of 6505 tests on the RTX 3080 (agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, pr_overlap_names) and 1 of 2097 AGC/video tests on the iGPU (agc_driver_stencil_plane_memory). With the batch the RTX 3080 run fails 8 of 6506: those 4, agc_driver_store_over_untracked (known flaky, #22670) and three new ones: guest_pthread_guard_size (does not build, #8041), guest_pthread_timed_locks (abort, caused by #14103) and guest_kernel_rwlockattr_bounds (abort, caused by #14108). On the iGPU agc_storage_write_back_host_retile also failed once and passes 5 of 5 alone (known race, #23708). I isolated the two aborts by reverting the PRs one at a time.

AI-assisted: yes (Claude Code)

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 0d8f38812afa0b39ff117cbf7a16561889f08be0 using the prepared diff and repo_read.py targeted 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

Check Result Note
Diff and changed code passed All six changed files are included and reviewed
Build and tests not run Results in the PR description are author reported
Security and performance passed No concrete concern found in inspected changes

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, and core/libs/tests/GuestPthreadGuardSize.cpp against 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.

@malekaifa

Copy link
Copy Markdown
Contributor

Current-main validation on machine main found that the original branch needs a small refresh before it is merge-ready. I rebased it locally onto main 8dd777ce0cbe738a05aef2835cdfb0511d5609a6 and kept the result local-only (no push to your branch).

The four changes needed on top of the rebased PR are:

  • Use the current thread-attribute default guard size, 0x4000, rather than the branch's old 0x1000. Current PthreadAttrPrivate::_guardsize and the existing attr tests now use 0x4000.
  • When the creation attribute has a caller-supplied stackAddress, store 0 as the thread's reported guard size. This matches the firmware 13.42 disassembly posted above: the thread gets a copy of the attribute and its copied guard field is cleared for a user stack, while the caller's attribute retains the requested guard.
  • Refresh the regression test: declare ProbeEntry as APS5_VABI, do both scePthreadAttrGet / pthread_attr_get_np checks while the thread is live rather than after join, and add a caller-supplied-stack case that requests 0x2000 but expects the thread queries to report 0 while the original attribute still reports 0x2000.
  • Add guest_pthread_guard_size to the Windows PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel> CTest property alongside guest_pthread_attr_stack.

My local-only candidate is dbad9a5da34456270c3ab885120a34229c2b2b2b (not published). On Windows 11 / MSYS2 UCRT64 GCC 16.2.0, Release, BUILD_TESTING=ON:

  • tools/check_conventions.py --base origin/main --head HEAD: pass
  • tools/debt_fold.py --check: pass
  • git diff --check origin/main...HEAD: pass
  • guest_pthread_guard_size: 10/10
  • guest_pthread_attr: 5/5
  • guest_pthread_attr_stack: 5/5
  • guest_pthread_attr_errors: 5/5
  • guest_pthread_stack: 5/5
  • guest_pthread_join_detach: 5/5
  • guest_kernel_pthread_attr_stack_bounds: 5/5

This preserves the PR's core approach (copy the creation guard into PthreadPrivate and return it from both thread-attribute queries), while bringing the test and user-stack behavior in line with current main and the firmware evidence. AI-assisted: yes.

@malekaifa

Copy link
Copy Markdown
Contributor

@plokmklo: follow-up to the earlier local-only review. The candidate has now been rebased onto canonical main 4f39d4f73d692ddfc3f8ce2e1ab397356c6705d4 and integrated the exact PR head 0d8f38812afa0b39ff117cbf7a16561889f08be0 as an ancestor without changing the validated tree. The local maintainer candidate is dea5da4814932e4f7bc9f6d152e133d6417d91a2 (tree 9e6bcb25494572467052f4b65edb0c45f1edbbc5).

Windows 11 / MSYS2 UCRT64 GCC 16.2 Release: libkernel.prx and six pthread regression executables built; 7/7 focused CTests passed five consecutive runs each, and guest_pthread_guard_size passed 10/10 extra runs. The candidate reports default/adopted guard size 0x4000, preserves explicit sizes, and reports zero for caller-supplied stacks. check_conventions.py and debt_fold.py --check pass when the two none template fields are checked.

I did not push or rewrite your contributor-owned branch. The PR description still has unchecked Depends on: none and Unblocks: none; the current integration cannot update PR metadata, so please tick both fields and rebase/cherry-pick this candidate if you want the update applied. AI-assisted: yes.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

I am closing this for now. The open review point is that the new test does not compile on Windows because ProbeEntry has no APS5_VABI while the pthread entry is sysv_abi, and the joins also run before RequireProbe. There has been no push since 25 Oct. Feel free to reopen or push a fixed branch at any time and we will look at it again.

@malekaifa

Copy link
Copy Markdown
Contributor

@plokmklo @oneandonlydean I’m keeping the guard-size recovery on this existing #8041 route rather than opening another PR.

The Dec 3 closure points are understood: the refresh must add APS5_VABI to ProbeEntry, keep the attribute checks on a live thread rather than after join, and preserve the already-established caller-supplied-stack behavior (thread reports guard size 0 while the caller attribute keeps its requested value). The Windows CTest runtime path also needs to be carried forward.

I have preserved the local recovery material and routed a fresh manual reconciliation against current upstream main (now fc26a09318d70846b78b21db55ccb5d238a1f412). The old local candidate dea5da4814932e4f7bc9f6d152e133d6417d91a2 is not being treated as recovered or current, and the saved patch no longer applies cleanly, so this needs a real rebase/reconciliation rather than a blind apply.

No duplicate PR will be created. #6893 stays closed as the duplicate, and I’m leaving #9938 alone because its latest maintainer note says the next step there is maintainer-side. I’m not asking to reopen #8041 yet; the corrected current-main candidate and validation should come back here first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build fix error Closes an issue (Fixes #N) libkernel needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libkernel: pthread_attr_get_np and scePthreadAttrGet do not report the thread's guard size; fix branch ready

9 participants