fix(libkernel): refresh adopted thread bounds when entering the main stack #15436

Merged
JJenkx merged 1 commit from upstream-pr/15436 into main 2026-11-03 19:13:16 +00:00
JJenkx commented 2026-11-03 09:38:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-11-03T09:38:48Z.


What

When a module calls scePthreadSelf before the Linux guest entry runs, the adopted thread records the original host-stack bounds. EnterGuestMainStack_nid_no_patch subsequently moves execution to the guest stack but leaves that record unchanged. Stack queries and collectors can then combine a guest-stack pointer with the old host-stack end.

Refresh the existing thread's stack address and size under the live-thread registry lock before entering the mapped main stack. Preserve the thread identity and the existing stack address, guard and argument-passing behavior. The default late-adoption path remains covered.

The regression explicitly adopts the thread before entry, then checks sceKernelIsStack, thread identity, both SCE/POSIX attribute queries, the stack guard and a worker stack. A separate CTest case retains the original late-adoption path. This follows the merged #7532 and the startup evidence reported there.

Tested

Linux 7.2.11, Ryzen 9 7950X, GCC 16.2.1, Release. Base 4f41f4c375f5abb487dbd184fbc150f31994d762, change 4199ddb20550a83466b64df7caa938c5f1fc82fe.

  • With the new tests and unchanged base production code, guest_main_stack passes and guest_main_stack_adopted fails. Zero skips.
  • Restoring the fix and rebuilding passes all eight selected CPU cases: guest_kernel_is_stack, guest_main_stack, guest_main_stack_adopted, guest_pthread_attr, guest_pthread_attr_stack, guest_pthread_attr_errors, guest_pthread_start, guest_pthread_stack. Zero skips/failures.
  • A fresh native Outer Wilds (PPSA08102) relink against base exits 139 at 2.1 seconds, before a window. Two GDB probes reproduce a read 280 bytes above the mapped guest stack; the scanner's range calculation reaches the original host-stack page. A host-stack-only diagnostic avoids that early crash but shows a black two-present window. Copying the initial argument block onto the guest stack alone still crashes. These diagnostics narrow the issue; they are not successful game bring-up or performance results.
  • Official pr_overlap.py --base main --branch fix/linux-main-stack-adopted-attributes-20261103 scanned 1,668 open PRs. It could not automatically compare 35 conflicting older branches; their reported shared-file diffs were inspected manually. They change other platform/thread/I/O paths or add unrelated tests; none supplies this main-stack refresh or the new regression. Merge-tree against the fetched current main is clean.
  • Native candidate, exact committed source, no preload: the same generated Outer Wilds executable/modules now run to the scheduled close at 291 seconds, native/harness exit 0. The reviewed 260-second screenshot shows the rendered title screen with readable logo/start prompt and its small planet/trees. The 170-second capture was black while shaders were still being prepared. Compositor and independent X11 readbacks agree.
  • That cold run used the same archived save seed and fresh private project/Mesa shader caches. Scripted Cross inputs ended before cold loading completed, so menu interaction/gameplay, audio and an FPS gain are not established. SDK/generated/input hashes remain intact; the kernel setting is restored and no private native process remains.
  • Additional warm-cache run on the same head: menu advancement and Square reach the opening outdoor scene. Directly reviewed 200/300-second captures show the tower, trees, planet and Move/Look Around prompts, with day/night progression. Normal scheduled close at 400.7 seconds, native/harness exit 0; SDK/generated hashes intact and kernel setting restored. Full walking, audio and reference rendering correctness remain unverified. The diagnostic timing/CPU capture is a single-build observation, with no FPS improvement claimed. Warm-run evidence and screenshots, SHA-256 2018ff198377cb5b572c344490a87cd282b420f966e599c8c6f0766c94d6660e.
  • Windows/macOS execution is not tested; the changed entry helper and new case are Linux-only.
  • Linux evidence archive: CPU JUnit/logs and negative control, open-source patch, compact diagnostic summaries, control source and the title-screen screenshot. SHA-256 714cd5b9c1265631d13ea7fe40d38b8f4120d6edfaf816ab2a02b5f31ec77000, verified against GitHub's asset digest. No title binaries, assets, saves, raw memory or raw shader logs.

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: none
  • Unblocks: PPSA08102 #9744
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5134985229 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15436). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-11-03T09:38:48Z. --- ### What When a module calls `scePthreadSelf` before the Linux guest entry runs, the adopted thread records the original host-stack bounds. `EnterGuestMainStack_nid_no_patch` subsequently moves execution to the guest stack but leaves that record unchanged. Stack queries and collectors can then combine a guest-stack pointer with the old host-stack end. Refresh the existing thread's stack address and size under the live-thread registry lock before entering the mapped main stack. Preserve the thread identity and the existing stack address, guard and argument-passing behavior. The default late-adoption path remains covered. The regression explicitly adopts the thread before entry, then checks `sceKernelIsStack`, thread identity, both SCE/POSIX attribute queries, the stack guard and a worker stack. A separate CTest case retains the original late-adoption path. This follows the merged #7532 and the startup evidence reported [there](https://github.com/boykopovar/AnyPS5/pull/7532#issuecomment-6599759884). ### Tested Linux 7.2.11, Ryzen 9 7950X, GCC 16.2.1, Release. Base `4f41f4c375f5abb487dbd184fbc150f31994d762`, change `4199ddb20550a83466b64df7caa938c5f1fc82fe`. - With the new tests and unchanged base production code, `guest_main_stack` passes and `guest_main_stack_adopted` fails. Zero skips. - Restoring the fix and rebuilding passes all eight selected CPU cases: `guest_kernel_is_stack`, `guest_main_stack`, `guest_main_stack_adopted`, `guest_pthread_attr`, `guest_pthread_attr_stack`, `guest_pthread_attr_errors`, `guest_pthread_start`, `guest_pthread_stack`. Zero skips/failures. - A fresh native Outer Wilds (PPSA08102) relink against base exits 139 at 2.1 seconds, before a window. Two GDB probes reproduce a read 280 bytes above the mapped guest stack; the scanner's range calculation reaches the original host-stack page. A host-stack-only diagnostic avoids that early crash but shows a black two-present window. Copying the initial argument block onto the guest stack alone still crashes. These diagnostics narrow the issue; they are not successful game bring-up or performance results. - Official `pr_overlap.py --base main --branch fix/linux-main-stack-adopted-attributes-20261103` scanned 1,668 open PRs. It could not automatically compare 35 conflicting older branches; their reported shared-file diffs were inspected manually. They change other platform/thread/I/O paths or add unrelated tests; none supplies this main-stack refresh or the new regression. Merge-tree against the fetched current main is clean. - **Native candidate, exact committed source, no preload:** the same generated Outer Wilds executable/modules now run to the scheduled close at 291 seconds, native/harness exit 0. The reviewed 260-second screenshot shows the rendered title screen with readable logo/start prompt and its small planet/trees. The 170-second capture was black while shaders were still being prepared. Compositor and independent X11 readbacks agree. - That cold run used the same archived save seed and fresh private project/Mesa shader caches. Scripted Cross inputs ended before cold loading completed, so menu interaction/gameplay, audio and an FPS gain are **not** established. SDK/generated/input hashes remain intact; the kernel setting is restored and no private native process remains. - **Additional warm-cache run on the same head:** menu advancement and Square reach the opening outdoor scene. Directly reviewed 200/300-second captures show the tower, trees, planet and Move/Look Around prompts, with day/night progression. Normal scheduled close at 400.7 seconds, native/harness exit 0; SDK/generated hashes intact and kernel setting restored. Full walking, audio and reference rendering correctness remain unverified. The diagnostic timing/CPU capture is a single-build observation, with no FPS improvement claimed. [Warm-run evidence and screenshots](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/outerwilds-4199-opening-profile-20261103.tar.gz), SHA-256 `2018ff198377cb5b572c344490a87cd282b420f966e599c8c6f0766c94d6660e`. - Windows/macOS execution is not tested; the changed entry helper and new case are Linux-only. - [Linux evidence archive](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/pr15436-linux-main-stack-4199-20261103.tar.gz): CPU JUnit/logs and negative control, open-source patch, compact diagnostic summaries, control source and the title-screen screenshot. SHA-256 `714cd5b9c1265631d13ea7fe40d38b8f4120d6edfaf816ab2a02b5f31ec77000`, verified against GitHub's asset digest. No title binaries, assets, saves, raw memory or raw shader logs. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: PPSA08102 #9744 - [x] GPUs tested: n/a - [x] AI-assisted: yes
XairRrR commented 2026-11-03 09:47:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T09:47:32Z.

Review: APPROVED


Reviewed — approved

When a thread was adopted through scePthreadSelf before EnterGuestMainStack_nid_no_patch, it kept its old host-stack bounds; the fix updates them, the new guest_main_stack_adopted test fails without it and passes with it, and I found nothing blocking.

What I ran

Head 4199ddb20550a83466b64df7caa938c5f1fc82fe, main 4f41f4c375f5abb487dbd184fbc150f31994d762, merged tree deb724ce6859ce62f57eb7d54bdab12c59683310 (Debian 13 VM, Xeon Gold 6136, GCC 14.2.0, Release, Ninja).

git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...4199ddb20550a83466b64df7caa938c5f1fc82fe
python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762
ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "^(guest_main_stack|guest_main_stack_adopted|guest_kernel_is_stack|guest_pthread_attr|guest_pthread_attr_stack|guest_pthread_attr_errors|guest_pthread_start|guest_pthread_stack)$"
git show 4f41f4c375f5abb487dbd184fbc150f31994d762:core/libs/prx/libkernel/Pthread/src/Thread.cpp > core/libs/prx/libkernel/Pthread/src/Thread.cpp
ninja -C build -j32 -l32 guest_main_stack_tests
ctest --test-dir build --output-on-failure -R "^guest_main_stack"
git show deb724ce6859ce62f57eb7d54bdab12c59683310:core/libs/prx/libkernel/Pthread/src/Thread.cpp > core/libs/prx/libkernel/Pthread/src/Thread.cpp
ninja -C build -j32 -l32 guest_main_stack_tests
ctest --test-dir build -R "^guest_main_stack"
git status --porcelain

Results

Check Result
git diff --check clean
check_conventions.py All conventions checks passed
Configure / build / libs (script) ok
Script test run (selected) no new failures, no timeouts; the known failures on main (AGC denormal/division, guest_interfaces, multicast, …) are unrelated to this PR. Skip report: guest_net_ctl is an unexpected skip, and it is skipped on main too
The 8 CPU tests named in the description 8/8 pass (longest guest_pthread_start, 1.87 s)
Negative control guest_main_stack_adopted fails, guest_main_stack passes
Vulkan validation not applicable (no AGC/shader/VideoOut change)
Negative control output (production file from main)
1/2 Test #3306: guest_main_stack .................   Passed    0.01 sec
2/2 Test #3307: guest_main_stack_adopted .........***Failed    0.01 sec
GuestMainStack failed at line 68

Negative control

I restored only core/libs/prx/libkernel/Pthread/src/Thread.cpp from main and rebuilt. guest_main_stack_adopted failed at GuestMainStack.cpp:68: sceKernelIsStack reports the old host-stack end where the guest main-stack top should be. guest_main_stack, the late-adoption path, still passed. This matches the description. After I put the merged file back and rebuilt, both tests passed, and git status --porcelain was empty.

Code review

  • Thread.cpp:257-262: CurrentStack (Thread.cpp:414-421) prefers current->stackAddress/stackSize over HostStackLimits. So an adopted thread kept its host-stack range after the switch, while HostStackLimits had already moved to the guest main-stack range. Updating both fields fixes sceKernelIsStack, GuestThreadStack and both attribute getters together.
  • Locking is consistent with the readers. scePthreadAttrGet (src/Attr.cpp:93-96) and pthread_attr_get_np (Posix/Attr.cpp:25-29) read the same fields under LockLiveGuestThread. The unique_lock is scoped to the if block, so it is released before the noreturn inline asm.
  • Adopted threads are never put in liveStacks (RegisterStack is only called from RunThread, Thread.cpp:898), and they have no guestStack mapping. So no other stack record needs updating.
  • The code is Linux-only (inside the __linux__ block that begins at Thread.cpp:138), and so is the CMake registration. It contains no comments and no title-specific logic. The new test case finishes in about 0.01 s.
  • Checklist lines are present: Depends on, Fixes, Unblocks (PPSA08102 #9744), GPUs tested n/a (correct for a CPU-only change), and AI-assisted.

Findings

Blocking

None.

Non-blocking

  1. The "not live" throw leaves the main stack half-entered (core/libs/prx/libkernel/Pthread/src/Thread.cpp:259).
    • The check runs after the mapping is created and after guestMainStackLow/guestMainStackHigh are published (Thread.cpp:255-256).
    • If it ever throws, the mapping stays, and a later call fails with "already entered" instead of reporting the real cause.
    • The case is unlikely: an adopted thread is registered by BindHostCpuClock and is never marked finished while it is running.
    • Suggested fix: check liveness before mapping, or before the two stores, so the failure leaves no state behind.

Not verified

  • The Outer Wilds (PPSA08102) bring-up, the GDB probes and the linked evidence archive: I did not launch a title, and I did not download the archive.
  • Windows and macOS: the change and the test are Linux-only, and I ran nothing on those platforms.
  • The description's pr_overlap.py result: I had no network to run it.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5750014163 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15436#pullrequestreview-5750014163). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-03T09:47:32Z. **Review:** APPROVED --- # Reviewed — approved When a thread was adopted through `scePthreadSelf` before `EnterGuestMainStack_nid_no_patch`, it kept its old host-stack bounds; the fix updates them, the new `guest_main_stack_adopted` test fails without it and passes with it, and I found nothing blocking. ## What I ran Head `4199ddb20550a83466b64df7caa938c5f1fc82fe`, `main` `4f41f4c375f5abb487dbd184fbc150f31994d762`, merged tree `deb724ce6859ce62f57eb7d54bdab12c59683310` (Debian 13 VM, Xeon Gold 6136, GCC 14.2.0, Release, Ninja). ``` git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...4199ddb20550a83466b64df7caa938c5f1fc82fe python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "^(guest_main_stack|guest_main_stack_adopted|guest_kernel_is_stack|guest_pthread_attr|guest_pthread_attr_stack|guest_pthread_attr_errors|guest_pthread_start|guest_pthread_stack)$" git show 4f41f4c375f5abb487dbd184fbc150f31994d762:core/libs/prx/libkernel/Pthread/src/Thread.cpp > core/libs/prx/libkernel/Pthread/src/Thread.cpp ninja -C build -j32 -l32 guest_main_stack_tests ctest --test-dir build --output-on-failure -R "^guest_main_stack" git show deb724ce6859ce62f57eb7d54bdab12c59683310:core/libs/prx/libkernel/Pthread/src/Thread.cpp > core/libs/prx/libkernel/Pthread/src/Thread.cpp ninja -C build -j32 -l32 guest_main_stack_tests ctest --test-dir build -R "^guest_main_stack" git status --porcelain ``` ## Results | Check | Result | |---|---| | `git diff --check` | clean | | `check_conventions.py` | All conventions checks passed | | Configure / build / libs (script) | ok | | Script test run (selected) | no new failures, no timeouts; the known failures on `main` (AGC denormal/division, `guest_interfaces`, multicast, …) are unrelated to this PR. Skip report: `guest_net_ctl` is an unexpected skip, and it is skipped on `main` too | | The 8 CPU tests named in the description | 8/8 pass (longest `guest_pthread_start`, 1.87 s) | | Negative control | `guest_main_stack_adopted` fails, `guest_main_stack` passes | | Vulkan validation | not applicable (no AGC/shader/VideoOut change) | <details><summary>Negative control output (production file from <code>main</code>)</summary> ``` 1/2 Test #3306: guest_main_stack ................. Passed 0.01 sec 2/2 Test #3307: guest_main_stack_adopted .........***Failed 0.01 sec GuestMainStack failed at line 68 ``` </details> ## Negative control I restored only `core/libs/prx/libkernel/Pthread/src/Thread.cpp` from `main` and rebuilt. `guest_main_stack_adopted` failed at `GuestMainStack.cpp:68`: `sceKernelIsStack` reports the old host-stack end where the guest main-stack top should be. `guest_main_stack`, the late-adoption path, still passed. This matches the description. After I put the merged file back and rebuilt, both tests passed, and `git status --porcelain` was empty. ## Code review - `Thread.cpp:257-262`: `CurrentStack` (`Thread.cpp:414-421`) prefers `current->stackAddress/stackSize` over `HostStackLimits`. So an adopted thread kept its host-stack range after the switch, while `HostStackLimits` had already moved to the guest main-stack range. Updating both fields fixes `sceKernelIsStack`, `GuestThreadStack` and both attribute getters together. - Locking is consistent with the readers. `scePthreadAttrGet` (`src/Attr.cpp:93-96`) and `pthread_attr_get_np` (`Posix/Attr.cpp:25-29`) read the same fields under `LockLiveGuestThread`. The `unique_lock` is scoped to the `if` block, so it is released before the `noreturn` inline asm. - Adopted threads are never put in `liveStacks` (`RegisterStack` is only called from `RunThread`, `Thread.cpp:898`), and they have no `guestStack` mapping. So no other stack record needs updating. - The code is Linux-only (inside the `__linux__` block that begins at `Thread.cpp:138`), and so is the CMake registration. It contains no comments and no title-specific logic. The new test case finishes in about 0.01 s. - Checklist lines are present: Depends on, Fixes, Unblocks (`PPSA08102 #9744`), GPUs tested `n/a` (correct for a CPU-only change), and AI-assisted. ## Findings ### Blocking None. ### Non-blocking 1. **The "not live" throw leaves the main stack half-entered** (`core/libs/prx/libkernel/Pthread/src/Thread.cpp:259`). - The check runs after the mapping is created and after `guestMainStackLow`/`guestMainStackHigh` are published (`Thread.cpp:255-256`). - If it ever throws, the mapping stays, and a later call fails with "already entered" instead of reporting the real cause. - The case is unlikely: an adopted thread is registered by `BindHostCpuClock` and is never marked finished while it is running. - Suggested fix: check liveness before mapping, or before the two `store`s, so the failure leaves no state behind. ## Not verified - The Outer Wilds (PPSA08102) bring-up, the GDB probes and the linked evidence archive: I did not launch a title, and I did not download the archive. - Windows and macOS: the change and the test are Linux-only, and I ran nothing on those platforms. - The description's `pr_overlap.py` result: I had no network to run it. <!-- anyps5-bots job=3261 head=4199ddb20550a83466b64df7caa938c5f1fc82fe -->
MarcZX10 commented 2026-11-03 09:54:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-03T09:54:47Z.

Review: COMMENTED


Reviewed — no blocking findings

I reviewed all three changed files at head 4199ddb20550a83466b64df7caa938c5f1fc82fe; the stack-bound update is protected by a scoped registry lock that ends before the stack switch, and the supplied test logs support the new regression case, but hosted checks are still pending so this is a COMMENTED result.

What I ran

Reviewed exact head 4199ddb20550a83466b64df7caa938c5f1fc82fe against base 4f41f4c375f5abb487dbd184fbc150f31994d762. The exact-head merge preview against that base is clean. Environment: Debian 12, Linux x86_64, Python 3.11.2, Git 2.39.5, GCC 12.2.0; I did not compile with GCC. I read the full three-file diff, the thread-registry lock implementation and readers, the test registration, and the attached evidence archive. The archived test logs are author-provided evidence; I inspected but did not run them.

git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...4199ddb20550a83466b64df7caa938c5f1fc82fe
python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 15436
python3 /marc/AnyPS5/tools/pr_test_quality.py --root /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15436-4199ddb20550/head-4199ddb20550-82ea9f88 --json core/libs/tests/GuestMainStack.cpp
sha256sum /tmp/anyps5-15436-linux-validation.tar.gz
tar -xOf /tmp/anyps5-15436-linux-validation.tar.gz candidate-focused.log
tar -xOf /tmp/anyps5-15436-linux-validation.tar.gz baseline-new-tests.log
gh release view linux-validation-20261023 --repo JJenkx/AnyPS5 --json assets --jq '.assets[] | select(.name=="pr15436-linux-main-stack-4199-20261103.tar.gz") | {name,size,digest,url}'
gh pr checks 15436 --repo boykopovar/AnyPS5

Results

Check Result Note
Diff and conventions passed Whitespace and repository convention/template checks passed.
Base merge preview passed Exact head previews cleanly on the exact base.
Test registration passed The Linux CMake block registers both main-stack cases.
Test-quality heuristic passed Its registration warning is a false positive; registration was verified in CMake.
Supplied Linux test evidence passed Archive hash matches the PR description; logs report 8/8 selected tests and the adopted-case baseline failure.
Hosted checks not run Windows is running; conventions and labels are queued. Other applicable policy checks have passed.
Local build, CTest, and negative control not run I did not build or execute C++ tests or mutate the code.
Commands and unedited outputs

Precheck summary:

PR: https://github.com/boykopovar/AnyPS5/pull/15436
Head: `4199ddb20550a83466b64df7caa938c5f1fc82fe`
Base: `4f41f4c375f5abb487dbd184fbc150f31994d762`
Head unchanged at completion: **True**
Base unchanged at completion: **True**

Precheck table:

Check Status Command / reason
build_and_compile not_applicable The precheck deliberately does not configure, build, or compile AnyPS5.
diff_check passed git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...4199ddb20550a83466b64df7caa938c5f1fc82fe
conventions_and_pr_template passed /usr/bin/python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 --head 4199ddb20550a83466b64df7caa938c5f1fc82fe --title fix(libkernel): refresh adopted thread bounds when entering the main stack --body /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15436-4199ddb20550/pr-body.md
changed_export_abi_audit failed /usr/bin/python3 tools/pr_abi_audit.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 --head 4199ddb20550a83466b64df7caa938c5f1fc82fe --json
python_syntax not_applicable No changed Python implementation files.
related_python_unit_tests not_applicable No changed tools/ module has an existing sibling tools/tests/test_<module>.py suite.
python_test_registration not_applicable No changed test_*.py files.
live_dependency_and_mergeability_check passed /usr/bin/python3 /marc/AnyPS5/tools/pr_stack_check.py 15436 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15436-4199ddb20550/stack
build_dependent_cpp_tests not_applicable Not run: C++ tests need exact-head binaries, which require a build; the precheck does not build.
test_quality_heuristics failed /usr/bin/python3 /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15436-4199ddb20550/head-4199ddb20550-82ea9f88/tools/pr_test_quality.py --root /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15436-4199ddb20550/head-4199ddb20550-82ea9f88 --json core/libs/prx/libkernel/CMakeLists.txt core/libs/prx/libkernel/Pthread/src/Thread.cpp core/libs/tests/GuestMainStack.cpp
negative_controls not_applicable No changed Python test module in tools/ can be run as a no-build base-source control.

The precheck's two helper failures are snapshot-tooling limitations: tools/pr_abi_audit.py and tools/pr_test_quality.py are not in the isolated PR snapshot. The ABI audit is not applicable to this diff. The precheck stderr for those rows was:

/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15436-4199ddb20550/head-4199ddb20550-82ea9f88/tools/pr_abi_audit.py': [Errno 2] No such file or directory
/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15436-4199ddb20550/head-4199ddb20550-82ea9f88/tools/pr_test_quality.py': [Errno 2] No such file or directory

I ran the workspace test-quality helper against the exact snapshot; its raw output was:

{
  "findings": [
    {
      "path": "core/libs/tests/GuestMainStack.cpp",
      "line": 1,
      "kind": "possible-unregistered-cpp-test",
      "message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage."
    }
  ],
  "negative_control_candidates": [],
  "limits": [
    "Heuristics can miss weak assertions and can flag valid tests; inspect every finding.",
    "A test that passes against base is not by itself proof that the PR test is inadequate.",
    "Negative controls are only candidates until the test actually runs against base and fails by assertion rather than import/setup error."
  ]
}

The exact-head CMake registration inspected manually is add_test(NAME guest_main_stack_adopted COMMAND guest_main_stack_tests adopted). Stack report: /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15436-4199ddb20550/stack/stack-report.md; it reports a clean merge preview and no declared dependency.

Archive checksum output:

714cd5b9c1265631d13ea7fe40d38b8f4120d6edfaf816ab2a02b5f31ec77000  /tmp/anyps5-15436-linux-validation.tar.gz

GitHub release asset metadata output:

{"digest":null,"name":"pr15436-linux-main-stack-4199-20261103.tar.gz","size":251456,"url":"https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/pr15436-linux-main-stack-4199-20261103.tar.gz"}

Candidate focused log:

Test project /mnt/sas-ssd/AnyPS5-work/workspace/http9834-main92d2-20261102/build
    Start 3305: guest_kernel_is_stack
1/8 Test #3305: guest_kernel_is_stack ............   Passed    0.01 sec
    Start 3306: guest_main_stack
2/8 Test #3306: guest_main_stack .................   Passed    0.00 sec
    Start 3307: guest_main_stack_adopted
3/8 Test #3307: guest_main_stack_adopted .........   Passed    0.00 sec
    Start 3316: guest_pthread_attr
4/8 Test #3316: guest_pthread_attr ...............   Passed    0.04 sec
    Start 3319: guest_pthread_attr_stack
5/8 Test #3319: guest_pthread_attr_stack .........   Passed    0.00 sec
    Start 3325: guest_pthread_start
6/8 Test #3325: guest_pthread_start ..............   Passed    0.56 sec
    Start 3331: guest_pthread_attr_errors
7/8 Test #3331: guest_pthread_attr_errors ........   Passed    0.00 sec
    Start 3332: guest_pthread_stack
8/8 Test #3332: guest_pthread_stack ..............   Passed    0.12 sec

100% tests passed out of 8

Total Test time (real) =   0.89 sec

Baseline new-tests log:

Test project /mnt/sas-ssd/AnyPS5-work/workspace/http9834-main92d2-20261102/build
    Start 3306: guest_main_stack
1/2 Test #3306: guest_main_stack .................   Passed    0.01 sec
    Start 3307: guest_main_stack_adopted
2/2 Test #3307: guest_main_stack_adopted .........***Failed    0.00 sec
[src/HostCpu.cpp:220 operator()] host CPU AMD Ryzen 9 7950X 16-Core Processor: has SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, POPCNT, LZCNT, BMI1, BMI2, MOVBE, CMPXCHG16B, LAHF/SAHF, AVX, AVX2, FMA, F16C, AES, PCLMULQDQ, RDRAND, RDSEED, ADX, SHA, CLFLUSHOPT, CLWB, RDPID, XSAVEOPT, XSAVEC, SSE4A, PREFETCHW, CLZERO, OS AVX state (XCR0); lacks none
[memory] configured flexible memory: 0x1c000000 bytes (448 MiB)
GuestMainStack failed at line 68

50% tests passed, 1 tests failed out of 2

Total Test time (real) =   0.14 sec

The following tests FAILED:
	3307 - guest_main_stack_adopted (Failed)
Errors while running CTest

Negative control

Assertion Change to code under test Did the new test fail?
An adopted thread's reported stack bounds must match the guest main stack after entry. The supplied archive's baseline run uses the unmodified base production code; I did not mutate or execute the source. Yes, the archive reports guest_main_stack_adopted failing on baseline; candidate log reports it passing.

Findings

Blocking

None found in the three changed files.

Non-blocking

  • The attached archive is author-provided. Its SHA-256 matches the value in the PR description, and its metadata identifies the reviewed head and base. The GitHub release API currently returns digest: null for the asset, so I could not independently verify the description's claim that this checksum was checked against a GitHub-supplied digest. I did not independently reproduce the Linux build, CTest run, or Outer Wilds run.
  • At the final status refresh, Windows was in progress; conventions and labels were queued; the other checks that ran passed, while Linux and specialized jobs were skipped. I am withholding approval until applicable hosted checks complete.

Sources

Not verified

I did not build or run CTest, reproduce the baseline negative control, test Windows or macOS behavior, run Outer Wilds, or test on a PS5 console. The archived GPU/title diagnostics and CPU test logs are supplied evidence, not runs performed by me. No performance claim is made.

To get this to a good state

No source change is requested. Let the remaining applicable hosted checks complete. If the head changes, I will rerun the diff, conventions, precheck, merge preview, test-registration inspection and relevant tests on that new head before deciding whether approval is warranted.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5750125715 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15436#pullrequestreview-5750125715). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-03T09:54:47Z. **Review:** COMMENTED --- # Reviewed — no blocking findings I reviewed all three changed files at head `4199ddb20550a83466b64df7caa938c5f1fc82fe`; the stack-bound update is protected by a scoped registry lock that ends before the stack switch, and the supplied test logs support the new regression case, but hosted checks are still pending so this is a COMMENTED result. ## What I ran Reviewed exact head `4199ddb20550a83466b64df7caa938c5f1fc82fe` against base `4f41f4c375f5abb487dbd184fbc150f31994d762`. The exact-head merge preview against that base is clean. Environment: Debian 12, Linux x86_64, Python 3.11.2, Git 2.39.5, GCC 12.2.0; I did not compile with GCC. I read the full three-file diff, the thread-registry lock implementation and readers, the test registration, and the attached evidence archive. The archived test logs are author-provided evidence; I inspected but did not run them. ```sh git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...4199ddb20550a83466b64df7caa938c5f1fc82fe python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 15436 python3 /marc/AnyPS5/tools/pr_test_quality.py --root /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15436-4199ddb20550/head-4199ddb20550-82ea9f88 --json core/libs/tests/GuestMainStack.cpp sha256sum /tmp/anyps5-15436-linux-validation.tar.gz tar -xOf /tmp/anyps5-15436-linux-validation.tar.gz candidate-focused.log tar -xOf /tmp/anyps5-15436-linux-validation.tar.gz baseline-new-tests.log gh release view linux-validation-20261023 --repo JJenkx/AnyPS5 --json assets --jq '.assets[] | select(.name=="pr15436-linux-main-stack-4199-20261103.tar.gz") | {name,size,digest,url}' gh pr checks 15436 --repo boykopovar/AnyPS5 ``` ## Results | Check | Result | Note | |---|---|---| | Diff and conventions | passed | Whitespace and repository convention/template checks passed. | | Base merge preview | passed | Exact head previews cleanly on the exact base. | | Test registration | passed | The Linux CMake block registers both main-stack cases. | | Test-quality heuristic | passed | Its registration warning is a false positive; registration was verified in CMake. | | Supplied Linux test evidence | passed | Archive hash matches the PR description; logs report 8/8 selected tests and the adopted-case baseline failure. | | Hosted checks | not run | Windows is running; conventions and labels are queued. Other applicable policy checks have passed. | | Local build, CTest, and negative control | not run | I did not build or execute C++ tests or mutate the code. | <details> <summary>Commands and unedited outputs</summary> Precheck summary: ```text PR: https://github.com/boykopovar/AnyPS5/pull/15436 Head: `4199ddb20550a83466b64df7caa938c5f1fc82fe` Base: `4f41f4c375f5abb487dbd184fbc150f31994d762` Head unchanged at completion: **True** Base unchanged at completion: **True** ``` Precheck table: | Check | Status | Command / reason | |---|---|---| | build_and_compile | not_applicable | `The precheck deliberately does not configure, build, or compile AnyPS5.` | | diff_check | passed | `git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...4199ddb20550a83466b64df7caa938c5f1fc82fe` | | conventions_and_pr_template | passed | `/usr/bin/python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 --head 4199ddb20550a83466b64df7caa938c5f1fc82fe --title fix(libkernel): refresh adopted thread bounds when entering the main stack --body /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15436-4199ddb20550/pr-body.md` | | changed_export_abi_audit | failed | `/usr/bin/python3 tools/pr_abi_audit.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 --head 4199ddb20550a83466b64df7caa938c5f1fc82fe --json` | | python_syntax | not_applicable | `No changed Python implementation files.` | | related_python_unit_tests | not_applicable | `No changed tools/ module has an existing sibling tools/tests/test_<module>.py suite.` | | python_test_registration | not_applicable | `No changed test_*.py files.` | | live_dependency_and_mergeability_check | passed | `/usr/bin/python3 /marc/AnyPS5/tools/pr_stack_check.py 15436 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15436-4199ddb20550/stack` | | build_dependent_cpp_tests | not_applicable | `Not run: C++ tests need exact-head binaries, which require a build; the precheck does not build.` | | test_quality_heuristics | failed | `/usr/bin/python3 /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15436-4199ddb20550/head-4199ddb20550-82ea9f88/tools/pr_test_quality.py --root /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15436-4199ddb20550/head-4199ddb20550-82ea9f88 --json core/libs/prx/libkernel/CMakeLists.txt core/libs/prx/libkernel/Pthread/src/Thread.cpp core/libs/tests/GuestMainStack.cpp` | | negative_controls | not_applicable | `No changed Python test module in tools/ can be run as a no-build base-source control.` | The precheck's two helper failures are snapshot-tooling limitations: `tools/pr_abi_audit.py` and `tools/pr_test_quality.py` are not in the isolated PR snapshot. The ABI audit is not applicable to this diff. The precheck stderr for those rows was: ```text /usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15436-4199ddb20550/head-4199ddb20550-82ea9f88/tools/pr_abi_audit.py': [Errno 2] No such file or directory /usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15436-4199ddb20550/head-4199ddb20550-82ea9f88/tools/pr_test_quality.py': [Errno 2] No such file or directory ``` I ran the workspace test-quality helper against the exact snapshot; its raw output was: ```json { "findings": [ { "path": "core/libs/tests/GuestMainStack.cpp", "line": 1, "kind": "possible-unregistered-cpp-test", "message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage." } ], "negative_control_candidates": [], "limits": [ "Heuristics can miss weak assertions and can flag valid tests; inspect every finding.", "A test that passes against base is not by itself proof that the PR test is inadequate.", "Negative controls are only candidates until the test actually runs against base and fails by assertion rather than import/setup error." ] } ``` The exact-head CMake registration inspected manually is `add_test(NAME guest_main_stack_adopted COMMAND guest_main_stack_tests adopted)`. Stack report: `/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15436-4199ddb20550/stack/stack-report.md`; it reports a clean merge preview and no declared dependency. Archive checksum output: ```text 714cd5b9c1265631d13ea7fe40d38b8f4120d6edfaf816ab2a02b5f31ec77000 /tmp/anyps5-15436-linux-validation.tar.gz ``` GitHub release asset metadata output: ```json {"digest":null,"name":"pr15436-linux-main-stack-4199-20261103.tar.gz","size":251456,"url":"https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/pr15436-linux-main-stack-4199-20261103.tar.gz"} ``` Candidate focused log: ```text Test project /mnt/sas-ssd/AnyPS5-work/workspace/http9834-main92d2-20261102/build Start 3305: guest_kernel_is_stack 1/8 Test #3305: guest_kernel_is_stack ............ Passed 0.01 sec Start 3306: guest_main_stack 2/8 Test #3306: guest_main_stack ................. Passed 0.00 sec Start 3307: guest_main_stack_adopted 3/8 Test #3307: guest_main_stack_adopted ......... Passed 0.00 sec Start 3316: guest_pthread_attr 4/8 Test #3316: guest_pthread_attr ............... Passed 0.04 sec Start 3319: guest_pthread_attr_stack 5/8 Test #3319: guest_pthread_attr_stack ......... Passed 0.00 sec Start 3325: guest_pthread_start 6/8 Test #3325: guest_pthread_start .............. Passed 0.56 sec Start 3331: guest_pthread_attr_errors 7/8 Test #3331: guest_pthread_attr_errors ........ Passed 0.00 sec Start 3332: guest_pthread_stack 8/8 Test #3332: guest_pthread_stack .............. Passed 0.12 sec 100% tests passed out of 8 Total Test time (real) = 0.89 sec ``` Baseline new-tests log: ```text Test project /mnt/sas-ssd/AnyPS5-work/workspace/http9834-main92d2-20261102/build Start 3306: guest_main_stack 1/2 Test #3306: guest_main_stack ................. Passed 0.01 sec Start 3307: guest_main_stack_adopted 2/2 Test #3307: guest_main_stack_adopted .........***Failed 0.00 sec [src/HostCpu.cpp:220 operator()] host CPU AMD Ryzen 9 7950X 16-Core Processor: has SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, POPCNT, LZCNT, BMI1, BMI2, MOVBE, CMPXCHG16B, LAHF/SAHF, AVX, AVX2, FMA, F16C, AES, PCLMULQDQ, RDRAND, RDSEED, ADX, SHA, CLFLUSHOPT, CLWB, RDPID, XSAVEOPT, XSAVEC, SSE4A, PREFETCHW, CLZERO, OS AVX state (XCR0); lacks none [memory] configured flexible memory: 0x1c000000 bytes (448 MiB) GuestMainStack failed at line 68 50% tests passed, 1 tests failed out of 2 Total Test time (real) = 0.14 sec The following tests FAILED: 3307 - guest_main_stack_adopted (Failed) Errors while running CTest ``` </details> ## Negative control | Assertion | Change to code under test | Did the new test fail? | |---|---|---| | An adopted thread's reported stack bounds must match the guest main stack after entry. | The supplied archive's baseline run uses the unmodified base production code; I did not mutate or execute the source. | Yes, the archive reports `guest_main_stack_adopted` failing on baseline; candidate log reports it passing. | ## Findings ### Blocking None found in the three changed files. ### Non-blocking - The attached archive is author-provided. Its SHA-256 matches the value in the PR description, and its metadata identifies the reviewed head and base. The GitHub release API currently returns `digest: null` for the asset, so I could not independently verify the description's claim that this checksum was checked against a GitHub-supplied digest. I did not independently reproduce the Linux build, CTest run, or Outer Wilds run. - At the final status refresh, Windows was in progress; conventions and labels were queued; the other checks that ran passed, while Linux and specialized jobs were skipped. I am withholding approval until applicable hosted checks complete. ## Sources - [Stack bounds update and lock scope at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/4199ddb20550a83466b64df7caa938c5f1fc82fe/core/libs/prx/libkernel/Pthread/src/Thread.cpp#L257-L263) - [Thread attribute lookup takes the live-thread lock](https://github.com/boykopovar/AnyPS5/blob/4199ddb20550a83466b64df7caa938c5f1fc82fe/core/libs/prx/libkernel/Pthread/src/Attr.cpp#L90-L105) - [Adopted and default main-stack test registration](https://github.com/boykopovar/AnyPS5/blob/4199ddb20550a83466b64df7caa938c5f1fc82fe/core/libs/prx/libkernel/CMakeLists.txt#L624-L630) - [Supplied Linux evidence archive](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/pr15436-linux-main-stack-4199-20261103.tar.gz) ## Not verified I did not build or run CTest, reproduce the baseline negative control, test Windows or macOS behavior, run Outer Wilds, or test on a PS5 console. The archived GPU/title diagnostics and CPU test logs are supplied evidence, not runs performed by me. No performance claim is made. ## To get this to a good state No source change is requested. Let the remaining applicable hosted checks complete. If the head changes, I will rerun the diff, conventions, precheck, merge preview, test-registration inspection and relevant tests on that new head before deciding whether approval is warranted.
hugodearaujo commented 2026-11-03 11:58:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-11-03T11:58:15Z.

Review: APPROVED


I wrote #7532, which caused this regression, so I built and ran the change to back up the logs in the archive.

What I ran: head 4199ddb205 on main 4f41f4c375 (the PR's parent), Arch Linux 7.2.11, GCC, Release, Ninja. I built the test targets and ran them with ctest --output-on-failure.

Tree guest_main_stack guest_main_stack_adopted
Head, with Thread.cpp from main (new test, old code) passed failed at GuestMainStack.cpp:68
Head passed passed

The failing check is Require(high == ConsoleMainStackTop). On the old code, sceKernelIsStack reports the host stack's end as the top of a thread that was adopted before the switch. A scan up to that end runs past the mapped guest stack, which matches the read 280 bytes above GUEST_MAIN_STACK_TOP in the report on #7532.

With the fix, all eight selected cases pass (100% tests passed out of 8): guest_kernel_is_stack, guest_main_stack, guest_main_stack_adopted, guest_pthread_attr, guest_pthread_attr_stack, guest_pthread_attr_errors, guest_pthread_start and guest_pthread_stack.

Code: the update only runs when a thread was already adopted, keeps that record's identity, and holds the live-thread lock in a scope that ends before the stack switch. A thread adopted after the switch still reads the guest bounds as before, and guest_main_stack covers that path.

Not verified: I didn't run Outer Wilds or any other title, and I didn't test Windows or macOS. The changed path is Linux-only.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5751781211 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15436#pullrequestreview-5751781211). Originally posted by [hugodearaujo](https://github.com/hugodearaujo) on 2026-11-03T11:58:15Z. **Review:** APPROVED --- I wrote #7532, which caused this regression, so I built and ran the change to back up the logs in the archive. **What I ran:** head `4199ddb205` on main `4f41f4c375` (the PR's parent), Arch Linux 7.2.11, GCC, Release, Ninja. I built the test targets and ran them with `ctest --output-on-failure`. | Tree | `guest_main_stack` | `guest_main_stack_adopted` | |---|---|---| | Head, with `Thread.cpp` from `main` (new test, old code) | passed | **failed** at `GuestMainStack.cpp:68` | | Head | passed | passed | The failing check is `Require(high == ConsoleMainStackTop)`. On the old code, `sceKernelIsStack` reports the host stack's end as the top of a thread that was adopted before the switch. A scan up to that end runs past the mapped guest stack, which matches the read 280 bytes above `GUEST_MAIN_STACK_TOP` in the report on #7532. With the fix, all eight selected cases pass (`100% tests passed out of 8`): `guest_kernel_is_stack`, `guest_main_stack`, `guest_main_stack_adopted`, `guest_pthread_attr`, `guest_pthread_attr_stack`, `guest_pthread_attr_errors`, `guest_pthread_start` and `guest_pthread_stack`. **Code:** the update only runs when a thread was already adopted, keeps that record's identity, and holds the live-thread lock in a scope that ends before the stack switch. A thread adopted after the switch still reads the guest bounds as before, and `guest_main_stack` covers that path. **Not verified:** I didn't run Outer Wilds or any other title, and I didn't test Windows or macOS. The changed path is Linux-only.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!15436
No description provided.