feat(libkernel): initialize created guest thread MXCSR to 0x9fc0 at entry boundary #7565

Merged
pushkarreddyy merged 3 commits from upstream-pr/7565 into main 2026-11-14 11:30:24 +00:00
pushkarreddyy commented 2026-10-18 14:23:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-18T14:23:58Z.


What

Measured on PS5 firmware 12.70: threads of a PS5 payload process start with MXCSR 0x9fc0 (Flush-to-Zero and Denormals-are-Zero enabled, all FP exceptions masked).

In Aps5CallGuestEntry_nid_no_patch, created guest threads now set 0x9fc0 upon entering guest execution. The 16-byte MXCSR scratch slot is allocated below %rbp (sub $16, %rsp / add $32, %rsp), preserving the sentinel frame-pointer zero record for guest_pthread_frame_chain. In RunThread and scePthreadExit, host worker MXCSR is recorded and restored only after finishThread has completed, ensuring that guest thread destructors and TSD key destructors execute symmetrically under guest MXCSR 0x9fc0 across both explicit exit and normal return paths, while host native workers return to host MXCSR upon thread completion. Note: the main ELF thread entry stub is handled separately in #7594 and is not covered here.

Tested

Linux x86_64 and Windows: core/libs/tests/PthreadStart.cpp exercises 10,000 guest thread starts across normal return and scePthreadExit explicit exits. Tests verify that guest execution and cleanup (WorkerThreadDtor) observe 0x9fc0, the native worker thread (WorkerTlsHook TLS destructor) restores host MXCSR upon guest completion, and the process main thread preserves its host MXCSR throughout; python tools/check_conventions.py --base origin/main passes with 0 findings.

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: Uncharted: Legacy of Thieves Collection (PPSA05684) #7565
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4909868984 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-18T14:23:58Z. --- ### What Measured on PS5 firmware 12.70: threads of a PS5 payload process start with MXCSR `0x9fc0` (Flush-to-Zero and Denormals-are-Zero enabled, all FP exceptions masked). In `Aps5CallGuestEntry_nid_no_patch`, created guest threads now set `0x9fc0` upon entering guest execution. The 16-byte MXCSR scratch slot is allocated below `%rbp` (`sub $16, %rsp` / `add $32, %rsp`), preserving the sentinel frame-pointer zero record for `guest_pthread_frame_chain`. In `RunThread` and `scePthreadExit`, host worker MXCSR is recorded and restored only after `finishThread` has completed, ensuring that guest thread destructors and TSD key destructors execute symmetrically under guest MXCSR `0x9fc0` across both explicit exit and normal return paths, while host native workers return to host MXCSR upon thread completion. Note: the main ELF thread entry stub is handled separately in #7594 and is not covered here. ### Tested Linux x86_64 and Windows: `core/libs/tests/PthreadStart.cpp` exercises 10,000 guest thread starts across normal return and `scePthreadExit` explicit exits. Tests verify that guest execution and cleanup (`WorkerThreadDtor`) observe `0x9fc0`, the native worker thread (`WorkerTlsHook` TLS destructor) restores host MXCSR upon guest completion, and the process main thread preserves its host MXCSR throughout; `python tools/check_conventions.py --base origin/main` passes with 0 findings. ### Checklist - [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: Uncharted: Legacy of Thieves Collection (PPSA05684) #7565 - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-18 14:28:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T14:28:53Z.

Review: COMMENTED


One test coverage gap: hostMxcsrBefore and hostMxcsrAfter are sampled on the test process main thread, while scePthreadCreate runs Aps5CallGuestEntry_nid_no_patch on a separate native worker. That assertion would remain unchanged even if the wrapper failed to restore the worker’s MXCSR after a returning guest callback. The explicit restore instruction is present in the diff, but the PR’s stated host-preservation test does not exercise it. Could you add a same-worker post-callback check if practical, or narrow the Tested claim to what the current test observes?

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5563386681 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#pullrequestreview-5563386681). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T14:28:53Z. **Review:** COMMENTED --- One test coverage gap: `hostMxcsrBefore` and `hostMxcsrAfter` are sampled on the test process main thread, while `scePthreadCreate` runs `Aps5CallGuestEntry_nid_no_patch` on a separate native worker. That assertion would remain unchanged even if the wrapper failed to restore the worker’s MXCSR after a returning guest callback. The explicit restore instruction is present in the diff, but the PR’s stated host-preservation test does not exercise it. Could you add a same-worker post-callback check if practical, or narrow the Tested claim to what the current test observes?
ionut27001 commented 2026-10-18 15:13:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ionut27001 on 2026-10-18T15:13:27Z.


Two corrections about what #7548 covers, since this PR cites it:

  • #7548 measured firmware 12.70 only, in a payload process. 13.42 was not measured there.
  • The guest main thread does not go through Aps5CallGuestEntry_nid_no_patch (the relinker's entry stub calls the ELF entry directly), and the main thread is where p14 and p15 also read 0x9fc0. With this change it keeps the host MXCSR, so Fixes: #7548 would close the issue with that part still open.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251532370 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#issuecomment-6251532370). Originally posted by [ionut27001](https://github.com/ionut27001) on 2026-10-18T15:13:27Z. --- Two corrections about what #7548 covers, since this PR cites it: - #7548 measured firmware 12.70 only, in a payload process. 13.42 was not measured there. - The guest main thread does not go through `Aps5CallGuestEntry_nid_no_patch` (the relinker's entry stub calls the ELF entry directly), and the main thread is where p14 and p15 also read 0x9fc0. With this change it keeps the host MXCSR, so `Fixes: #7548` would close the issue with that part still open.
MarcZX10 commented 2026-10-18 15:14:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T15:14:04Z.


The new #7548 report follow-up confirms a scope gap beyond my earlier test comment: the console main thread also reads MXCSR 0x9fc0, while the AnyPS5 main guest entry bypasses Aps5CallGuestEntry_nid_no_patch and the change in this PR. The issue report also says this main-thread measurement is part of the same payload probe. As written, the PR changes spawned guest threads only and does not fully fix #7548. Could you either cover the main guest-entry boundary too (without leaving host-side work under guest MXCSR), with a main-entry regression, or narrow the PR title/body/Fixes: #7548 claim to created threads and coordinate the remaining main-thread behavior separately? I have not run the Windows test locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251538661 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#issuecomment-6251538661). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T15:14:04Z. --- The new #7548 report follow-up confirms a scope gap beyond my earlier test comment: the console main thread also reads MXCSR `0x9fc0`, while the AnyPS5 main guest entry bypasses `Aps5CallGuestEntry_nid_no_patch` and the change in this PR. The issue report also says this main-thread measurement is part of the same payload probe. As written, the PR changes spawned guest threads only and does not fully fix #7548. Could you either cover the main guest-entry boundary too (without leaving host-side work under guest MXCSR), with a main-entry regression, or narrow the PR title/body/`Fixes: #7548` claim to created threads and coordinate the remaining main-thread behavior separately? I have not run the Windows test locally.
jotitadev commented 2026-10-18 15:45:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T15:45:18Z.


Ran this on macOS (x86-64 under Rosetta 2), head 296d1d44a. The Linux and Windows CI jobs were skipped on this PR, so this is the first full-suite run I know of.

Machine: Apple M2 Max, macOS 27.2, Apple clang 21, full x86-64 build. Base: main e5f18ea99 with @mugurc's macOS series (ci/macos-series-2 on his fork) and the open macOS fixes it uses, since main alone does not link the libraries on macOS. Non-GPU suite with and without this PR.

guest_pthread_frame_chain fails with this PR, every run:

guest pthread frame chain: the last frame of a guest thread's chain also has a saved frame pointer of 0

It passes on the same tree without the PR. Aps5CallGuestEntry_nid_no_patch pushes two zeros and points %rbp at them. That pair is the zero record that ends the guest thread's frame chain. The new stmxcsr (%rsp) / movl $0x9fc0, 4(%rsp) write into the saved frame pointer half of that record. After that it holds 0x00009fc0_00001f80, not 0. This does not depend on the host, so Linux and Windows should fail the same way.

Keeping the MXCSR values in their own slot below the record fixes it:

     mov %rsp, %rbp
+    sub $16, %rsp
+    .cfi_adjust_cfa_offset 16
     stmxcsr (%rsp)
     movl $0x9fc0, 4(%rsp)
     ldmxcsr 4(%rsp)
     mov %rdi, %rax
     mov %rsi, %rdi
     call *%rax
     ldmxcsr (%rsp)
-    add $16, %rsp
-    .cfi_adjust_cfa_offset -16
+    add $32, %rsp
+    .cfi_adjust_cfa_offset -32

With that change, guest_pthread_frame_chain (still 3 frames), guest_pthread_start, guest_raise_exception and the other 23 guest_pthread* tests pass.

Other results:

  • guest_pthread_start passes with the PR. With only the test applied it fails with Guest thread MXCSR does not have FTZ and DAZ bits set, so the thread-side check covers the change under Rosetta too.

  • I removed the restoring ldmxcsr (%rsp) and guest_pthread_start still passed. That confirms @MarcZX10's point: the host-preservation check samples the test's main thread, so it cannot see a missing restore.

  • Guest TSD destructors do not run under 0x9fc0 when the entry returns. finishThread runs the key destructors and the thread-exit callback after Aps5CallGuestEntry_nid_no_patch has restored the host MXCSR. A local probe with a scePthreadKeyCreate destructor that reads MXCSR printed:

    Guest thread ends by MXCSR in the entry MXCSR in the key destructor
    returning from the entry 0x9fc0 0x1f80
    scePthreadExit 0x9fc0 0x9fc0

    So the same guest destructor runs with different FTZ/DAZ depending on how the thread ended.

  • On macOS with @mugurc's feat/libkernel-macos-main-thread branch (not opened yet), the guest main thread is also a second host thread: Aps5StartGuest_nid_no_patch runs the entry from RunGuest on a new pthread_create thread, which starts at 0x1f80. Covering the main thread there means setting MXCSR in RunGuest, not only in the relinker's entry stub.

  • Apart from guest_pthread_frame_chain, the non-GPU suite fails the same tests with and without the PR. Those failures are macOS gaps that the series does not cover yet. guest_refused_connect failed in about half of the runs on both trees.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251855367 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#issuecomment-6251855367). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-18T15:45:18Z. --- Ran this on macOS (x86-64 under Rosetta 2), head `296d1d44a`. The Linux and Windows CI jobs were skipped on this PR, so this is the first full-suite run I know of. Machine: Apple M2 Max, macOS 27.2, Apple clang 21, full x86-64 build. Base: `main` e5f18ea99 with @mugurc's macOS series (`ci/macos-series-2` on his fork) and the open macOS fixes it uses, since `main` alone does not link the libraries on macOS. Non-GPU suite with and without this PR. **`guest_pthread_frame_chain` fails with this PR, every run:** ``` guest pthread frame chain: the last frame of a guest thread's chain also has a saved frame pointer of 0 ``` It passes on the same tree without the PR. `Aps5CallGuestEntry_nid_no_patch` pushes two zeros and points `%rbp` at them. That pair is the zero record that ends the guest thread's frame chain. The new `stmxcsr (%rsp)` / `movl $0x9fc0, 4(%rsp)` write into the saved frame pointer half of that record. After that it holds `0x00009fc0_00001f80`, not 0. This does not depend on the host, so Linux and Windows should fail the same way. Keeping the MXCSR values in their own slot below the record fixes it: ```diff mov %rsp, %rbp + sub $16, %rsp + .cfi_adjust_cfa_offset 16 stmxcsr (%rsp) movl $0x9fc0, 4(%rsp) ldmxcsr 4(%rsp) mov %rdi, %rax mov %rsi, %rdi call *%rax ldmxcsr (%rsp) - add $16, %rsp - .cfi_adjust_cfa_offset -16 + add $32, %rsp + .cfi_adjust_cfa_offset -32 ``` With that change, `guest_pthread_frame_chain` (still 3 frames), `guest_pthread_start`, `guest_raise_exception` and the other 23 `guest_pthread*` tests pass. Other results: - `guest_pthread_start` passes with the PR. With only the test applied it fails with `Guest thread MXCSR does not have FTZ and DAZ bits set`, so the thread-side check covers the change under Rosetta too. - I removed the restoring `ldmxcsr (%rsp)` and `guest_pthread_start` still passed. That confirms @MarcZX10's point: the host-preservation check samples the test's main thread, so it cannot see a missing restore. - Guest TSD destructors do not run under `0x9fc0` when the entry returns. `finishThread` runs the key destructors and the thread-exit callback after `Aps5CallGuestEntry_nid_no_patch` has restored the host MXCSR. A local probe with a `scePthreadKeyCreate` destructor that reads MXCSR printed: | Guest thread ends by | MXCSR in the entry | MXCSR in the key destructor | |---|---|---| | returning from the entry | `0x9fc0` | `0x1f80` | | `scePthreadExit` | `0x9fc0` | `0x9fc0` | So the same guest destructor runs with different FTZ/DAZ depending on how the thread ended. - On macOS with @mugurc's `feat/libkernel-macos-main-thread` branch (not opened yet), the guest main thread is also a second host thread: `Aps5StartGuest_nid_no_patch` runs the entry from `RunGuest` on a new `pthread_create` thread, which starts at `0x1f80`. Covering the main thread there means setting MXCSR in `RunGuest`, not only in the relinker's entry stub. - Apart from `guest_pthread_frame_chain`, the non-GPU suite fails the same tests with and without the PR. Those failures are macOS gaps that the series does not cover yet. `guest_refused_connect` failed in about half of the runs on both trees. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
pushkarreddyy commented 2026-10-18 15:59:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-18T15:59:09Z.


Pushed commit 251ef0f28 addressing all feedback:

  1. Stack Unwinding & Frame Chain Record Isolation (@jotitadev):

    • In Aps5CallGuestEntry_nid_no_patch, allocating 16 bytes below %rbp (sub $16, %rsp / .cfi_adjust_cfa_offset 16 and .cfi_adjust_cfa_offset -32 / add $32, %rsp) isolates the MXCSR storage slot into [rbp - 16].
    • This prevents clobbering the two zero words pushed at (%rbp), preserving the sentinel frame pointer record for guest_pthread_frame_chain.
  2. Same-Worker Host MXCSR Restoration Test Coverage (@MarcZX10, @jotitadev):

    • Registered a thread destructor hook via sceKernelSetThreadDtors(WorkerThreadDtor) in core/libs/tests/PthreadStart.cpp.
    • When a guest thread finishes by returning to Aps5CallGuestEntry_nid_no_patch, the wrapper restores the host MXCSR via ldmxcsr (%rsp). Subsequently, finishThread executes WorkerThreadDtor on the exact same worker thread.
    • The test asserts workerMxcsrAfterReturn.load() == hostMxcsrBefore for non-explicit returns (and confirms 0x9fc0 remains active during explicit exit cleanup), directly verifying the worker's restore instruction.
  3. Narrowed PR Scope & Title/Debt Update (@ionut27001, @MarcZX10):

    • Updated the PR title to feat(libkernel): initialize created guest thread MXCSR to 0x9fc0 at entry boundary and set Fixes: none.
    • Clarified in ### What and docs/dev/debt/libkernel.md that this PR specifically covers created guest threads under firmware 12.70 payload findings. The main ELF thread entry stub (which bypasses Aps5CallGuestEntry_nid_no_patch) and macOS RunGuest entry remain open and will not be closed by this PR.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251995499 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#issuecomment-6251995499). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-18T15:59:09Z. --- Pushed commit `251ef0f28` addressing all feedback: 1. **Stack Unwinding & Frame Chain Record Isolation (@jotitadev)**: - In `Aps5CallGuestEntry_nid_no_patch`, allocating 16 bytes below `%rbp` (`sub $16, %rsp` / `.cfi_adjust_cfa_offset 16` and `.cfi_adjust_cfa_offset -32` / `add $32, %rsp`) isolates the MXCSR storage slot into `[rbp - 16]`. - This prevents clobbering the two zero words pushed at `(%rbp)`, preserving the sentinel frame pointer record for `guest_pthread_frame_chain`. 2. **Same-Worker Host MXCSR Restoration Test Coverage (@MarcZX10, @jotitadev)**: - Registered a thread destructor hook via `sceKernelSetThreadDtors(WorkerThreadDtor)` in `core/libs/tests/PthreadStart.cpp`. - When a guest thread finishes by returning to `Aps5CallGuestEntry_nid_no_patch`, the wrapper restores the host MXCSR via `ldmxcsr (%rsp)`. Subsequently, `finishThread` executes `WorkerThreadDtor` on the exact same worker thread. - The test asserts `workerMxcsrAfterReturn.load() == hostMxcsrBefore` for non-explicit returns (and confirms `0x9fc0` remains active during explicit exit cleanup), directly verifying the worker's restore instruction. 3. **Narrowed PR Scope & Title/Debt Update (@ionut27001, @MarcZX10)**: - Updated the PR title to `feat(libkernel): initialize created guest thread MXCSR to 0x9fc0 at entry boundary` and set `Fixes: none`. - Clarified in `### What` and `docs/dev/debt/libkernel.md` that this PR specifically covers created guest threads under firmware 12.70 payload findings. The main ELF thread entry stub (which bypasses `Aps5CallGuestEntry_nid_no_patch`) and macOS `RunGuest` entry remain open and will not be closed by this PR.
MarcZX10 commented 2026-10-18 16:07:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T16:07:56Z.


One remaining state-consistency issue from the new destructor probe: when the guest entry returns normally, Aps5CallGuestEntry_nid_no_patch restores the host MXCSR before RunThread calls finishThread, so threadDtors and RunKeyDtors execute under host MXCSR. When the guest calls scePthreadExit, finishThread runs before the assembly wrapper returns, so the same cleanup executes under guest MXCSR 0x9fc0. A guest TSD destructor therefore observes different floating-point state depending on whether the entry returns or exits explicitly. Could the host MXCSR restoration be delayed until guest-thread cleanup has completed on the normal-return path, and could the regression assert the destructor sees 0x9fc0 in both cases while the worker itself is restored afterward? The current 10,000-iteration test checks the opposite state for normal return cleanup.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6252085124 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#issuecomment-6252085124). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T16:07:56Z. --- One remaining state-consistency issue from the new destructor probe: when the guest entry returns normally, `Aps5CallGuestEntry_nid_no_patch` restores the host MXCSR before `RunThread` calls `finishThread`, so `threadDtors` and `RunKeyDtors` execute under host MXCSR. When the guest calls `scePthreadExit`, `finishThread` runs before the assembly wrapper returns, so the same cleanup executes under guest MXCSR 0x9fc0. A guest TSD destructor therefore observes different floating-point state depending on whether the entry returns or exits explicitly. Could the host MXCSR restoration be delayed until guest-thread cleanup has completed on the normal-return path, and could the regression assert the destructor sees 0x9fc0 in both cases while the worker itself is restored afterward? The current 10,000-iteration test checks the opposite state for normal return cleanup.
MarcZX10 commented 2026-10-18 16:21:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T16:21:24Z.


Update on the main-entry gap I noted earlier: I opened #7594 for the Linux and Windows relinker startup stubs. It sets guest MXCSR to 0x9fc0 at main ELF entry and restores the host MXCSR if that entry returns. This is separate from the created-thread trampoline covered here; macOS’s distinct launcher path remains outside #7594.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6252222607 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#issuecomment-6252222607). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T16:21:24Z. --- Update on the main-entry gap I noted earlier: I opened #7594 for the Linux and Windows relinker startup stubs. It sets guest MXCSR to 0x9fc0 at main ELF entry and restores the host MXCSR if that entry returns. This is separate from the created-thread trampoline covered here; macOS’s distinct launcher path remains outside #7594.
jotitadev commented 2026-10-18 16:39:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T16:39:54Z.

Review: COMMENTED


Re-ran on macOS (x86-64 under Rosetta 2), head 251ef0f28. Linux and Windows CI are still skipped on this PR.

Same setup as my earlier run: Apple M2 Max, macOS 27.2, Apple clang 21, full x86-64 build. Base: main d3d8d79c5 with @mugurc's macOS series and the open macOS fixes it uses.

  • guest_pthread_frame_chain now passes (5/5), so the zero record is intact.
  • guest_pthread_start passes (5/5). The new destructor check covers the restore. With only the ldmxcsr (%rsp) after the call removed, it fails every run with Worker thread host MXCSR was not restored upon guest return. With only the test applied on the base it still fails with Guest thread MXCSR does not have FTZ and DAZ bits set.
  • Non-GPU suite: same failures with and without the PR, all of them macOS gaps that the series does not cover yet. The 51 pthread/thread/raise_exception tests pass on both.

This does not address @MarcZX10's last point: on a normal return the key destructors still run under the host MXCSR. The new check asserts that state.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5563904573 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#pullrequestreview-5563904573). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-18T16:39:54Z. **Review:** COMMENTED --- Re-ran on macOS (x86-64 under Rosetta 2), head `251ef0f28`. Linux and Windows CI are still skipped on this PR. Same setup as my earlier run: Apple M2 Max, macOS 27.2, Apple clang 21, full x86-64 build. Base: `main` d3d8d79c5 with @mugurc's macOS series and the open macOS fixes it uses. - `guest_pthread_frame_chain` now passes (5/5), so the zero record is intact. - `guest_pthread_start` passes (5/5). The new destructor check covers the restore. With only the `ldmxcsr (%rsp)` after the call removed, it fails every run with `Worker thread host MXCSR was not restored upon guest return`. With only the test applied on the base it still fails with `Guest thread MXCSR does not have FTZ and DAZ bits set`. - Non-GPU suite: same failures with and without the PR, all of them macOS gaps that the series does not cover yet. The 51 `pthread`/`thread`/`raise_exception` tests pass on both. This does not address @MarcZX10's last point: on a normal return the key destructors still run under the host MXCSR. The new check asserts that state. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
pushkarreddyy commented 2026-10-18 16:41:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-18T16:41:15Z.


Pushed commit 1f99bd900 addressing the destructor state-consistency:

  1. Retain 0x9fc0 Across Normal-Return Cleanup:

    • In Aps5CallGuestEntry_nid_no_patch, removed the immediate ldmxcsr upon returning from call *%rax.
    • In RunThread, hostMxcsr is saved prior to Aps5CallGuestEntry_nid_no_patch and restored via ldmxcsr immediately after finishThread(self, retval) returns.
    • Consequently, both threadDtors and ThreadLifecycle::RunKeyDtors() execute under guest MXCSR 0x9fc0 whether the thread terminates via normal return or explicit exit (scePthreadExit).
  2. Unified Regression Assertion in PthreadStart.cpp:

    • Updated the destructor hook assertion to confirm (workerMxcsrInDtor.load() & 0x9fc0) == 0x9fc0 across all 10,000 iterations (both explicit exit and normal return paths).
    • Confirmed main thread host MXCSR preservation upon join across the entire run.
  3. Coordination with #7594:

    • Thanks for opening #7594 for the relinker main entry boundary! Updated docs/dev/debt/libkernel.md and the PR description to note the coordination with #7594 for the main ELF thread entry stub.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6252427532 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#issuecomment-6252427532). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-18T16:41:15Z. --- Pushed commit `1f99bd900` addressing the destructor state-consistency: 1. **Retain `0x9fc0` Across Normal-Return Cleanup**: - In `Aps5CallGuestEntry_nid_no_patch`, removed the immediate `ldmxcsr` upon returning from `call *%rax`. - In `RunThread`, `hostMxcsr` is saved prior to `Aps5CallGuestEntry_nid_no_patch` and restored via `ldmxcsr` immediately after `finishThread(self, retval)` returns. - Consequently, both `threadDtors` and `ThreadLifecycle::RunKeyDtors()` execute under guest MXCSR `0x9fc0` whether the thread terminates via normal return or explicit exit (`scePthreadExit`). 2. **Unified Regression Assertion in `PthreadStart.cpp`**: - Updated the destructor hook assertion to confirm `(workerMxcsrInDtor.load() & 0x9fc0) == 0x9fc0` across all 10,000 iterations (both explicit exit and normal return paths). - Confirmed main thread host MXCSR preservation upon join across the entire run. 3. **Coordination with #7594**: - Thanks for opening #7594 for the relinker main entry boundary! Updated `docs/dev/debt/libkernel.md` and the PR description to note the coordination with #7594 for the main ELF thread entry stub.
pushkarreddyy commented 2026-10-18 16:45:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-18T16:45:30Z.


@jotitadev Please note repository review etiquette: formal GitHub Reviews (Submit Review / Review Decisions) are reserved exclusively for AnyPS5 repository maintainers with merge permissions. If you have local reproduction data or technical observations to share, post them strictly as standard PR discussion comments rather than submitting formal reviews.

Regarding the technical point: that state-consistency issue was already addressed in commit 1f99bd900 (pushed right before your review).

Specifically:

  • In Aps5CallGuestEntry_nid_no_patch, the immediate restore instruction upon guest return was removed, keeping guest MXCSR 0x9fc0 active across thread exit.
  • In RunThread, hostMxcsr is recorded prior to entry and restored via ldmxcsr only after finishThread(self, retval) returns.
  • Consequently, both threadDtors and ThreadLifecycle::RunKeyDtors() execute under 0x9fc0 consistently regardless of whether the thread exits via scePthreadExit or normal return.
  • In PthreadStart.cpp, the destructor hook now asserts that (workerMxcsrInDtor.load() & 0x9fc0) == 0x9fc0 across all 10,000 iterations for both paths.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6252471600 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#issuecomment-6252471600). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-18T16:45:30Z. --- @jotitadev Please note repository review etiquette: formal GitHub Reviews (Submit Review / Review Decisions) are reserved exclusively for AnyPS5 repository maintainers with merge permissions. If you have local reproduction data or technical observations to share, post them strictly as standard PR discussion comments rather than submitting formal reviews. Regarding the technical point: that state-consistency issue was already addressed in commit `1f99bd900` (pushed right before your review). Specifically: - In `Aps5CallGuestEntry_nid_no_patch`, the immediate restore instruction upon guest return was removed, keeping guest MXCSR `0x9fc0` active across thread exit. - In `RunThread`, `hostMxcsr` is recorded prior to entry and restored via `ldmxcsr` only after `finishThread(self, retval)` returns. - Consequently, both `threadDtors` and `ThreadLifecycle::RunKeyDtors()` execute under `0x9fc0` consistently regardless of whether the thread exits via `scePthreadExit` or normal return. - In `PthreadStart.cpp`, the destructor hook now asserts that `(workerMxcsrInDtor.load() & 0x9fc0) == 0x9fc0` across all 10,000 iterations for both paths.
oneandonlydean commented 2026-10-18 16:52:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T16:52:22Z.


The stubs look right. One question before merge: with the main thread (here) and created guest threads (#7565) at 0x9fc0, host code called from the guest, and host threads created from a guest thread on Linux (which inherit MXCSR), will run with FTZ/DAZ. Which host work runs in that context, especially the shader recompiler's constant folding and the driver workers? Should host-owned worker threads set the host default MXCSR when they start, so console FP semantics stay on guest code?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6252539780 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#issuecomment-6252539780). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-18T16:52:22Z. --- The stubs look right. One question before merge: with the main thread (here) and created guest threads (#7565) at 0x9fc0, host code called from the guest, and host threads created from a guest thread on Linux (which inherit MXCSR), will run with FTZ/DAZ. Which host work runs in that context, especially the shader recompiler's constant folding and the driver workers? Should host-owned worker threads set the host default MXCSR when they start, so console FP semantics stay on guest code?
pushkarreddyy commented 2026-10-18 17:01:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-18T17:01:18Z.


@oneandonlydean Thanks for the question! Here is an analysis of what host work executes in that context and how host threads are affected:

  1. Host Work Called Directly From Guest Threads:

    • PRX runtime exports & AGC driver: PRX runtime calls (libkernel, libc, libSceAgcDriver, libSceAudioOut2, etc.) and AGC draw/state dispatch run synchronously on the guest thread's stack with the current MXCSR (0x9fc0).
    • Shader recompiler constant folding: ConstantFolder (core/shader/recompiler/Optimization/src/ConstantFolder.cpp) does not perform IEEE floating-point arithmetic folding (FAdd, FMul, FDiv, etc.); it exclusively folds integer math, bitwise operations, bitcasts (BitCastU32F32, BitCastF32U32), and conditional SelectF32 arms. The SRT evaluator (SrtEvaluator.cpp / SrtTape.cpp) does evaluate table arithmetic (ConvertF32U32, FPMul32, FPTrunc32), but this evaluates game-provided shader resource tables where console FTZ/DAZ semantics are actually the desired behavior matching retail hardware.
  2. Host-Owned Worker Threads (Linux clone Inheritance):

    • On Linux, host worker threads spawned from a guest thread (e.g., AGC Submission queue workers, PipelineLibrary / PipelineCache background compilers, and ShaderDiskCache writer) inherit the parent's 0x9fc0 via clone().
    • While most driver tasks involve queue submission, synchronization, SPIR-V translation, and host I/O, host libraries or underlying Vulkan driver internal helper threads could theoretically be sensitive to denormal flushing.
  3. Recommendation:

    • Yes, having host-owned worker threads explicitly initialize the host default MXCSR (0x1f80) at their thread entry is the cleanest architectural boundary. It guarantees that console FP semantics (0x9fc0) remain strictly bound to guest code (and synchronous guest PRX/AGC invocations), while all asynchronous host background workers (AGC submission, shader disk cache, Vulkan compilation workers) run in standard host IEEE-754 mode. We can add _mm_setcsr(0x1f80) at host worker thread entry points in a small follow-up.

Also, whenever you have a moment, could you please take a look at two open PRs that are cleanly rebased on latest origin/main with all pre-flight and CI checks passing green?

  • #6342: feat(libSceVoice): implement sceVoiceEnableChat and sceVoiceDisableChat (pairs with #5817, matching the sceAudioOut2EnableChat model)
  • #6370: feat(libSceSysmodule): register libSceProprietaryVoiceChatHelperPrx module id 0x132 (verified in #5017, resolves startup notice in Discussion #6344)

Thanks!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6252633008 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#issuecomment-6252633008). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-18T17:01:18Z. --- @oneandonlydean Thanks for the question! Here is an analysis of what host work executes in that context and how host threads are affected: 1. **Host Work Called Directly From Guest Threads**: - **PRX runtime exports & AGC driver**: PRX runtime calls (`libkernel`, `libc`, `libSceAgcDriver`, `libSceAudioOut2`, etc.) and AGC draw/state dispatch run synchronously on the guest thread's stack with the current MXCSR (`0x9fc0`). - **Shader recompiler constant folding**: `ConstantFolder` (`core/shader/recompiler/Optimization/src/ConstantFolder.cpp`) does not perform IEEE floating-point arithmetic folding (`FAdd`, `FMul`, `FDiv`, etc.); it exclusively folds integer math, bitwise operations, bitcasts (`BitCastU32F32`, `BitCastF32U32`), and conditional `SelectF32` arms. The SRT evaluator (`SrtEvaluator.cpp` / `SrtTape.cpp`) does evaluate table arithmetic (`ConvertF32U32`, `FPMul32`, `FPTrunc32`), but this evaluates game-provided shader resource tables where console FTZ/DAZ semantics are actually the desired behavior matching retail hardware. 2. **Host-Owned Worker Threads (Linux `clone` Inheritance)**: - On Linux, host worker threads spawned from a guest thread (e.g., AGC `Submission` queue workers, `PipelineLibrary` / `PipelineCache` background compilers, and `ShaderDiskCache` writer) inherit the parent's `0x9fc0` via `clone()`. - While most driver tasks involve queue submission, synchronization, SPIR-V translation, and host I/O, host libraries or underlying Vulkan driver internal helper threads could theoretically be sensitive to denormal flushing. 3. **Recommendation**: - Yes, having host-owned worker threads explicitly initialize the host default MXCSR (`0x1f80`) at their thread entry is the cleanest architectural boundary. It guarantees that console FP semantics (`0x9fc0`) remain strictly bound to guest code (and synchronous guest PRX/AGC invocations), while all asynchronous host background workers (AGC submission, shader disk cache, Vulkan compilation workers) run in standard host IEEE-754 mode. We can add `_mm_setcsr(0x1f80)` at host worker thread entry points in a small follow-up. --- Also, whenever you have a moment, could you please take a look at two open PRs that are cleanly rebased on latest `origin/main` with all pre-flight and CI checks passing green? - **#6342**: `feat(libSceVoice): implement sceVoiceEnableChat and sceVoiceDisableChat` (pairs with #5817, matching the `sceAudioOut2EnableChat` model) - **#6370**: `feat(libSceSysmodule): register libSceProprietaryVoiceChatHelperPrx module id 0x132` (verified in #5017, resolves startup notice in Discussion #6344) Thanks!
MarcZX10 commented 2026-10-18 17:43:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T17:43:55Z.


The host-worker boundary you asked about is now covered in follow-up #7622. Its helper resets MXCSR to 0x1f80 at native std::thread entry across runtime, AGC, shader cache, AvPlayer and libkernel workers, and at the shader-registration pthread trampoline. The focused Linux regression verifies worker MXCSR 0x1f80 while the caller remains at 0x9fc0. This addresses worker inheritance; it does not claim to isolate synchronous host work that runs on a guest thread, which remains a separate boundary question.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253076451 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#issuecomment-6253076451). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T17:43:55Z. --- The host-worker boundary you asked about is now covered in follow-up #7622. Its helper resets MXCSR to 0x1f80 at native std::thread entry across runtime, AGC, shader cache, AvPlayer and libkernel workers, and at the shader-registration pthread trampoline. The focused Linux regression verifies worker MXCSR 0x1f80 while the caller remains at 0x9fc0. This addresses worker inheritance; it does not claim to isolate synchronous host work that runs on a guest thread, which remains a separate boundary question.
pushkarreddyy commented 2026-10-18 18:02:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-18T18:02:12Z.


@MarcZX10 @oneandonlydean Thanks for putting together follow-up #7622!

As noted in #7622's description and test suite, the host-worker MXCSR isolation specifically builds upon the guest caller environment remaining at 0x9fc0. PR #7565 establishes this primary prerequisite—initializing created guest threads to 0x9fc0 at the Aps5CallGuestEntry_nid_no_patch boundary, preserving the sentinel frame-chain record for unwinding, and ensuring guest TSD key destructors in finishThread execute symmetrically under 0x9fc0 across both explicit exit and normal return paths.

Because #7565 provides the foundational guest execution state that #7622's tests verify caller inheritance against, having #7565 take precedence and merge first establishes the core guest baseline cleanly, allowing #7622 to land smoothly on top to handle host background worker defaults.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253262531 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#issuecomment-6253262531). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-18T18:02:12Z. --- @MarcZX10 @oneandonlydean Thanks for putting together follow-up #7622! As noted in #7622's description and test suite, the host-worker MXCSR isolation specifically builds upon the guest caller environment remaining at `0x9fc0`. PR #7565 establishes this primary prerequisite—initializing created guest threads to `0x9fc0` at the `Aps5CallGuestEntry_nid_no_patch` boundary, preserving the sentinel frame-chain record for unwinding, and ensuring guest TSD key destructors in `finishThread` execute symmetrically under `0x9fc0` across both explicit exit and normal return paths. Because #7565 provides the foundational guest execution state that #7622's tests verify caller inheritance against, having #7565 take precedence and merge first establishes the core guest baseline cleanly, allowing #7622 to land smoothly on top to handle host background worker defaults.
MarcZX10 commented 2026-10-18 21:37:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T21:37:53Z.


At the current head (1f99bd9), the restore instruction is present after finishThread, but the committed host-preservation assertion still samples MXCSR only on the test process main thread. The worker dtor check runs before RunThread restores host MXCSR, so it verifies guest cleanup state rather than the worker state after guest return. The implementation looks straightforward; please either add a same-worker observation if practical or narrow the Tested claim to avoid saying this test verifies host preservation.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6255456547 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#issuecomment-6255456547). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T21:37:53Z. --- At the current head (1f99bd9), the restore instruction is present after finishThread, but the committed host-preservation assertion still samples MXCSR only on the test process main thread. The worker dtor check runs before RunThread restores host MXCSR, so it verifies guest cleanup state rather than the worker state after guest return. The implementation looks straightforward; please either add a same-worker observation if practical or narrow the Tested claim to avoid saying this test verifies host preservation.
jotitadev commented 2026-10-19 00:27:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T00:27:00Z.


Linux run of 1f99bd900, since the Linux and Windows CI jobs were skipped on this PR and the existing runs are Windows and macOS.

Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON, full build.
Head 1f99bd900 merged onto main 84c1a4d9a (clean merge).

  • Builds. The 26 pthread tests (ctest -R pthread) pass, including guest_pthread_start and guest_pthread_frame_chain. Non-GPU suite (ctest -E "^agc|gpu|vulkan|video_out"): 739/739, same as main.

  • Without the ldmxcsr (%rsp) in Aps5CallGuestEntry_nid_no_patch, guest_pthread_start fails with Guest thread MXCSR does not have FTZ and DAZ bits set, so the guest-side check works.

  • Without the ldmxcsr %0 restore after finishThread in RunThread, guest_pthread_start still passes 3/3. This is @MarcZX10's point: the host check samples the test's main thread, not the worker.

  • On Linux the restore only runs when the entry returns. scePthreadExit calls finishThread and then longjmps to StartNativeThread, which skips the rest of RunThread, the restore included. I added a thread_local object with a destructor that reads MXCSR to guest_pthread_start (set in CheckThread, 10000 threads, 3 runs):

    exit path MXCSR in the thread_local destructor
    entry returns (6666 threads) host value, all 6666
    scePthreadExit (3334 threads) 0x9fc0, all 3334

    So after an explicit exit (or a cancel, which goes through scePthreadExit), ThreadGuard, ReleaseThread and the native thread's TLS destructors run with FTZ and DAZ set. Restoring in StartNativeThread after the setjmp block would cover both paths. The Windows _endthreadex path looks the same from the source, but I did not run it.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6257070767 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#issuecomment-6257070767). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-19T00:27:00Z. --- Linux run of `1f99bd900`, since the Linux and Windows CI jobs were skipped on this PR and the existing runs are Windows and macOS. Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, `BUILD_TESTING=ON`, full build. Head `1f99bd900` merged onto `main` `84c1a4d9a` (clean merge). - Builds. The 26 pthread tests (`ctest -R pthread`) pass, including `guest_pthread_start` and `guest_pthread_frame_chain`. Non-GPU suite (`ctest -E "^agc|gpu|vulkan|video_out"`): 739/739, same as `main`. - Without the `ldmxcsr (%rsp)` in `Aps5CallGuestEntry_nid_no_patch`, `guest_pthread_start` fails with `Guest thread MXCSR does not have FTZ and DAZ bits set`, so the guest-side check works. - Without the `ldmxcsr %0` restore after `finishThread` in `RunThread`, `guest_pthread_start` still passes 3/3. This is @MarcZX10's point: the host check samples the test's main thread, not the worker. - On Linux the restore only runs when the entry returns. `scePthreadExit` calls `finishThread` and then `longjmp`s to `StartNativeThread`, which skips the rest of `RunThread`, the restore included. I added a `thread_local` object with a destructor that reads MXCSR to `guest_pthread_start` (set in `CheckThread`, 10000 threads, 3 runs): | exit path | MXCSR in the `thread_local` destructor | |---|---| | entry returns (6666 threads) | host value, all 6666 | | `scePthreadExit` (3334 threads) | `0x9fc0`, all 3334 | So after an explicit exit (or a cancel, which goes through `scePthreadExit`), `ThreadGuard`, `ReleaseThread` and the native thread's TLS destructors run with FTZ and DAZ set. Restoring in `StartNativeThread` after the `setjmp` block would cover both paths. The Windows `_endthreadex` path looks the same from the source, but I did not run it. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
pushkarreddyy commented 2026-10-19 05:40:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-19T05:40:46Z.


Pushed commit 8659e828b rebased onto latest origin/main (4ffb0cd12) addressing both points:

  1. Host MXCSR Restoration Across Explicit Exits (scePthreadExit) and Normal Returns (@jotitadev, @MarcZX10):

    • Stored the native caller's hostMxcsr inside PthreadPrivate.
    • In RunThread, finishThread executes all guest TSD destructors under 0x9fc0, followed immediately by asm volatile("ldmxcsr %0" : : "m"(hostMxcsr)).
    • In scePthreadExit, finishThread executes all guest cleanup handlers and key destructors under 0x9fc0, restores host MXCSR via ldmxcsr prior to thread exit/jump, and on Linux the setjmp receiver in StartNativeThread additionally executes ldmxcsr before guard and thread termination.
    • Consequently, both explicit exit (scePthreadExit / cancel) and normal return cleanup run under 0x9fc0, while host worker thread teardown runs under host MXCSR.
  2. Same-Worker MXCSR Observation Across 10,000 Iterations (@MarcZX10):

    • Added a thread_local hook (WorkerTlsHook) in core/libs/tests/PthreadStart.cpp that is activated on each spawned worker. When the native worker thread terminates, its C++ TLS destructor executes on that exact same native thread and reads the thread's final MXCSR.
    • After scePthreadJoin, main() asserts workerMxcsrAfterReturn.load() == hostMxcsrBefore while simultaneously checking (workerMxcsrInDtor.load() & 0x9fc0) == 0x9fc0. This directly observes host MXCSR restoration on the same worker across all 10,000 iterations for both normal return (6,666 iterations) and scePthreadExit (3,334 iterations) paths.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6260515665 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#issuecomment-6260515665). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-19T05:40:46Z. --- Pushed commit `8659e828b` rebased onto latest `origin/main` (`4ffb0cd12`) addressing both points: 1. **Host MXCSR Restoration Across Explicit Exits (`scePthreadExit`) and Normal Returns (@jotitadev, @MarcZX10)**: - Stored the native caller's `hostMxcsr` inside `PthreadPrivate`. - In `RunThread`, `finishThread` executes all guest TSD destructors under `0x9fc0`, followed immediately by `asm volatile("ldmxcsr %0" : : "m"(hostMxcsr))`. - In `scePthreadExit`, `finishThread` executes all guest cleanup handlers and key destructors under `0x9fc0`, restores host MXCSR via `ldmxcsr` prior to thread exit/jump, and on Linux the `setjmp` receiver in `StartNativeThread` additionally executes `ldmxcsr` before `guard` and thread termination. - Consequently, both explicit exit (`scePthreadExit` / cancel) and normal return cleanup run under `0x9fc0`, while host worker thread teardown runs under host MXCSR. 2. **Same-Worker MXCSR Observation Across 10,000 Iterations (@MarcZX10)**: - Added a `thread_local` hook (`WorkerTlsHook`) in `core/libs/tests/PthreadStart.cpp` that is activated on each spawned worker. When the native worker thread terminates, its C++ TLS destructor executes on that exact same native thread and reads the thread's final MXCSR. - After `scePthreadJoin`, `main()` asserts `workerMxcsrAfterReturn.load() == hostMxcsrBefore` while simultaneously checking `(workerMxcsrInDtor.load() & 0x9fc0) == 0x9fc0`. This directly observes host MXCSR restoration on the same worker across all 10,000 iterations for both normal return (6,666 iterations) and `scePthreadExit` (3,334 iterations) paths.
jotitadev commented 2026-10-19 08:12:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T08:12:41Z.


Linux rerun of 8659e828b with the same thread_local probe as my earlier comment on 1f99bd900.

Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON, full build. Head 8659e828b merged onto main 6b8228b2b (clean merge).

  • Builds. The 27 pthread tests pass and the non-GPU suite is 766/766, same as main.
  • Probe (10000 threads, 3 runs): MXCSR in the native thread's thread_local destructor is now the host value on both paths, 6666 of 6666 after a return and 3334 of 3334 after scePthreadExit. On 1f99bd900 the second was 0x9fc0 in all 3334.
  • The new WorkerTlsHook check catches it. Without the two ldmxcsr of self->hostMxcsr (StartNativeThread and scePthreadExit), guest_pthread_start fails 3 of 3 with Worker thread host MXCSR was not restored upon guest return. Without only the restore in RunThread it still passes 3 of 3, because on Linux the one in StartNativeThread runs after RunThread returns as well. That makes the RunThread restore redundant on Linux, though it may still matter for the Windows path, which I didn't run.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6262730694 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#issuecomment-6262730694). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-19T08:12:41Z. --- Linux rerun of `8659e828b` with the same `thread_local` probe as my earlier comment on `1f99bd900`. Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, `BUILD_TESTING=ON`, full build. Head `8659e828b` merged onto `main` `6b8228b2b` (clean merge). - Builds. The 27 pthread tests pass and the non-GPU suite is 766/766, same as `main`. - Probe (10000 threads, 3 runs): MXCSR in the native thread's `thread_local` destructor is now the host value on both paths, 6666 of 6666 after a return and 3334 of 3334 after `scePthreadExit`. On `1f99bd900` the second was `0x9fc0` in all 3334. - The new `WorkerTlsHook` check catches it. Without the two `ldmxcsr` of `self->hostMxcsr` (`StartNativeThread` and `scePthreadExit`), `guest_pthread_start` fails 3 of 3 with `Worker thread host MXCSR was not restored upon guest return`. Without only the restore in `RunThread` it still passes 3 of 3, because on Linux the one in `StartNativeThread` runs after `RunThread` returns as well. That makes the `RunThread` restore redundant on Linux, though it may still matter for the Windows path, which I didn't run. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
pushkarreddyy commented 2026-10-19 14:02:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-19T14:02:27Z.


@jotitadev Thank you for running the 10,000-thread Linux rerun and probe! Really appreciate the detailed verification confirming host MXCSR restoration on both the normal return (6,666/6,666) and scePthreadExit (3,334/3,334) paths, as well as the WorkerTlsHook test coverage.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6269070789 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#issuecomment-6269070789). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-19T14:02:27Z. --- @jotitadev Thank you for running the 10,000-thread Linux rerun and probe! Really appreciate the detailed verification confirming host MXCSR restoration on both the normal return (6,666/6,666) and `scePthreadExit` (3,334/3,334) paths, as well as the `WorkerTlsHook` test coverage.
adriadam10 commented 2026-10-19 16:29:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T16:29:47Z.

Review: CHANGES_REQUESTED


Thanks for the rebase and the tests. One issue left:

  • core/libs/prx/libkernel/Pthread/include/Pthread.hpp:154 / Thread.cpp:999: hostMxcsr defaults to 0 and only RunThread (Thread.cpp:669) sets it, but scePthreadExit runs ldmxcsr self->hostMxcsr for any registered thread (e.g. threads adopted through scePthreadSelf on Windows, which never pass through RunThread). Loading 0 unmasks every FP exception and sets different rounding, so any later FP op in that thread's exit path can fault. Capture the host value where the thread is registered, or skip the ldmxcsr when it was never captured (and default to 0x1f80 rather than 0), and add a case that calls scePthreadExit from a thread that did not go through RunThread if one exists on a supported platform.

The rest (stack slot below %rbp, restore after finishThread, test pinning guest and host values) looks right.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5574602403 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#pullrequestreview-5574602403). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T16:29:47Z. **Review:** CHANGES_REQUESTED --- Thanks for the rebase and the tests. One issue left: - `core/libs/prx/libkernel/Pthread/include/Pthread.hpp:154` / `Thread.cpp:999`: `hostMxcsr` defaults to `0` and only `RunThread` (`Thread.cpp:669`) sets it, but `scePthreadExit` runs `ldmxcsr self->hostMxcsr` for any registered thread (e.g. threads adopted through `scePthreadSelf` on Windows, which never pass through `RunThread`). Loading `0` unmasks every FP exception and sets different rounding, so any later FP op in that thread's exit path can fault. Capture the host value where the thread is registered, or skip the `ldmxcsr` when it was never captured (and default to `0x1f80` rather than `0`), and add a case that calls `scePthreadExit` from a thread that did not go through `RunThread` if one exists on a supported platform. The rest (stack slot below `%rbp`, restore after `finishThread`, test pinning guest and host values) looks right.
pushkarreddyy commented 2026-10-19 17:05:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-19T17:05:27Z.


@adriadam10 Thanks for the review!

Pushed commit e6d73a3e8 rebased onto latest origin/main (00d7e611e) addressing both points:

  1. Default hostMxcsr & Adoption Capture:

    • Initialized hostMxcsr in PthreadPrivate to 0x1f80 (standard x86_64 host default with all FP exceptions masked and round-to-nearest) rather than 0.
    • Captured the active thread's host MXCSR via stmxcsr during thread adoption in scePthreadSelf() across both Windows and non-Windows paths so adopted threads retain their native caller's exact FP environment.
  2. Adopted Thread scePthreadExit Test Case:

    • Added an explicit test in core/libs/tests/PthreadStart.cpp: spawns a native std::thread, adopts it as guest state via scePthreadSelf(), enables workerTlsHook, and executes scePthreadExit(nullptr).
    • Asserts that upon thread completion, the native thread's TLS destructor observes that the thread's host MXCSR remained intact and matches hostMxcsrBefore.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6272731882 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#issuecomment-6272731882). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-19T17:05:27Z. --- @adriadam10 Thanks for the review! Pushed commit `e6d73a3e8` rebased onto latest `origin/main` (`00d7e611e`) addressing both points: 1. **Default `hostMxcsr` & Adoption Capture**: - Initialized `hostMxcsr` in `PthreadPrivate` to `0x1f80` (standard x86_64 host default with all FP exceptions masked and round-to-nearest) rather than `0`. - Captured the active thread's host MXCSR via `stmxcsr` during thread adoption in `scePthreadSelf()` across both Windows and non-Windows paths so adopted threads retain their native caller's exact FP environment. 2. **Adopted Thread `scePthreadExit` Test Case**: - Added an explicit test in `core/libs/tests/PthreadStart.cpp`: spawns a native `std::thread`, adopts it as guest state via `scePthreadSelf()`, enables `workerTlsHook`, and executes `scePthreadExit(nullptr)`. - Asserts that upon thread completion, the native thread's TLS destructor observes that the thread's host MXCSR remained intact and matches `hostMxcsrBefore`.
MarcZX10 commented 2026-10-21 01:39:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T01:39:51Z.

Review: APPROVED


Reviewed exact head e6d73a3e8bd3cc7acc517ff8c5a9957224f3008c in response to the review request. The earlier adopted-thread issue is addressed: hostMxcsr has a safe default and is captured during adoption on both platform branches; the new adopted native-thread exit case checks restoration through a same-thread TLS destructor. Guest MXCSR remains active through finishThread on both return and explicit-exit paths, and the assembly scratch slot remains below the frame-chain sentinel. The previous frame-chain and host-restore concerns have independent Rosetta/Linux test reports; current conventions pass. Hosted Linux/Windows jobs are skipped by path policy. No remaining blocking issue found.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5593941175 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#pullrequestreview-5593941175). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T01:39:51Z. **Review:** APPROVED --- Reviewed exact head `e6d73a3e8bd3cc7acc517ff8c5a9957224f3008c` in response to the review request. The earlier adopted-thread issue is addressed: `hostMxcsr` has a safe default and is captured during adoption on both platform branches; the new adopted native-thread exit case checks restoration through a same-thread TLS destructor. Guest MXCSR remains active through `finishThread` on both return and explicit-exit paths, and the assembly scratch slot remains below the frame-chain sentinel. The previous frame-chain and host-restore concerns have independent Rosetta/Linux test reports; current conventions pass. Hosted Linux/Windows jobs are skipped by path policy. No remaining blocking issue found.
oneandonlydean commented 2026-10-21 08:26:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T08:26:47Z.


Picking this up for a joint test: #7622 is written to complete this PR together with #7594, so we need to game-test all of them on one tree before any of them merges. We'll review, test and merge under the normal process. Your comments and review are still very welcome, @adriadam10.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6311535752 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#issuecomment-6311535752). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T08:26:47Z. --- Picking this up for a joint test: #7622 is written to complete this PR together with #7594, so we need to game-test all of them on one tree before any of them merges. We'll review, test and merge under the normal process. Your comments and review are still very welcome, @adriadam10.
MarcZX10 commented 2026-10-29 02:22:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T02:22:47Z.

Review: CHANGES_REQUESTED


Re-checked — new head, changes requested

The new test and implementation assume a worker's host MXCSR is always 0x1f80, but POSIX threads inherit the creator's floating-point environment; a local reproduction confirms the worker inherits 0x9fc0 when created from that state.

What I ran

Reviewed PR head 6575915344cf607e3937de9a34341de68a0b869e against current main 3a2b919816; the merge preview is clean. Environment: Linux x86_64, kernel 6.1.0-54-amd64, GCC 12.2.0.

Commands:

git diff --check upstream/main...refs/remotes/review/7565
python3 tools/check_conventions.py --base upstream/main --head refs/remotes/review/7565
git merge-tree --write-tree upstream/main refs/remotes/review/7565

For the host-thread inheritance check, I compiled and ran this minimal probe:

cat > /tmp/mxcsr-inherit-probe.cpp <<'EOF'
#include <cstdint>
#include <cstdio>
#include <thread>
static std::uint32_t readMxcsr() { std::uint32_t value = 0; asm volatile("stmxcsr %0" : "=m"(value)); return value; }
static void writeMxcsr(std::uint32_t value) { asm volatile("ldmxcsr %0" : : "m"(value)); }
int main() {
  const auto before = readMxcsr();
  const std::uint32_t guest = 0x9fc0;
  writeMxcsr(guest);
  std::uint32_t child = 0;
  std::thread worker([&] { child = readMxcsr(); });
  worker.join();
  writeMxcsr(before);
  std::printf("parent_before=0x%04x child_initial=0x%04x restored_parent=0x%04x\\n", before, child, readMxcsr());
}
EOF
g++ -std=c++20 -O2 -pthread /tmp/mxcsr-inherit-probe.cpp -o /tmp/mxcsr-inherit-probe
/tmp/mxcsr-inherit-probe

Results

Check Result
Merge preview with current main Clean
Diff check Passed
Conventions Passed
Native thread inheritance probe Child inherited 0x9fc0 from its creator
PR's PthreadStart test Not run locally
Hosted Windows job Pending at review time
Other hosted product jobs Skipped
Raw output
Merge preview:
ee60de153f658d996a4b0fbaf36678eba5adb9cf

Diff check:
(no output; exit status 0)

Convention checker:
All conventions checks passed.

MXCSR probe:
parent_before=0x1f80 child_initial=0x9fc0 restored_parent=0x1f80

Hosted checks:
windows pending
linux skipping
register-context skipping
relinker skipping
relinker-asan skipping
write-watch skipping
conventions pass
eligibility pass
labels pass
report pass

Negative control

Assertion Change Result
A newly created POSIX thread inherits its creator's floating-point environment Set the creator's MXCSR to 0x9fc0 before starting std::thread Confirmed: the child initially read 0x9fc0; this was a native-thread probe, not a mutation of the PR test

The PR test currently checks only that the worker MXCSR after guest execution is 0x1f80; it does not record the worker's incoming MXCSR before guest entry, so it cannot distinguish the inherited value from the hard-coded restoration value.

Findings

Blocking

  • Thread.cpp assigns hostMxcsr = 0x1f80 immediately before guest entry and restores that constant after guest execution. On POSIX, pthread_create inherits the creator's floating-point environment. When a guest thread creates another guest thread while its MXCSR is 0x9fc0, the new native worker starts with inherited 0x9fc0, but this code later changes it to 0x1f80. The added test sets the creator to 0x9fc0 and asserts that the worker ends at 0x1f80, so it codifies the clobber instead of checking restoration of the worker's incoming state. Please capture the actual worker MXCSR before guest setup, restore that value on return/exit, and update the test to verify preservation of the captured incoming state.

Non-blocking

No other blocking issue found in the reviewed diff. The branch merges cleanly with current main; conventions pass. The hosted Windows job was still running, so I have not treated its build or tests as passing.

Sources

Not verified

I did not build or run the PR's PthreadStart test locally, and did not test Windows or console behavior. The hosted Windows job was pending; the hosted Linux and specialized jobs were skipped. The native probe verifies POSIX thread inheritance, not the full emulator test path.

To get this to a good state

Capture each worker's actual incoming MXCSR before guest setup, restore that value on normal return and explicit exit, and update the test so it checks the captured incoming value rather than assuming 0x1f80. Please rerun PthreadStart on Linux and Windows and attach the output for the resulting head. I will rerun the merge, diff, convention, and inheritance checks on that head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5692117606 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#pullrequestreview-5692117606). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T02:22:47Z. **Review:** CHANGES_REQUESTED --- # Re-checked — new head, changes requested The new test and implementation assume a worker's host MXCSR is always 0x1f80, but POSIX threads inherit the creator's floating-point environment; a local reproduction confirms the worker inherits 0x9fc0 when created from that state. ## What I ran Reviewed PR head 6575915344cf607e3937de9a34341de68a0b869e against current main 3a2b91981651569163768854a1fcdc7193b6667b; the merge preview is clean. Environment: Linux x86_64, kernel 6.1.0-54-amd64, GCC 12.2.0. Commands: ~~~sh git diff --check upstream/main...refs/remotes/review/7565 python3 tools/check_conventions.py --base upstream/main --head refs/remotes/review/7565 git merge-tree --write-tree upstream/main refs/remotes/review/7565 ~~~ For the host-thread inheritance check, I compiled and ran this minimal probe: ~~~sh cat > /tmp/mxcsr-inherit-probe.cpp <<'EOF' #include <cstdint> #include <cstdio> #include <thread> static std::uint32_t readMxcsr() { std::uint32_t value = 0; asm volatile("stmxcsr %0" : "=m"(value)); return value; } static void writeMxcsr(std::uint32_t value) { asm volatile("ldmxcsr %0" : : "m"(value)); } int main() { const auto before = readMxcsr(); const std::uint32_t guest = 0x9fc0; writeMxcsr(guest); std::uint32_t child = 0; std::thread worker([&] { child = readMxcsr(); }); worker.join(); writeMxcsr(before); std::printf("parent_before=0x%04x child_initial=0x%04x restored_parent=0x%04x\\n", before, child, readMxcsr()); } EOF g++ -std=c++20 -O2 -pthread /tmp/mxcsr-inherit-probe.cpp -o /tmp/mxcsr-inherit-probe /tmp/mxcsr-inherit-probe ~~~ ## Results | Check | Result | |---|---| | Merge preview with current main | Clean | | Diff check | Passed | | Conventions | Passed | | Native thread inheritance probe | Child inherited 0x9fc0 from its creator | | PR's PthreadStart test | Not run locally | | Hosted Windows job | Pending at review time | | Other hosted product jobs | Skipped | <details><summary>Raw output</summary> ~~~text Merge preview: ee60de153f658d996a4b0fbaf36678eba5adb9cf Diff check: (no output; exit status 0) Convention checker: All conventions checks passed. MXCSR probe: parent_before=0x1f80 child_initial=0x9fc0 restored_parent=0x1f80 Hosted checks: windows pending linux skipping register-context skipping relinker skipping relinker-asan skipping write-watch skipping conventions pass eligibility pass labels pass report pass ~~~ </details> ## Negative control | Assertion | Change | Result | |---|---|---| | A newly created POSIX thread inherits its creator's floating-point environment | Set the creator's MXCSR to 0x9fc0 before starting std::thread | Confirmed: the child initially read 0x9fc0; this was a native-thread probe, not a mutation of the PR test | The PR test currently checks only that the worker MXCSR after guest execution is 0x1f80; it does not record the worker's incoming MXCSR before guest entry, so it cannot distinguish the inherited value from the hard-coded restoration value. ## Findings ### Blocking - Thread.cpp assigns hostMxcsr = 0x1f80 immediately before guest entry and restores that constant after guest execution. On POSIX, pthread_create inherits the creator's floating-point environment. When a guest thread creates another guest thread while its MXCSR is 0x9fc0, the new native worker starts with inherited 0x9fc0, but this code later changes it to 0x1f80. The added test sets the creator to 0x9fc0 and asserts that the worker ends at 0x1f80, so it codifies the clobber instead of checking restoration of the worker's incoming state. Please capture the actual worker MXCSR before guest setup, restore that value on return/exit, and update the test to verify preservation of the captured incoming state. ### Non-blocking No other blocking issue found in the reviewed diff. The branch merges cleanly with current main; conventions pass. The hosted Windows job was still running, so I have not treated its build or tests as passing. ## Sources - [POSIX pthread_create specification](https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_create.html) states that the new thread inherits the creator's floating-point environment. - [PR Thread.cpp at reviewed head](https://github.com/boykopovar/AnyPS5/blob/6575915344cf607e3937de9a34341de68a0b869e/core/libs/prx/libkernel/Pthread/src/Thread.cpp#L811-L814) sets and later restores the fixed MXCSR value. - [PR PthreadStart.cpp at reviewed head](https://github.com/boykopovar/AnyPS5/blob/6575915344cf607e3937de9a34341de68a0b869e/core/libs/tests/PthreadStart.cpp#L124-L136) sets the creator to 0x9fc0 and expects the worker to finish at 0x1f80. - [PR StartNativeThread at reviewed head](https://github.com/boykopovar/AnyPS5/blob/6575915344cf607e3937de9a34341de68a0b869e/core/libs/prx/libkernel/Pthread/src/Thread.cpp#L925-L963) shows the POSIX worker entry and restoration path. ## Not verified I did not build or run the PR's PthreadStart test locally, and did not test Windows or console behavior. The hosted Windows job was pending; the hosted Linux and specialized jobs were skipped. The native probe verifies POSIX thread inheritance, not the full emulator test path. ## To get this to a good state Capture each worker's actual incoming MXCSR before guest setup, restore that value on normal return and explicit exit, and update the test so it checks the captured incoming value rather than assuming 0x1f80. Please rerun PthreadStart on Linux and Windows and attach the output for the resulting head. I will rerun the merge, diff, convention, and inheritance checks on that head.
MarcZX10 commented 2026-10-29 03:06:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T03:06:32Z.

Review: APPROVED


Re-checked — approved

The follow-up captures the native worker’s incoming MXCSR before guest setup and restores that value after guest cleanup on both normal return and explicit exit. This addresses the portability finding from my previous review. I approve exact head f0c460b9ba3d4c69d7a96d75b78e0fb1094d13e8.

What I ran

  • Reviewed the exact diff against current main.
  • Ran python3 tools/check_conventions.py --base upstream/main --head HEAD.
  • Ran git diff --check upstream/main...HEAD.
  • Ran git merge-tree --write-tree upstream/main HEAD.
  • Refreshed hosted checks and inspected the regression test and author’s current-head report.

Results

Check Result
Conventions Passed
Diff whitespace Passed
Merge preview Clean; tree 8883aea222b18ab44c508e6fa4c4867e7b35c9b2
Hosted Windows build Passed
Hosted conventions, eligibility, labels, and report Passed
Hosted Linux and specialized jobs Skipped
Author-reported focused regression 10,000 thread starts across Linux and Windows, including normal return and scePthreadExit paths

The current code captures MXCSR at native-thread entry, sets the guest value at guest entry, and restores the captured host value after finishThread. The explicit-exit path restores before native thread termination or the POSIX exit jump. Adopted threads also record their current host value. The regression checks that POSIX workers inherit the creator’s MXCSR and that native TLS destruction observes the restored value.

Negative control

No separate mutation run was reported or independently run in this review. The test now explicitly checks the POSIX inherited value that exposed the previous hard-coded restore behavior.

Findings

Blocking

None found at this head.

Non-blocking

  • The 10,000-iteration Linux and Windows test results are from the author’s report; I did not rerun them locally.
  • Linux product and specialized hosted jobs were skipped, so the hosted result is not a Linux runtime test.

Sources

All code links point to the reviewed commit f0c460b9ba3d4c69d7a96d75b78e0fb1094d13e8.

Not verified

  • I did not run the focused C++ test locally.
  • I did not test console behavior.
  • Linux product and specialized hosted jobs were skipped.

To get to a good state

No further changes are required for the findings in this review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5692376846 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#pullrequestreview-5692376846). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T03:06:32Z. **Review:** APPROVED --- # Re-checked — approved The follow-up captures the native worker’s incoming MXCSR before guest setup and restores that value after guest cleanup on both normal return and explicit exit. This addresses the portability finding from my previous review. I approve exact head `f0c460b9ba3d4c69d7a96d75b78e0fb1094d13e8`. ## What I ran - Reviewed the exact diff against current `main`. - Ran `python3 tools/check_conventions.py --base upstream/main --head HEAD`. - Ran `git diff --check upstream/main...HEAD`. - Ran `git merge-tree --write-tree upstream/main HEAD`. - Refreshed hosted checks and inspected the regression test and author’s current-head report. ## Results | Check | Result | |---|---| | Conventions | Passed | | Diff whitespace | Passed | | Merge preview | Clean; tree `8883aea222b18ab44c508e6fa4c4867e7b35c9b2` | | Hosted Windows build | Passed | | Hosted conventions, eligibility, labels, and report | Passed | | Hosted Linux and specialized jobs | Skipped | | Author-reported focused regression | 10,000 thread starts across Linux and Windows, including normal return and `scePthreadExit` paths | The current code captures MXCSR at native-thread entry, sets the guest value at guest entry, and restores the captured host value after `finishThread`. The explicit-exit path restores before native thread termination or the POSIX exit jump. Adopted threads also record their current host value. The regression checks that POSIX workers inherit the creator’s MXCSR and that native TLS destruction observes the restored value. ## Negative control No separate mutation run was reported or independently run in this review. The test now explicitly checks the POSIX inherited value that exposed the previous hard-coded restore behavior. ## Findings ### Blocking None found at this head. ### Non-blocking - The 10,000-iteration Linux and Windows test results are from the author’s report; I did not rerun them locally. - Linux product and specialized hosted jobs were skipped, so the hosted result is not a Linux runtime test. ## Sources All code links point to the reviewed commit `f0c460b9ba3d4c69d7a96d75b78e0fb1094d13e8`. - [Guest entry MXCSR setup and normal-return restoration](https://github.com/boykopovar/AnyPS5/blob/f0c460b9ba3d4c69d7a96d75b78e0fb1094d13e8/core/libs/prx/libkernel/Pthread/src/Thread.cpp#L770-L814) - [Native worker capture and restore](https://github.com/boykopovar/AnyPS5/blob/f0c460b9ba3d4c69d7a96d75b78e0fb1094d13e8/core/libs/prx/libkernel/Pthread/src/Thread.cpp#L888-L968) - [Explicit exit and adopted-thread capture](https://github.com/boykopovar/AnyPS5/blob/f0c460b9ba3d4c69d7a96d75b78e0fb1094d13e8/core/libs/prx/libkernel/Pthread/src/Thread.cpp#L1166-L1209) - [Regression test](https://github.com/boykopovar/AnyPS5/blob/f0c460b9ba3d4c69d7a96d75b78e0fb1094d13e8/core/libs/tests/PthreadStart.cpp#L1-L190) - [Author’s follow-up and test description](https://github.com/boykopovar/AnyPS5/pull/7565#issuecomment-6486213445) ## Not verified - I did not run the focused C++ test locally. - I did not test console behavior. - Linux product and specialized hosted jobs were skipped. ## To get to a good state No further changes are required for the findings in this review.
XairRrR commented 2026-10-29 03:13:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T03:13:55Z.

Review: APPROVED


Reviewed — approved

On Linux the change merges cleanly, builds and passes the pthread, TLS and exception tests. Reverting the production code makes guest_pthread_start fail, and so does removing either the worker MXCSR capture or the restores.

What I ran

  • PR head: f0c460b9ba3d4c69d7a96d75b78e0fb1094d13e8
  • main: 3a2b91981651569163768854a1fcdc7193b6667b
  • Merge of the head into main in a clean worktree (--no-ff): no conflicts.
  • Machine: Arch Linux 7.2.11-zen, GCC 16.2.1, Release, Ninja, BUILD_TESTING=ON, Intel Core i9-14900KF.
git merge --no-ff --no-edit refs/review/7565          # onto origin/main
git diff --check origin/main...refs/review/7565
python3 tools/check_conventions.py --base origin/main
cmake --build build -j10 --target libs guest_pthread_start_tests
cmake --build build -j10
ctest --test-dir build -j4 --output-on-failure \
  -R "pthread|thread_self|thread_atexit|thread_callback|kernel_sys_thread|libc_threads|raise_exception|cancel|thread_local|tls|exception"
for i in 1 2 3 4 5; do ctest --test-dir build --output-on-failure -R "^guest_pthread_start$|^guest_pthread_frame_chain$"; done
# negative control and mutations: see below

Results

Check Result
Merge into main Clean
git diff --check No output
check_conventions.py All conventions checks passed
Build (libs and the full tree) OK, no errors
172 thread, TLS, cancellation and exception tests 172/172 passed
guest_pthread_start and guest_pthread_frame_chain, 5 runs 5/5 passed each; guest_pthread_start takes about 0.5 s
Negative control (only Thread.cpp reverted) Fails 3/3
Mutation: POSIX StartNativeThread capture removed Fails 3/3
Mutation: all three ldmxcsr self->hostMxcsr restores removed Fails 3/3
guest_pthread_start on the merged tree
2432: PASS: 10000 thread starts, committed stacks, large frames, explicit exits and joins; 100 detach checks; adopted thread exit
1/1 Test #2432: guest_pthread_start ..............   Passed    0.40 sec
100% tests passed out of 1
Focused set (tail)
100% tests passed out of 172
Total Test time (real) =   9.29 sec

Negative control

The test reads the new PthreadPrivate::hostMxcsr field, so it does not compile against main's Pthread.hpp. I kept the PR's header, which only adds the field, and restored core/libs/prx/libkernel/Pthread/src/Thread.cpp from origin/main. guest_pthread_start then failed 3 of 3 runs:

terminate called after throwing an instance of 'std::runtime_error'
  what():  Guest thread MXCSR does not have FTZ and DAZ bits set

I also ran two mutations on the merged tree:

  • Deleting self->hostMxcsr = incomingMxcsr; in the POSIX StartNativeThread (Thread.cpp:932) failed 3 of 3 with Worker incoming MXCSR did not match creator MXCSR on POSIX. The test therefore covers the inheritance issue from the previous round.
  • Deleting the three restores (Thread.cpp:812, :967, :1173) failed 3 of 3 with Worker thread host MXCSR was not restored upon guest return.

I restored the PR files, rebuilt the tree and confirmed the test passes again.

Findings

Blocking

None.

I checked the following on the code:

  • Aps5CallGuestEntry_nid_no_patch keeps the zero frame record at (%rbp).
  • %rsp is 16-byte aligned at call *%rax: 8 + 3×8 + 16 bytes are pushed or allocated.
  • The CFA offsets balance (+16, then −32, which also undoes the two push $0).
  • self is still alive at every ldmxcsr self->hostMxcsr, because the thread drops its own reference later in ReleaseThread or ThreadGuard.
  • The worker's TLS-destructor value cannot be read early: scePthreadJoin calls pthread_join or WaitForSingleObject before the test reads it.

Non-blocking

  1. Unblocks points at this PR, not the title's discussion. The line reads Unblocks: Uncharted: Legacy of Thieves Collection (PPSA05684) #7565. CONTRIBUTING.md asks for the title ID and its Game bring-up discussion, which for PPSA05684 is #4001. Suggested line: Unblocks: PPSA05684 #4001.
  2. The test never clears its probe values (core/libs/tests/PthreadStart.cpp:11-12, checked at :107, :109, :141, :160, :178). workerMxcsrInDtor and workerMxcsrAfterReturn are written only by the hooks and never reset. In the 10,000-iteration loop every iteration stores the same value, so an iteration where the destructor or TLS hook did not run would pass on the previous value. On Windows, where a new thread starts at its default MXCSR rather than inheriting the creator's, the adopted-thread case (:178) could also pass on the value left by the previous case. Storing 0 in both atomics before each scePthreadCreate, and before starting nativeWorker, makes each check observe its own thread.
  3. Possible follow-up, not introduced here: guest exception handlers. CallHandler (core/libs/prx/libkernel/System/src/Exception.cpp:186-190) calls the guest handler inside the host signal handler. On Linux, signal handlers start with the kernel's default FP state (MXCSR 0x1f80), so a guest handler on a created guest thread runs without FTZ/DAZ, while its interrupted context holds 0x9fc0. I did not measure this, and the console's MXCSR inside an exception handler is unmeasured as far as I know. It could be a line in the new debt entry or a separate issue.

Not verified

  • Windows. The _beginthreadex path, _endthreadex in scePthreadExit, and Windows adoption in scePthreadSelf were not built or run here. The PR's Windows results are the author's.
  • macOS: not built.
  • Console behaviour. The 0x9fc0 initial value rests on the firmware 12.70 measurement cited in the PR. I did not check whether a console thread inherits a creator's changed MXCSR or always starts at 0x9fc0, which is what this PR does.
  • Title behaviour: no game was run for this review.
  • The interaction with #7594 (main thread) and #7622 (host workers) was not tested on a combined tree.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5692420427 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#pullrequestreview-5692420427). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-29T03:13:55Z. **Review:** APPROVED --- # Reviewed — approved On Linux the change merges cleanly, builds and passes the pthread, TLS and exception tests. Reverting the production code makes `guest_pthread_start` fail, and so does removing either the worker MXCSR capture or the restores. ## What I ran - PR head: `f0c460b9ba3d4c69d7a96d75b78e0fb1094d13e8` - `main`: `3a2b91981651569163768854a1fcdc7193b6667b` - Merge of the head into `main` in a clean worktree (`--no-ff`): no conflicts. - Machine: Arch Linux 7.2.11-zen, GCC 16.2.1, Release, Ninja, `BUILD_TESTING=ON`, Intel Core i9-14900KF. ```sh git merge --no-ff --no-edit refs/review/7565 # onto origin/main git diff --check origin/main...refs/review/7565 python3 tools/check_conventions.py --base origin/main cmake --build build -j10 --target libs guest_pthread_start_tests cmake --build build -j10 ctest --test-dir build -j4 --output-on-failure \ -R "pthread|thread_self|thread_atexit|thread_callback|kernel_sys_thread|libc_threads|raise_exception|cancel|thread_local|tls|exception" for i in 1 2 3 4 5; do ctest --test-dir build --output-on-failure -R "^guest_pthread_start$|^guest_pthread_frame_chain$"; done # negative control and mutations: see below ``` ## Results | Check | Result | |---|---| | Merge into `main` | Clean | | `git diff --check` | No output | | `check_conventions.py` | All conventions checks passed | | Build (`libs` and the full tree) | OK, no errors | | 172 thread, TLS, cancellation and exception tests | 172/172 passed | | `guest_pthread_start` and `guest_pthread_frame_chain`, 5 runs | 5/5 passed each; `guest_pthread_start` takes about 0.5 s | | Negative control (only `Thread.cpp` reverted) | Fails 3/3 | | Mutation: POSIX `StartNativeThread` capture removed | Fails 3/3 | | Mutation: all three `ldmxcsr self->hostMxcsr` restores removed | Fails 3/3 | <details><summary>guest_pthread_start on the merged tree</summary> ```text 2432: PASS: 10000 thread starts, committed stacks, large frames, explicit exits and joins; 100 detach checks; adopted thread exit 1/1 Test #2432: guest_pthread_start .............. Passed 0.40 sec 100% tests passed out of 1 ``` </details> <details><summary>Focused set (tail)</summary> ```text 100% tests passed out of 172 Total Test time (real) = 9.29 sec ``` </details> ## Negative control The test reads the new `PthreadPrivate::hostMxcsr` field, so it does not compile against `main`'s `Pthread.hpp`. I kept the PR's header, which only adds the field, and restored `core/libs/prx/libkernel/Pthread/src/Thread.cpp` from `origin/main`. `guest_pthread_start` then failed 3 of 3 runs: ```text terminate called after throwing an instance of 'std::runtime_error' what(): Guest thread MXCSR does not have FTZ and DAZ bits set ``` I also ran two mutations on the merged tree: - Deleting `self->hostMxcsr = incomingMxcsr;` in the POSIX `StartNativeThread` (`Thread.cpp:932`) failed 3 of 3 with `Worker incoming MXCSR did not match creator MXCSR on POSIX`. The test therefore covers the inheritance issue from the previous round. - Deleting the three restores (`Thread.cpp:812`, `:967`, `:1173`) failed 3 of 3 with `Worker thread host MXCSR was not restored upon guest return`. I restored the PR files, rebuilt the tree and confirmed the test passes again. ## Findings ### Blocking None. I checked the following on the code: - `Aps5CallGuestEntry_nid_no_patch` keeps the zero frame record at `(%rbp)`. - `%rsp` is 16-byte aligned at `call *%rax`: 8 + 3×8 + 16 bytes are pushed or allocated. - The CFA offsets balance (+16, then −32, which also undoes the two `push $0`). - `self` is still alive at every `ldmxcsr self->hostMxcsr`, because the thread drops its own reference later in `ReleaseThread` or `ThreadGuard`. - The worker's TLS-destructor value cannot be read early: `scePthreadJoin` calls `pthread_join` or `WaitForSingleObject` before the test reads it. ### Non-blocking 1. **`Unblocks` points at this PR, not the title's discussion.** The line reads `Unblocks: Uncharted: Legacy of Thieves Collection (PPSA05684) #7565`. CONTRIBUTING.md asks for the title ID and its Game bring-up discussion, which for PPSA05684 is #4001. Suggested line: `Unblocks: PPSA05684 #4001`. 2. **The test never clears its probe values** (`core/libs/tests/PthreadStart.cpp:11-12`, checked at `:107`, `:109`, `:141`, `:160`, `:178`). `workerMxcsrInDtor` and `workerMxcsrAfterReturn` are written only by the hooks and never reset. In the 10,000-iteration loop every iteration stores the same value, so an iteration where the destructor or TLS hook did not run would pass on the previous value. On Windows, where a new thread starts at its default MXCSR rather than inheriting the creator's, the adopted-thread case (`:178`) could also pass on the value left by the previous case. Storing `0` in both atomics before each `scePthreadCreate`, and before starting `nativeWorker`, makes each check observe its own thread. 3. **Possible follow-up, not introduced here: guest exception handlers.** `CallHandler` (`core/libs/prx/libkernel/System/src/Exception.cpp:186-190`) calls the guest handler inside the host signal handler. On Linux, signal handlers start with the kernel's default FP state (MXCSR `0x1f80`), so a guest handler on a created guest thread runs without FTZ/DAZ, while its interrupted context holds `0x9fc0`. I did not measure this, and the console's MXCSR inside an exception handler is unmeasured as far as I know. It could be a line in the new debt entry or a separate issue. ## Not verified - Windows. The `_beginthreadex` path, `_endthreadex` in `scePthreadExit`, and Windows adoption in `scePthreadSelf` were not built or run here. The PR's Windows results are the author's. - macOS: not built. - Console behaviour. The `0x9fc0` initial value rests on the firmware 12.70 measurement cited in the PR. I did not check whether a console thread inherits a creator's changed MXCSR or always starts at `0x9fc0`, which is what this PR does. - Title behaviour: no game was run for this review. - The interaction with #7594 (main thread) and #7622 (host workers) was not tested on a combined tree.
Superseabas commented 2026-11-06 16:01:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-06T16:01:10Z.

Review: APPROVED


Windows run of the current head, c91c5f98f4, since the earlier reviews didn't build or run the Windows paths (_beginthreadex, _endthreadex in scePthreadExit, adoption in scePthreadSelf). They work here, and the test catches the loss of each restore that matters. One non-blocking suggestion for the adoption capture, which the test can't see on Windows.

Head merged onto main 492ed5c5fe (clean merge, local only). Windows 11 Home 10.0.26200, Ryzen 7 7700X, WinLibs GCC 16.2.0 (x86_64-ucrt-posix-seh, r3), Release, BUILD_TESTING=ON.

Tests. The 343 tests matching XairRrR's set (pthread|thread_self|thread_atexit|thread_callback|kernel_sys_thread|libc_threads|raise_exception|cancel|thread_local|tls|exception) pass 3 of 3 on main and on this PR. guest_pthread_start and guest_pthread_frame_chain pass 5 of 5. The non-GPU suite (ctest -E '^agc|gpu|vulkan|video_out' -j 8, 2,886 tests) gives 2,883 on both trees. The same three fail on main here: windows_crash_thread_name (#15578), plus test_registration and select_tests_MissingCommandTests, which need the Windows symlink privilege.

Red checks on guest_pthread_start, each a local edit of the merged tree, 3 runs:

Edit Result
none passes
Thread.cpp from main (the PR's header kept) fails: Guest thread MXCSR does not have FTZ and DAZ bits set
the restore in scePthreadExit removed fails: Worker thread host MXCSR was not restored upon guest return
the restore in RunThread removed passes
the restore in the Windows StartNativeThread removed passes
both of those removed fails: the same message
the capture in the Windows StartNativeThread removed passes
the capture in the Windows scePthreadSelf adoption removed passes

On Windows, as on Linux, the restores in RunThread and StartNativeThread cover each other on a normal return; only the one in scePthreadExit runs before _endthreadex.

XairRrR's second point, on Windows. I set workerMxcsrInDtor and workerMxcsrAfterReturn to 0 before each scePthreadCreate and before nativeWorker starts. The test still passes 3 of 3, and it still fails without the scePthreadExit restore or without both normal-return restores. So each check, the adopted-thread case included, reads its own thread's value here, and the TLS hook runs on threads that end through _endthreadex. With a print added to the guest-MXCSR creator case, the main thread reads 0x1f80, and a worker created while its creator held 0x9fc0 reads 0x1f80 coming in and 0x1f80 after it returns. Windows threads don't inherit the creator's MXCSR.

Non-blocking. On Windows the two captures can't be told apart from the 0x1f80 default, since every thread starts there, so removing either one passes. For StartNativeThread that's harmless. For adoption, a native thread can hold any MXCSR before calling scePthreadSelf, and setting one in the test covers the capture:

    std::thread nativeWorker([&] {
        workerTlsHook.active = true;
        const std::uint32_t adoptedMxcsr = 0x1fc0;
        asm volatile("ldmxcsr %0" : : "m"(adoptedMxcsr));
        Pthread adoptedSelf = scePthreadSelf();

with the check after nativeWorker.join() comparing against 0x1fc0 instead of hostMxcsrBefore. I tried it locally: it passes 3 of 3 on this head and fails 3 of 3 (Adopted thread host MXCSR was corrupted upon scePthreadExit) with the Windows adoption capture removed. Nothing in it is Windows-specific, so it should cover the POSIX adoption capture too, which I didn't run.

check_conventions.py --base main passes. No title run, and #7594 and #7622 aren't on this tree.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5803004119 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#pullrequestreview-5803004119). Originally posted by [Superseabas](https://github.com/Superseabas) on 2026-11-06T16:01:10Z. **Review:** APPROVED --- Windows run of the current head, `c91c5f98f4`, since the earlier reviews didn't build or run the Windows paths (`_beginthreadex`, `_endthreadex` in `scePthreadExit`, adoption in `scePthreadSelf`). They work here, and the test catches the loss of each restore that matters. One non-blocking suggestion for the adoption capture, which the test can't see on Windows. Head merged onto `main` `492ed5c5fe` (clean merge, local only). Windows 11 Home 10.0.26200, Ryzen 7 7700X, WinLibs GCC 16.2.0 (`x86_64-ucrt-posix-seh`, r3), Release, `BUILD_TESTING=ON`. **Tests.** The 343 tests matching XairRrR's set (`pthread|thread_self|thread_atexit|thread_callback|kernel_sys_thread|libc_threads|raise_exception|cancel|thread_local|tls|exception`) pass 3 of 3 on `main` and on this PR. `guest_pthread_start` and `guest_pthread_frame_chain` pass 5 of 5. The non-GPU suite (`ctest -E '^agc|gpu|vulkan|video_out' -j 8`, 2,886 tests) gives 2,883 on both trees. The same three fail on `main` here: `windows_crash_thread_name` (#15578), plus `test_registration` and `select_tests_MissingCommandTests`, which need the Windows symlink privilege. **Red checks** on `guest_pthread_start`, each a local edit of the merged tree, 3 runs: | Edit | Result | |---|---| | none | passes | | `Thread.cpp` from `main` (the PR's header kept) | fails: `Guest thread MXCSR does not have FTZ and DAZ bits set` | | the restore in `scePthreadExit` removed | fails: `Worker thread host MXCSR was not restored upon guest return` | | the restore in `RunThread` removed | passes | | the restore in the Windows `StartNativeThread` removed | passes | | both of those removed | fails: the same message | | the capture in the Windows `StartNativeThread` removed | passes | | the capture in the Windows `scePthreadSelf` adoption removed | passes | On Windows, as on Linux, the restores in `RunThread` and `StartNativeThread` cover each other on a normal return; only the one in `scePthreadExit` runs before `_endthreadex`. **XairRrR's second point, on Windows.** I set `workerMxcsrInDtor` and `workerMxcsrAfterReturn` to `0` before each `scePthreadCreate` and before `nativeWorker` starts. The test still passes 3 of 3, and it still fails without the `scePthreadExit` restore or without both normal-return restores. So each check, the adopted-thread case included, reads its own thread's value here, and the TLS hook runs on threads that end through `_endthreadex`. With a print added to the guest-MXCSR creator case, the main thread reads `0x1f80`, and a worker created while its creator held `0x9fc0` reads `0x1f80` coming in and `0x1f80` after it returns. Windows threads don't inherit the creator's MXCSR. **Non-blocking.** On Windows the two captures can't be told apart from the `0x1f80` default, since every thread starts there, so removing either one passes. For `StartNativeThread` that's harmless. For adoption, a native thread can hold any MXCSR before calling `scePthreadSelf`, and setting one in the test covers the capture: ```cpp std::thread nativeWorker([&] { workerTlsHook.active = true; const std::uint32_t adoptedMxcsr = 0x1fc0; asm volatile("ldmxcsr %0" : : "m"(adoptedMxcsr)); Pthread adoptedSelf = scePthreadSelf(); ``` with the check after `nativeWorker.join()` comparing against `0x1fc0` instead of `hostMxcsrBefore`. I tried it locally: it passes 3 of 3 on this head and fails 3 of 3 (`Adopted thread host MXCSR was corrupted upon scePthreadExit`) with the Windows adoption capture removed. Nothing in it is Windows-specific, so it should cover the POSIX adoption capture too, which I didn't run. `check_conventions.py --base main` passes. No title run, and #7594 and #7622 aren't on this tree. AI-assisted: yes (Claude Code)
Superseabas commented 2026-11-06 18:41:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-06T18:41:55Z.

Review: APPROVED


Re-checked the new head, db410ee8f6, on Windows. Thanks for adding the adoption case. git range-diff against c91c5f98f4, which I approved, shows your two earlier commits unchanged; the new commit only adds the 0x1fc0 adoption check in PthreadStart.cpp. It passes here and now catches the missing adoption capture on Windows.

Head merged onto main 9f2b939606 (clean merge, local only). Windows 11 Home 10.0.26200, Ryzen 7 7700X, WinLibs GCC 16.2.0 (x86_64-ucrt-posix-seh, r3), Release.

  • The 344 tests matching pthread|thread_self|thread_atexit|thread_callback|kernel_sys_thread|libc_threads|raise_exception|cancel|thread_local|tls|exception pass 3 of 3. guest_pthread_start and guest_pthread_frame_chain pass 5 of 5.
  • Red checks on guest_pthread_start, 3 runs each:
Edit Result
the capture in the Windows scePthreadSelf adoption removed fails: Adopted thread host MXCSR was corrupted upon scePthreadExit (passed on the previous head)
Thread.cpp from main fails: Guest thread MXCSR does not have FTZ and DAZ bits set
the restore in scePthreadExit removed fails: Worker thread host MXCSR was not restored upon guest return
the restores in RunThread and the Windows StartNativeThread removed fails: the same message
the capture in the Windows StartNativeThread removed passes, as before: every Windows thread starts at 0x1f80

check_conventions.py --base main passes.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5805193593 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#pullrequestreview-5805193593). Originally posted by [Superseabas](https://github.com/Superseabas) on 2026-11-06T18:41:55Z. **Review:** APPROVED --- Re-checked the new head, `db410ee8f6`, on Windows. Thanks for adding the adoption case. `git range-diff` against `c91c5f98f4`, which I approved, shows your two earlier commits unchanged; the new commit only adds the `0x1fc0` adoption check in `PthreadStart.cpp`. It passes here and now catches the missing adoption capture on Windows. Head merged onto `main` `9f2b939606` (clean merge, local only). Windows 11 Home 10.0.26200, Ryzen 7 7700X, WinLibs GCC 16.2.0 (`x86_64-ucrt-posix-seh`, r3), Release. - The 344 tests matching `pthread|thread_self|thread_atexit|thread_callback|kernel_sys_thread|libc_threads|raise_exception|cancel|thread_local|tls|exception` pass 3 of 3. `guest_pthread_start` and `guest_pthread_frame_chain` pass 5 of 5. - Red checks on `guest_pthread_start`, 3 runs each: | Edit | Result | |---|---| | the capture in the Windows `scePthreadSelf` adoption removed | fails: `Adopted thread host MXCSR was corrupted upon scePthreadExit` (passed on the previous head) | | `Thread.cpp` from `main` | fails: `Guest thread MXCSR does not have FTZ and DAZ bits set` | | the restore in `scePthreadExit` removed | fails: `Worker thread host MXCSR was not restored upon guest return` | | the restores in `RunThread` and the Windows `StartNativeThread` removed | fails: the same message | | the capture in the Windows `StartNativeThread` removed | passes, as before: every Windows thread starts at `0x1f80` | `check_conventions.py --base main` passes. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-11-14 11:14:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T11:14:12Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the points below are optional.

What I ran

Reviewed head 25c8cc6be699fb564bcfe6d68ef069e68a6fa8b9 against the prepared diff. No tests or builds were run. I read all changed lines in core/libs/prx/libkernel/Pthread/include/Pthread.hpp, core/libs/prx/libkernel/Pthread/src/Thread.cpp, core/libs/tests/PthreadStart.cpp, and docs/dev/debt/libkernel.md, plus the relevant thread creation, cleanup, and exit context. The prepared bundle lists no excluded changed files.

Results

Check Result Note
Diff and changed lines passed All four changed files read
Targeted control flow passed Creation, return, and explicit exit inspected
Tests and build not run Author reports Linux x86_64 and Windows tests; not independently run

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author-reported test runs and firmware measurement were not independently verified. No test or build was run in this review; platform behavior outside the inspected source remains unverified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5904021470 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7565#pullrequestreview-5904021470). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T11:14:12Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the points below are optional. ## What I ran Reviewed head `25c8cc6be699fb564bcfe6d68ef069e68a6fa8b9` against the prepared diff. No tests or builds were run. I read all changed lines in `core/libs/prx/libkernel/Pthread/include/Pthread.hpp`, `core/libs/prx/libkernel/Pthread/src/Thread.cpp`, `core/libs/tests/PthreadStart.cpp`, and `docs/dev/debt/libkernel.md`, plus the relevant thread creation, cleanup, and exit context. The prepared bundle lists no excluded changed files. ## Results | Check | Result | Note | |---|---|---| | Diff and changed lines | passed | All four changed files read | | Targeted control flow | passed | Creation, return, and explicit exit inspected | | Tests and build | not run | Author reports Linux x86_64 and Windows tests; not independently run | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The author-reported test runs and firmware measurement were not independently verified. No test or build was run in this review; platform behavior outside the inspected source remains unverified. ## To get this to a good state Nothing is required.
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!7565
No description provided.