feat(libkernel): initialize created guest thread MXCSR to 0x9fc0 at entry boundary #7565
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7565"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by 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 set0x9fc0upon 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 forguest_pthread_frame_chain. InRunThreadandscePthreadExit, host worker MXCSR is recorded and restored only afterfinishThreadhas completed, ensuring that guest thread destructors and TSD key destructors execute symmetrically under guest MXCSR0x9fc0across 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.cppexercises 10,000 guest thread starts across normal return andscePthreadExitexplicit exits. Tests verify that guest execution and cleanup (WorkerThreadDtor) observe0x9fc0, the native worker thread (WorkerTlsHookTLS destructor) restores host MXCSR upon guest completion, and the process main thread preserves its host MXCSR throughout;python tools/check_conventions.py --base origin/mainpasses with 0 findings.Checklist
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T14:28:53Z.
Review: COMMENTED
One test coverage gap:
hostMxcsrBeforeandhostMxcsrAfterare sampled on the test process main thread, whilescePthreadCreaterunsAps5CallGuestEntry_nid_no_patchon 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?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:
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, soFixes: #7548would close the issue with that part still open.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 bypassesAps5CallGuestEntry_nid_no_patchand 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: #7548claim to created threads and coordinate the remaining main-thread behavior separately? I have not run the Windows test locally.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:
maine5f18ea99with @mugurc's macOS series (ci/macos-series-2on his fork) and the open macOS fixes it uses, sincemainalone does not link the libraries on macOS. Non-GPU suite with and without this PR.guest_pthread_frame_chainfails with this PR, every run:It passes on the same tree without the PR.
Aps5CallGuestEntry_nid_no_patchpushes two zeros and points%rbpat them. That pair is the zero record that ends the guest thread's frame chain. The newstmxcsr (%rsp)/movl $0x9fc0, 4(%rsp)write into the saved frame pointer half of that record. After that it holds0x00009fc0_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:
With that change,
guest_pthread_frame_chain(still 3 frames),guest_pthread_start,guest_raise_exceptionand the other 23guest_pthread*tests pass.Other results:
guest_pthread_startpasses with the PR. With only the test applied it fails withGuest 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)andguest_pthread_startstill 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
0x9fc0when the entry returns.finishThreadruns the key destructors and the thread-exit callback afterAps5CallGuestEntry_nid_no_patchhas restored the host MXCSR. A local probe with ascePthreadKeyCreatedestructor that reads MXCSR printed:0x9fc00x1f80scePthreadExit0x9fc00x9fc0So the same guest destructor runs with different FTZ/DAZ depending on how the thread ended.
On macOS with @mugurc's
feat/libkernel-macos-main-threadbranch (not opened yet), the guest main thread is also a second host thread:Aps5StartGuest_nid_no_patchruns the entry fromRunGueston a newpthread_createthread, which starts at0x1f80. Covering the main thread there means setting MXCSR inRunGuest, 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_connectfailed 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.
Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-18T15:59:09Z.
Pushed commit
251ef0f28addressing all feedback:Stack Unwinding & Frame Chain Record Isolation (@jotitadev):
Aps5CallGuestEntry_nid_no_patch, allocating 16 bytes below%rbp(sub $16, %rsp/.cfi_adjust_cfa_offset 16and.cfi_adjust_cfa_offset -32/add $32, %rsp) isolates the MXCSR storage slot into[rbp - 16].(%rbp), preserving the sentinel frame pointer record forguest_pthread_frame_chain.Same-Worker Host MXCSR Restoration Test Coverage (@MarcZX10, @jotitadev):
sceKernelSetThreadDtors(WorkerThreadDtor)incore/libs/tests/PthreadStart.cpp.Aps5CallGuestEntry_nid_no_patch, the wrapper restores the host MXCSR vialdmxcsr (%rsp). Subsequently,finishThreadexecutesWorkerThreadDtoron the exact same worker thread.workerMxcsrAfterReturn.load() == hostMxcsrBeforefor non-explicit returns (and confirms0x9fc0remains active during explicit exit cleanup), directly verifying the worker's restore instruction.Narrowed PR Scope & Title/Debt Update (@ionut27001, @MarcZX10):
feat(libkernel): initialize created guest thread MXCSR to 0x9fc0 at entry boundaryand setFixes: none.### Whatanddocs/dev/debt/libkernel.mdthat this PR specifically covers created guest threads under firmware 12.70 payload findings. The main ELF thread entry stub (which bypassesAps5CallGuestEntry_nid_no_patch) and macOSRunGuestentry remain open and will not be closed by this PR.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_patchrestores the host MXCSR beforeRunThreadcallsfinishThread, sothreadDtorsandRunKeyDtorsexecute under host MXCSR. When the guest callsscePthreadExit,finishThreadruns 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.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.
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:
maind3d8d79c5with @mugurc's macOS series and the open macOS fixes it uses.guest_pthread_frame_chainnow passes (5/5), so the zero record is intact.guest_pthread_startpasses (5/5). The new destructor check covers the restore. With only theldmxcsr (%rsp)after the call removed, it fails every run withWorker thread host MXCSR was not restored upon guest return. With only the test applied on the base it still fails withGuest thread MXCSR does not have FTZ and DAZ bits set.pthread/thread/raise_exceptiontests 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.
Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-18T16:41:15Z.
Pushed commit
1f99bd900addressing the destructor state-consistency:Retain
0x9fc0Across Normal-Return Cleanup:Aps5CallGuestEntry_nid_no_patch, removed the immediateldmxcsrupon returning fromcall *%rax.RunThread,hostMxcsris saved prior toAps5CallGuestEntry_nid_no_patchand restored vialdmxcsrimmediately afterfinishThread(self, retval)returns.threadDtorsandThreadLifecycle::RunKeyDtors()execute under guest MXCSR0x9fc0whether the thread terminates via normal return or explicit exit (scePthreadExit).Unified Regression Assertion in
PthreadStart.cpp:(workerMxcsrInDtor.load() & 0x9fc0) == 0x9fc0across all 10,000 iterations (both explicit exit and normal return paths).Coordination with #7594:
docs/dev/debt/libkernel.mdand the PR description to note the coordination with #7594 for the main ELF thread entry stub.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:
Aps5CallGuestEntry_nid_no_patch, the immediate restore instruction upon guest return was removed, keeping guest MXCSR0x9fc0active across thread exit.RunThread,hostMxcsris recorded prior to entry and restored vialdmxcsronly afterfinishThread(self, retval)returns.threadDtorsandThreadLifecycle::RunKeyDtors()execute under0x9fc0consistently regardless of whether the thread exits viascePthreadExitor normal return.PthreadStart.cpp, the destructor hook now asserts that(workerMxcsrInDtor.load() & 0x9fc0) == 0x9fc0across all 10,000 iterations for both paths.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?
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:
Host Work Called Directly From Guest Threads:
libkernel,libc,libSceAgcDriver,libSceAudioOut2, etc.) and AGC draw/state dispatch run synchronously on the guest thread's stack with the current MXCSR (0x9fc0).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 conditionalSelectF32arms. 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.Host-Owned Worker Threads (Linux
cloneInheritance):Submissionqueue workers,PipelineLibrary/PipelineCachebackground compilers, andShaderDiskCachewriter) inherit the parent's0x9fc0viaclone().Recommendation:
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/mainwith all pre-flight and CI checks passing green?feat(libSceVoice): implement sceVoiceEnableChat and sceVoiceDisableChat(pairs with #5817, matching thesceAudioOut2EnableChatmodel)feat(libSceSysmodule): register libSceProprietaryVoiceChatHelperPrx module id 0x132(verified in #5017, resolves startup notice in Discussion #6344)Thanks!
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.
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 to0x9fc0at theAps5CallGuestEntry_nid_no_patchboundary, preserving the sentinel frame-chain record for unwinding, and ensuring guest TSD key destructors infinishThreadexecute symmetrically under0x9fc0across 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.
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.
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
1f99bd900merged ontomain84c1a4d9a(clean merge).Builds. The 26 pthread tests (
ctest -R pthread) pass, includingguest_pthread_startandguest_pthread_frame_chain. Non-GPU suite (ctest -E "^agc|gpu|vulkan|video_out"): 739/739, same asmain.Without the
ldmxcsr (%rsp)inAps5CallGuestEntry_nid_no_patch,guest_pthread_startfails withGuest thread MXCSR does not have FTZ and DAZ bits set, so the guest-side check works.Without the
ldmxcsr %0restore afterfinishThreadinRunThread,guest_pthread_startstill 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.
scePthreadExitcallsfinishThreadand thenlongjmps toStartNativeThread, which skips the rest ofRunThread, the restore included. I added athread_localobject with a destructor that reads MXCSR toguest_pthread_start(set inCheckThread, 10000 threads, 3 runs):thread_localdestructorscePthreadExit(3334 threads)0x9fc0, all 3334So after an explicit exit (or a cancel, which goes through
scePthreadExit),ThreadGuard,ReleaseThreadand the native thread's TLS destructors run with FTZ and DAZ set. Restoring inStartNativeThreadafter thesetjmpblock would cover both paths. The Windows_endthreadexpath 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.
Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-19T05:40:46Z.
Pushed commit
8659e828brebased onto latestorigin/main(4ffb0cd12) addressing both points:Host MXCSR Restoration Across Explicit Exits (
scePthreadExit) and Normal Returns (@jotitadev, @MarcZX10):hostMxcsrinsidePthreadPrivate.RunThread,finishThreadexecutes all guest TSD destructors under0x9fc0, followed immediately byasm volatile("ldmxcsr %0" : : "m"(hostMxcsr)).scePthreadExit,finishThreadexecutes all guest cleanup handlers and key destructors under0x9fc0, restores host MXCSR vialdmxcsrprior to thread exit/jump, and on Linux thesetjmpreceiver inStartNativeThreadadditionally executesldmxcsrbeforeguardand thread termination.scePthreadExit/ cancel) and normal return cleanup run under0x9fc0, while host worker thread teardown runs under host MXCSR.Same-Worker MXCSR Observation Across 10,000 Iterations (@MarcZX10):
thread_localhook (WorkerTlsHook) incore/libs/tests/PthreadStart.cppthat 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.scePthreadJoin,main()assertsworkerMxcsrAfterReturn.load() == hostMxcsrBeforewhile 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) andscePthreadExit(3,334 iterations) paths.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T08:12:41Z.
Linux rerun of
8659e828bwith the samethread_localprobe as my earlier comment on1f99bd900.Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release,
BUILD_TESTING=ON, full build. Head8659e828bmerged ontomain6b8228b2b(clean merge).main.thread_localdestructor is now the host value on both paths, 6666 of 6666 after a return and 3334 of 3334 afterscePthreadExit. On1f99bd900the second was0x9fc0in all 3334.WorkerTlsHookcheck catches it. Without the twoldmxcsrofself->hostMxcsr(StartNativeThreadandscePthreadExit),guest_pthread_startfails 3 of 3 withWorker thread host MXCSR was not restored upon guest return. Without only the restore inRunThreadit still passes 3 of 3, because on Linux the one inStartNativeThreadruns afterRunThreadreturns as well. That makes theRunThreadrestore 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.
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 theWorkerTlsHooktest coverage.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:hostMxcsrdefaults to0and onlyRunThread(Thread.cpp:669) sets it, butscePthreadExitrunsldmxcsr self->hostMxcsrfor any registered thread (e.g. threads adopted throughscePthreadSelfon Windows, which never pass throughRunThread). Loading0unmasks 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 theldmxcsrwhen it was never captured (and default to0x1f80rather than0), and add a case that callsscePthreadExitfrom a thread that did not go throughRunThreadif one exists on a supported platform.The rest (stack slot below
%rbp, restore afterfinishThread, test pinning guest and host values) looks right.Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-19T17:05:27Z.
@adriadam10 Thanks for the review!
Pushed commit
e6d73a3e8rebased onto latestorigin/main(00d7e611e) addressing both points:Default
hostMxcsr& Adoption Capture:hostMxcsrinPthreadPrivateto0x1f80(standard x86_64 host default with all FP exceptions masked and round-to-nearest) rather than0.stmxcsrduring thread adoption inscePthreadSelf()across both Windows and non-Windows paths so adopted threads retain their native caller's exact FP environment.Adopted Thread
scePthreadExitTest Case:core/libs/tests/PthreadStart.cpp: spawns a nativestd::thread, adopts it as guest state viascePthreadSelf(), enablesworkerTlsHook, and executesscePthreadExit(nullptr).hostMxcsrBefore.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T01:39:51Z.
Review: APPROVED
Reviewed exact head
e6d73a3e8bd3cc7acc517ff8c5a9957224f3008cin response to the review request. The earlier adopted-thread issue is addressed:hostMxcsrhas 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 throughfinishThreadon 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.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.
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:
For the host-thread inheritance check, I compiled and ran this minimal probe:
Results
Raw output
Negative control
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
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.
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
main.python3 tools/check_conventions.py --base upstream/main --head HEAD.git diff --check upstream/main...HEAD.git merge-tree --write-tree upstream/main HEAD.Results
8883aea222b18ab44c508e6fa4c4867e7b35c9b2scePthreadExitpathsThe 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
Sources
All code links point to the reviewed commit
f0c460b9ba3d4c69d7a96d75b78e0fb1094d13e8.Not verified
To get to a good state
No further changes are required for the findings in this review.
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_startfail, and so does removing either the worker MXCSR capture or the restores.What I ran
f0c460b9ba3d4c69d7a96d75b78e0fb1094d13e8main:3a2b91981651569163768854a1fcdc7193b6667bmainin a clean worktree (--no-ff): no conflicts.BUILD_TESTING=ON, Intel Core i9-14900KF.Results
maingit diff --checkcheck_conventions.pylibsand the full tree)guest_pthread_startandguest_pthread_frame_chain, 5 runsguest_pthread_starttakes about 0.5 sThread.cppreverted)StartNativeThreadcapture removedldmxcsr self->hostMxcsrrestores removedguest_pthread_start on the merged tree
Focused set (tail)
Negative control
The test reads the new
PthreadPrivate::hostMxcsrfield, so it does not compile againstmain'sPthread.hpp. I kept the PR's header, which only adds the field, and restoredcore/libs/prx/libkernel/Pthread/src/Thread.cppfromorigin/main.guest_pthread_startthen failed 3 of 3 runs:I also ran two mutations on the merged tree:
self->hostMxcsr = incomingMxcsr;in the POSIXStartNativeThread(Thread.cpp:932) failed 3 of 3 withWorker incoming MXCSR did not match creator MXCSR on POSIX. The test therefore covers the inheritance issue from the previous round.Thread.cpp:812,:967,:1173) failed 3 of 3 withWorker 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_patchkeeps the zero frame record at(%rbp).%rspis 16-byte aligned atcall *%rax: 8 + 3×8 + 16 bytes are pushed or allocated.push $0).selfis still alive at everyldmxcsr self->hostMxcsr, because the thread drops its own reference later inReleaseThreadorThreadGuard.scePthreadJoincallspthread_joinorWaitForSingleObjectbefore the test reads it.Non-blocking
Unblockspoints at this PR, not the title's discussion. The line readsUnblocks: 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.core/libs/tests/PthreadStart.cpp:11-12, checked at:107,:109,:141,:160,:178).workerMxcsrInDtorandworkerMxcsrAfterReturnare 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. Storing0in both atomics before eachscePthreadCreate, and before startingnativeWorker, makes each check observe its own thread.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 (MXCSR0x1f80), so a guest handler on a created guest thread runs without FTZ/DAZ, while its interrupted context holds0x9fc0. 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
_beginthreadexpath,_endthreadexinscePthreadExit, and Windows adoption inscePthreadSelfwere not built or run here. The PR's Windows results are the author's.0x9fc0initial 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 at0x9fc0, which is what this PR does.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,_endthreadexinscePthreadExit, adoption inscePthreadSelf). 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
main492ed5c5fe(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 onmainand on this PR.guest_pthread_startandguest_pthread_frame_chainpass 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 onmainhere:windows_crash_thread_name(#15578), plustest_registrationandselect_tests_MissingCommandTests, which need the Windows symlink privilege.Red checks on
guest_pthread_start, each a local edit of the merged tree, 3 runs:Thread.cppfrommain(the PR's header kept)Guest thread MXCSR does not have FTZ and DAZ bits setscePthreadExitremovedWorker thread host MXCSR was not restored upon guest returnRunThreadremovedStartNativeThreadremovedStartNativeThreadremovedscePthreadSelfadoption removedOn Windows, as on Linux, the restores in
RunThreadandStartNativeThreadcover each other on a normal return; only the one inscePthreadExitruns before_endthreadex.XairRrR's second point, on Windows. I set
workerMxcsrInDtorandworkerMxcsrAfterReturnto0before eachscePthreadCreateand beforenativeWorkerstarts. The test still passes 3 of 3, and it still fails without thescePthreadExitrestore 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 reads0x1f80, and a worker created while its creator held0x9fc0reads0x1f80coming in and0x1f80after 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
0x1f80default, since every thread starts there, so removing either one passes. ForStartNativeThreadthat's harmless. For adoption, a native thread can hold any MXCSR before callingscePthreadSelf, and setting one in the test covers the capture:with the check after
nativeWorker.join()comparing against0x1fc0instead ofhostMxcsrBefore. 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 mainpasses. No title run, and #7594 and #7622 aren't on this tree.AI-assisted: yes (Claude Code)
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-diffagainstc91c5f98f4, which I approved, shows your two earlier commits unchanged; the new commit only adds the0x1fc0adoption check inPthreadStart.cpp. It passes here and now catches the missing adoption capture on Windows.Head merged onto
main9f2b939606(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.pthread|thread_self|thread_atexit|thread_callback|kernel_sys_thread|libc_threads|raise_exception|cancel|thread_local|tls|exceptionpass 3 of 3.guest_pthread_startandguest_pthread_frame_chainpass 5 of 5.guest_pthread_start, 3 runs each:scePthreadSelfadoption removedAdopted thread host MXCSR was corrupted upon scePthreadExit(passed on the previous head)Thread.cppfrommainGuest thread MXCSR does not have FTZ and DAZ bits setscePthreadExitremovedWorker thread host MXCSR was not restored upon guest returnRunThreadand the WindowsStartNativeThreadremovedStartNativeThreadremoved0x1f80check_conventions.py --base mainpasses.AI-assisted: yes (Claude Code)
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
25c8cc6be699fb564bcfe6d68ef069e68a6fa8b9against the prepared diff. No tests or builds were run. I read all changed lines incore/libs/prx/libkernel/Pthread/include/Pthread.hpp,core/libs/prx/libkernel/Pthread/src/Thread.cpp,core/libs/tests/PthreadStart.cpp, anddocs/dev/debt/libkernel.md, plus the relevant thread creation, cleanup, and exit context. The prepared bundle lists no excluded changed files.Results
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.