kernel: run guest threads and fibers with the console's FP environment #2173
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!2173
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2173/head"
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?
@Nawid3333 on GitHub · 2026-11-08 00:04 UTC · original
Nawid3333:fix/guest-fp-env→main· +220 −3 · 5 files · 2 commits · closed without mergingOn the console, threads start with flush-to-zero and denormals-are-zero set, and the default FP environment is MXCSR
0x9fc0(FTZ, DAZ, all exceptions masked) with x87 control word0x037f. Kyty ran guest code with the host defaults (MXCSR0x1f80, and x870x027fon Windows), so guest float code read subnormal values as numbers where the console reads zero.Sources: a payload process on a PS5 (firmware 13.60) and the console's
__fe_dfl_env(AnyPS5 docs/dev/debt/libc.md, lines 60 and 65). For fibers, Kyty already setsFIBER_FLAG_SET_FPU_REGS(0x100) for SDK 3.50 and later but never used it; starting such a fiber with0x9fc0/0x037ffollows shadPS4's libSceFiber and is not measured on a console.Measured in games (RX 9070 XT, Windows 11; one run per game and build, with a lab-only probe in
PRINT_NAME(), which nearly every HLE function calls). At each HLE entry the probe reads the guest's MXCSR denormal-operand (DE) and underflow (UE) flags; inside the HLE function it clears them and reports any flag the function itself raises.0x9f80,0x9fc00x9fc00x9f80,0x1f80,0x9fc00x9fc00x9fc0,0x1f800x9fc00x9fc0,0x1f80,0x9f800x9fc00x1f800x9fc00x9f80(FTZ without DAZ) on main and all read0x9fc0with this change: these threads turn on FTZ on top of the environment they find, so on main DAZ stays off for them.long doubleis a 64-bit double computed with SSE, so only guest x87 code sees the new control word there; on Linux and macOS threads already start with0x037f, the x86-64 System V default.Change.
RunThreadloads the guest environment when the host thread of a guest thread starts, so the entry, key and TLS destructors and cancellation all run with it; the host thread ends with the guest thread.RuntimeLinker::Executeloads it on the main thread before the first module initializer.longjmpand_longjmpdo (same AnyPS5 page, line 57); a fiber withFIBER_FLAG_SET_FPU_REGSstarts with0x9fc0/0x037f, others with the current environment.Test.
GuestPthreadFpandFiberFp(VirtualMemoryAllocationTests, x86-64,--fp-only): a guest thread and a key destructor of it see0x9fc0/0x037f, and the largest subnormal times 2 gives zero; an SDK 3.50 fiber starts with them, its caller gets its own controls back with the current flags, and a resumed fiber gets its controls back.On my PC: main fails
GuestPthreadFp("a guest thread did not start with MXCSR 0x9fc0 and x87 control 0x037f"); with this change both pass. Each of the four parts reverted alone fails its own check. The Windows CI test set passes as on main (32 of 32).Fork CI on this head: Linux and macOS build and pass the tests; Windows stops at the same MSVC STL 14.51 build error as main (
xutility(320), fixed by #2165). With #2165 on top (0634c81), Linux, macOS and Windows build and pass the tests (run).Written with Claude Code and OpenAI Codex (AI): the fix, the test and the measurements, run on my PC; reviewed by me.
@coderabbitai[bot] on GitHub · 2026-11-08 00:09 UTC · original
Walkthrough
The change adds a shared floating-point environment type and guest defaults. Thread startup and runtime execution apply those defaults. Fiber contexts now save and restore MXCSR and the x87 control word. New x86-64 tests check thread and fiber floating-point behavior, including state preservation across fiber yields and resumes.
Suggested reviewers:
nmzik,chaitan3Change: Bug fix
Merge Risk:
Minimal · up to
e6415The change applies the console floating-point environment to guest threads, the main thread and fibers, and adds tests for it. No concrete merge-blocking risk was identified.
Pre-merge checks:
4 ·
1
Full details: Title check
Explanation
The title "kernel: run guest threads and fibers with the console's FP environment" matches the main change: guest threads, fibers and the main thread now start with the console's MXCSR 0x9fc0 and x87 control word 0x037f. The title is specific, concise and follows a component-prefix style. It does not list every detail, such as signal handlers being unchanged, which is expected.
Full details: Description check
Explanation
The description explains the purpose of the change: console threads use flush-to-zero and denormals-are-zero defaults, and Kyty used host defaults. It names the changed areas (RunThread, RuntimeLinker::Execute, fiber switches), the new GuestPthreadFp and FiberFp tests, and gives measurement and CI details. It is clearly related to the changeset.
Full details: Docstring Coverage
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 12 functions across 5 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
@coderabbitai[bot] on GitHub · 2026-11-08 00:09 UTC · original · reviewed
75587346-39ae-473a-ac50-8feb9340c00aReviewing files that changed from the base of the PR and between
751fbd0965ande64155503e.src/common/fpEnv.hsrc/kernel/pthread.cppsrc/libs/libKernel.cppsrc/loader/runtimeLinker.cpptests/VirtualMemoryAllocationTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
@Nmzik on GitHub · 2026-11-09 10:54 UTC · original
Credited
Pull request closed